def test_eam_run(pt_eam_potential_file): eam = EAM(potential=StringIO(pt_eam_potential_file.read_text()), form='eam', elements=['Pt']) slab = fcc111('Pt', size=(4, 4, 2), vacuum=10.0) slab.calc = eam assert(abs(-164.277599313 - slab.get_potential_energy()) < 1E-8) assert(abs(6.36379627645 - np.linalg.norm(slab.get_forces())) < 1E-8)
def phonon_run(runID, save_to_db=False, plot_bands=False): print("Running ID %d" % (runID)) db = connect(db_name) atoms = db.get_atoms(id=runID) #view(atoms) #atoms = bulk("Al") #atoms = atoms*(2,1,1) #calc = EAM(potential="/home/davidkl/Documents/EAM/Al-LEA.eam.alloy") calc = EAM(potential="/home/davidkl/Documents/EAM/mg-al-set.eam.alloy") atoms.set_calculator(calc) #calc = gp.GPAW( mode=gp.PW(600), xc="PBE", kpts=(4,4,4), nbands="120%", symmetry="off" ) #atoms.set_calculator(calc) ph = Phonons(atoms, calc, supercell=(3, 3, 3), name=wrk + "/phonon_files/phonon%d" % (runID)) ph.run() #return ph.read(acoustic=True) omega_e, dos_e = ph.dos(kpts=(30, 30, 30), npts=1000, delta=5E-4) if (plot_bands): points = ibz_points['fcc'] G = points['Gamma'] X = points['X'] W = points['W'] K = points['K'] L = points['L'] U = points['U'] point_names = ['$\Gamma$', 'X', 'U', 'L', '$\Gamma$', 'K'] path = [G, X, U, L, G, K] path_kc, q, Q = bandpath(path, atoms.cell, 100) omega_kn = 1000.0 * ph.band_structure(path_kc) figb = plt.figure() axb = figb.add_subplot(1, 1, 1) for n in range(len(omega_kn[0])): omega_n = omega_kn[:, n] axb.plot(q, omega_n) plt.show() if (save_to_db): # Store the results in the database db.update(runID, has_dos=True) manager = cpd.PhononDOS_DB(db_name) # Extract relevant information from the atoms database row = db.get(id=runID) name = row.name atID = row.id manager.save(name=name, atID=atID, omega_e=omega_e, dos_e=dos_e)
def call_DFT(self): prev_calc = self.atoms.calc pseudopotentials = self.dft_input['pseudopotentials'] # label = self.dft_input['label'] # input_data = self.dft_input['input_data'] # kpts = self.dft_input['kpts'] # calc = Espresso(pseudopotentials=pseudopotentials, label=label, # tstress=True, tprnfor=True, nosym=True, # input_data=input_data, kpts=kpts) calc = EAM(potential=pseudopotentials) self.atoms.set_calculator(calc) forces = self.atoms.get_forces() self.call_observers() self.atoms.set_calculator(prev_calc) return forces
def test_eam_run(): import numpy as np from ase.calculators.eam import EAM from ase.test.eam_pot import Pt_u3 from ase.build import fcc111 from io import StringIO eam = EAM(potential=StringIO(Pt_u3), form='eam', elements=['Pt']) slab = fcc111('Pt', size=(4, 4, 2), vacuum=10.0) slab.calc = eam assert( abs(-164.277599313 - slab.get_potential_energy()) < 1E-8 ) assert( abs(6.36379627645 - np.linalg.norm(slab.get_forces())) < 1E-8 )
def get_calc(p): ''' Takes the potential parameters A, lambda, D, and 2mu and returns an ASE calculator object. ''' A, lmbd, D, twomu = p rs = np.linspace(0.0, cutoff, 1024) rhos = np.linspace(1e-10, 10, 1000) # Smooth cutoff function psi = lambda x: [(a < cutoff) * a**4 / (1 + a**4) for a in x] dpsi = lambda x: [(a < cutoff) * 4 * a**3 / (1 + a**4)**2 for a in x] m_phi = A * np.exp(-lmbd * rs) * psi((rs - cutoff) / 3) m_d_phi = -lmbd*A*np.exp(-lmbd*rs) * psi((rs-cutoff)/3) + \ A*np.exp(-lmbd*rs) * dpsi((rs-cutoff)/3) / 3 m_embedded = -D * np.sqrt(rhos) m_d_embedded = -D / (2 * np.sqrt(rhos)) m_density = np.exp(-twomu * rs) * psi((rs - cutoff) / 3) m_d_density = -twomu*np.exp(-twomu*rs) * psi((rs-cutoff)/3) + \ np.exp(-twomu*rs) * dpsi((rs-cutoff)/3) / 3 m_densityf = spline(rs, m_density) m_d_densityf = spline(rs, m_d_density) m_embeddedf = spline(rhos, m_embedded) m_d_embeddedf = spline(rhos, m_d_embedded) m_phif = spline(rs, m_phi) m_d_phif = spline(rs, m_d_phi) calc = EAM(elements=['Al'], embedded_energy=np.array([m_embeddedf]), electron_density=np.array([m_densityf]), phi=np.array([[m_phif]]), d_embedded_energy=np.array([m_d_embeddedf]), d_electron_density=np.array([m_d_densityf]), d_phi=np.array([[m_d_phif]]), cutoff=cutoff, form='alloy', Z=[13], nr=1024, nrho=1024, dr=rs[1] - rs[0], drho=rhos[1] - rhos[0], lattice=['fcc'], mass=[26.982], a=[4.05]) return calc
def test_mishin(): from ase.calculators.eam import EAM sys_setting ={'elements':['Al', 'Fe'], 'pot':'zhou', \ 'pca':[10], 'nAtoms':250,\ #'structure':'bcc',\ #'positions':'rnd','a':3.0, 'period':[5,5,5]} 'structure':'fcc',\ 'positions':'rnd','a':4.6, 'period':[2,2,2]} sys1 = sys.System(sys_setting) potDir = './' fileName = potDir + 'Zhou_AlFe.alloy' #potDir = '../../lammps/potentials/' #fileName = potDir + 'Ni.adp' mishin = EAM(potential=fileName) mishin.write_potential('new.eam.alloy') sys1.bulk.set_calculator(mishin) nAtoms = sys1.bulk.get_number_of_atoms() ep = sys1.bulk.get_potential_energy() / nAtoms forces = sys1.bulk.get_forces() print ep print mishin.Z print mishin.mass print mishin.a print mishin.lattice print mishin.nrho print mishin.drho print mishin.nr print mishin.dr #print mishin.d_d mishin.set_splines() print mishin.embedded_energy[0](30) mishin.plot()
def main(argv): relax_atoms = (argv[1] == "atoms") runID = int(argv[0]) print("Running job: %d" % (runID)) db_name = db_name_atoms #db_name = "/home/ntnu/davidkl/Documents/GPAWTutorials/ceTest.db" db = ase.db.connect(db_name) new_run = not db.get(id=runID).key_value_pairs["started"] # Update the databse db.update(runID, started=True, converged=False) atoms = db.get_atoms(id=runID) calc = EAM(potential="/home/davidkl/Documents/EAM/mg-al-set.eam.alloy") atoms.set_calculator(calc) init_energy = atoms.get_potential_energy() logfile = "CE_eam/ceEAM%d.log" % (runID) traj = "CE_eam/ceEAM%d.traj" % (runID) trajObj = Trajectory(traj, 'w', atoms) if (relax_atoms): relaxer = BFGS(atoms, logfile=logfile) relaxer.attach(trajObj) relaxer.run(fmax=0.025) energy = atoms.get_potential_energy() else: res = minimize(target_function, x0=4.05, args=(atoms, )) a = res["x"] atoms = set_cell_parameter(atoms, a) energy = atoms.get_potential_energy() print("Final energy: {}, final a_la: {}".format(energy, a)) row = db.get(id=runID) del db[runID] kvp = row.key_value_pairs kvp["init_energy"] = init_energy runID = db.write(atoms, key_value_pairs=kvp) db.update(runID, converged=True) print("Energy: %.2E eV/atom" % (energy / len(atoms))) print("Initial energy: %.2E eV/atom" % (init_energy / len(atoms)))
def get_alloy_energies(cell_list, position_list, param_file): """ Parameters: cell_list: (list) list of cell arrays position_list: (list) list of positions param_file: (str) name of file containing parameters Returns: energy_list: (list) list of cell energies """ calc = EAM(potential=param_file) energies = [] for i in range(len(cell_list)): cell = cell_list[i] positions = position_list[i] atoms = Atoms(['Fe' for i in range(positions.shape[0])], positions=positions, cell=cell) atoms.set_calculator(calc) energy = atoms.get_potential_energy() energies.append(energy) return energies
def test_eam(): # test to generate an EAM potential file using a simplified # approximation to the Mishin potential Al99.eam.alloy data from scipy.interpolate import InterpolatedUnivariateSpline as spline cutoff = 6.28721 n = 21 rs = np.arange(0, n) * (cutoff / n) rhos = np.arange(0, 2, 2. / n) # generated from # mishin = EAM(potential='../potentials/Al99.eam.alloy') # m_density = mishin.electron_density[0](rs) # m_embedded = mishin.embedded_energy[0](rhos) # m_phi = mishin.phi[0,0](rs) m_density = np.array([ 2.78589606e-01, 2.02694937e-01, 1.45334053e-01, 1.06069912e-01, 8.42517168e-02, 7.65140344e-02, 7.76263116e-02, 8.23214224e-02, 8.53322309e-02, 8.13915861e-02, 6.59095390e-02, 4.28915711e-02, 2.27910928e-02, 1.13713167e-02, 6.05020311e-03, 3.65836583e-03, 2.60587564e-03, 2.06750708e-03, 1.48749693e-03, 7.40019174e-04, 6.21225205e-05 ]) m_embedded = np.array([ 1.04222211e-10, -1.04142633e+00, -1.60359806e+00, -1.89287637e+00, -2.09490167e+00, -2.26456628e+00, -2.40590322e+00, -2.52245359e+00, -2.61385603e+00, -2.67744693e+00, -2.71053295e+00, -2.71110418e+00, -2.69287013e+00, -2.68464527e+00, -2.69204083e+00, -2.68976209e+00, -2.66001244e+00, -2.60122024e+00, -2.51338548e+00, -2.39650817e+00, -2.25058831e+00 ]) m_phi = np.array([ 6.27032242e+01, 3.49638589e+01, 1.79007014e+01, 8.69001383e+00, 4.51545250e+00, 2.83260884e+00, 1.93216616e+00, 1.06795515e+00, 3.37740836e-01, 1.61087890e-02, -6.20816372e-02, -6.51314297e-02, -5.35210341e-02, -5.20950200e-02, -5.51709524e-02, -4.89093894e-02, -3.28051688e-02, -1.13738785e-02, 2.33833655e-03, 4.19132033e-03, 1.68600692e-04 ]) m_densityf = spline(rs, m_density) m_embeddedf = spline(rhos, m_embedded) m_phif = spline(rs, m_phi) a = 4.05 # Angstrom lattice spacing al = bulk('Al', 'fcc', a=a) mishin_approx = EAM( elements=['Al'], embedded_energy=np.array([m_embeddedf]), electron_density=np.array([m_densityf]), phi=np.array([[m_phif]]), cutoff=cutoff, form='alloy', # the following terms are only required to write out a file Z=[13], nr=n, nrho=n, dr=cutoff / n, drho=2. / n, lattice=['fcc'], mass=[26.982], a=[a]) al.calc = mishin_approx mishin_approx_energy = al.get_potential_energy() mishin_approx.write_potential('Al99-test.eam.alloy') mishin_check = EAM(potential='Al99-test.eam.alloy') al.calc = mishin_check mishin_check_energy = al.get_potential_energy() print('Cohesive Energy for Al = ', mishin_approx_energy, ' eV') error = (mishin_approx_energy - mishin_check_energy) / mishin_approx_energy print('read/write check error = ', error) assert abs(error) < 1e-4
from ase.lattice.cubic import FaceCenteredCubic from ase.md.velocitydistribution import MaxwellBoltzmannDistribution from ase.md.verlet import VelocityVerlet from ase.md.langevin import Langevin from ase import units from ase.calculators.eam import EAM from ase.visualize import view, write from ase.io.trajectory import Trajectory calc = EAM(potential='FeNiCr_pt.alloy') size = 5 atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol='Fe', size=(size, size, size), pbc=True, latticeconstant=3.5646) view(atoms) atoms.set_calculator(calc) # MaxwellBoltzmannDistribution(atoms, 300 * units.kB) # dyn = VelocityVerlet(atoms, 5 * units.fs) T = 10 dyn = Langevin(atoms, 5 * units.fs, T * units.kB, 0.002) traj = Trajectory('md.traj', 'w', atoms) dyn.attach(traj.write, interval=50)
# Load the database, row by row, and calculate the cohesive energy. # The cohesive energy is the same as the potential energy since that is # the energy required to separate the atoms. db = connect('../CourseGitRepo/HA5_Al-clusters-initial.db') vibDB = connect('./vib.db', append=False) # Sort the clusters based on number of atoms allClust = list(db.select()) sort = np.argsort([len(clust.numbers) for clust in allClust]) allClust = np.array(allClust)[sort] for clust in allClust: # General info atoms = clust.toatoms() N = len(atoms.positions) # Define calculator - mishin mishin = EAM( potential='../CourseGitRepo/HA5_al_potential.alloy') # Set up EAM atoms.set_calculator(mishin) # Relax structure dyn = BFGS(atoms, trajectory=f'traj/Al{N}.traj') dyn.run(fmax=0.05) # Get vibrational spectrum str1 = f'-------- N={N}' str2 = ' ---------' print(str1 + str2.ljust(40 - len(str1))) ##### Using Vibrations module v = Vibrations(atoms, name=f'./vibs/vib_{N}') if not p.isfile(f'./vibs/vib_{N}.all.pckl'): print('Running vibration calculation') v.run() v.combine() # Combine pickle files
from ase.build import fcc111, add_adsorbate from ase.visualize import view from ase.optimize import BFGS from ase.neb import NEB import numpy as np import matplotlib.pyplot as plt import kernels import gp import struc from gp_calculator import GPCalculator ###EAM Setup, Optimization, and Plotting pot_file = os.environ.get('LAMMPS_POTENTIALS') + '/Al_zhou.eam.alloy' pot_file2 = 'Al.pbe-n-rrkjus_psl.1.0.1.UPF' pseudopotentials = {'Al': pot_file2} zhou = EAM(potential=pot_file) slabEAM = fcc111('Al', size=(2, 2, 3)) add_adsorbate(slabEAM, 'Al', 2, 'hcp') slabEAM.center(vacuum=5.0, axis=2) slabEAM.set_calculator(zhou) print(slabEAM.get_potential_energy()) dyn = BFGS(slabEAM) dyn.run(fmax=0.0001) slab_2EAM = fcc111('Al', size=(2, 2, 3)) add_adsorbate(slab_2EAM, 'Al', 2, 'fcc') slab_2EAM.center(vacuum=5.0, axis=2) slab_2EAM.set_calculator(EAM(potential=pot_file)) dyn = BFGS(slab_2EAM) slab_2EAM.get_potential_energy() print(slab_2EAM.get_potential_energy())
struc_params = { 'species': 'Al', 'cube_lat': 100 * np.eye(3), #super_cell.cell, 'mass_dict': { 'Al': 0.000103642695727 * 27 } } mff_model = MappedForceField(gp_model, grid_params, struc_params) calc = FLARE_Calculator(gp_model, mff_model=mff_model, use_mapping=True) super_cell.set_calculator(calc) # -------------- set up dft calculator ---------------- dft_input = {'label': 'al', 'pseudopotentials': 'Al99.eam.alloy'} dft_calc = EAM(potential=dft_input['pseudopotentials']) #pw_loc = "/n/home08/xiey/q-e/bin/pw.x" #no_cpus = 1 #npool = 1 #pwi_file = dft_input['label'] + '.pwi' #pwo_file = dft_input['label'] + '.pwo' #os.environ['ASE_ESPRESSO_COMMAND'] = 'srun -n {0} --mpi=pmi2 {1} -npool {2} < {3} > {4}'.format(no_cpus, pw_loc, npool, pwi_file, pwo_file) #input_data = dft_input['input_data'] #dft_calc = Espresso(pseudopotentials=dft_input['pseudopotentials'], label=dft_input['label'], # tstress=True, tprnfor=True, nosym=True, # input_data=input_data, kpts=dft_input['kpts']) # -------------- set up otf npt md -------------------- timestep = 1 # fs temperature = 100 externalstress = 0
import numpy as np from ase.calculators.eam import EAM from ase.test.eam_pot import Pt_u3 from ase.build import fcc111 import os # test to read EAM potential from *.eam file (aka funcfl format) - for one element pot_fn = 'Pt_u3.eam' f = open(pot_fn, 'w') f.write(Pt_u3) f.close() eam = EAM(potential='Pt_u3.eam', elements=['Pt']) slab = fcc111('Pt', size=(4, 4, 2), vacuum=10.0) slab.set_calculator(eam) assert (abs(-164.277599313 - slab.get_potential_energy()) < 1E-8) assert (abs(6.36379627645 - np.linalg.norm(slab.get_forces())) < 1E-8) os.remove(pot_fn)
from ase.lattice.cubic import * from ase.lattice.surface import surface from ase.calculators.eam import EAM from ase.visualize import view, write from ase.utils.eos import EquationOfState import matplotlib.pyplot as plt import elastic from ase.optimize import BFGS from ase.build import fcc111 from ase.md.langevin import Langevin from ase import units from ase.io.trajectory import Trajectory # calc = EAM(potential='FeNiCr_pt.alloy') calc = EAM(potential='Fe-Ni.eam.alloy') a = 3.5574 fcc = FaceCenteredCubic('Ni', directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], latticeconstant=a) # slab1 = surface(fcc, (1,1,1), 36) slab1 = fcc111('Fe', size=(20, 20, 30), a=a, orthogonal=True) # slab1 = slab1*(5,5,1) slab1.set_pbc([1, 1, 1]) slab2 = fcc111('Fe', size=(20, 20, 29), a=a, orthogonal=True) #slab2 = surface(fcc, (1,1,1), 35) #slab2 = slab2*(5,5,1)
def test_rescaled_calculator(): """ Test rescaled RescaledCalculator() by computing lattice constant and bulk modulus using fit to equation of state and comparing it to the desired values """ from ase.calculators.eam import EAM from ase.units import GPa # A simple empirical N-body potential for # transition metals by M. W. Finnis & J.E. Sinclair # https://www.tandfonline.com/doi/abs/10.1080/01418618408244210 # using analytical formulation in order to avoid extra file dependence # All the constants are taken from the paper. # Please refer to the paper for more details def pair_potential(r): """ returns the pair potential as a equation 27 in pair_potential r - numpy array with the values of distance to compute the pair function """ # parameters for W c = 3.25 c0 = 47.1346499 c1 = -33.7665655 c2 = 6.2541999 energy = (c0 + c1 * r + c2 * r**2.0) * (r - c)**2.0 energy[r > c] = 0.0 return energy def cohesive_potential(r): """ returns the cohesive potential as a equation 28 in pair_potential r - numpy array with the values of distance to compute the pair function """ # parameters for W d = 4.400224 rho = (r - d)**2.0 rho[r > d] = 0.0 return rho def embedding_function(rho): """ returns energy as a function of electronic density from eq 3 """ A = 1.896373 energy = -A * np.sqrt(rho) return energy cutoff = 4.400224 W_FS = EAM(elements=['W'], embedded_energy=np.array([embedding_function]), electron_density=np.array([[cohesive_potential]]), phi=np.array([[pair_potential]]), cutoff=cutoff, form='fs') # compute MM and QM equations of state def strain(at, e, calc): at = at.copy() at.set_cell((1.0 + e) * at.cell, scale_atoms=True) at.calc = calc v = at.get_volume() e = at.get_potential_energy() return v, e # desired DFT values a0_qm = 3.18556 C11_qm = 522 # pm 15 GPa C12_qm = 193 # pm 5 GPa B_qm = (C11_qm + 2.0 * C12_qm) / 3.0 bulk_at = bulk("W", cubic=True) mm_calc = W_FS eps = np.linspace(-0.01, 0.01, 13) v_mm, E_mm = zip(*[strain(bulk_at, e, mm_calc) for e in eps]) eos_mm = EquationOfState(v_mm, E_mm) v0_mm, E0_mm, B_mm = eos_mm.fit() B_mm /= GPa a0_mm = v0_mm**(1.0 / 3.0) mm_r = RescaledCalculator(mm_calc, a0_qm, B_qm, a0_mm, B_mm) bulk_at = bulk("W", cubic=True, a=a0_qm) v_mm_r, E_mm_r = zip(*[strain(bulk_at, e, mm_r) for e in eps]) eos_mm_r = EquationOfState(v_mm_r, E_mm_r) v0_mm_r, E0_mm_r, B_mm_r = eos_mm_r.fit() B_mm_r /= GPa a0_mm_r = v0_mm_r**(1.0 / 3) # check match of a0 and B after rescaling is adequate # 0.1% error in lattice constant and bulk modulus assert abs((a0_mm_r - a0_qm) / a0_qm) < 1e-3 assert abs((B_mm_r - B_qm) / B_qm) < 1e-3
1.93216616e+00, 1.06795515e+00, 3.37740836e-01, 1.61087890e-02, -6.20816372e-02, -6.51314297e-02, -5.35210341e-02, -5.20950200e-02, -5.51709524e-02, -4.89093894e-02, -3.28051688e-02, -1.13738785e-02, 2.33833655e-03, 4.19132033e-03, 1.68600692e-04]) m_densityf = spline(rs, m_density) m_embeddedf = spline(rhos, m_embedded) m_phif = spline(rs, m_phi) a = 4.05 # Angstrom lattice spacing al = bulk('Al', 'fcc', a=a) mishin_approx = EAM(elements=['Al'], embedded_energy=np.array([m_embeddedf]), electron_density=np.array([m_densityf]), phi=np.array([[m_phif]]), cutoff=cutoff, form='alloy', # the following terms are only required to write out a file Z=[13], nr=n, nrho=n, dr=cutoff / n, drho=2. / n, lattice=['fcc'], mass=[26.982], a=[a]) al.set_calculator(mishin_approx) mishin_approx_energy = al.get_potential_energy() mishin_approx.write_potential('Al99-test.eam.alloy') mishin_check = EAM(potential='Al99-test.eam.alloy') al.set_calculator(mishin_check) mishin_check_energy = al.get_potential_energy() print('Cohesive Energy for Al = ', mishin_approx_energy, ' eV') error = (mishin_approx_energy - mishin_check_energy) / mishin_approx_energy
1.93216616e+00, 1.06795515e+00, 3.37740836e-01, 1.61087890e-02, -6.20816372e-02, -6.51314297e-02, -5.35210341e-02, -5.20950200e-02, -5.51709524e-02, -4.89093894e-02, -3.28051688e-02, -1.13738785e-02, 2.33833655e-03, 4.19132033e-03, 1.68600692e-04]) m_densityf = spline(rs, m_density) m_embeddedf = spline(rhos, m_embedded) m_phif = spline(rs, m_phi) a = 4.05 # Angstrom lattice spacing al = bulk('Al', 'fcc', a=a) mishin_approx = EAM(elements=['Al'], embedded_energy=np.array([m_embeddedf]), electron_density=np.array([m_densityf]), phi=np.array([[m_phif]]), cutoff=cutoff, form='alloy', # the following terms are only required to write out a file Z=[13], nr=n, nrho=n, dr=cutoff / n, drho=2. / n, lattice=['fcc'], mass=[26.982], a=[a]) al.set_calculator(mishin_approx) mishin_approx_energy = al.get_potential_energy() mishin_approx.write_file('Al99-test.eam.alloy') mishin_check = EAM('Al99-test.eam.alloy') al.set_calculator(mishin_check) mishin_check_energy = al.get_potential_energy() print 'Cohesive Energy for Al = ', mishin_approx_energy, ' eV' error = (mishin_approx_energy - mishin_check_energy) / mishin_approx_energy
from ase.io import read, write from ase.calculators.eam import EAM from ase.optimize import BFGS calc = EAM(potential='NiAlH_jea.eam.alloy') atoms = read("input.traj") # input is always input.traj atoms.set_calculator(calc) dyn = BFGS(atoms, logfile="opt.log") dyn.run(fmax=0.05) write("optimized.traj", atoms) # mandatory
# import calculator and set potential from ase.calculators.eam import EAM import os pot_file = os.environ.get('LAMMPS_POTENTIALS') + '/Al_zhou.eam.alloy' zhou = EAM(potential=pot_file) #create structure as FCC surface with addsorbate from ase.build import fcc111, add_adsorbate slab = fcc111('Al', size=(2, 2, 3)) add_adsorbate(slab, 'Al', 2, 'hcp') slab.center(vacuum=5.0, axis=2) #view and set calculator from ase.visualize import view view(slab, viewer='x3d') slab.set_calculator(zhou) slab.get_potential_energy() print(slab.get_calculator()) print(slab.get_potential_energy()) #relax structure from ase.optimize import BFGS dyn = BFGS(slab) dyn.run(fmax=0.0001) #make second endpoint structure, add adatom and relax slab_2 = fcc111('Al', size=(2, 2, 3)) add_adsorbate(slab_2, 'Al', 2, 'fcc') slab_2.center(vacuum=5.0, axis=2) slab_2.set_calculator(EAM(potential=pot_file))
import numpy as np from ase.calculators.eam import EAM from ase.test.eam_pot import Pt_u3 from ase.build import fcc111 from io import StringIO eam = EAM(potential=StringIO(Pt_u3), form='eam', elements=['Pt']) slab = fcc111('Pt', size=(4, 4, 2), vacuum=10.0) slab.set_calculator(eam) assert (abs(-164.277599313 - slab.get_potential_energy()) < 1E-8) assert (abs(6.36379627645 - np.linalg.norm(slab.get_forces())) < 1E-8)