--- branches/development/src/nonbonded/Electrostatic.cpp 2011/08/04 20:04:35 1601 +++ branches/development/src/nonbonded/Electrostatic.cpp 2012/01/06 19:03:05 1668 @@ -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; @@ -454,6 +461,7 @@ namespace OpenMD { RealType c1, c2, c3, c4; 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; @@ -578,9 +586,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 { @@ -610,7 +622,7 @@ namespace OpenMD { if (idat.excluded) { indirect_vpair += preVal * rfVal; indirect_Pot += *(idat.sw) * preVal * rfVal; - indirect_dVdr += *(idat.sw) * preVal * 2.0 * rfVal * riji * rhat; + indirect_dVdr += *(idat.sw) * preVal * two * rfVal * riji * rhat; } } else { @@ -638,7 +650,7 @@ namespace OpenMD { vpair += vterm; epot += *(idat.sw) * vterm; - dVdr += -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j); + 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, @@ -667,9 +679,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 +718,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; @@ -723,7 +739,7 @@ namespace OpenMD { c2ri = c2 * riji; c3ri = c3 * riji; c4rij = c4 * *(idat.rij) ; - rhatdot2 = 2.0 * rhat * c3; + rhatdot2 = two * rhat * c3; rhatc4 = rhat * c4rij; // calculate the potential @@ -736,9 +752,9 @@ namespace OpenMD { // 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; @@ -762,7 +778,7 @@ namespace OpenMD { 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) ); @@ -793,9 +809,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; @@ -838,10 +856,10 @@ namespace OpenMD { 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; @@ -872,9 +890,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 +943,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; @@ -942,7 +964,7 @@ namespace OpenMD { c2ri = c2 * riji; c3ri = c3 * riji; c4rij = c4 * *(idat.rij) ; - rhatdot2 = 2.0 * rhat * c3; + rhatdot2 = two * rhat * c3; rhatc4 = rhat * c4rij; // calculate the potential @@ -956,9 +978,9 @@ namespace OpenMD { // 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; @@ -990,6 +1012,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;