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 : /// the vector of the forces 45 : std::vector<double> outputForces; 46 : /// the pointer to the bias component 47 : Value *valueBias; 48 : std::vector<double> f; 49 : std::vector<double> forces; 50 : protected: 51 : /// set the force from the bias on argument i, this automatically set the partial derivative of the bias with respect to i to -f 52 : void setOutputForce(int i,double f); 53 : /// set the value of the bias 54 : void setBias(double bias); 55 : public: 56 : static void registerKeywords(Keywords&); 57 : explicit Bias(const ActionOptions&ao); 58 : void apply() override; 59 : unsigned getNumberOfDerivatives() override; 60 : }; 61 : 62 : inline 63 177395 : void Bias::setOutputForce(int i,double f) { 64 177425 : outputForces[i]=f; 65 177425 : valueBias->addDerivative(i,-f); 66 177395 : } 67 : 68 : inline 69 101370 : void Bias::setBias(double bias) { 70 101370 : valueBias->set(bias); 71 101370 : } 72 : 73 : inline 74 1115 : unsigned Bias::getNumberOfDerivatives() { 75 1115 : return getNumberOfArguments(); 76 : } 77 : 78 : } 79 : } 80 : 81 : #endif 82 :