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 $V(x,t')$ is acting on 30 : the system we can remove the bias and get the unbiased probability distribution using: 31 : 32 : $$ 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 : $$ 35 : 36 : The weights calculated by this action are equal to $\exp\left( +\frac{V(x,t')}{k_B T} \right)$ these weights can then be used in any action 37 : that computes ensemble averages. For example this action can be used in tandem with [HISTOGRAM](HISTOGRAM.md) or [AVERAGE](AVERAGE.md). 38 : 39 : ## 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, $x$, is accumulated, 44 : we use reweighting into order to discount the effect of the bias from our final histogram. 45 : 46 : ```plumed 47 : x: DISTANCE ATOMS=1,2 48 : RESTRAINT ARG=x SLOPE=1.0 AT=0.0 49 : bias: REWEIGHT_BIAS TEMP=300 50 : 51 : hB: 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 : NORMALIZATION=true 59 : ... 60 : 61 : DUMPGRID ARG=hB FILE=histoB STRIDE=1 62 : ``` 63 : 64 : */ 65 : //+ENDPLUMEDOC 66 : 67 : namespace PLMD { 68 : namespace bias { 69 : 70 : class ReweightBias : public ReweightBase { 71 : public: 72 : static void registerKeywords(Keywords&); 73 : explicit ReweightBias(const ActionOptions&ao); 74 : double getLogWeight() override; 75 : }; 76 : 77 : PLUMED_REGISTER_ACTION(ReweightBias,"REWEIGHT_BIAS") 78 : 79 8 : void ReweightBias::registerKeywords(Keywords& keys ) { 80 8 : ReweightBase::registerKeywords( keys ); 81 16 : keys.addInputKeyword("compulsory","ARG","scalar","*.bias","the biases that must be taken into account when reweighting"); 82 16 : keys.setValueDescription("scalar","the weight to use for this frame to negate the effect the bias"); 83 8 : } 84 : 85 4 : ReweightBias::ReweightBias(const ActionOptions&ao): 86 : Action(ao), 87 4 : ReweightBase(ao) { 88 4 : } 89 : 90 1011 : double ReweightBias::getLogWeight() { 91 : // Retrieve the bias 92 : double bias=0.0; 93 2022 : for(unsigned i=0; i<getNumberOfArguments(); ++i) { 94 1011 : bias+=getArgument(i); 95 : } 96 1011 : return bias / simtemp; 97 : } 98 : 99 : } 100 : }