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_bias_Bias_h 23 : #define __PLUMED_bias_Bias_h 24 : 25 : #include "core/ActionPilot.h" 26 : #include "core/ActionWithValue.h" 27 : #include "core/ActionWithArguments.h" 28 : 29 : #define PLUMED_BIAS_INIT(ao) Action(ao),Bias(ao) 30 : 31 : namespace PLMD { 32 : namespace bias { 33 : 34 : /** 35 : \ingroup INHERIT 36 : This is the abstract base class to use for implementing new simulation biases, within it there is 37 : information as to how to go about implementing a new bias. 38 : */ 39 : 40 : class Bias : 41 : public ActionPilot, 42 : public ActionWithValue, 43 : public ActionWithArguments 44 : { 45 : /// the vector of the forces 46 : std::vector<double> outputForces; 47 : /// the pointer to the bias component 48 : Value *valueBias; 49 : std::vector<double> f; 50 : std::vector<double> forces; 51 : protected: 52 : /// set the force from the bias on argument i, this automatically set the partial derivative of the bias with respect to i to -f 53 : void setOutputForce(int i,double f); 54 : /// set the value of the bias 55 : void setBias(double bias); 56 : public: 57 : static void registerKeywords(Keywords&); 58 : explicit Bias(const ActionOptions&ao); 59 : void apply() override; 60 : unsigned getNumberOfDerivatives() override; 61 : }; 62 : 63 : inline 64 174821 : void Bias::setOutputForce(int i,double f) { 65 174851 : outputForces[i]=f; 66 174851 : valueBias->addDerivative(i,-f); 67 174821 : } 68 : 69 : inline 70 99204 : void Bias::setBias(double bias) { 71 99204 : valueBias->set(bias); 72 99204 : } 73 : 74 : inline 75 1088 : unsigned Bias::getNumberOfDerivatives() { 76 1088 : return getNumberOfArguments(); 77 : } 78 : 79 : } 80 : } 81 : 82 : #endif 83 :