From 285d6e3fc8efc64a97b475df2e6000a3dfa32b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Fr=C3=A9rot?= Date: Wed, 28 Jun 2023 16:02:38 +0200 Subject: [PATCH] fix: added relaxation step to molecule tests for nonaffine + hessian Hessians are still failing, need to understand how to compute for fixed connectivities --- tests/manybody/test_manybody_molecules.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/manybody/test_manybody_molecules.py b/tests/manybody/test_manybody_molecules.py index 62851186..e1d32eff 100644 --- a/tests/manybody/test_manybody_molecules.py +++ b/tests/manybody/test_manybody_molecules.py @@ -22,6 +22,7 @@ import numpy.testing as nt from ase import Atoms +from ase.optimize import FIRE from matscipy.calculators.manybody.newmb import Manybody from matscipy.calculators.manybody.potentials import ( ZeroAngle, ZeroPair, @@ -30,7 +31,8 @@ from matscipy.molecules import Molecules from matscipy.neighbours import MolecularNeighbourhood from matscipy.numerical import ( - numerical_forces, numerical_hessian, numerical_stress + numerical_forces, numerical_hessian, numerical_stress, + numerical_nonaffine_forces ) import pytest @@ -104,6 +106,14 @@ def test_harmonic_bond(co2, molecule): s_ref = numerical_stress(co2, d=1e-6) nt.assert_allclose(co2.get_stress(), s_ref, rtol=1e-8, atol=1e-7) + # Following tests need relaxation + FIRE(co2, logfile=None).run(fmax=1e-9, steps=500) + + # Testing nonaffine forces with finite differences + nf_ref = numerical_nonaffine_forces(co2, d=1e-6) + nf = co2.calc.get_property('nonaffine_forces', co2) + nt.assert_allclose(nf, nf_ref, rtol=1e-8, atol=1e-6) + # Testing hessian h = co2.calc.get_property('hessian', co2).todense() h_ref = numerical_hessian(co2, d=1e-6).todense() @@ -138,6 +148,14 @@ def test_harmonic_angle(co2, molecule): s_ref = numerical_stress(co2, d=1e-6) nt.assert_allclose(s, s_ref, rtol=1e-6, atol=2e-9) + # Following tests need relaxation + FIRE(co2, logfile=None).run(fmax=1e-9, steps=500) + + # Testing nonaffine forces with finite differences + nf_ref = numerical_nonaffine_forces(co2, d=1e-6) + nf = co2.calc.get_property('nonaffine_forces', co2) + nt.assert_allclose(nf, nf_ref, rtol=1e-8, atol=1e-6) + # Testing hessian h = co2.calc.get_property('hessian', co2) h_ref = numerical_hessian(co2, d=1e-4)