#!/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 import write import numpy as np import os np.set_printoptions(precision=3, suppress=True) atoms = Icosahedron('Pt', noshells=2) calc = Aims(label='cluster/pt-isosahedron-2-relax', xc='pbe', spin='none', relativistic = 'atomic_zora scalar', sc_accuracy_rho=1e-4, sc_accuracy_eev=1e-2, sc_accuracy_etot=1e-5, sc_iter_limit=100, relax_geometry = 'bfgs 1.e-2') atoms.set_calculator(calc) print('energy = {0} eV'.format(atoms.get_potential_energy())) print('Forces') print('=======') print(atoms.get_forces())
from numpy.linalg import norm 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) E = ar_nc.get_potential_energy() F = ar_nc.get_forces() assert abs(E - -0.47) < 1E-2 assert abs(norm(F) - 0.0574) < 1E-4 assert abs(norm(ar_nc.positions) - 23.588) < 1E-3 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)
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)
import numpy as np 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['mass'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] calc = LAMMPS(specorder=['Ar'], parameters=params) ar_nc.set_calculator(calc) E = ar_nc.get_potential_energy() F = ar_nc.get_forces() assert abs(E - -0.47) < 1E-2 assert abs(np.linalg.norm(F) - 0.0574) < 1E-4 dyn = LBFGS(ar_nc, force_consistent=False) dyn.run(fmax=1E-6) E = round(ar_nc.get_potential_energy(), 2) F = ar_nc.get_forces() assert abs(E - -0.48) < 1E-2 assert abs(np.linalg.norm(F) - 0.0) < 1E-5
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) 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(), calc.calculate_numerical_forces(ar_nc), 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)