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 1723 by gezelter, Thu May 24 20:59:54 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 209 | Line 217 | namespace OpenMD {
217          addType(at);
218      }
219      
212
220      cutoffRadius2_ = cutoffRadius_ * cutoffRadius_;
221      rcuti_ = 1.0 / cutoffRadius_;
222      rcuti2_ = rcuti_ * rcuti_;
# Line 248 | Line 255 | namespace OpenMD {
255        preRF2_ = 2.0 * preRF_;
256      }
257      
258 <    RealType dx = cutoffRadius_ / RealType(np_ - 1);
258 >    // Add a 2 angstrom safety window to deal with cutoffGroups that
259 >    // have charged atoms longer than the cutoffRadius away from each
260 >    // other.  Splining may not be the best choice here.  Direct calls
261 >    // to erfc might be preferrable.
262 >
263 >    RealType dx = (cutoffRadius_ + 2.0) / RealType(np_ - 1);
264      RealType rval;
265      vector<RealType> rvals;
266      vector<RealType> yvals;
# Line 271 | Line 283 | namespace OpenMD {
283      electrostaticAtomData.is_Dipole = false;
284      electrostaticAtomData.is_SplitDipole = false;
285      electrostaticAtomData.is_Quadrupole = false;
286 +    electrostaticAtomData.is_Fluctuating = 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 +    }
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 >          // may not be necessary if Slater coulomb integral is symmetric
368 >          J2vals.push_back( sSTOCoulInt( b, a, n, m, rval * PhysicalConstants::angstromsToBohr ) );
369 >        }
370 >
371 >        CubicSpline* J1 = new CubicSpline();
372 >        J1->addPoints(rvals, J1vals);
373 >        CubicSpline* J2 = new CubicSpline();
374 >        J2->addPoints(rvals, J2vals);
375 >        
376 >        pair<AtomType*, AtomType*> key1, key2;
377 >        key1 = make_pair(atomType, atype2);
378 >        key2 = make_pair(atype2, atomType);
379 >        
380 >        Jij[key1] = J1;
381 >        Jij[key2] = J2;
382 >      }
383 >    }
384 >
385      return;
386    }
387    
388 <  void Electrostatic::setElectrostaticCutoffRadius( RealType theECR,
389 <                                                    RealType theRSW ) {
412 <    cutoffRadius_ = theECR;
388 >  void Electrostatic::setCutoffRadius( RealType rCut ) {
389 >    cutoffRadius_ = rCut;
390      rrf_ = cutoffRadius_;
414    rt_ = theRSW;
391      haveCutoffRadius_ = true;
392    }
393 +
394 +  void Electrostatic::setSwitchingRadius( RealType rSwitch ) {
395 +    rt_ = rSwitch;
396 +  }
397    void Electrostatic::setElectrostaticSummationMethod( ElectrostaticSummationMethod esm ) {
398      summationMethod_ = esm;
399    }
# Line 429 | Line 409 | namespace OpenMD {
409      haveDielectric_ = true;
410    }
411  
412 <  void Electrostatic::calcForce(InteractionData idat) {
412 >  void Electrostatic::calcForce(InteractionData &idat) {
413  
414      // utility variables.  Should clean these up and use the Vector3d and
415      // Mat3x3d to replace as many as we can in future versions:
# Line 443 | Line 423 | namespace OpenMD {
423      RealType ct_i, ct_j, ct_ij, a1;
424      RealType riji, ri, ri2, ri3, ri4;
425      RealType pref, vterm, epot, dudr;
426 +    RealType vpair(0.0);
427      RealType scale, sc2;
428      RealType pot_term, preVal, rfVal;
429      RealType c2ri, c3ri, c4rij, cti3, ctj3, ctidotj;
430      RealType preSw, preSwSc;
431      RealType c1, c2, c3, c4;
432 <    RealType erfcVal, derfcVal;
432 >    RealType erfcVal(1.0), derfcVal(0.0);
433      RealType BigR;
434 +    RealType two(2.0), three(3.0);
435  
436      Vector3d Q_i, Q_j;
437      Vector3d ux_i, uy_i, uz_i;
# Line 459 | Line 441 | namespace OpenMD {
441      Vector3d rhatdot2, rhatc4;
442      Vector3d dVdr;
443  
444 +    // variables for indirect (reaction field) interactions for excluded pairs:
445 +    RealType indirect_Pot(0.0);
446 +    RealType indirect_vpair(0.0);
447 +    Vector3d indirect_dVdr(V3Zero);
448 +    Vector3d indirect_duduz_i(V3Zero), indirect_duduz_j(V3Zero);
449 +
450 +    RealType coulInt, vFluc1(0.0), vFluc2(0.0);
451      pair<RealType, RealType> res;
452      
453 +    // splines for coulomb integrals
454 +    CubicSpline* J1;
455 +    CubicSpline* J2;
456 +    
457      if (!initialized_) initialize();
458      
459 <    ElectrostaticAtomData data1 = ElectrostaticMap[idat.atype1];
460 <    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atype2];
459 >    ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first];
460 >    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second];
461      
462      // some variables we'll need independent of electrostatic type:
463  
464 <    riji = 1.0 / idat.rij;
465 <    Vector3d rhat = idat.d  * riji;
464 >    riji = 1.0 /  *(idat.rij) ;
465 >    Vector3d rhat =  *(idat.d)   * riji;
466  
467      // logicals
468  
# Line 477 | Line 470 | namespace OpenMD {
470      bool i_is_Dipole = data1.is_Dipole;
471      bool i_is_SplitDipole = data1.is_SplitDipole;
472      bool i_is_Quadrupole = data1.is_Quadrupole;
473 +    bool i_is_Fluctuating = data1.is_Fluctuating;
474  
475      bool j_is_Charge = data2.is_Charge;
476      bool j_is_Dipole = data2.is_Dipole;
477      bool j_is_SplitDipole = data2.is_SplitDipole;
478      bool j_is_Quadrupole = data2.is_Quadrupole;
479 +    bool j_is_Fluctuating = data2.is_Fluctuating;
480      
481 <    if (i_is_Charge)
482 <      q_i = data1.charge;
481 >    if (i_is_Charge) {
482 >      q_i = data1.fixedCharge;
483  
484 +      if (i_is_Fluctuating) {
485 +        q_i += *(idat.flucQ1);
486 +      }
487 +      
488 +      if (idat.excluded) {
489 +        *(idat.skippedCharge2) += q_i;
490 +      }
491 +    }
492 +
493      if (i_is_Dipole) {
494        mu_i = data1.dipole_moment;
495 <      uz_i = idat.eFrame1.getColumn(2);
495 >      uz_i = idat.eFrame1->getColumn(2);
496        
497        ct_i = dot(uz_i, rhat);
498  
# Line 504 | Line 508 | namespace OpenMD {
508        qyy_i = Q_i.y();
509        qzz_i = Q_i.z();
510        
511 <      ux_i = idat.eFrame1.getColumn(0);
512 <      uy_i = idat.eFrame1.getColumn(1);
513 <      uz_i = idat.eFrame1.getColumn(2);
511 >      ux_i = idat.eFrame1->getColumn(0);
512 >      uy_i = idat.eFrame1->getColumn(1);
513 >      uz_i = idat.eFrame1->getColumn(2);
514  
515        cx_i = dot(ux_i, rhat);
516        cy_i = dot(uy_i, rhat);
# Line 517 | Line 521 | namespace OpenMD {
521        duduz_i = V3Zero;
522      }
523  
524 <    if (j_is_Charge)
525 <      q_j = data2.charge;
524 >    if (j_is_Charge) {
525 >      q_j = data2.fixedCharge;
526  
527 +      if (i_is_Fluctuating)
528 +        q_j += *(idat.flucQ2);
529 +
530 +      if (idat.excluded) {
531 +        *(idat.skippedCharge1) += q_j;
532 +      }
533 +    }
534 +
535 +
536      if (j_is_Dipole) {
537        mu_j = data2.dipole_moment;
538 <      uz_j = idat.eFrame2.getColumn(2);
538 >      uz_j = idat.eFrame2->getColumn(2);
539        
540        ct_j = dot(uz_j, rhat);
541  
# Line 538 | Line 551 | namespace OpenMD {
551        qyy_j = Q_j.y();
552        qzz_j = Q_j.z();
553        
554 <      ux_j = idat.eFrame2.getColumn(0);
555 <      uy_j = idat.eFrame2.getColumn(1);
556 <      uz_j = idat.eFrame2.getColumn(2);
554 >      ux_j = idat.eFrame2->getColumn(0);
555 >      uy_j = idat.eFrame2->getColumn(1);
556 >      uz_j = idat.eFrame2->getColumn(2);
557  
558        cx_j = dot(ux_j, rhat);
559        cy_j = dot(uy_j, rhat);
# Line 551 | Line 564 | namespace OpenMD {
564        duduz_j = V3Zero;
565      }
566      
567 +    if (i_is_Fluctuating && j_is_Fluctuating) {
568 +      J1 = Jij[idat.atypes];
569 +      J2 = Jij[make_pair(idat.atypes.second, idat.atypes.first)];
570 +    }
571 +
572      epot = 0.0;
573      dVdr = V3Zero;
574      
# Line 559 | Line 577 | namespace OpenMD {
577        if (j_is_Charge) {
578          if (screeningMethod_ == DAMPED) {
579            // assemble the damping variables
580 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
581 <          erfcVal = res.first;
582 <          derfcVal = res.second;
580 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
581 >          //erfcVal = res.first;
582 >          //derfcVal = res.second;
583 >
584 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
585 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
586 >
587            c1 = erfcVal * riji;
588            c2 = (-derfcVal + c1) * riji;
589          } else {
# Line 569 | Line 591 | namespace OpenMD {
591            c2 = c1 * riji;
592          }
593  
594 <        preVal = idat.electroMult * pre11_ * q_i * q_j;
594 >        preVal =  *(idat.electroMult) * pre11_ * q_i * q_j;
595          
596          if (summationMethod_ == esm_SHIFTED_POTENTIAL) {
597            vterm = preVal * (c1 - c1c_);
598 <          dudr  = -idat.sw * preVal * c2;
598 >          dudr  = - *(idat.sw)  * preVal * c2;
599  
600          } else if (summationMethod_ == esm_SHIFTED_FORCE)  {
601 <          vterm = preVal * ( c1 - c1c_ + c2c_*(idat.rij - cutoffRadius_) );
602 <          dudr  = idat.sw * preVal * (c2c_ - c2);
601 >          vterm = preVal * ( c1 - c1c_ + c2c_*( *(idat.rij)  - cutoffRadius_) );
602 >          dudr  =  *(idat.sw)  * preVal * (c2c_ - c2);
603  
604          } else if (summationMethod_ == esm_REACTION_FIELD) {
605 <          rfVal = idat.electroMult * preRF_ * idat.rij * idat.rij;
605 >          rfVal = preRF_ *  *(idat.rij)  *  *(idat.rij);
606 >
607            vterm = preVal * ( riji + rfVal );            
608 <          dudr  = idat.sw * preVal * ( 2.0 * rfVal - riji ) * riji;
608 >          dudr  =  *(idat.sw)  * preVal * ( 2.0 * rfVal - riji ) * riji;
609 >          
610 >          // if this is an excluded pair, there are still indirect
611 >          // interactions via the reaction field we must worry about:
612  
613 +          if (idat.excluded) {
614 +            indirect_vpair += preVal * rfVal;
615 +            indirect_Pot += *(idat.sw) * preVal * rfVal;
616 +            indirect_dVdr += *(idat.sw)  * preVal * two * rfVal  * riji * rhat;
617 +          }
618 +          
619          } else {
588          vterm = preVal * riji * erfcVal;            
620  
621 <          dudr  = - idat.sw * preVal * c2;
621 >          vterm = preVal * riji * erfcVal;          
622 >          dudr  = -  *(idat.sw)  * preVal * c2;
623 >          
624 >        }
625 >        
626 >        vpair += vterm;
627 >        epot +=  *(idat.sw)  * vterm;
628 >        dVdr += dudr * rhat;
629  
630 +        if (i_is_Fluctuating) {
631 +          if (idat.excluded) {
632 +            // vFluc1 is the difference between the direct coulomb integral
633 +            // and the normal 1/r-like  interaction between point charges.
634 +            coulInt = J1->getValueAt( *(idat.rij) );
635 +            vFluc1 = pre11_ * coulInt * q_i * q_j  - (*(idat.sw) * vterm);
636 +          } else {
637 +            vFluc1 = 0.0;
638 +          }
639 +          *(idat.dVdFQ1) += ( *(idat.sw) * vterm + vFluc1 ) / q_i;
640          }
593
594        idat.vpair += vterm;
595        epot += idat.sw * vterm;
641  
642 <        dVdr += dudr * rhat;      
642 >        if (j_is_Fluctuating) {
643 >          if (idat.excluded) {
644 >            // vFluc2 is the difference between the direct coulomb integral
645 >            // and the normal 1/r-like  interaction between point charges.
646 >            coulInt = J2->getValueAt( *(idat.rij) );
647 >            vFluc2 = pre11_ * coulInt * q_i * q_j  - (*(idat.sw) * vterm);
648 >          } else {
649 >            vFluc2 = 0.0;
650 >          }
651 >          *(idat.dVdFQ2) += ( *(idat.sw) * vterm + vFluc2 ) / q_j;
652 >        }
653 >          
654 >
655        }
656  
657        if (j_is_Dipole) {
658          // pref is used by all the possible methods
659 <        pref = idat.electroMult * pre12_ * q_i * mu_j;
660 <        preSw = idat.sw * pref;
659 >        pref =  *(idat.electroMult) * pre12_ * q_i * mu_j;
660 >        preSw =  *(idat.sw)  * pref;
661  
662          if (summationMethod_ == esm_REACTION_FIELD) {
663            ri2 = riji * riji;
664            ri3 = ri2 * riji;
665      
666 <          vterm = - pref * ct_j * ( ri2 - preRF2_ * idat.rij );
667 <          idat.vpair += vterm;
668 <          epot += idat.sw * vterm;
612 <
613 <          dVdr +=  -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
614 <          duduz_j += -preSw * rhat * (ri2 - preRF2_ * idat.rij);  
666 >          vterm = - pref * ct_j * ( ri2 - preRF2_ *  *(idat.rij)  );
667 >          vpair += vterm;
668 >          epot +=  *(idat.sw)  * vterm;
669  
670 +          dVdr +=  -preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j);
671 +          duduz_j += -preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );  
672 +
673 +          // Even if we excluded this pair from direct interactions,
674 +          // we still have the reaction-field-mediated charge-dipole
675 +          // interaction:
676 +
677 +          if (idat.excluded) {
678 +            indirect_vpair += pref * ct_j * preRF2_ * *(idat.rij);
679 +            indirect_Pot += preSw * ct_j * preRF2_ * *(idat.rij);
680 +            indirect_dVdr += preSw * preRF2_ * uz_j;
681 +            indirect_duduz_j += preSw * rhat * preRF2_ *  *(idat.rij);
682 +          }
683 +                      
684          } else {
685            // determine the inverse r used if we have split dipoles
686            if (j_is_SplitDipole) {
687 <            BigR = sqrt(idat.r2 + 0.25 * d_j * d_j);
687 >            BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j);
688              ri = 1.0 / BigR;
689 <            scale = idat.rij * ri;
689 >            scale =  *(idat.rij)  * ri;
690            } else {
691              ri = riji;
692              scale = 1.0;
# Line 628 | Line 696 | namespace OpenMD {
696  
697            if (screeningMethod_ == DAMPED) {
698              // assemble the damping variables
699 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
700 <            erfcVal = res.first;
701 <            derfcVal = res.second;
699 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
700 >            //erfcVal = res.first;
701 >            //derfcVal = res.second;
702 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
703 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
704              c1 = erfcVal * ri;
705              c2 = (-derfcVal + c1) * ri;
706              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 645 | Line 715 | namespace OpenMD {
715            // calculate the potential
716            pot_term =  scale * c2;
717            vterm = -pref * ct_j * pot_term;
718 <          idat.vpair += vterm;
719 <          epot += idat.sw * vterm;
718 >          vpair += vterm;
719 >          epot +=  *(idat.sw)  * vterm;
720              
721            // calculate derivatives for forces and torques
722  
# Line 654 | Line 724 | namespace OpenMD {
724            duduz_j += -preSw * pot_term * rhat;
725  
726          }
727 +        if (i_is_Fluctuating) {
728 +          *(idat.dVdFQ1) += ( *(idat.sw) * vterm ) / q_i;
729 +        }
730        }
731  
732        if (j_is_Quadrupole) {
# Line 661 | Line 734 | namespace OpenMD {
734          cx2 = cx_j * cx_j;
735          cy2 = cy_j * cy_j;
736          cz2 = cz_j * cz_j;
737 <        pref =  idat.electroMult * pre14_ * q_i * one_third_;
737 >        pref =   *(idat.electroMult) * pre14_ * q_i * one_third_;
738            
739          if (screeningMethod_ == DAMPED) {
740            // assemble the damping variables
741 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
742 <          erfcVal = res.first;
743 <          derfcVal = res.second;
741 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
742 >          //erfcVal = res.first;
743 >          //derfcVal = res.second;
744 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
745 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
746            c1 = erfcVal * riji;
747            c2 = (-derfcVal + c1) * riji;
748            c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji;
# Line 680 | Line 755 | namespace OpenMD {
755          }
756  
757          // precompute variables for convenience
758 <        preSw = idat.sw * pref;
758 >        preSw =  *(idat.sw)  * pref;
759          c2ri = c2 * riji;
760          c3ri = c3 * riji;
761 <        c4rij = c4 * idat.rij;
762 <        rhatdot2 = 2.0 * rhat * c3;
761 >        c4rij = c4 *  *(idat.rij) ;
762 >        rhatdot2 = two * rhat * c3;
763          rhatc4 = rhat * c4rij;
764  
765          // calculate the potential
# Line 692 | Line 767 | namespace OpenMD {
767                       qyy_j * (cy2*c3 - c2ri) +
768                       qzz_j * (cz2*c3 - c2ri) );
769          vterm = pref * pot_term;
770 <        idat.vpair += vterm;
771 <        epot += idat.sw * vterm;
770 >        vpair += vterm;
771 >        epot +=  *(idat.sw)  * vterm;
772                  
773          // calculate derivatives for the forces and torques
774  
775 <        dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (2.0*cx_j*ux_j + rhat)*c3ri) +
776 <                           qyy_j* (cy2*rhatc4 - (2.0*cy_j*uy_j + rhat)*c3ri) +
777 <                           qzz_j* (cz2*rhatc4 - (2.0*cz_j*uz_j + rhat)*c3ri));
775 >        dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (two*cx_j*ux_j + rhat)*c3ri) +
776 >                           qyy_j* (cy2*rhatc4 - (two*cy_j*uy_j + rhat)*c3ri) +
777 >                           qzz_j* (cz2*rhatc4 - (two*cz_j*uz_j + rhat)*c3ri));
778                            
779          dudux_j += preSw * qxx_j * cx_j * rhatdot2;
780          duduy_j += preSw * qyy_j * cy_j * rhatdot2;
781          duduz_j += preSw * qzz_j * cz_j * rhatdot2;
782 +        if (i_is_Fluctuating) {
783 +          *(idat.dVdFQ1) += ( *(idat.sw) * vterm ) / q_i;
784 +        }
785 +
786        }
787      }
788      
# Line 711 | Line 790 | namespace OpenMD {
790  
791        if (j_is_Charge) {
792          // variables used by all the methods
793 <        pref = idat.electroMult * pre12_ * q_j * mu_i;
794 <        preSw = idat.sw * pref;
793 >        pref =  *(idat.electroMult) * pre12_ * q_j * mu_i;
794 >        preSw =  *(idat.sw)  * pref;
795  
796          if (summationMethod_ == esm_REACTION_FIELD) {
797  
798            ri2 = riji * riji;
799            ri3 = ri2 * riji;
800  
801 <          vterm = pref * ct_i * ( ri2 - preRF2_ * idat.rij );
802 <          idat.vpair += vterm;
803 <          epot += idat.sw * vterm;
801 >          vterm = pref * ct_i * ( ri2 - preRF2_ *  *(idat.rij)  );
802 >          vpair += vterm;
803 >          epot +=  *(idat.sw)  * vterm;
804            
805 <          dVdr += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);
805 >          dVdr += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_ * uz_i);
806            
807 <          duduz_i += preSw * rhat * (ri2 - preRF2_ * idat.rij);
807 >          duduz_i += preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );
808 >
809 >          // Even if we excluded this pair from direct interactions,
810 >          // we still have the reaction-field-mediated charge-dipole
811 >          // interaction:
812 >
813 >          if (idat.excluded) {
814 >            indirect_vpair += -pref * ct_i * preRF2_ * *(idat.rij);
815 >            indirect_Pot += -preSw * ct_i * preRF2_ * *(idat.rij);
816 >            indirect_dVdr += -preSw * preRF2_ * uz_i;
817 >            indirect_duduz_i += -preSw * rhat * preRF2_ *  *(idat.rij);
818 >          }
819              
820          } else {
821            
822            // determine inverse r if we are using split dipoles
823            if (i_is_SplitDipole) {
824 <            BigR = sqrt(idat.r2 + 0.25 * d_i * d_i);
824 >            BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i);
825              ri = 1.0 / BigR;
826 <            scale = idat.rij * ri;
826 >            scale =  *(idat.rij)  * ri;
827            } else {
828              ri = riji;
829              scale = 1.0;
# Line 743 | Line 833 | namespace OpenMD {
833              
834            if (screeningMethod_ == DAMPED) {
835              // assemble the damping variables
836 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
837 <            erfcVal = res.first;
838 <            derfcVal = res.second;
836 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
837 >            //erfcVal = res.first;
838 >            //derfcVal = res.second;
839 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
840 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
841              c1 = erfcVal * ri;
842              c2 = (-derfcVal + c1) * ri;
843              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 760 | Line 852 | namespace OpenMD {
852            // calculate the potential
853            pot_term = c2 * scale;
854            vterm = pref * ct_i * pot_term;
855 <          idat.vpair += vterm;
856 <          epot += idat.sw * vterm;
855 >          vpair += vterm;
856 >          epot +=  *(idat.sw)  * vterm;
857  
858            // calculate derivatives for the forces and torques
859            dVdr += preSw * (uz_i * c2ri - ct_i * rhat * sc2 * c3);
860            duduz_i += preSw * pot_term * rhat;
861          }
862 +
863 +        if (j_is_Fluctuating) {
864 +          *(idat.dVdFQ2) += ( *(idat.sw) * vterm ) / q_j;
865 +        }
866 +
867        }
868  
869        if (j_is_Dipole) {
870          // variables used by all methods
871          ct_ij = dot(uz_i, uz_j);
872  
873 <        pref = idat.electroMult * pre22_ * mu_i * mu_j;
874 <        preSw = idat.sw * pref;
873 >        pref =  *(idat.electroMult) * pre22_ * mu_i * mu_j;
874 >        preSw =  *(idat.sw)  * pref;
875  
876          if (summationMethod_ == esm_REACTION_FIELD) {
877            ri2 = riji * riji;
# Line 783 | Line 880 | namespace OpenMD {
880  
881            vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) -
882                             preRF2_ * ct_ij );
883 <          idat.vpair += vterm;
884 <          epot += idat.sw * vterm;
883 >          vpair += vterm;
884 >          epot +=  *(idat.sw)  * vterm;
885              
886            a1 = 5.0 * ct_i * ct_j - ct_ij;
887              
888 <          dVdr += preSw * 3.0 * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i);
888 >          dVdr += preSw * three * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i);
889  
890 <          duduz_i += preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
891 <          duduz_j += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_*uz_i);
890 >          duduz_i += preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j);
891 >          duduz_j += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_*uz_i);
892  
893 +          if (idat.excluded) {
894 +            indirect_vpair +=  - pref * preRF2_ * ct_ij;
895 +            indirect_Pot +=    - preSw * preRF2_ * ct_ij;
896 +            indirect_duduz_i += -preSw * preRF2_ * uz_j;
897 +            indirect_duduz_j += -preSw * preRF2_ * uz_i;
898 +          }
899 +
900          } else {
901            
902            if (i_is_SplitDipole) {
903              if (j_is_SplitDipole) {
904 <              BigR = sqrt(idat.r2 + 0.25 * d_i * d_i + 0.25 * d_j * d_j);
904 >              BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i + 0.25 * d_j * d_j);
905              } else {
906 <              BigR = sqrt(idat.r2 + 0.25 * d_i * d_i);
906 >              BigR = sqrt( *(idat.r2) + 0.25 * d_i * d_i);
907              }
908              ri = 1.0 / BigR;
909 <            scale = idat.rij * ri;
909 >            scale =  *(idat.rij)  * ri;
910            } else {
911              if (j_is_SplitDipole) {
912 <              BigR = sqrt(idat.r2 + 0.25 * d_j * d_j);
912 >              BigR = sqrt( *(idat.r2) + 0.25 * d_j * d_j);
913                ri = 1.0 / BigR;
914 <              scale = idat.rij * ri;
914 >              scale =  *(idat.rij)  * ri;
915              } else {
916                ri = riji;
917                scale = 1.0;
# Line 815 | Line 919 | namespace OpenMD {
919            }
920            if (screeningMethod_ == DAMPED) {
921              // assemble damping variables
922 <            res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
923 <            erfcVal = res.first;
924 <            derfcVal = res.second;
922 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
923 >            //erfcVal = res.first;
924 >            //derfcVal = res.second;
925 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
926 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
927              c1 = erfcVal * ri;
928              c2 = (-derfcVal + c1) * ri;
929              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 837 | Line 943 | namespace OpenMD {
943            preSwSc = preSw * scale;
944            c2ri = c2 * ri;
945            c3ri = c3 * ri;
946 <          c4rij = c4 * idat.rij;
946 >          c4rij = c4 *  *(idat.rij) ;
947  
948            // calculate the potential
949            pot_term = (ct_ij * c2ri - ctidotj * c3);
950            vterm = pref * pot_term;
951 <          idat.vpair += vterm;
952 <          epot += idat.sw * vterm;
951 >          vpair += vterm;
952 >          epot +=  *(idat.sw)  * vterm;
953  
954            // calculate derivatives for the forces and torques
955            dVdr += preSwSc * ( ctidotj * rhat * c4rij  -
# Line 862 | Line 968 | namespace OpenMD {
968          cy2 = cy_i * cy_i;
969          cz2 = cz_i * cz_i;
970  
971 <        pref = idat.electroMult * pre14_ * q_j * one_third_;
971 >        pref =  *(idat.electroMult) * pre14_ * q_j * one_third_;
972  
973          if (screeningMethod_ == DAMPED) {
974            // assemble the damping variables
975 <          res = erfcSpline_->getValueAndDerivativeAt(idat.rij);
976 <          erfcVal = res.first;
977 <          derfcVal = res.second;
975 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
976 >          //erfcVal = res.first;
977 >          //derfcVal = res.second;
978 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
979 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
980            c1 = erfcVal * riji;
981            c2 = (-derfcVal + c1) * riji;
982            c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji;
# Line 881 | Line 989 | namespace OpenMD {
989          }
990            
991          // precompute some variables for convenience
992 <        preSw = idat.sw * pref;
992 >        preSw =  *(idat.sw)  * pref;
993          c2ri = c2 * riji;
994          c3ri = c3 * riji;
995 <        c4rij = c4 * idat.rij;
996 <        rhatdot2 = 2.0 * rhat * c3;
995 >        c4rij = c4 *  *(idat.rij) ;
996 >        rhatdot2 = two * rhat * c3;
997          rhatc4 = rhat * c4rij;
998  
999          // calculate the potential
# Line 894 | Line 1002 | namespace OpenMD {
1002                       qzz_i * (cz2 * c3 - c2ri) );
1003          
1004          vterm = pref * pot_term;
1005 <        idat.vpair += vterm;
1006 <        epot += idat.sw * vterm;
1005 >        vpair += vterm;
1006 >        epot +=  *(idat.sw)  * vterm;
1007  
1008          // calculate the derivatives for the forces and torques
1009  
1010 <        dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (2.0*cx_i*ux_i + rhat)*c3ri) +
1011 <                          qyy_i* (cy2*rhatc4 - (2.0*cy_i*uy_i + rhat)*c3ri) +
1012 <                          qzz_i* (cz2*rhatc4 - (2.0*cz_i*uz_i + rhat)*c3ri));
1010 >        dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (two*cx_i*ux_i + rhat)*c3ri) +
1011 >                          qyy_i* (cy2*rhatc4 - (two*cy_i*uy_i + rhat)*c3ri) +
1012 >                          qzz_i* (cz2*rhatc4 - (two*cz_i*uz_i + rhat)*c3ri));
1013  
1014          dudux_i += preSw * qxx_i * cx_i *  rhatdot2;
1015          duduy_i += preSw * qyy_i * cy_i *  rhatdot2;
1016          duduz_i += preSw * qzz_i * cz_i *  rhatdot2;
1017 +
1018 +        if (j_is_Fluctuating) {
1019 +          *(idat.dVdFQ2) += ( *(idat.sw) * vterm ) / q_j;
1020 +        }
1021 +
1022        }
1023      }
1024  
912    idat.pot += epot;
913    idat.f1 += dVdr;
1025  
1026 <    if (i_is_Dipole || i_is_Quadrupole)
1027 <      idat.t1 -= cross(uz_i, duduz_i);
1028 <    if (i_is_Quadrupole) {
1029 <      idat.t1 -= cross(ux_i, dudux_i);
1030 <      idat.t1 -= cross(uy_i, duduy_i);
1031 <    }
1026 >    if (!idat.excluded) {
1027 >      *(idat.vpair) += vpair;
1028 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += epot;
1029 >      *(idat.f1) += dVdr;
1030 >      
1031 >      if (i_is_Dipole || i_is_Quadrupole)
1032 >        *(idat.t1) -= cross(uz_i, duduz_i);
1033 >      if (i_is_Quadrupole) {
1034 >        *(idat.t1) -= cross(ux_i, dudux_i);
1035 >        *(idat.t1) -= cross(uy_i, duduy_i);
1036 >      }
1037 >      
1038 >      if (j_is_Dipole || j_is_Quadrupole)
1039 >        *(idat.t2) -= cross(uz_j, duduz_j);
1040 >      if (j_is_Quadrupole) {
1041 >        *(idat.t2) -= cross(uz_j, dudux_j);
1042 >        *(idat.t2) -= cross(uz_j, duduy_j);
1043 >      }
1044  
1045 <    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 <    }
1045 >    } else {
1046  
1047 <    return;
1048 <  }  
1047 >      // only accumulate the forces and torques resulting from the
1048 >      // indirect reaction field terms.
1049  
1050 <  void Electrostatic::calcSkipCorrection(SkipCorrectionData skdat) {
1051 <
1052 <    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:
1050 >      *(idat.vpair) += indirect_vpair;
1051 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot;
1052 >      *(idat.f1) += indirect_dVdr;
1053        
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      
1054        if (i_is_Dipole)
1055 <        skdat.t1 -= cross(uz_i, duduz_i);
1055 >        *(idat.t1) -= cross(uz_i, indirect_duduz_i);
1056        if (j_is_Dipole)
1057 <        skdat.t2 -= cross(uz_j, duduz_j);
1057 >        *(idat.t2) -= cross(uz_j, indirect_duduz_j);
1058      }
1059 <  }
1059 >
1060 >    return;
1061 >  }  
1062      
1063 <  void Electrostatic::calcSelfCorrection(SelfCorrectionData scdat) {
1063 >  void Electrostatic::calcSelfCorrection(SelfData &sdat) {
1064      RealType mu1, preVal, chg1, self;
1065      
1066      if (!initialized_) initialize();
1067 <    
1068 <    ElectrostaticAtomData data = ElectrostaticMap[scdat.atype];
1067 >
1068 >    ElectrostaticAtomData data = ElectrostaticMap[sdat.atype];
1069    
1070      // logicals
1041
1071      bool i_is_Charge = data.is_Charge;
1072      bool i_is_Dipole = data.is_Dipole;
1073  
# Line 1046 | Line 1075 | namespace OpenMD {
1075        if (i_is_Dipole) {
1076          mu1 = data.dipole_moment;          
1077          preVal = pre22_ * preRF2_ * mu1 * mu1;
1078 <        scdat.pot -= 0.5 * preVal;
1078 >        (*(sdat.pot))[ELECTROSTATIC_FAMILY] -= 0.5 * preVal;
1079          
1080          // The self-correction term adds into the reaction field vector
1081 <        Vector3d uz_i = scdat.eFrame.getColumn(2);
1081 >        Vector3d uz_i = sdat.eFrame->getColumn(2);
1082          Vector3d ei = preVal * uz_i;
1083  
1084          // This looks very wrong.  A vector crossed with itself is zero.
1085 <        scdat.t -= cross(uz_i, ei);
1085 >        *(sdat.t) -= cross(uz_i, ei);
1086        }
1087      } else if (summationMethod_ == esm_SHIFTED_FORCE || summationMethod_ == esm_SHIFTED_POTENTIAL) {
1088        if (i_is_Charge) {        
1089 <        chg1 = data.charge;
1089 >        chg1 = data.fixedCharge;
1090          if (screeningMethod_ == DAMPED) {
1091 <          self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + scdat.skippedCharge) * pre11_;
1091 >          self = - 0.5 * (c1c_ + alphaPi_) * chg1 * (chg1 + *(sdat.skippedCharge)) * pre11_;
1092          } else {        
1093 <          self = - 0.5 * rcuti_ * chg1 * (chg1 + scdat.skippedCharge) * pre11_;
1093 >          self = - 0.5 * rcuti_ * chg1 * (chg1 +  *(sdat.skippedCharge)) * pre11_;
1094          }
1095 <        scdat.pot += self;
1095 >        (*(sdat.pot))[ELECTROSTATIC_FAMILY] += self;
1096        }
1097      }
1098    }
1099  
1100 <  RealType Electrostatic::getSuggestedCutoffRadius(AtomType* at1, AtomType* at2) {
1100 >  RealType Electrostatic::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
1101      // This seems to work moderately well as a default.  There's no
1102      // inherent scale for 1/r interactions that we can standardize.
1103      // 12 angstroms seems to be a reasonably good guess for most

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines