Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-2019 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.org for more information.
6 :
7 : This file is part of plumed, version 2.
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 :
42 : class ActionWithArguments:
43 : public virtual Action
44 : {
45 : std::vector<Value*> arguments;
46 : bool lockRequestArguments;
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 : virtual 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 : /// Parse a numbered list of arguments
68 : bool parseArgumentList(const std::string&key,int i,std::vector<Value*>&args);
69 : /// Setup the dependencies
70 : void requestArguments(const std::vector<Value*> &arg);
71 : /// Add forces to arguments (used in apply)
72 : void addForcesOnArguments( const std::vector<double>& forces );
73 : public:
74 : explicit ActionWithArguments(const ActionOptions&);
75 1948 : virtual ~ActionWithArguments() {}
76 : /// Calculate the numerical derivatives
77 : /// N.B. only pass an ActionWithValue to this routine if you know exactly what you
78 : /// are doing. The default will be correct for the vast majority of cases
79 : virtual void calculateNumericalDerivatives( ActionWithValue* a=NULL );
80 : void lockRequests();
81 : void unlockRequests();
82 : /// Returns an array of pointers to the arguments
83 : const std::vector<Value*> & getArguments() const ;
84 : /// Convert a list of argument names into a list of pointers to the values
85 : void interpretArgumentList(const std::vector<std::string>& c, std::vector<Value*>&arg);
86 : };
87 :
88 :
89 : inline
90 : Value* ActionWithArguments::getPntrToArgument( const unsigned n ) {
91 6254382 : return arguments[n];
92 : }
93 :
94 : inline
95 : double ActionWithArguments::getArgument(const unsigned n) const {
96 393937 : return arguments[n]->get();
97 : }
98 :
99 : inline
100 4112656777 : unsigned ActionWithArguments::getNumberOfArguments()const {
101 4112819662 : return arguments.size();
102 : }
103 :
104 : inline
105 : double ActionWithArguments::difference(int i,double d1,double d2)const {
106 27734104 : return arguments[i]->difference(d1,d2);
107 : }
108 :
109 : inline
110 584 : double ActionWithArguments::bringBackInPbc(int i,double d1)const {
111 1752 : return arguments[i]->bringBackInPbc(d1);
112 : }
113 :
114 : inline
115 92929 : void ActionWithArguments::lockRequests() {
116 100081 : lockRequestArguments=true;
117 92929 : }
118 :
119 : inline
120 92929 : void ActionWithArguments::unlockRequests() {
121 95066 : lockRequestArguments=false;
122 92929 : }
123 :
124 : inline
125 : const std::vector<Value*> & ActionWithArguments::getArguments() const {
126 184676 : return arguments;
127 : }
128 :
129 : }
130 :
131 : #endif
|