LCOV - code coverage report
Current view: top level - colvar - Energy.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 26 26 100.0 %
Date: 2024-10-11 08:09:47 Functions: 8 9 88.9 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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 "Colvar.h"
      23             : #include "ActionRegister.h"
      24             : #include "core/PlumedMain.h"
      25             : #include "core/Atoms.h"
      26             : 
      27             : namespace PLMD {
      28             : namespace colvar {
      29             : 
      30             : //+PLUMEDOC COLVAR ENERGY
      31             : /*
      32             : Calculate the total potential energy of the simulation box.
      33             : 
      34             : The potential energy can be biased e.g. with umbrella sampling \cite bart-karp98jpcb or with well-tempered metadynamics \cite Bonomi:2009p17935.
      35             : 
      36             : Notice that this CV could be unavailable with some MD code. When
      37             : it is available, and when also replica exchange is available,
      38             : metadynamics applied to ENERGY can be used to decrease the
      39             : number of required replicas.
      40             : 
      41             : \bug This \ref ENERGY does not include long tail corrections.
      42             : Thus when using e.g. LAMMPS `"pair_modify tail yes"` or GROMACS `"DispCorr Ener"` (or `"DispCorr EnerPres"`),
      43             : the potential energy from \ref ENERGY will be slightly different form the one of the MD code.
      44             : You should still be able to use \ref ENERGY and then reweight your simulation with the correct MD energy value.
      45             : 
      46             : \bug Acceptance for replica exchange when \ref ENERGY is biased
      47             : is computed correctly only if all the replicas have the same
      48             : potential energy function. This is for instance not true when
      49             : using GROMACS with lambda replica exchange or with plumed-hrex branch.
      50             : 
      51             : \par Examples
      52             : 
      53             : The following input instructs plumed to print the energy of the system
      54             : \plumedfile
      55             : ene: ENERGY
      56             : PRINT ARG=ene
      57             : \endplumedfile
      58             : 
      59             : */
      60             : //+ENDPLUMEDOC
      61             : 
      62             : 
      63             : class Energy : public Colvar {
      64             : 
      65             : public:
      66             :   explicit Energy(const ActionOptions&);
      67             : // active methods:
      68             :   void prepare() override;
      69             :   void calculate() override;
      70             :   unsigned getNumberOfDerivatives() override;
      71             :   static void registerKeywords( Keywords& keys );
      72             : };
      73             : 
      74             : 
      75       10499 : PLUMED_REGISTER_ACTION(Energy,"ENERGY")
      76             : 
      77          40 : Energy::Energy(const ActionOptions&ao):
      78          40 :   PLUMED_COLVAR_INIT(ao)
      79             : {
      80             : //  if(checkNumericalDerivatives())
      81             : //    error("Cannot use NUMERICAL_DERIVATIVES with ENERGY");
      82          40 :   isEnergy=true;
      83          40 :   addValueWithDerivatives(); setNotPeriodic();
      84          40 :   getPntrToValue()->resizeDerivatives(1);
      85          40 :   log<<"  Bibliography ";
      86          80 :   log<<plumed.cite("Bartels and Karplus, J. Phys. Chem. B 102, 865 (1998)");
      87          80 :   log<<plumed.cite("Bonomi and Parrinello, J. Comp. Chem. 30, 1615 (2009)");
      88          40 :   log<<"\n";
      89          40 : }
      90             : 
      91          41 : void Energy::registerKeywords( Keywords& keys ) {
      92          41 :   Action::registerKeywords( keys );
      93          41 :   ActionAtomistic::registerKeywords( keys );
      94          41 :   ActionWithValue::registerKeywords( keys );
      95          41 :   keys.remove("NUMERICAL_DERIVATIVES");
      96          41 : }
      97             : 
      98           2 : unsigned Energy::getNumberOfDerivatives() {
      99           2 :   return 1;
     100             : }
     101             : 
     102        3989 : void Energy::prepare() {
     103        3989 :   plumed.getAtoms().setCollectEnergy(true);
     104        3989 : }
     105             : 
     106             : // calculator
     107        3989 : void Energy::calculate() {
     108        3989 :   setValue( getEnergy() );
     109        3989 :   getPntrToComponent(0)->addDerivative(0,1.0);
     110        3989 : }
     111             : 
     112             : }
     113             : }
     114             : 
     115             : 
     116             : 

Generated by: LCOV version 1.15