def test_matrix_to_angles(self): """ Note that there are two possible sets of angles for a rotation matrix. Also note that for the cases where cos(beta)=0, there is no unique answer """ # print sys._getframe().f_code.co_name r = self.rot1.as_double() expected_angles = self.rot_angles1 angles = nu.rotation_to_angles(rotation=r, deg=False) assert approx_equal(expected_angles,angles,1e-3) expected_angles = self.rot_angles1_deg angles = nu.rotation_to_angles(rotation=r, deg=True) assert approx_equal(expected_angles,angles,1e-3) # Test cos(beta)=0 # sin(beta) = 1 r = self.rot2.as_double() # when sin(beta) = 1 the (alpha + gamma) is the solution expected_angles_sum = self.rot_angles2[0] + self.rot_angles2[2] angles = nu.rotation_to_angles(rotation=r, deg=False) angles_sum = angles[0] + angles[2] assert approx_equal(expected_angles_sum,angles_sum,1e-3) # sin(beta) = -1 # when sin(beta) = -1 the (alpha - gamma) is the solution expected_angles_sum = self.rot_angles2[0] - self.rot_angles2[2] r = self.rot3.as_double() angles = nu.rotation_to_angles(rotation=r, deg=False) angles_sum = angles[0] - angles[2] assert approx_equal(expected_angles_sum,angles_sum,1e-3)
def test_working_with_tuples(self): """ When working with scitbx matrix.rec or matrix.sqr (the form rotation matrices are in) the elements of those matrices are available as tuple. Verify that we process tuple well """ # print sys._getframe().f_code.co_name r = tuple(self.rot1.as_double()) expected_angles = self.rot_angles1 angles = nu.rotation_to_angles(rotation=r, deg=False) assert approx_equal(expected_angles,angles,1e-3)
def concatenate_rot_tran(self): """ Concatenate rotation angles, corresponding to the rotation matrices and scaled translation vectors to a single long flex.double object Returns: flex.double : [(alpha_1,beta_1,gamma_1,Tx_1,Ty_1,Tz_1)...] """ x = [] for gr in self: for tr in gr.copies: x.extend(list(nu.rotation_to_angles(rotation=tr.r.elems)) + list(tr.t.elems)) return flex.double(x)