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 "CoordinationBase.h"
23 #include "tools/SwitchingFunction.h"
24 #include "ActionRegister.h"
25 #include "core/PlumedMain.h"
26 #include "core/Atoms.h"
27 
28 #include <iostream>
29 
30 #include <string>
31 
32 using namespace std;
33 
34 namespace PLMD{
35 namespace colvar{
36 
37 //+PLUMEDOC COLVAR DHENERGY
38 /*
39 Calculate Debye-Huckel interaction energy among GROUPA and GROUPB.
40 
41 This variable calculates the electrostatic interaction among GROUPA and GROUPB
42 using a Debye-Huckel approximation defined as
43 \f[
44 \frac{1}{4\pi\epsilon_r\epsilon_0}
45 \sum_{i\in A} \sum_{j \in B} q_i q_j
46 \frac{e^{-\kappa |{\bf r}_{ij}|}}{|{\bf r}_{ij}|}
47 \f]
48 
49 This collective variable can be used to analyze or induce electrostatically driven reactions \cite do13jctc.
50 The two atom groups should be disjointed. Notice that the value of the DHENERGY is returned in plumed units (see \ref UNITS).
51 
52 \par Examples
53 \verbatim
54 # this is printing the electrostatic interaction between two groups of atoms
55 dh: DHENERGY GROUPA=1-10 GROUPB=11-20 EPSILON=80.0 I=0.1 TEMP=300.0
56 PRINT ARG=dh
57 \endverbatim
58 (see also \ref PRINT)
59 
60 */
61 //+ENDPLUMEDOC
62 
63 class DHEnergy : public CoordinationBase{
64  double k; // Inverse Debye screening length
65  double constant;
66  double epsilon;
67 
68 public:
69  DHEnergy(const ActionOptions&);
70 // active methods:
71  static void registerKeywords( Keywords& keys );
72  virtual double pairing(double distance,double&dfunc,unsigned i,unsigned j)const;
73 };
74 
75 PLUMED_REGISTER_ACTION(DHEnergy,"DHENERGY")
76 
77 void DHEnergy::registerKeywords( Keywords& keys ){
78  CoordinationBase::registerKeywords(keys);
79  keys.add("compulsory","I","1.0","Ionic strength (M)");
80  keys.add("compulsory","TEMP","300.0","Simulation temperature (K)");
81  keys.add("compulsory","EPSILON","80.0","Dielectric constant of solvent");
82 }
83 
84  /*
85  Global constants in SI unit used in this calculation:
86  N_A = 6.0221412927 * 10^(23) mol^(-1) : Avogadro number
87  q = 1.60217656535 * 10^(-19) C : proton charge
88  e_0 = 8.854187817620 * 10^(-12) C^2/(N*m^2) : vacuum's dielectric constant
89  k_B = 1.380648813 * 10^(-23) N*m/K : Boltzmann constant
90  In SI unit, Debye Huckel CV is defined as:
91  DHen = \sum_i\sum_j (q_i*q_j*q^2*N_A)/(4*pi*eps*e_0) * exp(-k*|f_ij|)/(|f_ij|)
92  + \sum_i\sum_j (q_i*q_j*q^2*N_A)/(4*pi*epp*e_0) * (1/|r_ij| - 1/|f_ij|)
93  = (q^2*N_A)/(4*pi*e_0) * \sum_i\sum_j q_i*q_j * (exp(-k*|f_ij|)/(eps*|f_ij|) + 1/epp*(1/|r_ij| - 1/|f_ij|))
94  (in which |f_ij| = \sqrt(|r_ij|^2+\sigma_i*\sigma_j*exp(-|r_ij|^2/4*\sigma_i*\sigma_j)),
95  \sigma_i and \sigma_j are the effective Born radius.)
96  For an efficient calculation, we group constants and variables into groups:
97  constant = (q^2*N_A)/(4*pi*e_0)
98  tmp = 1/eps*exp(-k*|f_ij|)/(|f_ij|) + 1/epp*(1/|r_ij| - 1/|f_ij|)
99 
100  To speed up the loop calculation, constant can be modified as followed:
101  constant= (q^2*N_A)/(4*pi*e_0*10^(-9))*10^(-3) (kJ/mol)
102  = ((1.60217656535*10^(-19))^2*6.0221412927*10^(23)*10^(-3))/(4*3.14159265*8.854187817620*10^(-12)*10^(-9))
103  = 138.935458111 (kJ/mol)
104 
105  */
106 
107 DHEnergy::DHEnergy(const ActionOptions&ao):
108 Action(ao),
109 CoordinationBase(ao),
110 k(0.0),
111 constant(0.0)
112 {
113  double I,T;
114  parse("I",I);
115  parse("TEMP",T);
116  parse("EPSILON",epsilon);
117  checkRead();
118  if( plumed.getAtoms().usingNaturalUnits() ) error("DHENERGY cannot be used for calculations performed with natural units");
119  constant=138.935458111/atoms.getUnits().getEnergy()/atoms.getUnits().getLength();
120  k=sqrt(I/(epsilon*T))*502.903741125*atoms.getUnits().getLength();
121  checkRead();
122  log<<" with solvent dielectric constant "<<epsilon<<"\n";
123  log<<" at temperature "<<T<<" K\n";
124  log<<" at ionic strength "<<I<< "M\n";
125  log<<" these parameters correspond to a screening length of "<<(1.0/k)<<"\n";
126  log<<" Bibliography "<<plumed.cite("Do, Carloni, Varani and Bussi, J. Chem. Theory Comput. 9, 1720 (2013)")<<" \n";
127 }
128 
129 double DHEnergy::pairing(double distance,double&dfunc,unsigned i,unsigned j)const{
131  dfunc=0.0;
132  return 0.0;
133  }
134  double invdistance=1.0/distance;
135  double tmp=exp(-k*distance)*invdistance*constant*getCharge(i)*getCharge(j)/epsilon;
136  double dtmp=-(k+invdistance)*tmp;
137  dfunc=dtmp*invdistance;
138  return tmp;
139 }
140 
141 }
142 
143 }
Log & log
Reference to the log stream.
Definition: Action.h:93
AtomNumber getAbsoluteIndex(int i) const
Get the absolute index of an atom.
void error(const std::string &msg) const
Crash calculation and print documentation.
Definition: Action.cpp:195
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Definition: Action.h:273
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
const double & getEnergy() const
Get energy units as double.
Definition: Units.h:90
Base class for all the input Actions.
Definition: Action.h:60
double getCharge(int i) const
Get charge of i-th atom.
virtual double pairing(double distance, double &dfunc, unsigned i, unsigned j) const
Definition: DHEnergy.cpp:129
const Units & getUnits()
Definition: Atoms.h:181
const double & getLength() const
Get length units as double.
Definition: Units.h:95
Provides the keyword DHENERGY
Definition: DHEnergy.cpp:63
Main plumed object.
Definition: Plumed.h:201