diff --git a/src/vatom/COM.cpp b/src/vatom/COM.cpp index da0259c9095b255400da1f2e9cf3779c72120086..c12773d2c01edf83032fd16e620484cd7e54f5e7 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() ) {