Skip to content

Commit

Permalink
more powerful (and somehow correct) test
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Nov 23, 2023
1 parent 67311eb commit 78b7679
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 14 deletions.
10 changes: 5 additions & 5 deletions pycv/regtest/pycvcomm/rt-Coordination/colvar.out.reference
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! FIELDS time cvPY coord diff
0.000000 1.833292 1.833292 -0.000000
1.000000 0.051942 0.051942 -0.000000
2.000000 0.004564 0.004564 -0.000000
3.000000 0.051942 0.051942 -0.000000
4.000000 1.833292 1.833292 -0.000000
0.000000 0.054853 0.054853 -0.000000
1.000000 0.000648 0.000648 0.000000
2.000000 0.000000 0.000000 0.000000
3.000000 0.000648 0.000648 0.000000
4.000000 0.054853 0.054853 -0.000000
8 changes: 8 additions & 0 deletions pycv/regtest/pycvcomm/rt-Coordination/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
type=driver
arg="--plumed plumed.dat --ixyz traj.xyz"

plumed_regtest_after() {
{
head -1 deriv | awk '{printf "%s %s %s %s %s-%s\n" , $1, $2,$3,$4,$5,$6 }'
#I'm giving some(a LOT OF) space to the floating point precision
awk 'function abs(v) {return v < 0 ? -v : v} NR>1{print $1, $2, 0.01 < abs($3-$4) } ' <deriv
} >deriv_delta
}
166 changes: 166 additions & 0 deletions pycv/regtest/pycvcomm/rt-Coordination/deriv_delta.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#! FIELDS time parameter cvPY-coord
0.000000 0 0
0.000000 1 0
0.000000 2 0
0.000000 3 0
0.000000 4 0
0.000000 5 0
0.000000 6 0
0.000000 7 0
0.000000 8 0
0.000000 9 0
0.000000 10 0
0.000000 11 0
0.000000 12 0
0.000000 13 0
0.000000 14 0
0.000000 15 0
0.000000 16 0
0.000000 17 0
0.000000 18 0
0.000000 19 0
0.000000 20 0
0.000000 21 0
0.000000 22 0
0.000000 23 0
0.000000 24 0
0.000000 25 0
0.000000 26 0
0.000000 27 0
0.000000 28 0
0.000000 29 0
0.000000 30 0
0.000000 31 0
0.000000 32 0
1.000000 0 0
1.000000 1 0
1.000000 2 0
1.000000 3 0
1.000000 4 0
1.000000 5 0
1.000000 6 0
1.000000 7 0
1.000000 8 0
1.000000 9 0
1.000000 10 0
1.000000 11 0
1.000000 12 0
1.000000 13 0
1.000000 14 0
1.000000 15 0
1.000000 16 0
1.000000 17 0
1.000000 18 0
1.000000 19 0
1.000000 20 0
1.000000 21 0
1.000000 22 0
1.000000 23 0
1.000000 24 0
1.000000 25 0
1.000000 26 0
1.000000 27 0
1.000000 28 0
1.000000 29 0
1.000000 30 0
1.000000 31 0
1.000000 32 0
2.000000 0 0
2.000000 1 0
2.000000 2 0
2.000000 3 0
2.000000 4 0
2.000000 5 0
2.000000 6 0
2.000000 7 0
2.000000 8 0
2.000000 9 0
2.000000 10 0
2.000000 11 0
2.000000 12 0
2.000000 13 0
2.000000 14 0
2.000000 15 0
2.000000 16 0
2.000000 17 0
2.000000 18 0
2.000000 19 0
2.000000 20 0
2.000000 21 0
2.000000 22 0
2.000000 23 0
2.000000 24 0
2.000000 25 0
2.000000 26 0
2.000000 27 0
2.000000 28 0
2.000000 29 0
2.000000 30 0
2.000000 31 0
2.000000 32 0
3.000000 0 0
3.000000 1 0
3.000000 2 0
3.000000 3 0
3.000000 4 0
3.000000 5 0
3.000000 6 0
3.000000 7 0
3.000000 8 0
3.000000 9 0
3.000000 10 0
3.000000 11 0
3.000000 12 0
3.000000 13 0
3.000000 14 0
3.000000 15 0
3.000000 16 0
3.000000 17 0
3.000000 18 0
3.000000 19 0
3.000000 20 0
3.000000 21 0
3.000000 22 0
3.000000 23 0
3.000000 24 0
3.000000 25 0
3.000000 26 0
3.000000 27 0
3.000000 28 0
3.000000 29 0
3.000000 30 0
3.000000 31 0
3.000000 32 0
4.000000 0 0
4.000000 1 0
4.000000 2 0
4.000000 3 0
4.000000 4 0
4.000000 5 0
4.000000 6 0
4.000000 7 0
4.000000 8 0
4.000000 9 0
4.000000 10 0
4.000000 11 0
4.000000 12 0
4.000000 13 0
4.000000 14 0
4.000000 15 0
4.000000 16 0
4.000000 17 0
4.000000 18 0
4.000000 19 0
4.000000 20 0
4.000000 21 0
4.000000 22 0
4.000000 23 0
4.000000 24 0
4.000000 25 0
4.000000 26 0
4.000000 27 0
4.000000 28 0
4.000000 29 0
4.000000 30 0
4.000000 31 0
4.000000 32 0
3 changes: 1 addition & 2 deletions pycv/regtest/pycvcomm/rt-Coordination/plumed.dat
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ LOAD GLOBAL FILE=../../../../PythonCVInterface.so

cvPY: ...
PYCVINTERFACE
GROUPA=1-4
IMPORT=pyCOORDINATION
CALCULATE=pyCoord
...

coord: COORDINATION GROUPA=1-4 R_0=1.0
coord: COORDINATION GROUPA=@mdatoms,@mdatoms R_0=0.4

diff: CUSTOM ARG=cvPY,coord FUNC=y-x PERIODIC=NO

Expand Down
24 changes: 17 additions & 7 deletions pycv/regtest/pycvcomm/rt-Coordination/pyCOORDINATION.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
N: int = 6
M: int = 12
D0: float = 0.0
R0: float = 1.0
R0: float = 0.4
INVR0: float = 1.0 / R0
DMAX = D0 + R0 * (0.00001 ** (1.0 / (N - M)))
STRETCH = 1.0
Expand All @@ -35,7 +35,7 @@ def switch(d: np.ndarray) -> np.ndarray:
WhereToCalc = d < DMAX # & d > D0
# print(f"{dfunc=}", file=log)
# not doinf d-D0 for now, so no need for rdist<=0
ret[WhereToCalc], dfunc[WhereToCalc] = jaxSwitch(d)
ret[WhereToCalc], dfunc[WhereToCalc] = jaxSwitch(d[WhereToCalc])
return ret, dfunc


Expand All @@ -58,13 +58,20 @@ def pyCoord(action: plumedCommunications.PythonCVInterface):
assert nl.size() == ((nat - 1) * nat) // 2
pbc = action.getPbc()
couples = nl.getClosePairs()

absoluteIndexes=[]
#not so fast, but speed here is not important
for i in action.absoluteIndexes:
absoluteIndexes.append(i.index)
absoluteIndexes=np.array(absoluteIndexes)
#sameIndex = np.where(absoluteIndexes[couples[:, 0]]==absoluteIndexes[couples[:, 1]])
sameIndex = absoluteIndexes[couples[:, 0]]==absoluteIndexes[couples[:, 1]]
d = atoms[couples[:, 0]] - atoms[couples[:, 1]]
# print(f"before {d}",file=log)
d = pbc.apply(d)
# print(f"after {d}",file=log)
# from here we are in "pure python"
dist = np.linalg.norm(d, axis=1)

dist[sameIndex] += DMAX*2.0

sw, dfunc = switch(dist)
dev = np.zeros_like(atoms)

Expand All @@ -81,5 +88,8 @@ def pyCoord(action: plumedCommunications.PythonCVInterface):

return np.sum(sw), dev, virial


plumedInit = {"Value": plumedCommunications.defaults.COMPONENT}
#this tests also the concatenating special keywords
plumedInit = {
"Value": plumedCommunications.defaults.COMPONENT,
"GROUPA": "@mdatoms,@mdatoms",
}

0 comments on commit 78b7679

Please sign in to comment.