From 78b7679d81973d5efeeee143b7e05594a47b963c Mon Sep 17 00:00:00 2001 From: Daniele Rapetti <5535617+Iximiel@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:53:58 +0100 Subject: [PATCH] more powerful (and somehow correct) test --- .../rt-Coordination/colvar.out.reference | 10 +- pycv/regtest/pycvcomm/rt-Coordination/config | 8 + .../rt-Coordination/deriv_delta.reference | 166 ++++++++++++++++++ .../pycvcomm/rt-Coordination/plumed.dat | 3 +- .../rt-Coordination/pyCOORDINATION.py | 24 ++- 5 files changed, 197 insertions(+), 14 deletions(-) create mode 100644 pycv/regtest/pycvcomm/rt-Coordination/deriv_delta.reference diff --git a/pycv/regtest/pycvcomm/rt-Coordination/colvar.out.reference b/pycv/regtest/pycvcomm/rt-Coordination/colvar.out.reference index e1673a0b74..bbbec97bca 100644 --- a/pycv/regtest/pycvcomm/rt-Coordination/colvar.out.reference +++ b/pycv/regtest/pycvcomm/rt-Coordination/colvar.out.reference @@ -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 diff --git a/pycv/regtest/pycvcomm/rt-Coordination/config b/pycv/regtest/pycvcomm/rt-Coordination/config index 2893c90964..b8fdbcf9a4 100644 --- a/pycv/regtest/pycvcomm/rt-Coordination/config +++ b/pycv/regtest/pycvcomm/rt-Coordination/config @@ -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_delta +} \ No newline at end of file diff --git a/pycv/regtest/pycvcomm/rt-Coordination/deriv_delta.reference b/pycv/regtest/pycvcomm/rt-Coordination/deriv_delta.reference new file mode 100644 index 0000000000..ca9bc7a311 --- /dev/null +++ b/pycv/regtest/pycvcomm/rt-Coordination/deriv_delta.reference @@ -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 diff --git a/pycv/regtest/pycvcomm/rt-Coordination/plumed.dat b/pycv/regtest/pycvcomm/rt-Coordination/plumed.dat index 0343599479..d2bb02e14e 100644 --- a/pycv/regtest/pycvcomm/rt-Coordination/plumed.dat +++ b/pycv/regtest/pycvcomm/rt-Coordination/plumed.dat @@ -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 diff --git a/pycv/regtest/pycvcomm/rt-Coordination/pyCOORDINATION.py b/pycv/regtest/pycvcomm/rt-Coordination/pyCOORDINATION.py index 747da8afd1..3a916f91f0 100644 --- a/pycv/regtest/pycvcomm/rt-Coordination/pyCOORDINATION.py +++ b/pycv/regtest/pycvcomm/rt-Coordination/pyCOORDINATION.py @@ -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 @@ -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 @@ -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) @@ -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", +}