From b3e9f22df0955fe22c7e010ce4bce7549df416a9 Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:18:58 +0200 Subject: [PATCH] added an extra test --- plugins/pycv/pythontests/pycvPersistentData | 1 + plugins/pycv/pythontests/test_cv.py | 33 +++++++++++++++++++++ plugins/pycv/pythontests/test_cv_calls.py | 9 +++--- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 120000 plugins/pycv/pythontests/pycvPersistentData diff --git a/plugins/pycv/pythontests/pycvPersistentData b/plugins/pycv/pythontests/pycvPersistentData new file mode 120000 index 0000000000..e74d2380e4 --- /dev/null +++ b/plugins/pycv/pythontests/pycvPersistentData @@ -0,0 +1 @@ +../regtest/pycvcomm/rt-persistentData/pycvPersistentData \ No newline at end of file diff --git a/plugins/pycv/pythontests/test_cv.py b/plugins/pycv/pythontests/test_cv.py index 44f78224a5..7d0ddc1631 100644 --- a/plugins/pycv/pythontests/test_cv.py +++ b/plugins/pycv/pythontests/test_cv.py @@ -160,6 +160,39 @@ def test_newFrameNewAtom(self): np.testing.assert_almost_equal(cvPy, step + 1.0, decimal=4) + def test_loadAmodule_and_persistData(self): + """This test loads a module that is a directory and stores some data within plumed""" + with cd(THIS_DIR): + os.environ["PLUMED_MAXBACKUP"] = "0" + traj, num_frames, num_atoms, box, virial, masses, forces, charges = ( + setUpTraj("trajnewFrameNewAtom.xyz") + ) + plmd = preparePlumed(num_atoms) + + cvPy = create_plumed_var( + plmd, + "cvPy", + "PYCVINTERFACE ATOMS=@mdatoms IMPORT=pycvPersistentData CALCULATE=pydist INIT=pyinit", + ) + + plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") + + # Now analyze the trajectory + for step in range(0, num_frames): + plmd.cmd("setStep", step) + plmd.cmd("setBox", box) + plmd.cmd("setMasses", masses) + plmd.cmd("setCharges", charges) + plmd.cmd("setPositions", traj[step]) + plmd.cmd("setForces", forces) + plmd.cmd("setVirial", virial) + plmd.cmd("calc") + # this cv sums the number of the step till now: + # to future me: "//" is integer (floor) division + np.testing.assert_almost_equal( + cvPy, ((step) * (step + 1)) // 2, decimal=4 + ) + if __name__ == "__main__": # Output to four decimal places only diff --git a/plugins/pycv/pythontests/test_cv_calls.py b/plugins/pycv/pythontests/test_cv_calls.py index d32264cc1e..49ec3efd10 100644 --- a/plugins/pycv/pythontests/test_cv_calls.py +++ b/plugins/pycv/pythontests/test_cv_calls.py @@ -94,9 +94,12 @@ def test_PREPARE(self): "traj.xyz" ) plmd = preparePlumed(num_atoms) - #atoms=4 but the module choses 1 + # atoms=4 but the module choses 1 cvPy = create_plumed_var( - plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justPrepare PREPARE=plumedPrepare") + plmd, + "cvPy", + "PYCVINTERFACE ATOMS=4 IMPORT=justPrepare PREPARE=plumedPrepare", + ) plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") # Open an output file @@ -114,8 +117,6 @@ def test_PREPARE(self): np.testing.assert_almost_equal(cvPy, 5.0, decimal=4) - - if __name__ == "__main__": # Output to four decimal places only np.set_printoptions(precision=4)