Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-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 : #include "ReweightBase.h" 23 : #include "core/ActionRegister.h" 24 : 25 : //+PLUMEDOC REWEIGHTING REWEIGHT_BIAS 26 : /* 27 : Calculate weights for ensemble averages that negate the effect the bias has on the region of phase space explored 28 : 29 : If a static or pseudo-static bias \f$V(x,t')\f$ is acting on 30 : the system we can remove the bias and get the unbiased probability distribution using: 31 : 32 : \f[ 33 : \langle P(s',t) \rangle = \frac{ \sum_{t'}^t \delta( s(x) - s' ) \exp\left( +\frac{V(x,t')}{k_B T} \right) }{ \sum_t'^t \exp\left( +\frac{V(x,t')}{k_B T} \right) } 34 : \f] 35 : 36 : The weights calculated by this action are equal to \f$\exp\left( +\frac{V(x,t')}{k_B T} \right)\f$ these weights can then be used in any action 37 : that computes ensemble averages. For example this action can be used in tandem with \ref HISTOGRAM or \ref AVERAGE. 38 : 39 : \par Examples 40 : 41 : In the following example there is a fixed restraint on the distance between atoms 1 and 2. Clearly, this 42 : restraint will have an effect on the region of phase space that will be sampled when an MD simulation is 43 : run using this variable. Consequently, when the histogram as a function of the distance, \f$x\f$, is accumulated, 44 : we use reweighting into order to discount the effect of the bias from our final histogram. 45 : 46 : \plumedfile 47 : x: DISTANCE ATOMS=1,2 48 : RESTRAINT ARG=x SLOPE=1.0 AT=0.0 49 : bias: REWEIGHT_BIAS TEMP=300 50 : 51 : HISTOGRAM ... 52 : ARG=x 53 : GRID_MIN=0.0 54 : GRID_MAX=3.0 55 : GRID_BIN=100 56 : BANDWIDTH=0.1 57 : LOGWEIGHTS=bias 58 : LABEL=hB 59 : ... HISTOGRAM 60 : 61 : DUMPGRID GRID=hB FILE=histoB STRIDE=1 FMT=%8.4f 62 : \endplumedfile 63 : 64 : 65 : */ 66 : //+ENDPLUMEDOC 67 : 68 : namespace PLMD { 69 : namespace bias { 70 : 71 : class ReweightBias : public ReweightBase { 72 : public: 73 : static void registerKeywords(Keywords&); 74 : explicit ReweightBias(const ActionOptions&ao); 75 : double getLogWeight() override; 76 : }; 77 : 78 10425 : PLUMED_REGISTER_ACTION(ReweightBias,"REWEIGHT_BIAS") 79 : 80 4 : void ReweightBias::registerKeywords(Keywords& keys ) { 81 4 : ReweightBase::registerKeywords( keys ); keys.remove("ARG"); 82 8 : keys.add("compulsory","ARG","*.bias","the biases that must be taken into account when reweighting"); 83 4 : } 84 : 85 3 : ReweightBias::ReweightBias(const ActionOptions&ao): 86 : Action(ao), 87 3 : ReweightBase(ao) 88 : { 89 3 : } 90 : 91 1007 : double ReweightBias::getLogWeight() { 92 : // Retrieve the bias 93 2014 : double bias=0.0; for(unsigned i=0; i<getNumberOfArguments(); ++i) bias+=getArgument(i); 94 1007 : return bias / simtemp; 95 : } 96 : 97 : } 98 : }