Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-2018 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 : #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 :
51 : The following input instructs plumed to print the energy of the system
52 : \verbatim
53 : ENERGY LABEL=ene
54 : PRINT ARG=ene
55 : \endverbatim
56 : (See also \ref PRINT).
57 :
58 : */
59 : //+ENDPLUMEDOC
60 :
61 :
62 2 : class Energy : public Colvar {
63 :
64 : public:
65 : explicit Energy(const ActionOptions&);
66 : // active methods:
67 : void prepare();
68 : virtual void calculate();
69 : unsigned getNumberOfDerivatives();
70 : static void registerKeywords( Keywords& keys );
71 : };
72 :
73 :
74 : using namespace std;
75 :
76 :
77 2524 : PLUMED_REGISTER_ACTION(Energy,"ENERGY")
78 :
79 1 : Energy::Energy(const ActionOptions&ao):
80 1 : PLUMED_COLVAR_INIT(ao)
81 : {
82 : // if(checkNumericalDerivatives())
83 : // error("Cannot use NUMERICAL_DERIVATIVES with ENERGY");
84 1 : isEnergy=true;
85 1 : addValueWithDerivatives(); setNotPeriodic();
86 1 : getPntrToValue()->resizeDerivatives(1);
87 1 : log<<" Bibliography ";
88 1 : log<<plumed.cite("Bartels and Karplus, J. Phys. Chem. B 102, 865 (1998)");
89 1 : log<<plumed.cite("Bonomi and Parrinello, J. Comp. Chem. 30, 1615 (2009)");
90 1 : log<<"\n";
91 1 : }
92 :
93 2 : void Energy::registerKeywords( Keywords& keys ) {
94 2 : Action::registerKeywords( keys );
95 2 : ActionAtomistic::registerKeywords( keys );
96 2 : ActionWithValue::registerKeywords( keys );
97 2 : keys.remove("NUMERICAL_DERIVATIVES");
98 2 : }
99 :
100 2 : unsigned Energy::getNumberOfDerivatives() {
101 2 : return 1;
102 : }
103 :
104 50 : void Energy::prepare() {
105 50 : plumed.getAtoms().setCollectEnergy(true);
106 50 : }
107 :
108 : // calculator
109 50 : void Energy::calculate() {
110 50 : setValue( getEnergy() );
111 50 : getPntrToComponent(0)->addDerivative(0,1.0);
112 50 : }
113 :
114 : }
115 2523 : }
116 :
117 :
118 :
|