From d32b6f4b8b5f1ef0c79d799c69490a5369ec2cc2 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi Date: Fri, 13 Oct 2023 15:33:10 +0200 Subject: [PATCH] Added specific regtest for mklib --- regtest/basic/rt15-mklib/COLVAR.reference | 3 + regtest/basic/rt15-mklib/Distance2.cpp | 75 +++++++++++++++++++ regtest/basic/rt15-mklib/Distance2.h | 37 ++++++++++ regtest/basic/rt15-mklib/Distance2b.cpp | 78 ++++++++++++++++++++ regtest/basic/rt15-mklib/Makefile | 1 + regtest/basic/rt15-mklib/config | 25 +++++++ regtest/basic/rt15-mklib/plumed.dat.template | 8 ++ regtest/basic/rt15-mklib/trajectory.xyz | 20 +++++ 8 files changed, 247 insertions(+) create mode 100644 regtest/basic/rt15-mklib/COLVAR.reference create mode 100644 regtest/basic/rt15-mklib/Distance2.cpp create mode 100644 regtest/basic/rt15-mklib/Distance2.h create mode 100644 regtest/basic/rt15-mklib/Distance2b.cpp create mode 100644 regtest/basic/rt15-mklib/Makefile create mode 100644 regtest/basic/rt15-mklib/config create mode 100644 regtest/basic/rt15-mklib/plumed.dat.template create mode 100644 regtest/basic/rt15-mklib/trajectory.xyz diff --git a/regtest/basic/rt15-mklib/COLVAR.reference b/regtest/basic/rt15-mklib/COLVAR.reference new file mode 100644 index 0000000000..a95e7f5e54 --- /dev/null +++ b/regtest/basic/rt15-mklib/COLVAR.reference @@ -0,0 +1,3 @@ +#! FIELDS time d2 + 0.000000 1.000000 + 0.050000 9.000000 diff --git a/regtest/basic/rt15-mklib/Distance2.cpp b/regtest/basic/rt15-mklib/Distance2.cpp new file mode 100644 index 0000000000..9ab8309533 --- /dev/null +++ b/regtest/basic/rt15-mklib/Distance2.cpp @@ -0,0 +1,75 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2013 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed-code.org for more information. + + This file is part of plumed, version 2.0. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see . ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#include "../Distance2.h" +#include "colvar/Colvar.h" +#include "core/ActionRegister.h" + +#include +#include + +using namespace std; + +namespace PLMD{ + +PLUMED_REGISTER_ACTION(Distance,"DISTANCE2") + +void Distance::registerKeywords( Keywords& keys ){ + Colvar::registerKeywords( keys ); + keys.add("atoms","ATOMS","the pair of atom that we are calculating the distance between"); + keys.addFlag("COMPONENTS",false,"calculate the x, y and z components of the distance separately and store them as label.x, label.y and label.z"); +} + +Distance::Distance(const ActionOptions&ao): +PLUMED_COLVAR_INIT(ao), +components(false), +pbc(true) +{ + vector atoms; + parseAtomList("ATOMS",atoms); + if(atoms.size()!=2) + error("Number of specified atoms should be 2"); + parseFlag("COMPONENTS",components); + bool nopbc=!pbc; + parseFlag("NOPBC",nopbc); + pbc=!nopbc; + checkRead(); + + log.printf(" between atoms %d %d\n",atoms[0].serial(),atoms[1].serial()); + if(pbc) log.printf(" using periodic boundary conditions\n"); + else log.printf(" without periodic boundary conditions\n"); + + + if(!components){ + + addValueWithDerivatives(); setNotPeriodic(); + + } else{ + addComponentWithDerivatives("x"); componentIsNotPeriodic("x"); + addComponentWithDerivatives("y"); componentIsNotPeriodic("y"); + addComponentWithDerivatives("z"); componentIsNotPeriodic("z"); + } + + requestAtoms(atoms); +} + + +} diff --git a/regtest/basic/rt15-mklib/Distance2.h b/regtest/basic/rt15-mklib/Distance2.h new file mode 100644 index 0000000000..ae9a7b4f83 --- /dev/null +++ b/regtest/basic/rt15-mklib/Distance2.h @@ -0,0 +1,37 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2013 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed-code.org for more information. + + This file is part of plumed, version 2.0. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see . ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#include "colvar/Colvar.h" + +namespace PLMD{ + +class Distance : public colvar::Colvar { + bool components; + bool pbc; + +public: + static void registerKeywords( Keywords& keys ); + Distance(const ActionOptions&); +// active methods: + virtual void calculate(); +}; + +} diff --git a/regtest/basic/rt15-mklib/Distance2b.cpp b/regtest/basic/rt15-mklib/Distance2b.cpp new file mode 100644 index 0000000000..c8ca29bd48 --- /dev/null +++ b/regtest/basic/rt15-mklib/Distance2b.cpp @@ -0,0 +1,78 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2013 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed-code.org for more information. + + This file is part of plumed, version 2.0. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see . ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#include "../Distance2.h" +#include "colvar/Colvar.h" +#include "core/ActionRegister.h" + +#include +#include + +using namespace std; + +namespace PLMD{ + +// calculator +void Distance::calculate(){ + + Vector distance; + if(pbc){ + distance=pbcDistance(getPosition(0),getPosition(1)); + } else { + distance=delta(getPosition(0),getPosition(1)); + } + const double value=distance.modulo(); + const double invvalue=1.0/value; + + if(!components){ + + setAtomsDerivatives(0,-invvalue*distance); + setAtomsDerivatives(1,invvalue*distance); + setBoxDerivatives (-invvalue*Tensor(distance,distance)); + setValue (value); + + }else{ + + Value* valuex=getPntrToComponent("x"); + Value* valuey=getPntrToComponent("y"); + Value* valuez=getPntrToComponent("z"); + + setAtomsDerivatives (valuex,0,Vector(-1,0,0)); + setAtomsDerivatives (valuex,1,Vector(+1,0,0)); + setBoxDerivatives (valuex,Tensor(distance,Vector(-1,0,0))); + valuex->set(distance[0]); + + setAtomsDerivatives (valuey,0,Vector(0,-1,0)); + setAtomsDerivatives (valuey,1,Vector(0,+1,0)); + setBoxDerivatives (valuey,Tensor(distance,Vector(0,-1,0))); + valuey->set(distance[1]); + + setAtomsDerivatives (valuez,0,Vector(0,0,-1)); + setAtomsDerivatives (valuez,1,Vector(0,0,+1)); + setBoxDerivatives (valuez,Tensor(distance,Vector(0,0,-1))); + valuez->set(distance[2]); + }; +} + +} + + + diff --git a/regtest/basic/rt15-mklib/Makefile b/regtest/basic/rt15-mklib/Makefile new file mode 100644 index 0000000000..3703b27cea --- /dev/null +++ b/regtest/basic/rt15-mklib/Makefile @@ -0,0 +1 @@ +include ../../scripts/test.make diff --git a/regtest/basic/rt15-mklib/config b/regtest/basic/rt15-mklib/config new file mode 100644 index 0000000000..b07c08b0bf --- /dev/null +++ b/regtest/basic/rt15-mklib/config @@ -0,0 +1,25 @@ +type=driver +plumed_needs="dlopen" +arg="--plumed plumed.dat --trajectory-stride 10 --timestep 0.005 --ixyz trajectory.xyz" + +function plumed_regtest_before(){ + # find the name of the main executable + plumed="${PLUMED_PROGRAM_NAME:-plumed} --no-mpi" + + # find soext + root=$(eval $plumed info --root) + source "$root"/src/config/compile_options.sh + + # replace soext in the plumed.dat file + sed "s/__SOEXT__/$soext/g" plumed.dat.template > plumed.dat + + # testing mklib with multiple arguments + eval $plumed mklib Distance2.cpp Distance2b.cpp + # notice that the library gets its name from the name of the first cpp file + # (Distance2.cpp) + + # move library to make sure plumed does not compile it again from cpp + mv Distance2.$soext Distance3.$soext + + # at this point Distance3.$soext is ready to be LOADed +} diff --git a/regtest/basic/rt15-mklib/plumed.dat.template b/regtest/basic/rt15-mklib/plumed.dat.template new file mode 100644 index 0000000000..e00da8da6f --- /dev/null +++ b/regtest/basic/rt15-mklib/plumed.dat.template @@ -0,0 +1,8 @@ +# This is loading a collective variable on the fly: +LOAD FILE=./Distance3.__SOEXT__ + +d2: DISTANCE2 ATOMS=1,2 + +PRINT FILE=COLVAR ARG=d2 + +ENDPLUMED diff --git a/regtest/basic/rt15-mklib/trajectory.xyz b/regtest/basic/rt15-mklib/trajectory.xyz new file mode 100644 index 0000000000..aa856131c7 --- /dev/null +++ b/regtest/basic/rt15-mklib/trajectory.xyz @@ -0,0 +1,20 @@ +8 +10 0 0 0 10 0 0 0 10 +X 0.5 0.5 0.5 +X 0.5 0.5 9.5 +X 0.5 9.5 0.5 +X 0.5 9.5 9.5 +X 9.5 0.5 0.5 +X 9.5 0.5 9.5 +X 9.5 9.5 0.5 +X 9.5 9.5 9.5 +8 +10 10 0 0 10 10 10 0 10 +X 0.5 0.5 0.5 +X 0.5 0.5 9.5 +X 0.5 9.5 0.5 +X 0.5 9.5 9.5 +X 9.5 0.5 0.5 +X 9.5 0.5 9.5 +X 9.5 9.5 0.5 +X 9.5 9.4 9.5