-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import numpy as np | ||
import plumedCommunications | ||
|
||
|
||
def myInit(_: plumedCommunications.PythonCVInterface): | ||
return{"Value": plumedCommunications.defaults.COMPONENT_NODEV,} | ||
|
||
def plumedCalculate(action: plumedCommunications.PythonCVInterface): | ||
at: np.ndarray = action.getPositions() | ||
return at[0][0]+at[0][1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import numpy as np | ||
import plumedCommunications | ||
|
||
plumedInit={"Value": plumedCommunications.defaults.COMPONENT,} | ||
|
||
def plumedCalculate(action: plumedCommunications.PythonCVInterface): | ||
at: np.ndarray = action.getPositions() | ||
return at[0][0]+at[0][1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import numpy as np | ||
import plumedCommunications | ||
|
||
plumedInit={"Value": plumedCommunications.defaults.COMPONENT,} | ||
|
||
def plumedPrepare(_: plumedCommunications.PythonCVInterface): | ||
toret = {"setAtomRequest": f"1"} | ||
return toret | ||
|
||
|
||
def plumedCalculate(action: plumedCommunications.PythonCVInterface): | ||
at: np.ndarray = action.getPositions() | ||
return at[0][0]+at[0][1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import numpy as np | ||
import plumedCommunications | ||
|
||
plumedInit={"Value": plumedCommunications.defaults.COMPONENT,} | ||
|
||
def myUpdate(_: plumedCommunications.PythonCVInterface): | ||
print("myUpdate") | ||
return {} | ||
|
||
def plumedCalculate(action: plumedCommunications.PythonCVInterface): | ||
at: np.ndarray = action.getPositions() | ||
return at[0][0]+at[0][1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import unittest | ||
import numpy as np | ||
|
||
from utilities_for_test import * | ||
|
||
import os | ||
|
||
THIS_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
class TestPyCV(unittest.TestCase): | ||
def test_INIT(self): | ||
with cd(THIS_DIR): | ||
os.environ["PLUMED_MAXBACKUP"] = "0" | ||
traj, _, num_atoms, box, virial, masses, forces, charges = setUpTraj( | ||
"traj.xyz" | ||
) | ||
plmd = preparePlumed(num_atoms) | ||
|
||
cvPy = create_plumed_var( | ||
plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justInit INIT=myInit" | ||
) | ||
|
||
plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") | ||
|
||
step = 0 | ||
|
||
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") | ||
np.testing.assert_almost_equal(cvPy, 10.0, decimal=4) | ||
|
||
def test_INITDICT(self): | ||
with cd(THIS_DIR): | ||
os.environ["PLUMED_MAXBACKUP"] = "0" | ||
traj, _, num_atoms, box, virial, masses, forces, charges = setUpTraj( | ||
"traj.xyz" | ||
) | ||
plmd = preparePlumed(num_atoms) | ||
|
||
cvPy = create_plumed_var( | ||
plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justInitDict" | ||
) | ||
|
||
plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") | ||
|
||
step = 0 | ||
|
||
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") | ||
np.testing.assert_almost_equal(cvPy, 10.0, decimal=4) | ||
|
||
def test_UPDATE(self): | ||
with cd(THIS_DIR): | ||
os.environ["PLUMED_MAXBACKUP"] = "0" | ||
traj, _, num_atoms, box, virial, masses, forces, charges = setUpTraj( | ||
"traj.xyz" | ||
) | ||
plmd = preparePlumed(num_atoms) | ||
|
||
cvPy = create_plumed_var( | ||
plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justUpdate UPDATE=myUpdate" | ||
) | ||
|
||
plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") | ||
|
||
step = 0 | ||
|
||
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") | ||
np.testing.assert_almost_equal(cvPy, 10.0, decimal=4) | ||
|
||
def test_PREPARE(self): | ||
with cd(THIS_DIR): | ||
os.environ["PLUMED_MAXBACKUP"] = "0" | ||
traj, _, num_atoms, box, virial, masses, forces, charges = setUpTraj( | ||
"traj.xyz" | ||
) | ||
plmd = preparePlumed(num_atoms) | ||
#atoms=4 but the module choses 1 | ||
cvPy = create_plumed_var( | ||
plmd, "cvPy", "PYCVINTERFACE ATOMS=4 IMPORT=justPrepare PREPARE=plumedPrepare") | ||
plmd.cmd("readInputLine", "PRINT FILE=colvar.out ARG=*") | ||
# Open an output file | ||
|
||
step = 0 | ||
|
||
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") | ||
|
||
np.testing.assert_almost_equal(cvPy, 5.0, decimal=4) | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
# Output to four decimal places only | ||
np.set_printoptions(precision=4) | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters