def calc_elast_dipole_eam(input_file, force_tol, relax_cell): """ Calculate elastic dipole using an Embedded Atom Potential. Args: input_file (str): Name of .xyz file contains unitcell with defect. force_tol (float): Force tolerance to stop relaxation. relax_cell (bool): Relax lattice vectors. Returns: Elastic Dipole Tensor 3x3 numpy array. """ try: POT_DIR = os.environ['POTDIR'] except KeyError: sys.exit("PLEASE SET export POTDIR='path/to/potfiles/'") elastic = ElasticDipole() eam_pot = os.path.join(POT_DIR, 'PotBH.xml') pot = Potential( 'IP EAM_ErcolAd do_rescale_r=T r_scale={0}'.format(1.00894848312), param_filename=eam_pot) ats = Atoms(input_file) ats.set_calculator(pot) init_vol = ats.get_volume() print 'Initial Vol.', init_vol elastic.relax_defect_cell(ats, force_tol=force_tol, relax_cell=relax_cell) final_vol = ats.get_volume() print 'Final Vol.', final_vol print 'Volume Diff.', final_vol - init_vol ats = Atoms('defect_cell_relaxed.xyz') defect = find_h_atom(ats) print 'Defect index', defect.index, 'Position', defect.position, 'Type: ', defect.number ats.set_calculator(pot) return elastic.compute_vacancy_dipole(defect, ats.copy(), pot)
else: print ("Using PURE EAM POTENTIAL") qm_pot = Potential('IP EAM_ErcolAd do_rescale_r=T r_scale={0}'.format(1.00894848312), param_filename=eam_pot) nebpath = NEBPaths() nebanalysis = NEBAnalysis() if args.auto_gen: disloc_ini, disloc_fin = nebpath.build_h_nebpath(neb_path=np.array(args.neb_path), fmax = args.fmax, sup_cell=args.sup_cell) else: disloc_ini = Atoms('disloc_0.xyz') disloc_fin = Atoms('disloc_1.xyz') n_knots = args.knots images = [disloc_ini] + \ [disloc_ini.copy() for i in range(n_knots)] + \ [disloc_fin] #copied this from Tom's scripts: need to check and understand #Will turn these on after the initial run throughs to check the difference. #alpha = dft_alat/eam_alat #eam_bulk_mod = (eam_C11 + 2.0*eam_C12)/3.0 #dft_bulk_mod = (dft_C11 + 2.0*dft_C12)/3.0 #beta = eam_bulk_mod/dft_bulk_mod/alpha/alpha/alpha qmmm_pot = ForceMixingCarvingCalculator(disloc_ini, qm_region_mask, mm_pot, qm_pot, buffer_width=buff, alpha=1.0, beta=1.0, vacuum=5.0, pbc_type=[False, False, True])
eam_pot = os.path.join(POT_DIR, 'PotBH.xml') r_scale = 1.00894848312 pot = Potential('IP EAM_ErcolAd do_rescale_r=T r_scale={0}'.format(r_scale), param_filename=eam_pot) if __name__ == '__main__': gen_interface() decorate_interface() with open('unique_h_sites.json', 'r') as f: h_sites = json.load(f) g = open('h_site_ener_{}_{}.txt'.format(mode, str(num)), 'w') ats = Atoms('output.xyz') gb_min, gb_max, z_width, at_min = get_interface_bounds(ats) with open('subgb.json', 'r') as f: subgb_dict = json.load(f) s_ats = ats.copy() s_ats = apply_strain(s_ats, mode, num) s_ats.set_calculator(pot) E_gb = s_ats.get_potential_energy() for h_site in h_sites[:50]: h_ats = s_ats.copy() h_site_tmp = list(h_site) #-1.0 to subtract vacuum added in calc_eseg.py at_min to account for diff between gb_min and lowest atom. h_site_tmp[2] += gb_min - 1.0 + at_min h_ats.add_atoms(h_site_tmp, 1) h_ats.set_calculator(pot) opt = FIRE(h_ats) opt.run(fmax=force_tol) E_gbh = h_ats.get_potential_energy() h_at_rel = filter(lambda x: x.number == 1, h_ats) #print position of relaxed h atom and the interstitial energies.
help='Force Tolerance', default=0.05, type=float) args = parser.parse_args() with open('unique_h_sites.json', 'r') as f: h_sites = json.load(f) print 'There are ', len(h_sites), 'H interstitials' ats = Atoms('output.xyz') gb_min, gb_max, z_width, at_min = get_interface_bounds(ats) with open('subgb.json', 'r') as f: subgb_dict = json.load(f) force_tol = args.force_tol E_h2 = -4.73831215121 #E_gb = subgb_dict['E_gb'] all_h_ats = ats.copy() for mode in args.modes: for num in args.nums: g = open('h_site_ener_{}_{}.txt'.format(mode, str(num)), 'w') s_ats = ats.copy() s_ats = apply_strain(s_ats, mode, num) s_ats.set_calculator(pot) E_gb = s_ats.get_potential_energy() for h_site in h_sites: h_ats = s_ats.copy() h_site_tmp = list(h_site) #-1.0 to subtract vacuum added in calc_eseg.py at_min to account for diff between gb_min and lowest atom. h_site_tmp[2] += gb_min - 1.0 + at_min h_ats.add_atoms(h_site_tmp, 1) h_ats.set_calculator(pot) opt = FIRE(h_ats)