Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-2023 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 ActionSet; 43 : 44 : class ActionWithArguments: 45 : public virtual Action 46 : { 47 : std::vector<Value*> arguments; 48 : bool lockRequestArguments; 49 : protected: 50 : /// This changes the arg keyword in the pdb file 51 : void expandArgKeywordInPDB( const PDB& pdb ); 52 : public: 53 : /// Get the scalar product between the gradients of two variables 54 : double getProjection(unsigned i,unsigned j)const; 55 : /// Registers the list of keywords 56 : static void registerKeywords( Keywords& keys ); 57 : /// Returns the value of an argument 58 : double getArgument( const unsigned n ) const; 59 : /// Return a pointer to specific argument 60 : Value* getPntrToArgument( const unsigned n ) const; 61 : /// Returns the number of arguments 62 : virtual unsigned getNumberOfArguments() const ; 63 : /// Takes the difference taking into account pbc for arg i 64 : double difference(int, double, double) const; 65 : /// Takes one value and brings it back into the pbc of argument i 66 : double bringBackInPbc(int i,double d1)const; 67 : /// Parse a list of arguments 68 : void parseArgumentList(const std::string&key,std::vector<Value*>&args); 69 : /// Parse a numbered list of arguments 70 : bool parseArgumentList(const std::string&key,int i,std::vector<Value*>&args); 71 : /// Setup the dependencies 72 : void requestArguments(const std::vector<Value*> &arg); 73 : void requestExtraDependencies(const std::vector<Value*> &extra); 74 : /// Add forces to arguments (used in apply) 75 : void addForcesOnArguments( const unsigned& argstart, const std::vector<double>& forces, unsigned& ind, const std::string& c ); 76 : public: 77 : explicit ActionWithArguments(const ActionOptions&); 78 10200 : virtual ~ActionWithArguments() {} 79 : /// Calculate the numerical derivatives 80 : /// N.B. only pass an ActionWithValue to this routine if you know exactly what you 81 : /// are doing. The default will be correct for the vast majority of cases 82 : void calculateNumericalDerivatives( ActionWithValue* a=NULL ) override; 83 : void lockRequests() override; 84 : void unlockRequests() override; 85 : /// Returns an array of pointers to the arguments 86 : virtual const std::vector<Value*> & getArguments() const ; 87 : /// Convert a list of argument names into a list of pointers to the values 88 : static void interpretArgumentList(const std::vector<std::string>& c, const ActionSet& as, Action* action, std::vector<Value*>&arg); 89 : /// Used to calculate constant values in startup 90 : virtual bool calculateConstantValues( const bool& have_atoms ); 91 : /// Get the gradient for this action 92 : void setGradients( Value* myval, unsigned& start ) const ; 93 21105 : ActionWithArguments* castToActionWithArguments() noexcept final { return this; } 94 : }; 95 : 96 : 97 : inline 98 : Value* ActionWithArguments::getPntrToArgument( const unsigned n ) const { 99 971921158 : return arguments[n]; 100 : } 101 : 102 : inline 103 207350 : double ActionWithArguments::getArgument(const unsigned n) const { 104 207350 : return arguments[n]->get(); 105 : } 106 : 107 : inline 108 618212184 : unsigned ActionWithArguments::getNumberOfArguments()const { 109 618248319 : return arguments.size(); 110 : } 111 : 112 : inline 113 : double ActionWithArguments::difference(int i,double d1,double d2)const { 114 11460347 : return arguments[i]->difference(d1,d2); 115 : } 116 : 117 : inline 118 : double ActionWithArguments::bringBackInPbc(int i,double d1)const { 119 1427 : return arguments[i]->bringBackInPbc(d1); 120 : } 121 : 122 : inline 123 677766 : void ActionWithArguments::lockRequests() { 124 961288 : lockRequestArguments=true; 125 677766 : } 126 : 127 : inline 128 677766 : void ActionWithArguments::unlockRequests() { 129 961288 : lockRequestArguments=false; 130 677766 : } 131 : 132 : inline 133 186381 : const std::vector<Value*> & ActionWithArguments::getArguments() const { 134 186812 : return arguments; 135 : } 136 : 137 : } 138 : 139 : #endif