30 #include "tools/Exception.h"
32 #include "tools/Pbc.h"
33 #include "tools/PDB.h"
38 ActionAtomistic::~ActionAtomistic(){
47 lockRequestAtoms(false),
51 if(
atoms.
getNatoms()==0)
error(
"Cannot perform calculations involving atoms without atoms");
60 plumed_massert(!
lockRequestAtoms,
"requested atom list can only be changed in the prepare() method");
70 for(
unsigned i=0;i<
indexes.size();i++){
71 plumed_massert(
indexes[i].index()<n,
"atom out of range");
90 plumed_massert(a,
"only Actions with a value can be differentiated");
95 std::vector<Vector> value(nval*natoms);
96 std::vector<Tensor> valuebox(nval);
97 std::vector<Vector> savedPositions(natoms);
100 for(
int i=0;i<natoms;i++)
for(
int k=0;k<3;k++){
105 for(
unsigned j=0;j<nval;j++){
109 for(
int i=0;i<3;i++)
for(
int k=0;k<3;k++){
110 double arg0=
box(i,k);
118 for(
int j=0;j<natoms;j++)
positions[j]=savedPositions[j];
124 for(
unsigned j=0;j<nval;j++){
128 for(
int i=0;i<natoms;i++)
for(
int k=0;k<3;k++) {
129 double d=(value[j*natoms+i][k]-ref)/delta;
133 for(
int i=0;i<3;i++)
for(
int k=0;k<3;k++)
virial(i,k)= (valuebox[j](i,k)-ref)/
delta;
136 for(
int i=0;i<3;i++)
for(
int k=0;k<3;k++) v->
addDerivative(startnum+3*natoms+3*k+i,virial(k,i));
146 plumed_massert(
keywords.
style(key,
"atoms"),
"keyword " + key +
" should be registered as atoms");
147 vector<string> strings;
150 if(strings.empty())
return;
156 for(
unsigned i=0;i<strings.size();++i){
160 if(ok) t.push_back(atom);
164 map<string,vector<AtomNumber> >::const_iterator
m=
atoms.
groups.find(strings[i]);
165 t.insert(t.end(),m->second.begin(),m->second.end());
172 for(ActionSet::const_iterator
a=actionSet.begin();
a!=actionSet.end();++
a){
174 if(c)
if(c->
getLabel()==strings[i]){
181 plumed_massert(ok,
"it was not possible to interpret atom name " + strings[i]);
201 for(
unsigned i=0;i<
indexes.size();++i){
202 forces[i][0]=forcesToApply[ind]; ind++;
203 forces[i][1]=forcesToApply[ind]; ind++;
204 forces[i][2]=forcesToApply[ind]; ind++;
206 virial(0,0)=forcesToApply[ind]; ind++;
207 virial(0,1)=forcesToApply[ind]; ind++;
208 virial(0,2)=forcesToApply[ind]; ind++;
209 virial(1,0)=forcesToApply[ind]; ind++;
210 virial(1,1)=forcesToApply[ind]; ind++;
211 virial(1,2)=forcesToApply[ind]; ind++;
212 virial(2,0)=forcesToApply[ind]; ind++;
213 virial(2,1)=forcesToApply[ind]; ind++;
214 virial(2,2)=forcesToApply[ind]; ind++;
215 plumed_dbg_assert( ind==forcesToApply.size() );
230 for(
unsigned j=0;j<
indexes.size();j++){
231 if(
indexes[j].index()>pdb.
size() )
error(
"there are not enough atoms in the input pdb file");
Simple class to store the index of an atom.
const int & getNatoms() const
std::vector< Vector > forces
std::vector< double > charges
static void registerKeywords(Keywords &keys)
TensorGeneric< m, n > transpose() const
return the transpose matrix
std::vector containing the sequence of Action to be done.
double get() const
Get the value of the function.
Class implementing fixed size matrices of doubles.
void add(const ActionAtomistic *)
TensorGeneric< n, l > matmul(const TensorGeneric< n, m > &a, const TensorGeneric< m, l > &b)
Class implementing fixed size vectors of doubles.
A class for holding the value of a function together with its derivatives.
std::vector< double > masses
Vector scaledToReal(const Vector &) const
Transform a vector in scaled coordinates to a vector in real space.
void error(const std::string &msg) const
Crash calculation and print documentation.
const std::string & getLabel() const
Returns the label.
std::set< AtomNumber > unique
void parseAtomList(const std::string &key, std::vector< AtomNumber > &t)
Parse a list of atoms without a numbered keyword.
virtual void calculate()=0
Calculate an Action.
virtual void calculateNumericalDerivatives(ActionWithValue *a=NULL)
N.B.
std::vector< Vector > positions
void addDependency(Action *)
Specify that this Action depends on another one.
Vector distance(const Vector &, const Vector &, int *nshifts) const
internal version of distance, also returns the number of attempted shifts (used in Pbc::test())...
Used to create a PLMD::Action that has some scalar or vectorial output that may or may not have some ...
const std::vector< Vector > & getPositions() const
Access to the position array.
This class holds the keywords and their documentation.
const std::vector< double > & getBeta() const
Access to the beta array.
bool chargesWereSet() const
This class is used to bring the relevant information to the Action constructor.
std::vector< Vector > positions
This is the abstract base class to use for implementing new collective variables, within it there is ...
void readAtomsFromPDB(const PDB &pdb)
Read in an input file containing atom positions and calculate the action for the atomic configuration...
Base class for all the input Actions.
const std::vector< double > & getOccupancy() const
Access to the occupancy array.
Value * copyOutput(const std::string &name) const
Return a pointer to the value with name (this is used to retrieve values in other PLMD::Actions) You ...
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) ...
VectorGeneric< n > delta(const VectorGeneric< n > &v1, const VectorGeneric< n > &v2)
bool style(const std::string &k, const std::string &t) const
Check if the keyword with name k has style t.
double getOutputQuantity(const unsigned j) const
Get the value of one of the components of the PLMD::Action.
std::vector< AtomNumber > indexes
AtomNumber getIndex() const
Return the atom id of the corresponding virtual atom.
Vector pbcDistance(const Vector &, const Vector &) const
Compute the pbc distance between two positions.
void calculateAtomicNumericalDerivatives(ActionWithValue *a, const unsigned &startnum)
Numerical derivative routine to use when using Actions that inherit from BOTH ActionWithArguments and...
bool parseNumberedVector(const std::string &key, const int no, std::vector< T > &t)
Parse a vector with a number.
bool isVirtualAtom(AtomNumber) const
virtual void clearDerivatives()
Clear the derivatives of values wrt parameters.
void requestAtoms(const std::vector< AtomNumber > &a)
Request an array of atoms.
int getNumberOfComponents() const
Returns the number of values defined.
void clearDependencies()
Clear the dependence list for this Action.
ActionWithVirtualAtom * getVirtualAtomsAction(AtomNumber) const
unsigned size() const
Returns the number of atoms.
const std::vector< AtomNumber > & getAtomNumbers() const
Access to the indexes.
void setForcesOnAtoms(const std::vector< double > &forcesToApply, unsigned ind=0)
Add the forces to the atoms.
unsigned getNumberOfAtoms() const
Get number of available atoms.
std::vector< double > charges
Vector realToScaled(const Vector &) const
Transform a vector in real space to a vector in scaled coordinates.
const Keywords & keywords
void addDerivative(unsigned i, double d)
Add some derivative to the ith component of the derivatives array.
std::vector< Vector > forces
std::vector< double > masses
void setBox(const Tensor &b)
Set the lattice vectors.
bool hasDerivatives() const
Check whether or not this particular quantity has derivatives.
std::map< std::string, std::vector< AtomNumber > > groups