ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/nonbonded/Electrostatic.cpp
(Generate patch)

Comparing branches/development/src/nonbonded/Electrostatic.cpp (file contents):
Revision 1587 by gezelter, Fri Jul 8 20:25:32 2011 UTC vs.
Revision 1721 by gezelter, Thu May 24 14:17:42 2012 UTC

# Line 36 | Line 36
36   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
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),
# Line 64 | Line 70 | namespace OpenMD {
70      Globals* simParams_ = info_->getSimParams();
71  
72      summationMap_["HARD"]               = esm_HARD;
73 +    summationMap_["NONE"]               = esm_HARD;
74      summationMap_["SWITCHING_FUNCTION"] = esm_SWITCHING_FUNCTION;
75      summationMap_["SHIFTED_POTENTIAL"]  = esm_SHIFTED_POTENTIAL;
76      summationMap_["SHIFTED_FORCE"]      = esm_SHIFTED_FORCE;    
# Line 116 | Line 123 | namespace OpenMD {
123          sprintf( painCave.errMsg,
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 249 | 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 273 | Line 285 | namespace OpenMD {
285      electrostaticAtomData.is_SplitDipole = false;
286      electrostaticAtomData.is_Quadrupole = false;
287  
288 <    if (atomType->isCharge()) {
277 <      GenericData* data = atomType->getPropertyByName("Charge");
288 >    FixedChargeAdapter fca = FixedChargeAdapter(atomType);
289  
290 <      if (data == NULL) {
280 <        sprintf( painCave.errMsg, "Electrostatic::addType could not find "
281 <                 "Charge\n"
282 <                 "\tparameters for atomType %s.\n",
283 <                 atomType->getName().c_str());
284 <        painCave.severity = OPENMD_ERROR;
285 <        painCave.isFatal = 1;
286 <        simError();                  
287 <      }
288 <      
289 <      DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
290 <      if (doubleData == NULL) {
291 <        sprintf( painCave.errMsg,
292 <                 "Electrostatic::addType could not convert GenericData to "
293 <                 "Charge for\n"
294 <                 "\tatom type %s\n", atomType->getName().c_str());
295 <        painCave.severity = OPENMD_ERROR;
296 <        painCave.isFatal = 1;
297 <        simError();          
298 <      }
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 <      
306 <      if (daType->isDipole()) {
307 <        GenericData* data = daType->getPropertyByName("Dipole");
308 <        
309 <        if (data == NULL) {
310 <          sprintf( painCave.errMsg,
311 <                   "Electrostatic::addType could not find Dipole\n"
312 <                   "\tparameters for atomType %s.\n",
313 <                   daType->getName().c_str());
314 <          painCave.severity = OPENMD_ERROR;
315 <          painCave.isFatal = 1;
316 <          simError();                  
317 <        }
318 <      
319 <        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
320 <        if (doubleData == NULL) {
321 <          sprintf( painCave.errMsg,
322 <                   "Electrostatic::addType could not convert GenericData to "
323 <                   "Dipole Moment\n"
324 <                   "\tfor atom type %s\n", daType->getName().c_str());
325 <          painCave.severity = OPENMD_ERROR;
326 <          painCave.isFatal = 1;
327 <          simError();          
328 <        }
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 <
333 <      if (daType->isSplitDipole()) {
334 <        GenericData* data = daType->getPropertyByName("SplitDipoleDistance");
335 <        
336 <        if (data == NULL) {
337 <          sprintf(painCave.errMsg,
338 <                  "Electrostatic::addType could not find SplitDipoleDistance\n"
339 <                  "\tparameter for atomType %s.\n",
340 <                  daType->getName().c_str());
341 <          painCave.severity = OPENMD_ERROR;
342 <          painCave.isFatal = 1;
343 <          simError();                  
344 <        }
345 <      
346 <        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
347 <        if (doubleData == NULL) {
348 <          sprintf( painCave.errMsg,
349 <                   "Electrostatic::addType could not convert GenericData to "
350 <                   "SplitDipoleDistance for\n"
351 <                   "\tatom type %s\n", daType->getName().c_str());
352 <          painCave.severity = OPENMD_ERROR;
353 <          painCave.isFatal = 1;
354 <          simError();          
355 <        }
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 <
360 <      if (daType->isQuadrupole()) {
361 <        GenericData* data = daType->getPropertyByName("QuadrupoleMoments");
362 <        
363 <        if (data == NULL) {
364 <          sprintf( painCave.errMsg,
365 <                   "Electrostatic::addType could not find QuadrupoleMoments\n"
366 <                   "\tparameter for atomType %s.\n",
367 <                   daType->getName().c_str());
368 <          painCave.severity = OPENMD_ERROR;
369 <          painCave.isFatal = 1;
370 <          simError();                  
371 <        }
372 <        
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.
378
379        Vector3dGenericData* v3dData = dynamic_cast<Vector3dGenericData*>(data);
380        if (v3dData == NULL) {
381          sprintf( painCave.errMsg,
382                   "Electrostatic::addType could not convert GenericData to "
383                   "Quadrupole Moments for\n"
384                   "\tatom type %s\n", daType->getName().c_str());
385          painCave.severity = OPENMD_ERROR;
386          painCave.isFatal = 1;
387          simError();          
388        }
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    
# Line 454 | Line 433 | namespace OpenMD {
433      RealType c1, c2, c3, c4;
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 471 | Line 451 | namespace OpenMD {
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.atypes.first];
# Line 487 | 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;
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        }
# Line 532 | Line 523 | namespace OpenMD {
523      }
524  
525      if (j_is_Charge) {
526 <      q_j = data2.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        }
# Line 570 | 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 578 | 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 610 | Line 614 | namespace OpenMD {
614            if (idat.excluded) {
615              indirect_vpair += preVal * rfVal;
616              indirect_Pot += *(idat.sw) * preVal * rfVal;
617 <            indirect_dVdr += *(idat.sw)  * preVal * 2.0 * rfVal  * riji * rhat;
617 >            indirect_dVdr += *(idat.sw)  * preVal * two * rfVal  * riji * rhat;
618            }
619            
620          } else {
621  
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 +        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          vpair += vterm;
646          epot +=  *(idat.sw)  * vterm;
# Line 638 | Line 660 | namespace OpenMD {
660            vpair += vterm;
661            epot +=  *(idat.sw)  * vterm;
662  
663 <          dVdr +=  -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
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,
# Line 667 | 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 704 | Line 728 | namespace OpenMD {
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 723 | Line 749 | namespace OpenMD {
749          c2ri = c2 * riji;
750          c3ri = c3 * riji;
751          c4rij = c4 *  *(idat.rij) ;
752 <        rhatdot2 = 2.0 * rhat * c3;
752 >        rhatdot2 = two * rhat * c3;
753          rhatc4 = rhat * c4rij;
754  
755          // calculate the potential
# Line 736 | Line 762 | namespace OpenMD {
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 762 | Line 788 | namespace OpenMD {
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) );
794  
# Line 793 | 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 838 | Line 866 | namespace OpenMD {
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;
# Line 872 | 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 923 | Line 953 | namespace OpenMD {
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 942 | Line 974 | namespace OpenMD {
974          c2ri = c2 * riji;
975          c3ri = c3 * riji;
976          c4rij = c4 *  *(idat.rij) ;
977 <        rhatdot2 = 2.0 * rhat * c3;
977 >        rhatdot2 = two * rhat * c3;
978          rhatc4 = rhat * c4rij;
979  
980          // calculate the potential
# Line 956 | Line 988 | namespace OpenMD {
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 990 | Line 1022 | namespace OpenMD {
1022  
1023        // only accumulate the forces and torques resulting from the
1024        // indirect reaction field terms.
1025 +
1026        *(idat.vpair) += indirect_vpair;
1027        (*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot;
1028        *(idat.f1) += indirect_dVdr;
# Line 1003 | Line 1036 | namespace OpenMD {
1036  
1037      return;
1038    }  
1006
1007  void Electrostatic::calcSkipCorrection(InteractionData &idat) {
1008
1009    if (!initialized_) initialize();
1039      
1011    ElectrostaticAtomData data1 = ElectrostaticMap[idat.atypes.first];
1012    ElectrostaticAtomData data2 = ElectrostaticMap[idat.atypes.second];
1013    
1014    // logicals
1015
1016    bool i_is_Charge = data1.is_Charge;
1017    bool i_is_Dipole = data1.is_Dipole;
1018
1019    bool j_is_Charge = data2.is_Charge;
1020    bool j_is_Dipole = data2.is_Dipole;
1021
1022    RealType q_i, q_j;
1023
1024    // The skippedCharge computation is needed by the real-space
1025    // cutoff methods (i.e. shifted force and shifted potential)
1026      
1027    if (i_is_Charge) {
1028      q_i = data1.charge;
1029      *(idat.skippedCharge2) += q_i;
1030    }
1031    
1032    if (j_is_Charge) {
1033      q_j = data2.charge;
1034      *(idat.skippedCharge1) += q_j;
1035    }
1036
1037    // the rest of this function should only be necessary for reaction field.
1038
1039    if (summationMethod_ == esm_REACTION_FIELD) {
1040      RealType riji, ri2, ri3;
1041      RealType mu_i, ct_i;
1042      RealType mu_j, ct_j;
1043      RealType preVal, rfVal, vterm, dudr, pref, myPot(0.0);
1044      Vector3d dVdr, uz_i, uz_j, duduz_i, duduz_j, rhat;
1045
1046      // some variables we'll need independent of electrostatic type:
1047      
1048      riji = 1.0 /  *(idat.rij) ;
1049      rhat =  *(idat.d)  * riji;
1050
1051      if (i_is_Dipole) {
1052        mu_i = data1.dipole_moment;
1053        uz_i = idat.eFrame1->getColumn(2);      
1054        ct_i = dot(uz_i, rhat);
1055        duduz_i = V3Zero;
1056      }
1057            
1058      if (j_is_Dipole) {
1059        mu_j = data2.dipole_moment;
1060        uz_j = idat.eFrame2->getColumn(2);      
1061        ct_j = dot(uz_j, rhat);
1062        duduz_j = V3Zero;
1063      }
1064    
1065      if (i_is_Charge) {
1066        if (j_is_Charge) {
1067          preVal =  *(idat.electroMult) * pre11_ * q_i * q_j;
1068          rfVal = preRF_ *  *(idat.rij)  *  *(idat.rij) ;
1069          vterm = preVal * rfVal;
1070          myPot +=  *(idat.sw)  * vterm;        
1071          dudr  =  *(idat.sw)  * preVal * 2.0 * rfVal * riji;        
1072          dVdr += dudr * rhat;
1073        }
1074        
1075        if (j_is_Dipole) {
1076          ri2 = riji * riji;
1077          ri3 = ri2 * riji;        
1078          pref =  *(idat.electroMult) * pre12_ * q_i * mu_j;
1079          vterm = - pref * ct_j * ( ri2 - preRF2_ *  *(idat.rij)  );
1080          myPot +=  *(idat.sw)  * vterm;        
1081          dVdr += - *(idat.sw)  * pref * ( ri3 * ( uz_j - 3.0 * ct_j * rhat) - preRF2_ * uz_j);
1082          duduz_j += - *(idat.sw)  * pref * rhat * (ri2 - preRF2_ *  *(idat.rij) );
1083        }
1084      }
1085      if (i_is_Dipole) {
1086        if (j_is_Charge) {
1087          ri2 = riji * riji;
1088          ri3 = ri2 * riji;        
1089          pref =  *(idat.electroMult) * pre12_ * q_j * mu_i;
1090          vterm = - pref * ct_i * ( ri2 - preRF2_ *  *(idat.rij)  );
1091          myPot +=  *(idat.sw)  * vterm;        
1092          dVdr +=  *(idat.sw)  * pref * ( ri3 * ( uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);      
1093          duduz_i +=  *(idat.sw)  * pref * rhat * (ri2 - preRF2_ *  *(idat.rij));
1094        }
1095      }
1096      
1097      // accumulate the forces and torques resulting from the self term
1098      (*(idat.pot))[ELECTROSTATIC_FAMILY] += myPot;
1099      *(idat.f1) += dVdr;
1100      
1101      if (i_is_Dipole)
1102        *(idat.t1) -= cross(uz_i, duduz_i);
1103      if (j_is_Dipole)
1104        *(idat.t2) -= cross(uz_j, duduz_j);
1105    }
1106  }
1107    
1040    void Electrostatic::calcSelfCorrection(SelfData &sdat) {
1041      RealType mu1, preVal, chg1, self;
1042      
# Line 1131 | Line 1063 | namespace OpenMD {
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 + *(sdat.skippedCharge)) * pre11_;
1069          } else {        

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines