Skip to content

Commit 6ec0d6c

Browse files
committed
added some methods for function arguments
1 parent 87cb499 commit 6ec0d6c

File tree

7 files changed

+97
-0
lines changed

7 files changed

+97
-0
lines changed

pycv/PlumedPythonEmbeddedModule.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,16 @@ return toRet;
261261
,"Retuns a ndarray with the values of the arguments")
262262
.def_property_readonly("nargs", &PLMD::pycv::PythonFunction::
263263
getNumberOfArguments,"Get the number of arguments")
264+
.def("difference", &PLMD::pycv::PythonFunction::
265+
difference,"Takes the difference taking into account pbc for argument i",
266+
py::arg("i"),py::arg("x"),py::arg("y"))
267+
.def("bringBackInPbc", &PLMD::pycv::PythonFunction::
268+
bringBackInPbc,"Takes one value and brings it back into the pbc of argument i",
269+
py::arg("i"),py::arg("x"))
270+
//I cannot find a way of testing:
271+
// .def("getProjection", &PLMD::pycv::PythonFunction::
272+
// getProjection,"Get the scalar product between the gradients of two variables",
273+
// py::arg("i"),py::arg("j"))
274+
//to be added and tested getNumberOfArguments
264275
;
265276
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../scripts/test.make
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! FIELDS time fPY.py-difference fPY.py-bringBackInPbc dz
2+
#! SET min_dz 0.0
3+
#! SET max_dz 1.3
4+
0.000000 0.000000 0.000000 0.000000
5+
1.000000 0.300000 0.000000 0.000000
6+
2.000000 -0.400000 0.600000 0.300000
7+
3.000000 -0.100000 0.900000 0.300000
8+
4.000000 0.200000 1.200000 0.300000
9+
5.000000 0.200000 0.000000 0.000000
10+
6.000000 -0.500000 0.500000 0.300000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
type=driver
3+
arg="--plumed plumed.dat --ixyz traj.xyz"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
LOAD GLOBAL FILE=../../../../PythonCVInterface.so
2+
3+
d12c: DISTANCE ATOMS=1,2 COMPONENTS
4+
5+
dz: COMBINE ARG=d12c.z PERIODIC=0.0,1.3
6+
7+
fPY: ...
8+
PYFUNCTION
9+
IMPORT=unitTest
10+
INIT=initForF
11+
CALCULATE=function
12+
ARG=dz
13+
...
14+
15+
PRINT FILE=colvar.out ARG=fPY.py-difference,fPY.py-bringBackInPbc,dz
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
3
2+
100 100 100
3+
X 0 0 0
4+
X 99 0 0
5+
X 99 0 50
6+
3
7+
100 100 100
8+
X 0 0 0
9+
X 0 99 0
10+
X 0 99 50
11+
3
12+
100 100 100
13+
X 0 0 0
14+
X 0 0 99
15+
X 0 0 50
16+
3
17+
100 100 100
18+
X 0 0 0
19+
X 0 99 99
20+
X 50 99 50
21+
3
22+
100 100 100
23+
X 0 0 0
24+
X 99 0 99
25+
X 98 0 50
26+
3
27+
100 100 100
28+
X 0 0 0
29+
X 99 99 0
30+
X 99 98 50
31+
3
32+
100 100 100
33+
X 0 0 0
34+
X 99 99 99
35+
X 99 99 50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import plumedCommunications as PLMD
2+
import numpy
3+
4+
log = open("pydist.log", "w")
5+
6+
print("Imported my pydist+.", file=log)
7+
8+
initForF = {
9+
"COMPONENTS": {
10+
"difference": PLMD.defaults.COMPONENT_NODEV,
11+
"bringBackInPbc": PLMD.defaults.COMPONENT_NODEV,
12+
}
13+
}
14+
15+
16+
def function(action: PLMD.PythonFunction):
17+
arg = action.arguments()
18+
19+
return {
20+
"difference": action.difference(0, action.getStep(), arg[0]),
21+
"bringBackInPbc": action.bringBackInPbc(0, arg[0] * action.getStep()),
22+
}

0 commit comments

Comments
 (0)