def relax_structure(system, potential, potential_filename=None, relax_positions=True, relax_cell=True): """ Run a geometry optimisation on the structure to find the energy minimum. Parameters ---------- system : ase.Atoms A system of atoms to run the minimisation on. The structure is altered in-place. potential : Potential or str A quippy Potential object with the desired potential, or a potential_str to initialise a new potential. Returns ------- minimised_structure : Atoms The geometry optimised structure. """ info("Inside minimiser.") qsystem = Atoms(system) if not isinstance(potential, Potential): if potential_filename: potential = Potential(potential, param_filename=potential_filename) else: potential = Potential(potential) qsystem.set_calculator(potential) minimiser = Minim(qsystem, relax_positions=relax_positions, relax_cell=relax_cell) with Capturing(debug_on_exit=True): minimiser.run() system.set_cell(qsystem.cell) system.set_positions(qsystem.positions) system.energy = qsystem.get_potential_energy() info("Minimiser done.") return system
def h2_formation_energy(pot): """ Given a potential calculate the H2 formation energy and equilibrium bond spacing. Args: pot(:quippy:class:`Potential`) potential object. Returns: float: Hydrogen molecule formation energy. """ h2 = aseAtoms('H2', positions=[[0, 0, 0], [0, 0, 0.7]]) h2 = Atoms(h2) h2.set_calculator(pot) opt = BFGS(h2) opt.run(fmax=0.0001) E_h2 = h2.get_potential_energy() return E_h2
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)
block=block, corner=corner, shape=shape, exe = vasp, ediffg = -0.05, nelmin = 6, nelmdl = -15, kpar = 32, parmode='cobalt', xc='PBE', lreal=False, ibrion=13, nsw=40, algo='VeryFast', npar=8, lplane=False, lwave=False, lcharg=False, nsim=1, voskown=1, ismear=1, sigma=0.01, iwavpr=11, isym=2, nelm=100) sock_calc = SocketCalculator(vasp_client, ip=ip, bgq=True) bulk.set_calculator(sock_calc) opt = LBFGS(bulk) opt.run(fmax=0.05, steps=100) sock_e = bulk.get_potential_energy() sock_f = bulk.get_forces() sock_s = bulk.get_stress() print 'energy', sock_e print 'forces', sock_f print 'stress', sock_s sock_calc.shutdown()
ibrion=13, nsw=40, algo='VeryFast', npar=8, lplane=False, lwave=False, lcharg=False, nsim=1, voskown=1, ismear=1, sigma=0.01, iwavpr=11, isym=2, nelm=100) sock_calc = SocketCalculator(vasp_client, ip=ip, bgq=True) bulk.set_calculator(sock_calc) opt = LBFGS(bulk) opt.run(fmax=0.05, steps=100) sock_e = bulk.get_potential_energy() sock_f = bulk.get_forces() sock_s = bulk.get_stress() print 'energy', sock_e print 'forces', sock_f print 'stress', sock_s sock_calc.shutdown()
print 'Delete atoms' at = gbr.delete_atoms(grain=at, rcut=1.5) at.info['OrigHeight'] = at.positions[:, 1].max() - at.positions[:, 1].min() r_scale = 1.00894848312 rem = [] for atom in at: if atom.position[0] <= 0.00 and atom.position[1] <= 100.0: rem.append(atom.index + 1) print 'Removing ', len(rem), ' atoms.' if len(rem) > 0: at.remove_atoms(rem) else: print 'No atoms displaced from unitcell' pot = Potential('IP EAM_ErcolAd do_rescale_r=T r_scale={0}'.format(r_scale), param_filename=eam_pot) at.set_calculator(pot) at.write('unrelaxed.xyz') print 'Running Relaxation' opt = FIRE(at) opt.run(fmax=0.1) print 'Calculating connectivity and Nye Tensor' ref_slab = Atoms('ref_slab.xyz') ref_slab.set_cutoff(3.0) ref_slab.calc_connect() at.set_cutoff(3.0) at.calc_connect() alpha = calc_nye_tensor(at, ref_slab, 3, 3, at.n) at.add_property('screw', alpha[2, 2, :])
<per_type_data type="2" atomic_num="6"/> <per_type_data type="3" atomic_num="1"/> </LMTO_TBE_params> </params>""") print 'Initializing LOTF Potential, qm_radii:', params.qm_inner_radius, params.qm_outer_radius qmmm_pot = ForceMixingPotential(pot1=mm_pot, pot2=qm_pot, atoms=defect, qm_args_str='single_cluster cluster_periodic_z carve_cluster '+ 'terminate=F cluster_hopping=F randomise_buffer=F', fit_hops=2, lotf_spring_hops=2, hysteretic_buffer=True, hysteretic_buffer_inner_radius=params.hyst_buffer_inner, hysteretic_buffer_outer_radius=params.hyst_buffer_outer, cluster_hopping_nneighb_only=False, min_images_only=True) defect.set_calculator(qmmm_pot) elif pot_type == 'EAM': eam_pot = os.path.join(potdir, '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) defect.set_calculator(pot) else: print 'No potential chosen', 1/0 print 'Finding initial dislocation core positions...' try: defect.params['core'] except KeyError: defect.params['core'] = np.array([98.0, 98.0, 1.49]) defect = set_quantum(defect, params.n_core)
</params>""") print 'Initializing LOTF Potential, qm_radii:', params.qm_inner_radius, params.qm_outer_radius qmmm_pot = ForceMixingPotential( pot1=mm_pot, pot2=qm_pot, atoms=defect, qm_args_str='single_cluster cluster_periodic_z carve_cluster ' + 'terminate=F cluster_hopping=F randomise_buffer=F', fit_hops=2, lotf_spring_hops=2, hysteretic_buffer=True, hysteretic_buffer_inner_radius=params.hyst_buffer_inner, hysteretic_buffer_outer_radius=params.hyst_buffer_outer, cluster_hopping_nneighb_only=False, min_images_only=True) defect.set_calculator(qmmm_pot) elif pot_type == 'EAM': eam_pot = os.path.join(potdir, '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) defect.set_calculator(pot) else: print 'No potential chosen', 1 / 0 print 'Finding initial dislocation core positions...' try: defect.params['core'] except KeyError: defect.params['core'] = np.array([98.0, 98.0, 1.49])
sys.exit() Grain_Boundary = False if not Grain_Boundary: unit_slab = crack.build_unit_slab() pot_dir = os.environ['POTDIR'] pot_file = os.path.join(pot_dir, crack_info['param_file']) mm_pot = Potential('IP EAM_ErcolAd do_rescale_r=T r_scale=1.00894848312', param_filename=pot_file, cutoff_skin=2.0) # gb_frac.py will generate the frac_cell.xyz file which contains # a crack_cell: if Grain_Boundary: unit_slab = Atoms('frac_cell.xyz') unit_slab.set_calculator(mm_pot) #calculate the elasticity tensor: crack.calculate_c(mm_pot) surface = crack.build_surface(mm_pot) E_surf = surface.get_potential_energy() bulk = bcc(2.82893) bulk.set_atoms(26) bulk.info['adsorbate_info']=None bulk.set_calculator(mm_pot) E_bulk = bulk.get_potential_energy()/len(bulk) area = (surface.get_cell()[0,0]*surface.get_cell()[2,2]) print E_surf, E_bulk gamma = (E_surf - E_bulk*len(surface))/(2.0*area) print('Surface energy of %s surface %.4f J/m^2\n' % (crack.cleavage_plane, gamma/(units.J/units.m**2)))
def calc_bulk_dissolution(args): """Calculate the bulk dissolution energy for hydrogen in a tetrahedral position in bcc iron. Args: args(list): determine applied strain to unit cell. """ POT_DIR = os.path.join(app.root_path, 'potentials') 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) alat = 2.83 gb = BodyCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], size=(6, 6, 6), symbol='Fe', pbc=(1, 1, 1), latticeconstant=alat) cell = gb.get_cell() print 'Fe Cell', cell e1 = np.array([1, 0, 0]) e2 = np.array([0, 1, 0]) e3 = np.array([0, 0, 1]) if args.hydrostatic != 0.0: strain_tensor = np.eye(3) + args.hydrostatic * np.eye(3) cell = cell * strain_tensor gb.set_cell(cell, scale_atoms=True) print 'Hydrostatic strain', args.hydrostatic print 'strain tensor', strain_tensor print gb.get_cell() elif args.stretch != 0.0: strain_tensor = np.tensordot(e2, e2, axes=0) strain_tensor = np.eye(3) + args.stretch * strain_tensor cell = strain_tensor * cell print 'Stretch strain' print 'Cell:', cell gb.set_cell(cell, scale_atoms=True) elif args.shear != 0.0: strain_tensor = np.tensordot(e1, e2, axes=0) strain_tensor = np.eye(3) + args.shear * strain_tensor cell = strain_tensor.dot(cell) print 'Shear Strain', strain_tensor print 'Cell:', cell gb.set_cell(cell, scale_atoms=True) gb.write('sheared.xyz') else: print 'No strain applied.' tetra_pos = alat * np.array([0.25, 0.0, 0.5]) h2 = aseAtoms('H2', positions=[[0, 0, 0], [0, 0, 0.7]]) h2 = Atoms(h2) gb = Atoms(gb) gb_h = gb.copy() gb_h.add_atoms(tetra_pos, 1) #caclulators gb.set_calculator(pot) h2.set_calculator(pot) gb_h.set_calculator(pot) gb_h.write('hydrogen_bcc.xyz') #Calc Hydrogen molecule energy opt = BFGS(h2) opt.run(fmax=0.0001) E_h2 = h2.get_potential_energy() h2.write('h2mol.xyz') #strain_mask = [1,1,1,0,0,0] strain_mask = [0, 0, 0, 0, 0, 0] ucf = UnitCellFilter(gb_h, strain_mask) #opt = BFGS(gb_h) opt = FIRE(ucf) opt.run(fmax=0.0001) E_gb = gb.get_potential_energy() E_gbh = gb_h.get_potential_energy() E_dis = E_gbh - E_gb - 0.5 * E_h2 print 'E_gb', E_gb print 'E_gbh', E_gbh print 'H2 Formation Energy', E_h2 print 'Dissolution Energy', E_dis
cell = surf_cell.get_cell() A = cell[0][0]*cell[1][1] gamma = (surf_ener- len(surf_cell)*ener_per_atom)/A print '2*gamma ev/A2', gamma print '2*gamma J/m2', gamma/(units.J/units.m**2) j_dict = {'or_axis':or_axis, 'bp':bp, 'gamma':gamma} with open('gbfrac.json','w') as f: json.dump(j_dict, f) out = AtomsWriter('{0}'.format('{0}_surf.xyz'.format(gbid))) out.write(Atoms(surf_cell)) out.close() frac_cell = gb_frac.build_tilt_sym_frac() #Unit cell for grain boundary fracture cell: print frac_cell.get_cell().round(2) frac_cell = Atoms(frac_cell) frac_cell = del_atoms(frac_cell) #Relax grainboundary crack cell unit cell: pot = Potential('IP EAM_ErcolAd', param_filename='Fe_Mendelev.xml') frac_cell.set_calculator(pot) slab_opt = FIRE(frac_cell) slab_opt.run(fmax = (0.02*units.eV/units.Ang)) #Print frac_cell to file: out = AtomsWriter('{0}'.format('frac_cell.xyz'.format(gbid))) out.write(Atoms(frac_cell)) out.close()
scaled_positions = unit_cell.get_scaled_positions() THZ_to_mev = 4.135665538536 unit_cell = PhonopyAtoms(symbols=symbols, cell=cell, scaled_positions=scaled_positions) phonon = Phonopy(unit_cell, [[n_sup_x,0,0],[0,n_sup_y,0],[0,0,n_sup_z]]) phonon.generate_displacements(distance=0.05) supercells = phonon.get_supercells_with_displacements() #We need to get the forces on these atoms... forces = [] print 'There are', len(supercells), 'displacement patterns' for sc in supercells: cell = aseAtoms(symbols=sc.get_chemical_symbols(), scaled_positions=sc.get_scaled_positions(), cell=sc.get_cell(), pbc=(1,1,1)) cell = Atoms(cell) cell.set_calculator(pot) forces.append(cell.get_forces()) phonon.set_forces(forces) phonon.produce_force_constants() mesh = [nqx, nqy, nqz] phonon.set_mesh(mesh, is_eigenvectors=True) qpoints, weights, frequencies, eigvecs = phonon.get_mesh() #SHOW DOS STRUCTURE phonon.set_total_DOS(freq_min=0.0, freq_max=12.0, tetrahedron_method=False) phonon.get_total_DOS() phonon.write_total_DOS() phonon.plot_total_DOS().show()
symbol='Fe', pbc=(1, 1, 1), latticeconstant=alat) tetra_pos = alat * np.array([0.25, 0.0, 0.5]) h2 = aseAtoms('H2', positions=[[0, 0, 0], [0, 0, 0.7]]) h2 = Atoms(h2) gb = Atoms(gb) gb_h = gb.copy() gb_h.add_atoms(tetra_pos, 1) #caclulators gb.set_calculator(pot) h2.set_calculator(pot) gb_h.set_calculator(pot) gb_h.write('hydrogen_bcc.xyz') #Calc Hydrogen molecule energy opt = BFGS(h2) opt.run(fmax=0.0001) E_h2 = h2.get_potential_energy() strain_mask = [1, 1, 1, 0, 0, 0] ucf = UnitCellFilter(gb_h, strain_mask) #opt = BFGS(gb_h) opt = FIRE(ucf) opt.run(fmax=0.0001) E_gb = gb.get_potential_energy()
structure_2d = Atoms( sheet(species, fs_lattice_parameter, gamma=angle, supercell=supercell, orthorhombic=True)) structure_2d.name = "W_{0}_{1:.0f}_{2}x{2}".format(sheet_type, angle, supercell) relax_cell = True # structure_2d.translate((0, 0, -structure_2d.get_center_of_mass()[2])) # castep_write(structure_2d, structure_2d.name, optimise=False, fix_lattice=False) structure_2d.set_cutoff(fs_potential.cutoff() + 2.0) structure_2d.set_calculator(fs_potential) minimiser = Minim(structure_2d, relax_positions=True, relax_cell=relax_cell) minimiser.run() castep_write(structure_2d, structure_2d.name, optimise=False, fix_lattice=True) # From 10.1007/BF01184339, thermal expansion of tungsten is small, but for # different temperatures we can expand a bit: # 3000 K V/V0 = 1.11; # 5000 K V/V0 = 1.29 # if temperature == 1000: structure_2d.set_lattice(structure_2d.lattice * 1.003, scale_positions=True) elif temperature == 3000:
Grain_Boundary = False if not Grain_Boundary: unit_slab = crack.build_unit_slab() pot_dir = os.environ['POTDIR'] pot_file = os.path.join(pot_dir, crack_info['param_file']) mm_pot = Potential('IP EAM_ErcolAd do_rescale_r=T r_scale=1.00894848312', param_filename=pot_file, cutoff_skin=2.0) # gb_frac.py will generate the frac_cell.xyz file which contains # a crack_cell: if Grain_Boundary: unit_slab = Atoms('frac_cell.xyz') unit_slab.set_calculator(mm_pot) #calculate the elasticity tensor: crack.calculate_c(mm_pot) surface = crack.build_surface(mm_pot) E_surf = surface.get_potential_energy() bulk = bcc(2.82893) bulk.set_atoms(26) bulk.info['adsorbate_info'] = None bulk.set_calculator(mm_pot) E_bulk = bulk.get_potential_energy() / len(bulk) area = (surface.get_cell()[0, 0] * surface.get_cell()[2, 2]) print E_surf, E_bulk gamma = (E_surf - E_bulk * len(surface)) / (2.0 * area) print('Surface energy of %s surface %.4f J/m^2\n' % (crack.cleavage_plane, gamma / (units.J / units.m**2)))