Example #1
0
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
Example #2
0
def bicryst_planar_den(inds, t_mat, l_g_go, inds_type='miller_index',
                       mat_ref='g1'):
    """
    The function computes the planar densities of the planes
    1 and 2 and the two-dimensional CSL

    Parameters
    ---------------
    inds: numpy array
    The boundary plane indices

    inds_type: string
    {'miller_index', 'normal_go', 'normal_g'}

    t_mat: numpy array
    Transformation matrix from g1 to g2 in go1 reference frame

    mat_ref: string
    {'go1', 'g1'}

    lattice: Lattice class
    Attributes of the underlying lattice

    Returns
    -----------
    pl_den_pl1, pl_den_pl2: numpy array
    The planar density of planes 1 and 2

    pl_den_csl: numpy array
    The planare density of the two-dimensional CSL
    """
    import GBpy.lattice as lat
    if isinstance(l_g_go, lat.Lattice):
        l_g_go = np.array(l_g_go.l_g_go, dtype=np.float64)
    l_g1_go1 = l_g_go
    l_rg1_go1 = fcd.reciprocal_mat(l_g1_go1)
    l_go1_rg1 = np.linalg.inv(l_rg1_go1)

    if inds_type == 'normal_go':
        bp1_go1 = inds
        miller1_inds = int_man.int_finder(np.dot(l_go1_rg1, bp1_go1))
    elif inds_type == 'miller_index':
        miller1_inds = inds
    elif inds_type == 'normal_g':
        bp1_g1 = inds
        l_g1_rg1 = np.dot(l_go1_rg1, l_g1_go1)
        miller1_inds = int_man.int_finder(np.dot(l_g1_rg1, bp1_g1))
    else:
        raise Exception('Wrong index type')

    if mat_ref == 'go1':
        l_2d_csl_g1, l_pl1_g1, l_pl2_g1 = gb_2d_csl(miller1_inds,
                                                    t_mat, l_g_go,
                                                    'miller_index', 'go1')
    elif mat_ref == 'g1':
        l_2d_csl_g1, l_pl1_g1, l_pl2_g1 = gb_2d_csl(miller1_inds,
                                                    t_mat, l_g_go,
                                                    'miller_index', 'g1')
    else:
        raise Exception('Wrong reference axis type')

    check_2d_csl(l_pl1_g1, l_pl2_g1, l_2d_csl_g1)

    pl_den_pl1 = pl_density(l_pl1_g1, l_g1_go1)
    pl_den_pl2 = pl_density(l_pl2_g1, l_g1_go1)
    pl_den_csl = pl_density(l_2d_csl_g1, l_g1_go1)

    return pl_den_pl1, pl_den_pl2, pl_den_csl
Example #3
0
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
Example #4
0
def gb_2d_csl(inds, t_mat, l_g_go,
              inds_type='miller_index', mat_ref='g1'):
    """
    For a given boundary plane normal 'bp1_g1' and the misorientation
    matrix 't_g1tog2_g1', the two-dimensional CSL lattice is computed

    Parameters
    ------------------
    inds: numpy array
    The boundary plane indices

    inds_type: string
    {'miller_index', 'normal_go', 'normal_g'}

    t_mat: numpy array
    Transformation matrix from g1 to g2 in 'mat_ref' reference frame

    mat_ref: string
    {'go1', 'g1'}

    lattice: Lattice class
    Attributes of the underlying lattice

    Returns
    -----------
    l_2d_csl_g1, l_pl1_g1, l_pl2_g1: numpy arrays
    l_2d_csl_g1 is the 2d CSL in g1 ref frame
    l_pl1_g1 is the plane 1 basis in g1 ref frame
    l_pl2_g1 is the plane 2 basis in g1 ref frame
    """
    import GBpy.lattice as lat
    if isinstance(l_g_go, lat.Lattice):
        l_g_go = np.array(l_g_go.l_g_go, dtype=np.float64)
    
    l_g1_go1 = l_g_go
    
    l_go1_g1 = np.linalg.inv(l_g1_go1)
    l_rg1_go1 = fcd.reciprocal_mat(l_g1_go1)
    l_go1_rg1 = np.linalg.inv(l_rg1_go1)

    if inds_type == 'normal_go':
        bp1_go1 = inds
        miller1_ind = int_man.int_finder(np.dot(l_go1_rg1, bp1_go1))
    elif inds_type == 'miller_index':
        miller1_ind = inds
    elif inds_type == 'normal_g':
        bp1_g1 = inds
        l_g1_rg1 = np.dot(l_go1_rg1, l_g1_go1)
        miller1_ind = int_man.int_finder(np.dot(l_g1_rg1, bp1_g1))
    else:
        raise Exception('Wrong index type')

    if mat_ref == 'go1':
        t_g1tog2_g1 = np.dot(l_go1_g1, np.dot(t_mat, l_g1_go1))
    elif mat_ref == 'g1':
        t_g1tog2_g1 = t_mat
    else:
        raise Exception('Wrong reference axis type')

    bp1_go1 = int_man.int_finder(np.dot(l_rg1_go1, miller1_ind))
    l_g2_g1 = t_g1tog2_g1
    l_g2_go1 = np.dot(l_g1_go1, l_g2_g1)
    l_rg2_go1 = fcd.reciprocal_mat(l_g2_go1)
    l_go1_rg2 = np.linalg.inv(l_rg2_go1)
    # bp2_g2 = int_man.int_finder(np.dot(-l_go1_g2, bp1_go1))
    miller2_ind = int_man.int_finder(np.dot(-l_go1_rg2, bp1_go1))
    
    l_pl1_g1 = bp_basis(miller1_ind)
    l_pl2_g2 = bp_basis(miller2_ind)

    l_pl2_g1 = np.dot(l_g2_g1, l_pl2_g2)

    l_2d_csl_g1 = csl_finder_2d(l_pl1_g1, l_pl2_g1)

    return l_2d_csl_g1, l_pl1_g1, l_pl2_g1