All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ActionWithVirtualAtom.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 The plumed team
3  (see the PEOPLE file at the root of the distribution for a list of names)
4 
5  See http://www.plumed-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
8 
9  plumed is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  plumed is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #include "ActionWithVirtualAtom.h"
23 #include "Atoms.h"
24 
25 using namespace std;
26 
27 namespace PLMD{
28 
29 void ActionWithVirtualAtom::registerKeywords(Keywords& keys){
30  Action::registerKeywords(keys);
31  ActionAtomistic::registerKeywords(keys);
32  keys.add("atoms","ATOMS","the list of atoms which are involved the virtual atom's definition");
33 }
34 
35 ActionWithVirtualAtom::ActionWithVirtualAtom(const ActionOptions&ao):
36  Action(ao),
37  ActionAtomistic(ao)
38 {
40  log.printf(" serial associated to this virtual atom is %d\n",index.serial());
41 }
42 
45 }
46 
48  const Vector & f(atoms.forces[index.index()]);
49  for(unsigned i=0;i<getNumberOfAtoms();i++) modifyForces()[i]=matmul(derivatives[i],f);
50 }
51 
52 void ActionWithVirtualAtom::requestAtoms(const std::vector<AtomNumber> & a){
54  derivatives.resize(a.size());
55 }
56 
58  gradients.clear();
59  for(unsigned i=0;i<getNumberOfAtoms();i++){
61  // this case if the atom is a virtual one
62  if(atoms.isVirtualAtom(an)){
64  for(std::map<AtomNumber,Tensor>::const_iterator p=a->gradients.begin();p!=a->gradients.end();++p){
65  gradients[(*p).first]+=matmul(derivatives[i],(*p).second);
66  }
67  // this case if the atom is a normal one
68  } else {
69  gradients[an]+=derivatives[i];
70  }
71  }
72 }
73 
74 
76  if(isOptionOn("GRADIENTS")) {
77  setGradients() ;
78  }
79 }
80 
81 }
std::map< AtomNumber, Tensor > gradients
Simple class to store the index of an atom.
Definition: AtomNumber.h:39
void removeVirtualAtom(ActionWithVirtualAtom *)
Definition: Atoms.cpp:377
AtomNumber addVirtualAtom(ActionWithVirtualAtom *)
Definition: Atoms.cpp:370
std::vector< Vector > forces
Definition: Atoms.h:51
Log & log
Reference to the log stream.
Definition: Action.h:93
unsigned serial() const
Returns the serial number.
Definition: AtomNumber.h:84
TensorGeneric< n, l > matmul(const TensorGeneric< n, m > &a, const TensorGeneric< m, l > &b)
Definition: Tensor.h:343
std::vector< Tensor > derivatives
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
AtomNumber getAbsoluteIndex(int i) const
Get the absolute index of an atom.
STL namespace.
void add(const std::string &t, const std::string &k, const std::string &d)
Add a new keyword of type t with name k and description d.
Definition: Keywords.cpp:167
void requestAtoms(const std::vector< AtomNumber > &a)
Request atoms on which the calculation depends.
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
Action used to create objects that access the positions of the atoms from the MD code.
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
Base class for all the input Actions.
Definition: Action.h:60
Inherit from here if you are calculating the position of a virtual atom (eg a center of mass) ...
bool isOptionOn(const std::string &s) const
Check if an option is on.
Definition: Action.h:380
unsigned index() const
Returns the index number.
Definition: AtomNumber.h:89
bool isVirtualAtom(AtomNumber) const
Definition: Atoms.h:206
void requestAtoms(const std::vector< AtomNumber > &a)
Request an array of atoms.
ActionWithVirtualAtom * getVirtualAtomsAction(AtomNumber) const
Definition: Atoms.h:211
std::vector< Vector > & modifyForces()
Get a reference to forces array.
unsigned getNumberOfAtoms() const
Get number of available atoms.
void const char const char int double * a
Definition: Matrix.h:42