--- branches/development/src/nonbonded/Electrostatic.cpp 2010/10/02 20:41:53 1504 +++ branches/development/src/nonbonded/Electrostatic.cpp 2012/07/06 22:01:58 1767 @@ -34,9 +34,10 @@ * work. Good starting points are: * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). - * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [2] Fennell & Gezelter, J. Chem. Phys. 124 234104 (2006). * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include @@ -46,15 +47,40 @@ #include "nonbonded/Electrostatic.hpp" #include "utils/simError.h" #include "types/NonBondedInteractionType.hpp" -#include "types/DirectionalAtomType.hpp" +#include "types/FixedChargeAdapter.hpp" +#include "types/FluctuatingChargeAdapter.hpp" +#include "types/MultipoleAdapter.hpp" +#include "io/Globals.hpp" +#include "nonbonded/SlaterIntegrals.hpp" +#include "utils/PhysicalConstants.hpp" +#include "math/erfc.hpp" - namespace OpenMD { Electrostatic::Electrostatic(): name_("Electrostatic"), initialized_(false), - forceField_(NULL) {} + forceField_(NULL), info_(NULL), + haveCutoffRadius_(false), + haveDampingAlpha_(false), + haveDielectric_(false), + haveElectroSpline_(false) + {} void Electrostatic::initialize() { + + Globals* simParams_ = info_->getSimParams(); + + summationMap_["HARD"] = esm_HARD; + summationMap_["NONE"] = esm_HARD; + summationMap_["SWITCHING_FUNCTION"] = esm_SWITCHING_FUNCTION; + summationMap_["SHIFTED_POTENTIAL"] = esm_SHIFTED_POTENTIAL; + summationMap_["SHIFTED_FORCE"] = esm_SHIFTED_FORCE; + summationMap_["REACTION_FIELD"] = esm_REACTION_FIELD; + summationMap_["EWALD_FULL"] = esm_EWALD_FULL; + summationMap_["EWALD_PME"] = esm_EWALD_PME; + summationMap_["EWALD_SPME"] = esm_EWALD_SPME; + screeningMap_["DAMPED"] = DAMPED; + screeningMap_["UNDAMPED"] = UNDAMPED; + // these prefactors convert the multipole interactions into kcal / mol // all were computed assuming distances are measured in angstroms // Charge-Charge, assuming charges are measured in electrons @@ -79,20 +105,112 @@ namespace OpenMD { // variables to handle different summation methods for long-range // electrostatics: - summationMethod_ = NONE; + summationMethod_ = esm_HARD; screeningMethod_ = UNDAMPED; dielectric_ = 1.0; one_third_ = 1.0 / 3.0; - haveDefaultCutoff_ = false; - haveDampingAlpha_ = false; - haveDielectric_ = false; - haveElectroSpline_ = false; + // check the summation method: + if (simParams_->haveElectrostaticSummationMethod()) { + string myMethod = simParams_->getElectrostaticSummationMethod(); + toUpper(myMethod); + map::iterator i; + i = summationMap_.find(myMethod); + if ( i != summationMap_.end() ) { + summationMethod_ = (*i).second; + } else { + // throw error + sprintf( painCave.errMsg, + "Electrostatic::initialize: Unknown electrostaticSummationMethod.\n" + "\t(Input file specified %s .)\n" + "\telectrostaticSummationMethod must be one of: \"hard\",\n" + "\t\"shifted_potential\", \"shifted_force\", or \n" + "\t\"reaction_field\".\n", myMethod.c_str() ); + painCave.isFatal = 1; + simError(); + } + } else { + // set ElectrostaticSummationMethod to the cutoffMethod: + if (simParams_->haveCutoffMethod()){ + string myMethod = simParams_->getCutoffMethod(); + toUpper(myMethod); + map::iterator i; + i = summationMap_.find(myMethod); + if ( i != summationMap_.end() ) { + summationMethod_ = (*i).second; + } + } + } + + if (summationMethod_ == esm_REACTION_FIELD) { + if (!simParams_->haveDielectric()) { + // throw warning + sprintf( painCave.errMsg, + "SimInfo warning: dielectric was not specified in the input file\n\tfor the reaction field correction method.\n" + "\tA default value of %f will be used for the dielectric.\n", dielectric_); + painCave.isFatal = 0; + painCave.severity = OPENMD_INFO; + simError(); + } else { + dielectric_ = simParams_->getDielectric(); + } + haveDielectric_ = true; + } + + if (simParams_->haveElectrostaticScreeningMethod()) { + string myScreen = simParams_->getElectrostaticScreeningMethod(); + toUpper(myScreen); + map::iterator i; + i = screeningMap_.find(myScreen); + if ( i != screeningMap_.end()) { + screeningMethod_ = (*i).second; + } else { + sprintf( painCave.errMsg, + "SimInfo error: Unknown electrostaticScreeningMethod.\n" + "\t(Input file specified %s .)\n" + "\telectrostaticScreeningMethod must be one of: \"undamped\"\n" + "or \"damped\".\n", myScreen.c_str() ); + painCave.isFatal = 1; + simError(); + } + } + + // check to make sure a cutoff value has been set: + if (!haveCutoffRadius_) { + sprintf( painCave.errMsg, "Electrostatic::initialize has no Default " + "Cutoff value!\n"); + painCave.severity = OPENMD_ERROR; + painCave.isFatal = 1; + simError(); + } + + if (screeningMethod_ == DAMPED) { + if (!simParams_->haveDampingAlpha()) { + // first set a cutoff dependent alpha value + // we assume alpha depends linearly with rcut from 0 to 20.5 ang + dampingAlpha_ = 0.425 - cutoffRadius_* 0.02; + if (dampingAlpha_ < 0.0) dampingAlpha_ = 0.0; + + // throw warning + sprintf( painCave.errMsg, + "Electrostatic::initialize: dampingAlpha was not specified in the\n" + "\tinput file. A default value of %f (1/ang) will be used for the\n" + "\tcutoff of %f (ang).\n", + dampingAlpha_, cutoffRadius_); + painCave.severity = OPENMD_INFO; + painCave.isFatal = 0; + simError(); + } else { + dampingAlpha_ = simParams_->getDampingAlpha(); + } + haveDampingAlpha_ = true; + } + // find all of the Electrostatic atom Types: ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes(); ForceField::AtomTypeContainer::MapTypeIterator i; AtomType* at; - + for (at = atomTypes->beginType(i); at != NULL; at = atomTypes->nextType(i)) { @@ -100,40 +218,24 @@ namespace OpenMD { addType(at); } - // check to make sure a cutoff value has been set: - if (!haveDefaultCutoff_) { - sprintf( painCave.errMsg, "Electrostatic::initialize has no Default " - "Cutoff value!\n"); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - defaultCutoff2_ = defaultCutoff_ * defaultCutoff_; - rcuti_ = 1.0 / defaultCutoff_; + cutoffRadius2_ = cutoffRadius_ * cutoffRadius_; + rcuti_ = 1.0 / cutoffRadius_; rcuti2_ = rcuti_ * rcuti_; rcuti3_ = rcuti2_ * rcuti_; rcuti4_ = rcuti2_ * rcuti2_; if (screeningMethod_ == DAMPED) { - if (!haveDampingAlpha_) { - sprintf( painCave.errMsg, "Electrostatic::initialize has no " - "DampingAlpha value!\n"); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - + alpha2_ = dampingAlpha_ * dampingAlpha_; alpha4_ = alpha2_ * alpha2_; alpha6_ = alpha4_ * alpha2_; alpha8_ = alpha4_ * alpha4_; - constEXP_ = exp(-alpha2_ * defaultCutoff2_); + constEXP_ = exp(-alpha2_ * cutoffRadius2_); invRootPi_ = 0.56418958354775628695; alphaPi_ = 2.0 * dampingAlpha_ * invRootPi_; - c1c_ = erfc(dampingAlpha_ * defaultCutoff_) * rcuti_; + c1c_ = erfc(dampingAlpha_ * cutoffRadius_) * rcuti_; c2c_ = alphaPi_ * constEXP_ * rcuti_ + c1c_ * rcuti_; c3c_ = 2.0 * alphaPi_ * alpha2_ + 3.0 * c2c_ * rcuti_; c4c_ = 4.0 * alphaPi_ * alpha4_ + 5.0 * c3c_ * rcuti2_; @@ -148,21 +250,18 @@ namespace OpenMD { c6c_ = 9.0 * c5c_ * rcuti2_; } - if (summationMethod_ == REACTION_FIELD) { - if (haveDielectric_) { - preRF_ = (dielectric_ - 1.0) / - ((2.0 * dielectric_ + 1.0) * defaultCutoff2_ * defaultCutoff_); - preRF2_ = 2.0 * preRF_; - } else { - sprintf( painCave.errMsg, "Electrostatic::initialize has no Dielectric" - " value!\n"); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } + if (summationMethod_ == esm_REACTION_FIELD) { + preRF_ = (dielectric_ - 1.0) / + ((2.0 * dielectric_ + 1.0) * cutoffRadius2_ * cutoffRadius_); + preRF2_ = 2.0 * preRF_; } - - RealType dx = defaultCutoff_ / RealType(np_ - 1); + + // Add a 2 angstrom safety window to deal with cutoffGroups that + // have charged atoms longer than the cutoffRadius away from each + // other. Splining may not be the best choice here. Direct calls + // to erfc might be preferrable. + + RealType dx = (cutoffRadius_ + 2.0) / RealType(np_ - 1); RealType rval; vector rvals; vector yvals; @@ -185,143 +284,118 @@ namespace OpenMD { electrostaticAtomData.is_Dipole = false; electrostaticAtomData.is_SplitDipole = false; electrostaticAtomData.is_Quadrupole = false; + electrostaticAtomData.is_Fluctuating = false; - if (atomType->isCharge()) { - GenericData* data = atomType->getPropertyByName("Charge"); + FixedChargeAdapter fca = FixedChargeAdapter(atomType); - if (data == NULL) { - sprintf( painCave.errMsg, "Electrostatic::addType could not find " - "Charge\n" - "\tparameters for atomType %s.\n", - atomType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - DoubleGenericData* doubleData = dynamic_cast(data); - if (doubleData == NULL) { - sprintf( painCave.errMsg, - "Electrostatic::addType could not convert GenericData to " - "Charge for\n" - "\tatom type %s\n", atomType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } + if (fca.isFixedCharge()) { electrostaticAtomData.is_Charge = true; - electrostaticAtomData.charge = doubleData->getData(); + electrostaticAtomData.fixedCharge = fca.getCharge(); } - if (atomType->isDirectional()) { - DirectionalAtomType* daType = dynamic_cast(atomType); - - if (daType->isDipole()) { - GenericData* data = daType->getPropertyByName("Dipole"); - - if (data == NULL) { - sprintf( painCave.errMsg, - "Electrostatic::addType could not find Dipole\n" - "\tparameters for atomType %s.\n", - daType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - DoubleGenericData* doubleData = dynamic_cast(data); - if (doubleData == NULL) { - sprintf( painCave.errMsg, - "Electrostatic::addType could not convert GenericData to " - "Dipole Moment\n" - "\tfor atom type %s\n", daType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } + MultipoleAdapter ma = MultipoleAdapter(atomType); + if (ma.isMultipole()) { + if (ma.isDipole()) { electrostaticAtomData.is_Dipole = true; - electrostaticAtomData.dipole_moment = doubleData->getData(); - } - - if (daType->isSplitDipole()) { - GenericData* data = daType->getPropertyByName("SplitDipoleDistance"); - - if (data == NULL) { - sprintf(painCave.errMsg, - "Electrostatic::addType could not find SplitDipoleDistance\n" - "\tparameter for atomType %s.\n", - daType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - DoubleGenericData* doubleData = dynamic_cast(data); - if (doubleData == NULL) { - sprintf( painCave.errMsg, - "Electrostatic::addType could not convert GenericData to " - "SplitDipoleDistance for\n" - "\tatom type %s\n", daType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } + electrostaticAtomData.dipole_moment = ma.getDipoleMoment(); + } + if (ma.isSplitDipole()) { electrostaticAtomData.is_SplitDipole = true; - electrostaticAtomData.split_dipole_distance = doubleData->getData(); + electrostaticAtomData.split_dipole_distance = ma.getSplitDipoleDistance(); } - - if (daType->isQuadrupole()) { - GenericData* data = daType->getPropertyByName("QuadrupoleMoments"); - - if (data == NULL) { - sprintf( painCave.errMsg, - "Electrostatic::addType could not find QuadrupoleMoments\n" - "\tparameter for atomType %s.\n", - daType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - Vector3dGenericData* v3dData = dynamic_cast(data); - if (v3dData == NULL) { - sprintf( painCave.errMsg, - "Electrostatic::addType could not convert GenericData to " - "Quadrupole Moments for\n" - "\tatom type %s\n", daType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } + if (ma.isQuadrupole()) { + // Quadrupoles in OpenMD are set as the diagonal elements + // of the diagonalized traceless quadrupole moment tensor. + // The column vectors of the unitary matrix that diagonalizes + // the quadrupole moment tensor become the eFrame (or the + // electrostatic version of the body-fixed frame. electrostaticAtomData.is_Quadrupole = true; - electrostaticAtomData.quadrupole_moments = v3dData->getData(); + electrostaticAtomData.quadrupole_moments = ma.getQuadrupoleMoments(); } } - AtomTypeProperties atp = atomType->getATP(); + FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType); + if (fqa.isFluctuatingCharge()) { + electrostaticAtomData.is_Fluctuating = true; + electrostaticAtomData.electronegativity = fqa.getElectronegativity(); + electrostaticAtomData.hardness = fqa.getHardness(); + electrostaticAtomData.slaterN = fqa.getSlaterN(); + electrostaticAtomData.slaterZeta = fqa.getSlaterZeta(); + } + pair::iterator,bool> ret; - ret = ElectrostaticList.insert( pair(atp.ident, atomType) ); + ret = ElectrostaticList.insert( pair(atomType->getIdent(), + atomType) ); if (ret.second == false) { sprintf( painCave.errMsg, "Electrostatic already had a previous entry with ident %d\n", - atp.ident); + atomType->getIdent() ); painCave.severity = OPENMD_INFO; painCave.isFatal = 0; simError(); } - ElectrostaticMap[atomType] = electrostaticAtomData; + ElectrostaticMap[atomType] = electrostaticAtomData; + + // Now, iterate over all known types and add to the mixing map: + + map::iterator it; + for( it = ElectrostaticMap.begin(); it != ElectrostaticMap.end(); ++it) { + AtomType* atype2 = (*it).first; + ElectrostaticAtomData eaData2 = (*it).second; + if (eaData2.is_Fluctuating && electrostaticAtomData.is_Fluctuating) { + + RealType a = electrostaticAtomData.slaterZeta; + RealType b = eaData2.slaterZeta; + int m = electrostaticAtomData.slaterN; + int n = eaData2.slaterN; + + // Create the spline of the coulombic integral for s-type + // Slater orbitals. Add a 2 angstrom safety window to deal + // with cutoffGroups that have charged atoms longer than the + // cutoffRadius away from each other. + + RealType rval; + RealType dr = (cutoffRadius_ + 2.0) / RealType(np_ - 1); + vector rvals; + vector J1vals; + vector J2vals; + // don't start at i = 0, as rval = 0 is undefined for the slater overlap integrals. + for (int i = 1; i < np_+1; i++) { + rval = RealType(i) * dr; + rvals.push_back(rval); + J1vals.push_back(sSTOCoulInt( a, b, m, n, rval * PhysicalConstants::angstromToBohr ) * PhysicalConstants::hartreeToKcal ); + // may not be necessary if Slater coulomb integral is symmetric + J2vals.push_back(sSTOCoulInt( b, a, n, m, rval * PhysicalConstants::angstromToBohr ) * PhysicalConstants::hartreeToKcal ); + } + + CubicSpline* J1 = new CubicSpline(); + J1->addPoints(rvals, J1vals); + CubicSpline* J2 = new CubicSpline(); + J2->addPoints(rvals, J2vals); + + pair key1, key2; + key1 = make_pair(atomType, atype2); + key2 = make_pair(atype2, atomType); + + Jij[key1] = J1; + Jij[key2] = J2; + } + } + return; } - void Electrostatic::setElectrostaticCutoffRadius( RealType theECR, - RealType theRSW ) { - defaultCutoff_ = theECR; - rrf_ = defaultCutoff_; - rt_ = theRSW; - haveDefaultCutoff_ = true; + void Electrostatic::setCutoffRadius( RealType rCut ) { + cutoffRadius_ = rCut; + rrf_ = cutoffRadius_; + haveCutoffRadius_ = true; } + + void Electrostatic::setSwitchingRadius( RealType rSwitch ) { + rt_ = rSwitch; + } void Electrostatic::setElectrostaticSummationMethod( ElectrostaticSummationMethod esm ) { summationMethod_ = esm; } @@ -337,7 +411,7 @@ namespace OpenMD { haveDielectric_ = true; } - void Electrostatic::calcForce(InteractionData idat) { + void Electrostatic::calcForce(InteractionData &idat) { // utility variables. Should clean these up and use the Vector3d and // Mat3x3d to replace as many as we can in future versions: @@ -351,13 +425,15 @@ namespace OpenMD { RealType ct_i, ct_j, ct_ij, a1; RealType riji, ri, ri2, ri3, ri4; RealType pref, vterm, epot, dudr; + RealType vpair(0.0); RealType scale, sc2; RealType pot_term, preVal, rfVal; RealType c2ri, c3ri, c4rij, cti3, ctj3, ctidotj; RealType preSw, preSwSc; RealType c1, c2, c3, c4; - RealType erfcVal, derfcVal; + RealType erfcVal(1.0), derfcVal(0.0); RealType BigR; + RealType two(2.0), three(3.0); Vector3d Q_i, Q_j; Vector3d ux_i, uy_i, uz_i; @@ -367,17 +443,28 @@ namespace OpenMD { Vector3d rhatdot2, rhatc4; Vector3d dVdr; + // variables for indirect (reaction field) interactions for excluded pairs: + RealType indirect_Pot(0.0); + RealType indirect_vpair(0.0); + Vector3d indirect_dVdr(V3Zero); + Vector3d indirect_duduz_i(V3Zero), indirect_duduz_j(V3Zero); + + RealType coulInt, vFluc1(0.0), vFluc2(0.0); pair res; + // splines for coulomb integrals + CubicSpline* J1; + CubicSpline* J2; + if (!initialized_) initialize(); - ElectrostaticAtomData data1 = ElectrostaticMap[idat.atype1]; - ElectrostaticAtomData data2 = ElectrostaticMap[idat.atype2]; + ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first]; + ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second]; // some variables we'll need independent of electrostatic type: - riji = 1.0 / idat.rij; - Vector3d rhat = idat.d * riji; + riji = 1.0 / *(idat.rij) ; + Vector3d rhat = *(idat.d) * riji; // logicals @@ -385,18 +472,29 @@ namespace OpenMD { bool i_is_Dipole = data1.is_Dipole; bool i_is_SplitDipole = data1.is_SplitDipole; bool i_is_Quadrupole = data1.is_Quadrupole; + bool i_is_Fluctuating = data1.is_Fluctuating; bool j_is_Charge = data2.is_Charge; bool j_is_Dipole = data2.is_Dipole; bool j_is_SplitDipole = data2.is_SplitDipole; bool j_is_Quadrupole = data2.is_Quadrupole; + bool j_is_Fluctuating = data2.is_Fluctuating; - if (i_is_Charge) - q_i = data1.charge; + if (i_is_Charge) { + q_i = data1.fixedCharge; + if (i_is_Fluctuating) { + q_i += *(idat.flucQ1); + } + + if (idat.excluded) { + *(idat.skippedCharge2) += q_i; + } + } + if (i_is_Dipole) { mu_i = data1.dipole_moment; - uz_i = idat.eFrame1.getColumn(2); + uz_i = idat.eFrame1->getColumn(2); ct_i = dot(uz_i, rhat); @@ -412,9 +510,9 @@ namespace OpenMD { qyy_i = Q_i.y(); qzz_i = Q_i.z(); - ux_i = idat.eFrame1.getColumn(0); - uy_i = idat.eFrame1.getColumn(1); - uz_i = idat.eFrame1.getColumn(2); + ux_i = idat.eFrame1->getColumn(0); + uy_i = idat.eFrame1->getColumn(1); + uz_i = idat.eFrame1->getColumn(2); cx_i = dot(ux_i, rhat); cy_i = dot(uy_i, rhat); @@ -425,12 +523,21 @@ namespace OpenMD { duduz_i = V3Zero; } - if (j_is_Charge) - q_j = data2.charge; + if (j_is_Charge) { + q_j = data2.fixedCharge; + if (j_is_Fluctuating) + q_j += *(idat.flucQ2); + + if (idat.excluded) { + *(idat.skippedCharge1) += q_j; + } + } + + if (j_is_Dipole) { mu_j = data2.dipole_moment; - uz_j = idat.eFrame2.getColumn(2); + uz_j = idat.eFrame2->getColumn(2); ct_j = dot(uz_j, rhat); @@ -446,9 +553,9 @@ namespace OpenMD { qyy_j = Q_j.y(); qzz_j = Q_j.z(); - ux_j = idat.eFrame2.getColumn(0); - uy_j = idat.eFrame2.getColumn(1); - uz_j = idat.eFrame2.getColumn(2); + ux_j = idat.eFrame2->getColumn(0); + uy_j = idat.eFrame2->getColumn(1); + uz_j = idat.eFrame2->getColumn(2); cx_j = dot(ux_j, rhat); cy_j = dot(uy_j, rhat); @@ -459,6 +566,11 @@ namespace OpenMD { duduz_j = V3Zero; } + if (i_is_Fluctuating && j_is_Fluctuating) { + J1 = Jij[idat.atypes]; + J2 = Jij[make_pair(idat.atypes.second, idat.atypes.first)]; + } + epot = 0.0; dVdr = V3Zero; @@ -467,9 +579,13 @@ namespace OpenMD { if (j_is_Charge) { if (screeningMethod_ == DAMPED) { // assemble the damping variables - res = erfcSpline_->getValueAndDerivativeAt(idat.rij); + res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); erfcVal = res.first; derfcVal = res.second; + + //erfcVal = erfc(dampingAlpha_ * *(idat.rij)); + //derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); + c1 = erfcVal * riji; c2 = (-derfcVal + c1) * riji; } else { @@ -477,56 +593,102 @@ namespace OpenMD { c2 = c1 * riji; } - preVal = idat.electroMult * pre11_ * q_i * q_j; + preVal = *(idat.electroMult) * pre11_; - if (summationMethod_ == SHIFTED_POTENTIAL) { + if (summationMethod_ == esm_SHIFTED_POTENTIAL) { vterm = preVal * (c1 - c1c_); - dudr = -idat.sw * preVal * c2; + dudr = - *(idat.sw) * preVal * c2; - } else if (summationMethod_ == SHIFTED_FORCE) { - vterm = preVal * ( c1 - c1c_ + c2c_*(idat.rij - defaultCutoff_) ); - dudr = idat.sw * preVal * (c2c_ - c2); + } else if (summationMethod_ == esm_SHIFTED_FORCE) { + vterm = preVal * ( c1 - c1c_ + c2c_*( *(idat.rij) - cutoffRadius_) ); + dudr = *(idat.sw) * preVal * (c2c_ - c2); - } else if (summationMethod_ == REACTION_FIELD) { - rfVal = idat.electroMult * preRF_ * idat.rij * idat.rij; + } else if (summationMethod_ == esm_REACTION_FIELD) { + rfVal = preRF_ * *(idat.rij) * *(idat.rij); + vterm = preVal * ( riji + rfVal ); - dudr = idat.sw * preVal * ( 2.0 * rfVal - riji ) * riji; + dudr = *(idat.sw) * preVal * ( 2.0 * rfVal - riji ) * riji; + + // if this is an excluded pair, there are still indirect + // interactions via the reaction field we must worry about: + if (idat.excluded) { + indirect_vpair += preVal * rfVal; + indirect_Pot += *(idat.sw) * preVal * rfVal; + indirect_dVdr += *(idat.sw) * preVal * two * rfVal * riji * rhat; + } + } else { - vterm = preVal * riji * erfcVal; - dudr = - idat.sw * preVal * c2; + vterm = preVal * riji * erfcVal; + dudr = - *(idat.sw) * preVal * c2; + + } + + vpair += vterm * q_i * q_j; + epot += *(idat.sw) * vterm * q_i * q_j; + dVdr += dudr * rhat * q_i * q_j; + if (i_is_Fluctuating) { + if (idat.excluded) { + // vFluc1 is the difference between the direct coulomb integral + // and the normal 1/r-like interaction between point charges. + coulInt = J1->getValueAt( *(idat.rij) ); + vFluc1 = coulInt - (*(idat.sw) * vterm); + } else { + vFluc1 = 0.0; + } + *(idat.dVdFQ1) += ( *(idat.sw) * vterm + vFluc1 ) * q_j; } - - idat.vpair += vterm; - epot += idat.sw * vterm; - dVdr += dudr * rhat; + if (j_is_Fluctuating) { + if (idat.excluded) { + // vFluc2 is the difference between the direct coulomb integral + // and the normal 1/r-like interaction between point charges. + coulInt = J2->getValueAt( *(idat.rij) ); + vFluc2 = coulInt - (*(idat.sw) * vterm); + } else { + vFluc2 = 0.0; + } + *(idat.dVdFQ2) += ( *(idat.sw) * vterm + vFluc2 ) * q_i; + } + + } if (j_is_Dipole) { // pref is used by all the possible methods - pref = idat.electroMult * pre12_ * q_i * mu_j; - preSw = idat.sw * pref; + pref = *(idat.electroMult) * pre12_ * q_i * mu_j; + preSw = *(idat.sw) * pref; - if (summationMethod_ == REACTION_FIELD) { + if (summationMethod_ == esm_REACTION_FIELD) { ri2 = riji * riji; ri3 = ri2 * riji; - vterm = - pref * ct_j * ( ri2 - preRF2_ * idat.rij ); - idat.vpair += vterm; - epot += idat.sw * vterm; + vterm = - pref * ct_j * ( ri2 - preRF2_ * *(idat.rij) ); + vpair += vterm; + epot += *(idat.sw) * vterm; - dVdr += -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j); - duduz_j += -preSw * rhat * (ri2 - preRF2_ * idat.rij); + dVdr += -preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j); + duduz_j += -preSw * rhat * (ri2 - preRF2_ * *(idat.rij) ); + // Even if we excluded this pair from direct interactions, + // we still have the reaction-field-mediated charge-dipole + // interaction: + + if (idat.excluded) { + indirect_vpair += pref * ct_j * preRF2_ * *(idat.rij); + indirect_Pot += preSw * ct_j * preRF2_ * *(idat.rij); + indirect_dVdr += preSw * preRF2_ * uz_j; + indirect_duduz_j += preSw * rhat * preRF2_ * *(idat.rij); + } + } else { // determine the inverse r used if we have split dipoles if (j_is_SplitDipole) { - BigR = sqrt(idat.r2 + 0.25 * d_j * d_j); + BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j); ri = 1.0 / BigR; - scale = idat.rij * ri; + scale = *(idat.rij) * ri; } else { ri = riji; scale = 1.0; @@ -536,9 +698,11 @@ namespace OpenMD { if (screeningMethod_ == DAMPED) { // assemble the damping variables - res = erfcSpline_->getValueAndDerivativeAt(idat.rij); - erfcVal = res.first; - derfcVal = res.second; + //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); + //erfcVal = res.first; + //derfcVal = res.second; + erfcVal = erfc(dampingAlpha_ * *(idat.rij)); + derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); c1 = erfcVal * ri; c2 = (-derfcVal + c1) * ri; c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; @@ -553,8 +717,8 @@ namespace OpenMD { // calculate the potential pot_term = scale * c2; vterm = -pref * ct_j * pot_term; - idat.vpair += vterm; - epot += idat.sw * vterm; + vpair += vterm; + epot += *(idat.sw) * vterm; // calculate derivatives for forces and torques @@ -562,6 +726,9 @@ namespace OpenMD { duduz_j += -preSw * pot_term * rhat; } + if (i_is_Fluctuating) { + *(idat.dVdFQ1) += ( *(idat.sw) * vterm ) / q_i; + } } if (j_is_Quadrupole) { @@ -569,13 +736,15 @@ namespace OpenMD { cx2 = cx_j * cx_j; cy2 = cy_j * cy_j; cz2 = cz_j * cz_j; - pref = idat.electroMult * pre14_ * q_i * one_third_; + pref = *(idat.electroMult) * pre14_ * q_i * one_third_; if (screeningMethod_ == DAMPED) { // assemble the damping variables - res = erfcSpline_->getValueAndDerivativeAt(idat.rij); - erfcVal = res.first; - derfcVal = res.second; + //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); + //erfcVal = res.first; + //derfcVal = res.second; + erfcVal = erfc(dampingAlpha_ * *(idat.rij)); + derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); c1 = erfcVal * riji; c2 = (-derfcVal + c1) * riji; c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji; @@ -588,11 +757,11 @@ namespace OpenMD { } // precompute variables for convenience - preSw = idat.sw * pref; + preSw = *(idat.sw) * pref; c2ri = c2 * riji; c3ri = c3 * riji; - c4rij = c4 * idat.rij; - rhatdot2 = 2.0 * rhat * c3; + c4rij = c4 * *(idat.rij) ; + rhatdot2 = two * rhat * c3; rhatc4 = rhat * c4rij; // calculate the potential @@ -600,18 +769,22 @@ namespace OpenMD { qyy_j * (cy2*c3 - c2ri) + qzz_j * (cz2*c3 - c2ri) ); vterm = pref * pot_term; - idat.vpair += vterm; - epot += idat.sw * vterm; + vpair += vterm; + epot += *(idat.sw) * vterm; // calculate derivatives for the forces and torques - dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (2.0*cx_j*ux_j + rhat)*c3ri) + - qyy_j* (cy2*rhatc4 - (2.0*cy_j*uy_j + rhat)*c3ri) + - qzz_j* (cz2*rhatc4 - (2.0*cz_j*uz_j + rhat)*c3ri)); + dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (two*cx_j*ux_j + rhat)*c3ri) + + qyy_j* (cy2*rhatc4 - (two*cy_j*uy_j + rhat)*c3ri) + + qzz_j* (cz2*rhatc4 - (two*cz_j*uz_j + rhat)*c3ri)); dudux_j += preSw * qxx_j * cx_j * rhatdot2; duduy_j += preSw * qyy_j * cy_j * rhatdot2; duduz_j += preSw * qzz_j * cz_j * rhatdot2; + if (i_is_Fluctuating) { + *(idat.dVdFQ1) += ( *(idat.sw) * vterm ) / q_i; + } + } } @@ -619,29 +792,40 @@ namespace OpenMD { if (j_is_Charge) { // variables used by all the methods - pref = idat.electroMult * pre12_ * q_j * mu_i; - preSw = idat.sw * pref; + pref = *(idat.electroMult) * pre12_ * q_j * mu_i; + preSw = *(idat.sw) * pref; - if (summationMethod_ == REACTION_FIELD) { + if (summationMethod_ == esm_REACTION_FIELD) { ri2 = riji * riji; ri3 = ri2 * riji; - vterm = pref * ct_i * ( ri2 - preRF2_ * idat.rij ); - idat.vpair += vterm; - epot += idat.sw * vterm; + vterm = pref * ct_i * ( ri2 - preRF2_ * *(idat.rij) ); + vpair += vterm; + epot += *(idat.sw) * vterm; - dVdr += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i); + dVdr += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_ * uz_i); - duduz_i += preSw * rhat * (ri2 - preRF2_ * idat.rij); + duduz_i += preSw * rhat * (ri2 - preRF2_ * *(idat.rij) ); + + // Even if we excluded this pair from direct interactions, + // we still have the reaction-field-mediated charge-dipole + // interaction: + + if (idat.excluded) { + indirect_vpair += -pref * ct_i * preRF2_ * *(idat.rij); + indirect_Pot += -preSw * ct_i * preRF2_ * *(idat.rij); + indirect_dVdr += -preSw * preRF2_ * uz_i; + indirect_duduz_i += -preSw * rhat * preRF2_ * *(idat.rij); + } } else { // determine inverse r if we are using split dipoles if (i_is_SplitDipole) { - BigR = sqrt(idat.r2 + 0.25 * d_i * d_i); + BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i); ri = 1.0 / BigR; - scale = idat.rij * ri; + scale = *(idat.rij) * ri; } else { ri = riji; scale = 1.0; @@ -651,9 +835,11 @@ namespace OpenMD { if (screeningMethod_ == DAMPED) { // assemble the damping variables - res = erfcSpline_->getValueAndDerivativeAt(idat.rij); - erfcVal = res.first; - derfcVal = res.second; + //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); + //erfcVal = res.first; + //derfcVal = res.second; + erfcVal = erfc(dampingAlpha_ * *(idat.rij)); + derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); c1 = erfcVal * ri; c2 = (-derfcVal + c1) * ri; c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; @@ -668,54 +854,66 @@ namespace OpenMD { // calculate the potential pot_term = c2 * scale; vterm = pref * ct_i * pot_term; - idat.vpair += vterm; - epot += idat.sw * vterm; + vpair += vterm; + epot += *(idat.sw) * vterm; // calculate derivatives for the forces and torques dVdr += preSw * (uz_i * c2ri - ct_i * rhat * sc2 * c3); duduz_i += preSw * pot_term * rhat; } + + if (j_is_Fluctuating) { + *(idat.dVdFQ2) += ( *(idat.sw) * vterm ) / q_j; + } + } if (j_is_Dipole) { // variables used by all methods ct_ij = dot(uz_i, uz_j); - pref = idat.electroMult * pre22_ * mu_i * mu_j; - preSw = idat.sw * pref; + pref = *(idat.electroMult) * pre22_ * mu_i * mu_j; + preSw = *(idat.sw) * pref; - if (summationMethod_ == REACTION_FIELD) { + if (summationMethod_ == esm_REACTION_FIELD) { ri2 = riji * riji; ri3 = ri2 * riji; ri4 = ri2 * ri2; vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) - preRF2_ * ct_ij ); - idat.vpair += vterm; - epot += idat.sw * vterm; + vpair += vterm; + epot += *(idat.sw) * vterm; a1 = 5.0 * ct_i * ct_j - ct_ij; - dVdr += preSw * 3.0 * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i); + dVdr += preSw * three * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i); - duduz_i += preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j); - duduz_j += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_*uz_i); + duduz_i += preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j); + duduz_j += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_*uz_i); + if (idat.excluded) { + indirect_vpair += - pref * preRF2_ * ct_ij; + indirect_Pot += - preSw * preRF2_ * ct_ij; + indirect_duduz_i += -preSw * preRF2_ * uz_j; + indirect_duduz_j += -preSw * preRF2_ * uz_i; + } + } else { if (i_is_SplitDipole) { if (j_is_SplitDipole) { - BigR = sqrt(idat.r2 + 0.25 * d_i * d_i + 0.25 * d_j * d_j); + BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i + 0.25 * d_j * d_j); } else { - BigR = sqrt(idat.r2 + 0.25 * d_i * d_i); + BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i); } ri = 1.0 / BigR; - scale = idat.rij * ri; + scale = *(idat.rij) * ri; } else { if (j_is_SplitDipole) { - BigR = sqrt(idat.r2 + 0.25 * d_j * d_j); + BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j); ri = 1.0 / BigR; - scale = idat.rij * ri; + scale = *(idat.rij) * ri; } else { ri = riji; scale = 1.0; @@ -723,9 +921,11 @@ namespace OpenMD { } if (screeningMethod_ == DAMPED) { // assemble damping variables - res = erfcSpline_->getValueAndDerivativeAt(idat.rij); - erfcVal = res.first; - derfcVal = res.second; + //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); + //erfcVal = res.first; + //derfcVal = res.second; + erfcVal = erfc(dampingAlpha_ * *(idat.rij)); + derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); c1 = erfcVal * ri; c2 = (-derfcVal + c1) * ri; c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri; @@ -745,13 +945,13 @@ namespace OpenMD { preSwSc = preSw * scale; c2ri = c2 * ri; c3ri = c3 * ri; - c4rij = c4 * idat.rij; + c4rij = c4 * *(idat.rij) ; // calculate the potential pot_term = (ct_ij * c2ri - ctidotj * c3); vterm = pref * pot_term; - idat.vpair += vterm; - epot += idat.sw * vterm; + vpair += vterm; + epot += *(idat.sw) * vterm; // calculate derivatives for the forces and torques dVdr += preSwSc * ( ctidotj * rhat * c4rij - @@ -770,13 +970,15 @@ namespace OpenMD { cy2 = cy_i * cy_i; cz2 = cz_i * cz_i; - pref = idat.electroMult * pre14_ * q_j * one_third_; + pref = *(idat.electroMult) * pre14_ * q_j * one_third_; if (screeningMethod_ == DAMPED) { // assemble the damping variables - res = erfcSpline_->getValueAndDerivativeAt(idat.rij); - erfcVal = res.first; - derfcVal = res.second; + //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) ); + //erfcVal = res.first; + //derfcVal = res.second; + erfcVal = erfc(dampingAlpha_ * *(idat.rij)); + derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2)); c1 = erfcVal * riji; c2 = (-derfcVal + c1) * riji; c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji; @@ -789,11 +991,11 @@ namespace OpenMD { } // precompute some variables for convenience - preSw = idat.sw * pref; + preSw = *(idat.sw) * pref; c2ri = c2 * riji; c3ri = c3 * riji; - c4rij = c4 * idat.rij; - rhatdot2 = 2.0 * rhat * c3; + c4rij = c4 * *(idat.rij) ; + rhatdot2 = two * rhat * c3; rhatc4 = rhat * c4rij; // calculate the potential @@ -802,177 +1004,117 @@ namespace OpenMD { qzz_i * (cz2 * c3 - c2ri) ); vterm = pref * pot_term; - idat.vpair += vterm; - epot += idat.sw * vterm; + vpair += vterm; + epot += *(idat.sw) * vterm; // calculate the derivatives for the forces and torques - dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (2.0*cx_i*ux_i + rhat)*c3ri) + - qyy_i* (cy2*rhatc4 - (2.0*cy_i*uy_i + rhat)*c3ri) + - qzz_i* (cz2*rhatc4 - (2.0*cz_i*uz_i + rhat)*c3ri)); + dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (two*cx_i*ux_i + rhat)*c3ri) + + qyy_i* (cy2*rhatc4 - (two*cy_i*uy_i + rhat)*c3ri) + + qzz_i* (cz2*rhatc4 - (two*cz_i*uz_i + rhat)*c3ri)); dudux_i += preSw * qxx_i * cx_i * rhatdot2; duduy_i += preSw * qyy_i * cy_i * rhatdot2; duduz_i += preSw * qzz_i * cz_i * rhatdot2; - } - } - idat.pot += epot; - idat.f1 += dVdr; + if (j_is_Fluctuating) { + *(idat.dVdFQ2) += ( *(idat.sw) * vterm ) / q_j; + } - if (i_is_Dipole || i_is_Quadrupole) - idat.t1 -= cross(uz_i, duduz_i); - if (i_is_Quadrupole) { - idat.t1 -= cross(ux_i, dudux_i); - idat.t1 -= cross(uy_i, duduy_i); + } } - if (j_is_Dipole || j_is_Quadrupole) - idat.t2 -= cross(uz_j, duduz_j); - if (j_is_Quadrupole) { - idat.t2 -= cross(uz_j, dudux_j); - idat.t2 -= cross(uz_j, duduy_j); - } - return; - } + if (!idat.excluded) { + *(idat.vpair) += vpair; + (*(idat.pot))[ELECTROSTATIC_FAMILY] += epot; + *(idat.f1) += dVdr; + + if (i_is_Dipole || i_is_Quadrupole) + *(idat.t1) -= cross(uz_i, duduz_i); + if (i_is_Quadrupole) { + *(idat.t1) -= cross(ux_i, dudux_i); + *(idat.t1) -= cross(uy_i, duduy_i); + } + + if (j_is_Dipole || j_is_Quadrupole) + *(idat.t2) -= cross(uz_j, duduz_j); + if (j_is_Quadrupole) { + *(idat.t2) -= cross(uz_j, dudux_j); + *(idat.t2) -= cross(uz_j, duduy_j); + } - void Electrostatic::calcSkipCorrection(SkipCorrectionData skdat) { + } else { - if (!initialized_) initialize(); - - ElectrostaticAtomData data1 = ElectrostaticMap[skdat.atype1]; - ElectrostaticAtomData data2 = ElectrostaticMap[skdat.atype2]; - - // logicals + // only accumulate the forces and torques resulting from the + // indirect reaction field terms. - bool i_is_Charge = data1.is_Charge; - bool i_is_Dipole = data1.is_Dipole; - - bool j_is_Charge = data2.is_Charge; - bool j_is_Dipole = data2.is_Dipole; - - RealType q_i, q_j; - - // The skippedCharge computation is needed by the real-space cutoff methods - // (i.e. shifted force and shifted potential) - - if (i_is_Charge) { - q_i = data1.charge; - skdat.skippedCharge2 += q_i; - } - - if (j_is_Charge) { - q_j = data2.charge; - skdat.skippedCharge1 += q_j; - } - - // the rest of this function should only be necessary for reaction field. - - if (summationMethod_ == REACTION_FIELD) { - RealType riji, ri2, ri3; - RealType q_i, mu_i, ct_i; - RealType q_j, mu_j, ct_j; - RealType preVal, rfVal, vterm, dudr, pref, myPot; - Vector3d dVdr, uz_i, uz_j, duduz_i, duduz_j, rhat; - - // some variables we'll need independent of electrostatic type: + *(idat.vpair) += indirect_vpair; - riji = 1.0 / skdat.rij; - rhat = skdat.d * riji; - - if (i_is_Dipole) { - mu_i = data1.dipole_moment; - uz_i = skdat.eFrame1.getColumn(2); - ct_i = dot(uz_i, rhat); - duduz_i = V3Zero; - } - - if (j_is_Dipole) { - mu_j = data2.dipole_moment; - uz_j = skdat.eFrame2.getColumn(2); - ct_j = dot(uz_j, rhat); - duduz_j = V3Zero; - } - - if (i_is_Charge) { - if (j_is_Charge) { - preVal = skdat.electroMult * pre11_ * q_i * q_j; - rfVal = preRF_ * skdat.rij * skdat.rij; - vterm = preVal * rfVal; - myPot += skdat.sw * vterm; - dudr = skdat.sw * preVal * 2.0 * rfVal * riji; - dVdr += dudr * rhat; - } - - if (j_is_Dipole) { - ri2 = riji * riji; - ri3 = ri2 * riji; - pref = skdat.electroMult * pre12_ * q_i * mu_j; - vterm = - pref * ct_j * ( ri2 - preRF2_ * skdat.rij ); - myPot += skdat.sw * vterm; - dVdr += -skdat.sw * pref * ( ri3 * ( uz_j - 3.0 * ct_j * rhat) - preRF2_ * uz_j); - duduz_j += -skdat.sw * pref * rhat * (ri2 - preRF2_ * skdat.rij); - } - } - if (i_is_Dipole) { - if (j_is_Charge) { - ri2 = riji * riji; - ri3 = ri2 * riji; - pref = skdat.electroMult * pre12_ * q_j * mu_i; - vterm = - pref * ct_i * ( ri2 - preRF2_ * skdat.rij ); - myPot += skdat.sw * vterm; - dVdr += skdat.sw * pref * ( ri3 * ( uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i); - duduz_i += skdat.sw * pref * rhat * (ri2 - preRF2_ * skdat.rij); - } - } + (*(idat.excludedPot))[ELECTROSTATIC_FAMILY] += (*(idat.sw) * vterm + + vFluc1 ) * q_i * q_j; + (*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot; + *(idat.f1) += indirect_dVdr; - // accumulate the forces and torques resulting from the self term - skdat.pot += myPot; - skdat.f1 += dVdr; - if (i_is_Dipole) - skdat.t1 -= cross(uz_i, duduz_i); + *(idat.t1) -= cross(uz_i, indirect_duduz_i); if (j_is_Dipole) - skdat.t2 -= cross(uz_j, duduz_j); + *(idat.t2) -= cross(uz_j, indirect_duduz_j); } - } + + return; + } - void Electrostatic::calcSelfCorrection(SelfCorrectionData scdat) { - RealType mu1, preVal, chg1, self; - + void Electrostatic::calcSelfCorrection(SelfData &sdat) { + RealType mu1, preVal, self; if (!initialized_) initialize(); - - ElectrostaticAtomData data = ElectrostaticMap[scdat.atype]; + + ElectrostaticAtomData data = ElectrostaticMap[sdat.atype]; // logicals - bool i_is_Charge = data.is_Charge; bool i_is_Dipole = data.is_Dipole; + bool i_is_Fluctuating = data.is_Fluctuating; + RealType chg1 = data.fixedCharge; + + if (i_is_Fluctuating) { + chg1 += *(sdat.flucQ); + // dVdFQ is really a force, so this is negative the derivative + *(sdat.dVdFQ) -= *(sdat.flucQ) * data.hardness + data.electronegativity; + (*(sdat.excludedPot))[ELECTROSTATIC_FAMILY] += (*sdat.flucQ) * + (*(sdat.flucQ) * data.hardness * 0.5 + data.electronegativity); + } - if (summationMethod_ == REACTION_FIELD) { + if (summationMethod_ == esm_REACTION_FIELD) { if (i_is_Dipole) { mu1 = data.dipole_moment; preVal = pre22_ * preRF2_ * mu1 * mu1; - scdat.pot -= 0.5 * preVal; + (*(sdat.pot))[ELECTROSTATIC_FAMILY] -= 0.5 * preVal; // The self-correction term adds into the reaction field vector - Vector3d uz_i = scdat.eFrame.getColumn(2); + Vector3d uz_i = sdat.eFrame->getColumn(2); Vector3d ei = preVal * uz_i; // This looks very wrong. A vector crossed with itself is zero. - scdat.t -= cross(uz_i, ei); + *(sdat.t) -= cross(uz_i, ei); } - } else if (summationMethod_ == SHIFTED_FORCE || summationMethod_ == SHIFTED_POTENTIAL) { + } else if (summationMethod_ == esm_SHIFTED_FORCE || summationMethod_ == esm_SHIFTED_POTENTIAL) { if (i_is_Charge) { - chg1 = data.charge; if (screeningMethod_ == DAMPED) { - self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + scdat.skippedCharge) * pre11_; + self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_; } else { - self = - 0.5 * rcuti_ * chg1 * (chg1 + scdat.skippedCharge) * pre11_; + self = - 0.5 * rcuti_ * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_; } - scdat.pot += self; + (*(sdat.pot))[ELECTROSTATIC_FAMILY] += self; } } } + + RealType Electrostatic::getSuggestedCutoffRadius(pair atypes) { + // This seems to work moderately well as a default. There's no + // inherent scale for 1/r interactions that we can standardize. + // 12 angstroms seems to be a reasonably good guess for most + // cases. + return 12.0; + } }