All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Energy.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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 #include <string>
28 #include <cmath>
29 
30 namespace PLMD{
31 namespace colvar{
32 
33 //+PLUMEDOC COLVAR ENERGY
34 /*
35 Calculate the total energy of the simulation box.
36 
37 Total energy can be biased with umbrella sampling \cite bart-karp98jpcb or with well tempered metadynamics \cite Bonomi:2009p17935.
38 
39 Notice that this CV could be unavailable with some MD code. When
40 it is available, and when also replica exchange is available,
41 metadynamics applied to ENERGY can be used to decrease the
42 number of required replicas.
43 
44 \bug Acceptance for replica exchange when \ref ENERGY is biased
45 is computed correctly only of all the replicas has the same
46 potential energy function. This is for instance not true when
47 using GROMACS with lambda replica exchange of with plumed-hrex branch.
48 
49 \par Examples
50 The following input instructs plumed to print the energy of the system
51 \verbatim
52 ENERGY LABEL=ene
53 PRINT ARG=ene
54 \endverbatim
55 (See also \ref PRINT).
56 
57 */
58 //+ENDPLUMEDOC
59 
60 
61 class Energy : public Colvar {
62 
63 public:
64  Energy(const ActionOptions&);
65 // active methods:
66  void prepare();
67  virtual void calculate();
68  static void registerKeywords( Keywords& keys );
69 };
70 
71 
72 using namespace std;
73 
74 
75 PLUMED_REGISTER_ACTION(Energy,"ENERGY")
76 
79 {
80 // if(checkNumericalDerivatives())
81 // error("Cannot use NUMERICAL_DERIVATIVES with ENERGY");
82  isEnergy=true;
83  addValueWithDerivatives(); setNotPeriodic();
84  getPntrToValue()->resizeDerivatives(1);
85  log<<" Bibliography ";
86  log<<plumed.cite("Bartels and Karplus, J. Phys. Chem. B 102, 865 (1998)");
87  log<<plumed.cite("Bonomi and Parrinello, J. Comp. Chem. 30, 1615 (2009)");
88  log<<"\n";
89 }
90 
95  keys.remove("NUMERICAL_DERIVATIVES");
96 }
97 
99  plumed.getAtoms().setCollectEnergy(true);
100 }
101 
102 // calculator
104  setValue( getEnergy() );
105  getPntrToComponent(0)->addDerivative(0,1.0);
106 }
107 
108 }
109 }
110 
111 
112 
static void registerKeywords(Keywords &keys)
Register all the relevant keywords for the action.
static void registerKeywords(Keywords &keys)
Provides the keyword ENERGY
Definition: Energy.cpp:61
STL namespace.
#define PLUMED_COLVAR_INIT(ao)
Definition: Colvar.h:29
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
This is the abstract base class to use for implementing new collective variables, within it there is ...
Definition: Colvar.h:39
void prepare()
Prepare an Action for calculation This can be used by Action if they need some special preparation be...
Definition: Energy.cpp:98
static void registerKeywords(Keywords &keys)
Register all the relevant keywords for the action.
Definition: Action.cpp:49
Energy(const ActionOptions &)
Definition: Energy.cpp:77
void remove(const std::string &k)
Remove the keyword with name k.
Definition: Keywords.cpp:204
virtual void calculate()
Calculate an Action.
Definition: Energy.cpp:103
Main plumed object.
Definition: Plumed.h:201
static void registerKeywords(Keywords &keys)
Definition: Energy.cpp:91