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