1 |
gezelter |
1502 |
/* |
2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
|
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
6 |
|
|
* redistribute this software in source and binary code form, provided |
7 |
|
|
* that the following conditions are met: |
8 |
|
|
* |
9 |
|
|
* 1. Redistributions of source code must retain the above copyright |
10 |
|
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
|
* |
12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
|
* documentation and/or other materials provided with the |
15 |
|
|
* distribution. |
16 |
|
|
* |
17 |
|
|
* This software is provided "AS IS," without a warranty of any |
18 |
|
|
* kind. All express or implied conditions, representations and |
19 |
|
|
* warranties, including any implied warranty of merchantability, |
20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
22 |
|
|
* be liable for any damages suffered by licensee as a result of |
23 |
|
|
* using, modifying or distributing the software or its |
24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
27 |
|
|
* damages, however caused and regardless of the theory of liability, |
28 |
|
|
* arising out of the use of or inability to use software, even if the |
29 |
|
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
|
* such damages. |
31 |
|
|
* |
32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
|
|
* research, please cite the appropriate papers when you publish your |
34 |
|
|
* work. Good starting points are: |
35 |
|
|
* |
36 |
|
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
gezelter |
1587 |
* [2] Fennell & Gezelter, J. Chem. Phys. 124 234104 (2006). |
38 |
gezelter |
1502 |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
gezelter |
1665 |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
|
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
gezelter |
1502 |
*/ |
42 |
|
|
|
43 |
|
|
#include <stdio.h> |
44 |
|
|
#include <string.h> |
45 |
|
|
|
46 |
|
|
#include <cmath> |
47 |
|
|
#include "nonbonded/Electrostatic.hpp" |
48 |
|
|
#include "utils/simError.h" |
49 |
|
|
#include "types/NonBondedInteractionType.hpp" |
50 |
gezelter |
1710 |
#include "types/FixedChargeAdapter.hpp" |
51 |
gezelter |
1720 |
#include "types/FluctuatingChargeAdapter.hpp" |
52 |
gezelter |
1710 |
#include "types/MultipoleAdapter.hpp" |
53 |
gezelter |
1535 |
#include "io/Globals.hpp" |
54 |
gezelter |
1718 |
#include "nonbonded/SlaterIntegrals.hpp" |
55 |
|
|
#include "utils/PhysicalConstants.hpp" |
56 |
gezelter |
1502 |
|
57 |
gezelter |
1718 |
|
58 |
gezelter |
1502 |
namespace OpenMD { |
59 |
|
|
|
60 |
|
|
Electrostatic::Electrostatic(): name_("Electrostatic"), initialized_(false), |
61 |
gezelter |
1587 |
forceField_(NULL), info_(NULL), |
62 |
|
|
haveCutoffRadius_(false), |
63 |
|
|
haveDampingAlpha_(false), |
64 |
|
|
haveDielectric_(false), |
65 |
gezelter |
1586 |
haveElectroSpline_(false) |
66 |
gezelter |
1587 |
{} |
67 |
gezelter |
1502 |
|
68 |
|
|
void Electrostatic::initialize() { |
69 |
gezelter |
1587 |
|
70 |
gezelter |
1584 |
Globals* simParams_ = info_->getSimParams(); |
71 |
gezelter |
1535 |
|
72 |
gezelter |
1528 |
summationMap_["HARD"] = esm_HARD; |
73 |
gezelter |
1616 |
summationMap_["NONE"] = esm_HARD; |
74 |
gezelter |
1528 |
summationMap_["SWITCHING_FUNCTION"] = esm_SWITCHING_FUNCTION; |
75 |
|
|
summationMap_["SHIFTED_POTENTIAL"] = esm_SHIFTED_POTENTIAL; |
76 |
|
|
summationMap_["SHIFTED_FORCE"] = esm_SHIFTED_FORCE; |
77 |
|
|
summationMap_["REACTION_FIELD"] = esm_REACTION_FIELD; |
78 |
|
|
summationMap_["EWALD_FULL"] = esm_EWALD_FULL; |
79 |
|
|
summationMap_["EWALD_PME"] = esm_EWALD_PME; |
80 |
|
|
summationMap_["EWALD_SPME"] = esm_EWALD_SPME; |
81 |
|
|
screeningMap_["DAMPED"] = DAMPED; |
82 |
|
|
screeningMap_["UNDAMPED"] = UNDAMPED; |
83 |
|
|
|
84 |
gezelter |
1502 |
// these prefactors convert the multipole interactions into kcal / mol |
85 |
|
|
// all were computed assuming distances are measured in angstroms |
86 |
|
|
// Charge-Charge, assuming charges are measured in electrons |
87 |
|
|
pre11_ = 332.0637778; |
88 |
|
|
// Charge-Dipole, assuming charges are measured in electrons, and |
89 |
|
|
// dipoles are measured in debyes |
90 |
|
|
pre12_ = 69.13373; |
91 |
|
|
// Dipole-Dipole, assuming dipoles are measured in debyes |
92 |
|
|
pre22_ = 14.39325; |
93 |
|
|
// Charge-Quadrupole, assuming charges are measured in electrons, and |
94 |
|
|
// quadrupoles are measured in 10^-26 esu cm^2 |
95 |
|
|
// This unit is also known affectionately as an esu centi-barn. |
96 |
|
|
pre14_ = 69.13373; |
97 |
|
|
|
98 |
|
|
// conversions for the simulation box dipole moment |
99 |
|
|
chargeToC_ = 1.60217733e-19; |
100 |
|
|
angstromToM_ = 1.0e-10; |
101 |
|
|
debyeToCm_ = 3.33564095198e-30; |
102 |
|
|
|
103 |
|
|
// number of points for electrostatic splines |
104 |
|
|
np_ = 100; |
105 |
|
|
|
106 |
|
|
// variables to handle different summation methods for long-range |
107 |
|
|
// electrostatics: |
108 |
gezelter |
1528 |
summationMethod_ = esm_HARD; |
109 |
gezelter |
1502 |
screeningMethod_ = UNDAMPED; |
110 |
|
|
dielectric_ = 1.0; |
111 |
|
|
one_third_ = 1.0 / 3.0; |
112 |
|
|
|
113 |
gezelter |
1528 |
// check the summation method: |
114 |
|
|
if (simParams_->haveElectrostaticSummationMethod()) { |
115 |
|
|
string myMethod = simParams_->getElectrostaticSummationMethod(); |
116 |
|
|
toUpper(myMethod); |
117 |
|
|
map<string, ElectrostaticSummationMethod>::iterator i; |
118 |
|
|
i = summationMap_.find(myMethod); |
119 |
|
|
if ( i != summationMap_.end() ) { |
120 |
|
|
summationMethod_ = (*i).second; |
121 |
|
|
} else { |
122 |
|
|
// throw error |
123 |
|
|
sprintf( painCave.errMsg, |
124 |
gezelter |
1536 |
"Electrostatic::initialize: Unknown electrostaticSummationMethod.\n" |
125 |
gezelter |
1528 |
"\t(Input file specified %s .)\n" |
126 |
gezelter |
1616 |
"\telectrostaticSummationMethod must be one of: \"hard\",\n" |
127 |
gezelter |
1528 |
"\t\"shifted_potential\", \"shifted_force\", or \n" |
128 |
|
|
"\t\"reaction_field\".\n", myMethod.c_str() ); |
129 |
|
|
painCave.isFatal = 1; |
130 |
|
|
simError(); |
131 |
|
|
} |
132 |
|
|
} else { |
133 |
|
|
// set ElectrostaticSummationMethod to the cutoffMethod: |
134 |
|
|
if (simParams_->haveCutoffMethod()){ |
135 |
|
|
string myMethod = simParams_->getCutoffMethod(); |
136 |
|
|
toUpper(myMethod); |
137 |
|
|
map<string, ElectrostaticSummationMethod>::iterator i; |
138 |
|
|
i = summationMap_.find(myMethod); |
139 |
|
|
if ( i != summationMap_.end() ) { |
140 |
|
|
summationMethod_ = (*i).second; |
141 |
|
|
} |
142 |
|
|
} |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
if (summationMethod_ == esm_REACTION_FIELD) { |
146 |
|
|
if (!simParams_->haveDielectric()) { |
147 |
|
|
// throw warning |
148 |
|
|
sprintf( painCave.errMsg, |
149 |
|
|
"SimInfo warning: dielectric was not specified in the input file\n\tfor the reaction field correction method.\n" |
150 |
|
|
"\tA default value of %f will be used for the dielectric.\n", dielectric_); |
151 |
|
|
painCave.isFatal = 0; |
152 |
|
|
painCave.severity = OPENMD_INFO; |
153 |
|
|
simError(); |
154 |
|
|
} else { |
155 |
|
|
dielectric_ = simParams_->getDielectric(); |
156 |
|
|
} |
157 |
|
|
haveDielectric_ = true; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
if (simParams_->haveElectrostaticScreeningMethod()) { |
161 |
|
|
string myScreen = simParams_->getElectrostaticScreeningMethod(); |
162 |
|
|
toUpper(myScreen); |
163 |
|
|
map<string, ElectrostaticScreeningMethod>::iterator i; |
164 |
|
|
i = screeningMap_.find(myScreen); |
165 |
|
|
if ( i != screeningMap_.end()) { |
166 |
|
|
screeningMethod_ = (*i).second; |
167 |
|
|
} else { |
168 |
|
|
sprintf( painCave.errMsg, |
169 |
|
|
"SimInfo error: Unknown electrostaticScreeningMethod.\n" |
170 |
|
|
"\t(Input file specified %s .)\n" |
171 |
|
|
"\telectrostaticScreeningMethod must be one of: \"undamped\"\n" |
172 |
|
|
"or \"damped\".\n", myScreen.c_str() ); |
173 |
|
|
painCave.isFatal = 1; |
174 |
|
|
simError(); |
175 |
|
|
} |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
// check to make sure a cutoff value has been set: |
179 |
|
|
if (!haveCutoffRadius_) { |
180 |
|
|
sprintf( painCave.errMsg, "Electrostatic::initialize has no Default " |
181 |
|
|
"Cutoff value!\n"); |
182 |
|
|
painCave.severity = OPENMD_ERROR; |
183 |
|
|
painCave.isFatal = 1; |
184 |
|
|
simError(); |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
if (screeningMethod_ == DAMPED) { |
188 |
|
|
if (!simParams_->haveDampingAlpha()) { |
189 |
|
|
// first set a cutoff dependent alpha value |
190 |
|
|
// we assume alpha depends linearly with rcut from 0 to 20.5 ang |
191 |
|
|
dampingAlpha_ = 0.425 - cutoffRadius_* 0.02; |
192 |
|
|
if (dampingAlpha_ < 0.0) dampingAlpha_ = 0.0; |
193 |
|
|
|
194 |
|
|
// throw warning |
195 |
|
|
sprintf( painCave.errMsg, |
196 |
|
|
"Electrostatic::initialize: dampingAlpha was not specified in the input file.\n" |
197 |
|
|
"\tA default value of %f (1/ang) will be used for the cutoff of\n\t%f (ang).\n", |
198 |
|
|
dampingAlpha_, cutoffRadius_); |
199 |
|
|
painCave.severity = OPENMD_INFO; |
200 |
|
|
painCave.isFatal = 0; |
201 |
|
|
simError(); |
202 |
|
|
} else { |
203 |
|
|
dampingAlpha_ = simParams_->getDampingAlpha(); |
204 |
|
|
} |
205 |
|
|
haveDampingAlpha_ = true; |
206 |
|
|
} |
207 |
|
|
|
208 |
gezelter |
1502 |
// find all of the Electrostatic atom Types: |
209 |
|
|
ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes(); |
210 |
|
|
ForceField::AtomTypeContainer::MapTypeIterator i; |
211 |
|
|
AtomType* at; |
212 |
gezelter |
1528 |
|
213 |
gezelter |
1502 |
for (at = atomTypes->beginType(i); at != NULL; |
214 |
|
|
at = atomTypes->nextType(i)) { |
215 |
|
|
|
216 |
|
|
if (at->isElectrostatic()) |
217 |
|
|
addType(at); |
218 |
|
|
} |
219 |
|
|
|
220 |
gezelter |
1528 |
cutoffRadius2_ = cutoffRadius_ * cutoffRadius_; |
221 |
|
|
rcuti_ = 1.0 / cutoffRadius_; |
222 |
gezelter |
1502 |
rcuti2_ = rcuti_ * rcuti_; |
223 |
|
|
rcuti3_ = rcuti2_ * rcuti_; |
224 |
|
|
rcuti4_ = rcuti2_ * rcuti2_; |
225 |
|
|
|
226 |
|
|
if (screeningMethod_ == DAMPED) { |
227 |
gezelter |
1528 |
|
228 |
gezelter |
1502 |
alpha2_ = dampingAlpha_ * dampingAlpha_; |
229 |
|
|
alpha4_ = alpha2_ * alpha2_; |
230 |
|
|
alpha6_ = alpha4_ * alpha2_; |
231 |
|
|
alpha8_ = alpha4_ * alpha4_; |
232 |
|
|
|
233 |
gezelter |
1528 |
constEXP_ = exp(-alpha2_ * cutoffRadius2_); |
234 |
gezelter |
1502 |
invRootPi_ = 0.56418958354775628695; |
235 |
|
|
alphaPi_ = 2.0 * dampingAlpha_ * invRootPi_; |
236 |
|
|
|
237 |
gezelter |
1528 |
c1c_ = erfc(dampingAlpha_ * cutoffRadius_) * rcuti_; |
238 |
gezelter |
1502 |
c2c_ = alphaPi_ * constEXP_ * rcuti_ + c1c_ * rcuti_; |
239 |
|
|
c3c_ = 2.0 * alphaPi_ * alpha2_ + 3.0 * c2c_ * rcuti_; |
240 |
|
|
c4c_ = 4.0 * alphaPi_ * alpha4_ + 5.0 * c3c_ * rcuti2_; |
241 |
|
|
c5c_ = 8.0 * alphaPi_ * alpha6_ + 7.0 * c4c_ * rcuti2_; |
242 |
|
|
c6c_ = 16.0 * alphaPi_ * alpha8_ + 9.0 * c5c_ * rcuti2_; |
243 |
|
|
} else { |
244 |
|
|
c1c_ = rcuti_; |
245 |
|
|
c2c_ = c1c_ * rcuti_; |
246 |
|
|
c3c_ = 3.0 * c2c_ * rcuti_; |
247 |
|
|
c4c_ = 5.0 * c3c_ * rcuti2_; |
248 |
|
|
c5c_ = 7.0 * c4c_ * rcuti2_; |
249 |
|
|
c6c_ = 9.0 * c5c_ * rcuti2_; |
250 |
|
|
} |
251 |
|
|
|
252 |
gezelter |
1528 |
if (summationMethod_ == esm_REACTION_FIELD) { |
253 |
|
|
preRF_ = (dielectric_ - 1.0) / |
254 |
|
|
((2.0 * dielectric_ + 1.0) * cutoffRadius2_ * cutoffRadius_); |
255 |
|
|
preRF2_ = 2.0 * preRF_; |
256 |
gezelter |
1502 |
} |
257 |
gezelter |
1528 |
|
258 |
gezelter |
1613 |
// Add a 2 angstrom safety window to deal with cutoffGroups that |
259 |
|
|
// have charged atoms longer than the cutoffRadius away from each |
260 |
|
|
// other. Splining may not be the best choice here. Direct calls |
261 |
|
|
// to erfc might be preferrable. |
262 |
|
|
|
263 |
|
|
RealType dx = (cutoffRadius_ + 2.0) / RealType(np_ - 1); |
264 |
gezelter |
1502 |
RealType rval; |
265 |
|
|
vector<RealType> rvals; |
266 |
|
|
vector<RealType> yvals; |
267 |
|
|
for (int i = 0; i < np_; i++) { |
268 |
|
|
rval = RealType(i) * dx; |
269 |
|
|
rvals.push_back(rval); |
270 |
|
|
yvals.push_back(erfc(dampingAlpha_ * rval)); |
271 |
|
|
} |
272 |
|
|
erfcSpline_ = new CubicSpline(); |
273 |
|
|
erfcSpline_->addPoints(rvals, yvals); |
274 |
|
|
haveElectroSpline_ = true; |
275 |
|
|
|
276 |
|
|
initialized_ = true; |
277 |
|
|
} |
278 |
|
|
|
279 |
|
|
void Electrostatic::addType(AtomType* atomType){ |
280 |
|
|
|
281 |
|
|
ElectrostaticAtomData electrostaticAtomData; |
282 |
|
|
electrostaticAtomData.is_Charge = false; |
283 |
|
|
electrostaticAtomData.is_Dipole = false; |
284 |
|
|
electrostaticAtomData.is_SplitDipole = false; |
285 |
|
|
electrostaticAtomData.is_Quadrupole = false; |
286 |
gezelter |
1723 |
electrostaticAtomData.is_Fluctuating = false; |
287 |
gezelter |
1502 |
|
288 |
gezelter |
1710 |
FixedChargeAdapter fca = FixedChargeAdapter(atomType); |
289 |
gezelter |
1502 |
|
290 |
gezelter |
1710 |
if (fca.isFixedCharge()) { |
291 |
gezelter |
1502 |
electrostaticAtomData.is_Charge = true; |
292 |
gezelter |
1720 |
electrostaticAtomData.fixedCharge = fca.getCharge(); |
293 |
gezelter |
1502 |
} |
294 |
|
|
|
295 |
gezelter |
1710 |
MultipoleAdapter ma = MultipoleAdapter(atomType); |
296 |
|
|
if (ma.isMultipole()) { |
297 |
|
|
if (ma.isDipole()) { |
298 |
gezelter |
1502 |
electrostaticAtomData.is_Dipole = true; |
299 |
gezelter |
1710 |
electrostaticAtomData.dipole_moment = ma.getDipoleMoment(); |
300 |
gezelter |
1502 |
} |
301 |
gezelter |
1710 |
if (ma.isSplitDipole()) { |
302 |
gezelter |
1502 |
electrostaticAtomData.is_SplitDipole = true; |
303 |
gezelter |
1710 |
electrostaticAtomData.split_dipole_distance = ma.getSplitDipoleDistance(); |
304 |
gezelter |
1502 |
} |
305 |
gezelter |
1710 |
if (ma.isQuadrupole()) { |
306 |
gezelter |
1505 |
// Quadrupoles in OpenMD are set as the diagonal elements |
307 |
|
|
// of the diagonalized traceless quadrupole moment tensor. |
308 |
|
|
// The column vectors of the unitary matrix that diagonalizes |
309 |
|
|
// the quadrupole moment tensor become the eFrame (or the |
310 |
|
|
// electrostatic version of the body-fixed frame. |
311 |
gezelter |
1502 |
electrostaticAtomData.is_Quadrupole = true; |
312 |
gezelter |
1710 |
electrostaticAtomData.quadrupole_moments = ma.getQuadrupoleMoments(); |
313 |
gezelter |
1502 |
} |
314 |
|
|
} |
315 |
|
|
|
316 |
gezelter |
1718 |
FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType); |
317 |
gezelter |
1502 |
|
318 |
gezelter |
1718 |
if (fqa.isFluctuatingCharge()) { |
319 |
gezelter |
1720 |
electrostaticAtomData.is_Fluctuating = true; |
320 |
|
|
electrostaticAtomData.electronegativity = fqa.getElectronegativity(); |
321 |
|
|
electrostaticAtomData.hardness = fqa.getHardness(); |
322 |
|
|
electrostaticAtomData.slaterN = fqa.getSlaterN(); |
323 |
|
|
electrostaticAtomData.slaterZeta = fqa.getSlaterZeta(); |
324 |
gezelter |
1718 |
} |
325 |
|
|
|
326 |
gezelter |
1502 |
pair<map<int,AtomType*>::iterator,bool> ret; |
327 |
gezelter |
1710 |
ret = ElectrostaticList.insert( pair<int,AtomType*>(atomType->getIdent(), |
328 |
|
|
atomType) ); |
329 |
gezelter |
1502 |
if (ret.second == false) { |
330 |
|
|
sprintf( painCave.errMsg, |
331 |
|
|
"Electrostatic already had a previous entry with ident %d\n", |
332 |
gezelter |
1710 |
atomType->getIdent() ); |
333 |
gezelter |
1502 |
painCave.severity = OPENMD_INFO; |
334 |
|
|
painCave.isFatal = 0; |
335 |
|
|
simError(); |
336 |
|
|
} |
337 |
|
|
|
338 |
gezelter |
1718 |
ElectrostaticMap[atomType] = electrostaticAtomData; |
339 |
|
|
|
340 |
|
|
// Now, iterate over all known types and add to the mixing map: |
341 |
|
|
|
342 |
|
|
map<AtomType*, ElectrostaticAtomData>::iterator it; |
343 |
|
|
for( it = ElectrostaticMap.begin(); it != ElectrostaticMap.end(); ++it) { |
344 |
|
|
AtomType* atype2 = (*it).first; |
345 |
gezelter |
1720 |
ElectrostaticAtomData eaData2 = (*it).second; |
346 |
|
|
if (eaData2.is_Fluctuating && electrostaticAtomData.is_Fluctuating) { |
347 |
gezelter |
1718 |
|
348 |
|
|
RealType a = electrostaticAtomData.slaterZeta; |
349 |
gezelter |
1720 |
RealType b = eaData2.slaterZeta; |
350 |
gezelter |
1718 |
int m = electrostaticAtomData.slaterN; |
351 |
gezelter |
1720 |
int n = eaData2.slaterN; |
352 |
gezelter |
1718 |
|
353 |
|
|
// Create the spline of the coulombic integral for s-type |
354 |
|
|
// Slater orbitals. Add a 2 angstrom safety window to deal |
355 |
|
|
// with cutoffGroups that have charged atoms longer than the |
356 |
|
|
// cutoffRadius away from each other. |
357 |
|
|
|
358 |
gezelter |
1720 |
RealType rval; |
359 |
gezelter |
1718 |
RealType dr = (cutoffRadius_ + 2.0) / RealType(np_ - 1); |
360 |
|
|
vector<RealType> rvals; |
361 |
|
|
vector<RealType> J1vals; |
362 |
|
|
vector<RealType> J2vals; |
363 |
|
|
for (int i = 0; i < np_; i++) { |
364 |
|
|
rval = RealType(i) * dr; |
365 |
|
|
rvals.push_back(rval); |
366 |
|
|
J1vals.push_back( sSTOCoulInt( a, b, m, n, rval * PhysicalConstants::angstromsToBohr ) ); |
367 |
gezelter |
1721 |
// may not be necessary if Slater coulomb integral is symmetric |
368 |
gezelter |
1718 |
J2vals.push_back( sSTOCoulInt( b, a, n, m, rval * PhysicalConstants::angstromsToBohr ) ); |
369 |
|
|
} |
370 |
|
|
|
371 |
gezelter |
1720 |
CubicSpline* J1 = new CubicSpline(); |
372 |
gezelter |
1718 |
J1->addPoints(rvals, J1vals); |
373 |
gezelter |
1720 |
CubicSpline* J2 = new CubicSpline(); |
374 |
gezelter |
1718 |
J2->addPoints(rvals, J2vals); |
375 |
|
|
|
376 |
|
|
pair<AtomType*, AtomType*> key1, key2; |
377 |
|
|
key1 = make_pair(atomType, atype2); |
378 |
|
|
key2 = make_pair(atype2, atomType); |
379 |
|
|
|
380 |
|
|
Jij[key1] = J1; |
381 |
|
|
Jij[key2] = J2; |
382 |
|
|
} |
383 |
|
|
} |
384 |
|
|
|
385 |
gezelter |
1502 |
return; |
386 |
|
|
} |
387 |
|
|
|
388 |
gezelter |
1584 |
void Electrostatic::setCutoffRadius( RealType rCut ) { |
389 |
|
|
cutoffRadius_ = rCut; |
390 |
gezelter |
1528 |
rrf_ = cutoffRadius_; |
391 |
|
|
haveCutoffRadius_ = true; |
392 |
gezelter |
1502 |
} |
393 |
gezelter |
1584 |
|
394 |
|
|
void Electrostatic::setSwitchingRadius( RealType rSwitch ) { |
395 |
|
|
rt_ = rSwitch; |
396 |
|
|
} |
397 |
gezelter |
1502 |
void Electrostatic::setElectrostaticSummationMethod( ElectrostaticSummationMethod esm ) { |
398 |
|
|
summationMethod_ = esm; |
399 |
|
|
} |
400 |
|
|
void Electrostatic::setElectrostaticScreeningMethod( ElectrostaticScreeningMethod sm ) { |
401 |
|
|
screeningMethod_ = sm; |
402 |
|
|
} |
403 |
|
|
void Electrostatic::setDampingAlpha( RealType alpha ) { |
404 |
|
|
dampingAlpha_ = alpha; |
405 |
|
|
haveDampingAlpha_ = true; |
406 |
|
|
} |
407 |
|
|
void Electrostatic::setReactionFieldDielectric( RealType dielectric ){ |
408 |
|
|
dielectric_ = dielectric; |
409 |
|
|
haveDielectric_ = true; |
410 |
|
|
} |
411 |
|
|
|
412 |
gezelter |
1536 |
void Electrostatic::calcForce(InteractionData &idat) { |
413 |
gezelter |
1502 |
|
414 |
|
|
// utility variables. Should clean these up and use the Vector3d and |
415 |
|
|
// Mat3x3d to replace as many as we can in future versions: |
416 |
|
|
|
417 |
|
|
RealType q_i, q_j, mu_i, mu_j, d_i, d_j; |
418 |
|
|
RealType qxx_i, qyy_i, qzz_i; |
419 |
|
|
RealType qxx_j, qyy_j, qzz_j; |
420 |
|
|
RealType cx_i, cy_i, cz_i; |
421 |
|
|
RealType cx_j, cy_j, cz_j; |
422 |
|
|
RealType cx2, cy2, cz2; |
423 |
|
|
RealType ct_i, ct_j, ct_ij, a1; |
424 |
|
|
RealType riji, ri, ri2, ri3, ri4; |
425 |
|
|
RealType pref, vterm, epot, dudr; |
426 |
gezelter |
1587 |
RealType vpair(0.0); |
427 |
gezelter |
1502 |
RealType scale, sc2; |
428 |
|
|
RealType pot_term, preVal, rfVal; |
429 |
|
|
RealType c2ri, c3ri, c4rij, cti3, ctj3, ctidotj; |
430 |
|
|
RealType preSw, preSwSc; |
431 |
|
|
RealType c1, c2, c3, c4; |
432 |
gezelter |
1587 |
RealType erfcVal(1.0), derfcVal(0.0); |
433 |
gezelter |
1502 |
RealType BigR; |
434 |
gezelter |
1668 |
RealType two(2.0), three(3.0); |
435 |
gezelter |
1502 |
|
436 |
|
|
Vector3d Q_i, Q_j; |
437 |
|
|
Vector3d ux_i, uy_i, uz_i; |
438 |
|
|
Vector3d ux_j, uy_j, uz_j; |
439 |
|
|
Vector3d dudux_i, duduy_i, duduz_i; |
440 |
|
|
Vector3d dudux_j, duduy_j, duduz_j; |
441 |
|
|
Vector3d rhatdot2, rhatc4; |
442 |
|
|
Vector3d dVdr; |
443 |
|
|
|
444 |
gezelter |
1587 |
// variables for indirect (reaction field) interactions for excluded pairs: |
445 |
|
|
RealType indirect_Pot(0.0); |
446 |
|
|
RealType indirect_vpair(0.0); |
447 |
|
|
Vector3d indirect_dVdr(V3Zero); |
448 |
|
|
Vector3d indirect_duduz_i(V3Zero), indirect_duduz_j(V3Zero); |
449 |
|
|
|
450 |
gezelter |
1723 |
RealType coulInt, vFluc1(0.0), vFluc2(0.0); |
451 |
gezelter |
1502 |
pair<RealType, RealType> res; |
452 |
|
|
|
453 |
gezelter |
1721 |
// splines for coulomb integrals |
454 |
|
|
CubicSpline* J1; |
455 |
|
|
CubicSpline* J2; |
456 |
|
|
|
457 |
gezelter |
1502 |
if (!initialized_) initialize(); |
458 |
|
|
|
459 |
gezelter |
1571 |
ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first]; |
460 |
|
|
ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second]; |
461 |
gezelter |
1502 |
|
462 |
|
|
// some variables we'll need independent of electrostatic type: |
463 |
|
|
|
464 |
gezelter |
1554 |
riji = 1.0 / *(idat.rij) ; |
465 |
|
|
Vector3d rhat = *(idat.d) * riji; |
466 |
gezelter |
1502 |
|
467 |
|
|
// logicals |
468 |
|
|
|
469 |
|
|
bool i_is_Charge = data1.is_Charge; |
470 |
|
|
bool i_is_Dipole = data1.is_Dipole; |
471 |
|
|
bool i_is_SplitDipole = data1.is_SplitDipole; |
472 |
|
|
bool i_is_Quadrupole = data1.is_Quadrupole; |
473 |
gezelter |
1721 |
bool i_is_Fluctuating = data1.is_Fluctuating; |
474 |
gezelter |
1502 |
|
475 |
|
|
bool j_is_Charge = data2.is_Charge; |
476 |
|
|
bool j_is_Dipole = data2.is_Dipole; |
477 |
|
|
bool j_is_SplitDipole = data2.is_SplitDipole; |
478 |
|
|
bool j_is_Quadrupole = data2.is_Quadrupole; |
479 |
gezelter |
1721 |
bool j_is_Fluctuating = data2.is_Fluctuating; |
480 |
gezelter |
1502 |
|
481 |
gezelter |
1587 |
if (i_is_Charge) { |
482 |
gezelter |
1720 |
q_i = data1.fixedCharge; |
483 |
gezelter |
1721 |
|
484 |
|
|
if (i_is_Fluctuating) { |
485 |
|
|
q_i += *(idat.flucQ1); |
486 |
|
|
} |
487 |
|
|
|
488 |
gezelter |
1587 |
if (idat.excluded) { |
489 |
|
|
*(idat.skippedCharge2) += q_i; |
490 |
|
|
} |
491 |
|
|
} |
492 |
gezelter |
1502 |
|
493 |
|
|
if (i_is_Dipole) { |
494 |
|
|
mu_i = data1.dipole_moment; |
495 |
gezelter |
1554 |
uz_i = idat.eFrame1->getColumn(2); |
496 |
gezelter |
1502 |
|
497 |
|
|
ct_i = dot(uz_i, rhat); |
498 |
|
|
|
499 |
|
|
if (i_is_SplitDipole) |
500 |
|
|
d_i = data1.split_dipole_distance; |
501 |
|
|
|
502 |
|
|
duduz_i = V3Zero; |
503 |
|
|
} |
504 |
|
|
|
505 |
|
|
if (i_is_Quadrupole) { |
506 |
|
|
Q_i = data1.quadrupole_moments; |
507 |
|
|
qxx_i = Q_i.x(); |
508 |
|
|
qyy_i = Q_i.y(); |
509 |
|
|
qzz_i = Q_i.z(); |
510 |
|
|
|
511 |
gezelter |
1554 |
ux_i = idat.eFrame1->getColumn(0); |
512 |
|
|
uy_i = idat.eFrame1->getColumn(1); |
513 |
|
|
uz_i = idat.eFrame1->getColumn(2); |
514 |
gezelter |
1502 |
|
515 |
|
|
cx_i = dot(ux_i, rhat); |
516 |
|
|
cy_i = dot(uy_i, rhat); |
517 |
|
|
cz_i = dot(uz_i, rhat); |
518 |
|
|
|
519 |
|
|
dudux_i = V3Zero; |
520 |
|
|
duduy_i = V3Zero; |
521 |
|
|
duduz_i = V3Zero; |
522 |
|
|
} |
523 |
|
|
|
524 |
gezelter |
1587 |
if (j_is_Charge) { |
525 |
gezelter |
1720 |
q_j = data2.fixedCharge; |
526 |
gezelter |
1721 |
|
527 |
|
|
if (i_is_Fluctuating) |
528 |
|
|
q_j += *(idat.flucQ2); |
529 |
|
|
|
530 |
gezelter |
1587 |
if (idat.excluded) { |
531 |
|
|
*(idat.skippedCharge1) += q_j; |
532 |
|
|
} |
533 |
|
|
} |
534 |
gezelter |
1502 |
|
535 |
gezelter |
1587 |
|
536 |
gezelter |
1502 |
if (j_is_Dipole) { |
537 |
|
|
mu_j = data2.dipole_moment; |
538 |
gezelter |
1554 |
uz_j = idat.eFrame2->getColumn(2); |
539 |
gezelter |
1502 |
|
540 |
|
|
ct_j = dot(uz_j, rhat); |
541 |
|
|
|
542 |
|
|
if (j_is_SplitDipole) |
543 |
|
|
d_j = data2.split_dipole_distance; |
544 |
|
|
|
545 |
|
|
duduz_j = V3Zero; |
546 |
|
|
} |
547 |
|
|
|
548 |
|
|
if (j_is_Quadrupole) { |
549 |
|
|
Q_j = data2.quadrupole_moments; |
550 |
|
|
qxx_j = Q_j.x(); |
551 |
|
|
qyy_j = Q_j.y(); |
552 |
|
|
qzz_j = Q_j.z(); |
553 |
|
|
|
554 |
gezelter |
1554 |
ux_j = idat.eFrame2->getColumn(0); |
555 |
|
|
uy_j = idat.eFrame2->getColumn(1); |
556 |
|
|
uz_j = idat.eFrame2->getColumn(2); |
557 |
gezelter |
1502 |
|
558 |
|
|
cx_j = dot(ux_j, rhat); |
559 |
|
|
cy_j = dot(uy_j, rhat); |
560 |
|
|
cz_j = dot(uz_j, rhat); |
561 |
|
|
|
562 |
|
|
dudux_j = V3Zero; |
563 |
|
|
duduy_j = V3Zero; |
564 |
|
|
duduz_j = V3Zero; |
565 |
|
|
} |
566 |
|
|
|
567 |
gezelter |
1721 |
if (i_is_Fluctuating && j_is_Fluctuating) { |
568 |
|
|
J1 = Jij[idat.atypes]; |
569 |
|
|
J2 = Jij[make_pair(idat.atypes.second, idat.atypes.first)]; |
570 |
|
|
} |
571 |
|
|
|
572 |
gezelter |
1502 |
epot = 0.0; |
573 |
|
|
dVdr = V3Zero; |
574 |
|
|
|
575 |
|
|
if (i_is_Charge) { |
576 |
|
|
|
577 |
|
|
if (j_is_Charge) { |
578 |
|
|
if (screeningMethod_ == DAMPED) { |
579 |
|
|
// assemble the damping variables |
580 |
gezelter |
1616 |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
581 |
|
|
//erfcVal = res.first; |
582 |
|
|
//derfcVal = res.second; |
583 |
|
|
|
584 |
|
|
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
585 |
|
|
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
586 |
|
|
|
587 |
gezelter |
1502 |
c1 = erfcVal * riji; |
588 |
|
|
c2 = (-derfcVal + c1) * riji; |
589 |
|
|
} else { |
590 |
|
|
c1 = riji; |
591 |
|
|
c2 = c1 * riji; |
592 |
|
|
} |
593 |
|
|
|
594 |
gezelter |
1554 |
preVal = *(idat.electroMult) * pre11_ * q_i * q_j; |
595 |
gezelter |
1502 |
|
596 |
gezelter |
1528 |
if (summationMethod_ == esm_SHIFTED_POTENTIAL) { |
597 |
gezelter |
1502 |
vterm = preVal * (c1 - c1c_); |
598 |
gezelter |
1554 |
dudr = - *(idat.sw) * preVal * c2; |
599 |
gezelter |
1502 |
|
600 |
gezelter |
1528 |
} else if (summationMethod_ == esm_SHIFTED_FORCE) { |
601 |
gezelter |
1554 |
vterm = preVal * ( c1 - c1c_ + c2c_*( *(idat.rij) - cutoffRadius_) ); |
602 |
|
|
dudr = *(idat.sw) * preVal * (c2c_ - c2); |
603 |
gezelter |
1502 |
|
604 |
gezelter |
1528 |
} else if (summationMethod_ == esm_REACTION_FIELD) { |
605 |
gezelter |
1587 |
rfVal = preRF_ * *(idat.rij) * *(idat.rij); |
606 |
|
|
|
607 |
gezelter |
1502 |
vterm = preVal * ( riji + rfVal ); |
608 |
gezelter |
1554 |
dudr = *(idat.sw) * preVal * ( 2.0 * rfVal - riji ) * riji; |
609 |
gezelter |
1587 |
|
610 |
|
|
// if this is an excluded pair, there are still indirect |
611 |
|
|
// interactions via the reaction field we must worry about: |
612 |
gezelter |
1502 |
|
613 |
gezelter |
1587 |
if (idat.excluded) { |
614 |
|
|
indirect_vpair += preVal * rfVal; |
615 |
|
|
indirect_Pot += *(idat.sw) * preVal * rfVal; |
616 |
gezelter |
1668 |
indirect_dVdr += *(idat.sw) * preVal * two * rfVal * riji * rhat; |
617 |
gezelter |
1587 |
} |
618 |
|
|
|
619 |
gezelter |
1502 |
} else { |
620 |
|
|
|
621 |
gezelter |
1587 |
vterm = preVal * riji * erfcVal; |
622 |
gezelter |
1554 |
dudr = - *(idat.sw) * preVal * c2; |
623 |
gezelter |
1721 |
|
624 |
|
|
} |
625 |
gezelter |
1723 |
|
626 |
|
|
vpair += vterm; |
627 |
|
|
epot += *(idat.sw) * vterm; |
628 |
|
|
dVdr += dudr * rhat; |
629 |
gezelter |
1502 |
|
630 |
gezelter |
1721 |
if (i_is_Fluctuating) { |
631 |
gezelter |
1723 |
if (idat.excluded) { |
632 |
|
|
// vFluc1 is the difference between the direct coulomb integral |
633 |
|
|
// and the normal 1/r-like interaction between point charges. |
634 |
|
|
coulInt = J1->getValueAt( *(idat.rij) ); |
635 |
|
|
vFluc1 = pre11_ * coulInt * q_i * q_j - (*(idat.sw) * vterm); |
636 |
|
|
} else { |
637 |
|
|
vFluc1 = 0.0; |
638 |
gezelter |
1721 |
} |
639 |
gezelter |
1723 |
*(idat.dVdFQ1) += ( *(idat.sw) * vterm + vFluc1 ) / q_i; |
640 |
gezelter |
1502 |
} |
641 |
gezelter |
1723 |
|
642 |
gezelter |
1721 |
if (j_is_Fluctuating) { |
643 |
gezelter |
1723 |
if (idat.excluded) { |
644 |
|
|
// vFluc2 is the difference between the direct coulomb integral |
645 |
|
|
// and the normal 1/r-like interaction between point charges. |
646 |
|
|
coulInt = J2->getValueAt( *(idat.rij) ); |
647 |
|
|
vFluc2 = pre11_ * coulInt * q_i * q_j - (*(idat.sw) * vterm); |
648 |
|
|
} else { |
649 |
|
|
vFluc2 = 0.0; |
650 |
gezelter |
1721 |
} |
651 |
gezelter |
1723 |
*(idat.dVdFQ2) += ( *(idat.sw) * vterm + vFluc2 ) / q_j; |
652 |
gezelter |
1721 |
} |
653 |
gezelter |
1723 |
|
654 |
|
|
|
655 |
gezelter |
1502 |
} |
656 |
|
|
|
657 |
|
|
if (j_is_Dipole) { |
658 |
|
|
// pref is used by all the possible methods |
659 |
gezelter |
1554 |
pref = *(idat.electroMult) * pre12_ * q_i * mu_j; |
660 |
|
|
preSw = *(idat.sw) * pref; |
661 |
gezelter |
1502 |
|
662 |
gezelter |
1528 |
if (summationMethod_ == esm_REACTION_FIELD) { |
663 |
gezelter |
1502 |
ri2 = riji * riji; |
664 |
|
|
ri3 = ri2 * riji; |
665 |
|
|
|
666 |
gezelter |
1554 |
vterm = - pref * ct_j * ( ri2 - preRF2_ * *(idat.rij) ); |
667 |
gezelter |
1587 |
vpair += vterm; |
668 |
gezelter |
1554 |
epot += *(idat.sw) * vterm; |
669 |
gezelter |
1502 |
|
670 |
gezelter |
1668 |
dVdr += -preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j); |
671 |
gezelter |
1554 |
duduz_j += -preSw * rhat * (ri2 - preRF2_ * *(idat.rij) ); |
672 |
gezelter |
1502 |
|
673 |
gezelter |
1587 |
// Even if we excluded this pair from direct interactions, |
674 |
|
|
// we still have the reaction-field-mediated charge-dipole |
675 |
|
|
// interaction: |
676 |
|
|
|
677 |
|
|
if (idat.excluded) { |
678 |
|
|
indirect_vpair += pref * ct_j * preRF2_ * *(idat.rij); |
679 |
|
|
indirect_Pot += preSw * ct_j * preRF2_ * *(idat.rij); |
680 |
|
|
indirect_dVdr += preSw * preRF2_ * uz_j; |
681 |
|
|
indirect_duduz_j += preSw * rhat * preRF2_ * *(idat.rij); |
682 |
|
|
} |
683 |
|
|
|
684 |
gezelter |
1502 |
} else { |
685 |
|
|
// determine the inverse r used if we have split dipoles |
686 |
|
|
if (j_is_SplitDipole) { |
687 |
gezelter |
1554 |
BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j); |
688 |
gezelter |
1502 |
ri = 1.0 / BigR; |
689 |
gezelter |
1554 |
scale = *(idat.rij) * ri; |
690 |
gezelter |
1502 |
} else { |
691 |
|
|
ri = riji; |
692 |
|
|
scale = 1.0; |
693 |
|
|
} |
694 |
|
|
|
695 |
|
|
sc2 = scale * scale; |
696 |
|
|
|
697 |
|
|
if (screeningMethod_ == DAMPED) { |
698 |
|
|
// assemble the damping variables |
699 |
gezelter |
1616 |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
700 |
|
|
//erfcVal = res.first; |
701 |
|
|
//derfcVal = res.second; |
702 |
|
|
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
703 |
|
|
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
704 |
gezelter |
1502 |
c1 = erfcVal * ri; |
705 |
|
|
c2 = (-derfcVal + c1) * ri; |
706 |
|
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; |
707 |
|
|
} else { |
708 |
|
|
c1 = ri; |
709 |
|
|
c2 = c1 * ri; |
710 |
|
|
c3 = 3.0 * c2 * ri; |
711 |
|
|
} |
712 |
|
|
|
713 |
|
|
c2ri = c2 * ri; |
714 |
|
|
|
715 |
|
|
// calculate the potential |
716 |
|
|
pot_term = scale * c2; |
717 |
|
|
vterm = -pref * ct_j * pot_term; |
718 |
gezelter |
1587 |
vpair += vterm; |
719 |
gezelter |
1554 |
epot += *(idat.sw) * vterm; |
720 |
gezelter |
1502 |
|
721 |
|
|
// calculate derivatives for forces and torques |
722 |
|
|
|
723 |
|
|
dVdr += -preSw * (uz_j * c2ri - ct_j * rhat * sc2 * c3); |
724 |
|
|
duduz_j += -preSw * pot_term * rhat; |
725 |
|
|
|
726 |
|
|
} |
727 |
gezelter |
1723 |
if (i_is_Fluctuating) { |
728 |
|
|
*(idat.dVdFQ1) += ( *(idat.sw) * vterm ) / q_i; |
729 |
|
|
} |
730 |
gezelter |
1502 |
} |
731 |
|
|
|
732 |
|
|
if (j_is_Quadrupole) { |
733 |
|
|
// first precalculate some necessary variables |
734 |
|
|
cx2 = cx_j * cx_j; |
735 |
|
|
cy2 = cy_j * cy_j; |
736 |
|
|
cz2 = cz_j * cz_j; |
737 |
gezelter |
1554 |
pref = *(idat.electroMult) * pre14_ * q_i * one_third_; |
738 |
gezelter |
1502 |
|
739 |
|
|
if (screeningMethod_ == DAMPED) { |
740 |
|
|
// assemble the damping variables |
741 |
gezelter |
1616 |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
742 |
|
|
//erfcVal = res.first; |
743 |
|
|
//derfcVal = res.second; |
744 |
|
|
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
745 |
|
|
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
746 |
gezelter |
1502 |
c1 = erfcVal * riji; |
747 |
|
|
c2 = (-derfcVal + c1) * riji; |
748 |
|
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji; |
749 |
|
|
c4 = -4.0 * derfcVal * alpha4_ + 5.0 * c3 * riji * riji; |
750 |
|
|
} else { |
751 |
|
|
c1 = riji; |
752 |
|
|
c2 = c1 * riji; |
753 |
|
|
c3 = 3.0 * c2 * riji; |
754 |
|
|
c4 = 5.0 * c3 * riji * riji; |
755 |
|
|
} |
756 |
|
|
|
757 |
|
|
// precompute variables for convenience |
758 |
gezelter |
1554 |
preSw = *(idat.sw) * pref; |
759 |
gezelter |
1502 |
c2ri = c2 * riji; |
760 |
|
|
c3ri = c3 * riji; |
761 |
gezelter |
1554 |
c4rij = c4 * *(idat.rij) ; |
762 |
gezelter |
1668 |
rhatdot2 = two * rhat * c3; |
763 |
gezelter |
1502 |
rhatc4 = rhat * c4rij; |
764 |
|
|
|
765 |
|
|
// calculate the potential |
766 |
|
|
pot_term = ( qxx_j * (cx2*c3 - c2ri) + |
767 |
|
|
qyy_j * (cy2*c3 - c2ri) + |
768 |
|
|
qzz_j * (cz2*c3 - c2ri) ); |
769 |
|
|
vterm = pref * pot_term; |
770 |
gezelter |
1587 |
vpair += vterm; |
771 |
gezelter |
1554 |
epot += *(idat.sw) * vterm; |
772 |
gezelter |
1502 |
|
773 |
|
|
// calculate derivatives for the forces and torques |
774 |
|
|
|
775 |
gezelter |
1668 |
dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (two*cx_j*ux_j + rhat)*c3ri) + |
776 |
|
|
qyy_j* (cy2*rhatc4 - (two*cy_j*uy_j + rhat)*c3ri) + |
777 |
|
|
qzz_j* (cz2*rhatc4 - (two*cz_j*uz_j + rhat)*c3ri)); |
778 |
gezelter |
1502 |
|
779 |
|
|
dudux_j += preSw * qxx_j * cx_j * rhatdot2; |
780 |
|
|
duduy_j += preSw * qyy_j * cy_j * rhatdot2; |
781 |
|
|
duduz_j += preSw * qzz_j * cz_j * rhatdot2; |
782 |
gezelter |
1723 |
if (i_is_Fluctuating) { |
783 |
|
|
*(idat.dVdFQ1) += ( *(idat.sw) * vterm ) / q_i; |
784 |
|
|
} |
785 |
|
|
|
786 |
gezelter |
1502 |
} |
787 |
|
|
} |
788 |
|
|
|
789 |
|
|
if (i_is_Dipole) { |
790 |
|
|
|
791 |
|
|
if (j_is_Charge) { |
792 |
|
|
// variables used by all the methods |
793 |
gezelter |
1554 |
pref = *(idat.electroMult) * pre12_ * q_j * mu_i; |
794 |
|
|
preSw = *(idat.sw) * pref; |
795 |
gezelter |
1502 |
|
796 |
gezelter |
1528 |
if (summationMethod_ == esm_REACTION_FIELD) { |
797 |
gezelter |
1502 |
|
798 |
|
|
ri2 = riji * riji; |
799 |
|
|
ri3 = ri2 * riji; |
800 |
|
|
|
801 |
gezelter |
1554 |
vterm = pref * ct_i * ( ri2 - preRF2_ * *(idat.rij) ); |
802 |
gezelter |
1587 |
vpair += vterm; |
803 |
gezelter |
1554 |
epot += *(idat.sw) * vterm; |
804 |
gezelter |
1502 |
|
805 |
gezelter |
1668 |
dVdr += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_ * uz_i); |
806 |
gezelter |
1502 |
|
807 |
gezelter |
1554 |
duduz_i += preSw * rhat * (ri2 - preRF2_ * *(idat.rij) ); |
808 |
gezelter |
1587 |
|
809 |
|
|
// Even if we excluded this pair from direct interactions, |
810 |
|
|
// we still have the reaction-field-mediated charge-dipole |
811 |
|
|
// interaction: |
812 |
|
|
|
813 |
|
|
if (idat.excluded) { |
814 |
|
|
indirect_vpair += -pref * ct_i * preRF2_ * *(idat.rij); |
815 |
|
|
indirect_Pot += -preSw * ct_i * preRF2_ * *(idat.rij); |
816 |
|
|
indirect_dVdr += -preSw * preRF2_ * uz_i; |
817 |
|
|
indirect_duduz_i += -preSw * rhat * preRF2_ * *(idat.rij); |
818 |
|
|
} |
819 |
gezelter |
1502 |
|
820 |
|
|
} else { |
821 |
|
|
|
822 |
|
|
// determine inverse r if we are using split dipoles |
823 |
|
|
if (i_is_SplitDipole) { |
824 |
gezelter |
1554 |
BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i); |
825 |
gezelter |
1502 |
ri = 1.0 / BigR; |
826 |
gezelter |
1554 |
scale = *(idat.rij) * ri; |
827 |
gezelter |
1502 |
} else { |
828 |
|
|
ri = riji; |
829 |
|
|
scale = 1.0; |
830 |
|
|
} |
831 |
|
|
|
832 |
|
|
sc2 = scale * scale; |
833 |
|
|
|
834 |
|
|
if (screeningMethod_ == DAMPED) { |
835 |
|
|
// assemble the damping variables |
836 |
gezelter |
1616 |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
837 |
|
|
//erfcVal = res.first; |
838 |
|
|
//derfcVal = res.second; |
839 |
|
|
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
840 |
|
|
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
841 |
gezelter |
1502 |
c1 = erfcVal * ri; |
842 |
|
|
c2 = (-derfcVal + c1) * ri; |
843 |
|
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; |
844 |
|
|
} else { |
845 |
|
|
c1 = ri; |
846 |
|
|
c2 = c1 * ri; |
847 |
|
|
c3 = 3.0 * c2 * ri; |
848 |
|
|
} |
849 |
|
|
|
850 |
|
|
c2ri = c2 * ri; |
851 |
|
|
|
852 |
|
|
// calculate the potential |
853 |
|
|
pot_term = c2 * scale; |
854 |
|
|
vterm = pref * ct_i * pot_term; |
855 |
gezelter |
1587 |
vpair += vterm; |
856 |
gezelter |
1554 |
epot += *(idat.sw) * vterm; |
857 |
gezelter |
1502 |
|
858 |
|
|
// calculate derivatives for the forces and torques |
859 |
|
|
dVdr += preSw * (uz_i * c2ri - ct_i * rhat * sc2 * c3); |
860 |
|
|
duduz_i += preSw * pot_term * rhat; |
861 |
|
|
} |
862 |
gezelter |
1723 |
|
863 |
|
|
if (j_is_Fluctuating) { |
864 |
|
|
*(idat.dVdFQ2) += ( *(idat.sw) * vterm ) / q_j; |
865 |
|
|
} |
866 |
|
|
|
867 |
gezelter |
1502 |
} |
868 |
|
|
|
869 |
|
|
if (j_is_Dipole) { |
870 |
|
|
// variables used by all methods |
871 |
|
|
ct_ij = dot(uz_i, uz_j); |
872 |
|
|
|
873 |
gezelter |
1554 |
pref = *(idat.electroMult) * pre22_ * mu_i * mu_j; |
874 |
|
|
preSw = *(idat.sw) * pref; |
875 |
gezelter |
1502 |
|
876 |
gezelter |
1528 |
if (summationMethod_ == esm_REACTION_FIELD) { |
877 |
gezelter |
1502 |
ri2 = riji * riji; |
878 |
|
|
ri3 = ri2 * riji; |
879 |
|
|
ri4 = ri2 * ri2; |
880 |
|
|
|
881 |
|
|
vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) - |
882 |
|
|
preRF2_ * ct_ij ); |
883 |
gezelter |
1587 |
vpair += vterm; |
884 |
gezelter |
1554 |
epot += *(idat.sw) * vterm; |
885 |
gezelter |
1502 |
|
886 |
|
|
a1 = 5.0 * ct_i * ct_j - ct_ij; |
887 |
|
|
|
888 |
gezelter |
1668 |
dVdr += preSw * three * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i); |
889 |
gezelter |
1502 |
|
890 |
gezelter |
1668 |
duduz_i += preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j); |
891 |
|
|
duduz_j += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_*uz_i); |
892 |
gezelter |
1502 |
|
893 |
gezelter |
1587 |
if (idat.excluded) { |
894 |
|
|
indirect_vpair += - pref * preRF2_ * ct_ij; |
895 |
|
|
indirect_Pot += - preSw * preRF2_ * ct_ij; |
896 |
|
|
indirect_duduz_i += -preSw * preRF2_ * uz_j; |
897 |
|
|
indirect_duduz_j += -preSw * preRF2_ * uz_i; |
898 |
|
|
} |
899 |
|
|
|
900 |
gezelter |
1502 |
} else { |
901 |
|
|
|
902 |
|
|
if (i_is_SplitDipole) { |
903 |
|
|
if (j_is_SplitDipole) { |
904 |
gezelter |
1554 |
BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i + 0.25 * d_j * d_j); |
905 |
gezelter |
1502 |
} else { |
906 |
gezelter |
1554 |
BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i); |
907 |
gezelter |
1502 |
} |
908 |
|
|
ri = 1.0 / BigR; |
909 |
gezelter |
1554 |
scale = *(idat.rij) * ri; |
910 |
gezelter |
1502 |
} else { |
911 |
|
|
if (j_is_SplitDipole) { |
912 |
gezelter |
1554 |
BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j); |
913 |
gezelter |
1502 |
ri = 1.0 / BigR; |
914 |
gezelter |
1554 |
scale = *(idat.rij) * ri; |
915 |
gezelter |
1502 |
} else { |
916 |
|
|
ri = riji; |
917 |
|
|
scale = 1.0; |
918 |
|
|
} |
919 |
|
|
} |
920 |
|
|
if (screeningMethod_ == DAMPED) { |
921 |
|
|
// assemble damping variables |
922 |
gezelter |
1616 |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
923 |
|
|
//erfcVal = res.first; |
924 |
|
|
//derfcVal = res.second; |
925 |
|
|
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
926 |
|
|
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
927 |
gezelter |
1502 |
c1 = erfcVal * ri; |
928 |
|
|
c2 = (-derfcVal + c1) * ri; |
929 |
|
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; |
930 |
|
|
c4 = -4.0 * derfcVal * alpha4_ + 5.0 * c3 * ri * ri; |
931 |
|
|
} else { |
932 |
|
|
c1 = ri; |
933 |
|
|
c2 = c1 * ri; |
934 |
|
|
c3 = 3.0 * c2 * ri; |
935 |
|
|
c4 = 5.0 * c3 * ri * ri; |
936 |
|
|
} |
937 |
|
|
|
938 |
|
|
// precompute variables for convenience |
939 |
|
|
sc2 = scale * scale; |
940 |
|
|
cti3 = ct_i * sc2 * c3; |
941 |
|
|
ctj3 = ct_j * sc2 * c3; |
942 |
|
|
ctidotj = ct_i * ct_j * sc2; |
943 |
|
|
preSwSc = preSw * scale; |
944 |
|
|
c2ri = c2 * ri; |
945 |
|
|
c3ri = c3 * ri; |
946 |
gezelter |
1554 |
c4rij = c4 * *(idat.rij) ; |
947 |
gezelter |
1502 |
|
948 |
|
|
// calculate the potential |
949 |
|
|
pot_term = (ct_ij * c2ri - ctidotj * c3); |
950 |
|
|
vterm = pref * pot_term; |
951 |
gezelter |
1587 |
vpair += vterm; |
952 |
gezelter |
1554 |
epot += *(idat.sw) * vterm; |
953 |
gezelter |
1502 |
|
954 |
|
|
// calculate derivatives for the forces and torques |
955 |
|
|
dVdr += preSwSc * ( ctidotj * rhat * c4rij - |
956 |
|
|
(ct_i*uz_j + ct_j*uz_i + ct_ij*rhat) * c3ri); |
957 |
|
|
|
958 |
|
|
duduz_i += preSw * (uz_j * c2ri - ctj3 * rhat); |
959 |
|
|
duduz_j += preSw * (uz_i * c2ri - cti3 * rhat); |
960 |
|
|
} |
961 |
|
|
} |
962 |
|
|
} |
963 |
|
|
|
964 |
|
|
if (i_is_Quadrupole) { |
965 |
|
|
if (j_is_Charge) { |
966 |
|
|
// precompute some necessary variables |
967 |
|
|
cx2 = cx_i * cx_i; |
968 |
|
|
cy2 = cy_i * cy_i; |
969 |
|
|
cz2 = cz_i * cz_i; |
970 |
|
|
|
971 |
gezelter |
1554 |
pref = *(idat.electroMult) * pre14_ * q_j * one_third_; |
972 |
gezelter |
1502 |
|
973 |
|
|
if (screeningMethod_ == DAMPED) { |
974 |
|
|
// assemble the damping variables |
975 |
gezelter |
1616 |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
976 |
|
|
//erfcVal = res.first; |
977 |
|
|
//derfcVal = res.second; |
978 |
|
|
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
979 |
|
|
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
980 |
gezelter |
1502 |
c1 = erfcVal * riji; |
981 |
|
|
c2 = (-derfcVal + c1) * riji; |
982 |
|
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji; |
983 |
|
|
c4 = -4.0 * derfcVal * alpha4_ + 5.0 * c3 * riji * riji; |
984 |
|
|
} else { |
985 |
|
|
c1 = riji; |
986 |
|
|
c2 = c1 * riji; |
987 |
|
|
c3 = 3.0 * c2 * riji; |
988 |
|
|
c4 = 5.0 * c3 * riji * riji; |
989 |
|
|
} |
990 |
|
|
|
991 |
|
|
// precompute some variables for convenience |
992 |
gezelter |
1554 |
preSw = *(idat.sw) * pref; |
993 |
gezelter |
1502 |
c2ri = c2 * riji; |
994 |
|
|
c3ri = c3 * riji; |
995 |
gezelter |
1554 |
c4rij = c4 * *(idat.rij) ; |
996 |
gezelter |
1668 |
rhatdot2 = two * rhat * c3; |
997 |
gezelter |
1502 |
rhatc4 = rhat * c4rij; |
998 |
|
|
|
999 |
|
|
// calculate the potential |
1000 |
|
|
pot_term = ( qxx_i * (cx2 * c3 - c2ri) + |
1001 |
|
|
qyy_i * (cy2 * c3 - c2ri) + |
1002 |
|
|
qzz_i * (cz2 * c3 - c2ri) ); |
1003 |
|
|
|
1004 |
|
|
vterm = pref * pot_term; |
1005 |
gezelter |
1587 |
vpair += vterm; |
1006 |
gezelter |
1554 |
epot += *(idat.sw) * vterm; |
1007 |
gezelter |
1502 |
|
1008 |
|
|
// calculate the derivatives for the forces and torques |
1009 |
|
|
|
1010 |
gezelter |
1668 |
dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (two*cx_i*ux_i + rhat)*c3ri) + |
1011 |
|
|
qyy_i* (cy2*rhatc4 - (two*cy_i*uy_i + rhat)*c3ri) + |
1012 |
|
|
qzz_i* (cz2*rhatc4 - (two*cz_i*uz_i + rhat)*c3ri)); |
1013 |
gezelter |
1502 |
|
1014 |
|
|
dudux_i += preSw * qxx_i * cx_i * rhatdot2; |
1015 |
|
|
duduy_i += preSw * qyy_i * cy_i * rhatdot2; |
1016 |
|
|
duduz_i += preSw * qzz_i * cz_i * rhatdot2; |
1017 |
gezelter |
1723 |
|
1018 |
|
|
if (j_is_Fluctuating) { |
1019 |
|
|
*(idat.dVdFQ2) += ( *(idat.sw) * vterm ) / q_j; |
1020 |
|
|
} |
1021 |
|
|
|
1022 |
gezelter |
1502 |
} |
1023 |
|
|
} |
1024 |
|
|
|
1025 |
|
|
|
1026 |
gezelter |
1587 |
if (!idat.excluded) { |
1027 |
|
|
*(idat.vpair) += vpair; |
1028 |
|
|
(*(idat.pot))[ELECTROSTATIC_FAMILY] += epot; |
1029 |
|
|
*(idat.f1) += dVdr; |
1030 |
|
|
|
1031 |
|
|
if (i_is_Dipole || i_is_Quadrupole) |
1032 |
|
|
*(idat.t1) -= cross(uz_i, duduz_i); |
1033 |
|
|
if (i_is_Quadrupole) { |
1034 |
|
|
*(idat.t1) -= cross(ux_i, dudux_i); |
1035 |
|
|
*(idat.t1) -= cross(uy_i, duduy_i); |
1036 |
|
|
} |
1037 |
|
|
|
1038 |
|
|
if (j_is_Dipole || j_is_Quadrupole) |
1039 |
|
|
*(idat.t2) -= cross(uz_j, duduz_j); |
1040 |
|
|
if (j_is_Quadrupole) { |
1041 |
|
|
*(idat.t2) -= cross(uz_j, dudux_j); |
1042 |
|
|
*(idat.t2) -= cross(uz_j, duduy_j); |
1043 |
|
|
} |
1044 |
|
|
|
1045 |
|
|
} else { |
1046 |
|
|
|
1047 |
|
|
// only accumulate the forces and torques resulting from the |
1048 |
|
|
// indirect reaction field terms. |
1049 |
gezelter |
1616 |
|
1050 |
gezelter |
1587 |
*(idat.vpair) += indirect_vpair; |
1051 |
|
|
(*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot; |
1052 |
|
|
*(idat.f1) += indirect_dVdr; |
1053 |
|
|
|
1054 |
|
|
if (i_is_Dipole) |
1055 |
|
|
*(idat.t1) -= cross(uz_i, indirect_duduz_i); |
1056 |
|
|
if (j_is_Dipole) |
1057 |
|
|
*(idat.t2) -= cross(uz_j, indirect_duduz_j); |
1058 |
gezelter |
1502 |
} |
1059 |
|
|
|
1060 |
|
|
return; |
1061 |
|
|
} |
1062 |
|
|
|
1063 |
gezelter |
1545 |
void Electrostatic::calcSelfCorrection(SelfData &sdat) { |
1064 |
gezelter |
1502 |
RealType mu1, preVal, chg1, self; |
1065 |
|
|
|
1066 |
|
|
if (!initialized_) initialize(); |
1067 |
gezelter |
1586 |
|
1068 |
gezelter |
1545 |
ElectrostaticAtomData data = ElectrostaticMap[sdat.atype]; |
1069 |
gezelter |
1502 |
|
1070 |
|
|
// logicals |
1071 |
|
|
bool i_is_Charge = data.is_Charge; |
1072 |
|
|
bool i_is_Dipole = data.is_Dipole; |
1073 |
|
|
|
1074 |
gezelter |
1528 |
if (summationMethod_ == esm_REACTION_FIELD) { |
1075 |
gezelter |
1502 |
if (i_is_Dipole) { |
1076 |
|
|
mu1 = data.dipole_moment; |
1077 |
|
|
preVal = pre22_ * preRF2_ * mu1 * mu1; |
1078 |
gezelter |
1586 |
(*(sdat.pot))[ELECTROSTATIC_FAMILY] -= 0.5 * preVal; |
1079 |
gezelter |
1502 |
|
1080 |
|
|
// The self-correction term adds into the reaction field vector |
1081 |
gezelter |
1554 |
Vector3d uz_i = sdat.eFrame->getColumn(2); |
1082 |
gezelter |
1502 |
Vector3d ei = preVal * uz_i; |
1083 |
|
|
|
1084 |
|
|
// This looks very wrong. A vector crossed with itself is zero. |
1085 |
gezelter |
1554 |
*(sdat.t) -= cross(uz_i, ei); |
1086 |
gezelter |
1502 |
} |
1087 |
gezelter |
1528 |
} else if (summationMethod_ == esm_SHIFTED_FORCE || summationMethod_ == esm_SHIFTED_POTENTIAL) { |
1088 |
gezelter |
1502 |
if (i_is_Charge) { |
1089 |
gezelter |
1720 |
chg1 = data.fixedCharge; |
1090 |
gezelter |
1502 |
if (screeningMethod_ == DAMPED) { |
1091 |
gezelter |
1554 |
self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_; |
1092 |
gezelter |
1502 |
} else { |
1093 |
gezelter |
1554 |
self = - 0.5 * rcuti_ * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_; |
1094 |
gezelter |
1502 |
} |
1095 |
gezelter |
1586 |
(*(sdat.pot))[ELECTROSTATIC_FAMILY] += self; |
1096 |
gezelter |
1502 |
} |
1097 |
|
|
} |
1098 |
|
|
} |
1099 |
gezelter |
1505 |
|
1100 |
gezelter |
1545 |
RealType Electrostatic::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
1101 |
gezelter |
1505 |
// This seems to work moderately well as a default. There's no |
1102 |
|
|
// inherent scale for 1/r interactions that we can standardize. |
1103 |
|
|
// 12 angstroms seems to be a reasonably good guess for most |
1104 |
|
|
// cases. |
1105 |
|
|
return 12.0; |
1106 |
|
|
} |
1107 |
gezelter |
1502 |
} |