All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ActionAtomistic.h
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 #ifndef __PLUMED_core_ActionAtomistic_h
23 #define __PLUMED_core_ActionAtomistic_h
24 
25 #include "Action.h"
26 #include "tools/Tensor.h"
27 #include <vector>
28 #include <set>
29 
30 namespace PLMD {
31 
32 class Atoms;
33 class Pbc;
34 class PDB;
35 
36 /// \ingroup MULTIINHERIT
37 /// Action used to create objects that access the positions of the atoms from the MD code
39  virtual public Action
40  {
41 
42  std::vector<AtomNumber> indexes; // the set of needed atoms
43  std::set<AtomNumber> unique;
44  std::vector<Vector> positions; // positions of the needed atoms
45  double energy;
47  Pbc& pbc;
49  std::vector<double> masses;
51  std::vector<double> charges;
52 
53  std::vector<Vector> forces; // forces on the needed atoms
54  double forceOnEnergy;
55 
56  bool lockRequestAtoms; // forbid changes to request atoms
57 
58 protected:
60 
61 public:
62 /// Request an array of atoms.
63 /// This method is used to ask for a list of atoms. Atoms
64 /// should be asked for by number. If this routine is called
65 /// during the simulation, atoms will be available at the next step
66 /// MAYBE WE HAVE TO FIND SOMETHING MORE CLEAR FOR DYNAMIC
67 /// LISTS OF ATOMS
68  void requestAtoms(const std::vector<AtomNumber> & a);
69 /// Get position of i-th atom
70  const Vector & getPosition(int)const;
71 /// Get position of i-th atom
72  const Tensor & getBox()const;
73 /// Get the array of all positions
74  const std::vector<Vector> & getPositions()const;
75 /// Get energy
76  const double & getEnergy()const;
77 /// Get mass of i-th atom
78  double getMass(int i)const;
79 /// Get charge of i-th atom
80  double getCharge(int i)const;
81 /// Get a reference to forces array
82  std::vector<Vector> & modifyForces();
83 /// Get a reference to virial array
84  Tensor & modifyVirial();
85 /// Get a reference to force on energy
86  double & modifyForceOnEnergy();
87 /// Get number of available atoms
88  unsigned getNumberOfAtoms()const{return indexes.size();}
89 /// Compute the pbc distance between two positions
90  Vector pbcDistance(const Vector&,const Vector&)const;
91 /// Get the vector of absolute indexes
92  const std::vector<AtomNumber> & getAbsoluteIndexes()const;
93 /// Get the absolute index of an atom
94  AtomNumber getAbsoluteIndex(int i)const;
95 /// Parse a list of atoms without a numbered keyword
96  void parseAtomList(const std::string&key,std::vector<AtomNumber> &t);
97 /// Parse an list of atom with a numbred keyword
98  void parseAtomList(const std::string&key,const int num, std::vector<AtomNumber> &t);
99 /// Get reference to Pbc
100  const Pbc & getPbc() const;
101 /// Add the forces to the atoms
102  void setForcesOnAtoms( const std::vector<double>& forcesToApply, unsigned ind=0 );
103 public:
104 
105 // virtual functions:
106 
107  ActionAtomistic(const ActionOptions&ao);
109 
110  static void registerKeywords( Keywords& keys );
111 
112  void clearOutputForces();
113 
114 /// N.B. only pass an ActionWithValue to this routine if you know exactly what you
115 /// are doing. The default will be correct for the vast majority of cases
116  virtual void calculateNumericalDerivatives( ActionWithValue* a=NULL );
117 /// Numerical derivative routine to use when using Actions that inherit from BOTH
118 /// ActionWithArguments and ActionAtomistic
119  void calculateAtomicNumericalDerivatives( ActionWithValue* a, const unsigned& startnum );
120 
121  void retrieveAtoms();
122  void applyForces();
123  void lockRequests();
124  void unlockRequests();
125  const std::set<AtomNumber> & getUnique()const;
126 /// Read in an input file containing atom positions and calculate the action for the atomic
127 /// configuration therin
128  void readAtomsFromPDB( const PDB& pdb );
129 };
130 
131 inline
133  return positions[i];
134 }
135 
136 inline
137 double ActionAtomistic::getMass(int i)const{
138  return masses[i];
139 }
140 
141 inline
142 double ActionAtomistic::getCharge(int i) const {
143  if( !chargesWereSet ) error("charges were not passed to plumed");
144  return charges[i];
145 }
146 
147 inline
148 const std::vector<AtomNumber> & ActionAtomistic::getAbsoluteIndexes()const{
149  return indexes;
150 }
151 
152 inline
154  return indexes[i];
155 }
156 
157 inline
158 const std::vector<Vector> & ActionAtomistic::getPositions()const{
159  return positions;
160 }
161 
162 inline
163 const double & ActionAtomistic::getEnergy()const{
164  return energy;
165 }
166 
167 inline
169  return box;
170 }
171 
172 inline
173 std::vector<Vector> & ActionAtomistic::modifyForces(){
174  return forces;
175 }
176 
177 inline
179  return virial;
180 }
181 
182 inline
184  for(unsigned i=0;i<forces.size();++i)forces[i].zero();
185  forceOnEnergy=0.0;
186 }
187 
188 
189 inline
191  return forceOnEnergy;
192 }
193 
194 inline
195 const Pbc & ActionAtomistic::getPbc() const{
196  return pbc;
197 }
198 
199 inline
201  lockRequestAtoms=true;
202 }
203 
204 inline
206  lockRequestAtoms=false;
207 }
208 
209 inline
210 const std::set<AtomNumber> & ActionAtomistic::getUnique()const{
211  return unique;
212 }
213 
214 
215 }
216 
217 #endif
Simple class to store the index of an atom.
Definition: AtomNumber.h:39
const Vector & getPosition(int) const
Get position of i-th atom.
const double & getEnergy() const
Get energy.
static void registerKeywords(Keywords &keys)
Class implementing fixed size matrices of doubles.
Definition: Tensor.h:70
Tensor & modifyVirial()
Get a reference to virial array.
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
AtomNumber getAbsoluteIndex(int i) const
Get the absolute index of an atom.
void error(const std::string &msg) const
Crash calculation and print documentation.
Definition: Action.cpp:195
const std::vector< Vector > & getPositions() const
Get the array of all positions.
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 calculateNumericalDerivatives(ActionWithValue *a=NULL)
N.B.
Class containing atom related quantities from the MD code.
Definition: Atoms.h:45
Definition: Pbc.h:38
const Pbc & getPbc() const
Get reference to Pbc.
Used to create a PLMD::Action that has some scalar or vectorial output that may or may not have some ...
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.
std::vector< Vector > positions
ActionAtomistic(const ActionOptions &ao)
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.
Definition: Action.h:60
Minimalistic pdb parser.
Definition: PDB.h:38
std::vector< AtomNumber > indexes
double getCharge(int i) const
Get charge of i-th 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...
void requestAtoms(const std::vector< AtomNumber > &a)
Request an array of atoms.
std::vector< Vector > & modifyForces()
Get a reference to forces array.
const Tensor & getBox() const
Get position of i-th atom.
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
void const char const char int double * a
Definition: Matrix.h:42
const std::set< AtomNumber > & getUnique() const
double & modifyForceOnEnergy()
Get a reference to force on energy.
double getMass(int i) const
Get mass of i-th atom.
const std::vector< AtomNumber > & getAbsoluteIndexes() const
Get the vector of absolute indexes.
std::vector< Vector > forces
std::vector< double > masses