LCOV - code coverage report
Current view: top level - bias - ReweightMetad.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 "core/ActionRegister.h"
      23             : #include "ReweightBase.h"
      24             : 
      25             : //+PLUMEDOC REWEIGHTING REWEIGHT_METAD
      26             : /*
      27             : Calculate the weights configurations should contribute to the histogram in a simulation in which a metadynamics bias acts upon the system.
      28             : 
      29             : This command allows you to use the reweighting algorithm discussed in \cite PratyushReweighting when constructing a histogram
      30             : of the configurations visited during a metadynamics simulation.
      31             : 
      32             : \par Examples
      33             : 
      34             : In the following example there is a metadynamics bias acting on the distance between atoms 1 and 2.  Clearly, this
      35             : bias will have an effect on the region of phase space that will be sampled when an MD simulation is
      36             : run using this variable.  Consequently, when the histogram as a function of the angle, \f$a\f$, is accumulated,
      37             : we use reweighting into order to discount the effect of the bias from our final histogram.  We do not use
      38             : \ref REWEIGHT_BIAS here, however, as the bias changes with time.  We thus use the reweighting algorithm for
      39             : metadynamics instead.  Notice also that we have to specify how often we would like to calculate the c(t) reweighting
      40             : factor and the grid over which we calculate c(t) in the input to the METAD command.
      41             : 
      42             : \plumedfile
      43             : a: ANGLE ATOMS=1,2,3
      44             : x: DISTANCE ATOMS=1,2
      45             : METAD ARG=x PACE=100 SIGMA=0.1 HEIGHT=1.5 BIASFACTOR=5 GRID_MIN=0 GRID_MAX=10 GRID_BIN=100 CALC_RCT RCT_USTRIDE=50
      46             : 
      47             : bias: REWEIGHT_METAD TEMP=300
      48             : 
      49             : HISTOGRAM ...
      50             :   ARG=a
      51             :   GRID_MIN=0.0
      52             :   GRID_MAX=pi
      53             :   GRID_BIN=100
      54             :   BANDWIDTH=0.1
      55             :   LOGWEIGHTS=bias
      56             :   LABEL=hB
      57             : ... HISTOGRAM
      58             : 
      59             : DUMPGRID GRID=hB FILE=histoB STRIDE=1 FMT=%8.4f
      60             : \endplumedfile
      61             : 
      62             : */
      63             : //+ENDPLUMEDOC
      64             : 
      65             : namespace PLMD {
      66             : namespace bias {
      67             : 
      68             : class ReweightMetad : public ReweightBase {
      69             : public:
      70             :   static void registerKeywords(Keywords&);
      71             :   explicit ReweightMetad(const ActionOptions&ao);
      72             :   double getLogWeight() override;
      73             : };
      74             : 
      75             : PLUMED_REGISTER_ACTION(ReweightMetad,"REWEIGHT_METAD")
      76             : 
      77           3 : void ReweightMetad::registerKeywords(Keywords& keys ) {
      78           3 :   ReweightBase::registerKeywords( keys ); keys.remove("ARG");
      79           6 :   keys.add("compulsory","ARG","*.rbias","the biases that must be taken into account when reweighting");
      80           3 :   keys.setValueDescription("the weight to use for this frame to negate the effect the metadynamics bias");
      81           3 : }
      82             : 
      83           1 : ReweightMetad::ReweightMetad(const ActionOptions&ao):
      84             :   Action(ao),
      85           1 :   ReweightBase(ao)
      86             : {
      87           1 : }
      88             : 
      89           2 : double ReweightMetad::getLogWeight() {
      90             :   // Retrieve the bias
      91           4 :   double bias=0.0; for(unsigned i=0; i<getNumberOfArguments(); ++i) bias+=getArgument(i);
      92           2 :   return bias / simtemp;
      93             : }
      94             : 
      95             : }
      96             : }

Generated by: LCOV version 1.16