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 1586 by gezelter, Tue Jun 21 06:34:35 2011 UTC vs.
Revision 1710 by gezelter, Fri May 18 21:44:02 2012 UTC

# Line 34 | Line 34
34   * work.  Good starting points are:
35   *                                                                      
36   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 < * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
37 > * [2]  Fennell & Gezelter, J. Chem. Phys. 124 234104 (2006).          
38   * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
39 < * [4]  Vardeman & Gezelter, in progress (2009).                        
39 > * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 > * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include <stdio.h>
# Line 46 | Line 47
47   #include "nonbonded/Electrostatic.hpp"
48   #include "utils/simError.h"
49   #include "types/NonBondedInteractionType.hpp"
50 < #include "types/DirectionalAtomType.hpp"
50 > #include "types/FixedChargeAdapter.hpp"
51 > #include "types/MultipoleAdapter.hpp"
52   #include "io/Globals.hpp"
53  
54   namespace OpenMD {
55    
56    Electrostatic::Electrostatic(): name_("Electrostatic"), initialized_(false),
57 <                                  forceField_(NULL), info_(NULL), haveCutoffRadius_(false),
58 <                                  haveDampingAlpha_(false), haveDielectric_(false),
57 >                                  forceField_(NULL), info_(NULL),
58 >                                  haveCutoffRadius_(false),
59 >                                  haveDampingAlpha_(false),
60 >                                  haveDielectric_(false),
61                                    haveElectroSpline_(false)
62 < {}
62 >  {}
63    
64    void Electrostatic::initialize() {
65 <
65 >    
66      Globals* simParams_ = info_->getSimParams();
67  
68      summationMap_["HARD"]               = esm_HARD;
69 +    summationMap_["NONE"]               = esm_HARD;
70      summationMap_["SWITCHING_FUNCTION"] = esm_SWITCHING_FUNCTION;
71      summationMap_["SHIFTED_POTENTIAL"]  = esm_SHIFTED_POTENTIAL;
72      summationMap_["SHIFTED_FORCE"]      = esm_SHIFTED_FORCE;    
# Line 114 | Line 119 | namespace OpenMD {
119          sprintf( painCave.errMsg,
120                   "Electrostatic::initialize: Unknown electrostaticSummationMethod.\n"
121                   "\t(Input file specified %s .)\n"
122 <                 "\telectrostaticSummationMethod must be one of: \"none\",\n"
122 >                 "\telectrostaticSummationMethod must be one of: \"hard\",\n"
123                   "\t\"shifted_potential\", \"shifted_force\", or \n"
124                   "\t\"reaction_field\".\n", myMethod.c_str() );
125          painCave.isFatal = 1;
# Line 247 | Line 252 | namespace OpenMD {
252        preRF2_ = 2.0 * preRF_;
253      }
254      
255 <    RealType dx = cutoffRadius_ / RealType(np_ - 1);
255 >    // Add a 2 angstrom safety window to deal with cutoffGroups that
256 >    // have charged atoms longer than the cutoffRadius away from each
257 >    // other.  Splining may not be the best choice here.  Direct calls
258 >    // to erfc might be preferrable.
259 >
260 >    RealType dx = (cutoffRadius_ + 2.0) / RealType(np_ - 1);
261      RealType rval;
262      vector<RealType> rvals;
263      vector<RealType> yvals;
# Line 271 | Line 281 | namespace OpenMD {
281      electrostaticAtomData.is_SplitDipole = false;
282      electrostaticAtomData.is_Quadrupole = false;
283  
284 <    if (atomType->isCharge()) {
275 <      GenericData* data = atomType->getPropertyByName("Charge");
284 >    FixedChargeAdapter fca = FixedChargeAdapter(atomType);
285  
286 <      if (data == NULL) {
278 <        sprintf( painCave.errMsg, "Electrostatic::addType could not find "
279 <                 "Charge\n"
280 <                 "\tparameters for atomType %s.\n",
281 <                 atomType->getName().c_str());
282 <        painCave.severity = OPENMD_ERROR;
283 <        painCave.isFatal = 1;
284 <        simError();                  
285 <      }
286 <      
287 <      DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
288 <      if (doubleData == NULL) {
289 <        sprintf( painCave.errMsg,
290 <                 "Electrostatic::addType could not convert GenericData to "
291 <                 "Charge for\n"
292 <                 "\tatom type %s\n", atomType->getName().c_str());
293 <        painCave.severity = OPENMD_ERROR;
294 <        painCave.isFatal = 1;
295 <        simError();          
296 <      }
286 >    if (fca.isFixedCharge()) {
287        electrostaticAtomData.is_Charge = true;
288 <      electrostaticAtomData.charge = doubleData->getData();          
288 >      electrostaticAtomData.charge = fca.getCharge();
289      }
290  
291 <    if (atomType->isDirectional()) {
292 <      DirectionalAtomType* daType = dynamic_cast<DirectionalAtomType*>(atomType);
293 <      
304 <      if (daType->isDipole()) {
305 <        GenericData* data = daType->getPropertyByName("Dipole");
306 <        
307 <        if (data == NULL) {
308 <          sprintf( painCave.errMsg,
309 <                   "Electrostatic::addType could not find Dipole\n"
310 <                   "\tparameters for atomType %s.\n",
311 <                   daType->getName().c_str());
312 <          painCave.severity = OPENMD_ERROR;
313 <          painCave.isFatal = 1;
314 <          simError();                  
315 <        }
316 <      
317 <        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
318 <        if (doubleData == NULL) {
319 <          sprintf( painCave.errMsg,
320 <                   "Electrostatic::addType could not convert GenericData to "
321 <                   "Dipole Moment\n"
322 <                   "\tfor atom type %s\n", daType->getName().c_str());
323 <          painCave.severity = OPENMD_ERROR;
324 <          painCave.isFatal = 1;
325 <          simError();          
326 <        }
291 >    MultipoleAdapter ma = MultipoleAdapter(atomType);
292 >    if (ma.isMultipole()) {
293 >      if (ma.isDipole()) {
294          electrostaticAtomData.is_Dipole = true;
295 <        electrostaticAtomData.dipole_moment = doubleData->getData();
295 >        electrostaticAtomData.dipole_moment = ma.getDipoleMoment();
296        }
297 <
331 <      if (daType->isSplitDipole()) {
332 <        GenericData* data = daType->getPropertyByName("SplitDipoleDistance");
333 <        
334 <        if (data == NULL) {
335 <          sprintf(painCave.errMsg,
336 <                  "Electrostatic::addType could not find SplitDipoleDistance\n"
337 <                  "\tparameter for atomType %s.\n",
338 <                  daType->getName().c_str());
339 <          painCave.severity = OPENMD_ERROR;
340 <          painCave.isFatal = 1;
341 <          simError();                  
342 <        }
343 <      
344 <        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
345 <        if (doubleData == NULL) {
346 <          sprintf( painCave.errMsg,
347 <                   "Electrostatic::addType could not convert GenericData to "
348 <                   "SplitDipoleDistance for\n"
349 <                   "\tatom type %s\n", daType->getName().c_str());
350 <          painCave.severity = OPENMD_ERROR;
351 <          painCave.isFatal = 1;
352 <          simError();          
353 <        }
297 >      if (ma.isSplitDipole()) {
298          electrostaticAtomData.is_SplitDipole = true;
299 <        electrostaticAtomData.split_dipole_distance = doubleData->getData();
299 >        electrostaticAtomData.split_dipole_distance = ma.getSplitDipoleDistance();
300        }
301 <
358 <      if (daType->isQuadrupole()) {
359 <        GenericData* data = daType->getPropertyByName("QuadrupoleMoments");
360 <        
361 <        if (data == NULL) {
362 <          sprintf( painCave.errMsg,
363 <                   "Electrostatic::addType could not find QuadrupoleMoments\n"
364 <                   "\tparameter for atomType %s.\n",
365 <                   daType->getName().c_str());
366 <          painCave.severity = OPENMD_ERROR;
367 <          painCave.isFatal = 1;
368 <          simError();                  
369 <        }
370 <        
301 >      if (ma.isQuadrupole()) {
302          // Quadrupoles in OpenMD are set as the diagonal elements
303          // of the diagonalized traceless quadrupole moment tensor.
304          // The column vectors of the unitary matrix that diagonalizes
305          // the quadrupole moment tensor become the eFrame (or the
306          // electrostatic version of the body-fixed frame.
376
377        Vector3dGenericData* v3dData = dynamic_cast<Vector3dGenericData*>(data);
378        if (v3dData == NULL) {
379          sprintf( painCave.errMsg,
380                   "Electrostatic::addType could not convert GenericData to "
381                   "Quadrupole Moments for\n"
382                   "\tatom type %s\n", daType->getName().c_str());
383          painCave.severity = OPENMD_ERROR;
384          painCave.isFatal = 1;
385          simError();          
386        }
307          electrostaticAtomData.is_Quadrupole = true;
308 <        electrostaticAtomData.quadrupole_moments = v3dData->getData();
308 >        electrostaticAtomData.quadrupole_moments = ma.getQuadrupoleMoments();
309        }
310      }
311      
392    AtomTypeProperties atp = atomType->getATP();    
312  
313      pair<map<int,AtomType*>::iterator,bool> ret;    
314 <    ret = ElectrostaticList.insert( pair<int,AtomType*>(atp.ident, atomType) );
314 >    ret = ElectrostaticList.insert( pair<int,AtomType*>(atomType->getIdent(),
315 >                                                        atomType) );
316      if (ret.second == false) {
317        sprintf( painCave.errMsg,
318                 "Electrostatic already had a previous entry with ident %d\n",
319 <               atp.ident);
319 >               atomType->getIdent() );
320        painCave.severity = OPENMD_INFO;
321        painCave.isFatal = 0;
322        simError();        
# Line 444 | Line 364 | namespace OpenMD {
364      RealType ct_i, ct_j, ct_ij, a1;
365      RealType riji, ri, ri2, ri3, ri4;
366      RealType pref, vterm, epot, dudr;
367 +    RealType vpair(0.0);
368      RealType scale, sc2;
369      RealType pot_term, preVal, rfVal;
370      RealType c2ri, c3ri, c4rij, cti3, ctj3, ctidotj;
371      RealType preSw, preSwSc;
372      RealType c1, c2, c3, c4;
373 <    RealType erfcVal, derfcVal;
373 >    RealType erfcVal(1.0), derfcVal(0.0);
374      RealType BigR;
375 +    RealType two(2.0), three(3.0);
376  
377      Vector3d Q_i, Q_j;
378      Vector3d ux_i, uy_i, uz_i;
# Line 460 | Line 382 | namespace OpenMD {
382      Vector3d rhatdot2, rhatc4;
383      Vector3d dVdr;
384  
385 +    // variables for indirect (reaction field) interactions for excluded pairs:
386 +    RealType indirect_Pot(0.0);
387 +    RealType indirect_vpair(0.0);
388 +    Vector3d indirect_dVdr(V3Zero);
389 +    Vector3d indirect_duduz_i(V3Zero), indirect_duduz_j(V3Zero);
390 +
391      pair<RealType, RealType> res;
392      
393      if (!initialized_) initialize();
# Line 484 | Line 412 | namespace OpenMD {
412      bool j_is_SplitDipole = data2.is_SplitDipole;
413      bool j_is_Quadrupole = data2.is_Quadrupole;
414      
415 <    if (i_is_Charge)
415 >    if (i_is_Charge) {
416        q_i = data1.charge;
417 +      if (idat.excluded) {
418 +        *(idat.skippedCharge2) += q_i;
419 +      }
420 +    }
421  
422      if (i_is_Dipole) {
423        mu_i = data1.dipole_moment;
# Line 518 | Line 450 | namespace OpenMD {
450        duduz_i = V3Zero;
451      }
452  
453 <    if (j_is_Charge)
453 >    if (j_is_Charge) {
454        q_j = data2.charge;
455 +      if (idat.excluded) {
456 +        *(idat.skippedCharge1) += q_j;
457 +      }
458 +    }
459  
460 +
461      if (j_is_Dipole) {
462        mu_j = data2.dipole_moment;
463        uz_j = idat.eFrame2->getColumn(2);
# Line 560 | Line 497 | namespace OpenMD {
497        if (j_is_Charge) {
498          if (screeningMethod_ == DAMPED) {
499            // assemble the damping variables
500 <          res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
501 <          erfcVal = res.first;
502 <          derfcVal = res.second;
500 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
501 >          //erfcVal = res.first;
502 >          //derfcVal = res.second;
503 >
504 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
505 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
506 >
507            c1 = erfcVal * riji;
508            c2 = (-derfcVal + c1) * riji;
509          } else {
# Line 581 | Line 522 | namespace OpenMD {
522            dudr  =  *(idat.sw)  * preVal * (c2c_ - c2);
523  
524          } else if (summationMethod_ == esm_REACTION_FIELD) {
525 <          rfVal =  *(idat.electroMult) * preRF_ *  *(idat.rij)  *  *(idat.rij) ;
525 >          rfVal = preRF_ *  *(idat.rij)  *  *(idat.rij);
526 >
527            vterm = preVal * ( riji + rfVal );            
528            dudr  =  *(idat.sw)  * preVal * ( 2.0 * rfVal - riji ) * riji;
529 +          
530 +          // if this is an excluded pair, there are still indirect
531 +          // interactions via the reaction field we must worry about:
532  
533 +          if (idat.excluded) {
534 +            indirect_vpair += preVal * rfVal;
535 +            indirect_Pot += *(idat.sw) * preVal * rfVal;
536 +            indirect_dVdr += *(idat.sw)  * preVal * two * rfVal  * riji * rhat;
537 +          }
538 +          
539          } else {
589          vterm = preVal * riji * erfcVal;            
540  
541 +          vterm = preVal * riji * erfcVal;          
542            dudr  = -  *(idat.sw)  * preVal * c2;
543  
544          }
594
595        *(idat.vpair) += vterm;
596        epot +=  *(idat.sw)  * vterm;
545  
546 <        dVdr += dudr * rhat;      
546 >        vpair += vterm;
547 >        epot +=  *(idat.sw)  * vterm;
548 >        dVdr += dudr * rhat;                
549        }
550  
551        if (j_is_Dipole) {
# Line 608 | Line 558 | namespace OpenMD {
558            ri3 = ri2 * riji;
559      
560            vterm = - pref * ct_j * ( ri2 - preRF2_ *  *(idat.rij)  );
561 <          *(idat.vpair) += vterm;
561 >          vpair += vterm;
562            epot +=  *(idat.sw)  * vterm;
563  
564 <          dVdr +=  -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
564 >          dVdr +=  -preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j);
565            duduz_j += -preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );  
566  
567 +          // Even if we excluded this pair from direct interactions,
568 +          // we still have the reaction-field-mediated charge-dipole
569 +          // interaction:
570 +
571 +          if (idat.excluded) {
572 +            indirect_vpair += pref * ct_j * preRF2_ * *(idat.rij);
573 +            indirect_Pot += preSw * ct_j * preRF2_ * *(idat.rij);
574 +            indirect_dVdr += preSw * preRF2_ * uz_j;
575 +            indirect_duduz_j += preSw * rhat * preRF2_ *  *(idat.rij);
576 +          }
577 +                      
578          } else {
579            // determine the inverse r used if we have split dipoles
580            if (j_is_SplitDipole) {
# Line 629 | Line 590 | namespace OpenMD {
590  
591            if (screeningMethod_ == DAMPED) {
592              // assemble the damping variables
593 <            res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
594 <            erfcVal = res.first;
595 <            derfcVal = res.second;
593 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
594 >            //erfcVal = res.first;
595 >            //derfcVal = res.second;
596 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
597 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
598              c1 = erfcVal * ri;
599              c2 = (-derfcVal + c1) * ri;
600              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 646 | Line 609 | namespace OpenMD {
609            // calculate the potential
610            pot_term =  scale * c2;
611            vterm = -pref * ct_j * pot_term;
612 <          *(idat.vpair) += vterm;
612 >          vpair += vterm;
613            epot +=  *(idat.sw)  * vterm;
614              
615            // calculate derivatives for forces and torques
# Line 666 | Line 629 | namespace OpenMD {
629            
630          if (screeningMethod_ == DAMPED) {
631            // assemble the damping variables
632 <          res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
633 <          erfcVal = res.first;
634 <          derfcVal = res.second;
632 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
633 >          //erfcVal = res.first;
634 >          //derfcVal = res.second;
635 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
636 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
637            c1 = erfcVal * riji;
638            c2 = (-derfcVal + c1) * riji;
639            c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji;
# Line 685 | Line 650 | namespace OpenMD {
650          c2ri = c2 * riji;
651          c3ri = c3 * riji;
652          c4rij = c4 *  *(idat.rij) ;
653 <        rhatdot2 = 2.0 * rhat * c3;
653 >        rhatdot2 = two * rhat * c3;
654          rhatc4 = rhat * c4rij;
655  
656          // calculate the potential
# Line 693 | Line 658 | namespace OpenMD {
658                       qyy_j * (cy2*c3 - c2ri) +
659                       qzz_j * (cz2*c3 - c2ri) );
660          vterm = pref * pot_term;
661 <        *(idat.vpair) += vterm;
661 >        vpair += vterm;
662          epot +=  *(idat.sw)  * vterm;
663                  
664          // calculate derivatives for the forces and torques
665  
666 <        dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (2.0*cx_j*ux_j + rhat)*c3ri) +
667 <                           qyy_j* (cy2*rhatc4 - (2.0*cy_j*uy_j + rhat)*c3ri) +
668 <                           qzz_j* (cz2*rhatc4 - (2.0*cz_j*uz_j + rhat)*c3ri));
666 >        dVdr += -preSw * ( qxx_j* (cx2*rhatc4 - (two*cx_j*ux_j + rhat)*c3ri) +
667 >                           qyy_j* (cy2*rhatc4 - (two*cy_j*uy_j + rhat)*c3ri) +
668 >                           qzz_j* (cz2*rhatc4 - (two*cz_j*uz_j + rhat)*c3ri));
669                            
670          dudux_j += preSw * qxx_j * cx_j * rhatdot2;
671          duduy_j += preSw * qyy_j * cy_j * rhatdot2;
# Line 721 | Line 686 | namespace OpenMD {
686            ri3 = ri2 * riji;
687  
688            vterm = pref * ct_i * ( ri2 - preRF2_ *  *(idat.rij)  );
689 <          *(idat.vpair) += vterm;
689 >          vpair += vterm;
690            epot +=  *(idat.sw)  * vterm;
691            
692 <          dVdr += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);
692 >          dVdr += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_ * uz_i);
693            
694            duduz_i += preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );
695 +
696 +          // Even if we excluded this pair from direct interactions,
697 +          // we still have the reaction-field-mediated charge-dipole
698 +          // interaction:
699 +
700 +          if (idat.excluded) {
701 +            indirect_vpair += -pref * ct_i * preRF2_ * *(idat.rij);
702 +            indirect_Pot += -preSw * ct_i * preRF2_ * *(idat.rij);
703 +            indirect_dVdr += -preSw * preRF2_ * uz_i;
704 +            indirect_duduz_i += -preSw * rhat * preRF2_ *  *(idat.rij);
705 +          }
706              
707          } else {
708            
# Line 744 | Line 720 | namespace OpenMD {
720              
721            if (screeningMethod_ == DAMPED) {
722              // assemble the damping variables
723 <            res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
724 <            erfcVal = res.first;
725 <            derfcVal = res.second;
723 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
724 >            //erfcVal = res.first;
725 >            //derfcVal = res.second;
726 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
727 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
728              c1 = erfcVal * ri;
729              c2 = (-derfcVal + c1) * ri;
730              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 761 | Line 739 | namespace OpenMD {
739            // calculate the potential
740            pot_term = c2 * scale;
741            vterm = pref * ct_i * pot_term;
742 <          *(idat.vpair) += vterm;
742 >          vpair += vterm;
743            epot +=  *(idat.sw)  * vterm;
744  
745            // calculate derivatives for the forces and torques
# Line 784 | Line 762 | namespace OpenMD {
762  
763            vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) -
764                             preRF2_ * ct_ij );
765 <          *(idat.vpair) += vterm;
765 >          vpair += vterm;
766            epot +=  *(idat.sw)  * vterm;
767              
768            a1 = 5.0 * ct_i * ct_j - ct_ij;
769              
770 <          dVdr += preSw * 3.0 * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i);
770 >          dVdr += preSw * three * ri4 * (a1 * rhat - ct_i * uz_j - ct_j * uz_i);
771  
772 <          duduz_i += preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
773 <          duduz_j += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_*uz_i);
772 >          duduz_i += preSw * (ri3 * (uz_j - three * ct_j * rhat) - preRF2_*uz_j);
773 >          duduz_j += preSw * (ri3 * (uz_i - three * ct_i * rhat) - preRF2_*uz_i);
774  
775 +          if (idat.excluded) {
776 +            indirect_vpair +=  - pref * preRF2_ * ct_ij;
777 +            indirect_Pot +=    - preSw * preRF2_ * ct_ij;
778 +            indirect_duduz_i += -preSw * preRF2_ * uz_j;
779 +            indirect_duduz_j += -preSw * preRF2_ * uz_i;
780 +          }
781 +
782          } else {
783            
784            if (i_is_SplitDipole) {
# Line 816 | Line 801 | namespace OpenMD {
801            }
802            if (screeningMethod_ == DAMPED) {
803              // assemble damping variables
804 <            res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
805 <            erfcVal = res.first;
806 <            derfcVal = res.second;
804 >            //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
805 >            //erfcVal = res.first;
806 >            //derfcVal = res.second;
807 >            erfcVal = erfc(dampingAlpha_ * *(idat.rij));
808 >            derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
809              c1 = erfcVal * ri;
810              c2 = (-derfcVal + c1) * ri;
811              c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * ri;
# Line 843 | Line 830 | namespace OpenMD {
830            // calculate the potential
831            pot_term = (ct_ij * c2ri - ctidotj * c3);
832            vterm = pref * pot_term;
833 <          *(idat.vpair) += vterm;
833 >          vpair += vterm;
834            epot +=  *(idat.sw)  * vterm;
835  
836            // calculate derivatives for the forces and torques
# Line 867 | Line 854 | namespace OpenMD {
854  
855          if (screeningMethod_ == DAMPED) {
856            // assemble the damping variables
857 <          res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
858 <          erfcVal = res.first;
859 <          derfcVal = res.second;
857 >          //res = erfcSpline_->getValueAndDerivativeAt( *(idat.rij) );
858 >          //erfcVal = res.first;
859 >          //derfcVal = res.second;
860 >          erfcVal = erfc(dampingAlpha_ * *(idat.rij));
861 >          derfcVal = - alphaPi_ * exp(-alpha2_ * *(idat.r2));
862            c1 = erfcVal * riji;
863            c2 = (-derfcVal + c1) * riji;
864            c3 = -2.0 * derfcVal * alpha2_ + 3.0 * c2 * riji;
# Line 886 | Line 875 | namespace OpenMD {
875          c2ri = c2 * riji;
876          c3ri = c3 * riji;
877          c4rij = c4 *  *(idat.rij) ;
878 <        rhatdot2 = 2.0 * rhat * c3;
878 >        rhatdot2 = two * rhat * c3;
879          rhatc4 = rhat * c4rij;
880  
881          // calculate the potential
# Line 895 | Line 884 | namespace OpenMD {
884                       qzz_i * (cz2 * c3 - c2ri) );
885          
886          vterm = pref * pot_term;
887 <        *(idat.vpair) += vterm;
887 >        vpair += vterm;
888          epot +=  *(idat.sw)  * vterm;
889  
890          // calculate the derivatives for the forces and torques
891  
892 <        dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (2.0*cx_i*ux_i + rhat)*c3ri) +
893 <                          qyy_i* (cy2*rhatc4 - (2.0*cy_i*uy_i + rhat)*c3ri) +
894 <                          qzz_i* (cz2*rhatc4 - (2.0*cz_i*uz_i + rhat)*c3ri));
892 >        dVdr += -preSw * (qxx_i* (cx2*rhatc4 - (two*cx_i*ux_i + rhat)*c3ri) +
893 >                          qyy_i* (cy2*rhatc4 - (two*cy_i*uy_i + rhat)*c3ri) +
894 >                          qzz_i* (cz2*rhatc4 - (two*cz_i*uz_i + rhat)*c3ri));
895  
896          dudux_i += preSw * qxx_i * cx_i *  rhatdot2;
897          duduy_i += preSw * qyy_i * cy_i *  rhatdot2;
# Line 910 | Line 899 | namespace OpenMD {
899        }
900      }
901  
913    (*(idat.pot))[ELECTROSTATIC_FAMILY] += epot;
914    *(idat.f1) += dVdr;
902  
903 <    if (i_is_Dipole || i_is_Quadrupole)
904 <      *(idat.t1) -= cross(uz_i, duduz_i);
905 <    if (i_is_Quadrupole) {
906 <      *(idat.t1) -= cross(ux_i, dudux_i);
907 <      *(idat.t1) -= cross(uy_i, duduy_i);
908 <    }
909 <    
910 <    if (j_is_Dipole || j_is_Quadrupole)
911 <      *(idat.t2) -= cross(uz_j, duduz_j);
912 <    if (j_is_Quadrupole) {
913 <      *(idat.t2) -= cross(uz_j, dudux_j);
914 <      *(idat.t2) -= cross(uz_j, duduy_j);
915 <    }
903 >    if (!idat.excluded) {
904 >      *(idat.vpair) += vpair;
905 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += epot;
906 >      *(idat.f1) += dVdr;
907 >      
908 >      if (i_is_Dipole || i_is_Quadrupole)
909 >        *(idat.t1) -= cross(uz_i, duduz_i);
910 >      if (i_is_Quadrupole) {
911 >        *(idat.t1) -= cross(ux_i, dudux_i);
912 >        *(idat.t1) -= cross(uy_i, duduy_i);
913 >      }
914 >      
915 >      if (j_is_Dipole || j_is_Quadrupole)
916 >        *(idat.t2) -= cross(uz_j, duduz_j);
917 >      if (j_is_Quadrupole) {
918 >        *(idat.t2) -= cross(uz_j, dudux_j);
919 >        *(idat.t2) -= cross(uz_j, duduy_j);
920 >      }
921 >
922 >    } else {
923 >
924 >      // only accumulate the forces and torques resulting from the
925 >      // indirect reaction field terms.
926  
927 <    return;
928 <  }  
929 <
933 <  void Electrostatic::calcSkipCorrection(InteractionData &idat) {
934 <
935 <    if (!initialized_) initialize();
936 <    
937 <    ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first];
938 <    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second];
939 <    
940 <    // logicals
941 <
942 <    bool i_is_Charge = data1.is_Charge;
943 <    bool i_is_Dipole = data1.is_Dipole;
944 <
945 <    bool j_is_Charge = data2.is_Charge;
946 <    bool j_is_Dipole = data2.is_Dipole;
947 <
948 <    RealType q_i, q_j;
949 <    
950 <    // The skippedCharge computation is needed by the real-space cutoff methods
951 <    // (i.e. shifted force and shifted potential)
952 <
953 <    if (i_is_Charge) {
954 <      q_i = data1.charge;
955 <      *(idat.skippedCharge2) += q_i;
956 <    }
957 <
958 <    if (j_is_Charge) {
959 <      q_j = data2.charge;
960 <      *(idat.skippedCharge1) += q_j;
961 <    }
962 <
963 <    // the rest of this function should only be necessary for reaction field.
964 <
965 <    if (summationMethod_ == esm_REACTION_FIELD) {
966 <      RealType riji, ri2, ri3;
967 <      RealType mu_i, ct_i;
968 <      RealType mu_j, ct_j;
969 <      RealType preVal, rfVal, vterm, dudr, pref, myPot(0.0);
970 <      Vector3d dVdr, uz_i, uz_j, duduz_i, duduz_j, rhat;
971 <
972 <      // some variables we'll need independent of electrostatic type:
927 >      *(idat.vpair) += indirect_vpair;
928 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot;
929 >      *(idat.f1) += indirect_dVdr;
930        
974      riji = 1.0 /  *(idat.rij) ;
975      rhat =  *(idat.d)  * riji;
976
977      if (i_is_Dipole) {
978        mu_i = data1.dipole_moment;
979        uz_i = idat.eFrame1->getColumn(2);      
980        ct_i = dot(uz_i, rhat);
981        duduz_i = V3Zero;
982      }
983            
984      if (j_is_Dipole) {
985        mu_j = data2.dipole_moment;
986        uz_j = idat.eFrame2->getColumn(2);      
987        ct_j = dot(uz_j, rhat);
988        duduz_j = V3Zero;
989      }
990    
991      if (i_is_Charge) {
992        if (j_is_Charge) {
993          preVal =  *(idat.electroMult) * pre11_ * q_i * q_j;
994          rfVal = preRF_ *  *(idat.rij)  *  *(idat.rij) ;
995          vterm = preVal * rfVal;
996          myPot +=  *(idat.sw)  * vterm;        
997          dudr  =  *(idat.sw)  * preVal * 2.0 * rfVal * riji;        
998          dVdr += dudr * rhat;
999        }
1000        
1001        if (j_is_Dipole) {
1002          ri2 = riji * riji;
1003          ri3 = ri2 * riji;        
1004          pref =  *(idat.electroMult) * pre12_ * q_i * mu_j;
1005          vterm = - pref * ct_j * ( ri2 - preRF2_ *  *(idat.rij)  );
1006          myPot +=  *(idat.sw)  * vterm;        
1007          dVdr += - *(idat.sw)  * pref * ( ri3 * ( uz_j - 3.0 * ct_j * rhat) - preRF2_ * uz_j);
1008          duduz_j += - *(idat.sw)  * pref * rhat * (ri2 - preRF2_ *  *(idat.rij) );
1009        }
1010      }
1011      if (i_is_Dipole) {
1012        if (j_is_Charge) {
1013          ri2 = riji * riji;
1014          ri3 = ri2 * riji;        
1015          pref =  *(idat.electroMult) * pre12_ * q_j * mu_i;
1016          vterm = - pref * ct_i * ( ri2 - preRF2_ *  *(idat.rij)  );
1017          myPot +=  *(idat.sw)  * vterm;        
1018          dVdr +=  *(idat.sw)  * pref * ( ri3 * ( uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);      
1019          duduz_i +=  *(idat.sw)  * pref * rhat * (ri2 - preRF2_ *  *(idat.rij));
1020        }
1021      }
1022      
1023      // accumulate the forces and torques resulting from the self term
1024      (*(idat.pot))[ELECTROSTATIC_FAMILY] += myPot;
1025      *(idat.f1) += dVdr;
1026      
931        if (i_is_Dipole)
932 <        *(idat.t1) -= cross(uz_i, duduz_i);
932 >        *(idat.t1) -= cross(uz_i, indirect_duduz_i);
933        if (j_is_Dipole)
934 <        *(idat.t2) -= cross(uz_j, duduz_j);
934 >        *(idat.t2) -= cross(uz_j, indirect_duduz_j);
935      }
936 <  }
936 >
937 >
938 >    return;
939 >  }  
940      
941    void Electrostatic::calcSelfCorrection(SelfData &sdat) {
942      RealType mu1, preVal, chg1, self;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines