All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DHEnergy.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 "vesselbase/VesselRegister.h"
23 #include "vesselbase/FunctionVessel.h"
24 #include "core/PlumedMain.h"
25 #include "core/Atoms.h"
26 #include "MultiColvar.h"
27 
28 namespace PLMD {
29 namespace multicolvar {
30 
32 private:
34  double I, T;
35  double k; // Inverse Debye screening length
36  double constant;
37  double epsilon;
38  std::vector<double> df;
39 public:
40  static void registerKeywords( Keywords& keys );
41  static void reserveKeyword( Keywords& keys );
43  std::string function_description();
44  bool calculate();
45  void finish();
46 };
47 
49 
50 void DHEnergy::registerKeywords( Keywords& keys ){
51  FunctionVessel::registerKeywords( keys );
52  keys.add("compulsory","I","1.0","Ionic strength (M)");
53  keys.add("compulsory","TEMP","300.0","Simulation temperature (K)");
54  keys.add("compulsory","EPSILON","80.0","Dielectric constant of solvent");
55 }
56 
58  keys.reserve("numbered","DHENERGY","calculate the Debye-Huckel interaction energy. This is a alternative "
59  "implementation of \\ref DHENERGY that is particularly useful if you "
60  "want to calculate the Debye-Huckel interaction energy and some other "
61  "function of set of distances between the atoms in the two groups. "
62  "The input for this keyword should read "
63  "DHENERGY={I=\\f$I\\f$ TEMP=\\f$T\\f$ EPSILON=\\f$\\epsilon\\f$}.");
64  keys.addOutputComponent("dhenergy","DHENERGY","the Debye-Huckel interaction energy. You can calculate "
65  "this quantity multiple times using different parameters");
66 }
67 
69 FunctionVessel(da),
70 df(2)
71 {
72  mycolv=dynamic_cast<MultiColvar*>( getAction() );
73  plumed_massert( mycolv, "DHENERGY can only be used with MultiColvars and should only be used with DISTANCES");
74 
75  parse("I",I); parse("TEMP",T); parse("EPSILON",epsilon);
76 
77  Atoms& catoms( getAction()->plumed.getAtoms() );
78  if( catoms.usingNaturalUnits() ) error("DHENERGY cannot be used for calculations performed with natural units");
79  constant=138.935458111/catoms.getUnits().getEnergy()/catoms.getUnits().getLength();
80  k=sqrt(I/(epsilon*T))*502.903741125*catoms.getUnits().getLength();
81 }
82 
84  std::ostringstream ostr;
85  ostr<<"the Debye-Huckel interaction energy "<<getAction()->plumed.cite("Do, Carloni, Varani and Bussi, J. Chem. Theory Comput. 9, 1720 (2013)")<<".";
86  ostr<<" Parameters : temperature "<<T<<" K, ionic strength "<<I<<" M, ";
87  ostr<<"solvent dielectric constant "<<epsilon;
88  return ostr.str();
89 }
90 
92  if( mycolv->getAbsoluteIndex(0)==mycolv->getAbsoluteIndex(1) ) return false;
93 
94  double val=getAction()->getElementValue(0);
95  double invdistance = 1.0 / val;
96  double f=exp(-k*val)*invdistance*constant*mycolv->getCharge(0)*mycolv->getCharge(1)/epsilon;
97  double dval=-(k+invdistance)*f;
99  getAction()->chainRuleForElementDerivatives( 0, 0, dval, this );
100  return true;
101 }
102 
105  df[0]=1.0; df[1]=0.0;
107 }
108 
109 }
110 }
std::vector< double > df
Definition: DHEnergy.cpp:38
static void registerKeywords(Keywords &keys)
Definition: DHEnergy.cpp:50
double getFinalValue(const unsigned &j)
Get the nth value in the distribution.
void chainRuleForElementDerivatives(const unsigned &, const unsigned &, const double &, Vessel *)
Merge the derivatives.
double getCharge(unsigned) const
Get the charge of atom iatom.
Definition: MultiColvar.h:103
std::string function_description()
The rest of the description of what we are calculating.
Definition: DHEnergy.cpp:83
void setOutputValue(const double &val)
Set the final value.
Objects that inherit from FunctionVessel can be used (in tandem with PLMD::ActionWithVessel) to calcu...
static void reserveKeyword(Keywords &keys)
Definition: DHEnergy.cpp:57
Class containing atom related quantities from the MD code.
Definition: Atoms.h:45
void mergeFinalDerivatives(const std::vector< double > &df)
This does a combination of the product and chain rules.
void addOutputComponent(const std::string &name, const std::string &key, const std::string &descr)
Add a potential component which can be output by this particular action.
Definition: Keywords.cpp:565
void finish()
Complete the calculation once the loop is finished.
Definition: DHEnergy.cpp:103
This class holds the keywords and their documentation.
Definition: Keywords.h:36
void addValueIgnoringTolerance(const unsigned &jval, const double &val)
Add some value to the accumulator and ignore the tolerance.
#define PLUMED_REGISTER_VESSEL(classname, keyword)
void reserve(const std::string &t, const std::string &k, const std::string &d, const bool isvessel=false)
Reserve a keyword.
Definition: Keywords.cpp:110
PlumedMain & plumed
Reference to main plumed object.
Definition: Action.h:90
void error(const std::string &errmsg)
Report an error.
Definition: Vessel.cpp:122
This class is used to pass the input to Vessels.
Definition: Vessel.h:53
bool calculate()
Calculate the part of the vessel that is done in the loop.
Definition: DHEnergy.cpp:91
AtomNumber getAbsoluteIndex(unsigned) const
Get the absolute index of atom iatom.
Definition: MultiColvar.h:108
This is the abstract base class to use for creating distributions of colvars and functions thereof...
Definition: MultiColvar.h:39
void int double * da
Definition: Matrix.h:47
DHEnergy(const vesselbase::VesselOptions &da)
Definition: DHEnergy.cpp:68
Main plumed object.
Definition: Plumed.h:201
void parse(const std::string &key, T &t)
Parse something from the input.
Definition: Vessel.h:169
std::string cite(const std::string &)
Add a citation, returning a string containing the reference number, something like "[10]"...
Definition: PlumedMain.cpp:652
double getElementValue(const unsigned &ival) const
Get the value of this element.
ActionWithVessel * getAction()
Return a pointer to the action we are working in.
Definition: Vessel.h:236