--- branches/development/src/nonbonded/Electrostatic.cpp 2011/07/08 20:25:32 1587 +++ branches/development/src/nonbonded/Electrostatic.cpp 2011/11/22 20:38:56 1665 @@ -36,7 +36,8 @@ * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [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 @@ -64,6 +65,7 @@ namespace OpenMD { 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; @@ -116,7 +118,7 @@ namespace OpenMD { sprintf( painCave.errMsg, "Electrostatic::initialize: Unknown electrostaticSummationMethod.\n" "\t(Input file specified %s .)\n" - "\telectrostaticSummationMethod must be one of: \"none\",\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; @@ -249,7 +251,12 @@ namespace OpenMD { preRF2_ = 2.0 * preRF_; } - RealType dx = cutoffRadius_ / 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; @@ -578,9 +585,13 @@ namespace OpenMD { if (j_is_Charge) { 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; } else { @@ -667,9 +678,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; @@ -704,9 +717,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 * riji; c2 = (-derfcVal + c1) * riji; c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji; @@ -793,9 +808,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; @@ -872,9 +889,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; @@ -923,9 +942,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 * riji; c2 = (-derfcVal + c1) * riji; c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji; @@ -990,6 +1011,7 @@ namespace OpenMD { // only accumulate the forces and torques resulting from the // indirect reaction field terms. + *(idat.vpair) += indirect_vpair; (*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot; *(idat.f1) += indirect_dVdr; @@ -1003,108 +1025,7 @@ namespace OpenMD { return; } - - void Electrostatic::calcSkipCorrection(InteractionData &idat) { - - if (!initialized_) initialize(); - ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first]; - ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second]; - - // logicals - - 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; - *(idat.skippedCharge2) += q_i; - } - - if (j_is_Charge) { - q_j = data2.charge; - *(idat.skippedCharge1) += q_j; - } - - // the rest of this function should only be necessary for reaction field. - - if (summationMethod_ == esm_REACTION_FIELD) { - RealType riji, ri2, ri3; - RealType mu_i, ct_i; - RealType mu_j, ct_j; - RealType preVal, rfVal, vterm, dudr, pref, myPot(0.0); - Vector3d dVdr, uz_i, uz_j, duduz_i, duduz_j, rhat; - - // some variables we'll need independent of electrostatic type: - - riji = 1.0 / *(idat.rij) ; - rhat = *(idat.d) * riji; - - if (i_is_Dipole) { - mu_i = data1.dipole_moment; - uz_i = idat.eFrame1->getColumn(2); - ct_i = dot(uz_i, rhat); - duduz_i = V3Zero; - } - - if (j_is_Dipole) { - mu_j = data2.dipole_moment; - uz_j = idat.eFrame2->getColumn(2); - ct_j = dot(uz_j, rhat); - duduz_j = V3Zero; - } - - if (i_is_Charge) { - if (j_is_Charge) { - preVal = *(idat.electroMult) * pre11_ * q_i * q_j; - rfVal = preRF_ * *(idat.rij) * *(idat.rij) ; - vterm = preVal * rfVal; - myPot += *(idat.sw) * vterm; - dudr = *(idat.sw) * preVal * 2.0 * rfVal * riji; - dVdr += dudr * rhat; - } - - if (j_is_Dipole) { - ri2 = riji * riji; - ri3 = ri2 * riji; - pref = *(idat.electroMult) * pre12_ * q_i * mu_j; - vterm = - pref * ct_j * ( ri2 - preRF2_ * *(idat.rij) ); - myPot += *(idat.sw) * vterm; - dVdr += - *(idat.sw) * pref * ( ri3 * ( uz_j - 3.0 * ct_j * rhat) - preRF2_ * uz_j); - duduz_j += - *(idat.sw) * pref * rhat * (ri2 - preRF2_ * *(idat.rij) ); - } - } - if (i_is_Dipole) { - if (j_is_Charge) { - ri2 = riji * riji; - ri3 = ri2 * riji; - pref = *(idat.electroMult) * pre12_ * q_j * mu_i; - vterm = - pref * ct_i * ( ri2 - preRF2_ * *(idat.rij) ); - myPot += *(idat.sw) * vterm; - dVdr += *(idat.sw) * pref * ( ri3 * ( uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i); - duduz_i += *(idat.sw) * pref * rhat * (ri2 - preRF2_ * *(idat.rij)); - } - } - - // accumulate the forces and torques resulting from the self term - (*(idat.pot))[ELECTROSTATIC_FAMILY] += myPot; - *(idat.f1) += dVdr; - - if (i_is_Dipole) - *(idat.t1) -= cross(uz_i, duduz_i); - if (j_is_Dipole) - *(idat.t2) -= cross(uz_j, duduz_j); - } - } - void Electrostatic::calcSelfCorrection(SelfData &sdat) { RealType mu1, preVal, chg1, self;