ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/nonbonded/Electrostatic.cpp
(Generate patch)

Comparing branches/development/src/nonbonded/Electrostatic.cpp (file contents):
Revision 1504 by gezelter, Sat Oct 2 20:41:53 2010 UTC vs.
Revision 1710 by gezelter, Fri May 18 21:44:02 2012 UTC

# Line 34 | Line 34
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>
# Line 46 | Line 47
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  
51
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_ = 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;    
73 +    summationMap_["REACTION_FIELD"]     = esm_REACTION_FIELD;    
74 +    summationMap_["EWALD_FULL"]         = esm_EWALD_FULL;        
75 +    summationMap_["EWALD_PME"]          = esm_EWALD_PME;        
76 +    summationMap_["EWALD_SPME"]         = esm_EWALD_SPME;        
77 +    screeningMap_["DAMPED"]             = DAMPED;
78 +    screeningMap_["UNDAMPED"]           = UNDAMPED;
79 +
80      // these prefactors convert the multipole interactions into kcal / mol
81      // all were computed assuming distances are measured in angstroms
82      // Charge-Charge, assuming charges are measured in electrons
# Line 79 | Line 101 | namespace OpenMD {
101      
102      // variables to handle different summation methods for long-range
103      // electrostatics:
104 <    summationMethod_ = NONE;    
104 >    summationMethod_ = esm_HARD;    
105      screeningMethod_ = UNDAMPED;
106      dielectric_ = 1.0;
107      one_third_ = 1.0 / 3.0;
86    haveDefaultCutoff_ = false;
87    haveDampingAlpha_ = false;
88    haveDielectric_ = false;  
89    haveElectroSpline_ = false;
108    
109 +    // check the summation method:
110 +    if (simParams_->haveElectrostaticSummationMethod()) {
111 +      string myMethod = simParams_->getElectrostaticSummationMethod();
112 +      toUpper(myMethod);
113 +      map<string, ElectrostaticSummationMethod>::iterator i;
114 +      i = summationMap_.find(myMethod);
115 +      if ( i != summationMap_.end() ) {
116 +        summationMethod_ = (*i).second;
117 +      } else {
118 +        // throw error
119 +        sprintf( painCave.errMsg,
120 +                 "Electrostatic::initialize: Unknown electrostaticSummationMethod.\n"
121 +                 "\t(Input file specified %s .)\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;
126 +        simError();
127 +      }
128 +    } else {
129 +      // set ElectrostaticSummationMethod to the cutoffMethod:
130 +      if (simParams_->haveCutoffMethod()){
131 +        string myMethod = simParams_->getCutoffMethod();
132 +        toUpper(myMethod);
133 +        map<string, ElectrostaticSummationMethod>::iterator i;
134 +        i = summationMap_.find(myMethod);
135 +        if ( i != summationMap_.end() ) {
136 +          summationMethod_ = (*i).second;
137 +        }
138 +      }
139 +    }
140 +    
141 +    if (summationMethod_ == esm_REACTION_FIELD) {        
142 +      if (!simParams_->haveDielectric()) {
143 +        // throw warning
144 +        sprintf( painCave.errMsg,
145 +                 "SimInfo warning: dielectric was not specified in the input file\n\tfor the reaction field correction method.\n"
146 +                 "\tA default value of %f will be used for the dielectric.\n", dielectric_);
147 +        painCave.isFatal = 0;
148 +        painCave.severity = OPENMD_INFO;
149 +        simError();
150 +      } else {
151 +        dielectric_ = simParams_->getDielectric();      
152 +      }
153 +      haveDielectric_ = true;
154 +    }
155 +    
156 +    if (simParams_->haveElectrostaticScreeningMethod()) {
157 +      string myScreen = simParams_->getElectrostaticScreeningMethod();
158 +      toUpper(myScreen);
159 +      map<string, ElectrostaticScreeningMethod>::iterator i;
160 +      i = screeningMap_.find(myScreen);
161 +      if ( i != screeningMap_.end()) {
162 +        screeningMethod_ = (*i).second;
163 +      } else {
164 +        sprintf( painCave.errMsg,
165 +                 "SimInfo error: Unknown electrostaticScreeningMethod.\n"
166 +                 "\t(Input file specified %s .)\n"
167 +                 "\telectrostaticScreeningMethod must be one of: \"undamped\"\n"
168 +                 "or \"damped\".\n", myScreen.c_str() );
169 +        painCave.isFatal = 1;
170 +        simError();
171 +      }
172 +    }
173 +
174 +    // check to make sure a cutoff value has been set:
175 +    if (!haveCutoffRadius_) {
176 +      sprintf( painCave.errMsg, "Electrostatic::initialize has no Default "
177 +               "Cutoff value!\n");
178 +      painCave.severity = OPENMD_ERROR;
179 +      painCave.isFatal = 1;
180 +      simError();
181 +    }
182 +          
183 +    if (screeningMethod_ == DAMPED) {      
184 +      if (!simParams_->haveDampingAlpha()) {
185 +        // first set a cutoff dependent alpha value
186 +        // we assume alpha depends linearly with rcut from 0 to 20.5 ang
187 +        dampingAlpha_ = 0.425 - cutoffRadius_* 0.02;
188 +        if (dampingAlpha_ < 0.0) dampingAlpha_ = 0.0;
189 +        
190 +        // throw warning
191 +        sprintf( painCave.errMsg,
192 +                 "Electrostatic::initialize: dampingAlpha was not specified in the input file.\n"
193 +                 "\tA default value of %f (1/ang) will be used for the cutoff of\n\t%f (ang).\n",
194 +                 dampingAlpha_, cutoffRadius_);
195 +        painCave.severity = OPENMD_INFO;
196 +        painCave.isFatal = 0;
197 +        simError();
198 +      } else {
199 +        dampingAlpha_ = simParams_->getDampingAlpha();
200 +      }
201 +      haveDampingAlpha_ = true;
202 +    }
203 +
204      // find all of the Electrostatic atom Types:
205      ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
206      ForceField::AtomTypeContainer::MapTypeIterator i;
207      AtomType* at;
208 <
208 >    
209      for (at = atomTypes->beginType(i); at != NULL;
210           at = atomTypes->nextType(i)) {
211        
# Line 100 | Line 213 | namespace OpenMD {
213          addType(at);
214      }
215      
103    // check to make sure a cutoff value has been set:
104    if (!haveDefaultCutoff_) {
105      sprintf( painCave.errMsg, "Electrostatic::initialize has no Default "
106               "Cutoff value!\n");
107      painCave.severity = OPENMD_ERROR;
108      painCave.isFatal = 1;
109      simError();
110    }
216  
217 <    defaultCutoff2_ = defaultCutoff_ * defaultCutoff_;
218 <    rcuti_ = 1.0 / defaultCutoff_;
217 >    cutoffRadius2_ = cutoffRadius_ * cutoffRadius_;
218 >    rcuti_ = 1.0 / cutoffRadius_;
219      rcuti2_ = rcuti_ * rcuti_;
220      rcuti3_ = rcuti2_ * rcuti_;
221      rcuti4_ = rcuti2_ * rcuti2_;
222  
223      if (screeningMethod_ == DAMPED) {
224 <      if (!haveDampingAlpha_) {
120 <        sprintf( painCave.errMsg, "Electrostatic::initialize has no "
121 <                 "DampingAlpha value!\n");
122 <        painCave.severity = OPENMD_ERROR;
123 <        painCave.isFatal = 1;
124 <        simError();
125 <      }
126 <
224 >      
225        alpha2_ = dampingAlpha_ * dampingAlpha_;
226        alpha4_ = alpha2_ * alpha2_;
227        alpha6_ = alpha4_ * alpha2_;
228        alpha8_ = alpha4_ * alpha4_;
229        
230 <      constEXP_ = exp(-alpha2_ * defaultCutoff2_);
230 >      constEXP_ = exp(-alpha2_ * cutoffRadius2_);
231        invRootPi_ = 0.56418958354775628695;
232        alphaPi_ = 2.0 * dampingAlpha_ * invRootPi_;
233  
234 <      c1c_ = erfc(dampingAlpha_ * defaultCutoff_) * rcuti_;
234 >      c1c_ = erfc(dampingAlpha_ * cutoffRadius_) * rcuti_;
235        c2c_ = alphaPi_ * constEXP_ * rcuti_ + c1c_ * rcuti_;
236        c3c_ = 2.0 * alphaPi_ * alpha2_ + 3.0 * c2c_ * rcuti_;
237        c4c_ = 4.0 * alphaPi_ * alpha4_ + 5.0 * c3c_ * rcuti2_;
# Line 148 | Line 246 | namespace OpenMD {
246        c6c_ = 9.0 * c5c_ * rcuti2_;
247      }
248    
249 <    if (summationMethod_ == REACTION_FIELD) {
250 <      if (haveDielectric_) {
251 <        preRF_ = (dielectric_ - 1.0) /
252 <            ((2.0 * dielectric_ + 1.0) * defaultCutoff2_ * defaultCutoff_);
155 <        preRF2_ = 2.0 * preRF_;
156 <      } else {
157 <        sprintf( painCave.errMsg, "Electrostatic::initialize has no Dielectric"
158 <                 " value!\n");
159 <        painCave.severity = OPENMD_ERROR;
160 <        painCave.isFatal = 1;
161 <        simError();
162 <      }
249 >    if (summationMethod_ == esm_REACTION_FIELD) {
250 >      preRF_ = (dielectric_ - 1.0) /
251 >        ((2.0 * dielectric_ + 1.0) * cutoffRadius2_ * cutoffRadius_);
252 >      preRF2_ = 2.0 * preRF_;
253      }
254 <                              
255 <    RealType dx = defaultCutoff_ / RealType(np_ - 1);
254 >    
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;
# Line 186 | Line 281 | namespace OpenMD {
281      electrostaticAtomData.is_SplitDipole = false;
282      electrostaticAtomData.is_Quadrupole = false;
283  
284 <    if (atomType->isCharge()) {
190 <      GenericData* data = atomType->getPropertyByName("Charge");
284 >    FixedChargeAdapter fca = FixedChargeAdapter(atomType);
285  
286 <      if (data == NULL) {
193 <        sprintf( painCave.errMsg, "Electrostatic::addType could not find "
194 <                 "Charge\n"
195 <                 "\tparameters for atomType %s.\n",
196 <                 atomType->getName().c_str());
197 <        painCave.severity = OPENMD_ERROR;
198 <        painCave.isFatal = 1;
199 <        simError();                  
200 <      }
201 <      
202 <      DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
203 <      if (doubleData == NULL) {
204 <        sprintf( painCave.errMsg,
205 <                 "Electrostatic::addType could not convert GenericData to "
206 <                 "Charge for\n"
207 <                 "\tatom type %s\n", atomType->getName().c_str());
208 <        painCave.severity = OPENMD_ERROR;
209 <        painCave.isFatal = 1;
210 <        simError();          
211 <      }
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 <      
219 <      if (daType->isDipole()) {
220 <        GenericData* data = daType->getPropertyByName("Dipole");
221 <        
222 <        if (data == NULL) {
223 <          sprintf( painCave.errMsg,
224 <                   "Electrostatic::addType could not find Dipole\n"
225 <                   "\tparameters for atomType %s.\n",
226 <                   daType->getName().c_str());
227 <          painCave.severity = OPENMD_ERROR;
228 <          painCave.isFatal = 1;
229 <          simError();                  
230 <        }
231 <      
232 <        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
233 <        if (doubleData == NULL) {
234 <          sprintf( painCave.errMsg,
235 <                   "Electrostatic::addType could not convert GenericData to "
236 <                   "Dipole Moment\n"
237 <                   "\tfor atom type %s\n", daType->getName().c_str());
238 <          painCave.severity = OPENMD_ERROR;
239 <          painCave.isFatal = 1;
240 <          simError();          
241 <        }
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 <
246 <      if (daType->isSplitDipole()) {
247 <        GenericData* data = daType->getPropertyByName("SplitDipoleDistance");
248 <        
249 <        if (data == NULL) {
250 <          sprintf(painCave.errMsg,
251 <                  "Electrostatic::addType could not find SplitDipoleDistance\n"
252 <                  "\tparameter for atomType %s.\n",
253 <                  daType->getName().c_str());
254 <          painCave.severity = OPENMD_ERROR;
255 <          painCave.isFatal = 1;
256 <          simError();                  
257 <        }
258 <      
259 <        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
260 <        if (doubleData == NULL) {
261 <          sprintf( painCave.errMsg,
262 <                   "Electrostatic::addType could not convert GenericData to "
263 <                   "SplitDipoleDistance for\n"
264 <                   "\tatom type %s\n", daType->getName().c_str());
265 <          painCave.severity = OPENMD_ERROR;
266 <          painCave.isFatal = 1;
267 <          simError();          
268 <        }
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 <
302 <      if (daType->isQuadrupole()) {
303 <        GenericData* data = daType->getPropertyByName("QuadrupoleMoments");
304 <        
305 <        if (data == NULL) {
306 <          sprintf( painCave.errMsg,
278 <                   "Electrostatic::addType could not find QuadrupoleMoments\n"
279 <                   "\tparameter for atomType %s.\n",
280 <                   daType->getName().c_str());
281 <          painCave.severity = OPENMD_ERROR;
282 <          painCave.isFatal = 1;
283 <          simError();                  
284 <        }
285 <        
286 <        Vector3dGenericData* v3dData = dynamic_cast<Vector3dGenericData*>(data);
287 <        if (v3dData == NULL) {
288 <          sprintf( painCave.errMsg,
289 <                   "Electrostatic::addType could not convert GenericData to "
290 <                   "Quadrupole Moments for\n"
291 <                   "\tatom type %s\n", daType->getName().c_str());
292 <          painCave.severity = OPENMD_ERROR;
293 <          painCave.isFatal = 1;
294 <          simError();          
295 <        }
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.
307          electrostaticAtomData.is_Quadrupole = true;
308 <        electrostaticAtomData.quadrupole_moments = v3dData->getData();
308 >        electrostaticAtomData.quadrupole_moments = ma.getQuadrupoleMoments();
309        }
310      }
311      
301    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();        
# Line 315 | Line 326 | namespace OpenMD {
326      return;
327    }
328    
329 <  void Electrostatic::setElectrostaticCutoffRadius( RealType theECR,
330 <                                                    RealType theRSW ) {
331 <    defaultCutoff_ = theECR;
332 <    rrf_ = defaultCutoff_;
322 <    rt_ = theRSW;
323 <    haveDefaultCutoff_ = true;
329 >  void Electrostatic::setCutoffRadius( RealType rCut ) {
330 >    cutoffRadius_ = rCut;
331 >    rrf_ = cutoffRadius_;
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    }
# Line 337 | Line 350 | namespace OpenMD {
350      haveDielectric_ = true;
351    }
352  
353 <  void Electrostatic::calcForce(InteractionData idat) {
353 >  void Electrostatic::calcForce(InteractionData &idat) {
354  
355      // utility variables.  Should clean these up and use the Vector3d and
356      // Mat3x3d to replace as many as we can in future versions:
# Line 351 | Line 364 | namespace OpenMD {
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;
# Line 367 | Line 382 | namespace OpenMD {
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.atype1];
396 <    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atype2];
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  
400 <    riji = 1.0 / idat.rij;
401 <    Vector3d rhat = idat.d  * riji;
400 >    riji = 1.0 /  *(idat.rij) ;
401 >    Vector3d rhat =  *(idat.d)   * riji;
402  
403      // logicals
404  
# Line 391 | Line 412 | namespace OpenMD {
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;
424 <      uz_i = idat.eFrame1.getColumn(2);
424 >      uz_i = idat.eFrame1->getColumn(2);
425        
426        ct_i = dot(uz_i, rhat);
427  
# Line 412 | Line 437 | namespace OpenMD {
437        qyy_i = Q_i.y();
438        qzz_i = Q_i.z();
439        
440 <      ux_i = idat.eFrame1.getColumn(0);
441 <      uy_i = idat.eFrame1.getColumn(1);
442 <      uz_i = idat.eFrame1.getColumn(2);
440 >      ux_i = idat.eFrame1->getColumn(0);
441 >      uy_i = idat.eFrame1->getColumn(1);
442 >      uz_i = idat.eFrame1->getColumn(2);
443  
444        cx_i = dot(ux_i, rhat);
445        cy_i = dot(uy_i, rhat);
# Line 425 | Line 450 | namespace OpenMD {
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);
463 >      uz_j = idat.eFrame2->getColumn(2);
464        
465        ct_j = dot(uz_j, rhat);
466  
# Line 446 | Line 476 | namespace OpenMD {
476        qyy_j = Q_j.y();
477        qzz_j = Q_j.z();
478        
479 <      ux_j = idat.eFrame2.getColumn(0);
480 <      uy_j = idat.eFrame2.getColumn(1);
481 <      uz_j = idat.eFrame2.getColumn(2);
479 >      ux_j = idat.eFrame2->getColumn(0);
480 >      uy_j = idat.eFrame2->getColumn(1);
481 >      uz_j = idat.eFrame2->getColumn(2);
482  
483        cx_j = dot(ux_j, rhat);
484        cy_j = dot(uy_j, rhat);
# Line 467 | Line 497 | namespace OpenMD {
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 {
# Line 477 | Line 511 | namespace OpenMD {
511            c2 = c1 * riji;
512          }
513  
514 <        preVal = idat.electroMult * pre11_ * q_i * q_j;
514 >        preVal =  *(idat.electroMult) * pre11_ * q_i * q_j;
515          
516 <        if (summationMethod_ == SHIFTED_POTENTIAL) {
516 >        if (summationMethod_ == esm_SHIFTED_POTENTIAL) {
517            vterm = preVal * (c1 - c1c_);
518 <          dudr  = -idat.sw * preVal * c2;
518 >          dudr  = - *(idat.sw)  * preVal * c2;
519  
520 <        } else if (summationMethod_ == SHIFTED_FORCE)  {
521 <          vterm = preVal * ( c1 - c1c_ + c2c_*(idat.rij - defaultCutoff_) );
522 <          dudr  = idat.sw * preVal * (c2c_ - c2);
520 >        } else if (summationMethod_ == esm_SHIFTED_FORCE)  {
521 >          vterm = preVal * ( c1 - c1c_ + c2c_*( *(idat.rij)  - cutoffRadius_) );
522 >          dudr  =  *(idat.sw)  * preVal * (c2c_ - c2);
523  
524 <        } else if (summationMethod_ == REACTION_FIELD) {
525 <          rfVal = idat.electroMult * preRF_ * idat.rij * idat.rij;
524 >        } else if (summationMethod_ == esm_REACTION_FIELD) {
525 >          rfVal = preRF_ *  *(idat.rij)  *  *(idat.rij);
526 >
527            vterm = preVal * ( riji + rfVal );            
528 <          dudr  = idat.sw * preVal * ( 2.0 * rfVal - riji ) * riji;
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 {
496          vterm = preVal * riji * erfcVal;            
540  
541 <          dudr  = - idat.sw * preVal * c2;
541 >          vterm = preVal * riji * erfcVal;          
542 >          dudr  = -  *(idat.sw)  * preVal * c2;
543  
544          }
501
502        idat.vpair += vterm;
503        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) {
552          // pref is used by all the possible methods
553 <        pref = idat.electroMult * pre12_ * q_i * mu_j;
554 <        preSw = idat.sw * pref;
553 >        pref =  *(idat.electroMult) * pre12_ * q_i * mu_j;
554 >        preSw =  *(idat.sw)  * pref;
555  
556 <        if (summationMethod_ == REACTION_FIELD) {
556 >        if (summationMethod_ == esm_REACTION_FIELD) {
557            ri2 = riji * riji;
558            ri3 = ri2 * riji;
559      
560 <          vterm = - pref * ct_j * ( ri2 - preRF2_ * idat.rij );
561 <          idat.vpair += vterm;
562 <          epot += idat.sw * vterm;
560 >          vterm = - pref * ct_j * ( ri2 - preRF2_ *  *(idat.rij)  );
561 >          vpair += vterm;
562 >          epot +=  *(idat.sw)  * vterm;
563  
564 <          dVdr +=  -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
565 <          duduz_j += -preSw * rhat * (ri2 - preRF2_ * idat.rij);  
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) {
581 <            BigR = sqrt(idat.r2 + 0.25 * d_j * d_j);
581 >            BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j);
582              ri = 1.0 / BigR;
583 <            scale = idat.rij * ri;
583 >            scale =  *(idat.rij)  * ri;
584            } else {
585              ri = riji;
586              scale = 1.0;
# Line 536 | Line 590 | namespace OpenMD {
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;
# Line 553 | Line 609 | namespace OpenMD {
609            // calculate the potential
610            pot_term =  scale * c2;
611            vterm = -pref * ct_j * pot_term;
612 <          idat.vpair += vterm;
613 <          epot += idat.sw * vterm;
612 >          vpair += vterm;
613 >          epot +=  *(idat.sw)  * vterm;
614              
615            // calculate derivatives for forces and torques
616  
# Line 569 | Line 625 | namespace OpenMD {
625          cx2 = cx_j * cx_j;
626          cy2 = cy_j * cy_j;
627          cz2 = cz_j * cz_j;
628 <        pref =  idat.electroMult * pre14_ * q_i * one_third_;
628 >        pref =   *(idat.electroMult) * pre14_ * q_i * one_third_;
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;
# Line 588 | Line 646 | namespace OpenMD {
646          }
647  
648          // precompute variables for convenience
649 <        preSw = idat.sw * pref;
649 >        preSw =  *(idat.sw)  * pref;
650          c2ri = c2 * riji;
651          c3ri = c3 * riji;
652 <        c4rij = c4 * idat.rij;
653 <        rhatdot2 = 2.0 * rhat * c3;
652 >        c4rij = c4 *  *(idat.rij) ;
653 >        rhatdot2 = two * rhat * c3;
654          rhatc4 = rhat * c4rij;
655  
656          // calculate the potential
# Line 600 | Line 658 | namespace OpenMD {
658                       qyy_j * (cy2*c3 - c2ri) +
659                       qzz_j * (cz2*c3 - c2ri) );
660          vterm = pref * pot_term;
661 <        idat.vpair += vterm;
662 <        epot += idat.sw * 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;
# Line 619 | Line 677 | namespace OpenMD {
677  
678        if (j_is_Charge) {
679          // variables used by all the methods
680 <        pref = idat.electroMult * pre12_ * q_j * mu_i;
681 <        preSw = idat.sw * pref;
680 >        pref =  *(idat.electroMult) * pre12_ * q_j * mu_i;
681 >        preSw =  *(idat.sw)  * pref;
682  
683 <        if (summationMethod_ == REACTION_FIELD) {
683 >        if (summationMethod_ == esm_REACTION_FIELD) {
684  
685            ri2 = riji * riji;
686            ri3 = ri2 * riji;
687  
688 <          vterm = pref * ct_i * ( ri2 - preRF2_ * idat.rij );
689 <          idat.vpair += vterm;
690 <          epot += idat.sw * vterm;
688 >          vterm = pref * ct_i * ( ri2 - preRF2_ *  *(idat.rij)  );
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);
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            
709            // determine inverse r if we are using split dipoles
710            if (i_is_SplitDipole) {
711 <            BigR = sqrt(idat.r2 + 0.25 * d_i * d_i);
711 >            BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i);
712              ri = 1.0 / BigR;
713 <            scale = idat.rij * ri;
713 >            scale =  *(idat.rij)  * ri;
714            } else {
715              ri = riji;
716              scale = 1.0;
# Line 651 | Line 720 | namespace OpenMD {
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;
# Line 668 | Line 739 | namespace OpenMD {
739            // calculate the potential
740            pot_term = c2 * scale;
741            vterm = pref * ct_i * pot_term;
742 <          idat.vpair += vterm;
743 <          epot += idat.sw * vterm;
742 >          vpair += vterm;
743 >          epot +=  *(idat.sw)  * vterm;
744  
745            // calculate derivatives for the forces and torques
746            dVdr += preSw * (uz_i * c2ri - ct_i * rhat * sc2 * c3);
# Line 681 | Line 752 | namespace OpenMD {
752          // variables used by all methods
753          ct_ij = dot(uz_i, uz_j);
754  
755 <        pref = idat.electroMult * pre22_ * mu_i * mu_j;
756 <        preSw = idat.sw * pref;
755 >        pref =  *(idat.electroMult) * pre22_ * mu_i * mu_j;
756 >        preSw =  *(idat.sw)  * pref;
757  
758 <        if (summationMethod_ == REACTION_FIELD) {
758 >        if (summationMethod_ == esm_REACTION_FIELD) {
759            ri2 = riji * riji;
760            ri3 = ri2 * riji;
761            ri4 = ri2 * ri2;
762  
763            vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) -
764                             preRF2_ * ct_ij );
765 <          idat.vpair += vterm;
766 <          epot += idat.sw * 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) {
785              if (j_is_SplitDipole) {
786 <              BigR = sqrt(idat.r2 + 0.25 * d_i * d_i + 0.25 * d_j * d_j);
786 >              BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i + 0.25 * d_j * d_j);
787              } else {
788 <              BigR = sqrt(idat.r2 + 0.25 * d_i * d_i);
788 >              BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i);
789              }
790              ri = 1.0 / BigR;
791 <            scale = idat.rij * ri;
791 >            scale =  *(idat.rij)  * ri;
792            } else {
793              if (j_is_SplitDipole) {
794 <              BigR = sqrt(idat.r2 + 0.25 * d_j * d_j);
794 >              BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j);
795                ri = 1.0 / BigR;
796 <              scale = idat.rij * ri;
796 >              scale =  *(idat.rij)  * ri;
797              } else {
798                ri = riji;
799                scale = 1.0;
# Line 723 | Line 801 | namespace OpenMD {
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;
# Line 745 | Line 825 | namespace OpenMD {
825            preSwSc = preSw * scale;
826            c2ri = c2 * ri;
827            c3ri = c3 * ri;
828 <          c4rij = c4 * idat.rij;
828 >          c4rij = c4 *  *(idat.rij) ;
829  
830            // calculate the potential
831            pot_term = (ct_ij * c2ri - ctidotj * c3);
832            vterm = pref * pot_term;
833 <          idat.vpair += vterm;
834 <          epot += idat.sw * vterm;
833 >          vpair += vterm;
834 >          epot +=  *(idat.sw)  * vterm;
835  
836            // calculate derivatives for the forces and torques
837            dVdr += preSwSc * ( ctidotj * rhat * c4rij  -
# Line 770 | Line 850 | namespace OpenMD {
850          cy2 = cy_i * cy_i;
851          cz2 = cz_i * cz_i;
852  
853 <        pref = idat.electroMult * pre14_ * q_j * one_third_;
853 >        pref =  *(idat.electroMult) * pre14_ * q_j * one_third_;
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;
# Line 789 | Line 871 | namespace OpenMD {
871          }
872            
873          // precompute some variables for convenience
874 <        preSw = idat.sw * pref;
874 >        preSw =  *(idat.sw)  * pref;
875          c2ri = c2 * riji;
876          c3ri = c3 * riji;
877 <        c4rij = c4 * idat.rij;
878 <        rhatdot2 = 2.0 * rhat * c3;
877 >        c4rij = c4 *  *(idat.rij) ;
878 >        rhatdot2 = two * rhat * c3;
879          rhatc4 = rhat * c4rij;
880  
881          // calculate the potential
# Line 802 | Line 884 | namespace OpenMD {
884                       qzz_i * (cz2 * c3 - c2ri) );
885          
886          vterm = pref * pot_term;
887 <        idat.vpair += vterm;
888 <        epot += idat.sw * 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;
# Line 817 | Line 899 | namespace OpenMD {
899        }
900      }
901  
820    idat.pot += epot;
821    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 <    }
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 <    if (j_is_Dipole || j_is_Quadrupole)
831 <      idat.t2 -= cross(uz_j, duduz_j);
832 <    if (j_is_Quadrupole) {
833 <      idat.t2 -= cross(uz_j, dudux_j);
834 <      idat.t2 -= cross(uz_j, duduy_j);
835 <    }
922 >    } else {
923  
924 <    return;
925 <  }  
924 >      // only accumulate the forces and torques resulting from the
925 >      // indirect reaction field terms.
926  
927 <  void Electrostatic::calcSkipCorrection(SkipCorrectionData skdat) {
928 <
929 <    if (!initialized_) initialize();
843 <    
844 <    ElectrostaticAtomData data1 = ElectrostaticMap[skdat.atype1];
845 <    ElectrostaticAtomData data2 = ElectrostaticMap[skdat.atype2];
846 <    
847 <    // logicals
848 <
849 <    bool i_is_Charge = data1.is_Charge;
850 <    bool i_is_Dipole = data1.is_Dipole;
851 <
852 <    bool j_is_Charge = data2.is_Charge;
853 <    bool j_is_Dipole = data2.is_Dipole;
854 <
855 <    RealType q_i, q_j;
856 <    
857 <    // The skippedCharge computation is needed by the real-space cutoff methods
858 <    // (i.e. shifted force and shifted potential)
859 <
860 <    if (i_is_Charge) {
861 <      q_i = data1.charge;
862 <      skdat.skippedCharge2 += q_i;
863 <    }
864 <
865 <    if (j_is_Charge) {
866 <      q_j = data2.charge;
867 <      skdat.skippedCharge1 += q_j;
868 <    }
869 <
870 <    // the rest of this function should only be necessary for reaction field.
871 <
872 <    if (summationMethod_ == REACTION_FIELD) {
873 <      RealType riji, ri2, ri3;
874 <      RealType q_i, mu_i, ct_i;
875 <      RealType q_j, mu_j, ct_j;
876 <      RealType preVal, rfVal, vterm, dudr, pref, myPot;
877 <      Vector3d dVdr, uz_i, uz_j, duduz_i, duduz_j, rhat;
878 <
879 <      // 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        
881      riji = 1.0 / skdat.rij;
882      rhat = skdat.d  * riji;
883
884      if (i_is_Dipole) {
885        mu_i = data1.dipole_moment;
886        uz_i = skdat.eFrame1.getColumn(2);      
887        ct_i = dot(uz_i, rhat);
888        duduz_i = V3Zero;
889      }
890            
891      if (j_is_Dipole) {
892        mu_j = data2.dipole_moment;
893        uz_j = skdat.eFrame2.getColumn(2);      
894        ct_j = dot(uz_j, rhat);
895        duduz_j = V3Zero;
896      }
897    
898      if (i_is_Charge) {
899        if (j_is_Charge) {
900          preVal = skdat.electroMult * pre11_ * q_i * q_j;
901          rfVal = preRF_ * skdat.rij * skdat.rij;
902          vterm = preVal * rfVal;
903          myPot += skdat.sw * vterm;        
904          dudr  = skdat.sw * preVal * 2.0 * rfVal * riji;        
905          dVdr += dudr * rhat;
906        }
907        
908        if (j_is_Dipole) {
909          ri2 = riji * riji;
910          ri3 = ri2 * riji;        
911          pref = skdat.electroMult * pre12_ * q_i * mu_j;
912          vterm = - pref * ct_j * ( ri2 - preRF2_ * skdat.rij );
913          myPot += skdat.sw * vterm;        
914          dVdr += -skdat.sw * pref * ( ri3 * ( uz_j - 3.0 * ct_j * rhat) - preRF2_ * uz_j);
915          duduz_j += -skdat.sw * pref * rhat * (ri2 - preRF2_ * skdat.rij);
916        }
917      }
918      if (i_is_Dipole) {
919        if (j_is_Charge) {
920          ri2 = riji * riji;
921          ri3 = ri2 * riji;        
922          pref = skdat.electroMult * pre12_ * q_j * mu_i;
923          vterm = - pref * ct_i * ( ri2 - preRF2_ * skdat.rij );
924          myPot += skdat.sw * vterm;        
925          dVdr += skdat.sw * pref * ( ri3 * ( uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);      
926          duduz_i += skdat.sw * pref * rhat * (ri2 - preRF2_ * skdat.rij);
927        }
928      }
929      
930      // accumulate the forces and torques resulting from the self term
931      skdat.pot += myPot;
932      skdat.f1 += dVdr;
933      
931        if (i_is_Dipole)
932 <        skdat.t1 -= cross(uz_i, duduz_i);
932 >        *(idat.t1) -= cross(uz_i, indirect_duduz_i);
933        if (j_is_Dipole)
934 <        skdat.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(SelfCorrectionData scdat) {
941 >  void Electrostatic::calcSelfCorrection(SelfData &sdat) {
942      RealType mu1, preVal, chg1, self;
943      
944      if (!initialized_) initialize();
945 <    
946 <    ElectrostaticAtomData data = ElectrostaticMap[scdat.atype];
945 >
946 >    ElectrostaticAtomData data = ElectrostaticMap[sdat.atype];
947    
948      // logicals
949
949      bool i_is_Charge = data.is_Charge;
950      bool i_is_Dipole = data.is_Dipole;
951  
952 <    if (summationMethod_ == REACTION_FIELD) {
952 >    if (summationMethod_ == esm_REACTION_FIELD) {
953        if (i_is_Dipole) {
954          mu1 = data.dipole_moment;          
955          preVal = pre22_ * preRF2_ * mu1 * mu1;
956 <        scdat.pot -= 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 = scdat.eFrame.getColumn(2);
959 >        Vector3d uz_i = sdat.eFrame->getColumn(2);
960          Vector3d ei = preVal * uz_i;
961  
962          // This looks very wrong.  A vector crossed with itself is zero.
963 <        scdat.t -= cross(uz_i, ei);
963 >        *(sdat.t) -= cross(uz_i, ei);
964        }
965 <    } else if (summationMethod_ == SHIFTED_FORCE || summationMethod_ == SHIFTED_POTENTIAL) {
965 >    } else if (summationMethod_ == esm_SHIFTED_FORCE || summationMethod_ == esm_SHIFTED_POTENTIAL) {
966        if (i_is_Charge) {        
967          chg1 = data.charge;
968          if (screeningMethod_ == DAMPED) {
969 <          self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + scdat.skippedCharge) * pre11_;
969 >          self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_;
970          } else {        
971 <          self = - 0.5 * rcuti_ * chg1 * (chg1 + scdat.skippedCharge) * pre11_;
971 >          self = - 0.5 * rcuti_ * chg1 * (chg1 +  *(sdat.skippedCharge)) * pre11_;
972          }
973 <        scdat.pot += self;
973 >        (*(sdat.pot))[ELECTROSTATIC_FAMILY] += self;
974        }
975      }
976    }
977 +
978 +  RealType Electrostatic::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
979 +    // This seems to work moderately well as a default.  There's no
980 +    // inherent scale for 1/r interactions that we can standardize.
981 +    // 12 angstroms seems to be a reasonably good guess for most
982 +    // cases.
983 +    return 12.0;
984 +  }
985   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines