def Sigma3CSL(left, right): fcc_rotation_location = os.path.join( os.path.dirname(inspect.getfile(GBpy)), 'pkl_files', 'cF_Id_csl_common_rotations.pkl') with open(fcc_rotation_location) as infile: fcc_rotations = pickle.load(infile) # misorientation for sigma 3 boundary sig3 = fcc_rotations['3']['N'][0] / fcc_rotations['3']['D'][0] # create lattice instance and multiply by lattice parameter of nickel Ni = lattice.Lattice() a_Ni = 3.52 a_Al = 4.050 #4.032, LEA (Liu, Ercolessi, Adams) potential on NIST a_ref = 1. Ni.l_g_go *= a_Al basis = [[0., 0.5, 0.5], [0.5, 0., 0.5], [0.5, 0.5, 0.]] # get primitive CSL vectors and convert them to orthogonal basis csl_p, __ = find_csl_dsc.find_csl_dsc(basis, sig3) print csl_p csl_o = np.dot(Ni.l_g_go, csl_p).T # take boundary plane from orientation matrix, use it to get # 2D CSL in boundary plane, and convert to orthogonal basis boundary_plane = left[0] gb = bp_basis.gb_2d_csl(boundary_plane, sig3, basis, 'normal_go', 'g1') #print "gb =",gb csl_2d = np.dot(Ni.l_g_go, gb[0]).T #print "csl_2d =",csl_2d # normalize orientation matrix to make it a rotation matrix, # and rotate both CSL and 2D CSL into crystal frame rotation_matrix = [list(np.array(i) / np.linalg.norm(i)) for i in left] #print rotation_matrix csl_2d = [np.dot(rotation_matrix, i) for i in csl_2d] csl = [np.dot(rotation_matrix, i) for i in csl_o] # iterate through the vertices of the CSL unit cell # and use the highest and lowest x coordinates # to calculate the period in the x direction xlo, xhi = 0, 0 for i in product([0, 1], [0, 1], [0, 1]): csl_vertex = np.sum(np.array(csl).T * i, axis=1) xlo = min(xlo, csl_vertex[0]) xhi = max(xhi, csl_vertex[0]) x_period = xhi - xlo # iterate through the vertices of the 2D CSL unit cell # and use the highest and lowest y and z coordinates # to calculate the period in the y and z directions ylo, yhi, zlo, zhi = 0, 0, 0, 0 for i in product([0, 1], [0, 1]): csl_2d_vertex = np.sum(np.array(csl_2d).T * i, axis=1) ylo = min(ylo, csl_2d_vertex[1]) yhi = max(yhi, csl_2d_vertex[1]) zlo = min(zlo, csl_2d_vertex[2]) zhi = max(zhi, csl_2d_vertex[2]) y_period = yhi - ylo z_period = zhi - zlo return x_period, y_period, z_period
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
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