All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ActionWithArguments.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_ActionWithArguments_h
23 #define __PLUMED_core_ActionWithArguments_h
24 
25 #include "Action.h"
26 #include "Value.h"
27 #include <vector>
28 
29 namespace PLMD{
30 
31 /**
32 \ingroup MULTIINHERIT
33 This is used to create PLMD::Action objects that take the output from some other Action as input.
34 This is used in PLMD::Function and PLMD::Bias
35  PLMD::Action objects that inherit from PLMD::ActionWithArguments take
36  values and components calculated in other PLMD::Action objects and
37  use this information to calculate some new function. If you have
38  only one list of arguments you should use the reserved keyword <b> ARG </b>
39  when you use parseArgumentList.
40 */
41 
43  public virtual Action
44 {
45  std::vector<Value*> arguments;
47 protected:
48 /// This changes the arg keyword in the pdb file
49  void expandArgKeywordInPDB( PDB& pdb );
50 public:
51 /// Get the scalar product between the gradients of two variables
52  double getProjection(unsigned i,unsigned j)const;
53 /// Registers the list of keywords
54  static void registerKeywords( Keywords& keys );
55 /// Returns the value of an argument
56  double getArgument( const unsigned n ) const;
57 /// Return a pointer to specific argument
58  Value* getPntrToArgument( const unsigned n );
59 /// Returns the number of arguments
60  unsigned getNumberOfArguments() const ;
61 /// Takes the difference taking into account pbc for arg i
62  double difference(int, double, double) const;
63 /// Takes one value and brings it back into the pbc of argument i
64  double bringBackInPbc(int i,double d1)const;
65 /// Parse a list of arguments
66  void parseArgumentList(const std::string&key,std::vector<Value*>&args);
67 /// Setup the dependencies
68  void requestArguments(const std::vector<Value*> &arg);
69 /// Add forces to arguments (used in apply)
70  void addForcesOnArguments( const std::vector<double>& forces );
71 public:
74 /// Calculate the numerical derivatives
75 /// N.B. only pass an ActionWithValue to this routine if you know exactly what you
76 /// are doing. The default will be correct for the vast majority of cases
77  virtual void calculateNumericalDerivatives( ActionWithValue* a=NULL );
78  void lockRequests();
79  void unlockRequests();
80 /// Returns an array of pointers to the arguments
81  std::vector<Value*> & getArguments();
82 /// Convert a list of argument names into a list of pointers to the values
83  void interpretArgumentList(const std::vector<std::string>& c, std::vector<Value*>&arg);
84 };
85 
86 
87 inline
89  return arguments[n];
90 }
91 
92 inline
93 double ActionWithArguments::getArgument(const unsigned n) const {
94  return arguments[n]->get();
95 }
96 
97 inline
99  return arguments.size();
100 }
101 
102 inline
103 double ActionWithArguments::difference(int i,double d1,double d2)const{
104  return arguments[i]->difference(d1,d2);
105 }
106 
107 inline
108 double ActionWithArguments::bringBackInPbc(int i,double d1)const{
109  return arguments[i]->bringBackInPbc(d1);
110 }
111 
112 inline
115 }
116 
117 inline
119  lockRequestArguments=false;
120 }
121 
122 inline
123 std::vector<Value*> & ActionWithArguments::getArguments(){
124  return arguments;
125 }
126 
127 }
128 
129 #endif
virtual void calculateNumericalDerivatives(ActionWithValue *a=NULL)
Calculate the numerical derivatives N.B.
void parseArgumentList(const std::string &key, std::vector< Value * > &args)
Parse a list of arguments.
A class for holding the value of a function together with its derivatives.
Definition: Value.h:46
void interpretArgumentList(const std::vector< std::string > &c, std::vector< Value * > &arg)
Convert a list of argument names into a list of pointers to the values.
void requestArguments(const std::vector< Value * > &arg)
Setup the dependencies.
double difference(int, double, double) const
Takes the difference taking into account pbc for arg i.
static void registerKeywords(Keywords &keys)
Registers the list of keywords.
Value * getPntrToArgument(const unsigned n)
Return a pointer to specific argument.
This is used to create PLMD::Action objects that take the output from some other Action as input...
std::vector< Value * > arguments
void const char const char int * n
Definition: Matrix.h:42
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
double bringBackInPbc(int i, double d1) const
Takes one value and brings it back into the pbc of argument i.
std::vector< Value * > & getArguments()
Returns an array of pointers to the arguments.
void addForcesOnArguments(const std::vector< double > &forces)
Add forces to arguments (used in apply)
Base class for all the input Actions.
Definition: Action.h:60
double getProjection(unsigned i, unsigned j) const
Get the scalar product between the gradients of two variables.
Minimalistic pdb parser.
Definition: PDB.h:38
double getArgument(const unsigned n) const
Returns the value of an argument.
ActionWithArguments(const ActionOptions &)
void expandArgKeywordInPDB(PDB &pdb)
This changes the arg keyword in the pdb file.
void const char const char int double * a
Definition: Matrix.h:42
unsigned getNumberOfArguments() const
Returns the number of arguments.