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 1505 by gezelter, Sun Oct 3 22:18:59 2010 UTC vs.
Revision 1718 by gezelter, Thu May 24 01:29:59 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 > #include "nonbonded/SlaterIntegrals.hpp"
54 > #include "utils/PhysicalConstants.hpp"
55  
56  
57   namespace OpenMD {
58    
59    Electrostatic::Electrostatic(): name_("Electrostatic"), initialized_(false),
60 <                                  forceField_(NULL) {}
60 >                                  forceField_(NULL), info_(NULL),
61 >                                  haveCutoffRadius_(false),
62 >                                  haveDampingAlpha_(false),
63 >                                  haveDielectric_(false),
64 >                                  haveElectroSpline_(false)
65 >  {}
66    
67    void Electrostatic::initialize() {
68 +    
69 +    Globals* simParams_ = info_->getSimParams();
70 +
71 +    summationMap_["HARD"]               = esm_HARD;
72 +    summationMap_["NONE"]               = esm_HARD;
73 +    summationMap_["SWITCHING_FUNCTION"] = esm_SWITCHING_FUNCTION;
74 +    summationMap_["SHIFTED_POTENTIAL"]  = esm_SHIFTED_POTENTIAL;
75 +    summationMap_["SHIFTED_FORCE"]      = esm_SHIFTED_FORCE;    
76 +    summationMap_["REACTION_FIELD"]     = esm_REACTION_FIELD;    
77 +    summationMap_["EWALD_FULL"]         = esm_EWALD_FULL;        
78 +    summationMap_["EWALD_PME"]          = esm_EWALD_PME;        
79 +    summationMap_["EWALD_SPME"]         = esm_EWALD_SPME;        
80 +    screeningMap_["DAMPED"]             = DAMPED;
81 +    screeningMap_["UNDAMPED"]           = UNDAMPED;
82 +
83      // these prefactors convert the multipole interactions into kcal / mol
84      // all were computed assuming distances are measured in angstroms
85      // Charge-Charge, assuming charges are measured in electrons
# Line 79 | Line 104 | namespace OpenMD {
104      
105      // variables to handle different summation methods for long-range
106      // electrostatics:
107 <    summationMethod_ = NONE;    
107 >    summationMethod_ = esm_HARD;    
108      screeningMethod_ = UNDAMPED;
109      dielectric_ = 1.0;
110      one_third_ = 1.0 / 3.0;
86    haveDefaultCutoff_ = false;
87    haveDampingAlpha_ = false;
88    haveDielectric_ = false;  
89    haveElectroSpline_ = false;
111    
112 +    // check the summation method:
113 +    if (simParams_->haveElectrostaticSummationMethod()) {
114 +      string myMethod = simParams_->getElectrostaticSummationMethod();
115 +      toUpper(myMethod);
116 +      map<string, ElectrostaticSummationMethod>::iterator i;
117 +      i = summationMap_.find(myMethod);
118 +      if ( i != summationMap_.end() ) {
119 +        summationMethod_ = (*i).second;
120 +      } else {
121 +        // throw error
122 +        sprintf( painCave.errMsg,
123 +                 "Electrostatic::initialize: Unknown electrostaticSummationMethod.\n"
124 +                 "\t(Input file specified %s .)\n"
125 +                 "\telectrostaticSummationMethod must be one of: \"hard\",\n"
126 +                 "\t\"shifted_potential\", \"shifted_force\", or \n"
127 +                 "\t\"reaction_field\".\n", myMethod.c_str() );
128 +        painCave.isFatal = 1;
129 +        simError();
130 +      }
131 +    } else {
132 +      // set ElectrostaticSummationMethod to the cutoffMethod:
133 +      if (simParams_->haveCutoffMethod()){
134 +        string myMethod = simParams_->getCutoffMethod();
135 +        toUpper(myMethod);
136 +        map<string, ElectrostaticSummationMethod>::iterator i;
137 +        i = summationMap_.find(myMethod);
138 +        if ( i != summationMap_.end() ) {
139 +          summationMethod_ = (*i).second;
140 +        }
141 +      }
142 +    }
143 +    
144 +    if (summationMethod_ == esm_REACTION_FIELD) {        
145 +      if (!simParams_->haveDielectric()) {
146 +        // throw warning
147 +        sprintf( painCave.errMsg,
148 +                 "SimInfo warning: dielectric was not specified in the input file\n\tfor the reaction field correction method.\n"
149 +                 "\tA default value of %f will be used for the dielectric.\n", dielectric_);
150 +        painCave.isFatal = 0;
151 +        painCave.severity = OPENMD_INFO;
152 +        simError();
153 +      } else {
154 +        dielectric_ = simParams_->getDielectric();      
155 +      }
156 +      haveDielectric_ = true;
157 +    }
158 +    
159 +    if (simParams_->haveElectrostaticScreeningMethod()) {
160 +      string myScreen = simParams_->getElectrostaticScreeningMethod();
161 +      toUpper(myScreen);
162 +      map<string, ElectrostaticScreeningMethod>::iterator i;
163 +      i = screeningMap_.find(myScreen);
164 +      if ( i != screeningMap_.end()) {
165 +        screeningMethod_ = (*i).second;
166 +      } else {
167 +        sprintf( painCave.errMsg,
168 +                 "SimInfo error: Unknown electrostaticScreeningMethod.\n"
169 +                 "\t(Input file specified %s .)\n"
170 +                 "\telectrostaticScreeningMethod must be one of: \"undamped\"\n"
171 +                 "or \"damped\".\n", myScreen.c_str() );
172 +        painCave.isFatal = 1;
173 +        simError();
174 +      }
175 +    }
176 +
177 +    // check to make sure a cutoff value has been set:
178 +    if (!haveCutoffRadius_) {
179 +      sprintf( painCave.errMsg, "Electrostatic::initialize has no Default "
180 +               "Cutoff value!\n");
181 +      painCave.severity = OPENMD_ERROR;
182 +      painCave.isFatal = 1;
183 +      simError();
184 +    }
185 +          
186 +    if (screeningMethod_ == DAMPED) {      
187 +      if (!simParams_->haveDampingAlpha()) {
188 +        // first set a cutoff dependent alpha value
189 +        // we assume alpha depends linearly with rcut from 0 to 20.5 ang
190 +        dampingAlpha_ = 0.425 - cutoffRadius_* 0.02;
191 +        if (dampingAlpha_ < 0.0) dampingAlpha_ = 0.0;
192 +        
193 +        // throw warning
194 +        sprintf( painCave.errMsg,
195 +                 "Electrostatic::initialize: dampingAlpha was not specified in the input file.\n"
196 +                 "\tA default value of %f (1/ang) will be used for the cutoff of\n\t%f (ang).\n",
197 +                 dampingAlpha_, cutoffRadius_);
198 +        painCave.severity = OPENMD_INFO;
199 +        painCave.isFatal = 0;
200 +        simError();
201 +      } else {
202 +        dampingAlpha_ = simParams_->getDampingAlpha();
203 +      }
204 +      haveDampingAlpha_ = true;
205 +    }
206 +
207      // find all of the Electrostatic atom Types:
208      ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
209      ForceField::AtomTypeContainer::MapTypeIterator i;
210      AtomType* at;
211 <
211 >    
212      for (at = atomTypes->beginType(i); at != NULL;
213           at = atomTypes->nextType(i)) {
214        
# Line 100 | Line 216 | namespace OpenMD {
216          addType(at);
217      }
218      
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    }
219  
220 <    defaultCutoff2_ = defaultCutoff_ * defaultCutoff_;
221 <    rcuti_ = 1.0 / defaultCutoff_;
220 >    cutoffRadius2_ = cutoffRadius_ * cutoffRadius_;
221 >    rcuti_ = 1.0 / cutoffRadius_;
222      rcuti2_ = rcuti_ * rcuti_;
223      rcuti3_ = rcuti2_ * rcuti_;
224      rcuti4_ = rcuti2_ * rcuti2_;
225  
226      if (screeningMethod_ == DAMPED) {
227 <      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 <
227 >      
228        alpha2_ = dampingAlpha_ * dampingAlpha_;
229        alpha4_ = alpha2_ * alpha2_;
230        alpha6_ = alpha4_ * alpha2_;
231        alpha8_ = alpha4_ * alpha4_;
232        
233 <      constEXP_ = exp(-alpha2_ * defaultCutoff2_);
233 >      constEXP_ = exp(-alpha2_ * cutoffRadius2_);
234        invRootPi_ = 0.56418958354775628695;
235        alphaPi_ = 2.0 * dampingAlpha_ * invRootPi_;
236  
237 <      c1c_ = erfc(dampingAlpha_ * defaultCutoff_) * rcuti_;
237 >      c1c_ = erfc(dampingAlpha_ * cutoffRadius_) * rcuti_;
238        c2c_ = alphaPi_ * constEXP_ * rcuti_ + c1c_ * rcuti_;
239        c3c_ = 2.0 * alphaPi_ * alpha2_ + 3.0 * c2c_ * rcuti_;
240        c4c_ = 4.0 * alphaPi_ * alpha4_ + 5.0 * c3c_ * rcuti2_;
# Line 148 | Line 249 | namespace OpenMD {
249        c6c_ = 9.0 * c5c_ * rcuti2_;
250      }
251    
252 <    if (summationMethod_ == REACTION_FIELD) {
253 <      if (haveDielectric_) {
254 <        preRF_ = (dielectric_ - 1.0) /
255 <            ((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 <      }
252 >    if (summationMethod_ == esm_REACTION_FIELD) {
253 >      preRF_ = (dielectric_ - 1.0) /
254 >        ((2.0 * dielectric_ + 1.0) * cutoffRadius2_ * cutoffRadius_);
255 >      preRF2_ = 2.0 * preRF_;
256      }
257 <                              
258 <    RealType dx = defaultCutoff_ / RealType(np_ - 1);
257 >    
258 >    // Add a 2 angstrom safety window to deal with cutoffGroups that
259 >    // have charged atoms longer than the cutoffRadius away from each
260 >    // other.  Splining may not be the best choice here.  Direct calls
261 >    // to erfc might be preferrable.
262 >
263 >    RealType dx = (cutoffRadius_ + 2.0) / RealType(np_ - 1);
264      RealType rval;
265      vector<RealType> rvals;
266      vector<RealType> yvals;
# Line 186 | Line 284 | namespace OpenMD {
284      electrostaticAtomData.is_SplitDipole = false;
285      electrostaticAtomData.is_Quadrupole = false;
286  
287 <    if (atomType->isCharge()) {
190 <      GenericData* data = atomType->getPropertyByName("Charge");
287 >    FixedChargeAdapter fca = FixedChargeAdapter(atomType);
288  
289 <      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 <      }
289 >    if (fca.isFixedCharge()) {
290        electrostaticAtomData.is_Charge = true;
291 <      electrostaticAtomData.charge = doubleData->getData();          
291 >      electrostaticAtomData.charge = fca.getCharge();
292      }
293  
294 <    if (atomType->isDirectional()) {
295 <      DirectionalAtomType* daType = dynamic_cast<DirectionalAtomType*>(atomType);
296 <      
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 <        }
294 >    MultipoleAdapter ma = MultipoleAdapter(atomType);
295 >    if (ma.isMultipole()) {
296 >      if (ma.isDipole()) {
297          electrostaticAtomData.is_Dipole = true;
298 <        electrostaticAtomData.dipole_moment = doubleData->getData();
298 >        electrostaticAtomData.dipole_moment = ma.getDipoleMoment();
299        }
300 <
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 <        }
300 >      if (ma.isSplitDipole()) {
301          electrostaticAtomData.is_SplitDipole = true;
302 <        electrostaticAtomData.split_dipole_distance = doubleData->getData();
302 >        electrostaticAtomData.split_dipole_distance = ma.getSplitDipoleDistance();
303        }
304 <
273 <      if (daType->isQuadrupole()) {
274 <        GenericData* data = daType->getPropertyByName("QuadrupoleMoments");
275 <        
276 <        if (data == NULL) {
277 <          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 <        
304 >      if (ma.isQuadrupole()) {
305          // Quadrupoles in OpenMD are set as the diagonal elements
306          // of the diagonalized traceless quadrupole moment tensor.
307          // The column vectors of the unitary matrix that diagonalizes
308          // the quadrupole moment tensor become the eFrame (or the
309          // electrostatic version of the body-fixed frame.
291
292        Vector3dGenericData* v3dData = dynamic_cast<Vector3dGenericData*>(data);
293        if (v3dData == NULL) {
294          sprintf( painCave.errMsg,
295                   "Electrostatic::addType could not convert GenericData to "
296                   "Quadrupole Moments for\n"
297                   "\tatom type %s\n", daType->getName().c_str());
298          painCave.severity = OPENMD_ERROR;
299          painCave.isFatal = 1;
300          simError();          
301        }
310          electrostaticAtomData.is_Quadrupole = true;
311 <        electrostaticAtomData.quadrupole_moments = v3dData->getData();
311 >        electrostaticAtomData.quadrupole_moments = ma.getQuadrupoleMoments();
312        }
313      }
314      
315 <    AtomTypeProperties atp = atomType->getATP();    
315 >    FluctuatingChargeAdapter fqa = FluctuatingChargeAdapter(atomType);
316  
317 +    if (fqa.isFluctuatingCharge()) {
318 +      electrostaticAtomData.is_FluctuatingCharge = true;
319 +      electrostaticAtomData.electronegativity = fca.getElectronegativity();
320 +      electrostaticAtomData.hardness = fca.getHardness();
321 +      electrostaticAtomData.slaterN = fca.getSlaterN();
322 +      electrostaticAtomData.slaterZeta = fca.getSlaterZeta();
323 +    }
324 +
325      pair<map<int,AtomType*>::iterator,bool> ret;    
326 <    ret = ElectrostaticList.insert( pair<int,AtomType*>(atp.ident, atomType) );
326 >    ret = ElectrostaticList.insert( pair<int,AtomType*>(atomType->getIdent(),
327 >                                                        atomType) );
328      if (ret.second == false) {
329        sprintf( painCave.errMsg,
330                 "Electrostatic already had a previous entry with ident %d\n",
331 <               atp.ident);
331 >               atomType->getIdent() );
332        painCave.severity = OPENMD_INFO;
333        painCave.isFatal = 0;
334        simError();        
335      }
336      
337 <    ElectrostaticMap[atomType] = electrostaticAtomData;    
337 >    ElectrostaticMap[atomType] = electrostaticAtomData;  
338 >
339 >    // Now, iterate over all known types and add to the mixing map:
340 >    
341 >    map<AtomType*, ElectrostaticAtomData>::iterator it;
342 >    for( it = ElectrostaticMap.begin(); it != ElectrostaticMap.end(); ++it) {
343 >      AtomType* atype2 = (*it).first;
344 >      
345 >      if ((*it).is_FluctuatingCharge && electrostaticAtomData.is_FluctuatingCharge) {
346 >        
347 >        RealType a = electrostaticAtomData.slaterZeta;
348 >        RealType b = (*it).slaterZeta;
349 >        int m = electrostaticAtomData.slaterN;
350 >        int n = (*it).slaterN;
351 >
352 >        // Create the spline of the coulombic integral for s-type
353 >        // Slater orbitals.  Add a 2 angstrom safety window to deal
354 >        // with cutoffGroups that have charged atoms longer than the
355 >        // cutoffRadius away from each other.
356 >
357 >        RealType dr = (cutoffRadius_ + 2.0) / RealType(np_ - 1);
358 >        vector<RealType> rvals;
359 >        vector<RealType> J1vals;
360 >        vector<RealType> J2vals;
361 >        for (int i = 0; i < np_; i++) {
362 >          rval = RealType(i) * dr;
363 >          rvals.push_back(rval);
364 >          J1vals.push_back( sSTOCoulInt( a, b, m, n, rval * PhysicalConstants::angstromsToBohr ) );
365 >          J2vals.push_back( sSTOCoulInt( b, a, n, m, rval * PhysicalConstants::angstromsToBohr ) );
366 >        }
367 >
368 >        CubicSpline J1 = new CubicSpline();
369 >        J1->addPoints(rvals, J1vals);
370 >        CubicSpline J2 = new CubicSpline();
371 >        J2->addPoints(rvals, J2vals);
372 >        
373 >        pair<AtomType*, AtomType*> key1, key2;
374 >        key1 = make_pair(atomType, atype2);
375 >        key2 = make_pair(atype2, atomType);
376 >        
377 >        Jij[key1] = J1;
378 >        Jij[key2] = J2;
379 >      }
380 >    }
381 >
382      return;
383    }
384    
385 <  void Electrostatic::setElectrostaticCutoffRadius( RealType theECR,
386 <                                                    RealType theRSW ) {
387 <    defaultCutoff_ = theECR;
388 <    rrf_ = defaultCutoff_;
328 <    rt_ = theRSW;
329 <    haveDefaultCutoff_ = true;
385 >  void Electrostatic::setCutoffRadius( RealType rCut ) {
386 >    cutoffRadius_ = rCut;
387 >    rrf_ = cutoffRadius_;
388 >    haveCutoffRadius_ = true;
389    }
390 +
391 +  void Electrostatic::setSwitchingRadius( RealType rSwitch ) {
392 +    rt_ = rSwitch;
393 +  }
394    void Electrostatic::setElectrostaticSummationMethod( ElectrostaticSummationMethod esm ) {
395      summationMethod_ = esm;
396    }
# Line 343 | Line 406 | namespace OpenMD {
406      haveDielectric_ = true;
407    }
408  
409 <  void Electrostatic::calcForce(InteractionData idat) {
409 >  void Electrostatic::calcForce(InteractionData &idat) {
410  
411      // utility variables.  Should clean these up and use the Vector3d and
412      // Mat3x3d to replace as many as we can in future versions:
# Line 357 | Line 420 | namespace OpenMD {
420      RealType ct_i, ct_j, ct_ij, a1;
421      RealType riji, ri, ri2, ri3, ri4;
422      RealType pref, vterm, epot, dudr;
423 +    RealType vpair(0.0);
424      RealType scale, sc2;
425      RealType pot_term, preVal, rfVal;
426      RealType c2ri, c3ri, c4rij, cti3, ctj3, ctidotj;
427      RealType preSw, preSwSc;
428      RealType c1, c2, c3, c4;
429 <    RealType erfcVal, derfcVal;
429 >    RealType erfcVal(1.0), derfcVal(0.0);
430      RealType BigR;
431 +    RealType two(2.0), three(3.0);
432  
433      Vector3d Q_i, Q_j;
434      Vector3d ux_i, uy_i, uz_i;
# Line 373 | Line 438 | namespace OpenMD {
438      Vector3d rhatdot2, rhatc4;
439      Vector3d dVdr;
440  
441 +    // variables for indirect (reaction field) interactions for excluded pairs:
442 +    RealType indirect_Pot(0.0);
443 +    RealType indirect_vpair(0.0);
444 +    Vector3d indirect_dVdr(V3Zero);
445 +    Vector3d indirect_duduz_i(V3Zero), indirect_duduz_j(V3Zero);
446 +
447      pair<RealType, RealType> res;
448      
449      if (!initialized_) initialize();
450      
451 <    ElectrostaticAtomData data1 = ElectrostaticMap[idat.atype1];
452 <    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atype2];
451 >    ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first];
452 >    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second];
453      
454      // some variables we'll need independent of electrostatic type:
455  
456 <    riji = 1.0 / idat.rij;
457 <    Vector3d rhat = idat.d  * riji;
456 >    riji = 1.0 /  *(idat.rij) ;
457 >    Vector3d rhat =  *(idat.d)   * riji;
458  
459      // logicals
460  
# Line 397 | Line 468 | namespace OpenMD {
468      bool j_is_SplitDipole = data2.is_SplitDipole;
469      bool j_is_Quadrupole = data2.is_Quadrupole;
470      
471 <    if (i_is_Charge)
471 >    if (i_is_Charge) {
472        q_i = data1.charge;
473 +      if (idat.excluded) {
474 +        *(idat.skippedCharge2) += q_i;
475 +      }
476 +    }
477  
478      if (i_is_Dipole) {
479        mu_i = data1.dipole_moment;
480 <      uz_i = idat.eFrame1.getColumn(2);
480 >      uz_i = idat.eFrame1->getColumn(2);
481        
482        ct_i = dot(uz_i, rhat);
483  
# Line 418 | Line 493 | namespace OpenMD {
493        qyy_i = Q_i.y();
494        qzz_i = Q_i.z();
495        
496 <      ux_i = idat.eFrame1.getColumn(0);
497 <      uy_i = idat.eFrame1.getColumn(1);
498 <      uz_i = idat.eFrame1.getColumn(2);
496 >      ux_i = idat.eFrame1->getColumn(0);
497 >      uy_i = idat.eFrame1->getColumn(1);
498 >      uz_i = idat.eFrame1->getColumn(2);
499  
500        cx_i = dot(ux_i, rhat);
501        cy_i = dot(uy_i, rhat);
# Line 431 | Line 506 | namespace OpenMD {
506        duduz_i = V3Zero;
507      }
508  
509 <    if (j_is_Charge)
509 >    if (j_is_Charge) {
510        q_j = data2.charge;
511 +      if (idat.excluded) {
512 +        *(idat.skippedCharge1) += q_j;
513 +      }
514 +    }
515  
516 +
517      if (j_is_Dipole) {
518        mu_j = data2.dipole_moment;
519 <      uz_j = idat.eFrame2.getColumn(2);
519 >      uz_j = idat.eFrame2->getColumn(2);
520        
521        ct_j = dot(uz_j, rhat);
522  
# Line 452 | Line 532 | namespace OpenMD {
532        qyy_j = Q_j.y();
533        qzz_j = Q_j.z();
534        
535 <      ux_j = idat.eFrame2.getColumn(0);
536 <      uy_j = idat.eFrame2.getColumn(1);
537 <      uz_j = idat.eFrame2.getColumn(2);
535 >      ux_j = idat.eFrame2->getColumn(0);
536 >      uy_j = idat.eFrame2->getColumn(1);
537 >      uz_j = idat.eFrame2->getColumn(2);
538  
539        cx_j = dot(ux_j, rhat);
540        cy_j = dot(uy_j, rhat);
# Line 473 | Line 553 | namespace OpenMD {
553        if (j_is_Charge) {
554          if (screeningMethod_ == DAMPED) {
555            // assemble the damping variables
556 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
557 <          erfcVal = res.first;
558 <          derfcVal = res.second;
556 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
557 >          //erfcVal = res.first;
558 >          //derfcVal = res.second;
559 >
560 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
561 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
562 >
563            c1 = erfcVal * riji;
564            c2 = (-derfcVal + c1) * riji;
565          } else {
# Line 483 | Line 567 | namespace OpenMD {
567            c2 = c1 * riji;
568          }
569  
570 <        preVal = idat.electroMult * pre11_ * q_i * q_j;
570 >        preVal =  *(idat.electroMult) * pre11_ * q_i * q_j;
571          
572 <        if (summationMethod_ == SHIFTED_POTENTIAL) {
572 >        if (summationMethod_ == esm_SHIFTED_POTENTIAL) {
573            vterm = preVal * (c1 - c1c_);
574 <          dudr  = -idat.sw * preVal * c2;
574 >          dudr  = - *(idat.sw)  * preVal * c2;
575  
576 <        } else if (summationMethod_ == SHIFTED_FORCE)  {
577 <          vterm = preVal * ( c1 - c1c_ + c2c_*(idat.rij - defaultCutoff_) );
578 <          dudr  = idat.sw * preVal * (c2c_ - c2);
576 >        } else if (summationMethod_ == esm_SHIFTED_FORCE)  {
577 >          vterm = preVal * ( c1 - c1c_ + c2c_*( *(idat.rij)  - cutoffRadius_) );
578 >          dudr  =  *(idat.sw)  * preVal * (c2c_ - c2);
579  
580 <        } else if (summationMethod_ == REACTION_FIELD) {
581 <          rfVal = idat.electroMult * preRF_ * idat.rij * idat.rij;
580 >        } else if (summationMethod_ == esm_REACTION_FIELD) {
581 >          rfVal = preRF_ *  *(idat.rij)  *  *(idat.rij);
582 >
583            vterm = preVal * ( riji + rfVal );            
584 <          dudr  = idat.sw * preVal * ( 2.0 * rfVal - riji ) * riji;
584 >          dudr  =  *(idat.sw)  * preVal * ( 2.0 * rfVal - riji ) * riji;
585 >          
586 >          // if this is an excluded pair, there are still indirect
587 >          // interactions via the reaction field we must worry about:
588  
589 +          if (idat.excluded) {
590 +            indirect_vpair += preVal * rfVal;
591 +            indirect_Pot += *(idat.sw) * preVal * rfVal;
592 +            indirect_dVdr += *(idat.sw)  * preVal * two * rfVal  * riji * rhat;
593 +          }
594 +          
595          } else {
502          vterm = preVal * riji * erfcVal;            
596  
597 <          dudr  = - idat.sw * preVal * c2;
597 >          vterm = preVal * riji * erfcVal;          
598 >          dudr  = -  *(idat.sw)  * preVal * c2;
599  
600          }
507
508        idat.vpair += vterm;
509        epot += idat.sw * vterm;
601  
602 <        dVdr += dudr * rhat;      
602 >        vpair += vterm;
603 >        epot +=  *(idat.sw)  * vterm;
604 >        dVdr += dudr * rhat;                
605        }
606  
607        if (j_is_Dipole) {
608          // pref is used by all the possible methods
609 <        pref = idat.electroMult * pre12_ * q_i * mu_j;
610 <        preSw = idat.sw * pref;
609 >        pref =  *(idat.electroMult) * pre12_ * q_i * mu_j;
610 >        preSw =  *(idat.sw)  * pref;
611  
612 <        if (summationMethod_ == REACTION_FIELD) {
612 >        if (summationMethod_ == esm_REACTION_FIELD) {
613            ri2 = riji * riji;
614            ri3 = ri2 * riji;
615      
616 <          vterm = - pref * ct_j * ( ri2 - preRF2_ * idat.rij );
617 <          idat.vpair += vterm;
618 <          epot += idat.sw * vterm;
616 >          vterm = - pref * ct_j * ( ri2 - preRF2_ *  *(idat.rij)  );
617 >          vpair += vterm;
618 >          epot +=  *(idat.sw)  * vterm;
619  
620 <          dVdr +=  -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
621 <          duduz_j += -preSw * rhat * (ri2 - preRF2_ * idat.rij);  
620 >          dVdr +=  -preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j);
621 >          duduz_j += -preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );  
622  
623 +          // Even if we excluded this pair from direct interactions,
624 +          // we still have the reaction-field-mediated charge-dipole
625 +          // interaction:
626 +
627 +          if (idat.excluded) {
628 +            indirect_vpair += pref * ct_j * preRF2_ * *(idat.rij);
629 +            indirect_Pot += preSw * ct_j * preRF2_ * *(idat.rij);
630 +            indirect_dVdr += preSw * preRF2_ * uz_j;
631 +            indirect_duduz_j += preSw * rhat * preRF2_ *  *(idat.rij);
632 +          }
633 +                      
634          } else {
635            // determine the inverse r used if we have split dipoles
636            if (j_is_SplitDipole) {
637 <            BigR = sqrt(idat.r2 + 0.25 * d_j * d_j);
637 >            BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j);
638              ri = 1.0 / BigR;
639 <            scale = idat.rij * ri;
639 >            scale =  *(idat.rij)  * ri;
640            } else {
641              ri = riji;
642              scale = 1.0;
# Line 542 | Line 646 | namespace OpenMD {
646  
647            if (screeningMethod_ == DAMPED) {
648              // assemble the damping variables
649 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
650 <            erfcVal = res.first;
651 <            derfcVal = res.second;
649 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
650 >            //erfcVal = res.first;
651 >            //derfcVal = res.second;
652 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
653 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
654              c1 = erfcVal * ri;
655              c2 = (-derfcVal + c1) * ri;
656              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 559 | Line 665 | namespace OpenMD {
665            // calculate the potential
666            pot_term =  scale * c2;
667            vterm = -pref * ct_j * pot_term;
668 <          idat.vpair += vterm;
669 <          epot += idat.sw * vterm;
668 >          vpair += vterm;
669 >          epot +=  *(idat.sw)  * vterm;
670              
671            // calculate derivatives for forces and torques
672  
# Line 575 | Line 681 | namespace OpenMD {
681          cx2 = cx_j * cx_j;
682          cy2 = cy_j * cy_j;
683          cz2 = cz_j * cz_j;
684 <        pref =  idat.electroMult * pre14_ * q_i * one_third_;
684 >        pref =   *(idat.electroMult) * pre14_ * q_i * one_third_;
685            
686          if (screeningMethod_ == DAMPED) {
687            // assemble the damping variables
688 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
689 <          erfcVal = res.first;
690 <          derfcVal = res.second;
688 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
689 >          //erfcVal = res.first;
690 >          //derfcVal = res.second;
691 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
692 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
693            c1 = erfcVal * riji;
694            c2 = (-derfcVal + c1) * riji;
695            c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji;
# Line 594 | Line 702 | namespace OpenMD {
702          }
703  
704          // precompute variables for convenience
705 <        preSw = idat.sw * pref;
705 >        preSw =  *(idat.sw)  * pref;
706          c2ri = c2 * riji;
707          c3ri = c3 * riji;
708 <        c4rij = c4 * idat.rij;
709 <        rhatdot2 = 2.0 * rhat * c3;
708 >        c4rij = c4 *  *(idat.rij) ;
709 >        rhatdot2 = two * rhat * c3;
710          rhatc4 = rhat * c4rij;
711  
712          // calculate the potential
# Line 606 | Line 714 | namespace OpenMD {
714                       qyy_j * (cy2*c3 - c2ri) +
715                       qzz_j * (cz2*c3 - c2ri) );
716          vterm = pref * pot_term;
717 <        idat.vpair += vterm;
718 <        epot += idat.sw * vterm;
717 >        vpair += vterm;
718 >        epot +=  *(idat.sw)  * vterm;
719                  
720          // calculate derivatives for the forces and torques
721  
722 <        dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (2.0*cx_j*ux_j + rhat)*c3ri) +
723 <                           qyy_j* (cy2*rhatc4 - (2.0*cy_j*uy_j + rhat)*c3ri) +
724 <                           qzz_j* (cz2*rhatc4 - (2.0*cz_j*uz_j + rhat)*c3ri));
722 >        dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (two*cx_j*ux_j + rhat)*c3ri) +
723 >                           qyy_j* (cy2*rhatc4 - (two*cy_j*uy_j + rhat)*c3ri) +
724 >                           qzz_j* (cz2*rhatc4 - (two*cz_j*uz_j + rhat)*c3ri));
725                            
726          dudux_j += preSw * qxx_j * cx_j * rhatdot2;
727          duduy_j += preSw * qyy_j * cy_j * rhatdot2;
# Line 625 | Line 733 | namespace OpenMD {
733  
734        if (j_is_Charge) {
735          // variables used by all the methods
736 <        pref = idat.electroMult * pre12_ * q_j * mu_i;
737 <        preSw = idat.sw * pref;
736 >        pref =  *(idat.electroMult) * pre12_ * q_j * mu_i;
737 >        preSw =  *(idat.sw)  * pref;
738  
739 <        if (summationMethod_ == REACTION_FIELD) {
739 >        if (summationMethod_ == esm_REACTION_FIELD) {
740  
741            ri2 = riji * riji;
742            ri3 = ri2 * riji;
743  
744 <          vterm = pref * ct_i * ( ri2 - preRF2_ * idat.rij );
745 <          idat.vpair += vterm;
746 <          epot += idat.sw * vterm;
744 >          vterm = pref * ct_i * ( ri2 - preRF2_ *  *(idat.rij)  );
745 >          vpair += vterm;
746 >          epot +=  *(idat.sw)  * vterm;
747            
748 <          dVdr += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);
748 >          dVdr += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_ * uz_i);
749            
750 <          duduz_i += preSw * rhat * (ri2 - preRF2_ * idat.rij);
750 >          duduz_i += preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );
751 >
752 >          // Even if we excluded this pair from direct interactions,
753 >          // we still have the reaction-field-mediated charge-dipole
754 >          // interaction:
755 >
756 >          if (idat.excluded) {
757 >            indirect_vpair += -pref * ct_i * preRF2_ * *(idat.rij);
758 >            indirect_Pot += -preSw * ct_i * preRF2_ * *(idat.rij);
759 >            indirect_dVdr += -preSw * preRF2_ * uz_i;
760 >            indirect_duduz_i += -preSw * rhat * preRF2_ *  *(idat.rij);
761 >          }
762              
763          } else {
764            
765            // determine inverse r if we are using split dipoles
766            if (i_is_SplitDipole) {
767 <            BigR = sqrt(idat.r2 + 0.25 * d_i * d_i);
767 >            BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i);
768              ri = 1.0 / BigR;
769 <            scale = idat.rij * ri;
769 >            scale =  *(idat.rij)  * ri;
770            } else {
771              ri = riji;
772              scale = 1.0;
# Line 657 | Line 776 | namespace OpenMD {
776              
777            if (screeningMethod_ == DAMPED) {
778              // assemble the damping variables
779 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
780 <            erfcVal = res.first;
781 <            derfcVal = res.second;
779 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
780 >            //erfcVal = res.first;
781 >            //derfcVal = res.second;
782 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
783 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
784              c1 = erfcVal * ri;
785              c2 = (-derfcVal + c1) * ri;
786              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 674 | Line 795 | namespace OpenMD {
795            // calculate the potential
796            pot_term = c2 * scale;
797            vterm = pref * ct_i * pot_term;
798 <          idat.vpair += vterm;
799 <          epot += idat.sw * vterm;
798 >          vpair += vterm;
799 >          epot +=  *(idat.sw)  * vterm;
800  
801            // calculate derivatives for the forces and torques
802            dVdr += preSw * (uz_i * c2ri - ct_i * rhat * sc2 * c3);
# Line 687 | Line 808 | namespace OpenMD {
808          // variables used by all methods
809          ct_ij = dot(uz_i, uz_j);
810  
811 <        pref = idat.electroMult * pre22_ * mu_i * mu_j;
812 <        preSw = idat.sw * pref;
811 >        pref =  *(idat.electroMult) * pre22_ * mu_i * mu_j;
812 >        preSw =  *(idat.sw)  * pref;
813  
814 <        if (summationMethod_ == REACTION_FIELD) {
814 >        if (summationMethod_ == esm_REACTION_FIELD) {
815            ri2 = riji * riji;
816            ri3 = ri2 * riji;
817            ri4 = ri2 * ri2;
818  
819            vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) -
820                             preRF2_ * ct_ij );
821 <          idat.vpair += vterm;
822 <          epot += idat.sw * vterm;
821 >          vpair += vterm;
822 >          epot +=  *(idat.sw)  * vterm;
823              
824            a1 = 5.0 * ct_i * ct_j - ct_ij;
825              
826 <          dVdr += preSw * 3.0 * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i);
826 >          dVdr += preSw * three * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i);
827  
828 <          duduz_i += preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
829 <          duduz_j += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_*uz_i);
828 >          duduz_i += preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j);
829 >          duduz_j += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_*uz_i);
830  
831 +          if (idat.excluded) {
832 +            indirect_vpair +=  - pref * preRF2_ * ct_ij;
833 +            indirect_Pot +=    - preSw * preRF2_ * ct_ij;
834 +            indirect_duduz_i += -preSw * preRF2_ * uz_j;
835 +            indirect_duduz_j += -preSw * preRF2_ * uz_i;
836 +          }
837 +
838          } else {
839            
840            if (i_is_SplitDipole) {
841              if (j_is_SplitDipole) {
842 <              BigR = sqrt(idat.r2 + 0.25 * d_i * d_i + 0.25 * d_j * d_j);
842 >              BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i + 0.25 * d_j * d_j);
843              } else {
844 <              BigR = sqrt(idat.r2 + 0.25 * d_i * d_i);
844 >              BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i);
845              }
846              ri = 1.0 / BigR;
847 <            scale = idat.rij * ri;
847 >            scale =  *(idat.rij)  * ri;
848            } else {
849              if (j_is_SplitDipole) {
850 <              BigR = sqrt(idat.r2 + 0.25 * d_j * d_j);
850 >              BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j);
851                ri = 1.0 / BigR;
852 <              scale = idat.rij * ri;
852 >              scale =  *(idat.rij)  * ri;
853              } else {
854                ri = riji;
855                scale = 1.0;
# Line 729 | Line 857 | namespace OpenMD {
857            }
858            if (screeningMethod_ == DAMPED) {
859              // assemble damping variables
860 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
861 <            erfcVal = res.first;
862 <            derfcVal = res.second;
860 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
861 >            //erfcVal = res.first;
862 >            //derfcVal = res.second;
863 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
864 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
865              c1 = erfcVal * ri;
866              c2 = (-derfcVal + c1) * ri;
867              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 751 | Line 881 | namespace OpenMD {
881            preSwSc = preSw * scale;
882            c2ri = c2 * ri;
883            c3ri = c3 * ri;
884 <          c4rij = c4 * idat.rij;
884 >          c4rij = c4 *  *(idat.rij) ;
885  
886            // calculate the potential
887            pot_term = (ct_ij * c2ri - ctidotj * c3);
888            vterm = pref * pot_term;
889 <          idat.vpair += vterm;
890 <          epot += idat.sw * vterm;
889 >          vpair += vterm;
890 >          epot +=  *(idat.sw)  * vterm;
891  
892            // calculate derivatives for the forces and torques
893            dVdr += preSwSc * ( ctidotj * rhat * c4rij  -
# Line 776 | Line 906 | namespace OpenMD {
906          cy2 = cy_i * cy_i;
907          cz2 = cz_i * cz_i;
908  
909 <        pref = idat.electroMult * pre14_ * q_j * one_third_;
909 >        pref =  *(idat.electroMult) * pre14_ * q_j * one_third_;
910  
911          if (screeningMethod_ == DAMPED) {
912            // assemble the damping variables
913 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
914 <          erfcVal = res.first;
915 <          derfcVal = res.second;
913 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
914 >          //erfcVal = res.first;
915 >          //derfcVal = res.second;
916 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
917 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
918            c1 = erfcVal * riji;
919            c2 = (-derfcVal + c1) * riji;
920            c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji;
# Line 795 | Line 927 | namespace OpenMD {
927          }
928            
929          // precompute some variables for convenience
930 <        preSw = idat.sw * pref;
930 >        preSw =  *(idat.sw)  * pref;
931          c2ri = c2 * riji;
932          c3ri = c3 * riji;
933 <        c4rij = c4 * idat.rij;
934 <        rhatdot2 = 2.0 * rhat * c3;
933 >        c4rij = c4 *  *(idat.rij) ;
934 >        rhatdot2 = two * rhat * c3;
935          rhatc4 = rhat * c4rij;
936  
937          // calculate the potential
# Line 808 | Line 940 | namespace OpenMD {
940                       qzz_i * (cz2 * c3 - c2ri) );
941          
942          vterm = pref * pot_term;
943 <        idat.vpair += vterm;
944 <        epot += idat.sw * vterm;
943 >        vpair += vterm;
944 >        epot +=  *(idat.sw)  * vterm;
945  
946          // calculate the derivatives for the forces and torques
947  
948 <        dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (2.0*cx_i*ux_i + rhat)*c3ri) +
949 <                          qyy_i* (cy2*rhatc4 - (2.0*cy_i*uy_i + rhat)*c3ri) +
950 <                          qzz_i* (cz2*rhatc4 - (2.0*cz_i*uz_i + rhat)*c3ri));
948 >        dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (two*cx_i*ux_i + rhat)*c3ri) +
949 >                          qyy_i* (cy2*rhatc4 - (two*cy_i*uy_i + rhat)*c3ri) +
950 >                          qzz_i* (cz2*rhatc4 - (two*cz_i*uz_i + rhat)*c3ri));
951  
952          dudux_i += preSw * qxx_i * cx_i *  rhatdot2;
953          duduy_i += preSw * qyy_i * cy_i *  rhatdot2;
# Line 823 | Line 955 | namespace OpenMD {
955        }
956      }
957  
826    idat.pot += epot;
827    idat.f1 += dVdr;
958  
959 <    if (i_is_Dipole || i_is_Quadrupole)
960 <      idat.t1 -= cross(uz_i, duduz_i);
961 <    if (i_is_Quadrupole) {
962 <      idat.t1 -= cross(ux_i, dudux_i);
963 <      idat.t1 -= cross(uy_i, duduy_i);
964 <    }
959 >    if (!idat.excluded) {
960 >      *(idat.vpair) += vpair;
961 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += epot;
962 >      *(idat.f1) += dVdr;
963 >      
964 >      if (i_is_Dipole || i_is_Quadrupole)
965 >        *(idat.t1) -= cross(uz_i, duduz_i);
966 >      if (i_is_Quadrupole) {
967 >        *(idat.t1) -= cross(ux_i, dudux_i);
968 >        *(idat.t1) -= cross(uy_i, duduy_i);
969 >      }
970 >      
971 >      if (j_is_Dipole || j_is_Quadrupole)
972 >        *(idat.t2) -= cross(uz_j, duduz_j);
973 >      if (j_is_Quadrupole) {
974 >        *(idat.t2) -= cross(uz_j, dudux_j);
975 >        *(idat.t2) -= cross(uz_j, duduy_j);
976 >      }
977  
978 <    if (j_is_Dipole || j_is_Quadrupole)
837 <      idat.t2 -= cross(uz_j, duduz_j);
838 <    if (j_is_Quadrupole) {
839 <      idat.t2 -= cross(uz_j, dudux_j);
840 <      idat.t2 -= cross(uz_j, duduy_j);
841 <    }
978 >    } else {
979  
980 <    return;
981 <  }  
980 >      // only accumulate the forces and torques resulting from the
981 >      // indirect reaction field terms.
982  
983 <  void Electrostatic::calcSkipCorrection(SkipCorrectionData skdat) {
984 <
985 <    if (!initialized_) initialize();
849 <    
850 <    ElectrostaticAtomData data1 = ElectrostaticMap[skdat.atype1];
851 <    ElectrostaticAtomData data2 = ElectrostaticMap[skdat.atype2];
852 <    
853 <    // logicals
854 <
855 <    bool i_is_Charge = data1.is_Charge;
856 <    bool i_is_Dipole = data1.is_Dipole;
857 <
858 <    bool j_is_Charge = data2.is_Charge;
859 <    bool j_is_Dipole = data2.is_Dipole;
860 <
861 <    RealType q_i, q_j;
862 <    
863 <    // The skippedCharge computation is needed by the real-space cutoff methods
864 <    // (i.e. shifted force and shifted potential)
865 <
866 <    if (i_is_Charge) {
867 <      q_i = data1.charge;
868 <      skdat.skippedCharge2 += q_i;
869 <    }
870 <
871 <    if (j_is_Charge) {
872 <      q_j = data2.charge;
873 <      skdat.skippedCharge1 += q_j;
874 <    }
875 <
876 <    // the rest of this function should only be necessary for reaction field.
877 <
878 <    if (summationMethod_ == REACTION_FIELD) {
879 <      RealType riji, ri2, ri3;
880 <      RealType q_i, mu_i, ct_i;
881 <      RealType q_j, mu_j, ct_j;
882 <      RealType preVal, rfVal, vterm, dudr, pref, myPot;
883 <      Vector3d dVdr, uz_i, uz_j, duduz_i, duduz_j, rhat;
884 <
885 <      // some variables we'll need independent of electrostatic type:
983 >      *(idat.vpair) += indirect_vpair;
984 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot;
985 >      *(idat.f1) += indirect_dVdr;
986        
887      riji = 1.0 / skdat.rij;
888      rhat = skdat.d  * riji;
889
890      if (i_is_Dipole) {
891        mu_i = data1.dipole_moment;
892        uz_i = skdat.eFrame1.getColumn(2);      
893        ct_i = dot(uz_i, rhat);
894        duduz_i = V3Zero;
895      }
896            
897      if (j_is_Dipole) {
898        mu_j = data2.dipole_moment;
899        uz_j = skdat.eFrame2.getColumn(2);      
900        ct_j = dot(uz_j, rhat);
901        duduz_j = V3Zero;
902      }
903    
904      if (i_is_Charge) {
905        if (j_is_Charge) {
906          preVal = skdat.electroMult * pre11_ * q_i * q_j;
907          rfVal = preRF_ * skdat.rij * skdat.rij;
908          vterm = preVal * rfVal;
909          myPot += skdat.sw * vterm;        
910          dudr  = skdat.sw * preVal * 2.0 * rfVal * riji;        
911          dVdr += dudr * rhat;
912        }
913        
914        if (j_is_Dipole) {
915          ri2 = riji * riji;
916          ri3 = ri2 * riji;        
917          pref = skdat.electroMult * pre12_ * q_i * mu_j;
918          vterm = - pref * ct_j * ( ri2 - preRF2_ * skdat.rij );
919          myPot += skdat.sw * vterm;        
920          dVdr += -skdat.sw * pref * ( ri3 * ( uz_j - 3.0 * ct_j * rhat) - preRF2_ * uz_j);
921          duduz_j += -skdat.sw * pref * rhat * (ri2 - preRF2_ * skdat.rij);
922        }
923      }
924      if (i_is_Dipole) {
925        if (j_is_Charge) {
926          ri2 = riji * riji;
927          ri3 = ri2 * riji;        
928          pref = skdat.electroMult * pre12_ * q_j * mu_i;
929          vterm = - pref * ct_i * ( ri2 - preRF2_ * skdat.rij );
930          myPot += skdat.sw * vterm;        
931          dVdr += skdat.sw * pref * ( ri3 * ( uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);      
932          duduz_i += skdat.sw * pref * rhat * (ri2 - preRF2_ * skdat.rij);
933        }
934      }
935      
936      // accumulate the forces and torques resulting from the self term
937      skdat.pot += myPot;
938      skdat.f1 += dVdr;
939      
987        if (i_is_Dipole)
988 <        skdat.t1 -= cross(uz_i, duduz_i);
988 >        *(idat.t1) -= cross(uz_i, indirect_duduz_i);
989        if (j_is_Dipole)
990 <        skdat.t2 -= cross(uz_j, duduz_j);
990 >        *(idat.t2) -= cross(uz_j, indirect_duduz_j);
991      }
992 <  }
992 >
993 >
994 >    return;
995 >  }  
996      
997 <  void Electrostatic::calcSelfCorrection(SelfCorrectionData scdat) {
997 >  void Electrostatic::calcSelfCorrection(SelfData &sdat) {
998      RealType mu1, preVal, chg1, self;
999      
1000      if (!initialized_) initialize();
1001 <    
1002 <    ElectrostaticAtomData data = ElectrostaticMap[scdat.atype];
1001 >
1002 >    ElectrostaticAtomData data = ElectrostaticMap[sdat.atype];
1003    
1004      // logicals
955
1005      bool i_is_Charge = data.is_Charge;
1006      bool i_is_Dipole = data.is_Dipole;
1007  
1008 <    if (summationMethod_ == REACTION_FIELD) {
1008 >    if (summationMethod_ == esm_REACTION_FIELD) {
1009        if (i_is_Dipole) {
1010          mu1 = data.dipole_moment;          
1011          preVal = pre22_ * preRF2_ * mu1 * mu1;
1012 <        scdat.pot -= 0.5 * preVal;
1012 >        (*(sdat.pot))[ELECTROSTATIC_FAMILY] -= 0.5 * preVal;
1013          
1014          // The self-correction term adds into the reaction field vector
1015 <        Vector3d uz_i = scdat.eFrame.getColumn(2);
1015 >        Vector3d uz_i = sdat.eFrame->getColumn(2);
1016          Vector3d ei = preVal * uz_i;
1017  
1018          // This looks very wrong.  A vector crossed with itself is zero.
1019 <        scdat.t -= cross(uz_i, ei);
1019 >        *(sdat.t) -= cross(uz_i, ei);
1020        }
1021 <    } else if (summationMethod_ == SHIFTED_FORCE || summationMethod_ == SHIFTED_POTENTIAL) {
1021 >    } else if (summationMethod_ == esm_SHIFTED_FORCE || summationMethod_ == esm_SHIFTED_POTENTIAL) {
1022        if (i_is_Charge) {        
1023          chg1 = data.charge;
1024          if (screeningMethod_ == DAMPED) {
1025 <          self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + scdat.skippedCharge) * pre11_;
1025 >          self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_;
1026          } else {        
1027 <          self = - 0.5 * rcuti_ * chg1 * (chg1 + scdat.skippedCharge) * pre11_;
1027 >          self = - 0.5 * rcuti_ * chg1 * (chg1 +  *(sdat.skippedCharge)) * pre11_;
1028          }
1029 <        scdat.pot += self;
1029 >        (*(sdat.pot))[ELECTROSTATIC_FAMILY] += self;
1030        }
1031      }
1032    }
1033  
1034 <  RealType Electrostatic::getSuggestedCutoffRadius(AtomType* at1, AtomType* at2) {
1034 >  RealType Electrostatic::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
1035      // This seems to work moderately well as a default.  There's no
1036      // inherent scale for 1/r interactions that we can standardize.
1037      // 12 angstroms seems to be a reasonably good guess for most

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines