All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ActionVolume.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_multicolvar_ActionVolume_h
23 #define __PLUMED_multicolvar_ActionVolume_h
24 
25 #include "core/ActionAtomistic.h"
26 #include "tools/HistogramBead.h"
27 #include "tools/Pbc.h"
28 #include "core/ActionWithValue.h"
29 #include "vesselbase/ActionWithVessel.h"
30 #include "vesselbase/BridgeVessel.h"
31 #include "MultiColvarBase.h"
32 
33 namespace PLMD {
34 namespace multicolvar {
35 
36 /**
37 \ingroup INHERIT
38 This is the abstract base class to use for implementing a new way of definining a particular region of the simulation
39 box. You can use this to calculate the number of atoms inside that part or the average value of a quantity like the
40 coordination number inside that part of the cell.
41 */
42 
43 class ActionVolume :
44  public ActionAtomistic,
45  public ActionWithValue,
47  {
48 friend class Region;
49 private:
50 /// The value of sigma
51  double sigma;
52 /// Are we interested in the area outside the colvar
53  bool not_in;
54 /// This is used for storing positions properly
56 /// The bead for the histogram
58 /// The action that is calculating the colvars of interest
60 /// The vessel that bridges
62 /// Everything for controlling the updating of neighbor lists
64  unsigned lastUpdate;
65 /// Fast merging of derivatives (automatic skips of zero contributions)
67 /// This is used to store forces temporarily in apply
68  std::vector<double> tmpforces;
69 /// This sets up array above
70  void resizeLocalArrays();
71 protected:
72  double getSigma() const ;
73 /// Get the cell box
74  const Tensor & getBox() const;
75 /// Get reference to Pbc
76  const Pbc & getPbc() const;
77 /// Calculate distance between two points
78  Vector pbcDistance( const Vector& v1, const Vector& v2) const;
79 /// Get position of atom
80  const Vector & getPosition( int iatom );
81 /// Request the atoms
82  void requestAtoms( const std::vector<AtomNumber>& atoms );
84 /// Add derivatinve to one of the reference atoms here
85  void addReferenceAtomDerivatives( const unsigned& iatom, const Vector& der );
86 /// Add derivatives wrt to the virial
87  void addBoxDerivatives( const Tensor& vir );
88 public:
89  static void registerKeywords( Keywords& keys );
91 /// Don't actually clear the derivatives when this is called from plumed main.
92 /// They are calculated inside another action and clearing them would be bad
94 /// Get the number of derivatives for this action
95  unsigned getNumberOfDerivatives(); // N.B. This is replacing the virtual function in ActionWithValue
96 /// Is the output quantity periodic
97  bool isPeriodic();
98 /// Jobs to be done when the action is activated
99  void prepare();
100 /// Do jobs required before tasks are undertaken
102 /// This calculates all the vessels and is called from within a bridge vessel
103  void performTask(const unsigned& i );
104 /// Routines that have to be defined so as not to have problems with virtual methods
105  void deactivate_task();
106  void calculate(){}
107 /// We need our own calculate numerical derivatives here
109  virtual void setupRegion()=0;
110  virtual double calculateNumberInside( const Vector& cpos, HistogramBead& bead, Vector& derivatives )=0;
111 /// Forces here are applied through the bridge
112  void applyBridgeForces( const std::vector<double>& bb );
113  void apply(){};
114 /// These routines replace the virtual routines in ActionWithVessel for
115 /// code optimization
116  void mergeDerivatives( const unsigned& ider, const double& df );
117  void clearDerivativesAfterTask( const unsigned& ider );
118 };
119 
120 inline
122  return mycolv->getBox();
123 }
124 
125 inline
126 const Pbc & ActionVolume::getPbc() const {
127  return mycolv->getPbc();
128 }
129 
130 inline
131 Vector ActionVolume::pbcDistance( const Vector& v1, const Vector& v2) const {
132  return mycolv->pbcDistance(v1,v2);
133 }
134 
135 inline
136 const Vector & ActionVolume::getPosition( int iatom ){
138  // This is for numerical derivatives of quantity wrt to the local atoms
141  if( bridgeVariable>=3*iatom && bridgeVariable<(iatom+1)*3 ) tmp_p[bridgeVariable%3]+=sqrt(epsilon);
142  }
143  // This makes sure that numerical derivatives of virial are calculated correctly
146  return tmp_p;
147 }
148 
149 inline
150 double ActionVolume::getSigma() const {
151  return sigma;
152 }
153 
154 inline
156  return mycolv;
157 }
158 
159 inline
162 }
163 
164 inline
165 void ActionVolume::addReferenceAtomDerivatives( const unsigned& iatom, const Vector& der ){
166  // This is used for storing the derivatives wrt to the
167  // positions of any additional reference atoms
168  double pref=mycolv->getElementValue(1);
169  if( not_in ) pref*=-1;
170  unsigned nstart = getNumberOfDerivatives() + mycolv->getNumberOfDerivatives() + 3*iatom;
171  addElementDerivative( nstart + 0, pref*der[0] );
172  addElementDerivative( nstart + 1, pref*der[1] );
173  addElementDerivative( nstart + 2, pref*der[2] );
174 }
175 
176 inline
178  double pref=mycolv->getElementValue(1);
179  if( not_in ) pref*=-1;
180  unsigned nstart = getNumberOfDerivatives() + mycolv->getNumberOfDerivatives() - 9;
181  addElementDerivative( nstart + 0, pref*vir(0,0) );
182  addElementDerivative( nstart + 1, pref*vir(0,1) );
183  addElementDerivative( nstart + 2, pref*vir(0,2) );
184  addElementDerivative( nstart + 3, pref*vir(1,0) );
185  addElementDerivative( nstart + 4, pref*vir(1,1) );
186  addElementDerivative( nstart + 5, pref*vir(1,2) );
187  addElementDerivative( nstart + 6, pref*vir(2,0) );
188  addElementDerivative( nstart + 7, pref*vir(2,1) );
189  addElementDerivative( nstart + 8, pref*vir(2,2) );
190 }
191 
192 }
193 }
194 #endif
void doJobsRequiredBeforeTaskList()
Do jobs required before tasks are undertaken.
const Vector & getPosition(int) const
Get position of i-th atom.
const Pbc & getPbc() const
Get reference to Pbc.
Definition: ActionVolume.h:126
const double epsilon
double sigma
The value of sigma.
Definition: ActionVolume.h:51
void applyBridgeForces(const std::vector< double > &bb)
Forces here are applied through the bridge.
void addBoxDerivatives(const Tensor &vir)
Add derivatives wrt to the virial.
Definition: ActionVolume.h:177
const Tensor & getBox() const
Get the cell box.
Definition: ActionVolume.h:121
Class implementing fixed size matrices of doubles.
Definition: Tensor.h:70
MultiColvarBase * getPntrToMultiColvar()
Definition: ActionVolume.h:155
void calculate()
Calculate an Action.
Definition: ActionVolume.h:106
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
void addElementDerivative(const unsigned &, const double &)
Add some derivative of the quantity in the sum wrt to a numbered element.
DynamicList< unsigned > activeAtoms
Fast merging of derivatives (automatic skips of zero contributions)
Definition: ActionVolume.h:66
Vector scaledToReal(const Vector &) const
Transform a vector in scaled coordinates to a vector in real space.
Definition: Pbc.cpp:206
void calculateNumericalDerivatives(ActionWithValue *a=NULL)
We need our own calculate numerical derivatives here.
void prepare()
Jobs to be done when the action is activated.
unsigned bridgeVariable
This is used for numerical derivatives of bridge variables.
Definition: Pbc.h:38
bool not_in
Are we interested in the area outside the colvar.
Definition: ActionVolume.h:53
void mergeDerivatives(const unsigned &ider, const double &df)
These routines replace the virtual routines in ActionWithVessel for code optimization.
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 ...
unsigned getNumberOfDerivatives()
Get the number of derivatives for this action.
Definition: ActionVolume.h:160
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class allows you to calculate the vessel in one ActionWithVessel.
Definition: BridgeVessel.h:40
A class for calculating whether or not values are within a given range using : .
Definition: HistogramBead.h:41
bool isPeriodic()
Is the output quantity periodic.
Vector tmp_p
This is used for storing positions properly.
Definition: ActionVolume.h:55
void apply()
Apply an Action.
Definition: ActionVolume.h:113
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.
void clearDerivatives()
Don't actually clear the derivatives when this is called from plumed main.
Definition: ActionVolume.h:93
ActionVolume(const ActionOptions &)
void deactivate_task()
Routines that have to be defined so as not to have problems with virtual methods. ...
This is the abstract base class to use for implementing a new way of definining a particular region o...
Definition: ActionVolume.h:43
MultiColvarBase * mycolv
The action that is calculating the colvars of interest.
Definition: ActionVolume.h:59
void resizeLocalArrays()
This sets up array above.
bool checkNumericalDerivatives() const
Check if numerical derivatives should be used.
int updateFreq
Everything for controlling the updating of neighbor lists.
Definition: ActionVolume.h:63
void performTask(const unsigned &i)
This calculates all the vessels and is called from within a bridge vessel.
HistogramBead bead
The bead for the histogram.
Definition: ActionVolume.h:57
virtual double calculateNumberInside(const Vector &cpos, HistogramBead &bead, Vector &derivatives)=0
Vector pbcDistance(const Vector &, const Vector &) const
Compute the pbc distance between two positions.
void clearDerivativesAfterTask(const unsigned &ider)
void addReferenceAtomDerivatives(const unsigned &iatom, const Vector &der)
Add derivatinve to one of the reference atoms here.
Definition: ActionVolume.h:165
Vector pbcDistance(const Vector &v1, const Vector &v2) const
Calculate distance between two points.
Definition: ActionVolume.h:131
unsigned getNumberOfDerivatives()
Get the number of derivatives for this action.
const Tensor & getBox() const
Get position of i-th atom.
unsigned getNumberOfAtoms() const
Get number of available atoms.
static void registerKeywords(Keywords &keys)
vesselbase::BridgeVessel * myBridgeVessel
The vessel that bridges.
Definition: ActionVolume.h:61
void const char const char int double * a
Definition: Matrix.h:42
std::vector< double > derivatives
Vector of derivatives for the object.
Vector realToScaled(const Vector &) const
Transform a vector in real space to a vector in scaled coordinates.
Definition: Pbc.cpp:202
std::vector< double > tmpforces
This is used to store forces temporarily in apply.
Definition: ActionVolume.h:68
const Vector & getPosition(int iatom)
Get position of atom.
Definition: ActionVolume.h:136
double getElementValue(const unsigned &ival) const
Get the value of this element.
This is used to create PLMD::Action objects that are computed by calculating the same function multip...
void requestAtoms(const std::vector< AtomNumber > &atoms)
Request the atoms.