From f6b95fb4e6cbdf6de16b4a80a9af90862256cd8d Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Wed, 28 Jun 2017 08:10:41 +0200 Subject: [PATCH] Fix #251 Since isnan() is only available in c++11, I prefer not to backport this so v2.3. At variance with older commit fba71ad4ea8a7477a02f8d8b1bee682ce2eebb21 I here only perform the check at the first step --- src/vatom/COM.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/vatom/COM.cpp b/src/vatom/COM.cpp index da0259c90..c12773d2c 100644 --- a/src/vatom/COM.cpp +++ b/src/vatom/COM.cpp @@ -23,6 +23,7 @@ #include "ActionRegister.h" #include "core/PlumedMain.h" #include "core/Atoms.h" +#include <cmath> using namespace std; @@ -69,6 +70,7 @@ class COM: public ActionWithVirtualAtom { bool nopbc; + bool first; public: explicit COM(const ActionOptions&ao); void calculate(); @@ -85,7 +87,8 @@ void COM::registerKeywords(Keywords& keys) { COM::COM(const ActionOptions&ao): Action(ao), ActionWithVirtualAtom(ao), - nopbc(false) + nopbc(false), + first(true) { vector<AtomNumber> atoms; parseAtomList("ATOMS",atoms); @@ -110,6 +113,17 @@ void COM::calculate() { Vector pos; if(!nopbc) makeWhole(); double mass(0.0); + if( first ) { + for(unsigned i=0; i<getNumberOfAtoms(); i++) { + if(isnan(getMass(i))) { + error( + "You are trying to compute a COM but masses are not known.\n" + " If you are using plumed driver, please use the --mc option" + ); + } + } + first=false; + } vector<Tensor> deriv(getNumberOfAtoms()); for(unsigned i=0; i<getNumberOfAtoms(); i++) mass+=getMass(i); if( plumed.getAtoms().chargesWereSet() ) { -- GitLab