Esempio n. 1
0
def test_cubic_cslmats(l1):
        """
        Testing the CSL matrices generated using MATLAB with those
        generated using python code

        """
        # Define "ideal" cubic fcc lattice
        l_g_go = l1.l_g_go
        l_go_g = np.linalg.inv(l_g_go)

        cryst_ptgrp = l1.cryst_ptgrp

        # Load matlab generated CSL matrices
        mat_file = '../matlab_csls/432_CommonCSL.mat'
        matf = scipy.io.loadmat(mat_file)
        sig_rots = matf['Sigma_Rots']
        sig_type = 'common'

        # Load Python genererated CSL matrices
        pkl_file = ('../python_csls/' + l1.elem_type +
                    '_csl_' + sig_type + '_rotations' + '.pkl')
        jar1 = open(pkl_file, 'rb')
        sig_rots_p = pickle.load(jar1)

        sig_rots_m = {}
        for ct1 in range(np.size(sig_rots)):
                sig_num = sig_rots[0][ct1][0][0][0][0]
                rot_n = sig_rots[0][ct1][0][1]
                rot_d = sig_rots[0][ct1][0][2]
                sig_rots_m[str(sig_num)] = {}
                if rot_n.ndim == 3:
                        msz = np.shape(rot_n)[2]
                        n_mat = np.zeros((msz, 3, 3))
                        d_mat = np.zeros((msz, 3, 3))
                        for ct2 in range(msz):
                            n_mat[ct2, :, :] = rot_n[:, :, ct2]
                            d_mat[ct2, :, :] = rot_d[:, :, ct2]
                        sig_rots_m[str(sig_num)]['N'] = n_mat
                        sig_rots_m[str(sig_num)]['D'] = d_mat
                elif rot_n.ndim == 2:
                        msz = 1
                        n_mat = np.zeros((msz, 3, 3))
                        d_mat = np.zeros((msz, 3, 3))
                        n_mat[0, :, :] = rot_n
                        d_mat[0, :, :] = rot_d
                        sig_rots_m[str(sig_num)]['N'] = n_mat
                        sig_rots_m[str(sig_num)]['D'] = d_mat
                else:
                        raise Exception('Wrong Dimensions')

                sig_rots_m[str(sig_num)]['N'] = n_mat
                sig_rots_m[str(sig_num)]['D'] = d_mat

        sig_vals = sig_rots_m.keys()
        for ct1 in sig_vals:
                print ct1
                rot_np = sig_rots_p[str(ct1)]['N']
                rot_dp = sig_rots_p[str(ct1)]['D']

                rot_nm = sig_rots_m[str(ct1)]['N']
                rot_dm = sig_rots_m[str(ct1)]['D']

                if rot_nm.ndim == 3:
                        msz1 = np.shape(rot_np)[0]
                        msz2 = np.shape(rot_nm)[0]
                        if msz1 != msz2:
                                raise Exception('No Good')
                        
                        inds = []
                        for ct2 in range(msz1):
                                tn1 = rot_np[ct2, :, :]
                                td1 = rot_dp[ct2, :, :]
                                matp1 = tn1.astype(float) / td1.astype(float)
                                matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                                quat_p2 = tl.mat2quat(matp2)
                                disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)
                                tcheck = 0

                                for ct3 in range(msz2):
                                        tn2 = rot_nm[ct3, :, :]
                                        td2 = rot_dm[ct3, :, :]
                                        mat_m = tn2.astype(float) / td2.astype(float)
                                        quat_m = tl.mat2quat(mat_m)
                                        disquat_m= mis_fz.misorient_fz(quat_m, cryst_ptgrp)
                                        if quat.eq(disquat_p2, disquat_m, 1e-10):
                                                tcheck = 1
                                                inds.append(ct3)
                                                break
                                if (tcheck == 0):
                                        raise Exception('No Good')

                elif rot_nm.ndim == 2:
                        tn1 = rot_np[0, :, :]
                        td1 = rot_dp[0, :, :]
                        matp1 = tn1.astype(float) / td1.astype(float)
                        matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                        quat_p2 = tl.mat2quat(matp2)
                        disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)

                        tn2 = rot_nm[0, :, :]
                        td2 = rot_dm[0, :, :]
                        mat_m = tn2.astype(float) / td2.astype(float)
                        quat_m = tl.mat2quat(mat_m)
                        disquat_m = mis_fz.misorient_fz(quat_m, cryst_ptgrp)

                        # if mat_ops.eq(mat_m, matp2, 1e-10):
                        if quat.eq(disquat_p2, disquat_m, 1e-10):
                                print 'matp1 exists in mat_m'
                        # else:
                        #         raise Exception('No Good')
                else:
                        raise Exception('Wrong Dimensions')
Esempio n. 2
0
def compare_sig_rots(sig_rots_m1, sig_rots_p, l1):
    """
        """
    l_g_go = l1.l_g_go
    l_go_g = np.linalg.inv(l_g_go)

    cryst_ptgrp = csl_util.proper_ptgrp(l1.cryst_ptgrp)
    l1.cryst_ptgrp = cryst_ptgrp

    for ct1 in list(sig_rots_m1.keys()):
        rot_np = sig_rots_p[ct1]['N']
        rot_dp = sig_rots_p[ct1]['D']

        rot_nm = sig_rots_m1[ct1]['N']
        rot_dm = sig_rots_m1[ct1]['D']

        if rot_nm.ndim == 3:
            msz1 = np.shape(rot_np)[0]
            msz2 = np.shape(rot_nm)[0]

            if msz1 < msz2:
                raise Exception('No Good')
            if msz1 > msz2:
                print(('msz1= %d \t msz2 = %d \n' % (msz1, msz2)))

            inds = []
            for ct3 in range(msz2):
                tn2 = rot_nm[ct3, :, :]
                td2 = rot_dm[ct3, :, :]
                mat_m1 = tn2.astype(float) / td2.astype(float)
                mat_m2 = np.dot(np.dot(l_g_go, mat_m1), l_go_g)
                quat_m = tl.mat2quat(mat_m2)
                disquat_m = mis_fz.misorient_fz(quat_m, cryst_ptgrp)

                tcheck = 0

                for ct2 in range(msz1):
                    tn1 = rot_np[ct2, :, :]
                    td1 = rot_dp[ct2, :, :]
                    matp1 = tn1.astype(float) / td1.astype(float)
                    matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                    quat_p2 = tl.mat2quat(matp2)
                    disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)

                    if quat.eq(disquat_p2, disquat_m, 1e-10):
                        tcheck = 1
                        inds.append(ct3)
                        break
                if (tcheck == 0):
                    raise Exception('No Good')
                else:
                    print('matp1 exists in mat_m')

        elif rot_nm.ndim == 2:
            tn1 = rot_np[0, :, :]
            td1 = rot_dp[0, :, :]
            matp1 = tn1.astype(float) / td1.astype(float)
            matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
            quat_p2 = tl.mat2quat(matp2)
            disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)

            tn2 = rot_nm[0, :, :]
            td2 = rot_dm[0, :, :]
            mat_m1 = tn2.astype(float) / td2.astype(float)
            mat_m2 = np.dot(np.dot(l_g_go, mat_m1), l_go_g)
            quat_m = tl.mat2quat(mat_m2)
            disquat_m = mis_fz.misorient_fz(quat_m, cryst_ptgrp)

            # if mat_ops.eq(mat_m, matp2, 1e-10):
            if quat.eq(disquat_p2, disquat_m, 1e-10):
                print('matp1 exists in mat_m')
            else:
                raise Exception('No Good')
        else:
            raise Exception('Wrong Dimensions')
Esempio n. 3
0
def test_cubic_cslmats(l1):
        """
        Testing the CSL matrices generated using MATLAB with those
        generated using python code

        """
        # Define "ideal" cubic fcc lattice
        l_g_go = l1.l_g_go
        l_go_g = np.linalg.inv(l_g_go)

        cryst_ptgrp = l1.cryst_ptgrp

        # Load matlab generated CSL matrices
        mat_file = '../matlab_csls/432_CommonCSL.mat'
        matf = scipy.io.loadmat(mat_file)
        sig_rots = matf['Sigma_Rots']
        sig_type = 'common'

        # Load Python genererated CSL matrices
        pkl_file = ('../python_csls/' + l1.elem_type +
                    '_csl_' + sig_type + '_rotations' + '.pkl')
        jar1 = open(pkl_file, 'rb')
        sig_rots_p = pickle.load(jar1)

        sig_rots_m = {}
        for ct1 in range(np.size(sig_rots)):
                sig_num = sig_rots[0][ct1][0][0][0][0]
                rot_n = sig_rots[0][ct1][0][1]
                rot_d = sig_rots[0][ct1][0][2]
                sig_rots_m[str(sig_num)] = {}
                if rot_n.ndim == 3:
                        msz = np.shape(rot_n)[2]
                        n_mat = np.zeros((msz, 3, 3))
                        d_mat = np.zeros((msz, 3, 3))
                        for ct2 in range(msz):
                            n_mat[ct2, :, :] = rot_n[:, :, ct2]
                            d_mat[ct2, :, :] = rot_d[:, :, ct2]
                        sig_rots_m[str(sig_num)]['N'] = n_mat
                        sig_rots_m[str(sig_num)]['D'] = d_mat
                elif rot_n.ndim == 2:
                        msz = 1
                        n_mat = np.zeros((msz, 3, 3))
                        d_mat = np.zeros((msz, 3, 3))
                        n_mat[0, :, :] = rot_n
                        d_mat[0, :, :] = rot_d
                        sig_rots_m[str(sig_num)]['N'] = n_mat
                        sig_rots_m[str(sig_num)]['D'] = d_mat
                else:
                        raise Exception('Wrong Dimensions')

                sig_rots_m[str(sig_num)]['N'] = n_mat
                sig_rots_m[str(sig_num)]['D'] = d_mat

        sig_vals = list(sig_rots_m.keys())
        for ct1 in sig_vals:
                print(ct1)
                rot_np = sig_rots_p[str(ct1)]['N']
                rot_dp = sig_rots_p[str(ct1)]['D']

                rot_nm = sig_rots_m[str(ct1)]['N']
                rot_dm = sig_rots_m[str(ct1)]['D']

                if rot_nm.ndim == 3:
                        msz1 = np.shape(rot_np)[0]
                        msz2 = np.shape(rot_nm)[0]
                        if msz1 != msz2:
                                raise Exception('No Good')
                        
                        inds = []
                        for ct2 in range(msz1):
                                tn1 = rot_np[ct2, :, :]
                                td1 = rot_dp[ct2, :, :]
                                matp1 = tn1.astype(float) / td1.astype(float)
                                matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                                quat_p2 = tl.mat2quat(matp2)
                                disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)
                                tcheck = 0

                                for ct3 in range(msz2):
                                        tn2 = rot_nm[ct3, :, :]
                                        td2 = rot_dm[ct3, :, :]
                                        mat_m = tn2.astype(float) / td2.astype(float)
                                        quat_m = tl.mat2quat(mat_m)
                                        disquat_m= mis_fz.misorient_fz(quat_m, cryst_ptgrp)
                                        if quat.eq(disquat_p2, disquat_m, 1e-10):
                                                tcheck = 1
                                                inds.append(ct3)
                                                break
                                if (tcheck == 0):
                                        raise Exception('No Good')

                elif rot_nm.ndim == 2:
                        tn1 = rot_np[0, :, :]
                        td1 = rot_dp[0, :, :]
                        matp1 = tn1.astype(float) / td1.astype(float)
                        matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                        quat_p2 = tl.mat2quat(matp2)
                        disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)

                        tn2 = rot_nm[0, :, :]
                        td2 = rot_dm[0, :, :]
                        mat_m = tn2.astype(float) / td2.astype(float)
                        quat_m = tl.mat2quat(mat_m)
                        disquat_m = mis_fz.misorient_fz(quat_m, cryst_ptgrp)

                        # if mat_ops.eq(mat_m, matp2, 1e-10):
                        if quat.eq(disquat_p2, disquat_m, 1e-10):
                                print('matp1 exists in mat_m')
                        # else:
                        #         raise Exception('No Good')
                else:
                        raise Exception('Wrong Dimensions')
Esempio n. 4
0
def generate_symm_quats(cryst_ptgrp, tol=1e-10):
    """
    Give crystallographic point group, this function generates all the symmetry
    operations (as quaternions) that belong to the point group
    using 'generators'

    Parameters
    -----------------
    cryst_ptgrp: string
        Crystallogrphic point group in Schoenflies notation

    tol: float
        The tolerance used to check if two matrices are the same

    Returns
    ------------
    symm_quat: quaternion array
        Size: n x 5 \v
        Symmetry operations as matrices for the corresponding point group
    """

    prop_grps = ['C1', 'C2', 'C3', 'C4', 'C6', 'D2', 'D3', 'D4', 'D6',
                 'T', 'O']
    laue_grps = ['Ci', 'C2h', 'C3i', 'C4h', 'C6h', 'D2h', 'D3d', 'D4h', 'D6h', 'D8h',
                 'Th', 'Oh']
    noncentro_grps = ['Cs', 'S4', 'S6', 'C2v', 'C3v', 'C4v', 'C6v', 'D2d', 'D3h', 'Td']

    # if cryst_ptgrp in prop_grps:
    #     rot_type = 'proper'
    # elif cryst_ptgrp in laue_grps:
    #     rot_type = 'improper'
    # else:
    #     raise Exception('Wrong Input for crystal point group')

    if cryst_ptgrp in prop_grps:

        if cryst_ptgrp == 'C1':
            n = 1
            gsz = 1
            order_ptgrp = n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'C2':
            n = 2
            gsz = 2
            order_ptgrp = n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'C3':
            n = 3
            gsz = 2
            order_ptgrp = n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'C4':
            n = 4
            gsz = 2
            order_ptgrp = n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'C6':
            n = 6
            gsz = 2
            order_ptgrp = n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D2':
            n = 2
            gsz = 3
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D3':
            n = 3
            gsz = 3
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D4':
            n = 4
            gsz = 3
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D6':
            n = 6
            gsz = 3
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'T':
            gsz = 3
            order_ptgrp = 12
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/2, 1]))
            generators[:, 2] = trans.axang2quat(
                np.array([1, 1, 1, 2*np.pi/3, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'O':
            gsz = 3
            order_ptgrp = 24
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, np.pi/2, 1]))
            generators[:, 2] = trans.axang2quat(
                np.array([1, 0, 0, np.pi/2, 1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

    if cryst_ptgrp in laue_grps:

        if cryst_ptgrp == 'Ci':
            n = 1
            gsz = 2
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'C2h':
            n = 2
            gsz = 3
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'C3i':
            n = 3
            gsz = 3
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'C4h':
            n = 4
            gsz = 3
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'C6h':
            n = 6
            gsz = 3
            order_ptgrp = 2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D2h':
            n = 2
            gsz = 4
            order_ptgrp = 2*2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))
            generators[:, 3] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D3d':
            n = 3
            gsz = 4
            order_ptgrp = 2*2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))
            generators[:, 3] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D4h':
            n = 4
            gsz = 4
            order_ptgrp = 2*2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))
            generators[:, 3] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D6h':
            n = 6
            gsz = 4
            order_ptgrp = 2*2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))
            generators[:, 3] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'D8h':
            n = 8
            gsz = 4
            order_ptgrp = 2*2*n
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/n, 1]))
            generators[:, 2] = trans.axang2quat(np.array([1, 0, 0, np.pi, 1]))
            generators[:, 3] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'Td':
            gsz = 4
            order_ptgrp = 2*12
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, 2*np.pi/2, 1]))
            generators[:, 2] = trans.axang2quat(
                np.array([1, 1, 1, 2*np.pi/3, 1]))
            generators[:, 3] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

        elif cryst_ptgrp == 'Oh':
            gsz = 4
            order_ptgrp = 2*24
            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            generators[:, 1] = trans.axang2quat(
                np.array([0, 0, 1, np.pi/2, 1]))
            generators[:, 2] = trans.axang2quat(
                np.array([1, 0, 0, np.pi/2, 1]))
            generators[:, 3] = trans.axang2quat(np.array([0, 0, 1, 0, -1]))

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators


    if cryst_ptgrp in noncentro_grps:
        if cryst_ptgrp == 'Cs':
            n = 1
            gsz = 2
            order_ptgrp = 2*n
            # Generators

            # Generators
            generators = quat.Quaternion(np.zeros((5, gsz)))
            generators[:, 0] = trans.axang2quat(np.array([0, 0, 1, 0, 1]))
            t_q1 = trans.axang2quat(np.array([0, 0, 1, 0, -1]))
            t_q2 = trans.axang2quat(np.array([0, 0, 1, np.pi, 1]))
            t_mat = quat.mtimes(t_q1, t_q2)
            generators[:, 1] = t_mat

            # Symmetry Operations
            symm_quat = quat.Quaternion(np.zeros([5, order_ptgrp]))
            symm_quat[:, :gsz] = generators

    count1 = 1
    numops = gsz-1

    while numops < order_ptgrp-1:
        initsize = numops
        for ct1 in np.arange(count1, initsize+1):
            t1 = symm_quat[:, ct1]
            t2 = symm_quat[:, count1]
            tM1 = quat.mtimes(t1, t2)
            tcheck = 0
            ct2 = np.arange(0, numops+1)
            if np.any(quat.eq(tM1, symm_quat[:, ct2], tol)):
                tcheck = 1

            if tcheck == 0:
                symm_quat[:, numops+1] = tM1
                numops += 1
        if numops == initsize:
            count1 += 1

    symm_quat = quat.antipodal(symm_quat)

    # print quat.display(symm_quat)
    return symm_quat
Esempio n. 5
0
def test_tet_common_cslmats(l1):
        """
        """
        # Define "ideal" cubic fcc lattice
        l_g_go = l1.l_g_go
        l_go_g = np.linalg.inv(l_g_go)

        cryst_ptgrp = l1.cryst_ptgrp
        sig_type = 'common'

        # Load prior lit cls
        mat_file = '../prior_lit_csls/'+ l1.elem_type + \
                   '_lit_csl_' + sig_type + '_rotations' + '.pkl'
        jar1 = open(mat_file, 'rb')
        csl_rots = pickle.load(jar1)
        
        if csl_rots['type'] == 'matrices':
                csl_rots_m = csl_rots['rots']
                k1 = list(csl_rots_m.keys())
                sig_inds = {}
                for ct1 in k1:                        
                        if ct1[-1] in string.ascii_lowercase:
                                tstr1 = ct1[0:-1]
                        else:
                                tstr1 = ct1
                        if tstr1 in list(sig_inds.keys()):
                                sig_inds[tstr1] += 1
                        else:
                                sig_inds[tstr1] = 1

                sig_rots_m = {}
                sig_inds1 = {}
                for ct1 in list(sig_inds.keys()):
                        sig_rots_m[ct1] = np.zeros((sig_inds[ct1], 3, 3))
                for ct1 in k1:
                        if ct1[-1] in string.ascii_lowercase:
                                tstr1 = ct1[0:-1]
                        else:
                                tstr1 = ct1

                        if tstr1 in list(sig_inds1.keys()):
                                sig_inds1[tstr1] += 1
                                sig_rots_m[tstr1][sig_inds1[tstr1], :, :] = csl_rots_m[ct1]
                        else:
                                sig_inds1[tstr1] = 0
                                sig_rots_m[tstr1][sig_inds1[tstr1], :, :] = csl_rots_m[ct1]

                sig_rots_m1 = {}
                for ct1 in list(sig_rots_m.keys()):
                        sig_rots_m1[ct1] ={}
                        sig_rots_m1[ct1]['N'] = sig_rots_m[ct1]
                        sig_rots_m1[ct1]['D'] = \
                                                float(ct1)*np.ones(np.shape(sig_rots_m[ct1]))
                        
                        
        # Load Python genererated CSL matrices
        pkl_file = '../python_csls/'+l1.elem_type + \
                   '_csl_' + sig_type + '_rotations' + '.pkl'
        jar2 = open(pkl_file, 'rb')
        sig_rots_p = pickle.load(jar2)

        for ct1 in list(sig_rots_m1.keys()):
                rot_np = sig_rots_p[ct1]['N']
                rot_dp = sig_rots_p[ct1]['D']

                rot_nm = sig_rots_m1[ct1]['N']
                rot_dm = sig_rots_m1[ct1]['D']

                if rot_nm.ndim == 3:
                        msz1 = np.shape(rot_np)[0]
                        msz2 = np.shape(rot_nm)[0]
                        if msz1 != msz2:
                                raise Exception('No Good')

                        inds = []
                        for ct2 in range(msz1):
                                tn1 = rot_np[ct2, :, :]
                                td1 = rot_dp[ct2, :, :]
                                matp1 = tn1.astype(float) / td1.astype(float)
                                matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                                quat_p2 = trans.mat2quat(matp2)
                                disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)
                                tcheck = 0

                                for ct3 in range(msz2):
                                        tn2 = rot_nm[ct3, :, :]
                                        td2 = rot_dm[ct3, :, :]
                                        mat_m = tn2.astype(float) / td2.astype(float)
                                        quat_m = trans.mat2quat(mat_m)
                                        disquat_m= mis_fz.misorient_fz(quat_m, cryst_ptgrp)
                                        if quat.eq(disquat_p2, disquat_m, 1e-10):
                                                tcheck = 1
                                                inds.append(ct3)
                                                break
                                if (tcheck == 0):
                                        raise Exception('No Good')
                                else:
                                        print('matp1 exists in mat_m')

                elif rot_nm.ndim == 2:
                        tn1 = rot_np[0, :, :]
                        td1 = rot_dp[0, :, :]
                        matp1 = tn1.astype(float) / td1.astype(float)
                        matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                        quat_p2 = trans.mat2quat(matp2)
                        disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)

                        tn2 = rot_nm[0, :, :]
                        td2 = rot_dm[0, :, :]
                        mat_m = tn2.astype(float) / td2.astype(float)
                        quat_m = trans.mat2quat(mat_m)
                        disquat_m = mis_fz.misorient_fz(quat_m, cryst_ptgrp)

                        # if mat_ops.eq(mat_m, matp2, 1e-10):
                        if quat.eq(disquat_p2, disquat_m, 1e-10):
                                print('matp1 exists in mat_m')
                        else:
                                raise Exception('No Good')
                else:
                        raise Exception('Wrong Dimensions')
Esempio n. 6
0
def test_tet_common_cslmats(l1):
        """
        """
        # Define "ideal" cubic fcc lattice
        l_g_go = l1.l_g_go
        l_go_g = np.linalg.inv(l_g_go)

        cryst_ptgrp = l1.cryst_ptgrp
        sig_type = 'common'

        # Load prior lit cls
        mat_file = '../prior_lit_csls/'+ l1.elem_type + \
                   '_lit_csl_' + sig_type + '_rotations' + '.pkl'
        jar1 = open(mat_file, 'rb')
        csl_rots = pickle.load(jar1)
        
        if csl_rots['type'] == 'matrices':
                csl_rots_m = csl_rots['rots']
                k1 = csl_rots_m.keys()
                sig_inds = {}
                for ct1 in k1:                        
                        if ct1[-1] in string.ascii_lowercase:
                                tstr1 = ct1[0:-1]
                        else:
                                tstr1 = ct1
                        if tstr1 in sig_inds.keys():
                                sig_inds[tstr1] += 1
                        else:
                                sig_inds[tstr1] = 1

                sig_rots_m = {}
                sig_inds1 = {}
                for ct1 in sig_inds.keys():
                        sig_rots_m[ct1] = np.zeros((sig_inds[ct1], 3, 3))
                for ct1 in k1:
                        if ct1[-1] in string.ascii_lowercase:
                                tstr1 = ct1[0:-1]
                        else:
                                tstr1 = ct1

                        if tstr1 in sig_inds1.keys():
                                sig_inds1[tstr1] += 1
                                sig_rots_m[tstr1][sig_inds1[tstr1], :, :] = csl_rots_m[ct1]
                        else:
                                sig_inds1[tstr1] = 0
                                sig_rots_m[tstr1][sig_inds1[tstr1], :, :] = csl_rots_m[ct1]

                sig_rots_m1 = {}
                for ct1 in sig_rots_m.keys():
                        sig_rots_m1[ct1] ={}
                        sig_rots_m1[ct1]['N'] = sig_rots_m[ct1]
                        sig_rots_m1[ct1]['D'] = \
                                                float(ct1)*np.ones(np.shape(sig_rots_m[ct1]))
                        
                        
        # Load Python genererated CSL matrices
        pkl_file = '../python_csls/'+l1.elem_type + \
                   '_csl_' + sig_type + '_rotations' + '.pkl'
        jar2 = open(pkl_file, 'rb')
        sig_rots_p = pickle.load(jar2)

        for ct1 in sig_rots_m1.keys():
                rot_np = sig_rots_p[ct1]['N']
                rot_dp = sig_rots_p[ct1]['D']

                rot_nm = sig_rots_m1[ct1]['N']
                rot_dm = sig_rots_m1[ct1]['D']

                if rot_nm.ndim == 3:
                        msz1 = np.shape(rot_np)[0]
                        msz2 = np.shape(rot_nm)[0]
                        if msz1 != msz2:
                                raise Exception('No Good')

                        inds = []
                        for ct2 in range(msz1):
                                tn1 = rot_np[ct2, :, :]
                                td1 = rot_dp[ct2, :, :]
                                matp1 = tn1.astype(float) / td1.astype(float)
                                matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                                quat_p2 = trans.mat2quat(matp2)
                                disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)
                                tcheck = 0

                                for ct3 in range(msz2):
                                        tn2 = rot_nm[ct3, :, :]
                                        td2 = rot_dm[ct3, :, :]
                                        mat_m = tn2.astype(float) / td2.astype(float)
                                        quat_m = trans.mat2quat(mat_m)
                                        disquat_m= mis_fz.misorient_fz(quat_m, cryst_ptgrp)
                                        if quat.eq(disquat_p2, disquat_m, 1e-10):
                                                tcheck = 1
                                                inds.append(ct3)
                                                break
                                if (tcheck == 0):
                                        raise Exception('No Good')
                                else:
                                        print 'matp1 exists in mat_m'

                elif rot_nm.ndim == 2:
                        tn1 = rot_np[0, :, :]
                        td1 = rot_dp[0, :, :]
                        matp1 = tn1.astype(float) / td1.astype(float)
                        matp2 = np.dot(np.dot(l_g_go, matp1), l_go_g)
                        quat_p2 = trans.mat2quat(matp2)
                        disquat_p2 = mis_fz.misorient_fz(quat_p2, cryst_ptgrp)

                        tn2 = rot_nm[0, :, :]
                        td2 = rot_dm[0, :, :]
                        mat_m = tn2.astype(float) / td2.astype(float)
                        quat_m = trans.mat2quat(mat_m)
                        disquat_m = mis_fz.misorient_fz(quat_m, cryst_ptgrp)

                        # if mat_ops.eq(mat_m, matp2, 1e-10):
                        if quat.eq(disquat_p2, disquat_m, 1e-10):
                                print 'matp1 exists in mat_m'
                        else:
                                raise Exception('No Good')
                else:
                        raise Exception('Wrong Dimensions')
Esempio n. 7
0
# print quat.display(quat_mult);

# ### Testing mtimes
# q1 = rand_quat(5); q2 = rand_quat(1);
# quat_mult = quat.mtimes(q1, q2);
# print quat.display(quat_mult);

# ### Testing mtimes
# q1 = rand_quat(1); q2 = rand_quat(5);
# quat_mult = quat.mtimes(q1, q2);
# print quat.display(quat_mult);

### Testing eq
q1 = rand_quat(5)
q2 = rand_quat(1)
print quat.eq(q1, q2)

### Testing eq
q1 = rand_quat(1)
q2 = rand_quat(5)
q2[:, 2] = q1
print quat.eq(q1, q2)

### Testing eq
q1 = rand_quat(5)
q2 = rand_quat(5)
q2[:, 2] = q1[:, 2]
q2[:, 4] = q1[:, 4]
q2[4, 4] = -1
print quat.eq(q1, q2)
Esempio n. 8
0
# print quat.display(quat_mult);

# ### Testing mtimes
# q1 = rand_quat(5); q2 = rand_quat(1);
# quat_mult = quat.mtimes(q1, q2);
# print quat.display(quat_mult);

# ### Testing mtimes
# q1 = rand_quat(1); q2 = rand_quat(5);
# quat_mult = quat.mtimes(q1, q2);
# print quat.display(quat_mult);


### Testing eq
q1 = rand_quat(5); q2 = rand_quat(1);
print quat.eq(q1, q2);

### Testing eq
q1 = rand_quat(1); q2 = rand_quat(5);
q2[:, 2] = q1;
print quat.eq(q1, q2);


### Testing eq
q1 = rand_quat(5); q2 = rand_quat(5);
q2[:, 2] = q1[:, 2]; q2[:, 4] = q1[:, 4]; q2[4,4] = -1;
print quat.eq(q1, q2);