Spin reorientation driven by energy gap formation in UCu5