Ejemplo n.º 1
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)
Ejemplo n.º 2
0
 def test_ucell2B2ucell(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()
     ])
     B = tools.form_b_mat(ucell)
     ucell2 = tools.b_to_cell(B)
     diff = n.abs(ucell - ucell2).sum()
     self.assertAlmostEqual(diff, 0, 9)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def extract_strain_and_directions(cell, wavelength, distance, pixelsize, g, flt, ymin, ystep, omegastep, NY ):

    B = tools.form_b_mat(cell)

    keys = [ (hkl[0], hkl[1], hkl[2], int(s))
             for hkl, s in zip(g.hkl.T , g.etasigns)]

    uni = uniq(keys)
    akeys = np.array( keys )
    strains = []
    directions = []
    all_omegas = []
    dtys = []
    all_tths = []
    all_etas = []
    weights = []
    all_intensity = []
    all_sc = []
    all_Gws = []
    all_hkl = []

    for refi,u in enumerate(uni):

        # h==h, k==k, l==l, sign==sign
        mask = (akeys == u).astype(int).sum(axis=1) == 4
        tths = flt.tth[g.mask][mask]
        etas = flt.eta[g.mask][mask]
        omegas = flt.omega[g.mask][mask]
        scs = flt.sc[g.mask][mask]
        detector_y_pos = flt.dty[ g.mask ][mask]
        intensity = flt.sum_intensity[g.mask][mask]
        scs = flt.sc[g.mask][mask]
        G_ws = np.array( (flt.gx[g.mask][mask], flt.gy[g.mask][mask], flt.gz[g.mask][mask]) ).T
        h = u[0]
        k = u[1]
        l = u[2]

        for sc, dty, tth, eta, om, I, sc, G_w in zip( scs, detector_y_pos, tths, etas, omegas, intensity, scs, G_ws ):

            all_hkl.append( [h,k,l] )
            bragg_order, d_measured, d_original, eps = strain(B, h, k, l, tth, wavelength)
            strains.append( eps )
            directions.append( normal_omega(tth, eta, wavelength, om) )
            all_omegas.append( om )
            all_tths.append( tth )
            all_etas.append( eta )
            dtys.append( dty )
            all_intensity.append( I )
            all_sc.append( sc )
            all_Gws.append(G_w)
            weights.append( weight( d_measured, d_original, eps, tth, wavelength, bragg_order, distance, pixelsize ) )

    return np.array(strains), np.array(directions), np.array(all_omegas), np.array(dtys), np.array(weights), np.array(all_tths), np.array(all_etas), np.array(all_intensity), np.array(all_sc), np.asarray(all_Gws), np.asarray(all_hkl)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def build_B_from_Cif(ciffile):
    """
	Builds a B-matrix based on information in a cif file
	
	Parameter:
	- cif file name
	
	Returns
	- B matrix, as in polyxsim (watch out for the 2pi factor!!)
	
	Created: 12/2019, S. Merkel, Univ. Lille, France
	"""
    param['structure_phase_0'] = ciffile
    xtal_structure = open_cif(param, 0)
    unit_cell = param['unit_cell_phase_0']
    B = tools.form_b_mat(unit_cell)
    return B
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def rotations(crystal_system):
    
    """ 
    rotations returns the set of unitary rotation matrices
    corresponding to the indistinguasible lattice permutations
    The values of the function only differ from permutations for 
    trigonal and hexagonal crystal systems
    
    rot = rotations(crystal_system)
    U_new = U*rot
    
    U_new*B*perm*hkl = U*B*hkl, so U_new = U*B*perminv*Binv and
    rot = B*perminv*Binv. If B or perm is diagonal, rot = perminv.
    perminv included in perm, but to get the i'th entry of rot
    to correspond to the i'th entry of perm one must use perminv.
    
    crystal_system can be one of the following values   
    1: Triclinic
    2: Monoclinic
    3: Orthorhombic
    4: Tetragonal
    5: Trigonal
    6: Hexagonal
    7: Cubic
    
    Jette Oddershede, Riso, 8/2/2010
    """

    if crystal_system < 1 or crystal_system > 7:
        raise ValueError('Crystal system shoud have a value between 1 and 7')

    if crystal_system == 1: # Triclinic
        rot = permutations(crystal_system)
        for i in range(len(rot)):       
            rot[i] = inv(rot[i])

    if crystal_system == 2: # Monoclinic
        rot = permutations(crystal_system)
        for i in range(len(rot)):       
            rot[i] = inv(rot[i])

    if crystal_system == 3: # Orthorhombic
        rot = permutations(crystal_system)
        for i in range(len(rot)):       
            rot[i] = inv(rot[i])
 
    if crystal_system == 4: # Tetragonal
        rot = permutations(crystal_system)
        for i in range(len(rot)):       
            rot[i] = inv(rot[i])

    if crystal_system == 5: # Trigonal
        perm = permutations(crystal_system)
        B = tools.form_b_mat([1.,1.,1.,90.,90.,120.])
        Binv = inv(B)
        rot = zeros((6, 3, 3))
        for i in range(len(perm)):       
            rot[i] = dot(B,dot(inv(perm[i]),Binv))
                
    if crystal_system == 6: # Hexagonal
        perm = permutations(crystal_system)
        B = tools.form_b_mat([1.,1.,1.,90.,90.,120.])
        Binv = inv(B)
        rot = zeros((12, 3, 3))
        for i in range(len(perm)):       
            rot[i] = dot(B,dot(inv(perm[i]),Binv))

    if crystal_system == 7: # Cubic
        rot = permutations(crystal_system)
        for i in range(len(rot)):       
            rot[i] = inv(rot[i])

    return rot
Ejemplo n.º 11
0
tilt_x = 0.0
tilt_y = 0.0
tilt_z = 0.0
wedge = 0.0
unit_cell = [4.04975, 4.04975, 4.04975, 90, 90, 90]
sgno = 225
U = n.array([
    -0.52880000, 0.78460000, 0.32380000, -0.51780000, 0.00400000, -0.85550000,
    -0.67250000, -0.62000000, 0.40410000
]).reshape(3, 3)
pos = [0.0, 0.0, 0.0]

hkl = n.array([1, 1, 1]) * 3

unit_cell = [4.04975, 4.04975, 4.04975, 90, 90, 90]
B = tools.form_b_mat(unit_cell)
Gc = n.dot(B, hkl)
Gw = n.dot(U, Gc)

wavedisp = 1e-3
sigma_limit = 2.

wavelength_0 = 0.4859292

wavelength = wavelength_0
tth = tools.tth2(Gw, wavelength)
(Omega, Eta) = tools.find_omega_wedge(Gw, tth, wedge)
omega_0 = Omega[1] * 180. / n.pi
Om = tools.form_omega_mat(Omega[1])
Gt = n.dot(Om, Gw)
(dety, detz) = detector.det_coor(Gt, n.cos(tth), wavelength, distance,