LCOV - code coverage report
Current view: top level - ves - TD_MarginalWellTempered.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 34 38 89.5 %
Date: 2019-08-13 10:15:31 Functions: 9 11 81.8 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-2017 The VES code team
       3             :    (see the PEOPLE-VES file at the root of this folder for a list of names)
       4             : 
       5             :    See http://www.ves-code.org for more information.
       6             : 
       7             :    This file is part of VES code module.
       8             : 
       9             :    The VES code module 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             :    The VES code module 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 the VES code module.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : 
      23             : #include "TargetDistribution.h"
      24             : #include "GridIntegrationWeights.h"
      25             : 
      26             : #include "core/ActionRegister.h"
      27             : #include "tools/Grid.h"
      28             : 
      29             : #include "GridProjWeights.h"
      30             : 
      31             : 
      32             : namespace PLMD {
      33             : namespace ves {
      34             : 
      35             : //+PLUMEDOC VES_TARGETDIST TD_MARGINAL_WELLTEMPERED
      36             : /*
      37             : One-dimensional marginal well-tempered target distribution (dynamic).
      38             : 
      39             : One-dimensional  marginal well-tempered distribution \cite Barducci:2008
      40             : given by
      41             : \f[
      42             : p(s_{k}) =
      43             : \frac{e^{-(\beta/\gamma) F(s_{k})}}
      44             : {\int ds_{k}\, e^{-(\beta/\gamma) F(s_{k})}} =
      45             : \frac{[P_{0}(s_{k})]^{1/\gamma}}
      46             : {\int ds_{k}\, [P_{0}(s_{k})]^{1/\gamma}}
      47             : \f]
      48             : where \f$\gamma\f$ is a so-called bias factor and \f$P_{0}(\mathbf{s})\f$ is the
      49             : unbiased canonical distribution of the CVs. This target distribution thus
      50             : correponds to a biased ensemble where, as compared to the unbiased one,
      51             : the probability peaks have been broaden and the fluctations of the CVs are
      52             : enhanced.
      53             : The value of the bias factor \f$\gamma\f$ determines by how much the fluctations
      54             : are enhanced.
      55             : 
      56             : 
      57             : \par Examples
      58             : 
      59             : */
      60             : //+ENDPLUMEDOC
      61             : 
      62             : class TD_MarginalWellTempered: public TargetDistribution {
      63             : private:
      64             :   double bias_factor_;
      65             :   std::vector<std::string> proj_args;
      66             : public:
      67             :   static void registerKeywords(Keywords&);
      68             :   explicit TD_MarginalWellTempered(const ActionOptions& ao);
      69             :   void updateGrid();
      70             :   double getValue(const std::vector<double>&) const;
      71           2 :   ~TD_MarginalWellTempered() {}
      72             : };
      73             : 
      74             : 
      75        7836 : PLUMED_REGISTER_ACTION(TD_MarginalWellTempered,"TD_MARGINAL_WELLTEMPERED")
      76             : 
      77             : 
      78           3 : void TD_MarginalWellTempered::registerKeywords(Keywords& keys) {
      79           3 :   TargetDistribution::registerKeywords(keys);
      80          12 :   keys.add("compulsory","BIASFACTOR","The bias factor to be used for the well tempered distribution");
      81          12 :   keys.add("compulsory","MARGINAL_ARG","The argument to be used for the marginal.");
      82           3 : }
      83             : 
      84             : 
      85           2 : TD_MarginalWellTempered::TD_MarginalWellTempered(const ActionOptions& ao):
      86             :   PLUMED_VES_TARGETDISTRIBUTION_INIT(ao),
      87             :   bias_factor_(0.0),
      88           2 :   proj_args(0)
      89             : {
      90           4 :   parse("BIASFACTOR",bias_factor_);
      91           2 :   if(bias_factor_<=1.0) {
      92           0 :     plumed_merror(getName()+" target distribution: the value of the bias factor doesn't make sense, it should be larger than 1.0");
      93             :   }
      94           4 :   parseVector("MARGINAL_ARG",proj_args);
      95           2 :   if(proj_args.size()!=1) {
      96           0 :     plumed_merror(getName()+" target distribution: currently only supports one marginal argument in MARGINAL_ARG");
      97             :   }
      98             :   setDynamic();
      99             :   setFesGridNeeded();
     100             :   doNotAllowBiasCutoff();
     101           2 :   checkRead();
     102           2 : }
     103             : 
     104             : 
     105           0 : double TD_MarginalWellTempered::getValue(const std::vector<double>& argument) const {
     106           0 :   plumed_merror("getValue not implemented for TD_MarginalWellTempered");
     107             :   return 0.0;
     108             : }
     109             : 
     110             : 
     111          22 : void TD_MarginalWellTempered::updateGrid() {
     112          22 :   double beta_prime = getBeta()/bias_factor_;
     113          22 :   plumed_massert(getFesGridPntr()!=NULL,"the FES grid has to be linked to use TD_MarginalWellTempered!");
     114             :   //
     115          22 :   FesWeight* Fw = new FesWeight(getBeta());
     116          22 :   Grid fes_proj = getFesGridPntr()->project(proj_args,Fw);
     117          22 :   delete Fw;
     118          44 :   plumed_massert(fes_proj.getSize()==targetDistGrid().getSize(),"problem with FES projection - inconsistent grids");
     119          22 :   plumed_massert(fes_proj.getDimension()==1,"problem with FES projection - projected grid is not one-dimensional");
     120             :   //
     121          88 :   std::vector<double> integration_weights = GridIntegrationWeights::getIntegrationWeights(getTargetDistGridPntr());
     122             :   double norm = 0.0;
     123        4444 :   for(Grid::index_t l=0; l<targetDistGrid().getSize(); l++) {
     124        2200 :     double value = beta_prime * fes_proj.getValue(l);
     125        2200 :     logTargetDistGrid().setValue(l,value);
     126        2200 :     value = exp(-value);
     127        2200 :     norm += integration_weights[l]*value;
     128        2200 :     targetDistGrid().setValue(l,value);
     129             :   }
     130          44 :   targetDistGrid().scaleAllValuesAndDerivatives(1.0/norm);
     131          44 :   logTargetDistGrid().setMinToZero();
     132          22 : }
     133             : 
     134             : }
     135        5874 : }

Generated by: LCOV version 1.14