Skip to content

Commit

Permalink
Merge pull request plumed#949 from Iximiel/warningToMklib
Browse files Browse the repository at this point in the history
Proposal for mklib.sh modification
  • Loading branch information
GiovanniBussi authored Jun 21, 2023
2 parents a41a920 + 05a6feb commit abdbd10
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 4 deletions.
3 changes: 3 additions & 0 deletions regtest/basic/rt15bis-legacyIncludeWarning/COLVAR.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! FIELDS time d2
0.000000 1.000000
0.050000 9.000000
131 changes: 131 additions & 0 deletions regtest/basic/rt15bis-legacyIncludeWarning/Distance2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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 <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#include "colvar/Colvar.h"
//all the shortcuts to ActionRegister were removed and it should only be included by core/ActionRegister.h
#include "colvar/ActionRegister.h"

#include <string>
#include <cmath>

using namespace std;

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();
};

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<AtomNumber> 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);
}


// 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]);
};
}

}



131 changes: 131 additions & 0 deletions regtest/basic/rt15bis-legacyIncludeWarning/Distance2.cpp.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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 <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#include "colvar/Colvar.h"
//all the shortcuts to ActionRegister were removed and it should only be included by core/ActionRegister.h
#include "colvar/ActionRegister.h"

#include <string>
#include <cmath>

using namespace std;

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();
};

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<AtomNumber> 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);
}


// 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]);
};
}

}



1 change: 1 addition & 0 deletions regtest/basic/rt15bis-legacyIncludeWarning/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../scripts/test.make
8 changes: 8 additions & 0 deletions regtest/basic/rt15bis-legacyIncludeWarning/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type=driver
plumed_needs="dlopen"
arg="--plumed plumed.dat --trajectory-stride 10 --timestep 0.005 --ixyz trajectory.xyz"


function plumed_regtest_after(){
grep "WARNING: using a legacy ActionRegister" err > errorParsed
}
2 changes: 2 additions & 0 deletions regtest/basic/rt15bis-legacyIncludeWarning/der2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
works like rt15, but emulates an old include statement style for ActionRegister.h
Distance2.cpp reference is set up because mklib should NOT change the inputfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WARNING: using a legacy ActionRegister.h include path, please use <<#include "core/ActionRegister.h">>
8 changes: 8 additions & 0 deletions regtest/basic/rt15bis-legacyIncludeWarning/plumed.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is loading a collective variable on the fly:
LOAD FILE=Distance2.cpp

d2: DISTANCE2 ATOMS=1,2

PRINT FILE=COLVAR ARG=d2

ENDPLUMED
20 changes: 20 additions & 0 deletions regtest/basic/rt15bis-legacyIncludeWarning/trajectory.xyz
Original file line number Diff line number Diff line change
@@ -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
22 changes: 18 additions & 4 deletions scripts/mklib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,28 @@ then
echo "ERROR: I cannot find file $file"
exit 1
fi
#adding a simple tmpfile, to preprocess "in place" the input file,
#this assumes the user has write permission in the current directory
#which should be true since we are going to compile and output something here
tmpfile=$(mktemp ${file%.cpp}.XXXXXX.cpp)
cp "${file}" "${tmpfile}"

if grep -q '^#include "\(bias\|colvar\|function\|sasa\|vatom\)\/ActionRegister.h"' "${tmpfile}"; then
>&2 echo 'WARNING: using a legacy ActionRegister.h include path, please use <<#include "core/ActionRegister.h">>'
sed -i.bak 's%^#include ".*/ActionRegister.h"%#include "core/ActionRegister.h"%g' "${tmpfile}"
fi

if grep -q '^#include "\(cltools\)\/CLToolRegister.h"' "${tmpfile}"; then
>&2 echo 'WARNING: using a legacy CLToolRegister.h include path, please use <<#include "core/CLToolRegister.h">>'
sed -i.bak 's%^#include ".*/CLToolRegister.h"%#include "core/CLToolRegister.h"%g' "${tmpfile}"
fi

rm -f "$obj" "$lib"

if test "$PLUMED_IS_INSTALLED" = yes ; then
eval "$compile" "$obj" "$file" && eval "$link_installed" "$lib" "$obj"
eval "$compile" "$obj" "$tmpfile" && eval "$link_installed" "$lib" "$obj"
else
eval "$compile" "$obj" "$file" && eval "$link_uninstalled" "$lib" "$obj"
eval "$compile" "$obj" "$tmpfile" && eval "$link_uninstalled" "$lib" "$obj"
fi



rm -f ${tmpfile} ${tmpfile}.bak

0 comments on commit abdbd10

Please sign in to comment.