| 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). |
| 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). |
| 39 |
> |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
> |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
|
*/ |
| 42 |
|
|
| 43 |
|
#include <stdio.h> |
| 47 |
|
#include "nonbonded/Electrostatic.hpp" |
| 48 |
|
#include "utils/simError.h" |
| 49 |
|
#include "types/NonBondedInteractionType.hpp" |
| 50 |
< |
#include "types/DirectionalAtomType.hpp" |
| 50 |
> |
#include "types/FixedChargeAdapter.hpp" |
| 51 |
> |
#include "types/MultipoleAdapter.hpp" |
| 52 |
|
#include "io/Globals.hpp" |
| 53 |
|
|
| 54 |
|
namespace OpenMD { |
| 55 |
|
|
| 56 |
|
Electrostatic::Electrostatic(): name_("Electrostatic"), initialized_(false), |
| 57 |
< |
forceField_(NULL) {} |
| 57 |
> |
forceField_(NULL), info_(NULL), |
| 58 |
> |
haveCutoffRadius_(false), |
| 59 |
> |
haveDampingAlpha_(false), |
| 60 |
> |
haveDielectric_(false), |
| 61 |
> |
haveElectroSpline_(false) |
| 62 |
> |
{} |
| 63 |
|
|
| 64 |
|
void Electrostatic::initialize() { |
| 65 |
< |
|
| 66 |
< |
Globals* simParams_; |
| 65 |
> |
|
| 66 |
> |
Globals* simParams_ = info_->getSimParams(); |
| 67 |
|
|
| 68 |
|
summationMap_["HARD"] = esm_HARD; |
| 69 |
+ |
summationMap_["NONE"] = esm_HARD; |
| 70 |
|
summationMap_["SWITCHING_FUNCTION"] = esm_SWITCHING_FUNCTION; |
| 71 |
|
summationMap_["SHIFTED_POTENTIAL"] = esm_SHIFTED_POTENTIAL; |
| 72 |
|
summationMap_["SHIFTED_FORCE"] = esm_SHIFTED_FORCE; |
| 105 |
|
screeningMethod_ = UNDAMPED; |
| 106 |
|
dielectric_ = 1.0; |
| 107 |
|
one_third_ = 1.0 / 3.0; |
| 100 |
– |
haveCutoffRadius_ = false; |
| 101 |
– |
haveDampingAlpha_ = false; |
| 102 |
– |
haveDielectric_ = false; |
| 103 |
– |
haveElectroSpline_ = false; |
| 108 |
|
|
| 109 |
|
// check the summation method: |
| 110 |
|
if (simParams_->haveElectrostaticSummationMethod()) { |
| 119 |
|
sprintf( painCave.errMsg, |
| 120 |
|
"Electrostatic::initialize: Unknown electrostaticSummationMethod.\n" |
| 121 |
|
"\t(Input file specified %s .)\n" |
| 122 |
< |
"\telectrostaticSummationMethod must be one of: \"none\",\n" |
| 122 |
> |
"\telectrostaticSummationMethod must be one of: \"hard\",\n" |
| 123 |
|
"\t\"shifted_potential\", \"shifted_force\", or \n" |
| 124 |
|
"\t\"reaction_field\".\n", myMethod.c_str() ); |
| 125 |
|
painCave.isFatal = 1; |
| 252 |
|
preRF2_ = 2.0 * preRF_; |
| 253 |
|
} |
| 254 |
|
|
| 255 |
< |
RealType dx = cutoffRadius_ / RealType(np_ - 1); |
| 255 |
> |
// Add a 2 angstrom safety window to deal with cutoffGroups that |
| 256 |
> |
// have charged atoms longer than the cutoffRadius away from each |
| 257 |
> |
// other. Splining may not be the best choice here. Direct calls |
| 258 |
> |
// to erfc might be preferrable. |
| 259 |
> |
|
| 260 |
> |
RealType dx = (cutoffRadius_ + 2.0) / RealType(np_ - 1); |
| 261 |
|
RealType rval; |
| 262 |
|
vector<RealType> rvals; |
| 263 |
|
vector<RealType> yvals; |
| 281 |
|
electrostaticAtomData.is_SplitDipole = false; |
| 282 |
|
electrostaticAtomData.is_Quadrupole = false; |
| 283 |
|
|
| 284 |
< |
if (atomType->isCharge()) { |
| 276 |
< |
GenericData* data = atomType->getPropertyByName("Charge"); |
| 284 |
> |
FixedChargeAdapter fca = FixedChargeAdapter(atomType); |
| 285 |
|
|
| 286 |
< |
if (data == NULL) { |
| 279 |
< |
sprintf( painCave.errMsg, "Electrostatic::addType could not find " |
| 280 |
< |
"Charge\n" |
| 281 |
< |
"\tparameters for atomType %s.\n", |
| 282 |
< |
atomType->getName().c_str()); |
| 283 |
< |
painCave.severity = OPENMD_ERROR; |
| 284 |
< |
painCave.isFatal = 1; |
| 285 |
< |
simError(); |
| 286 |
< |
} |
| 287 |
< |
|
| 288 |
< |
DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data); |
| 289 |
< |
if (doubleData == NULL) { |
| 290 |
< |
sprintf( painCave.errMsg, |
| 291 |
< |
"Electrostatic::addType could not convert GenericData to " |
| 292 |
< |
"Charge for\n" |
| 293 |
< |
"\tatom type %s\n", atomType->getName().c_str()); |
| 294 |
< |
painCave.severity = OPENMD_ERROR; |
| 295 |
< |
painCave.isFatal = 1; |
| 296 |
< |
simError(); |
| 297 |
< |
} |
| 286 |
> |
if (fca.isFixedCharge()) { |
| 287 |
|
electrostaticAtomData.is_Charge = true; |
| 288 |
< |
electrostaticAtomData.charge = doubleData->getData(); |
| 288 |
> |
electrostaticAtomData.charge = fca.getCharge(); |
| 289 |
|
} |
| 290 |
|
|
| 291 |
< |
if (atomType->isDirectional()) { |
| 292 |
< |
DirectionalAtomType* daType = dynamic_cast<DirectionalAtomType*>(atomType); |
| 293 |
< |
|
| 305 |
< |
if (daType->isDipole()) { |
| 306 |
< |
GenericData* data = daType->getPropertyByName("Dipole"); |
| 307 |
< |
|
| 308 |
< |
if (data == NULL) { |
| 309 |
< |
sprintf( painCave.errMsg, |
| 310 |
< |
"Electrostatic::addType could not find Dipole\n" |
| 311 |
< |
"\tparameters for atomType %s.\n", |
| 312 |
< |
daType->getName().c_str()); |
| 313 |
< |
painCave.severity = OPENMD_ERROR; |
| 314 |
< |
painCave.isFatal = 1; |
| 315 |
< |
simError(); |
| 316 |
< |
} |
| 317 |
< |
|
| 318 |
< |
DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data); |
| 319 |
< |
if (doubleData == NULL) { |
| 320 |
< |
sprintf( painCave.errMsg, |
| 321 |
< |
"Electrostatic::addType could not convert GenericData to " |
| 322 |
< |
"Dipole Moment\n" |
| 323 |
< |
"\tfor atom type %s\n", daType->getName().c_str()); |
| 324 |
< |
painCave.severity = OPENMD_ERROR; |
| 325 |
< |
painCave.isFatal = 1; |
| 326 |
< |
simError(); |
| 327 |
< |
} |
| 291 |
> |
MultipoleAdapter ma = MultipoleAdapter(atomType); |
| 292 |
> |
if (ma.isMultipole()) { |
| 293 |
> |
if (ma.isDipole()) { |
| 294 |
|
electrostaticAtomData.is_Dipole = true; |
| 295 |
< |
electrostaticAtomData.dipole_moment = doubleData->getData(); |
| 295 |
> |
electrostaticAtomData.dipole_moment = ma.getDipoleMoment(); |
| 296 |
|
} |
| 297 |
< |
|
| 332 |
< |
if (daType->isSplitDipole()) { |
| 333 |
< |
GenericData* data = daType->getPropertyByName("SplitDipoleDistance"); |
| 334 |
< |
|
| 335 |
< |
if (data == NULL) { |
| 336 |
< |
sprintf(painCave.errMsg, |
| 337 |
< |
"Electrostatic::addType could not find SplitDipoleDistance\n" |
| 338 |
< |
"\tparameter for atomType %s.\n", |
| 339 |
< |
daType->getName().c_str()); |
| 340 |
< |
painCave.severity = OPENMD_ERROR; |
| 341 |
< |
painCave.isFatal = 1; |
| 342 |
< |
simError(); |
| 343 |
< |
} |
| 344 |
< |
|
| 345 |
< |
DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data); |
| 346 |
< |
if (doubleData == NULL) { |
| 347 |
< |
sprintf( painCave.errMsg, |
| 348 |
< |
"Electrostatic::addType could not convert GenericData to " |
| 349 |
< |
"SplitDipoleDistance for\n" |
| 350 |
< |
"\tatom type %s\n", daType->getName().c_str()); |
| 351 |
< |
painCave.severity = OPENMD_ERROR; |
| 352 |
< |
painCave.isFatal = 1; |
| 353 |
< |
simError(); |
| 354 |
< |
} |
| 297 |
> |
if (ma.isSplitDipole()) { |
| 298 |
|
electrostaticAtomData.is_SplitDipole = true; |
| 299 |
< |
electrostaticAtomData.split_dipole_distance = doubleData->getData(); |
| 299 |
> |
electrostaticAtomData.split_dipole_distance = ma.getSplitDipoleDistance(); |
| 300 |
|
} |
| 301 |
< |
|
| 359 |
< |
if (daType->isQuadrupole()) { |
| 360 |
< |
GenericData* data = daType->getPropertyByName("QuadrupoleMoments"); |
| 361 |
< |
|
| 362 |
< |
if (data == NULL) { |
| 363 |
< |
sprintf( painCave.errMsg, |
| 364 |
< |
"Electrostatic::addType could not find QuadrupoleMoments\n" |
| 365 |
< |
"\tparameter for atomType %s.\n", |
| 366 |
< |
daType->getName().c_str()); |
| 367 |
< |
painCave.severity = OPENMD_ERROR; |
| 368 |
< |
painCave.isFatal = 1; |
| 369 |
< |
simError(); |
| 370 |
< |
} |
| 371 |
< |
|
| 301 |
> |
if (ma.isQuadrupole()) { |
| 302 |
|
// Quadrupoles in OpenMD are set as the diagonal elements |
| 303 |
|
// of the diagonalized traceless quadrupole moment tensor. |
| 304 |
|
// The column vectors of the unitary matrix that diagonalizes |
| 305 |
|
// the quadrupole moment tensor become the eFrame (or the |
| 306 |
|
// electrostatic version of the body-fixed frame. |
| 377 |
– |
|
| 378 |
– |
Vector3dGenericData* v3dData = dynamic_cast<Vector3dGenericData*>(data); |
| 379 |
– |
if (v3dData == NULL) { |
| 380 |
– |
sprintf( painCave.errMsg, |
| 381 |
– |
"Electrostatic::addType could not convert GenericData to " |
| 382 |
– |
"Quadrupole Moments for\n" |
| 383 |
– |
"\tatom type %s\n", daType->getName().c_str()); |
| 384 |
– |
painCave.severity = OPENMD_ERROR; |
| 385 |
– |
painCave.isFatal = 1; |
| 386 |
– |
simError(); |
| 387 |
– |
} |
| 307 |
|
electrostaticAtomData.is_Quadrupole = true; |
| 308 |
< |
electrostaticAtomData.quadrupole_moments = v3dData->getData(); |
| 308 |
> |
electrostaticAtomData.quadrupole_moments = ma.getQuadrupoleMoments(); |
| 309 |
|
} |
| 310 |
|
} |
| 311 |
|
|
| 393 |
– |
AtomTypeProperties atp = atomType->getATP(); |
| 312 |
|
|
| 313 |
|
pair<map<int,AtomType*>::iterator,bool> ret; |
| 314 |
< |
ret = ElectrostaticList.insert( pair<int,AtomType*>(atp.ident, atomType) ); |
| 314 |
> |
ret = ElectrostaticList.insert( pair<int,AtomType*>(atomType->getIdent(), |
| 315 |
> |
atomType) ); |
| 316 |
|
if (ret.second == false) { |
| 317 |
|
sprintf( painCave.errMsg, |
| 318 |
|
"Electrostatic already had a previous entry with ident %d\n", |
| 319 |
< |
atp.ident); |
| 319 |
> |
atomType->getIdent() ); |
| 320 |
|
painCave.severity = OPENMD_INFO; |
| 321 |
|
painCave.isFatal = 0; |
| 322 |
|
simError(); |
| 326 |
|
return; |
| 327 |
|
} |
| 328 |
|
|
| 329 |
< |
void Electrostatic::setElectrostaticCutoffRadius( RealType theECR, |
| 330 |
< |
RealType theRSW ) { |
| 412 |
< |
cutoffRadius_ = theECR; |
| 329 |
> |
void Electrostatic::setCutoffRadius( RealType rCut ) { |
| 330 |
> |
cutoffRadius_ = rCut; |
| 331 |
|
rrf_ = cutoffRadius_; |
| 414 |
– |
rt_ = theRSW; |
| 332 |
|
haveCutoffRadius_ = true; |
| 333 |
|
} |
| 334 |
+ |
|
| 335 |
+ |
void Electrostatic::setSwitchingRadius( RealType rSwitch ) { |
| 336 |
+ |
rt_ = rSwitch; |
| 337 |
+ |
} |
| 338 |
|
void Electrostatic::setElectrostaticSummationMethod( ElectrostaticSummationMethod esm ) { |
| 339 |
|
summationMethod_ = esm; |
| 340 |
|
} |
| 364 |
|
RealType ct_i, ct_j, ct_ij, a1; |
| 365 |
|
RealType riji, ri, ri2, ri3, ri4; |
| 366 |
|
RealType pref, vterm, epot, dudr; |
| 367 |
+ |
RealType vpair(0.0); |
| 368 |
|
RealType scale, sc2; |
| 369 |
|
RealType pot_term, preVal, rfVal; |
| 370 |
|
RealType c2ri, c3ri, c4rij, cti3, ctj3, ctidotj; |
| 371 |
|
RealType preSw, preSwSc; |
| 372 |
|
RealType c1, c2, c3, c4; |
| 373 |
< |
RealType erfcVal, derfcVal; |
| 373 |
> |
RealType erfcVal(1.0), derfcVal(0.0); |
| 374 |
|
RealType BigR; |
| 375 |
+ |
RealType two(2.0), three(3.0); |
| 376 |
|
|
| 377 |
|
Vector3d Q_i, Q_j; |
| 378 |
|
Vector3d ux_i, uy_i, uz_i; |
| 382 |
|
Vector3d rhatdot2, rhatc4; |
| 383 |
|
Vector3d dVdr; |
| 384 |
|
|
| 385 |
+ |
// variables for indirect (reaction field) interactions for excluded pairs: |
| 386 |
+ |
RealType indirect_Pot(0.0); |
| 387 |
+ |
RealType indirect_vpair(0.0); |
| 388 |
+ |
Vector3d indirect_dVdr(V3Zero); |
| 389 |
+ |
Vector3d indirect_duduz_i(V3Zero), indirect_duduz_j(V3Zero); |
| 390 |
+ |
|
| 391 |
|
pair<RealType, RealType> res; |
| 392 |
|
|
| 393 |
|
if (!initialized_) initialize(); |
| 394 |
|
|
| 395 |
< |
ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes->first]; |
| 396 |
< |
ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes->second]; |
| 395 |
> |
ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first]; |
| 396 |
> |
ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second]; |
| 397 |
|
|
| 398 |
|
// some variables we'll need independent of electrostatic type: |
| 399 |
|
|
| 412 |
|
bool j_is_SplitDipole = data2.is_SplitDipole; |
| 413 |
|
bool j_is_Quadrupole = data2.is_Quadrupole; |
| 414 |
|
|
| 415 |
< |
if (i_is_Charge) |
| 415 |
> |
if (i_is_Charge) { |
| 416 |
|
q_i = data1.charge; |
| 417 |
+ |
if (idat.excluded) { |
| 418 |
+ |
*(idat.skippedCharge2) += q_i; |
| 419 |
+ |
} |
| 420 |
+ |
} |
| 421 |
|
|
| 422 |
|
if (i_is_Dipole) { |
| 423 |
|
mu_i = data1.dipole_moment; |
| 450 |
|
duduz_i = V3Zero; |
| 451 |
|
} |
| 452 |
|
|
| 453 |
< |
if (j_is_Charge) |
| 453 |
> |
if (j_is_Charge) { |
| 454 |
|
q_j = data2.charge; |
| 455 |
+ |
if (idat.excluded) { |
| 456 |
+ |
*(idat.skippedCharge1) += q_j; |
| 457 |
+ |
} |
| 458 |
+ |
} |
| 459 |
|
|
| 460 |
+ |
|
| 461 |
|
if (j_is_Dipole) { |
| 462 |
|
mu_j = data2.dipole_moment; |
| 463 |
|
uz_j = idat.eFrame2->getColumn(2); |
| 497 |
|
if (j_is_Charge) { |
| 498 |
|
if (screeningMethod_ == DAMPED) { |
| 499 |
|
// assemble the damping variables |
| 500 |
< |
res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 501 |
< |
erfcVal = res.first; |
| 502 |
< |
derfcVal = res.second; |
| 500 |
> |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 501 |
> |
//erfcVal = res.first; |
| 502 |
> |
//derfcVal = res.second; |
| 503 |
> |
|
| 504 |
> |
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
| 505 |
> |
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
| 506 |
> |
|
| 507 |
|
c1 = erfcVal * riji; |
| 508 |
|
c2 = (-derfcVal + c1) * riji; |
| 509 |
|
} else { |
| 522 |
|
dudr = *(idat.sw) * preVal * (c2c_ - c2); |
| 523 |
|
|
| 524 |
|
} else if (summationMethod_ == esm_REACTION_FIELD) { |
| 525 |
< |
rfVal = *(idat.electroMult) * preRF_ * *(idat.rij) * *(idat.rij) ; |
| 525 |
> |
rfVal = preRF_ * *(idat.rij) * *(idat.rij); |
| 526 |
> |
|
| 527 |
|
vterm = preVal * ( riji + rfVal ); |
| 528 |
|
dudr = *(idat.sw) * preVal * ( 2.0 * rfVal - riji ) * riji; |
| 529 |
+ |
|
| 530 |
+ |
// if this is an excluded pair, there are still indirect |
| 531 |
+ |
// interactions via the reaction field we must worry about: |
| 532 |
|
|
| 533 |
+ |
if (idat.excluded) { |
| 534 |
+ |
indirect_vpair += preVal * rfVal; |
| 535 |
+ |
indirect_Pot += *(idat.sw) * preVal * rfVal; |
| 536 |
+ |
indirect_dVdr += *(idat.sw) * preVal * two * rfVal * riji * rhat; |
| 537 |
+ |
} |
| 538 |
+ |
|
| 539 |
|
} else { |
| 588 |
– |
vterm = preVal * riji * erfcVal; |
| 540 |
|
|
| 541 |
+ |
vterm = preVal * riji * erfcVal; |
| 542 |
|
dudr = - *(idat.sw) * preVal * c2; |
| 543 |
|
|
| 544 |
|
} |
| 593 |
– |
|
| 594 |
– |
*(idat.vpair) += vterm; |
| 595 |
– |
epot += *(idat.sw) * vterm; |
| 545 |
|
|
| 546 |
< |
dVdr += dudr * rhat; |
| 546 |
> |
vpair += vterm; |
| 547 |
> |
epot += *(idat.sw) * vterm; |
| 548 |
> |
dVdr += dudr * rhat; |
| 549 |
|
} |
| 550 |
|
|
| 551 |
|
if (j_is_Dipole) { |
| 558 |
|
ri3 = ri2 * riji; |
| 559 |
|
|
| 560 |
|
vterm = - pref * ct_j * ( ri2 - preRF2_ * *(idat.rij) ); |
| 561 |
< |
*(idat.vpair) += vterm; |
| 561 |
> |
vpair += vterm; |
| 562 |
|
epot += *(idat.sw) * vterm; |
| 563 |
|
|
| 564 |
< |
dVdr += -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j); |
| 564 |
> |
dVdr += -preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j); |
| 565 |
|
duduz_j += -preSw * rhat * (ri2 - preRF2_ * *(idat.rij) ); |
| 566 |
|
|
| 567 |
+ |
// Even if we excluded this pair from direct interactions, |
| 568 |
+ |
// we still have the reaction-field-mediated charge-dipole |
| 569 |
+ |
// interaction: |
| 570 |
+ |
|
| 571 |
+ |
if (idat.excluded) { |
| 572 |
+ |
indirect_vpair += pref * ct_j * preRF2_ * *(idat.rij); |
| 573 |
+ |
indirect_Pot += preSw * ct_j * preRF2_ * *(idat.rij); |
| 574 |
+ |
indirect_dVdr += preSw * preRF2_ * uz_j; |
| 575 |
+ |
indirect_duduz_j += preSw * rhat * preRF2_ * *(idat.rij); |
| 576 |
+ |
} |
| 577 |
+ |
|
| 578 |
|
} else { |
| 579 |
|
// determine the inverse r used if we have split dipoles |
| 580 |
|
if (j_is_SplitDipole) { |
| 590 |
|
|
| 591 |
|
if (screeningMethod_ == DAMPED) { |
| 592 |
|
// assemble the damping variables |
| 593 |
< |
res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 594 |
< |
erfcVal = res.first; |
| 595 |
< |
derfcVal = res.second; |
| 593 |
> |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 594 |
> |
//erfcVal = res.first; |
| 595 |
> |
//derfcVal = res.second; |
| 596 |
> |
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
| 597 |
> |
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
| 598 |
|
c1 = erfcVal * ri; |
| 599 |
|
c2 = (-derfcVal + c1) * ri; |
| 600 |
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; |
| 609 |
|
// calculate the potential |
| 610 |
|
pot_term = scale * c2; |
| 611 |
|
vterm = -pref * ct_j * pot_term; |
| 612 |
< |
*(idat.vpair) += vterm; |
| 612 |
> |
vpair += vterm; |
| 613 |
|
epot += *(idat.sw) * vterm; |
| 614 |
|
|
| 615 |
|
// calculate derivatives for forces and torques |
| 629 |
|
|
| 630 |
|
if (screeningMethod_ == DAMPED) { |
| 631 |
|
// assemble the damping variables |
| 632 |
< |
res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 633 |
< |
erfcVal = res.first; |
| 634 |
< |
derfcVal = res.second; |
| 632 |
> |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 633 |
> |
//erfcVal = res.first; |
| 634 |
> |
//derfcVal = res.second; |
| 635 |
> |
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
| 636 |
> |
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
| 637 |
|
c1 = erfcVal * riji; |
| 638 |
|
c2 = (-derfcVal + c1) * riji; |
| 639 |
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji; |
| 650 |
|
c2ri = c2 * riji; |
| 651 |
|
c3ri = c3 * riji; |
| 652 |
|
c4rij = c4 * *(idat.rij) ; |
| 653 |
< |
rhatdot2 = 2.0 * rhat * c3; |
| 653 |
> |
rhatdot2 = two * rhat * c3; |
| 654 |
|
rhatc4 = rhat * c4rij; |
| 655 |
|
|
| 656 |
|
// calculate the potential |
| 658 |
|
qyy_j * (cy2*c3 - c2ri) + |
| 659 |
|
qzz_j * (cz2*c3 - c2ri) ); |
| 660 |
|
vterm = pref * pot_term; |
| 661 |
< |
*(idat.vpair) += vterm; |
| 661 |
> |
vpair += vterm; |
| 662 |
|
epot += *(idat.sw) * vterm; |
| 663 |
|
|
| 664 |
|
// calculate derivatives for the forces and torques |
| 665 |
|
|
| 666 |
< |
dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (2.0*cx_j*ux_j + rhat)*c3ri) + |
| 667 |
< |
qyy_j* (cy2*rhatc4 - (2.0*cy_j*uy_j + rhat)*c3ri) + |
| 668 |
< |
qzz_j* (cz2*rhatc4 - (2.0*cz_j*uz_j + rhat)*c3ri)); |
| 666 |
> |
dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (two*cx_j*ux_j + rhat)*c3ri) + |
| 667 |
> |
qyy_j* (cy2*rhatc4 - (two*cy_j*uy_j + rhat)*c3ri) + |
| 668 |
> |
qzz_j* (cz2*rhatc4 - (two*cz_j*uz_j + rhat)*c3ri)); |
| 669 |
|
|
| 670 |
|
dudux_j += preSw * qxx_j * cx_j * rhatdot2; |
| 671 |
|
duduy_j += preSw * qyy_j * cy_j * rhatdot2; |
| 686 |
|
ri3 = ri2 * riji; |
| 687 |
|
|
| 688 |
|
vterm = pref * ct_i * ( ri2 - preRF2_ * *(idat.rij) ); |
| 689 |
< |
*(idat.vpair) += vterm; |
| 689 |
> |
vpair += vterm; |
| 690 |
|
epot += *(idat.sw) * vterm; |
| 691 |
|
|
| 692 |
< |
dVdr += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i); |
| 692 |
> |
dVdr += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_ * uz_i); |
| 693 |
|
|
| 694 |
|
duduz_i += preSw * rhat * (ri2 - preRF2_ * *(idat.rij) ); |
| 695 |
+ |
|
| 696 |
+ |
// Even if we excluded this pair from direct interactions, |
| 697 |
+ |
// we still have the reaction-field-mediated charge-dipole |
| 698 |
+ |
// interaction: |
| 699 |
+ |
|
| 700 |
+ |
if (idat.excluded) { |
| 701 |
+ |
indirect_vpair += -pref * ct_i * preRF2_ * *(idat.rij); |
| 702 |
+ |
indirect_Pot += -preSw * ct_i * preRF2_ * *(idat.rij); |
| 703 |
+ |
indirect_dVdr += -preSw * preRF2_ * uz_i; |
| 704 |
+ |
indirect_duduz_i += -preSw * rhat * preRF2_ * *(idat.rij); |
| 705 |
+ |
} |
| 706 |
|
|
| 707 |
|
} else { |
| 708 |
|
|
| 720 |
|
|
| 721 |
|
if (screeningMethod_ == DAMPED) { |
| 722 |
|
// assemble the damping variables |
| 723 |
< |
res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 724 |
< |
erfcVal = res.first; |
| 725 |
< |
derfcVal = res.second; |
| 723 |
> |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 724 |
> |
//erfcVal = res.first; |
| 725 |
> |
//derfcVal = res.second; |
| 726 |
> |
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
| 727 |
> |
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
| 728 |
|
c1 = erfcVal * ri; |
| 729 |
|
c2 = (-derfcVal + c1) * ri; |
| 730 |
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; |
| 739 |
|
// calculate the potential |
| 740 |
|
pot_term = c2 * scale; |
| 741 |
|
vterm = pref * ct_i * pot_term; |
| 742 |
< |
*(idat.vpair) += vterm; |
| 742 |
> |
vpair += vterm; |
| 743 |
|
epot += *(idat.sw) * vterm; |
| 744 |
|
|
| 745 |
|
// calculate derivatives for the forces and torques |
| 762 |
|
|
| 763 |
|
vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) - |
| 764 |
|
preRF2_ * ct_ij ); |
| 765 |
< |
*(idat.vpair) += vterm; |
| 765 |
> |
vpair += vterm; |
| 766 |
|
epot += *(idat.sw) * vterm; |
| 767 |
|
|
| 768 |
|
a1 = 5.0 * ct_i * ct_j - ct_ij; |
| 769 |
|
|
| 770 |
< |
dVdr += preSw * 3.0 * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i); |
| 770 |
> |
dVdr += preSw * three * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i); |
| 771 |
|
|
| 772 |
< |
duduz_i += preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j); |
| 773 |
< |
duduz_j += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_*uz_i); |
| 772 |
> |
duduz_i += preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j); |
| 773 |
> |
duduz_j += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_*uz_i); |
| 774 |
|
|
| 775 |
+ |
if (idat.excluded) { |
| 776 |
+ |
indirect_vpair += - pref * preRF2_ * ct_ij; |
| 777 |
+ |
indirect_Pot += - preSw * preRF2_ * ct_ij; |
| 778 |
+ |
indirect_duduz_i += -preSw * preRF2_ * uz_j; |
| 779 |
+ |
indirect_duduz_j += -preSw * preRF2_ * uz_i; |
| 780 |
+ |
} |
| 781 |
+ |
|
| 782 |
|
} else { |
| 783 |
|
|
| 784 |
|
if (i_is_SplitDipole) { |
| 801 |
|
} |
| 802 |
|
if (screeningMethod_ == DAMPED) { |
| 803 |
|
// assemble damping variables |
| 804 |
< |
res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 805 |
< |
erfcVal = res.first; |
| 806 |
< |
derfcVal = res.second; |
| 804 |
> |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 805 |
> |
//erfcVal = res.first; |
| 806 |
> |
//derfcVal = res.second; |
| 807 |
> |
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
| 808 |
> |
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
| 809 |
|
c1 = erfcVal * ri; |
| 810 |
|
c2 = (-derfcVal + c1) * ri; |
| 811 |
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; |
| 830 |
|
// calculate the potential |
| 831 |
|
pot_term = (ct_ij * c2ri - ctidotj * c3); |
| 832 |
|
vterm = pref * pot_term; |
| 833 |
< |
*(idat.vpair) += vterm; |
| 833 |
> |
vpair += vterm; |
| 834 |
|
epot += *(idat.sw) * vterm; |
| 835 |
|
|
| 836 |
|
// calculate derivatives for the forces and torques |
| 854 |
|
|
| 855 |
|
if (screeningMethod_ == DAMPED) { |
| 856 |
|
// assemble the damping variables |
| 857 |
< |
res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 858 |
< |
erfcVal = res.first; |
| 859 |
< |
derfcVal = res.second; |
| 857 |
> |
//res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); |
| 858 |
> |
//erfcVal = res.first; |
| 859 |
> |
//derfcVal = res.second; |
| 860 |
> |
erfcVal = erfc(dampingAlpha_ * *(idat.rij)); |
| 861 |
> |
derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); |
| 862 |
|
c1 = erfcVal * riji; |
| 863 |
|
c2 = (-derfcVal + c1) * riji; |
| 864 |
|
c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji; |
| 875 |
|
c2ri = c2 * riji; |
| 876 |
|
c3ri = c3 * riji; |
| 877 |
|
c4rij = c4 * *(idat.rij) ; |
| 878 |
< |
rhatdot2 = 2.0 * rhat * c3; |
| 878 |
> |
rhatdot2 = two * rhat * c3; |
| 879 |
|
rhatc4 = rhat * c4rij; |
| 880 |
|
|
| 881 |
|
// calculate the potential |
| 884 |
|
qzz_i * (cz2 * c3 - c2ri) ); |
| 885 |
|
|
| 886 |
|
vterm = pref * pot_term; |
| 887 |
< |
*(idat.vpair) += vterm; |
| 887 |
> |
vpair += vterm; |
| 888 |
|
epot += *(idat.sw) * vterm; |
| 889 |
|
|
| 890 |
|
// calculate the derivatives for the forces and torques |
| 891 |
|
|
| 892 |
< |
dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (2.0*cx_i*ux_i + rhat)*c3ri) + |
| 893 |
< |
qyy_i* (cy2*rhatc4 - (2.0*cy_i*uy_i + rhat)*c3ri) + |
| 894 |
< |
qzz_i* (cz2*rhatc4 - (2.0*cz_i*uz_i + rhat)*c3ri)); |
| 892 |
> |
dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (two*cx_i*ux_i + rhat)*c3ri) + |
| 893 |
> |
qyy_i* (cy2*rhatc4 - (two*cy_i*uy_i + rhat)*c3ri) + |
| 894 |
> |
qzz_i* (cz2*rhatc4 - (two*cz_i*uz_i + rhat)*c3ri)); |
| 895 |
|
|
| 896 |
|
dudux_i += preSw * qxx_i * cx_i * rhatdot2; |
| 897 |
|
duduy_i += preSw * qyy_i * cy_i * rhatdot2; |
| 899 |
|
} |
| 900 |
|
} |
| 901 |
|
|
| 912 |
– |
idat.pot[ELECTROSTATIC_FAMILY] += epot; |
| 913 |
– |
*(idat.f1) += dVdr; |
| 902 |
|
|
| 903 |
< |
if (i_is_Dipole || i_is_Quadrupole) |
| 904 |
< |
*(idat.t1) -= cross(uz_i, duduz_i); |
| 905 |
< |
if (i_is_Quadrupole) { |
| 906 |
< |
*(idat.t1) -= cross(ux_i, dudux_i); |
| 907 |
< |
*(idat.t1) -= cross(uy_i, duduy_i); |
| 908 |
< |
} |
| 909 |
< |
|
| 910 |
< |
if (j_is_Dipole || j_is_Quadrupole) |
| 911 |
< |
*(idat.t2) -= cross(uz_j, duduz_j); |
| 912 |
< |
if (j_is_Quadrupole) { |
| 913 |
< |
*(idat.t2) -= cross(uz_j, dudux_j); |
| 914 |
< |
*(idat.t2) -= cross(uz_j, duduy_j); |
| 915 |
< |
} |
| 903 |
> |
if (!idat.excluded) { |
| 904 |
> |
*(idat.vpair) += vpair; |
| 905 |
> |
(*(idat.pot))[ELECTROSTATIC_FAMILY] += epot; |
| 906 |
> |
*(idat.f1) += dVdr; |
| 907 |
> |
|
| 908 |
> |
if (i_is_Dipole || i_is_Quadrupole) |
| 909 |
> |
*(idat.t1) -= cross(uz_i, duduz_i); |
| 910 |
> |
if (i_is_Quadrupole) { |
| 911 |
> |
*(idat.t1) -= cross(ux_i, dudux_i); |
| 912 |
> |
*(idat.t1) -= cross(uy_i, duduy_i); |
| 913 |
> |
} |
| 914 |
> |
|
| 915 |
> |
if (j_is_Dipole || j_is_Quadrupole) |
| 916 |
> |
*(idat.t2) -= cross(uz_j, duduz_j); |
| 917 |
> |
if (j_is_Quadrupole) { |
| 918 |
> |
*(idat.t2) -= cross(uz_j, dudux_j); |
| 919 |
> |
*(idat.t2) -= cross(uz_j, duduy_j); |
| 920 |
> |
} |
| 921 |
> |
|
| 922 |
> |
} else { |
| 923 |
> |
|
| 924 |
> |
// only accumulate the forces and torques resulting from the |
| 925 |
> |
// indirect reaction field terms. |
| 926 |
|
|
| 927 |
< |
return; |
| 928 |
< |
} |
| 929 |
< |
|
| 932 |
< |
void Electrostatic::calcSkipCorrection(InteractionData &idat) { |
| 933 |
< |
|
| 934 |
< |
if (!initialized_) initialize(); |
| 935 |
< |
|
| 936 |
< |
ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes->first]; |
| 937 |
< |
ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes->second]; |
| 938 |
< |
|
| 939 |
< |
// logicals |
| 940 |
< |
|
| 941 |
< |
bool i_is_Charge = data1.is_Charge; |
| 942 |
< |
bool i_is_Dipole = data1.is_Dipole; |
| 943 |
< |
|
| 944 |
< |
bool j_is_Charge = data2.is_Charge; |
| 945 |
< |
bool j_is_Dipole = data2.is_Dipole; |
| 946 |
< |
|
| 947 |
< |
RealType q_i, q_j; |
| 948 |
< |
|
| 949 |
< |
// The skippedCharge computation is needed by the real-space cutoff methods |
| 950 |
< |
// (i.e. shifted force and shifted potential) |
| 951 |
< |
|
| 952 |
< |
if (i_is_Charge) { |
| 953 |
< |
q_i = data1.charge; |
| 954 |
< |
*(idat.skippedCharge2) += q_i; |
| 955 |
< |
} |
| 956 |
< |
|
| 957 |
< |
if (j_is_Charge) { |
| 958 |
< |
q_j = data2.charge; |
| 959 |
< |
*(idat.skippedCharge1) += q_j; |
| 960 |
< |
} |
| 961 |
< |
|
| 962 |
< |
// the rest of this function should only be necessary for reaction field. |
| 963 |
< |
|
| 964 |
< |
if (summationMethod_ == esm_REACTION_FIELD) { |
| 965 |
< |
RealType riji, ri2, ri3; |
| 966 |
< |
RealType mu_i, ct_i; |
| 967 |
< |
RealType mu_j, ct_j; |
| 968 |
< |
RealType preVal, rfVal, vterm, dudr, pref, myPot(0.0); |
| 969 |
< |
Vector3d dVdr, uz_i, uz_j, duduz_i, duduz_j, rhat; |
| 970 |
< |
|
| 971 |
< |
// some variables we'll need independent of electrostatic type: |
| 927 |
> |
*(idat.vpair) += indirect_vpair; |
| 928 |
> |
(*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot; |
| 929 |
> |
*(idat.f1) += indirect_dVdr; |
| 930 |
|
|
| 973 |
– |
riji = 1.0 / *(idat.rij) ; |
| 974 |
– |
rhat = *(idat.d) * riji; |
| 975 |
– |
|
| 976 |
– |
if (i_is_Dipole) { |
| 977 |
– |
mu_i = data1.dipole_moment; |
| 978 |
– |
uz_i = idat.eFrame1->getColumn(2); |
| 979 |
– |
ct_i = dot(uz_i, rhat); |
| 980 |
– |
duduz_i = V3Zero; |
| 981 |
– |
} |
| 982 |
– |
|
| 983 |
– |
if (j_is_Dipole) { |
| 984 |
– |
mu_j = data2.dipole_moment; |
| 985 |
– |
uz_j = idat.eFrame2->getColumn(2); |
| 986 |
– |
ct_j = dot(uz_j, rhat); |
| 987 |
– |
duduz_j = V3Zero; |
| 988 |
– |
} |
| 989 |
– |
|
| 990 |
– |
if (i_is_Charge) { |
| 991 |
– |
if (j_is_Charge) { |
| 992 |
– |
preVal = *(idat.electroMult) * pre11_ * q_i * q_j; |
| 993 |
– |
rfVal = preRF_ * *(idat.rij) * *(idat.rij) ; |
| 994 |
– |
vterm = preVal * rfVal; |
| 995 |
– |
myPot += *(idat.sw) * vterm; |
| 996 |
– |
dudr = *(idat.sw) * preVal * 2.0 * rfVal * riji; |
| 997 |
– |
dVdr += dudr * rhat; |
| 998 |
– |
} |
| 999 |
– |
|
| 1000 |
– |
if (j_is_Dipole) { |
| 1001 |
– |
ri2 = riji * riji; |
| 1002 |
– |
ri3 = ri2 * riji; |
| 1003 |
– |
pref = *(idat.electroMult) * pre12_ * q_i * mu_j; |
| 1004 |
– |
vterm = - pref * ct_j * ( ri2 - preRF2_ * *(idat.rij) ); |
| 1005 |
– |
myPot += *(idat.sw) * vterm; |
| 1006 |
– |
dVdr += - *(idat.sw) * pref * ( ri3 * ( uz_j - 3.0 * ct_j * rhat) - preRF2_ * uz_j); |
| 1007 |
– |
duduz_j += - *(idat.sw) * pref * rhat * (ri2 - preRF2_ * *(idat.rij) ); |
| 1008 |
– |
} |
| 1009 |
– |
} |
| 1010 |
– |
if (i_is_Dipole) { |
| 1011 |
– |
if (j_is_Charge) { |
| 1012 |
– |
ri2 = riji * riji; |
| 1013 |
– |
ri3 = ri2 * riji; |
| 1014 |
– |
pref = *(idat.electroMult) * pre12_ * q_j * mu_i; |
| 1015 |
– |
vterm = - pref * ct_i * ( ri2 - preRF2_ * *(idat.rij) ); |
| 1016 |
– |
myPot += *(idat.sw) * vterm; |
| 1017 |
– |
dVdr += *(idat.sw) * pref * ( ri3 * ( uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i); |
| 1018 |
– |
duduz_i += *(idat.sw) * pref * rhat * (ri2 - preRF2_ * *(idat.rij)); |
| 1019 |
– |
} |
| 1020 |
– |
} |
| 1021 |
– |
|
| 1022 |
– |
// accumulate the forces and torques resulting from the self term |
| 1023 |
– |
idat.pot[ELECTROSTATIC_FAMILY] += myPot; |
| 1024 |
– |
*(idat.f1) += dVdr; |
| 1025 |
– |
|
| 931 |
|
if (i_is_Dipole) |
| 932 |
< |
*(idat.t1) -= cross(uz_i, duduz_i); |
| 932 |
> |
*(idat.t1) -= cross(uz_i, indirect_duduz_i); |
| 933 |
|
if (j_is_Dipole) |
| 934 |
< |
*(idat.t2) -= cross(uz_j, duduz_j); |
| 934 |
> |
*(idat.t2) -= cross(uz_j, indirect_duduz_j); |
| 935 |
|
} |
| 936 |
< |
} |
| 936 |
> |
|
| 937 |
> |
|
| 938 |
> |
return; |
| 939 |
> |
} |
| 940 |
|
|
| 941 |
|
void Electrostatic::calcSelfCorrection(SelfData &sdat) { |
| 942 |
|
RealType mu1, preVal, chg1, self; |
| 943 |
|
|
| 944 |
|
if (!initialized_) initialize(); |
| 945 |
< |
|
| 945 |
> |
|
| 946 |
|
ElectrostaticAtomData data = ElectrostaticMap[sdat.atype]; |
| 947 |
|
|
| 948 |
|
// logicals |
| 1041 |
– |
|
| 949 |
|
bool i_is_Charge = data.is_Charge; |
| 950 |
|
bool i_is_Dipole = data.is_Dipole; |
| 951 |
|
|
| 953 |
|
if (i_is_Dipole) { |
| 954 |
|
mu1 = data.dipole_moment; |
| 955 |
|
preVal = pre22_ * preRF2_ * mu1 * mu1; |
| 956 |
< |
sdat.pot[2] -= 0.5 * preVal; |
| 956 |
> |
(*(sdat.pot))[ELECTROSTATIC_FAMILY] -= 0.5 * preVal; |
| 957 |
|
|
| 958 |
|
// The self-correction term adds into the reaction field vector |
| 959 |
|
Vector3d uz_i = sdat.eFrame->getColumn(2); |
| 970 |
|
} else { |
| 971 |
|
self = - 0.5 * rcuti_ * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_; |
| 972 |
|
} |
| 973 |
< |
sdat.pot[ELECTROSTATIC_FAMILY] += self; |
| 973 |
> |
(*(sdat.pot))[ELECTROSTATIC_FAMILY] += self; |
| 974 |
|
} |
| 975 |
|
} |
| 976 |
|
} |