Skip to content

Commit

Permalink
added an extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Oct 18, 2024
1 parent a22dd66 commit b3e9f22
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions plugins/pycv/pythontests/pycvPersistentData
33 changes: 33 additions & 0 deletions plugins/pycv/pythontests/test_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions plugins/pycv/pythontests/test_cv_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit b3e9f22

Please sign in to comment.