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 1601 by gezelter, Thu Aug 4 20:04:35 2011 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).                        
40   */
# Line 52 | Line 52 | namespace OpenMD {
52   namespace OpenMD {
53    
54    Electrostatic::Electrostatic(): name_("Electrostatic"), initialized_(false),
55 <                                  forceField_(NULL), info_(NULL), haveCutoffRadius_(false),
56 <                                  haveDampingAlpha_(false), haveDielectric_(false),
55 >                                  forceField_(NULL), info_(NULL),
56 >                                  haveCutoffRadius_(false),
57 >                                  haveDampingAlpha_(false),
58 >                                  haveDielectric_(false),
59                                    haveElectroSpline_(false)
60 < {}
60 >  {}
61    
62    void Electrostatic::initialize() {
63 <
63 >    
64      Globals* simParams_ = info_->getSimParams();
65  
66      summationMap_["HARD"]               = esm_HARD;
# Line 444 | Line 446 | namespace OpenMD {
446      RealType ct_i, ct_j, ct_ij, a1;
447      RealType riji, ri, ri2, ri3, ri4;
448      RealType pref, vterm, epot, dudr;
449 +    RealType vpair(0.0);
450      RealType scale, sc2;
451      RealType pot_term, preVal, rfVal;
452      RealType c2ri, c3ri, c4rij, cti3, ctj3, ctidotj;
453      RealType preSw, preSwSc;
454      RealType c1, c2, c3, c4;
455 <    RealType erfcVal, derfcVal;
455 >    RealType erfcVal(1.0), derfcVal(0.0);
456      RealType BigR;
457  
458      Vector3d Q_i, Q_j;
# Line 460 | Line 463 | namespace OpenMD {
463      Vector3d rhatdot2, rhatc4;
464      Vector3d dVdr;
465  
466 +    // variables for indirect (reaction field) interactions for excluded pairs:
467 +    RealType indirect_Pot(0.0);
468 +    RealType indirect_vpair(0.0);
469 +    Vector3d indirect_dVdr(V3Zero);
470 +    Vector3d indirect_duduz_i(V3Zero), indirect_duduz_j(V3Zero);
471 +
472      pair<RealType, RealType> res;
473      
474      if (!initialized_) initialize();
# Line 484 | Line 493 | namespace OpenMD {
493      bool j_is_SplitDipole = data2.is_SplitDipole;
494      bool j_is_Quadrupole = data2.is_Quadrupole;
495      
496 <    if (i_is_Charge)
496 >    if (i_is_Charge) {
497        q_i = data1.charge;
498 +      if (idat.excluded) {
499 +        *(idat.skippedCharge2) += q_i;
500 +      }
501 +    }
502  
503      if (i_is_Dipole) {
504        mu_i = data1.dipole_moment;
# Line 518 | Line 531 | namespace OpenMD {
531        duduz_i = V3Zero;
532      }
533  
534 <    if (j_is_Charge)
534 >    if (j_is_Charge) {
535        q_j = data2.charge;
536 +      if (idat.excluded) {
537 +        *(idat.skippedCharge1) += q_j;
538 +      }
539 +    }
540 +
541  
542      if (j_is_Dipole) {
543        mu_j = data2.dipole_moment;
# Line 581 | Line 599 | namespace OpenMD {
599            dudr  =  *(idat.sw)  * preVal * (c2c_ - c2);
600  
601          } else if (summationMethod_ == esm_REACTION_FIELD) {
602 <          rfVal =  *(idat.electroMult) * preRF_ *  *(idat.rij)  *  *(idat.rij) ;
602 >          rfVal = preRF_ *  *(idat.rij)  *  *(idat.rij);
603 >
604            vterm = preVal * ( riji + rfVal );            
605            dudr  =  *(idat.sw)  * preVal * ( 2.0 * rfVal - riji ) * riji;
606 +          
607 +          // if this is an excluded pair, there are still indirect
608 +          // interactions via the reaction field we must worry about:
609  
610 +          if (idat.excluded) {
611 +            indirect_vpair += preVal * rfVal;
612 +            indirect_Pot += *(idat.sw) * preVal * rfVal;
613 +            indirect_dVdr += *(idat.sw)  * preVal * 2.0 * rfVal  * riji * rhat;
614 +          }
615 +          
616          } else {
589          vterm = preVal * riji * erfcVal;            
617  
618 +          vterm = preVal * riji * erfcVal;          
619            dudr  = -  *(idat.sw)  * preVal * c2;
620  
621          }
594
595        *(idat.vpair) += vterm;
596        epot +=  *(idat.sw)  * vterm;
622  
623 <        dVdr += dudr * rhat;      
623 >        vpair += vterm;
624 >        epot +=  *(idat.sw)  * vterm;
625 >        dVdr += dudr * rhat;                
626        }
627  
628        if (j_is_Dipole) {
# Line 608 | Line 635 | namespace OpenMD {
635            ri3 = ri2 * riji;
636      
637            vterm = - pref * ct_j * ( ri2 - preRF2_ *  *(idat.rij)  );
638 <          *(idat.vpair) += vterm;
638 >          vpair += vterm;
639            epot +=  *(idat.sw)  * vterm;
640  
641            dVdr +=  -preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
642            duduz_j += -preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );  
643  
644 +          // Even if we excluded this pair from direct interactions,
645 +          // we still have the reaction-field-mediated charge-dipole
646 +          // interaction:
647 +
648 +          if (idat.excluded) {
649 +            indirect_vpair += pref * ct_j * preRF2_ * *(idat.rij);
650 +            indirect_Pot += preSw * ct_j * preRF2_ * *(idat.rij);
651 +            indirect_dVdr += preSw * preRF2_ * uz_j;
652 +            indirect_duduz_j += preSw * rhat * preRF2_ *  *(idat.rij);
653 +          }
654 +                      
655          } else {
656            // determine the inverse r used if we have split dipoles
657            if (j_is_SplitDipole) {
# Line 646 | Line 684 | namespace OpenMD {
684            // calculate the potential
685            pot_term =  scale * c2;
686            vterm = -pref * ct_j * pot_term;
687 <          *(idat.vpair) += vterm;
687 >          vpair += vterm;
688            epot +=  *(idat.sw)  * vterm;
689              
690            // calculate derivatives for forces and torques
# Line 693 | Line 731 | namespace OpenMD {
731                       qyy_j * (cy2*c3 - c2ri) +
732                       qzz_j * (cz2*c3 - c2ri) );
733          vterm = pref * pot_term;
734 <        *(idat.vpair) += vterm;
734 >        vpair += vterm;
735          epot +=  *(idat.sw)  * vterm;
736                  
737          // calculate derivatives for the forces and torques
# Line 721 | Line 759 | namespace OpenMD {
759            ri3 = ri2 * riji;
760  
761            vterm = pref * ct_i * ( ri2 - preRF2_ *  *(idat.rij)  );
762 <          *(idat.vpair) += vterm;
762 >          vpair += vterm;
763            epot +=  *(idat.sw)  * vterm;
764            
765            dVdr += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_ * uz_i);
766            
767            duduz_i += preSw * rhat * (ri2 - preRF2_ *  *(idat.rij) );
768 +
769 +          // Even if we excluded this pair from direct interactions,
770 +          // we still have the reaction-field-mediated charge-dipole
771 +          // interaction:
772 +
773 +          if (idat.excluded) {
774 +            indirect_vpair += -pref * ct_i * preRF2_ * *(idat.rij);
775 +            indirect_Pot += -preSw * ct_i * preRF2_ * *(idat.rij);
776 +            indirect_dVdr += -preSw * preRF2_ * uz_i;
777 +            indirect_duduz_i += -preSw * rhat * preRF2_ *  *(idat.rij);
778 +          }
779              
780          } else {
781            
# Line 761 | Line 810 | namespace OpenMD {
810            // calculate the potential
811            pot_term = c2 * scale;
812            vterm = pref * ct_i * pot_term;
813 <          *(idat.vpair) += vterm;
813 >          vpair += vterm;
814            epot +=  *(idat.sw)  * vterm;
815  
816            // calculate derivatives for the forces and torques
# Line 784 | Line 833 | namespace OpenMD {
833  
834            vterm = pref * ( ri3 * (ct_ij - 3.0 * ct_i * ct_j) -
835                             preRF2_ * ct_ij );
836 <          *(idat.vpair) += vterm;
836 >          vpair += vterm;
837            epot +=  *(idat.sw)  * vterm;
838              
839            a1 = 5.0 * ct_i * ct_j - ct_ij;
# Line 793 | Line 842 | namespace OpenMD {
842  
843            duduz_i += preSw * (ri3 * (uz_j - 3.0 * ct_j * rhat) - preRF2_*uz_j);
844            duduz_j += preSw * (ri3 * (uz_i - 3.0 * ct_i * rhat) - preRF2_*uz_i);
845 +
846 +          if (idat.excluded) {
847 +            indirect_vpair +=  - pref * preRF2_ * ct_ij;
848 +            indirect_Pot +=    - preSw * preRF2_ * ct_ij;
849 +            indirect_duduz_i += -preSw * preRF2_ * uz_j;
850 +            indirect_duduz_j += -preSw * preRF2_ * uz_i;
851 +          }
852  
853          } else {
854            
# Line 843 | Line 899 | namespace OpenMD {
899            // calculate the potential
900            pot_term = (ct_ij * c2ri - ctidotj * c3);
901            vterm = pref * pot_term;
902 <          *(idat.vpair) += vterm;
902 >          vpair += vterm;
903            epot +=  *(idat.sw)  * vterm;
904  
905            // calculate derivatives for the forces and torques
# Line 895 | Line 951 | namespace OpenMD {
951                       qzz_i * (cz2 * c3 - c2ri) );
952          
953          vterm = pref * pot_term;
954 <        *(idat.vpair) += vterm;
954 >        vpair += vterm;
955          epot +=  *(idat.sw)  * vterm;
956  
957          // calculate the derivatives for the forces and torques
# Line 910 | Line 966 | namespace OpenMD {
966        }
967      }
968  
913    (*(idat.pot))[ELECTROSTATIC_FAMILY] += epot;
914    *(idat.f1) += dVdr;
969  
970 <    if (i_is_Dipole || i_is_Quadrupole)
971 <      *(idat.t1) -= cross(uz_i, duduz_i);
972 <    if (i_is_Quadrupole) {
973 <      *(idat.t1) -= cross(ux_i, dudux_i);
974 <      *(idat.t1) -= cross(uy_i, duduy_i);
975 <    }
976 <    
977 <    if (j_is_Dipole || j_is_Quadrupole)
978 <      *(idat.t2) -= cross(uz_j, duduz_j);
979 <    if (j_is_Quadrupole) {
980 <      *(idat.t2) -= cross(uz_j, dudux_j);
981 <      *(idat.t2) -= cross(uz_j, duduy_j);
982 <    }
970 >    if (!idat.excluded) {
971 >      *(idat.vpair) += vpair;
972 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += epot;
973 >      *(idat.f1) += dVdr;
974 >      
975 >      if (i_is_Dipole || i_is_Quadrupole)
976 >        *(idat.t1) -= cross(uz_i, duduz_i);
977 >      if (i_is_Quadrupole) {
978 >        *(idat.t1) -= cross(ux_i, dudux_i);
979 >        *(idat.t1) -= cross(uy_i, duduy_i);
980 >      }
981 >      
982 >      if (j_is_Dipole || j_is_Quadrupole)
983 >        *(idat.t2) -= cross(uz_j, duduz_j);
984 >      if (j_is_Quadrupole) {
985 >        *(idat.t2) -= cross(uz_j, dudux_j);
986 >        *(idat.t2) -= cross(uz_j, duduy_j);
987 >      }
988  
989 <    return;
931 <  }  
989 >    } else {
990  
991 <  void Electrostatic::calcSkipCorrection(InteractionData &idat) {
992 <
993 <    if (!initialized_) initialize();
994 <    
995 <    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:
991 >      // only accumulate the forces and torques resulting from the
992 >      // indirect reaction field terms.
993 >      *(idat.vpair) += indirect_vpair;
994 >      (*(idat.pot))[ELECTROSTATIC_FAMILY] += indirect_Pot;
995 >      *(idat.f1) += indirect_dVdr;
996        
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      
997        if (i_is_Dipole)
998 <        *(idat.t1) -= cross(uz_i, duduz_i);
998 >        *(idat.t1) -= cross(uz_i, indirect_duduz_i);
999        if (j_is_Dipole)
1000 <        *(idat.t2) -= cross(uz_j, duduz_j);
1000 >        *(idat.t2) -= cross(uz_j, indirect_duduz_j);
1001      }
1002 <  }
1002 >
1003 >
1004 >    return;
1005 >  }  
1006      
1007    void Electrostatic::calcSelfCorrection(SelfData &sdat) {
1008      RealType mu1, preVal, chg1, self;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines