LCOV - code coverage report
Current view: top level - bias - ReweightBias.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 11 11 100.0 %
Date: 2024-10-18 14:00:25 Functions: 3 4 75.0 %

          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             : PLUMED_REGISTER_ACTION(ReweightBias,"REWEIGHT_BIAS")
      79             : 
      80           5 : void ReweightBias::registerKeywords(Keywords& keys ) {
      81           5 :   ReweightBase::registerKeywords( keys ); keys.remove("ARG");
      82          10 :   keys.add("compulsory","ARG","*.bias","the biases that must be taken into account when reweighting");
      83           5 :   keys.setValueDescription("the weight to use for this frame to negate the effect the bias");
      84           5 : }
      85             : 
      86           3 : ReweightBias::ReweightBias(const ActionOptions&ao):
      87             :   Action(ao),
      88           3 :   ReweightBase(ao)
      89             : {
      90           3 : }
      91             : 
      92        1007 : double ReweightBias::getLogWeight() {
      93             :   // Retrieve the bias
      94        2014 :   double bias=0.0; for(unsigned i=0; i<getNumberOfArguments(); ++i) bias+=getArgument(i);
      95        1007 :   return bias / simtemp;
      96             : }
      97             : 
      98             : }
      99             : }

Generated by: LCOV version 1.16