print('energy error', eerr) print('forces') print(F_ac) print('ref forces') print(F_ac_ref) ferr = np.abs(F_ac - F_ac_ref).max() print('max force error', ferr) fdcheck = False if fdcheck: from ase.calculators.test import numeric_forces F_ac_fd = numeric_forces(mol) print('Self-consistent forces') print(F_ac) print('FD forces') print(F_ac_fd) print() print(repr(F_ac_fd)) print() err = np.abs(F_ac - F_ac_fd).max() print('max err', err) wfs = calc.wfs gd = wfs.gd psit_nG = wfs.kpt_u[0].psit_nG dH_asp = calc.hamiltonian.dH_asp
# Check that rightmost domain is in fact outside range of basis functions from gpaw.mpi import rank, size if rank == 0 and size > 1: assert len(calc.wfs.basis_functions.atom_indices) < len(system) fd = 0 # Values taken from FD calculation below # (Symmetry means only z-component may be nonzero) ref = array([[0.0, 0.0, 4.61734874], [0.0, 0.0, -2.74398046], [0.0, 0.0, 2.74398027], [0.0, 0.0, -4.61734856]]) if fd: from ase.calculators.test import numeric_forces ref = numeric_forces(system, axes=[2], d=0.002) print("Calced") print(F_ac) print("FD") print(ref) print(repr(ref)) err = np.abs(F_ac - ref).max() print("Ref") print(ref) print("Calculated") print(F_ac) print("Max error", err) assert err < 6e-4
from ase import Atoms from ase.calculators.emt import EMT from ase.calculators.test import numeric_forces h2 = Atoms('H2', positions=[(0, 0, 0), (0, 0, 1.1)], calculator=EMT()) f1 = numeric_forces(h2, d=0.0001) f2 = h2.get_forces() assert abs(f1 - f2).max() < 1e-6
print 'Reference result' print F_ac_ref print print 'Error' print err_ac print print 'Max error' print err # ASE uses dx = [+|-] 0.001 by default, # error should be around 2e-3. In fact 4e-3 would probably be acceptable equal(err, 0, 1e-3) # Set boolean to run new FD check fd = False if fd: from ase.calculators.test import numeric_forces calc.set(usesymm=False) F_ac_fd = numeric_forces(system) print 'Self-consistent forces' print F_ac print 'FD' print F_ac_fd print repr(F_ac_fd) print F_ac - F_ac_fd, np.abs(F_ac - F_ac_fd).max() assert np.abs(F_ac - F_ac_fd).max() < 4e-3
# Check that rightmost domain is in fact outside range of basis functions from gpaw.mpi import rank, size if rank == 0 and size > 1: assert len(calc.wfs.basis_functions.atom_indices) < len(system) fd = 0 # Values taken from FD calculation below # (Symmetry means only z-component may be nonzero) ref = array([[0.0, 0.0, 4.61734874], [0.0, 0.0, -2.74398046], [0.0, 0.0, 2.74398027], [0.0, 0.0, -4.61734856]]) if fd: from ase.calculators.test import numeric_forces ref = numeric_forces(system, axes=[2], d=0.002) print 'Calced' print F_ac print 'FD' print ref print repr(ref) err = np.abs(F_ac - ref).max() print 'Ref' print ref print 'Calculated' print F_ac print 'Max error', err assert err < 6e-4
def testforce(system, fortran=False, bj=False): system.set_calculator(D3(fortran=fortran, bj=bj)) f1 = system.get_forces() f2 = numeric_forces(system, d=0.0001) assert abs(f1 - f2).max() < 1e-6
from ase import Atoms from ase.calculators.emt import EMT from ase.calculators.test import numeric_forces h2 = Atoms('H2', positions=[(0, 0, 0), (0, 0, 1.1)], calculator=EMT()) f1 = numeric_forces(h2, d=0.0001) f2 = h2.get_forces() assert abs(f1 - f2).max() < 1e-6 assert (f1 == h2.calc.calculate_numerical_forces(h2, 0.0001)).all()