Skip to content

Commit

Permalink
added some methods for function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Nov 24, 2023
1 parent 87cb499 commit 6ec0d6c
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pycv/PlumedPythonEmbeddedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,16 @@ return toRet;
,"Retuns a ndarray with the values of the arguments")
.def_property_readonly("nargs", &PLMD::pycv::PythonFunction::
getNumberOfArguments,"Get the number of arguments")
.def("difference", &PLMD::pycv::PythonFunction::
difference,"Takes the difference taking into account pbc for argument i",
py::arg("i"),py::arg("x"),py::arg("y"))
.def("bringBackInPbc", &PLMD::pycv::PythonFunction::
bringBackInPbc,"Takes one value and brings it back into the pbc of argument i",
py::arg("i"),py::arg("x"))
//I cannot find a way of testing:
// .def("getProjection", &PLMD::pycv::PythonFunction::
// getProjection,"Get the scalar product between the gradients of two variables",
// py::arg("i"),py::arg("j"))
//to be added and tested getNumberOfArguments
;
}
1 change: 1 addition & 0 deletions pycv/regtest/pycvfunc/rt-ArgsMethods/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../scripts/test.make
10 changes: 10 additions & 0 deletions pycv/regtest/pycvfunc/rt-ArgsMethods/colvar.out.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! FIELDS time fPY.py-difference fPY.py-bringBackInPbc dz
#! SET min_dz 0.0
#! SET max_dz 1.3
0.000000 0.000000 0.000000 0.000000
1.000000 0.300000 0.000000 0.000000
2.000000 -0.400000 0.600000 0.300000
3.000000 -0.100000 0.900000 0.300000
4.000000 0.200000 1.200000 0.300000
5.000000 0.200000 0.000000 0.000000
6.000000 -0.500000 0.500000 0.300000
3 changes: 3 additions & 0 deletions pycv/regtest/pycvfunc/rt-ArgsMethods/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

type=driver
arg="--plumed plumed.dat --ixyz traj.xyz"
15 changes: 15 additions & 0 deletions pycv/regtest/pycvfunc/rt-ArgsMethods/plumed.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
LOAD GLOBAL FILE=../../../../PythonCVInterface.so

d12c: DISTANCE ATOMS=1,2 COMPONENTS

dz: COMBINE ARG=d12c.z PERIODIC=0.0,1.3

fPY: ...
PYFUNCTION
IMPORT=unitTest
INIT=initForF
CALCULATE=function
ARG=dz
...

PRINT FILE=colvar.out ARG=fPY.py-difference,fPY.py-bringBackInPbc,dz
35 changes: 35 additions & 0 deletions pycv/regtest/pycvfunc/rt-ArgsMethods/traj.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
3
100 100 100
X 0 0 0
X 99 0 0
X 99 0 50
3
100 100 100
X 0 0 0
X 0 99 0
X 0 99 50
3
100 100 100
X 0 0 0
X 0 0 99
X 0 0 50
3
100 100 100
X 0 0 0
X 0 99 99
X 50 99 50
3
100 100 100
X 0 0 0
X 99 0 99
X 98 0 50
3
100 100 100
X 0 0 0
X 99 99 0
X 99 98 50
3
100 100 100
X 0 0 0
X 99 99 99
X 99 99 50
22 changes: 22 additions & 0 deletions pycv/regtest/pycvfunc/rt-ArgsMethods/unitTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import plumedCommunications as PLMD
import numpy

log = open("pydist.log", "w")

print("Imported my pydist+.", file=log)

initForF = {
"COMPONENTS": {
"difference": PLMD.defaults.COMPONENT_NODEV,
"bringBackInPbc": PLMD.defaults.COMPONENT_NODEV,
}
}


def function(action: PLMD.PythonFunction):
arg = action.arguments()

return {
"difference": action.difference(0, action.getStep(), arg[0]),
"bringBackInPbc": action.bringBackInPbc(0, arg[0] * action.getStep()),
}

0 comments on commit 6ec0d6c

Please sign in to comment.