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 1535 by gezelter, Fri Dec 31 18:31:56 2010 UTC vs.
Revision 1721 by gezelter, Thu May 24 14:17:42 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  
59    Globals* simParams_;
60
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;    
# Line 97 | Line 109 | namespace OpenMD {
109      screeningMethod_ = UNDAMPED;
110      dielectric_ = 1.0;
111      one_third_ = 1.0 / 3.0;
100    haveCutoffRadius_ = false;
101    haveDampingAlpha_ = false;
102    haveDielectric_ = false;  
103    haveElectroSpline_ = false;
112    
113      // check the summation method:
114      if (simParams_->haveElectrostaticSummationMethod()) {
# Line 113 | Line 121 | namespace OpenMD {
121        } else {
122          // throw error
123          sprintf( painCave.errMsg,
124 <                 "SimInfo error: Unknown electrostaticSummationMethod.\n"
124 >                 "Electrostatic::initialize: Unknown electrostaticSummationMethod.\n"
125                   "\t(Input file specified %s .)\n"
126 <                 "\telectrostaticSummationMethod must be one of: \"none\",\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;
# Line 248 | Line 256 | namespace OpenMD {
256        preRF2_ = 2.0 * preRF_;
257      }
258      
259 <    RealType dx = cutoffRadius_ / RealType(np_ - 1);
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 272 | Line 285 | namespace OpenMD {
285      electrostaticAtomData.is_SplitDipole = false;
286      electrostaticAtomData.is_Quadrupole = false;
287  
288 <    if (atomType->isCharge()) {
276 <      GenericData* data = atomType->getPropertyByName("Charge");
288 >    FixedChargeAdapter fca = FixedChargeAdapter(atomType);
289  
290 <      if (data == NULL) {
279 <        sprintf( painCave.errMsg, "Electrostatic::addType could not find "
280 <                 "Charge\n"
281 <                 "\tparameters for atomType %s.\n",
282 <                 atomType->getName().c_str());
283 <        painCave.severity = OPENMD_ERROR;
284 <        painCave.isFatal = 1;
285 <        simError();                  
286 <      }
287 <      
288 <      DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
289 <      if (doubleData == NULL) {
290 <        sprintf( painCave.errMsg,
291 <                 "Electrostatic::addType could not convert GenericData to "
292 <                 "Charge for\n"
293 <                 "\tatom type %s\n", atomType->getName().c_str());
294 <        painCave.severity = OPENMD_ERROR;
295 <        painCave.isFatal = 1;
296 <        simError();          
297 <      }
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 <      
305 <      if (daType->isDipole()) {
306 <        GenericData* data = daType->getPropertyByName("Dipole");
307 <        
308 <        if (data == NULL) {
309 <          sprintf( painCave.errMsg,
310 <                   "Electrostatic::addType could not find Dipole\n"
311 <                   "\tparameters for atomType %s.\n",
312 <                   daType->getName().c_str());
313 <          painCave.severity = OPENMD_ERROR;
314 <          painCave.isFatal = 1;
315 <          simError();                  
316 <        }
317 <      
318 <        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
319 <        if (doubleData == NULL) {
320 <          sprintf( painCave.errMsg,
321 <                   "Electrostatic::addType could not convert GenericData to "
322 <                   "Dipole Moment\n"
323 <                   "\tfor atom type %s\n", daType->getName().c_str());
324 <          painCave.severity = OPENMD_ERROR;
325 <          painCave.isFatal = 1;
326 <          simError();          
327 <        }
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 <
332 <      if (daType->isSplitDipole()) {
333 <        GenericData* data = daType->getPropertyByName("SplitDipoleDistance");
334 <        
335 <        if (data == NULL) {
336 <          sprintf(painCave.errMsg,
337 <                  "Electrostatic::addType could not find SplitDipoleDistance\n"
338 <                  "\tparameter for atomType %s.\n",
339 <                  daType->getName().c_str());
340 <          painCave.severity = OPENMD_ERROR;
341 <          painCave.isFatal = 1;
342 <          simError();                  
343 <        }
344 <      
345 <        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
346 <        if (doubleData == NULL) {
347 <          sprintf( painCave.errMsg,
348 <                   "Electrostatic::addType could not convert GenericData to "
349 <                   "SplitDipoleDistance for\n"
350 <                   "\tatom type %s\n", daType->getName().c_str());
351 <          painCave.severity = OPENMD_ERROR;
352 <          painCave.isFatal = 1;
353 <          simError();          
354 <        }
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 <
359 <      if (daType->isQuadrupole()) {
360 <        GenericData* data = daType->getPropertyByName("QuadrupoleMoments");
361 <        
362 <        if (data == NULL) {
363 <          sprintf( painCave.errMsg,
364 <                   "Electrostatic::addType could not find QuadrupoleMoments\n"
365 <                   "\tparameter for atomType %s.\n",
366 <                   daType->getName().c_str());
367 <          painCave.severity = OPENMD_ERROR;
368 <          painCave.isFatal = 1;
369 <          simError();                  
370 <        }
371 <        
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.
377
378        Vector3dGenericData* v3dData = dynamic_cast<Vector3dGenericData*>(data);
379        if (v3dData == NULL) {
380          sprintf( painCave.errMsg,
381                   "Electrostatic::addType could not convert GenericData to "
382                   "Quadrupole Moments for\n"
383                   "\tatom type %s\n", daType->getName().c_str());
384          painCave.severity = OPENMD_ERROR;
385          painCave.isFatal = 1;
386          simError();          
387        }
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 +    } else {
325 +      electrostaticAtomData.is_Fluctuating = false;
326 +    }
327 +
328      pair<map<int,AtomType*>::iterator,bool> ret;    
329 <    ret = ElectrostaticList.insert( pair<int,AtomType*>(atp.ident, atomType) );
329 >    ret = ElectrostaticList.insert( pair<int,AtomType*>(atomType->getIdent(),
330 >                                                        atomType) );
331      if (ret.second == false) {
332        sprintf( painCave.errMsg,
333                 "Electrostatic already had a previous entry with ident %d\n",
334 <               atp.ident);
334 >               atomType->getIdent() );
335        painCave.severity = OPENMD_INFO;
336        painCave.isFatal = 0;
337        simError();        
338      }
339      
340 <    ElectrostaticMap[atomType] = electrostaticAtomData;    
340 >    ElectrostaticMap[atomType] = electrostaticAtomData;  
341 >
342 >    // Now, iterate over all known types and add to the mixing map:
343 >    
344 >    map<AtomType*, ElectrostaticAtomData>::iterator it;
345 >    for( it = ElectrostaticMap.begin(); it != ElectrostaticMap.end(); ++it) {
346 >      AtomType* atype2 = (*it).first;
347 >      ElectrostaticAtomData eaData2 = (*it).second;
348 >      if (eaData2.is_Fluctuating && electrostaticAtomData.is_Fluctuating) {
349 >        
350 >        RealType a = electrostaticAtomData.slaterZeta;
351 >        RealType b = eaData2.slaterZeta;
352 >        int m = electrostaticAtomData.slaterN;
353 >        int n = eaData2.slaterN;
354 >
355 >        // Create the spline of the coulombic integral for s-type
356 >        // Slater orbitals.  Add a 2 angstrom safety window to deal
357 >        // with cutoffGroups that have charged atoms longer than the
358 >        // cutoffRadius away from each other.
359 >
360 >        RealType rval;
361 >        RealType dr = (cutoffRadius_ + 2.0) / RealType(np_ - 1);
362 >        vector<RealType> rvals;
363 >        vector<RealType> J1vals;
364 >        vector<RealType> J2vals;
365 >        for (int i = 0; i < np_; i++) {
366 >          rval = RealType(i) * dr;
367 >          rvals.push_back(rval);
368 >          J1vals.push_back( sSTOCoulInt( a, b, m, n, rval * PhysicalConstants::angstromsToBohr ) );
369 >          // may not be necessary if Slater coulomb integral is symmetric
370 >          J2vals.push_back( sSTOCoulInt( b, a, n, m, rval * PhysicalConstants::angstromsToBohr ) );
371 >        }
372 >
373 >        CubicSpline* J1 = new CubicSpline();
374 >        J1->addPoints(rvals, J1vals);
375 >        CubicSpline* J2 = new CubicSpline();
376 >        J2->addPoints(rvals, J2vals);
377 >        
378 >        pair<AtomType*, AtomType*> key1, key2;
379 >        key1 = make_pair(atomType, atype2);
380 >        key2 = make_pair(atype2, atomType);
381 >        
382 >        Jij[key1] = J1;
383 >        Jij[key2] = J2;
384 >      }
385 >    }
386 >
387      return;
388    }
389    
390 <  void Electrostatic::setElectrostaticCutoffRadius( RealType theECR,
391 <                                                    RealType theRSW ) {
412 <    cutoffRadius_ = theECR;
390 >  void Electrostatic::setCutoffRadius( RealType rCut ) {
391 >    cutoffRadius_ = rCut;
392      rrf_ = cutoffRadius_;
414    rt_ = theRSW;
393      haveCutoffRadius_ = true;
394    }
395 +
396 +  void Electrostatic::setSwitchingRadius( RealType rSwitch ) {
397 +    rt_ = rSwitch;
398 +  }
399    void Electrostatic::setElectrostaticSummationMethod( ElectrostaticSummationMethod esm ) {
400      summationMethod_ = esm;
401    }
# Line 429 | Line 411 | namespace OpenMD {
411      haveDielectric_ = true;
412    }
413  
414 <  void Electrostatic::calcForce(InteractionData idat) {
414 >  void Electrostatic::calcForce(InteractionData &idat) {
415  
416      // utility variables.  Should clean these up and use the Vector3d and
417      // Mat3x3d to replace as many as we can in future versions:
# Line 443 | Line 425 | namespace OpenMD {
425      RealType ct_i, ct_j, ct_ij, a1;
426      RealType riji, ri, ri2, ri3, ri4;
427      RealType pref, vterm, epot, dudr;
428 +    RealType vpair(0.0);
429      RealType scale, sc2;
430      RealType pot_term, preVal, rfVal;
431      RealType c2ri, c3ri, c4rij, cti3, ctj3, ctidotj;
432      RealType preSw, preSwSc;
433      RealType c1, c2, c3, c4;
434 <    RealType erfcVal, derfcVal;
434 >    RealType erfcVal(1.0), derfcVal(0.0);
435      RealType BigR;
436 +    RealType two(2.0), three(3.0);
437  
438      Vector3d Q_i, Q_j;
439      Vector3d ux_i, uy_i, uz_i;
# Line 459 | Line 443 | namespace OpenMD {
443      Vector3d rhatdot2, rhatc4;
444      Vector3d dVdr;
445  
446 +    // variables for indirect (reaction field) interactions for excluded pairs:
447 +    RealType indirect_Pot(0.0);
448 +    RealType indirect_vpair(0.0);
449 +    Vector3d indirect_dVdr(V3Zero);
450 +    Vector3d indirect_duduz_i(V3Zero), indirect_duduz_j(V3Zero);
451 +
452      pair<RealType, RealType> res;
453      
454 +    // splines for coulomb integrals
455 +    CubicSpline* J1;
456 +    CubicSpline* J2;
457 +    
458      if (!initialized_) initialize();
459      
460 <    ElectrostaticAtomData data1 = ElectrostaticMap[idat.atype1];
461 <    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atype2];
460 >    ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first];
461 >    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second];
462      
463      // some variables we'll need independent of electrostatic type:
464  
465 <    riji = 1.0 / idat.rij;
466 <    Vector3d rhat = idat.d  * riji;
465 >    riji = 1.0 /  *(idat.rij) ;
466 >    Vector3d rhat =  *(idat.d)   * riji;
467  
468      // logicals
469  
# Line 477 | Line 471 | namespace OpenMD {
471      bool i_is_Dipole = data1.is_Dipole;
472      bool i_is_SplitDipole = data1.is_SplitDipole;
473      bool i_is_Quadrupole = data1.is_Quadrupole;
474 +    bool i_is_Fluctuating = data1.is_Fluctuating;
475  
476      bool j_is_Charge = data2.is_Charge;
477      bool j_is_Dipole = data2.is_Dipole;
478      bool j_is_SplitDipole = data2.is_SplitDipole;
479      bool j_is_Quadrupole = data2.is_Quadrupole;
480 +    bool j_is_Fluctuating = data2.is_Fluctuating;
481      
482 <    if (i_is_Charge)
483 <      q_i = data1.charge;
482 >    if (i_is_Charge) {
483 >      q_i = data1.fixedCharge;
484  
485 +      if (i_is_Fluctuating) {
486 +        q_i += *(idat.flucQ1);
487 +      }
488 +      
489 +      if (idat.excluded) {
490 +        *(idat.skippedCharge2) += q_i;
491 +      }
492 +    }
493 +
494      if (i_is_Dipole) {
495        mu_i = data1.dipole_moment;
496 <      uz_i = idat.eFrame1.getColumn(2);
496 >      uz_i = idat.eFrame1->getColumn(2);
497        
498        ct_i = dot(uz_i, rhat);
499  
# Line 504 | Line 509 | namespace OpenMD {
509        qyy_i = Q_i.y();
510        qzz_i = Q_i.z();
511        
512 <      ux_i = idat.eFrame1.getColumn(0);
513 <      uy_i = idat.eFrame1.getColumn(1);
514 <      uz_i = idat.eFrame1.getColumn(2);
512 >      ux_i = idat.eFrame1->getColumn(0);
513 >      uy_i = idat.eFrame1->getColumn(1);
514 >      uz_i = idat.eFrame1->getColumn(2);
515  
516        cx_i = dot(ux_i, rhat);
517        cy_i = dot(uy_i, rhat);
# Line 517 | Line 522 | namespace OpenMD {
522        duduz_i = V3Zero;
523      }
524  
525 <    if (j_is_Charge)
526 <      q_j = data2.charge;
525 >    if (j_is_Charge) {
526 >      q_j = data2.fixedCharge;
527  
528 +      if (i_is_Fluctuating)
529 +        q_j += *(idat.flucQ2);
530 +
531 +      if (idat.excluded) {
532 +        *(idat.skippedCharge1) += q_j;
533 +      }
534 +    }
535 +
536 +
537      if (j_is_Dipole) {
538        mu_j = data2.dipole_moment;
539 <      uz_j = idat.eFrame2.getColumn(2);
539 >      uz_j = idat.eFrame2->getColumn(2);
540        
541        ct_j = dot(uz_j, rhat);
542  
# Line 538 | Line 552 | namespace OpenMD {
552        qyy_j = Q_j.y();
553        qzz_j = Q_j.z();
554        
555 <      ux_j = idat.eFrame2.getColumn(0);
556 <      uy_j = idat.eFrame2.getColumn(1);
557 <      uz_j = idat.eFrame2.getColumn(2);
555 >      ux_j = idat.eFrame2->getColumn(0);
556 >      uy_j = idat.eFrame2->getColumn(1);
557 >      uz_j = idat.eFrame2->getColumn(2);
558  
559        cx_j = dot(ux_j, rhat);
560        cy_j = dot(uy_j, rhat);
# Line 551 | Line 565 | namespace OpenMD {
565        duduz_j = V3Zero;
566      }
567      
568 +    if (i_is_Fluctuating && j_is_Fluctuating) {
569 +      J1 = Jij[idat.atypes];
570 +      J2 = Jij[make_pair(idat.atypes.second, idat.atypes.first)];
571 +    }
572 +
573      epot = 0.0;
574      dVdr = V3Zero;
575      
# Line 559 | Line 578 | namespace OpenMD {
578        if (j_is_Charge) {
579          if (screeningMethod_ == DAMPED) {
580            // assemble the damping variables
581 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
582 <          erfcVal = res.first;
583 <          derfcVal = res.second;
581 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
582 >          //erfcVal = res.first;
583 >          //derfcVal = res.second;
584 >
585 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
586 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
587 >
588            c1 = erfcVal * riji;
589            c2 = (-derfcVal + c1) * riji;
590          } else {
# Line 569 | Line 592 | namespace OpenMD {
592            c2 = c1 * riji;
593          }
594  
595 <        preVal = idat.electroMult * pre11_ * q_i * q_j;
595 >        preVal =  *(idat.electroMult) * pre11_ * q_i * q_j;
596          
597          if (summationMethod_ == esm_SHIFTED_POTENTIAL) {
598            vterm = preVal * (c1 - c1c_);
599 <          dudr  = -idat.sw * preVal * c2;
599 >          dudr  = - *(idat.sw)  * preVal * c2;
600  
601          } else if (summationMethod_ == esm_SHIFTED_FORCE)  {
602 <          vterm = preVal * ( c1 - c1c_ + c2c_*(idat.rij - cutoffRadius_) );
603 <          dudr  = idat.sw * preVal * (c2c_ - c2);
602 >          vterm = preVal * ( c1 - c1c_ + c2c_*( *(idat.rij)  - cutoffRadius_) );
603 >          dudr  =  *(idat.sw)  * preVal * (c2c_ - c2);
604  
605          } else if (summationMethod_ == esm_REACTION_FIELD) {
606 <          rfVal = idat.electroMult * preRF_ * idat.rij * idat.rij;
606 >          rfVal = preRF_ *  *(idat.rij)  *  *(idat.rij);
607 >
608            vterm = preVal * ( riji + rfVal );            
609 <          dudr  = idat.sw * preVal * ( 2.0 * rfVal - riji ) * riji;
609 >          dudr  =  *(idat.sw)  * preVal * ( 2.0 * rfVal - riji ) * riji;
610 >          
611 >          // if this is an excluded pair, there are still indirect
612 >          // interactions via the reaction field we must worry about:
613  
614 +          if (idat.excluded) {
615 +            indirect_vpair += preVal * rfVal;
616 +            indirect_Pot += *(idat.sw) * preVal * rfVal;
617 +            indirect_dVdr += *(idat.sw)  * preVal * two * rfVal  * riji * rhat;
618 +          }
619 +          
620          } else {
588          vterm = preVal * riji * erfcVal;            
621  
622 <          dudr  = - idat.sw * preVal * c2;
622 >          vterm = preVal * riji * erfcVal;          
623 >          dudr  = -  *(idat.sw)  * preVal * c2;
624 >          
625 >        }
626  
627 +        
628 +        if (i_is_Fluctuating) {
629 +          if (!idat.excluded)
630 +            *(idat.dVdFQ1) += *(idat.sw) * vterm / q_i;
631 +          else {
632 +            res = J1->getValueAndDerivativeAt( *(idat.rij) );
633 +            *(idat.dVdFQ1) += pre11_ * res.first * q_j;
634 +          }
635          }
636 <
637 <        idat.vpair += vterm;
638 <        epot += idat.sw * vterm;
636 >        if (j_is_Fluctuating) {
637 >          if (!idat.excluded)
638 >            *(idat.dVdFQ2) += *(idat.sw) * vterm / q_j;
639 >          else {
640 >            res = J2->getValueAndDerivativeAt( *(idat.rij) );
641 >            *(idat.dVdFQ2) += pre11_ * res.first * q_i;
642 >          }
643 >        }
644  
645 <        dVdr += dudr * rhat;      
645 >        vpair += vterm;
646 >        epot +=  *(idat.sw)  * vterm;
647 >        dVdr += dudr * rhat;                
648        }
649  
650        if (j_is_Dipole) {
651          // pref is used by all the possible methods
652 <        pref = idat.electroMult * pre12_ * q_i * mu_j;
653 <        preSw = idat.sw * pref;
652 >        pref =  *(idat.electroMult) * pre12_ * q_i * mu_j;
653 >        preSw =  *(idat.sw)  * pref;
654  
655          if (summationMethod_ == esm_REACTION_FIELD) {
656            ri2 = riji * riji;
657            ri3 = ri2 * riji;
658      
659 <          vterm = - pref * ct_j * ( ri2 - preRF2_ * idat.rij );
660 <          idat.vpair += vterm;
661 <          epot += idat.sw * vterm;
659 >          vterm = - pref * ct_j * ( ri2 - preRF2_ *  *(idat.rij)  );
660 >          vpair += vterm;
661 >          epot +=  *(idat.sw)  * vterm;
662  
663 <          dVdr +=  -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
664 <          duduz_j += -preSw * rhat * (ri2 - preRF2_ * idat.rij);  
663 >          dVdr +=  -preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j);
664 >          duduz_j += -preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );  
665  
666 +          // Even if we excluded this pair from direct interactions,
667 +          // we still have the reaction-field-mediated charge-dipole
668 +          // interaction:
669 +
670 +          if (idat.excluded) {
671 +            indirect_vpair += pref * ct_j * preRF2_ * *(idat.rij);
672 +            indirect_Pot += preSw * ct_j * preRF2_ * *(idat.rij);
673 +            indirect_dVdr += preSw * preRF2_ * uz_j;
674 +            indirect_duduz_j += preSw * rhat * preRF2_ *  *(idat.rij);
675 +          }
676 +                      
677          } else {
678            // determine the inverse r used if we have split dipoles
679            if (j_is_SplitDipole) {
680 <            BigR = sqrt(idat.r2 + 0.25 * d_j * d_j);
680 >            BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j);
681              ri = 1.0 / BigR;
682 <            scale = idat.rij * ri;
682 >            scale =  *(idat.rij)  * ri;
683            } else {
684              ri = riji;
685              scale = 1.0;
# Line 628 | Line 689 | namespace OpenMD {
689  
690            if (screeningMethod_ == DAMPED) {
691              // assemble the damping variables
692 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
693 <            erfcVal = res.first;
694 <            derfcVal = res.second;
692 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
693 >            //erfcVal = res.first;
694 >            //derfcVal = res.second;
695 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
696 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
697              c1 = erfcVal * ri;
698              c2 = (-derfcVal + c1) * ri;
699              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 645 | Line 708 | namespace OpenMD {
708            // calculate the potential
709            pot_term =  scale * c2;
710            vterm = -pref * ct_j * pot_term;
711 <          idat.vpair += vterm;
712 <          epot += idat.sw * vterm;
711 >          vpair += vterm;
712 >          epot +=  *(idat.sw)  * vterm;
713              
714            // calculate derivatives for forces and torques
715  
# Line 661 | Line 724 | namespace OpenMD {
724          cx2 = cx_j * cx_j;
725          cy2 = cy_j * cy_j;
726          cz2 = cz_j * cz_j;
727 <        pref =  idat.electroMult * pre14_ * q_i * one_third_;
727 >        pref =   *(idat.electroMult) * pre14_ * q_i * one_third_;
728            
729          if (screeningMethod_ == DAMPED) {
730            // assemble the damping variables
731 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
732 <          erfcVal = res.first;
733 <          derfcVal = res.second;
731 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
732 >          //erfcVal = res.first;
733 >          //derfcVal = res.second;
734 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
735 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
736            c1 = erfcVal * riji;
737            c2 = (-derfcVal + c1) * riji;
738            c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji;
# Line 680 | Line 745 | namespace OpenMD {
745          }
746  
747          // precompute variables for convenience
748 <        preSw = idat.sw * pref;
748 >        preSw =  *(idat.sw)  * pref;
749          c2ri = c2 * riji;
750          c3ri = c3 * riji;
751 <        c4rij = c4 * idat.rij;
752 <        rhatdot2 = 2.0 * rhat * c3;
751 >        c4rij = c4 *  *(idat.rij) ;
752 >        rhatdot2 = two * rhat * c3;
753          rhatc4 = rhat * c4rij;
754  
755          // calculate the potential
# Line 692 | Line 757 | namespace OpenMD {
757                       qyy_j * (cy2*c3 - c2ri) +
758                       qzz_j * (cz2*c3 - c2ri) );
759          vterm = pref * pot_term;
760 <        idat.vpair += vterm;
761 <        epot += idat.sw * vterm;
760 >        vpair += vterm;
761 >        epot +=  *(idat.sw)  * vterm;
762                  
763          // calculate derivatives for the forces and torques
764  
765 <        dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (2.0*cx_j*ux_j + rhat)*c3ri) +
766 <                           qyy_j* (cy2*rhatc4 - (2.0*cy_j*uy_j + rhat)*c3ri) +
767 <                           qzz_j* (cz2*rhatc4 - (2.0*cz_j*uz_j + rhat)*c3ri));
765 >        dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (two*cx_j*ux_j + rhat)*c3ri) +
766 >                           qyy_j* (cy2*rhatc4 - (two*cy_j*uy_j + rhat)*c3ri) +
767 >                           qzz_j* (cz2*rhatc4 - (two*cz_j*uz_j + rhat)*c3ri));
768                            
769          dudux_j += preSw * qxx_j * cx_j * rhatdot2;
770          duduy_j += preSw * qyy_j * cy_j * rhatdot2;
# Line 711 | Line 776 | namespace OpenMD {
776  
777        if (j_is_Charge) {
778          // variables used by all the methods
779 <        pref = idat.electroMult * pre12_ * q_j * mu_i;
780 <        preSw = idat.sw * pref;
779 >        pref =  *(idat.electroMult) * pre12_ * q_j * mu_i;
780 >        preSw =  *(idat.sw)  * pref;
781  
782          if (summationMethod_ == esm_REACTION_FIELD) {
783  
784            ri2 = riji * riji;
785            ri3 = ri2 * riji;
786  
787 <          vterm = pref * ct_i * ( ri2 - preRF2_ * idat.rij );
788 <          idat.vpair += vterm;
789 <          epot += idat.sw * vterm;
787 >          vterm = pref * ct_i * ( ri2 - preRF2_ *  *(idat.rij)  );
788 >          vpair += vterm;
789 >          epot +=  *(idat.sw)  * vterm;
790            
791 <          dVdr += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);
791 >          dVdr += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_ * uz_i);
792            
793 <          duduz_i += preSw * rhat * (ri2 - preRF2_ * idat.rij);
793 >          duduz_i += preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );
794 >
795 >          // Even if we excluded this pair from direct interactions,
796 >          // we still have the reaction-field-mediated charge-dipole
797 >          // interaction:
798 >
799 >          if (idat.excluded) {
800 >            indirect_vpair += -pref * ct_i * preRF2_ * *(idat.rij);
801 >            indirect_Pot += -preSw * ct_i * preRF2_ * *(idat.rij);
802 >            indirect_dVdr += -preSw * preRF2_ * uz_i;
803 >            indirect_duduz_i += -preSw * rhat * preRF2_ *  *(idat.rij);
804 >          }
805              
806          } else {
807            
808            // determine inverse r if we are using split dipoles
809            if (i_is_SplitDipole) {
810 <            BigR = sqrt(idat.r2 + 0.25 * d_i * d_i);
810 >            BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i);
811              ri = 1.0 / BigR;
812 <            scale = idat.rij * ri;
812 >            scale =  *(idat.rij)  * ri;
813            } else {
814              ri = riji;
815              scale = 1.0;
# Line 743 | Line 819 | namespace OpenMD {
819              
820            if (screeningMethod_ == DAMPED) {
821              // assemble the damping variables
822 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
823 <            erfcVal = res.first;
824 <            derfcVal = res.second;
822 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
823 >            //erfcVal = res.first;
824 >            //derfcVal = res.second;
825 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
826 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
827              c1 = erfcVal * ri;
828              c2 = (-derfcVal + c1) * ri;
829              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 760 | Line 838 | namespace OpenMD {
838            // calculate the potential
839            pot_term = c2 * scale;
840            vterm = pref * ct_i * pot_term;
841 <          idat.vpair += vterm;
842 <          epot += idat.sw * vterm;
841 >          vpair += vterm;
842 >          epot +=  *(idat.sw)  * vterm;
843  
844            // calculate derivatives for the forces and torques
845            dVdr += preSw * (uz_i * c2ri - ct_i * rhat * sc2 * c3);
# Line 773 | Line 851 | namespace OpenMD {
851          // variables used by all methods
852          ct_ij = dot(uz_i, uz_j);
853  
854 <        pref = idat.electroMult * pre22_ * mu_i * mu_j;
855 <        preSw = idat.sw * pref;
854 >        pref =  *(idat.electroMult) * pre22_ * mu_i * mu_j;
855 >        preSw =  *(idat.sw)  * pref;
856  
857          if (summationMethod_ == esm_REACTION_FIELD) {
858            ri2 = riji * riji;
# Line 783 | Line 861 | namespace OpenMD {
861  
862            vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) -
863                             preRF2_ * ct_ij );
864 <          idat.vpair += vterm;
865 <          epot += idat.sw * vterm;
864 >          vpair += vterm;
865 >          epot +=  *(idat.sw)  * vterm;
866              
867            a1 = 5.0 * ct_i * ct_j - ct_ij;
868              
869 <          dVdr += preSw * 3.0 * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i);
869 >          dVdr += preSw * three * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i);
870  
871 <          duduz_i += preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
872 <          duduz_j += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_*uz_i);
871 >          duduz_i += preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j);
872 >          duduz_j += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_*uz_i);
873  
874 +          if (idat.excluded) {
875 +            indirect_vpair +=  - pref * preRF2_ * ct_ij;
876 +            indirect_Pot +=    - preSw * preRF2_ * ct_ij;
877 +            indirect_duduz_i += -preSw * preRF2_ * uz_j;
878 +            indirect_duduz_j += -preSw * preRF2_ * uz_i;
879 +          }
880 +
881          } else {
882            
883            if (i_is_SplitDipole) {
884              if (j_is_SplitDipole) {
885 <              BigR = sqrt(idat.r2 + 0.25 * d_i * d_i + 0.25 * d_j * d_j);
885 >              BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i + 0.25 * d_j * d_j);
886              } else {
887 <              BigR = sqrt(idat.r2 + 0.25 * d_i * d_i);
887 >              BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i);
888              }
889              ri = 1.0 / BigR;
890 <            scale = idat.rij * ri;
890 >            scale =  *(idat.rij)  * ri;
891            } else {
892              if (j_is_SplitDipole) {
893 <              BigR = sqrt(idat.r2 + 0.25 * d_j * d_j);
893 >              BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j);
894                ri = 1.0 / BigR;
895 <              scale = idat.rij * ri;
895 >              scale =  *(idat.rij)  * ri;
896              } else {
897                ri = riji;
898                scale = 1.0;
# Line 815 | Line 900 | namespace OpenMD {
900            }
901            if (screeningMethod_ == DAMPED) {
902              // assemble damping variables
903 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
904 <            erfcVal = res.first;
905 <            derfcVal = res.second;
903 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
904 >            //erfcVal = res.first;
905 >            //derfcVal = res.second;
906 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
907 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
908              c1 = erfcVal * ri;
909              c2 = (-derfcVal + c1) * ri;
910              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 837 | Line 924 | namespace OpenMD {
924            preSwSc = preSw * scale;
925            c2ri = c2 * ri;
926            c3ri = c3 * ri;
927 <          c4rij = c4 * idat.rij;
927 >          c4rij = c4 *  *(idat.rij) ;
928  
929            // calculate the potential
930            pot_term = (ct_ij * c2ri - ctidotj * c3);
931            vterm = pref * pot_term;
932 <          idat.vpair += vterm;
933 <          epot += idat.sw * vterm;
932 >          vpair += vterm;
933 >          epot +=  *(idat.sw)  * vterm;
934  
935            // calculate derivatives for the forces and torques
936            dVdr += preSwSc * ( ctidotj * rhat * c4rij  -
# Line 862 | Line 949 | namespace OpenMD {
949          cy2 = cy_i * cy_i;
950          cz2 = cz_i * cz_i;
951  
952 <        pref = idat.electroMult * pre14_ * q_j * one_third_;
952 >        pref =  *(idat.electroMult) * pre14_ * q_j * one_third_;
953  
954          if (screeningMethod_ == DAMPED) {
955            // assemble the damping variables
956 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
957 <          erfcVal = res.first;
958 <          derfcVal = res.second;
956 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
957 >          //erfcVal = res.first;
958 >          //derfcVal = res.second;
959 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
960 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
961            c1 = erfcVal * riji;
962            c2 = (-derfcVal + c1) * riji;
963            c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji;
# Line 881 | Line 970 | namespace OpenMD {
970          }
971            
972          // precompute some variables for convenience
973 <        preSw = idat.sw * pref;
973 >        preSw =  *(idat.sw)  * pref;
974          c2ri = c2 * riji;
975          c3ri = c3 * riji;
976 <        c4rij = c4 * idat.rij;
977 <        rhatdot2 = 2.0 * rhat * c3;
976 >        c4rij = c4 *  *(idat.rij) ;
977 >        rhatdot2 = two * rhat * c3;
978          rhatc4 = rhat * c4rij;
979  
980          // calculate the potential
# Line 894 | Line 983 | namespace OpenMD {
983                       qzz_i * (cz2 * c3 - c2ri) );
984          
985          vterm = pref * pot_term;
986 <        idat.vpair += vterm;
987 <        epot += idat.sw * vterm;
986 >        vpair += vterm;
987 >        epot +=  *(idat.sw)  * vterm;
988  
989          // calculate the derivatives for the forces and torques
990  
991 <        dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (2.0*cx_i*ux_i + rhat)*c3ri) +
992 <                          qyy_i* (cy2*rhatc4 - (2.0*cy_i*uy_i + rhat)*c3ri) +
993 <                          qzz_i* (cz2*rhatc4 - (2.0*cz_i*uz_i + rhat)*c3ri));
991 >        dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (two*cx_i*ux_i + rhat)*c3ri) +
992 >                          qyy_i* (cy2*rhatc4 - (two*cy_i*uy_i + rhat)*c3ri) +
993 >                          qzz_i* (cz2*rhatc4 - (two*cz_i*uz_i + rhat)*c3ri));
994  
995          dudux_i += preSw * qxx_i * cx_i *  rhatdot2;
996          duduy_i += preSw * qyy_i * cy_i *  rhatdot2;
# Line 909 | Line 998 | namespace OpenMD {
998        }
999      }
1000  
912    idat.pot += epot;
913    idat.f1 += dVdr;
1001  
1002 <    if (i_is_Dipole || i_is_Quadrupole)
1003 <      idat.t1 -= cross(uz_i, duduz_i);
1004 <    if (i_is_Quadrupole) {
1005 <      idat.t1 -= cross(ux_i, dudux_i);
1006 <      idat.t1 -= cross(uy_i, duduy_i);
1007 <    }
1002 >    if (!idat.excluded) {
1003 >      *(idat.vpair) += vpair;
1004 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += epot;
1005 >      *(idat.f1) += dVdr;
1006 >      
1007 >      if (i_is_Dipole || i_is_Quadrupole)
1008 >        *(idat.t1) -= cross(uz_i, duduz_i);
1009 >      if (i_is_Quadrupole) {
1010 >        *(idat.t1) -= cross(ux_i, dudux_i);
1011 >        *(idat.t1) -= cross(uy_i, duduy_i);
1012 >      }
1013 >      
1014 >      if (j_is_Dipole || j_is_Quadrupole)
1015 >        *(idat.t2) -= cross(uz_j, duduz_j);
1016 >      if (j_is_Quadrupole) {
1017 >        *(idat.t2) -= cross(uz_j, dudux_j);
1018 >        *(idat.t2) -= cross(uz_j, duduy_j);
1019 >      }
1020  
1021 <    if (j_is_Dipole || j_is_Quadrupole)
923 <      idat.t2 -= cross(uz_j, duduz_j);
924 <    if (j_is_Quadrupole) {
925 <      idat.t2 -= cross(uz_j, dudux_j);
926 <      idat.t2 -= cross(uz_j, duduy_j);
927 <    }
1021 >    } else {
1022  
1023 <    return;
1024 <  }  
1023 >      // only accumulate the forces and torques resulting from the
1024 >      // indirect reaction field terms.
1025  
1026 <  void Electrostatic::calcSkipCorrection(SkipCorrectionData skdat) {
1027 <
1028 <    if (!initialized_) initialize();
935 <    
936 <    ElectrostaticAtomData data1 = ElectrostaticMap[skdat.atype1];
937 <    ElectrostaticAtomData data2 = ElectrostaticMap[skdat.atype2];
938 <    
939 <    // logicals
940 <
941 <    bool i_is_Charge = data1.is_Charge;
942 <    bool i_is_Dipole = data1.is_Dipole;
943 <
944 <    bool j_is_Charge = data2.is_Charge;
945 <    bool j_is_Dipole = data2.is_Dipole;
946 <
947 <    RealType q_i, q_j;
948 <    
949 <    // The skippedCharge computation is needed by the real-space cutoff methods
950 <    // (i.e. shifted force and shifted potential)
951 <
952 <    if (i_is_Charge) {
953 <      q_i = data1.charge;
954 <      skdat.skippedCharge2 += q_i;
955 <    }
956 <
957 <    if (j_is_Charge) {
958 <      q_j = data2.charge;
959 <      skdat.skippedCharge1 += q_j;
960 <    }
961 <
962 <    // the rest of this function should only be necessary for reaction field.
963 <
964 <    if (summationMethod_ == esm_REACTION_FIELD) {
965 <      RealType riji, ri2, ri3;
966 <      RealType q_i, mu_i, ct_i;
967 <      RealType q_j, mu_j, ct_j;
968 <      RealType preVal, rfVal, vterm, dudr, pref, myPot;
969 <      Vector3d dVdr, uz_i, uz_j, duduz_i, duduz_j, rhat;
970 <
971 <      // some variables we'll need independent of electrostatic type:
1026 >      *(idat.vpair) += indirect_vpair;
1027 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot;
1028 >      *(idat.f1) += indirect_dVdr;
1029        
973      riji = 1.0 / skdat.rij;
974      rhat = skdat.d  * riji;
975
976      if (i_is_Dipole) {
977        mu_i = data1.dipole_moment;
978        uz_i = skdat.eFrame1.getColumn(2);      
979        ct_i = dot(uz_i, rhat);
980        duduz_i = V3Zero;
981      }
982            
983      if (j_is_Dipole) {
984        mu_j = data2.dipole_moment;
985        uz_j = skdat.eFrame2.getColumn(2);      
986        ct_j = dot(uz_j, rhat);
987        duduz_j = V3Zero;
988      }
989    
990      if (i_is_Charge) {
991        if (j_is_Charge) {
992          preVal = skdat.electroMult * pre11_ * q_i * q_j;
993          rfVal = preRF_ * skdat.rij * skdat.rij;
994          vterm = preVal * rfVal;
995          myPot += skdat.sw * vterm;        
996          dudr  = skdat.sw * preVal * 2.0 * rfVal * riji;        
997          dVdr += dudr * rhat;
998        }
999        
1000        if (j_is_Dipole) {
1001          ri2 = riji * riji;
1002          ri3 = ri2 * riji;        
1003          pref = skdat.electroMult * pre12_ * q_i * mu_j;
1004          vterm = - pref * ct_j * ( ri2 - preRF2_ * skdat.rij );
1005          myPot += skdat.sw * vterm;        
1006          dVdr += -skdat.sw * pref * ( ri3 * ( uz_j - 3.0 * ct_j * rhat) - preRF2_ * uz_j);
1007          duduz_j += -skdat.sw * pref * rhat * (ri2 - preRF2_ * skdat.rij);
1008        }
1009      }
1010      if (i_is_Dipole) {
1011        if (j_is_Charge) {
1012          ri2 = riji * riji;
1013          ri3 = ri2 * riji;        
1014          pref = skdat.electroMult * pre12_ * q_j * mu_i;
1015          vterm = - pref * ct_i * ( ri2 - preRF2_ * skdat.rij );
1016          myPot += skdat.sw * vterm;        
1017          dVdr += skdat.sw * pref * ( ri3 * ( uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);      
1018          duduz_i += skdat.sw * pref * rhat * (ri2 - preRF2_ * skdat.rij);
1019        }
1020      }
1021      
1022      // accumulate the forces and torques resulting from the self term
1023      skdat.pot += myPot;
1024      skdat.f1 += dVdr;
1025      
1030        if (i_is_Dipole)
1031 <        skdat.t1 -= cross(uz_i, duduz_i);
1031 >        *(idat.t1) -= cross(uz_i, indirect_duduz_i);
1032        if (j_is_Dipole)
1033 <        skdat.t2 -= cross(uz_j, duduz_j);
1033 >        *(idat.t2) -= cross(uz_j, indirect_duduz_j);
1034      }
1035 <  }
1035 >
1036 >
1037 >    return;
1038 >  }  
1039      
1040 <  void Electrostatic::calcSelfCorrection(SelfCorrectionData scdat) {
1040 >  void Electrostatic::calcSelfCorrection(SelfData &sdat) {
1041      RealType mu1, preVal, chg1, self;
1042      
1043      if (!initialized_) initialize();
1044 <    
1045 <    ElectrostaticAtomData data = ElectrostaticMap[scdat.atype];
1044 >
1045 >    ElectrostaticAtomData data = ElectrostaticMap[sdat.atype];
1046    
1047      // logicals
1041
1048      bool i_is_Charge = data.is_Charge;
1049      bool i_is_Dipole = data.is_Dipole;
1050  
# Line 1046 | Line 1052 | namespace OpenMD {
1052        if (i_is_Dipole) {
1053          mu1 = data.dipole_moment;          
1054          preVal = pre22_ * preRF2_ * mu1 * mu1;
1055 <        scdat.pot -= 0.5 * preVal;
1055 >        (*(sdat.pot))[ELECTROSTATIC_FAMILY] -= 0.5 * preVal;
1056          
1057          // The self-correction term adds into the reaction field vector
1058 <        Vector3d uz_i = scdat.eFrame.getColumn(2);
1058 >        Vector3d uz_i = sdat.eFrame->getColumn(2);
1059          Vector3d ei = preVal * uz_i;
1060  
1061          // This looks very wrong.  A vector crossed with itself is zero.
1062 <        scdat.t -= cross(uz_i, ei);
1062 >        *(sdat.t) -= cross(uz_i, ei);
1063        }
1064      } else if (summationMethod_ == esm_SHIFTED_FORCE || summationMethod_ == esm_SHIFTED_POTENTIAL) {
1065        if (i_is_Charge) {        
1066 <        chg1 = data.charge;
1066 >        chg1 = data.fixedCharge;
1067          if (screeningMethod_ == DAMPED) {
1068 <          self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + scdat.skippedCharge) * pre11_;
1068 >          self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_;
1069          } else {        
1070 <          self = - 0.5 * rcuti_ * chg1 * (chg1 + scdat.skippedCharge) * pre11_;
1070 >          self = - 0.5 * rcuti_ * chg1 * (chg1 +  *(sdat.skippedCharge)) * pre11_;
1071          }
1072 <        scdat.pot += self;
1072 >        (*(sdat.pot))[ELECTROSTATIC_FAMILY] += self;
1073        }
1074      }
1075    }
1076  
1077 <  RealType Electrostatic::getSuggestedCutoffRadius(AtomType* at1, AtomType* at2) {
1077 >  RealType Electrostatic::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
1078      // This seems to work moderately well as a default.  There's no
1079      // inherent scale for 1/r interactions that we can standardize.
1080      // 12 angstroms seems to be a reasonably good guess for most

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines