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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines