コード例 #1
0
ファイル: pick_uni_mis.py プロジェクト: spatala/GB_Lammps
def pick_uni_mis(lat_type, n=70):
    elem = GBl.Lattice(lat_type)
    l_g_go = elem.l_p_po
    l_go_g = np.linalg.inv(l_g_go)
    gb_dir = os.path.dirname(inspect.getfile(GBpy))
    pkl_path =  gb_dir + '/pkl_files/symm_mats_O.pkl'
    symm_O = pickle.load(open(pkl_path))
    symm_O_inv = np.linalg.inv(symm_O)
    mis_g, id = extract_mis(99, gb_dir)
    mis_go = np.tensordot(np.tensordot(l_g_go, mis_g.transpose(1, 2, 0), 1).transpose(2, 0, 1), l_go_g, 1)
    mis_go_inv = np.linalg.inv(mis_go)

    num = len(symm_O)*len(symm_O_inv)
    mis_go_symm1 = np.tensordot(np.tensordot(symm_O_inv, mis_go.transpose(1, 2, 0), 1).transpose(3, 0, 1, 2), symm_O.transpose(1, 2, 0), 1).transpose(0, 1, 4, 2, 3)
    mis_go_symm2 = np.tensordot(np.tensordot(symm_O_inv, mis_go_inv.transpose(1, 2, 0), 1).transpose(3, 0, 1, 2), symm_O.transpose(1, 2, 0), 1).transpose(0, 1, 4, 2, 3)
    mis_go_symm = np.concatenate((mis_go_symm1, mis_go_symm2))
    mis_go_symm = mis_go_symm.reshape(len(mis_go_symm)*num, 3, 3)
    id_attr3 = np.tile(np.arange(1, num+1, 1).reshape(num, 1), (len(id), 1))
    id_attr3 = np.vstack([id_attr3, -id_attr3])
    id_symm = np.tile(np.repeat(id, num, axis=0), (2, 1))
    id_symm = np.hstack([id_symm, id_attr3])
    quat_go_symm = GBq.mat2quat(mis_go_symm)
    quat_go_symm_fil = GBq.antipodal(quat_go_symm)
    ### Add code for pi rotations
    quat_t = quat_go_symm_fil.transpose()
    quat_t_unq, ind = GBt.unique_rows_tol(quat_t, tol=1e-06, return_index=True)

    id_unq = id_symm[ind]

    ind_id_sort = np.argsort(id_unq[:, 0])
    id_sort = id_unq[ind_id_sort]

    quat_sort = quat_t_unq[ind_id_sort].transpose()
    ### sort again according to sig vals
    mis_c = mf.sphr2cube_3d(quat_sort)

    ### testing
    # mis_r = mf.cube2sphr_3d(mis_c)

    grid, gce = make_grid(n)
    mis_gr_c, id_g = mis_in_grid(mis_c, id_sort, grid, gce)
    id_g_unq = GBt.unique_rows_tol(id_g[:, [0, 1]], 1e-06)
    ind_id_unq_sort = np.argsort(id_g_unq[:, 0]); id_g_unq = id_g_unq[ind_id_unq_sort]
    mis_pick_ind = mf.set_int_ind(id, id_g_unq)
    mis_pick = mis_g[mis_pick_ind]
    print '\n', len(mis_pick), '\n', id_g_unq
    # mis_gr_quat = mf.cube2sphr_3d(mis_gr_c)
    # mis_gr_go = GBq.quat2mat(mis_gr_quat)
    # mis_gr = np.tensordot(np.tensordot(l_go_g, mis_gr_go.transpose(1, 2, 0), 1).transpose(2, 0, 1), l_g_go, 1)
    # ### convert to g frame
    # ### pick in fz, check the code !!
    # dum = 0
    return [mis_pick, mis_pick_ind]
コード例 #2
0
ファイル: pick_uni_bpn.py プロジェクト: spatala/GB_Lammps
def gen_hkl(bound, mt_tensor):

    m = 1.0 * bound

    h = math.ceil(math.sqrt(m / mt_tensor[0][0]))
    k = math.ceil(math.sqrt(m / mt_tensor[1][1]))
    l = math.ceil(math.sqrt(m / mt_tensor[2][2]))

    print h, k, l, "\n"

    x_csl = np.arange(-h, h + 1, 1.0)
    y_csl = np.arange(-k, k + 1, 1.0)
    z_csl = np.arange(-l, l + 1, 1.0)

    num_mi = np.size(x_csl) * np.size(y_csl) * np.size(z_csl)
    xx_csl, yy_csl, zz_csl = np.meshgrid(x_csl, y_csl, z_csl, indexing="xy")
    xx_csl, yy_csl, zz_csl = xx_csl.reshape(1, num_mi)[0], yy_csl.reshape(1, num_mi)[0], zz_csl.reshape(1, num_mi)[0]
    mil_ind = np.column_stack([xx_csl, yy_csl, zz_csl])

    ind = np.where((mil_ind[:, 0] == 0) & (mil_ind[:, 1] == 0) & (mil_ind[:, 2] == 0))[0][0]
    ### deleting (0 0 0)
    mil_ind = np.delete(mil_ind, ind, 0)
    ### finding the unique miller indices
    mil_ind = GBim.int_finder(mil_ind, tol=1e-06, order="rows")
    mil_ind_csl = GBt.unique_rows_tol(mil_ind, tol=1e-06)

    ### Antipodal symmetry (h k l) ~ (-h -k -l)
    return mil_ind_csl
コード例 #3
0
ファイル: pick_uni_bpn.py プロジェクト: spatala/GB_Lammps
def grid(gs):

    g = gs + 1
    beta = math.sqrt(np.pi / 6)
    num = 300

    h_x = np.linspace(-beta, beta, g)
    h_y = np.linspace(-beta, beta, num)
    hl = np.transpose([np.tile(h_x, len(h_y)), np.repeat(h_y, len(h_x))])
    h_z = np.zeros(len(hl))
    h_z.fill(beta)
    hln = np.column_stack((hl[:, 0], hl[:, 1], h_z))
    hln = np.concatenate((hln, np.column_stack((hl[:, 0], hl[:, 1], -h_z))))
    hln = np.concatenate((hln, np.column_stack((hl[:, 0], h_z, hl[:, 1]))))
    hln = np.concatenate((hln, np.column_stack((hl[:, 0], -h_z, hl[:, 1]))))
    hln = np.concatenate((hln, np.column_stack((h_z, hl[:, 0], hl[:, 1]))))
    hln = np.concatenate((hln, np.column_stack((-h_z, hl[:, 0], hl[:, 1]))))

    v_x = np.linspace(-beta, beta, num)
    v_y = np.linspace(-beta, beta, g)
    vl = np.transpose([np.tile(v_x, len(v_y)), np.repeat(v_y, len(v_x))])
    vln = np.column_stack((vl[:, 0], vl[:, 1], h_z))
    vln = np.concatenate((vln, np.column_stack((vl[:, 0], vl[:, 1], -h_z))))
    vln = np.concatenate((vln, np.column_stack((vl[:, 0], h_z, vl[:, 1]))))
    vln = np.concatenate((vln, np.column_stack((vl[:, 0], -h_z, vl[:, 1]))))
    vln = np.concatenate((vln, np.column_stack((h_z, vl[:, 0], vl[:, 1]))))
    vln = np.concatenate((vln, np.column_stack((-h_z, vl[:, 0], vl[:, 1]))))

    grid_lines = np.concatenate((hln, vln))
    grid_lines_sphr = GBt.unique_rows_tol(mf.cube2sphr_2d(grid_lines), tol=1e-06)
    return grid_lines_sphr
コード例 #4
0
ファイル: pick_uni_bpn.py プロジェクト: spatala/GB_Lammps
def fz2sphr(bpn, bp_symm_grp, symm_grp_ax):
    gb_dir = os.path.dirname(inspect.getfile(GBpy))
    pkl_path = gb_dir + "/pkl_files/"

    if bp_symm_grp == "C_s":
        file_name = "symm_mats_Cs.pkl"
        file_path = pkl_path + file_name

    elif bp_symm_grp == "C_2h":
        file_name = "symm_mats_C2h.pkl"
        file_path = pkl_path + file_name

    elif bp_symm_grp == "D_3d":
        file_name = "symm_mats_D3d.pkl"
        file_path = pkl_path + file_name

    elif bp_symm_grp == "D_2h":
        file_name = "symm_mats_D2h.pkl"
        file_path = pkl_path + file_name

    elif bp_symm_grp == "D_4h":
        file_name = "symm_mats_D4h.pkl"
        file_path = pkl_path + file_name

    elif bp_symm_grp == "D_6h":
        file_name = "symm_mats_D6h.pkl"
        file_path = pkl_path + file_name

    elif bp_symm_grp == "D_8h":
        file_name = "symm_mats_D8h.pkl"
        file_path = pkl_path + file_name

    elif bp_symm_grp == "O_h":
        file_name = "symm_mats_Oh.pkl"
        file_path = pkl_path + file_name

    rot_mat = np.linalg.inv(symm_grp_ax)
    bpn_rot = np.dot(rot_mat, bpn.transpose()).transpose()
    symm_mat = pickle.load(open(file_path, "rb"))
    symm_bpn_rot_gop1 = np.tensordot(symm_mat, bpn_rot.transpose(), 1).transpose((1, 2, 0))
    symm_bpn_go1 = np.tensordot(np.linalg.inv(rot_mat), symm_bpn_rot_gop1, 1).transpose(2, 1, 0)

    dim1, dim2, dim3 = np.shape(symm_bpn_go1)
    symm_bpn_go1 = np.reshape(symm_bpn_go1, ((dim1 * dim2), dim3))
    symm_bpn_go1_unq = GBt.unique_rows_tol(symm_bpn_go1, tol=1e-06)
    return symm_bpn_go1_unq
コード例 #5
0
ファイル: pick_uni_bpn.py プロジェクト: spatala/GB_Lammps
def est_bound(bound, mt_rcsl_go, l_rcsl_go, sig_mis_go, num):
    dum_bpn = np.array([[0, 0, 1]])
    _, bp_symm_grp, _ = fpf.five_param_fz(sig_mis_go, dum_bpn)
    cube_grid, gs = make_grid(num, bp_symm_grp)
    req_bpn = 6 * gs * gs
    flag = True
    while flag:
        mil_ind_csl = gen_hkl(bound, mt_rcsl_go)
        ### Converting the miller indices to normals in po frame
        bpn_go = np.dot(l_rcsl_go, mil_ind_csl.transpose()).transpose()
        ### Finding the boundary plane normals in the FZ using five_param_fz
        bp_fz_norms_go1, bp_symm_grp, symm_grp_ax = fpf.five_param_fz(sig_mis_go, bpn_go)
        bp_fz_norms_go1_unq = GBt.unique_rows_tol(bp_fz_norms_go1, tol=1e-06)

        num_bpn_fz = len(bp_fz_norms_go1_unq)
        est_para = 20
        if bp_symm_grp == "C_s":
            num_bpn_sp = 2 * num_bpn_fz
        elif bp_symm_grp == "C_2h":
            est_para = 50
            num_bpn_sp = 4 * num_bpn_fz
        elif bp_symm_grp == "D_3d":
            num_bpn_sp = 12 * num_bpn_fz
        elif bp_symm_grp == "D_2h":
            num_bpn_sp = 8 * num_bpn_fz
            est_para = 200
        elif bp_symm_grp == "D_4h":
            num_bpn_sp = 16 * num_bpn_fz
        elif bp_symm_grp == "D_6h":
            num_bpn_sp = 24 * num_bpn_fz
        elif bp_symm_grp == "D_8h":
            num_bpn_sp = 32 * num_bpn_fz
        elif bp_symm_grp == "O_h":
            num_bpn_sp = 48 * num_bpn_fz

        # para_1 = len(bp_fz_norms_go1)/num_bpn_fz
        if num_bpn_sp >= est_para * req_bpn:
            flag = False
        else:
            bound = bound * 2
    print bound
    return bp_fz_norms_go1_unq, bp_symm_grp, symm_grp_ax, cube_grid, gs
コード例 #6
0
def gen_miller_ind(mesh_size):
    """
    Returns an array of unique miller indices

    Parameters
    ----------
    mesh_size: size of the mesh grid to create the indices array
    * positive integer

    Returns
    -------
    mil_ind: array of unique miller indices stored row wise
    * numpy array of size (m x 3)
    * m is the number of unique indices created for a given mesh_size

    See Also
    --------
    * GBpy.integer_manipulations.int_finder
    * GBpy.tools.unique_rows_tol
    """

    ### Creating an array of boundary plane miller indices
    r = mesh_size
    x_csl = np.arange(-r, r+1, 1.0)
    y_csl = np.arange(-r, r+1, 1.0)
    z_csl = np.arange(-r, r+1, 1.0)
    num_mi = np.size(x_csl)*np.size(y_csl)*np.size(z_csl)
    xx_csl, yy_csl, zz_csl = np.meshgrid(x_csl, y_csl, z_csl, indexing='xy')
    xx_csl, yy_csl, zz_csl = xx_csl.reshape(1, num_mi)[0], yy_csl.reshape(1, num_mi)[0], zz_csl.reshape(1, num_mi)[0]
    mil_ind = np.column_stack([xx_csl, yy_csl, zz_csl])
    ind = np.where((mil_ind[:, 0] == 0) & (mil_ind[:, 1] == 0) & (mil_ind[:, 2] == 0))[0][0]
    ### deleting (0 0 0)
    mil_ind = np.delete(mil_ind, ind, 0)
    ### finding the unique miller indices
    mil_ind = GBim.int_finder(mil_ind, tol=1e-06, order='rows')
    mil_ind = GBt.unique_rows_tol(mil_ind)
    # Try to remove (-h -k -l) for all (h k l) !!!
    return mil_ind
コード例 #7
0
ファイル: plots.py プロジェクト: spatala/GB_Lammps
def plots(mesh_size, sigma_val, n, lat_type):

    ####################################################################################################################
    ### Creating an array of boundary plane miller indices in CSL lattice
    mil_ind_csl = gen_miller_ind(mesh_size)

    ####################################################################################################################
    ### Creating an instance of lattice class
    elem = GBl.Lattice(lat_type)
    ### Getting the primitive lattice in orthogonal frame
    l_g_go = elem.l_g_go
    ### Extracting the sigma misorientation from the pickle file
    ### Misorientation is in the primitive frame of associated lattice
    gb_dir = os.path.dirname(inspect.getfile(GBpy))
    pkl_path =  gb_dir + '/pkl_files/cF_Id_csl_common_rotations.pkl'
    pkl_content = pickle.load(open(pkl_path))
    sig_mis_N = pkl_content[str(sigma_val)]['N'][0]
    sig_mis_D = pkl_content[str(sigma_val)]['D'][0]
    sig_mis_g = sig_mis_N/sig_mis_D
    ### Converting the misorientation to orthogonal frame/superlattice of the crystal
    ### Done using similarity transformation
    sig_mis_go = np.dot(np.dot(l_g_go, sig_mis_g), np.linalg.inv(l_g_go)).reshape(1,3,3)[0]
    ### Getting the csl basis in primitive frame
    l_csl_g, l_dsc_g = GBfcd.find_csl_dsc(l_g_go, sig_mis_g)
    ### Converting the csl basis to orthogonal frame
    l_csl_go = np.dot(l_g_go, l_csl_g)
    ### reciprocal csl basis in po frame
    l_rcsl_go = GBfcd.reciprocal_mat(l_csl_go)
    ### Converting the miller indices to normals in po frame
    bpn_go = np.dot(l_rcsl_go, mil_ind_csl.transpose()).transpose()

    ####################################################################################################################
    ### Finding the boundary plane normals in the FZ using five_param_fz
    bp_fz_norms_go1, bp_symm_grp, symm_grp_ax = five_param_fz(sig_mis_go, bpn_go)
    ### Finding unique normals
    bp_fz_norms_go1_unq, bfz_unq_ind = GBt.unique_rows_tol(bp_fz_norms_go1, return_index=True)
    ### Finding the input hkl indices corresponding to unique FZ normals
    mil_ind_csl_unq = mil_ind_csl[bfz_unq_ind]

    ####################################################################################################################
    ### Calculating interplanar distance (d sigma hkl) for unique FZ bpn
    l_rcsl_go = GBfcd.reciprocal_mat(l_csl_go)
    mt_cslr_go = np.dot(l_rcsl_go.transpose(), l_rcsl_go)
    d_inv_sqr = np.diag(np.dot(np.dot(mil_ind_csl_unq, mt_cslr_go),mil_ind_csl_unq.transpose()))
    d_inv = np.sqrt(d_inv_sqr)
    d_sig_hkl = np.true_divide(1, d_inv)

    ####################################################################################################################
    ### Calculating unit cell area for 2-D csl unit cells for unique FZ bpn
    pl_den = []
    num_bpn_unq = np.shape(bp_fz_norms_go1_unq)[0]
    for ct1 in range(num_bpn_unq):
        _, _, pl_den_csl = GBb2.bicryst_planar_den(bp_fz_norms_go1_unq[ct1, :], sig_mis_g, l_g_go, 'normal_go', 'g1')
        pl_den.append(pl_den_csl)
    pl_den = np.array(pl_den)
    a_sig_hkl = np.true_divide(1, pl_den)

    ####################################################################################################################
    ### Checking the csl primitive unit cell volume equality
    v_sig_hkl = np.multiply(d_sig_hkl, a_sig_hkl)
    # print v_sig_hkl
    v_basis = abs(np.linalg.det(l_csl_go))
    if np.all(abs(v_sig_hkl-v_basis) < 1e-04):
        print "The two volumes match!"
    else:
        print " Mismatch!"

    ####################################################################################################################
    ### Sorting attributes in increasing order of 2d csl primitive unit cell area
    ind_area_sort = np.argsort(a_sig_hkl)
    a_sig_hkl_sort = np.sort(a_sig_hkl)
    d_sig_hkl_sort = d_sig_hkl[ind_area_sort]
    bp_fz_norms_go1_unq_sort = bp_fz_norms_go1_unq[ind_area_sort]

    ####################################################################################################################
    ### Check to ensure required number of unique bpn are returned
    if np.shape(bp_fz_norms_go1_unq_sort)[0] < n:
        print "Please input a larger mesh grid or reduce the number of boundaries!"
        n = np.shape(bp_fz_norms_go1_unq_sort)[0]

    ####################################################################################################################
    ### Selecting the lowest 'n' area boundaries and their attributes for plotting
    a_plot = a_sig_hkl_sort[:n]
    pd_plot = np.true_divide(1, a_plot)
    d_plot = d_sig_hkl_sort[:n]
    bp_fz_plot = bp_fz_norms_go1_unq_sort[:n]

    ####################################################################################################################
    ### d vs pd plot
    fig1 = plt.figure(figsize=(12, 12), facecolor='w')
    plt.margins(0.05)
    plt.xlabel('Interplanar spacing')
    plt.ylabel('Planar density of 2D-CSL')
    plt.plot(d_plot, pd_plot, 'ro')
    # plt.show()
    plt.savefig('d_vs_pd_' + str(mesh_size) + '_' + str(n)+ '.png', dpi=100, bbox_inches='tight')

    ####################################################################################################################
    ### FZ plot for the sorted and selected boundaries
    na = '_'+ str(mesh_size) + '_'+ str(n)
    plot_fig(symm_grp_ax, bp_fz_plot, np.pi/6, na)
    # plt.show()
    return
コード例 #8
0
ファイル: pick_uni_bpn.py プロジェクト: spatala/GB_Lammps
def pick_uni_bpn(num, sigma_val, lat_type, bound=10, plot_sw=False):

    ### Creating an instance of lattice class
    elem = GBl.Lattice(lat_type)
    ### Getting the primitive lattice in orthogonal frame
    l_g_go = elem.l_g_go
    ### Extracting the sigma misorientation from the pickle file
    ### Misorientation is in the primitive frame of associated lattice
    gb_dir = os.path.dirname(inspect.getfile(GBpy))
    pkl_path = gb_dir + "/pkl_files/cF_Id_csl_common_rotations.pkl"
    pkl_content = pickle.load(open(pkl_path))
    pub_out = []
    for i in range(len(pkl_content[str(sigma_val)]["N"])):
        sig_mis_N = pkl_content[str(sigma_val)]["N"][i]
        sig_mis_D = pkl_content[str(sigma_val)]["D"][i]
        sig_mis_g = sig_mis_N / sig_mis_D

        sig_mis_go = np.dot(np.dot(l_g_go, sig_mis_g), np.linalg.inv(l_g_go)).reshape(1, 3, 3)[0]
        ### Getting the csl basis in primitive frame
        l_csl_g, l_dsc_g = GBfcd.find_csl_dsc(l_g_go, sig_mis_g)
        ### Converting the csl basis to orthogonal frame
        l_csl_go = np.dot(l_g_go, l_csl_g)
        ### reciprocal csl basis in po frame
        l_rcsl_go = GBfcd.reciprocal_mat(l_csl_go)

        mt_rcsl_go = np.dot(l_rcsl_go.transpose(), l_rcsl_go)

        bp_fz, bp_symm_grp, symm_grp_ax, cube_grid, gs = est_bound(bound, mt_rcsl_go, l_rcsl_go, sig_mis_go, num)

        bpn_sphr = fz2sphr(bp_fz, bp_symm_grp, symm_grp_ax)
        bpn = csl_area_sort(bpn_sphr, l_rcsl_go, mt_rcsl_go)
        bpn_grid = bpn_in_grid(bpn, cube_grid, gs, l_rcsl_go, mt_rcsl_go)

        bpn_grid_fz, _, _ = fpf.five_param_fz(sig_mis_go, bpn_grid)
        bpn_grid_fz = GBt.unique_rows_tol(bpn_grid_fz, tol=1e-06)
        bpn_sort, hkl_sort = csl_area_sort(bpn_grid_fz, l_rcsl_go, mt_rcsl_go, return_hkl=True)

        #### Preparing to pickle the contents
        num_hkl = len(hkl_sort)
        print num_hkl, "\n"
        hkl_save = np.hstack((np.arange(1, num_hkl + 1, 1).reshape(num_hkl, 1), hkl_sort))
        bpn_save = np.hstack((np.arange(1, num_hkl + 1, 1).reshape(num_hkl, 1), bpn_sort))
        mis_id = "Sig_" + str(sigma_val) + "_" + str(i)
        symm_ax = np.dot(np.linalg.inv(l_g_go), symm_grp_ax)
        sig_attr = [mis_id, hkl_save, bpn_save, sig_mis_g, bp_symm_grp, symm_ax]

        # pkl_file = mis_id + '.pkl'
        # jar = open(pkl_file, 'wb')
        # pickle.dump(sig_attr, jar)
        # jar.close()

        if plot_sw == True:
            plot_2d(bpn_grid, gs)
            grid_lines_sphr = grid(gs)
            plot_3d(grid_lines_sphr, bpn_grid)
            plot_3d(grid_lines_sphr, bpn)

        pub_out.append(sig_attr)

    # print pub_out, '\n'
    return pub_out