LCOV - code coverage report
Current view: top level - analysis - WhamHistogram.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 30 30 100.0 %
Date: 2024-10-11 08:09:47 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2018-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/ActionShortcut.h"
      23             : #include "core/ActionRegister.h"
      24             : 
      25             : namespace PLMD {
      26             : namespace analysis {
      27             : 
      28             : //+PLUMEDOC REWEIGHTING WHAM_HISTOGRAM
      29             : /*
      30             : This can be used to output the a histogram using the weighted histogram technique
      31             : 
      32             : This shortcut action allows you to calculate a histogram using the weighted histogram
      33             : analysis technique.  For more detail on how this the weights for configurations are
      34             : computed see \ref REWEIGHT_WHAM
      35             : 
      36             : \par Examples
      37             : 
      38             : The following input can be used to analyze the output from a series of umbrella sampling calculations.
      39             : The trajectory from each of the simulations run with the different biases should be concatenated into a
      40             : single trajectory before running the following analysis script on the concatenated trajectory using PLUMED
      41             : driver.  The umbrella sampling simulations that will be analyzed using the script below applied a harmonic
      42             : restraint that restrained the torsional angle involving atoms 5, 7, 9 and 15 to particular values.  The script
      43             : below calculates the reweighting weights for each of the trajectories and then applies the binless WHAM algorithm
      44             : to determine a weight for each configuration in the concatenated trajectory.  A histogram is then constructed from
      45             : the configurations visited and their weights.  This histogram is then converted into a free energy surface and output
      46             : to a file called fes.dat
      47             : 
      48             : \plumedfile
      49             : #SETTINGS NREPLICAS=4
      50             : phi: TORSION ATOMS=5,7,9,15
      51             : psi: TORSION ATOMS=7,9,15,17
      52             : rp: RESTRAINT ARG=phi KAPPA=50.0 ...
      53             :   AT=@replicas:{
      54             :         -3.00000000000000000000
      55             :         -1.45161290322580645168
      56             :         .09677419354838709664
      57             :         1.64516129032258064496
      58             :      }
      59             : ...
      60             : 
      61             : hh: WHAM_HISTOGRAM ARG=phi BIAS=rp.bias TEMP=300 GRID_MIN=-pi GRID_MAX=pi GRID_BIN=50
      62             : fes: CONVERT_TO_FES GRID=hh TEMP=300
      63             : DUMPGRID GRID=fes FILE=fes.dat
      64             : \endplumedfile
      65             : 
      66             : The script above must be run with multiple replicas using the following command:
      67             : 
      68             : \verbatim
      69             : mpirun -np 4 plumed driver --mf_xtc alltraj.xtc --multi 4
      70             : \endverbatim
      71             : 
      72             : */
      73             : //+ENDPLUMEDOC
      74             : 
      75             : class WhamHistogram : public ActionShortcut {
      76             : public:
      77             :   static void registerKeywords( Keywords& keys );
      78             :   explicit WhamHistogram( const ActionOptions& );
      79             : };
      80             : 
      81       10431 : PLUMED_REGISTER_ACTION(WhamHistogram,"WHAM_HISTOGRAM")
      82             : 
      83           7 : void WhamHistogram::registerKeywords( Keywords& keys ) {
      84           7 :   ActionShortcut::registerKeywords( keys );
      85          14 :   keys.add("compulsory","ARG","the arguments that you would like to make the histogram for");
      86          14 :   keys.add("compulsory","BIAS","*.bias","the value of the biases to use when performing WHAM");
      87          14 :   keys.add("compulsory","TEMP","the temperature at which the simulation was run");
      88          14 :   keys.add("compulsory","STRIDE","1","the frequency with which the data should be stored to perform WHAM");
      89          14 :   keys.add("compulsory","GRID_MIN","the minimum to use for the grid");
      90          14 :   keys.add("compulsory","GRID_MAX","the maximum to use for the grid");
      91          14 :   keys.add("compulsory","GRID_BIN","the number of bins to use for the grid");
      92          14 :   keys.add("optional","BANDWIDTH","the bandwidth for kernel density estimation");
      93           7 : }
      94             : 
      95             : 
      96           6 : WhamHistogram::WhamHistogram( const ActionOptions& ao ) :
      97             :   Action(ao),
      98           6 :   ActionShortcut(ao)
      99             : {
     100             :   // Input for REWEIGHT_WHAM
     101           6 :   std::string rew_line = getShortcutLabel() + "_weights: REWEIGHT_WHAM";
     102          18 :   std::string bias; parse("BIAS",bias); rew_line += " ARG=" + bias;
     103          12 :   std::string temp; parse("TEMP",temp); rew_line += " TEMP=" + temp;
     104           6 :   readInputLine( rew_line );
     105             :   // Input for COLLECT_FRAMES
     106          12 :   std::string col_line = getShortcutLabel() + "_collect: COLLECT_FRAMES LOGWEIGHTS=" + getShortcutLabel() + "_weights";
     107          18 :   std::string stride; parse("STRIDE",stride); col_line += " STRIDE=" + stride;
     108          12 :   std::string arg; parse("ARG",arg); col_line += " ARG=" + arg;
     109           6 :   readInputLine( col_line );
     110             :   // Input for HISTOGRAM
     111          12 :   std::string histo_line = getShortcutLabel() + ": HISTOGRAM ARG=" + getShortcutLabel() + "_collect.*";
     112          18 :   std::string min; parse("GRID_MIN",min); histo_line += " GRID_MIN=" + min;
     113          18 :   std::string max; parse("GRID_MAX",max); histo_line += " GRID_MAX=" + max;
     114          12 :   std::string bin; parse("GRID_BIN",bin); histo_line += " GRID_BIN=" + bin;
     115          12 :   std::string bw=""; parse("BANDWIDTH",bw);
     116           6 :   if( bw!="" ) histo_line += " BANDWIDTH=" + bw;
     117             :   else histo_line += " KERNEL=DISCRETE";
     118           6 :   readInputLine( histo_line );
     119           6 : }
     120             : 
     121             : }
     122             : }

Generated by: LCOV version 1.15