Example #1
0
 def _check_angles(self, angles):
     '''Check consistency for euler_to_u() and u_to_euler(). I.e check that 
     the orientation matrix constructed for some set of angles is recovered
     again when passing between the two functions.
     '''
     for phi1 in angles:
         for PHI in angles:
             for phi2 in angles:
                 U = tools.euler_to_u(phi1, PHI, phi2)
                 phi1_new, PHI_new, phi2_new = tools.u_to_euler(U)
                 U_new = tools.euler_to_u(phi1_new, PHI_new, phi2_new)
                 maxdiff = n.max(n.abs(U - U_new))
                 self.assertTrue(maxdiff < 1e-8)
                 self.assertTrue(0 <= phi1_new <= 2 * n.pi)
                 self.assertTrue(0 <= PHI_new <= 2 * n.pi)
                 self.assertTrue(0 <= phi2_new <= 2 * n.pi)
Example #2
0
 def test1(self):
     phi1 = 0.0
     PHI = 0.0
     phi2 = 0.0
     Umat = tools.euler_to_u(phi1, PHI, phi2)
     diff = n.abs(Umat - n.eye(3)).sum()
     self.assertAlmostEqual(diff, 0, 9)
Example #3
0
 def crystal_to_omega(self,grain_state):
     omega = []
     eps = np.zeros((3,3))
     for i in range(len(grain_state)//9):
         low = i*9
         mid = low+6
         high = low + 9
         euler = grain_state[mid:high]
         #[e11, e12, e13, e22, e23, e33] 
         e = grain_state[low:mid]
         eps[0,0] = e[0]
         eps[0,1] = e[1]
         eps[1,0] = e[1]
         eps[0,2] = e[2]
         eps[2,0] = e[2]
         eps[1,1] = e[3]
         eps[1,2] = e[4]
         eps[2,1] = e[4]
         eps[2,2] = e[5]           
         U = tools.euler_to_u(euler[0],euler[1],euler[2])
         eps_om = np.dot(np.dot(U.T,eps),U)
         eps_om_list = [eps[0,0], eps[0,1], eps[0,2], eps[1,1], eps[1,2], eps[2,2]]
         omega.extend( eps_om_list )
         omega.extend( euler )
     return np.asarray( omega )
Example #4
0
 def strain_and_euler_to_ub(self,strain,euler):
     '''
     cell = [a,b,c,alpha,beta,gamma]
     euler= [phi1,PHI,phi2]
     '''
     U = tools.euler_to_u(euler[0],euler[1],euler[2])
     B = tools.epsilon_to_b(strain, self.unit_cell)
     return np.dot(U,B)
Example #5
0
    def cell_and_euler_to_ub(self,cell,euler):
        '''
        cell = [a,b,c,alpha,beta,gamma]
        euler= [phi1,PHI,phi2]
        '''

        U = tools.euler_to_u(euler[0],euler[1],euler[2])
        B = tools.form_b_mat(cell)
        return np.dot(U,B)
Example #6
0
    def test_U2rod2U(self):
        phi1 = 0.2
        PHI = 0.4
        phi2 = 0.1
        Umat = tools.euler_to_u(phi1, PHI, phi2)
        rodvec = tools.u_to_rod(Umat)
        Umat2 = tools.rod_to_u(rodvec)

        diff = n.abs(Umat - Umat2).sum()
        self.assertAlmostEqual(diff, 0, 9)
Example #7
0
 def test_ubi2rod(self):
     phi1 = 0.13
     PHI = 0.4
     phi2 = 0.21
     cell = [3, 4, 5, 80, 95, 100]
     Umat = tools.euler_to_u(phi1, PHI, phi2)
     ubi = n.linalg.inv(n.dot(Umat, tools.form_b_mat(cell))) * 2 * n.pi
     rodubi = tools.ubi_to_rod(ubi)
     rodU = tools.u_to_rod(Umat)
     diff = n.abs(rodubi - rodU).sum()
     self.assertAlmostEqual(diff, 0, 9)
Example #8
0
 def test_ubi2rod(self):
     phi1 = 0.13
     PHI = 0.4
     phi2 = 0.21
     cell = [3, 4, 5, 80, 95, 100]
     Umat = tools.euler_to_u(phi1, PHI, phi2)
     Bmat = tools.form_b_mat(cell)
     ubi = n.linalg.inv(n.dot(Umat, Bmat)) * 2 * n.pi
     (U1, B1) = tools.ubi_to_u_b(ubi)
     diffU = n.abs(Umat - U1).sum()
     diffB = n.abs(Bmat - B1).sum()
     self.assertAlmostEqual(diffU, 0, 9)
     self.assertAlmostEqual(diffB, 0, 9)
Example #9
0
 def test1(self):
     phi1 = 0.13
     PHI = 0.4
     phi2 = 0.21
     cell = [3, 4, 5, 80, 95, 100]
     Umat = tools.euler_to_u(phi1, PHI, phi2)
     Bmat = tools.form_b_mat(cell)
     ubi = n.linalg.inv(n.dot(Umat, Bmat)) * 2 * n.pi
     ubi2 = tools.u_to_ubi(Umat, cell)
     (U2, B2) = tools.ubi_to_u_b(ubi2)
     diff = n.abs(ubi - ubi2).sum()
     self.assertAlmostEqual(diff, 0, 9)
     diff = n.abs(Umat - U2).sum()
     self.assertAlmostEqual(diff, 0, 9)
     diff = n.abs(Bmat - B2).sum()
     self.assertAlmostEqual(diff, 0, 9)
Example #10
0
 def test_UdotBtoUandB(self):
     ucell = n.array([
         3.5 + n.random.rand(), 3.5 + n.random.rand(),
         3.5 + n.random.rand(), 89.5 + n.random.rand(),
         89.5 + n.random.rand(), 89.5 + n.random.rand()
     ])
     eps = (n.random.rand(6) - .5) / 1000.
     B = tools.epsilon_to_b(eps, ucell)
     U = tools.euler_to_u(n.random.rand() * 2. * n.pi,
                          n.random.rand() * 2. * n.pi,
                          n.random.rand() * n.pi)
     UB = n.dot(U, B)
     (U1, B1) = tools.ub_to_u_b(UB)
     diffU = n.abs(U - U1).sum()
     diffB = n.abs(B - B1).sum()
     self.assertAlmostEqual(diffU, 0, 9)
     self.assertAlmostEqual(diffB, 0, 9)
Example #11
0
 def test_tth(self):
     # generate random gvector
     hkl = n.array([
         round(n.random.rand() * 10 - 5),
         round(n.random.rand() * 10 - 5),
         round(n.random.rand() * 10 - 5)
     ])
     ucell = n.array([
         3.5 + n.random.rand(), 3.5 + n.random.rand(),
         3.5 + n.random.rand(), 89.5 + n.random.rand(),
         89.5 + n.random.rand(), 89.5 + n.random.rand()
     ])
     B = tools.form_b_mat(ucell)
     U = tools.euler_to_u(n.random.rand() * 2. * n.pi,
                          n.random.rand() * 2. * n.pi,
                          n.random.rand() * n.pi)
     wavelength = 0.95 + n.random.rand() * 0.1
     gvec = n.dot(U, n.dot(B, hkl))
     tth = tools.tth(ucell, hkl, wavelength)
     tth2 = tools.tth2(gvec, wavelength)
     diff = n.abs(tth - tth2)
     self.assertAlmostEqual(diff, 0, 9)
Example #12
0
 def test_find_omega_general_nowedge(self):
     # generate random gvector
     hkl = n.array([
         round(n.random.rand() * 10 - 5),
         round(n.random.rand() * 10 - 5),
         round(n.random.rand() * 10 - 5)
     ])
     ucell = n.array([
         3.5 + n.random.rand(), 3.5 + n.random.rand(),
         3.5 + n.random.rand(), 89.5 + n.random.rand(),
         89.5 + n.random.rand(), 89.5 + n.random.rand()
     ])
     B = tools.form_b_mat(ucell)
     U = tools.euler_to_u(n.random.rand() * 2. * n.pi,
                          n.random.rand() * 2. * n.pi,
                          n.random.rand() * n.pi)
     wavelength = 0.95 + n.random.rand() * 0.1
     gvec = n.dot(U, n.dot(B, hkl))
     tth = tools.tth(ucell, hkl, wavelength)
     # calculate corresponding eta and Omega using tools.find_omega_general
     (omega1,
      eta1) = tools.find_omega_general(gvec * wavelength / (4. * n.pi), tth,
                                       0, 0)
     Om1 = []
     for i in range(len(omega1)):
         Om1.append(tools.form_omega_mat_general(omega1[i], 0, 0))
     # calculate corresponding eta and Omega using tools.find_omega_wedge
     omega2 = tools.find_omega(gvec, tth)
     Om2 = []
     for i in range(len(omega2)):
         Om2.append(tools.form_omega_mat(omega2[i]))
     #assert
     for i in range(len(omega1)):
         #            print Om1[i]
         #            print Om2[i]
         diff = n.abs(Om1[i] - Om2[i]).sum()
         self.assertAlmostEqual(diff, 0, 9)