24 #include "core/PlumedMain.h"
25 #include "core/Atoms.h"
73 static void registerKeywords(
Keywords& keys );
76 PLUMED_REGISTER_ACTION(
Center,
"CENTER")
79 ActionWithVirtualAtom::registerKeywords(keys);
80 keys.add(
"optional",
"WEIGHTS",
"Center is computed as a weighted average.");
81 keys.addFlag(
"MASS",
false,
"If set center is mass weighted");
89 vector<AtomNumber>
atoms;
91 if(atoms.size()==0)
error(
"at least one atom should be specified");
96 for(
unsigned i=0;i<atoms.size();++i)
log.
printf(
" %d",atoms[i].serial());
98 log<<
" mass weighted\n";
99 if(
weights.size()!=0)
error(
"WEIGHTS and MASS keywords should not be used simultaneously");
102 weights.resize( atoms.size() );
103 for(
unsigned i=0;i<atoms.size();i++)
weights[i] = 1.;
105 log<<
" with weights";
106 if(
weights.size()!=atoms.size() )
error(
"number of elements in weight vector does not match the number of atoms");
118 if(
plumed.getAtoms().chargesWereSet() ){
std::vector< double > weights
const Vector & getPosition(int) const
Get position of i-th atom.
void parseFlag(const std::string &key, bool &t)
Parse one keyword as boolean flag.
Log & log
Reference to the log stream.
void setPosition(const Vector &)
Set position of the virtual atom.
Class implementing fixed size vectors of doubles.
void error(const std::string &msg) const
Crash calculation and print documentation.
void checkRead()
Check if Action was properly read.
void parseAtomList(const std::string &key, std::vector< AtomNumber > &t)
Parse a list of atoms without a numbered keyword.
void setMass(double)
Set its mass.
void requestAtoms(const std::vector< AtomNumber > &a)
Request atoms on which the calculation depends.
void calculate()
Calculate an Action.
static TensorGeneric< n, n > identity()
return an identity tensor
This class holds the keywords and their documentation.
void setAtomsDerivatives(const std::vector< Tensor > &d)
Set the derivatives of virtual atom coordinate wrt atoms on which it dependes.
This class is used to bring the relevant information to the Action constructor.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Base class for all the input Actions.
void parseVector(const std::string &key, std::vector< T > &t)
Parse one keyword as std::vector.
Inherit from here if you are calculating the position of a virtual atom (eg a center of mass) ...
Provides the keyword CENTER
double getCharge(int i) const
Get charge of i-th atom.
void setCharge(double)
Set its charge.
unsigned getNumberOfAtoms() const
Get number of available atoms.
double getMass(int i) const
Get mass of i-th atom.