def relax(input_atoms, ref_db): atoms_string = input_atoms.get_chemical_symbols() # Open connection to the database with reference data db = connect(ref_db) # Load our model structure which is just FCC atoms = FaceCenteredCubic('X', latticeconstant=1.) atoms.set_chemical_symbols(atoms_string) # Compute the average lattice constant of the metals in this individual # and the sum of energies of the constituent metals in the fcc lattice # we will need this for calculating the heat of formation a = 0 ei = 0 for m in set(atoms_string): dct = db.get(metal=m) count = atoms_string.count(m) a += count * dct.latticeconstant ei += count * dct.energy_per_atom a /= len(atoms_string) atoms.set_cell([a, a, a], scale_atoms=True) # Since calculations are extremely fast with EMT we can also do a volume # relaxation atoms.calc = EMT() eps = 0.05 volumes = (a * np.linspace(1 - eps, 1 + eps, 9))**3 energies = [] for v in volumes: atoms.set_cell([v**(1. / 3)] * 3, scale_atoms=True) energies.append(atoms.get_potential_energy()) eos = EquationOfState(volumes, energies) v1, ef, B = eos.fit() latticeconstant = v1**(1. / 3) # Calculate the heat of formation by subtracting ef with ei hof = (ef - ei) / len(atoms) # Place the calculated parameters in the info dictionary of the # input_atoms object input_atoms.info['key_value_pairs']['hof'] = hof # Raw score must always be set # Use one of the following two; they are equivalent input_atoms.info['key_value_pairs']['raw_score'] = -hof # set_raw_score(input_atoms, -hof) input_atoms.info['key_value_pairs']['latticeconstant'] = latticeconstant # Setting the atoms_string directly for easier analysis atoms_string = ''.join(input_atoms.get_chemical_symbols()) input_atoms.info['key_value_pairs']['atoms_string'] = atoms_string
def test_calcenergy(self): atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol="Cu", size=(3, 3, 3), pbc=True) atoms.calc = EMT() ekin, epot = calcenergy(atoms) if ekin is not None and epot is not None: self.assertTrue(True) else: self.assertTrue(False)
def test_energy_forces_stress(): """ To test that the calculator can produce correct energy and forces. This is done by comparing the energy for an FCC argon lattice with an example model to the known value; the forces/stress returned by the model are compared to numerical estimates via finite difference. """ import numpy as np from pytest import importorskip importorskip('kimpy') from ase.calculators.kim import KIM from ase.lattice.cubic import FaceCenteredCubic # Create an FCC atoms crystal atoms = FaceCenteredCubic( directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], size=(1, 1, 1), symbol="Ar", pbc=(1, 0, 0), latticeconstant=3.0, ) # Perturb the x coordinate of the first atom by less than the cutoff distance atoms.positions[0, 0] += 0.01 calc = KIM("ex_model_Ar_P_Morse_07C") atoms.calc = calc # Get energy and analytical forces/stress from KIM model energy = atoms.get_potential_energy() forces = atoms.get_forces() stress = atoms.get_stress() # Previously computed energy for this configuration for this model energy_ref = 19.7196709065 # eV # Compute forces and virial stress numerically forces_numer = calc.calculate_numerical_forces(atoms, d=0.0001) stress_numer = calc.calculate_numerical_stress(atoms, d=0.0001, voigt=True) tol = 1e-6 assert np.isclose(energy, energy_ref, tol) assert np.allclose(forces, forces_numer, tol) assert np.allclose(stress, stress_numer, tol) # This has been known to segfault atoms.set_pbc(True) atoms.get_potential_energy()
def test_lammpslib_change_cell_bcs(factory, lattice_params, calc_params_NiH): """Test that a change in unit cell boundary conditions is handled correctly by lammpslib""" atoms = FaceCenteredCubic(**lattice_params) calc = factory.calc(**calc_params_NiH) atoms.calc = calc energy_ppp_ref = -142.400000403 energy_ppp = atoms.get_potential_energy() print("Computed energy with boundary ppp = {}".format(energy_ppp)) assert energy_ppp == pytest.approx(energy_ppp_ref, rel=1e-4) atoms.set_pbc((False, False, True)) energy_ssp_ref = -114.524625705 energy_ssp = atoms.get_potential_energy() print("Computed energy with boundary ssp = {}".format(energy_ssp)) assert energy_ssp == pytest.approx(energy_ssp_ref, rel=1e-4)
def run_md(): # Use Asap for a huge performance increase if it is installed use_asap = True if use_asap: from asap3 import EMT size = 10 else: from ase.calculators.emt import EMT size = 3 # Set up a crystal atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol="Cu", size=(size, size, size), pbc=True) # Describe the interatomic interactions with the Effective Medium Theory atoms.calc = EMT() # Set the momenta corresponding to T=300K MaxwellBoltzmannDistribution(atoms, 300 * units.kB) # We want to run MD with constant energy using the VelocityVerlet algorithm. dyn = VelocityVerlet(atoms, 5 * units.fs) # 5 fs time step. traj = Trajectory('cu.traj', 'w', atoms) dyn.attach(traj.write, interval=10) def printenergy(a=atoms): # store a reference to atoms in the definition. epot, ekin = calcenergy(a) print('Energy per atom: Epot = %.3feV Ekin = %.3feV (T=%3.0fK) ' 'Etot = %.3feV' % (epot, ekin, ekin / (1.5 * units.kB), epot + ekin)) # Now run the dynamics dyn.attach(printenergy, interval=10) printenergy() dyn.run(200)
def test_lammpslib_change_cell_bcs(): # test that a change in unit cell boundary conditions is # handled correctly by lammpslib import numpy as np from ase.calculators.lammpslib import LAMMPSlib from ase.lattice.cubic import FaceCenteredCubic cmds = ["pair_style eam/alloy", "pair_coeff * * NiAlH_jea.eam.alloy Ni H"] lammps = LAMMPSlib(lmpcmds=cmds, atom_types={ 'Ni': 1, 'H': 2 }, log_file='test.log', keep_alive=True) atoms = FaceCenteredCubic(size=(2, 2, 2), latticeconstant=3.52, symbol="Ni", pbc=True) atoms.calc = lammps energy_ppp_ref = -142.400000403 energy_ppp = atoms.get_potential_energy() print("Computed energy with boundary ppp = {}".format(energy_ppp)) np.testing.assert_allclose(energy_ppp, energy_ppp_ref, atol=1e-4, rtol=1e-4) atoms.set_pbc((False, False, True)) energy_ssp_ref = -114.524625705 energy_ssp = atoms.get_potential_energy() print("Computed energy with boundary ssp = {}".format(energy_ssp)) np.testing.assert_allclose(energy_ssp, energy_ssp_ref, atol=1e-4, rtol=1e-4)
if use_asap: from asap3 import EMT size = 10 else: from ase.calculators.emt import EMT size = 3 # Set up a crystal atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol="Cu", size=(size, size, size), pbc=True) # Describe the interatomic interactions with the Effective Medium Theory atoms.calc = EMT() # Set the momenta corresponding to T=300K MaxwellBoltzmannDistribution(atoms, 300 * units.kB) # We want to run MD with constant energy using the VelocityVerlet algorithm. dyn = VelocityVerlet(atoms, 5 * units.fs) # 5 fs time step. def printenergy(a=atoms): # store a reference to atoms in the definition. """Function to print the potential, kinetic and total energy.""" epot = a.get_potential_energy() / len(a) ekin = a.get_kinetic_energy() / len(a) print('Energy per atom: Epot = %.3feV Ekin = %.3feV (T=%3.0fK) ' 'Etot = %.3feV' % (epot, ekin, ekin / (1.5 * units.kB), epot + ekin))
from ase.lattice.cubic import FaceCenteredCubic from ase.calculators.kim.kim import KIM atoms = FaceCenteredCubic(symbol='Ar', latticeconstant=5.25, size=(1, 1, 1)) calc = KIM('LJ_ElliottAkerson_2015_Universal__MO_959249795837_003') atoms.calc = calc energy = atoms.get_potential_energy() print('Potential energy: {} eV'.format(energy))
from ase.lattice.cubic import FaceCenteredCubic from gpaw import GPAW, PW element = 'Pt' atoms = FaceCenteredCubic(symbol=element, size=(2, 2, 2), directions=[[1, 1, 0], [-1, 1, 0], [0, 0, 1]]) del atoms[4] del atoms[3] del atoms[2] h = 0.16 kpts = (8, 8, 4) ecut = 800 xc1 = 'PBE' atoms.calc = GPAW(mode=PW(ecut=ecut), kpts=kpts, xc=xc1) ncpus = 8
from ase.lattice.cubic import FaceCenteredCubic from gpaw import GPAW, PW element = 'Pt' atoms = FaceCenteredCubic(symbol=element, size=(2, 2, 2), directions=[[1, 1, 0], [-1, 1, 0], [0, 0, 1]]) del atoms[4] del atoms[3] del atoms[2] h = 0.16 kpts=(8, 8, 4) ecut = 800 xc1 = 'PBE' atoms.calc = GPAW(mode=PW(ecut=ecut), kpts=kpts, xc=xc1) ncpus = 8