def write_MC_poscar(atoms_in, Ef, istep=0): atoms = copy.deepcopy(atoms_in) if istep > 0.5: pos_name = 'POSCAR_step_%d_Ef_%+.3f' % (istep, Ef) else: pos_name = 'POSCAR_Ef_%+.3f' % (Ef) vf.my_write_vasp(atoms, filename=pos_name, vasp5=True)
def vasp_create_fcc_100(a, ncell, bp=0): print('==> create fcc 100 plane: ') print(a, ncell, bp) latt = np.array([ [1.0, 0, 0], [0, 1.0, 0], [0, 0, 1.0], ]) * a motif = np.array([ [0, 0, 0], [0.5, 0.5, 0], [0.5, 0, 0.5], [0, 0.5, 0.5], ]) atoms = vf.create_supercell(latt, motif, ncell) atoms.pos_a0 = a if bp == 33: atoms.positions = atoms.positions + np.array([0, 0, 0.1]) *a atoms.wrap() vf.my_write_vasp(atoms, filename='POSCAR', vasp5=True)
def vasp_create_hcp_pyr1(a, ca, ncell, bp=33): print('==> create hcp basal pyr1: ') print(a, ca, ncell, bp) latt = np.array([ [1.0, 0, 0], [0.5, np.sqrt(3) / 2, 0], [-1.0, 0, ca], ]) * a motif = np.array([ [0, 0, 0], [1 / 6, 2 / 3, 1 / 2], ]) ncell2 = ncell.copy() for i in np.arange(3): ncell2[i] = ncell[np.mod(i + 2, 3)] atoms = vf.create_supercell(latt, motif, ncell2) atoms = vf.make_SFP_xy(atoms, i1=1) atoms = vf.make_a3_ortho(atoms) if bp == 33: print('==> create pry1-W') atoms.positions = atoms.positions + np.array([0, 0, 0.1]) * a atoms.wrap() elif bp == -33: print('==> create pry1-N') atoms.positions = atoms.positions + np.array([0, 0, -0.05]) * a atoms.wrap() atoms.pos_a0 = a vf.my_write_vasp(atoms, filename='POSCAR', vasp5=True)
def vasp_create_fcc_111_ortho(a, ncell, bp=0): print('==> create fcc 111 plane (ortho): ') print(a, ncell, bp) latt = np.array([ [1, 0, 0], [0, np.sqrt(3), 0], [0, 0, np.sqrt(6)], ]) * a/np.sqrt(2) motif = np.array([ [ 0, 0, 0], [1/2, 1/2, 0], [ 0, 4/6, 1/3], [1/2, 1/6, 1/3], [ 0, 2/6, 2/3], [1/2, 5/6, 2/3], ]) atoms = vf.create_supercell(latt, motif, ncell) atoms.pos_a0 = a if bp == 33: atoms.positions = atoms.positions + np.array([0, 0, 0.1]) *a atoms.wrap() vf.my_write_vasp(atoms, filename='POSCAR', vasp5=True)
def vasp_create_hcp_prism1(a, ca, ncell, bp=33): print('==> create hcp prism plane: ') print(a, ca, ncell, bp) ncell2 = ncell.copy() for i in np.arange(3): ncell2[i] = ncell[np.mod(i + 2, 3)] vasp_create_hcp_basal(a, ca, ncell2, bp=0) atoms = vf.my_read_vasp('POSCAR') atoms = vf.make_SFP_xy(atoms, i1=1) atoms = vf.make_a3_ortho(atoms) if bp == 33: print('==> create prism1-W') atoms.positions = atoms.positions + np.array([0, 0, 0.1]) * a atoms.wrap() elif bp == -33: print('==> create prism1-N') atoms.positions = atoms.positions + np.array([0, 0, -0.1]) * a atoms.wrap() atoms.pos_a0 = a vf.my_write_vasp(atoms, filename='POSCAR', vasp5=True)
def vasp_create_hcp_basal_ortho(a, ca, ncell, bp=33): print('==> create hcp basal_ortho plane: ') print(a, ca, ncell, bp) latt = np.array([ [1.0, 0, 0], [0, np.sqrt(3), 0], [0, 0, ca], ]) * a motif = np.array([ [0.0, 0, 0], [1 / 2, 1 / 2, 0], [0, 2 / 6, 1 / 2], [1 / 2, 5 / 6, 1 / 2], ]) atoms = vf.create_supercell(latt, motif, ncell) if bp == 33: atoms.positions = atoms.positions + np.array([0, 0, 0.1]) * a atoms.wrap() atoms.pos_a0 = a vf.my_write_vasp(atoms, filename='POSCAR', vasp5=True)
def vasp_create_bcc_123(a, ncell, bp=0): print('==> create bcc 12-3 plane: ') print(a, ncell, bp) latt = np.array([ [1.0, 0, 0], [1 / 2, 1 / 2, 1 / 2], [5 / 2, -1 / 2, 1 / 2], ]) * a motif = np.array([ [0, 0, 0], ]) ncell2 = ncell.copy() for i in np.arange(3): ncell2[i] = ncell[np.mod(i + 2, 3)] atoms = vf.create_supercell(latt, motif, ncell2) atoms = vf.make_SFP_xy(atoms, i1=1) atoms = vf.make_a3_ortho(atoms) if bp == 33: atoms.positions = atoms.positions + np.array([0, 0, 0.1]) * a atoms.wrap() atoms.pos_a0 = a vf.my_write_vasp(atoms, filename='POSCAR', vasp5=True)
def calc_pairs_per_shell(atoms_in, shellmax=4, write_dp=True): atoms = copy.deepcopy(atoms_in) print('==> shellmax: ', shellmax) vf.my_rm('y_post_dp_shell.txt') natoms = atoms.get_positions().shape[0] V0 = atoms.get_volume() / natoms a0 = (V0 * 4)**(1 / 3) cn = atoms.get_cn() print('==> a0: ', a0, '; cn: ', cn) cc_scale = calc_cc_scale(cn) vf.my_write_vasp(atoms, filename='CONTCAR_for_ovito', vasp5=True) struc = calc_ovito_cna(atoms) rcrys, ncrys = crystal_shell(struc) cutoff = a0 * rcrys[shellmax - 1] + 1e-5 data_rdf = calc_ovito_rdf(atoms, cutoff) r, n = post_rdf(data_rdf, V0, cc_scale) while np.abs(n.sum() - ncrys[0:shellmax].sum()) > 1e-10: if n.sum() > ncrys[0:shellmax].sum(): sys.exit('==> ABORT. impossible cutoff. ') cutoff = cutoff + 0.1 data_rdf = calc_ovito_rdf(atoms, cutoff) r, n = post_rdf(data_rdf, V0, cc_scale) dn_shell, WC_SRO = calc_n_shell(ncrys, shellmax, r, n, cc_scale) rmid = calc_rmid(cn) dn_shell_r = read_reduced_dn_shell(dn_shell, rmid) WC_SRO_r = read_reduced_dn_shell(WC_SRO, rmid) dpw = np.prod(dn_shell_r.shape) # dp width dp_shell = dn_shell_r.reshape(dpw) / 2 WC_SRO_r2 = WC_SRO_r.reshape(dpw) if write_dp == True: np.savetxt("y_post_dp_shell.txt", dp_shell) np.savetxt("y_post_WC_SRO_shell.txt", WC_SRO_r2) return dp_shell
def vasp_create_fcc_111_min(a, ncell, bp=0): print('==> create fcc 111 plane min: ') print(a, ncell, bp) latt = np.array([ [1, 0, 0], [-0.5, np.sqrt(3)/2, 0], [ 0.5, np.sqrt(3)/6, np.sqrt(6)/3], ]) * a/np.sqrt(2) motif = np.array([ [0, 0, 0], ]) atoms = vf.create_supercell(latt, motif, ncell) atoms.pos_a0 = a if bp == 33: atoms.positions = atoms.positions + np.array([0, 0, 0.1]) *a atoms.wrap() vf.my_write_vasp(atoms, filename='POSCAR', vasp5=True)
def shift_to_poscar_layer(nmiss): atoms = vf.my_read_vasp(filename='CONTCAR') z = atoms.get_positions()[:, -1] z.sort() natoms = len(z) latt33 = atoms.get_cell()[2, 2] temp1 = latt33 - z[int(-1 * nmiss)] temp2 = z[int(-1 * nmiss)] - z[int(-1 * nmiss - 1)] zshift = temp1 + 0.5 * temp2 pos = atoms.get_positions() pos[:, 2] = pos[:, 2] + zshift atoms.set_positions(pos) atoms.wrap() vf.my_write_vasp(atoms, filename='POSCAR_layer', vasp5=True) # check atoms2 = vf.my_read_vasp('POSCAR_layer') atoms3 = vf.my_read_vasp('CONTCAR') latt = atoms2.get_cell()[:] vf.confirm_0(latt - atoms3.get_cell()[:]) dpos = atoms2.get_positions() - atoms3.get_positions() dposD = dpos @ np.linalg.inv(latt) dposD = dposD - np.around(dposD) dpos = dposD @ latt for i in np.arange(3): dpos[:, i] = dpos[:, i] - dpos[:, i].mean() vf.confirm_0(dpos)
def create_random_alloys(atoms_in, cn, nsamples=1, filename='POSCAR', id1=1, vasp5=False): atoms = copy.deepcopy(atoms_in) natoms = atoms.get_positions().shape[0] # calc natoms_elem cn = cn / cn.sum() natoms_elem = np.around(cn * natoms) if natoms_elem.min() < 0.1: sys.exit('==> ABORT. natoms is too small. ') max_elem = np.argmax(natoms_elem) temp = natoms_elem.sum() - natoms_elem[max_elem] natoms_elem[max_elem] = natoms - temp print(natoms_elem) # new symbols symb = np.array([]) for i in np.arange(natoms_elem.shape[0]): for j in np.arange(natoms_elem[i]): symb = np.append(symb, i + 1) atoms.set_chemical_symbols(symb) # randomize pos for i in np.arange(nsamples): temp = np.hstack([ atoms.positions, \ np.random.random_sample([natoms, 1]) ]) ind = np.argsort(temp[:, -1]) atoms.set_positions(temp[ind, 0:3], apply_constraint=False) filename2 = '%s_%03d' % (filename, i + id1) vf.my_write_vasp(atoms, filename2, vasp5=vasp5)