LCOV - code coverage report
Current view: top level - gridtools - ConvertToFES.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 22 22 100.0 %
Date: 2024-10-18 13:59:31 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2015-2020 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 "core/ActionShortcut.h"
      24             : #include "core/PlumedMain.h"
      25             : 
      26             : //+PLUMEDOC GRIDANALYSIS CONVERT_TO_FES
      27             : /*
      28             : Convert a histogram to a free energy surface.
      29             : 
      30             : This action allows you to take a free energy surface that was calculated using the \ref HISTOGRAM
      31             : action and to convert it to a free energy surface.  This transformation performed by doing:
      32             : 
      33             : \f[
      34             : F(x) = -k_B T \ln H(x)
      35             : \f]
      36             : 
      37             : The free energy calculated on a grid is output by this action and can be printed using \ref DUMPGRID
      38             : 
      39             : \par Examples
      40             : 
      41             : This is a typical example showing how CONVERT_TO_FES might be used when post processing a trajectory.
      42             : The input below calculates the free energy as a function of the distance between atom 1 and atom 2.
      43             : This is done by accumulating a histogram as a function of this distance using kernel density estimation
      44             : and the HISTOGRAM action.  All the data within this trajectory is used in the construction of this
      45             : HISTOGRAM.  Finally, once all the data has been read in, the histogram is converted to a free energy
      46             : using the formula above and the free energy is output to a file called fes.dat
      47             : 
      48             : \plumedfile
      49             : x: DISTANCE ATOMS=1,2
      50             : hA1: HISTOGRAM ARG=x GRID_MIN=0.0 GRID_MAX=3.0 GRID_BIN=100 BANDWIDTH=0.1
      51             : ff: CONVERT_TO_FES GRID=hA1 TEMP=300
      52             : DUMPGRID GRID=ff FILE=fes.dat
      53             : \endplumedfile
      54             : 
      55             : */
      56             : //+ENDPLUMEDOC
      57             : 
      58             : namespace PLMD {
      59             : namespace gridtools {
      60             : 
      61             : class ConvertToFES : public ActionShortcut {
      62             : public:
      63             :   static void registerKeywords( Keywords& keys );
      64             :   explicit ConvertToFES(const ActionOptions&ao);
      65             : };
      66             : 
      67             : PLUMED_REGISTER_ACTION(ConvertToFES,"CONVERT_TO_FES")
      68             : 
      69          17 : void ConvertToFES::registerKeywords( Keywords& keys ) {
      70          17 :   ActionShortcut::registerKeywords( keys );
      71          34 :   keys.add("optional","GRID","the histogram that you would like to convert into a free energy surface (old syntax)");
      72          34 :   keys.add("compulsory","ARG","the histogram that you would like to convert into a free energy surface");
      73          34 :   keys.add("optional","TEMP","the temperature at which you are operating");
      74          34 :   keys.addFlag("MINTOZERO",false,"set the minimum in the free energy to be equal to zero");
      75          34 :   keys.setValueDescription("grid","the free energy surface");
      76          34 :   keys.needsAction("FIND_GRID_MINIMUM"); keys.needsAction("CUSTOM");
      77          17 : }
      78             : 
      79          15 : ConvertToFES::ConvertToFES(const ActionOptions&ao):
      80             :   Action(ao),
      81          15 :   ActionShortcut(ao)
      82             : {
      83          15 :   bool minzero=false; parseFlag("MINTOZERO",minzero);
      84          15 :   double simtemp=getkBT(); if( simtemp==0 ) error("TEMP not set - use keyword TEMP");
      85             : 
      86          30 :   std::vector<std::string> argv; parseVector("GRID",argv);
      87          30 :   if( argv.size()==0 ) parseVector("ARG",argv);
      88          15 :   if( argv.size()!=1 ) error("should only have one argument");
      89             : 
      90          15 :   std::string str_temp; Tools::convert( simtemp, str_temp ); std::string flab=""; if( minzero ) flab="_unz";
      91          30 :   readInputLine( getShortcutLabel() + flab + ": CUSTOM ARG=" + argv[0] + " FUNC=-" + str_temp + "*log(x) PERIODIC=NO");
      92          15 :   if( minzero ) {
      93           4 :     readInputLine( getShortcutLabel() + "_min: FIND_GRID_MINIMUM ARG=" + getShortcutLabel() + "_unz" );
      94           4 :     readInputLine( getShortcutLabel() + ": CUSTOM ARG=" + getShortcutLabel() + "_unz," + getShortcutLabel() + "_min.optval FUNC=x-y PERIODIC=NO");
      95             :   }
      96          15 : }
      97             : 
      98             : }
      99             : }

Generated by: LCOV version 1.16