def test_fake_ase_opt(): atoms = Icosahedron("Ar", noshells=2, latticeconstant=3) atoms.set_calculator(FakeASE(LennardJones())) dyn = BFGS(atoms) dyn.run(fmax=0.0005) assert dyn.converged() assert dyn.get_number_of_steps() == 14 assert np.linalg.norm(dyn.f0) == pytest.approx(0.0041872094)
def test_lennard_jones(): atoms = Icosahedron("Ar", noshells=2, latticeconstant=3) atoms.set_calculator(ase_LJ()) ase_forces = atoms.get_forces() ase_energy = atoms.get_potential_energy() coords = atoms.positions.flatten() geom = Geometry(atoms.get_chemical_symbols(), coords / BOHR2ANG) geom.set_calculator(LennardJones()) pysis_energy = geom.energy assert pysis_energy == pytest.approx(ase_energy) pysis_forces = geom.forces / BOHR2ANG np.testing.assert_allclose(pysis_forces, ase_forces.flatten(), atol=1e-15)
def test_fake_ase(): # pysisyphus pysis_calc = LennardJones() ase_calc = FakeASE(pysis_calc) # ASE atoms, pysisyphus calculator atoms_pysis = Icosahedron("Ar", noshells=2, latticeconstant=3) # ASE atoms, ASE calculator atoms_ase = atoms_pysis.copy() atoms_pysis.set_calculator(ase_calc) atoms_ase.set_calculator(ase_LJ()) pysis_forces = atoms_pysis.get_forces() ase_forces = atoms_ase.get_forces() np.testing.assert_allclose(pysis_forces, ase_forces, atol=1e-15)
def test_Ar_minimize_multistep(): from ase.calculators.lammpsrun import LAMMPS from ase.cluster.icosahedron import Icosahedron from ase.data import atomic_numbers, atomic_masses from numpy.testing import assert_allclose ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True params = {} params['pair_style'] = 'lj/cut 8.0' params['pair_coeff'] = ['1 1 0.0108102 3.345'] params['masses'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] with LAMMPS(specorder=['Ar'], **params) as calc: ar_nc.set_calculator(calc) F1_numer = calc.calculate_numerical_forces(ar_nc) assert_allclose(ar_nc.get_potential_energy(), -0.468147667942117, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), F1_numer, atol=1e-4, rtol=1e-4) params['minimize'] = '1.0e-15 1.0e-6 2000 4000' # add minimize calc.parameters = params # set_atoms=True to read final coordinates after minimization calc.run(set_atoms=True) # get final coordinates after minimization ar_nc.set_positions(calc.atoms.positions) assert_allclose(ar_nc.get_potential_energy(), -0.4791815887032201, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4)
def test_Ar_minimize(): from ase.calculators.lammpsrun import LAMMPS from ase.cluster.icosahedron import Icosahedron from ase.data import atomic_numbers, atomic_masses from numpy.testing import assert_allclose from ase.optimize import LBFGS ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True params = {} params['pair_style'] = 'lj/cut 8.0' params['pair_coeff'] = ['1 1 0.0108102 3.345'] params['masses'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] with LAMMPS(specorder=['Ar'], **params) as calc: ar_nc.set_calculator(calc) assert_allclose(ar_nc.get_potential_energy(), -0.468147667942117, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4) dyn = LBFGS(ar_nc, force_consistent=False) dyn.run(fmax=1E-6) assert_allclose(ar_nc.get_potential_energy(), -0.4791815886953914, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4)
#!/usr/bin/env python from ase import Atoms, Atom from ase.calculators.aims import Aims, AimsCube from ase.cluster.icosahedron import Icosahedron from ase.io.aims import read_aims from ase.optimize.basin import BasinHopping from ase.optimize import LBFGS import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt atoms = Icosahedron('Pt', noshells=1) calc = Aims(label='cluster/pt-isosahedron-1-bh', xc='pbe', spin='none', relativistic = 'atomic_zora scalar', sc_accuracy_etot=1e-5, sc_accuracy_eev=1e-3, sc_accuracy_rho=1e-4, sc_accuracy_forces=1e-3) atoms.set_calculator(calc) bh = BasinHopping(atoms) bh.run(temperature=100 * kB, # 'temperature' to overcome barriers dr=0.5, # maximal stepwidth optimizer=LBFGS, # optimizer to find local minima fmax=0.1# maximal force for the optimizer )
from ase.data import atomic_numbers, atomic_masses from numpy.testing import assert_allclose from ase.optimize import LBFGS ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True params = {} params['pair_style'] = 'lj/cut 8.0' params['pair_coeff'] = ['1 1 0.0108102 3.345'] params['masses'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] calc = LAMMPS(specorder=['Ar'], **params) ar_nc.set_calculator(calc) assert_allclose(ar_nc.get_potential_energy(), -0.468147667942117, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4) dyn = LBFGS(ar_nc, force_consistent=False) dyn.run(fmax=1E-6) assert_allclose(ar_nc.get_potential_energy(), -0.4791815886953914,