All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MultiColvarBase.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_MultiColvarBase_h
23 #define __PLUMED_multicolvar_MultiColvarBase_h
24 
25 #include "core/ActionAtomistic.h"
26 #include "core/ActionWithValue.h"
27 #include "tools/DynamicList.h"
28 #include "vesselbase/ActionWithVessel.h"
30 #include <vector>
31 
32 namespace PLMD {
33 namespace multicolvar {
34 
36  public ActionAtomistic,
37  public ActionWithValue,
39  {
40 friend class ActionVolume;
41 friend class VolumeSubcell;
42 friend class StoreColvarVessel;
44 friend class MultiColvarFunction;
45 friend class MultiColvar;
46 private:
47 /// Use periodic boundary conditions
48  bool usepbc;
49 /// Everything for controlling the updating of neighbor lists
51  unsigned lastUpdate;
52 /// The list of all the atoms involved in the colvar
54 /// A dynamic list containing those atoms with derivatives
56 /// The lists of the atoms involved in each of the individual colvars
57 /// note these refer to the atoms in all_atoms
58  std::vector< DynamicList<unsigned> > colvar_atoms;
59 /// Variables used for central atoms
62  std::vector<Tensor> central_derivs;
63 /// The forces we are going to apply to things
64  std::vector<double> forcesToApply;
65 /// This resizes the local arrays after neighbor list updates and during initialization
66  void resizeLocalArrays();
67 protected:
68 /// Add a colvar to the set of colvars we are calculating (in practise just a list of atoms)
69  void addColvar( const std::vector<unsigned>& newatoms );
70 /// Finish setting up the multicolvar base
71  void setupMultiColvarBase();
72 /// Get the separation between a pair of vectors
73  Vector getSeparation( const Vector& vec1, const Vector& vec2 ) const ;
74 /// Do we use pbc to calculate this quantity
75  bool usesPbc() const ;
76 /// Return the index of an atom
77  unsigned getAtomIndex( const unsigned& ) const ;
78 /// Add some derivatives for an atom
79  void addAtomsDerivatives(const int&,const Vector&);
80 /// Add some derivatives to the virial
81  void addBoxDerivatives(const Tensor&);
82 /// Retrieve derivative of central atom position wrt jcomp'th component of position of iatom'th atom
83  double getCentralAtomDerivative( const unsigned& iatom, const unsigned jcomp, const Vector& df ) const ;
84 /// Set a weight for this colvar (used in MEAN and HISTOGRAM)
85  void setWeight( const double& weight );
86 /// Set the derivative of the weight (used in MEAN and HISTOGRAM)
87  void addAtomsDerivativeOfWeight( const unsigned& i, const Vector& wder );
88  void addBoxDerivativesOfWeight( const Tensor& vir );
89 /// Get the number of atoms in this particular colvar
90  unsigned getNAtoms() const;
91 /// Update the list of atoms after the neighbor list step
92  void removeAtomRequest( const unsigned& aa, const double& weight );
93 /// Add derivative of central atom position wrt to position of iatom'th atom
94  void addCentralAtomDerivatives( const unsigned& iatom, const Tensor& der );
95 public:
98  static void registerKeywords( Keywords& keys );
99 /// Prepare for the calculation
100  void prepare();
101  virtual void resizeDynamicArrays()=0;
102 /// Return the size of the colvar_atoms array
103  unsigned getNumberOfColvars() const ;
104 /// Perform one of the tasks
105  void performTask( const unsigned& j );
106 /// And a virtual function which actually computes the colvar
107  virtual double doCalculation( const unsigned& j )=0;
108 /// These replace the functions in ActionWithVessel to make the code faster
109  void mergeDerivatives( const unsigned& ider, const double& df );
110  void clearDerivativesAfterTask( const unsigned& ider );
111 /// Apply the forces from this action
112  void apply();
113 /// Deactivate one of the tasks
114  void deactivate_task();
115 /// Get the number of derivatives for this action
116  unsigned getNumberOfDerivatives(); // N.B. This is replacing the virtual function in ActionWithValue
117 /// Retrieve the position of the central atom
119 /// You can use this to screen contributions that are very small so we can avoid expensive (and pointless) calculations
120  virtual void calculateWeight();
121 /// A virtual routine to get the position of the central atom - used for things like cv gradient
123 /// Is this a density?
124  virtual bool isDensity(){ return false; }
125 /// Return a pointer to the vessel that stores the positions of
126 /// all the central atoms
128 };
129 
130 inline
132  return 3*getNumberOfAtoms()+9;
133 }
134 
135 inline
136 unsigned MultiColvarBase::getAtomIndex( const unsigned& iatom ) const {
137  plumed_dbg_assert( iatom<colvar_atoms[current].getNumberActive() );
138  return all_atoms.linkIndex( colvar_atoms[current][iatom] );
139 }
140 
141 inline
142 void MultiColvarBase::removeAtomRequest( const unsigned& i, const double& weight ){
143  if( !contributorsAreUnlocked ) return;
144  plumed_dbg_assert( weight<getTolerance() );
145  if( weight<getNLTolerance() ) colvar_atoms[current].deactivate( i );
146 }
147 
148 inline
150  if( !contributorsAreUnlocked ) return; // Deactivating tasks only possible during neighbor list update
151  colvar_atoms[current].deactivateAll(); // Deactivate all atom requests for this colvar
152  ActionWithVessel::deactivate_task(); // Deactivate the colvar from the list
153 }
154 
155 inline
157  return usepbc;
158 }
159 
160 inline
162  return colvar_atoms.size();
163 }
164 
165 inline
166 unsigned MultiColvarBase::getNAtoms() const {
167  return colvar_atoms[current].getNumberActive();
168 }
169 
170 inline
171 void MultiColvarBase::addAtomsDerivatives(const int& iatom, const Vector& der){
173  addElementDerivative( 3*iatom+0, der[0] );
174  addElementDerivative( 3*iatom+1, der[1] );
175  addElementDerivative( 3*iatom+2, der[2] );
176 }
177 
178 inline
180  unsigned nstart=3*getNumberOfAtoms();
181  addElementDerivative( nstart+0, vir(0,0) );
182  addElementDerivative( nstart+1, vir(0,1) );
183  addElementDerivative( nstart+2, vir(0,2) );
184  addElementDerivative( nstart+3, vir(1,0) );
185  addElementDerivative( nstart+4, vir(1,1) );
186  addElementDerivative( nstart+5, vir(1,2) );
187  addElementDerivative( nstart+6, vir(2,0) );
188  addElementDerivative( nstart+7, vir(2,1) );
189  addElementDerivative( nstart+8, vir(2,2) );
190 }
191 
192 inline
194  setElementValue( 1, 1.0 );
195 }
196 
197 inline
198 void MultiColvarBase::setWeight( const double& weight ){
199  setElementValue( 1, weight );
200 }
201 
202 inline
203 void MultiColvarBase::addAtomsDerivativeOfWeight( const unsigned& iatom, const Vector& wder ){
204  unsigned nstart = 3*getNumberOfAtoms() + 9 + 3*iatom;
206  addElementDerivative( nstart + 0, wder[0] );
207  addElementDerivative( nstart + 1, wder[1] );
208  addElementDerivative( nstart + 2, wder[2] );
209 }
210 
211 inline
213  int nstart = 6*getNumberOfAtoms() + 9;
214  addElementDerivative( nstart+0, vir(0,0) );
215  addElementDerivative( nstart+1, vir(0,1) );
216  addElementDerivative( nstart+2, vir(0,2) );
217  addElementDerivative( nstart+3, vir(1,0) );
218  addElementDerivative( nstart+4, vir(1,1) );
219  addElementDerivative( nstart+5, vir(1,2) );
220  addElementDerivative( nstart+6, vir(2,0) );
221  addElementDerivative( nstart+7, vir(2,1) );
222  addElementDerivative( nstart+8, vir(2,2) );
223 }
224 
225 }
226 }
227 
228 #endif
std::vector< Tensor > central_derivs
unsigned current
The numerical index of the task we are curently performing.
void addAtomsDerivatives(const int &, const Vector &)
Add some derivatives for an atom.
void addCentralAtomDerivatives(const unsigned &iatom, const Tensor &der)
Add derivative of central atom position wrt to position of iatom'th atom.
Vector getSeparation(const Vector &vec1, const Vector &vec2) const
Get the separation between a pair of vectors.
void prepare()
Prepare for the calculation.
Class implementing fixed size matrices of doubles.
Definition: Tensor.h:70
void removeAtomRequest(const unsigned &aa, const double &weight)
Update the list of atoms after the neighbor list step.
unsigned getNAtoms() const
Get the number of atoms in this particular colvar.
double getNLTolerance() const
Return the value for the neighbor list tolerance.
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
void resizeLocalArrays()
This resizes the local arrays after neighbor list updates and during initialization.
void addElementDerivative(const unsigned &, const double &)
Add some derivative of the quantity in the sum wrt to a numbered element.
A class for storing a list that changes which members are active as a function of time...
Definition: DynamicList.h:135
void activate(const unsigned ii)
Make something active.
Definition: DynamicList.h:263
void clearDerivativesAfterTask(const unsigned &ider)
void addColvar(const std::vector< unsigned > &newatoms)
Add a colvar to the set of colvars we are calculating (in practise just a list of atoms) ...
unsigned getAtomIndex(const unsigned &) const
Return the index of an atom.
virtual void calculateWeight()
You can use this to screen contributions that are very small so we can avoid expensive (and pointless...
void setupMultiColvarBase()
Finish setting up the multicolvar base.
std::vector< double > forcesToApply
The forces we are going to apply to things.
void apply()
Apply the forces from this action.
Used to create a PLMD::Action that has some scalar or vectorial output that may or may not have some ...
DynamicList< unsigned > atomsWithCatomDer
void deactivate_task()
Deactivate one of the tasks.
This class holds the keywords and their documentation.
Definition: Keywords.h:36
std::vector< DynamicList< unsigned > > colvar_atoms
The lists of the atoms involved in each of the individual colvars note these refer to the atoms in al...
static void registerKeywords(Keywords &keys)
void addBoxDerivatives(const Tensor &)
Add some derivatives to the virial.
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
virtual Vector calculateCentralAtomPosition()=0
A virtual routine to get the position of the central atom - used for things like cv gradient...
virtual bool isDensity()
Is this a density?
Action used to create objects that access the positions of the atoms from the MD code.
StoreCentralAtomsVessel * getCentralAtoms()
Return a pointer to the vessel that stores the positions of all the central atoms.
void mergeDerivatives(const unsigned &ider, const double &df)
These replace the functions in ActionWithVessel to make the code faster.
bool usepbc
Use periodic boundary conditions.
void setElementValue(const unsigned &, const double &)
Set the value of the element.
void setWeight(const double &weight)
Set a weight for this colvar (used in MEAN and HISTOGRAM)
This is the abstract base class to use for implementing a new way of definining a particular region o...
Definition: ActionVolume.h:43
Vector retrieveCentralAtomPos()
Retrieve the position of the central atom.
double getTolerance() const
Return the value of the tolerance.
This is the abstract base class to use for creating distributions of colvars and functions thereof...
Definition: MultiColvar.h:39
Tensor ibox
Variables used for central atoms.
virtual double doCalculation(const unsigned &j)=0
And a virtual function which actually computes the colvar.
MultiColvarBase(const ActionOptions &)
bool usesPbc() const
Do we use pbc to calculate this quantity.
DynamicList< unsigned > atoms_with_derivatives
A dynamic list containing those atoms with derivatives.
DynamicList< AtomNumber > all_atoms
The list of all the atoms involved in the colvar.
void performTask(const unsigned &j)
Perform one of the tasks.
unsigned getNumberOfDerivatives()
Get the number of derivatives for this action.
unsigned getNumberOfColvars() const
Return the size of the colvar_atoms array.
void addBoxDerivativesOfWeight(const Tensor &vir)
unsigned getNumberOfAtoms() const
Get number of available atoms.
double getCentralAtomDerivative(const unsigned &iatom, const unsigned jcomp, const Vector &df) const
Retrieve derivative of central atom position wrt jcomp'th component of position of iatom'th atom...
bool contributorsAreUnlocked
The terms in the series are locked.
int updateFreq
Everything for controlling the updating of neighbor lists.
void addAtomsDerivativeOfWeight(const unsigned &i, const Vector &wder)
Set the derivative of the weight (used in MEAN and HISTOGRAM)
This is used to create PLMD::Action objects that are computed by calculating the same function multip...