All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MultiColvarFunction.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 "MultiColvarFunction.h"
23 #include "core/PlumedMain.h"
24 #include "core/ActionSet.h"
25 #include "MultiColvarBase.h"
26 
27 namespace PLMD {
28 namespace multicolvar {
29 
32  keys.add("compulsory","ARG","the label of the action that calculates the vectors we are interested in");
33 }
34 
36 Action(ao),
38 {
39  std::string mlab; parse("ARG",mlab);
40  log.printf(" using vectors calculated by action %s\n",mlab.c_str() );
41  mycolv = plumed.getActionSet().selectWithLabel<multicolvar::MultiColvarBase*>(mlab);
42  if(!mycolv) error("action labeled " + mlab + " does not exist or is not a multicolvar");
44 
45  // Checks for neighbor list
46  if( mycolv->updateFreq>0 && updateFreq>0 ){
47  if( updateFreq%mycolv->updateFreq!=0 ) error("update frequency must be a multiple of the update frequency in the base colvar");
48  }
49 
50  // Retrieve the central atoms
52 }
53 
55  // Copy list of atoms involved from base multicolvar
56  for(unsigned i=0;i<mycolv->all_atoms.fullSize();++i){
57  all_atoms.addIndexToList( mycolv->all_atoms(i) );
58  }
60 }
61 
62 Vector MultiColvarFunction::getSeparation( const Vector& vec1, const Vector& vec2 ) const {
63  return mycolv->getSeparation( vec1, vec2 );
64 }
65 
67  plumed_massert( mycolv->contributorsAreUnlocked,"contributors in base colvar are not unlocked");
68  ActionWithVessel::unlockContributors();
69 }
70 
74 
75  // Store tasks that are currently active in base colvar
76  unsigned nactive=mycolv->taskList.getNumberActive();
77  std::vector<unsigned> active_tasks( nactive );
78  for(unsigned i=0;i<nactive;++i) active_tasks[i]=mycolv->taskList[i];
79 
80  // Now get the tasks that are active from here
82  for(unsigned i=0;i<taskList.getNumberActive();++i){
83  unsigned n=taskList[i];
84  for(unsigned j=0;j<colvar_atoms[n].getNumberActive();++j){
86  }
87  }
88 
89  // Add in tasks that are active in base
90  for(unsigned i=0;i<nactive;++i) mycolv->taskList.activate( active_tasks[i] );
91 
92  // Redo preparation step
93  mycolv->prepare();
94 
95  // And lock
96  ActionWithVessel::lockContributors();
97 }
98 
100  // Copy what is active in the base MultiColvar here
101  plumed_dbg_assert( all_atoms.fullSize()==mycolv->all_atoms.fullSize() );
102  all_atoms.deactivateAll();
103  for(unsigned i=0;i<mycolv->all_atoms.getNumberActive();++i){
104  unsigned iatom=mycolv->all_atoms.linkIndex( i );
105  all_atoms.activate( iatom );
106  }
107  all_atoms.updateActiveMembers();
108  // Request the atoms
109  ActionAtomistic::requestAtoms( all_atoms.retrieveActiveList() );
110  // Rerequest the dependency
112 }
113 
116  // Clear any derivatives in base colvar that were
117  // accumulated from previous calculations
119  // And recalculate
120  mycolv->calculate();
121  }
122  runAllTasks();
123 }
124 
125 double MultiColvarFunction::doCalculation( const unsigned& j ){
126  double val=compute(j);
128  return val;
129 }
130 
133 }
134 
136  Vector catom=getCentralAtom();
138  return catom;
139 }
140 
141 }
142 }
143 
Vector getSeparation(const Vector &vec1, const Vector &vec2) const
We use the distance from mycolv as otherwise numerical derivatives dont work.
Vector calculateCentralAtomPosition()
Calculate the position of the central atom.
Log & log
Reference to the log stream.
Definition: Action.h:93
Vector getSeparation(const Vector &vec1, const Vector &vec2) const
Get the separation between a pair of vectors.
void mpi_gatherActiveMembers(Communicator &comm, std::vector< DynamicList< U > > &ll)
Definition: DynamicList.h:318
void prepare()
Prepare for the calculation.
Class implementing fixed size vectors of doubles.
Definition: Vector.h:74
void unlockContributors()
Used to make sure we are calculating everything during neighbor list update step. ...
void error(const std::string &msg) const
Crash calculation and print documentation.
Definition: Action.cpp:195
multicolvar::StoreCentralAtomsVessel * catoms
The central atom positions.
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
Communicator & comm
Definition: Action.h:158
virtual void calculate()=0
Calculate an Action.
void activate(const unsigned ii)
Make something active.
Definition: DynamicList.h:263
virtual void calculateNumericalDerivatives(ActionWithValue *a=NULL)
N.B.
void updateActiveMembers()
Get the list of active members.
Definition: DynamicList.h:285
virtual Vector getCentralAtom()=0
Get the position of the central atom.
void runAllTasks()
Calculate the values of all the vessels.
void setupMultiColvarBase()
Finish setting up the multicolvar base.
void const char const char int * n
Definition: Matrix.h:42
void addDependency(Action *)
Specify that this Action depends on another one.
Definition: Action.cpp:123
Used to create a PLMD::Action that has some scalar or vectorial output that may or may not have some ...
DynamicList< unsigned > atomsWithCatomDer
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Definition: Action.h:273
This class holds the keywords and their documentation.
Definition: Keywords.h:36
virtual double compute(const unsigned &j)=0
Actually compute the colvar.
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)
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
StoreCentralAtomsVessel * getCentralAtoms()
Return a pointer to the vessel that stores the positions of all the central atoms.
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
void completeSetup()
Finish off the setup of the VectorFunction.
virtual void unlockContributors()
Used to make sure we are calculating everything during neighbor list update step. ...
void resizeDynamicArrays()
Resize the dynamic arrays.
DynamicList< unsigned > taskList
The list of tasks we have to perform.
bool checkNumericalDerivatives() const
Check if numerical derivatives should be used.
multicolvar::MultiColvarBase * mycolv
The multicolvar from which we construct these quantities.
void calculateNumericalDerivatives(ActionWithValue *a=NULL)
Calculate the numerical derivatives for this action.
double doCalculation(const unsigned &j)
Do the calculation.
virtual void clearDerivatives()
Clear the derivatives of values wrt parameters.
void requestAtoms(const std::vector< AtomNumber > &a)
Request an array of atoms.
Main plumed object.
Definition: Plumed.h:201
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.
static void registerKeywords(Keywords &keys)
void const char const char int double * a
Definition: Matrix.h:42
void deactivateAll()
Make everything in the list inactive.
Definition: DynamicList.h:255
bool contributorsAreUnlocked
The terms in the series are locked.
int updateFreq
Everything for controlling the updating of neighbor lists.
unsigned getNumberActive() const
Return the number of elements that are currently active.
Definition: DynamicList.h:230