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 1504 by gezelter, Sat Oct 2 20:41:53 2010 UTC vs.
Revision 1535 by gezelter, Fri Dec 31 18:31:56 2010 UTC

# Line 47 | Line 47
47   #include "utils/simError.h"
48   #include "types/NonBondedInteractionType.hpp"
49   #include "types/DirectionalAtomType.hpp"
50 + #include "io/Globals.hpp"
51  
51
52   namespace OpenMD {
53    
54    Electrostatic::Electrostatic(): name_("Electrostatic"), initialized_(false),
55                                    forceField_(NULL) {}
56    
57    void Electrostatic::initialize() {
58 +
59 +    Globals* simParams_;
60 +
61 +    summationMap_["HARD"]               = esm_HARD;
62 +    summationMap_["SWITCHING_FUNCTION"] = esm_SWITCHING_FUNCTION;
63 +    summationMap_["SHIFTED_POTENTIAL"]  = esm_SHIFTED_POTENTIAL;
64 +    summationMap_["SHIFTED_FORCE"]      = esm_SHIFTED_FORCE;    
65 +    summationMap_["REACTION_FIELD"]     = esm_REACTION_FIELD;    
66 +    summationMap_["EWALD_FULL"]         = esm_EWALD_FULL;        
67 +    summationMap_["EWALD_PME"]          = esm_EWALD_PME;        
68 +    summationMap_["EWALD_SPME"]         = esm_EWALD_SPME;        
69 +    screeningMap_["DAMPED"]             = DAMPED;
70 +    screeningMap_["UNDAMPED"]           = UNDAMPED;
71 +
72      // these prefactors convert the multipole interactions into kcal / mol
73      // all were computed assuming distances are measured in angstroms
74      // Charge-Charge, assuming charges are measured in electrons
# Line 79 | Line 93 | namespace OpenMD {
93      
94      // variables to handle different summation methods for long-range
95      // electrostatics:
96 <    summationMethod_ = NONE;    
96 >    summationMethod_ = esm_HARD;    
97      screeningMethod_ = UNDAMPED;
98      dielectric_ = 1.0;
99      one_third_ = 1.0 / 3.0;
100 <    haveDefaultCutoff_ = false;
100 >    haveCutoffRadius_ = false;
101      haveDampingAlpha_ = false;
102      haveDielectric_ = false;  
103      haveElectroSpline_ = false;
104    
105 +    // check the summation method:
106 +    if (simParams_->haveElectrostaticSummationMethod()) {
107 +      string myMethod = simParams_->getElectrostaticSummationMethod();
108 +      toUpper(myMethod);
109 +      map<string, ElectrostaticSummationMethod>::iterator i;
110 +      i = summationMap_.find(myMethod);
111 +      if ( i != summationMap_.end() ) {
112 +        summationMethod_ = (*i).second;
113 +      } else {
114 +        // throw error
115 +        sprintf( painCave.errMsg,
116 +                 "SimInfo error: Unknown electrostaticSummationMethod.\n"
117 +                 "\t(Input file specified %s .)\n"
118 +                 "\telectrostaticSummationMethod must be one of: \"none\",\n"
119 +                 "\t\"shifted_potential\", \"shifted_force\", or \n"
120 +                 "\t\"reaction_field\".\n", myMethod.c_str() );
121 +        painCave.isFatal = 1;
122 +        simError();
123 +      }
124 +    } else {
125 +      // set ElectrostaticSummationMethod to the cutoffMethod:
126 +      if (simParams_->haveCutoffMethod()){
127 +        string myMethod = simParams_->getCutoffMethod();
128 +        toUpper(myMethod);
129 +        map<string, ElectrostaticSummationMethod>::iterator i;
130 +        i = summationMap_.find(myMethod);
131 +        if ( i != summationMap_.end() ) {
132 +          summationMethod_ = (*i).second;
133 +        }
134 +      }
135 +    }
136 +    
137 +    if (summationMethod_ == esm_REACTION_FIELD) {        
138 +      if (!simParams_->haveDielectric()) {
139 +        // throw warning
140 +        sprintf( painCave.errMsg,
141 +                 "SimInfo warning: dielectric was not specified in the input file\n\tfor the reaction field correction method.\n"
142 +                 "\tA default value of %f will be used for the dielectric.\n", dielectric_);
143 +        painCave.isFatal = 0;
144 +        painCave.severity = OPENMD_INFO;
145 +        simError();
146 +      } else {
147 +        dielectric_ = simParams_->getDielectric();      
148 +      }
149 +      haveDielectric_ = true;
150 +    }
151 +    
152 +    if (simParams_->haveElectrostaticScreeningMethod()) {
153 +      string myScreen = simParams_->getElectrostaticScreeningMethod();
154 +      toUpper(myScreen);
155 +      map<string, ElectrostaticScreeningMethod>::iterator i;
156 +      i = screeningMap_.find(myScreen);
157 +      if ( i != screeningMap_.end()) {
158 +        screeningMethod_ = (*i).second;
159 +      } else {
160 +        sprintf( painCave.errMsg,
161 +                 "SimInfo error: Unknown electrostaticScreeningMethod.\n"
162 +                 "\t(Input file specified %s .)\n"
163 +                 "\telectrostaticScreeningMethod must be one of: \"undamped\"\n"
164 +                 "or \"damped\".\n", myScreen.c_str() );
165 +        painCave.isFatal = 1;
166 +        simError();
167 +      }
168 +    }
169 +
170 +    // check to make sure a cutoff value has been set:
171 +    if (!haveCutoffRadius_) {
172 +      sprintf( painCave.errMsg, "Electrostatic::initialize has no Default "
173 +               "Cutoff value!\n");
174 +      painCave.severity = OPENMD_ERROR;
175 +      painCave.isFatal = 1;
176 +      simError();
177 +    }
178 +          
179 +    if (screeningMethod_ == DAMPED) {      
180 +      if (!simParams_->haveDampingAlpha()) {
181 +        // first set a cutoff dependent alpha value
182 +        // we assume alpha depends linearly with rcut from 0 to 20.5 ang
183 +        dampingAlpha_ = 0.425 - cutoffRadius_* 0.02;
184 +        if (dampingAlpha_ < 0.0) dampingAlpha_ = 0.0;
185 +        
186 +        // throw warning
187 +        sprintf( painCave.errMsg,
188 +                 "Electrostatic::initialize: dampingAlpha was not specified in the input file.\n"
189 +                 "\tA default value of %f (1/ang) will be used for the cutoff of\n\t%f (ang).\n",
190 +                 dampingAlpha_, cutoffRadius_);
191 +        painCave.severity = OPENMD_INFO;
192 +        painCave.isFatal = 0;
193 +        simError();
194 +      } else {
195 +        dampingAlpha_ = simParams_->getDampingAlpha();
196 +      }
197 +      haveDampingAlpha_ = true;
198 +    }
199 +
200      // find all of the Electrostatic atom Types:
201      ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
202      ForceField::AtomTypeContainer::MapTypeIterator i;
203      AtomType* at;
204 <
204 >    
205      for (at = atomTypes->beginType(i); at != NULL;
206           at = atomTypes->nextType(i)) {
207        
# Line 100 | Line 209 | namespace OpenMD {
209          addType(at);
210      }
211      
103    // check to make sure a cutoff value has been set:
104    if (!haveDefaultCutoff_) {
105      sprintf( painCave.errMsg, "Electrostatic::initialize has no Default "
106               "Cutoff value!\n");
107      painCave.severity = OPENMD_ERROR;
108      painCave.isFatal = 1;
109      simError();
110    }
212  
213 <    defaultCutoff2_ = defaultCutoff_ * defaultCutoff_;
214 <    rcuti_ = 1.0 / defaultCutoff_;
213 >    cutoffRadius2_ = cutoffRadius_ * cutoffRadius_;
214 >    rcuti_ = 1.0 / cutoffRadius_;
215      rcuti2_ = rcuti_ * rcuti_;
216      rcuti3_ = rcuti2_ * rcuti_;
217      rcuti4_ = rcuti2_ * rcuti2_;
218  
219      if (screeningMethod_ == DAMPED) {
220 <      if (!haveDampingAlpha_) {
120 <        sprintf( painCave.errMsg, "Electrostatic::initialize has no "
121 <                 "DampingAlpha value!\n");
122 <        painCave.severity = OPENMD_ERROR;
123 <        painCave.isFatal = 1;
124 <        simError();
125 <      }
126 <
220 >      
221        alpha2_ = dampingAlpha_ * dampingAlpha_;
222        alpha4_ = alpha2_ * alpha2_;
223        alpha6_ = alpha4_ * alpha2_;
224        alpha8_ = alpha4_ * alpha4_;
225        
226 <      constEXP_ = exp(-alpha2_ * defaultCutoff2_);
226 >      constEXP_ = exp(-alpha2_ * cutoffRadius2_);
227        invRootPi_ = 0.56418958354775628695;
228        alphaPi_ = 2.0 * dampingAlpha_ * invRootPi_;
229  
230 <      c1c_ = erfc(dampingAlpha_ * defaultCutoff_) * rcuti_;
230 >      c1c_ = erfc(dampingAlpha_ * cutoffRadius_) * rcuti_;
231        c2c_ = alphaPi_ * constEXP_ * rcuti_ + c1c_ * rcuti_;
232        c3c_ = 2.0 * alphaPi_ * alpha2_ + 3.0 * c2c_ * rcuti_;
233        c4c_ = 4.0 * alphaPi_ * alpha4_ + 5.0 * c3c_ * rcuti2_;
# Line 148 | Line 242 | namespace OpenMD {
242        c6c_ = 9.0 * c5c_ * rcuti2_;
243      }
244    
245 <    if (summationMethod_ == REACTION_FIELD) {
246 <      if (haveDielectric_) {
247 <        preRF_ = (dielectric_ - 1.0) /
248 <            ((2.0 * dielectric_ + 1.0) * defaultCutoff2_ * defaultCutoff_);
155 <        preRF2_ = 2.0 * preRF_;
156 <      } else {
157 <        sprintf( painCave.errMsg, "Electrostatic::initialize has no Dielectric"
158 <                 " value!\n");
159 <        painCave.severity = OPENMD_ERROR;
160 <        painCave.isFatal = 1;
161 <        simError();
162 <      }
245 >    if (summationMethod_ == esm_REACTION_FIELD) {
246 >      preRF_ = (dielectric_ - 1.0) /
247 >        ((2.0 * dielectric_ + 1.0) * cutoffRadius2_ * cutoffRadius_);
248 >      preRF2_ = 2.0 * preRF_;
249      }
250 <                              
251 <    RealType dx = defaultCutoff_ / RealType(np_ - 1);
250 >    
251 >    RealType dx = cutoffRadius_ / RealType(np_ - 1);
252      RealType rval;
253      vector<RealType> rvals;
254      vector<RealType> yvals;
# Line 283 | Line 369 | namespace OpenMD {
369            simError();                  
370          }
371          
372 +        // Quadrupoles in OpenMD are set as the diagonal elements
373 +        // of the diagonalized traceless quadrupole moment tensor.
374 +        // The column vectors of the unitary matrix that diagonalizes
375 +        // the quadrupole moment tensor become the eFrame (or the
376 +        // electrostatic version of the body-fixed frame.
377 +
378          Vector3dGenericData* v3dData = dynamic_cast<Vector3dGenericData*>(data);
379          if (v3dData == NULL) {
380            sprintf( painCave.errMsg,
# Line 317 | Line 409 | namespace OpenMD {
409    
410    void Electrostatic::setElectrostaticCutoffRadius( RealType theECR,
411                                                      RealType theRSW ) {
412 <    defaultCutoff_ = theECR;
413 <    rrf_ = defaultCutoff_;
412 >    cutoffRadius_ = theECR;
413 >    rrf_ = cutoffRadius_;
414      rt_ = theRSW;
415 <    haveDefaultCutoff_ = true;
415 >    haveCutoffRadius_ = true;
416    }
417    void Electrostatic::setElectrostaticSummationMethod( ElectrostaticSummationMethod esm ) {
418      summationMethod_ = esm;
# Line 479 | Line 571 | namespace OpenMD {
571  
572          preVal = idat.electroMult * pre11_ * q_i * q_j;
573          
574 <        if (summationMethod_ == SHIFTED_POTENTIAL) {
574 >        if (summationMethod_ == esm_SHIFTED_POTENTIAL) {
575            vterm = preVal * (c1 - c1c_);
576            dudr  = -idat.sw * preVal * c2;
577  
578 <        } else if (summationMethod_ == SHIFTED_FORCE)  {
579 <          vterm = preVal * ( c1 - c1c_ + c2c_*(idat.rij - defaultCutoff_) );
578 >        } else if (summationMethod_ == esm_SHIFTED_FORCE)  {
579 >          vterm = preVal * ( c1 - c1c_ + c2c_*(idat.rij - cutoffRadius_) );
580            dudr  = idat.sw * preVal * (c2c_ - c2);
581  
582 <        } else if (summationMethod_ == REACTION_FIELD) {
582 >        } else if (summationMethod_ == esm_REACTION_FIELD) {
583            rfVal = idat.electroMult * preRF_ * idat.rij * idat.rij;
584            vterm = preVal * ( riji + rfVal );            
585            dudr  = idat.sw * preVal * ( 2.0 * rfVal - riji ) * riji;
# Line 510 | Line 602 | namespace OpenMD {
602          pref = idat.electroMult * pre12_ * q_i * mu_j;
603          preSw = idat.sw * pref;
604  
605 <        if (summationMethod_ == REACTION_FIELD) {
605 >        if (summationMethod_ == esm_REACTION_FIELD) {
606            ri2 = riji * riji;
607            ri3 = ri2 * riji;
608      
# Line 622 | Line 714 | namespace OpenMD {
714          pref = idat.electroMult * pre12_ * q_j * mu_i;
715          preSw = idat.sw * pref;
716  
717 <        if (summationMethod_ == REACTION_FIELD) {
717 >        if (summationMethod_ == esm_REACTION_FIELD) {
718  
719            ri2 = riji * riji;
720            ri3 = ri2 * riji;
# Line 684 | Line 776 | namespace OpenMD {
776          pref = idat.electroMult * pre22_ * mu_i * mu_j;
777          preSw = idat.sw * pref;
778  
779 <        if (summationMethod_ == REACTION_FIELD) {
779 >        if (summationMethod_ == esm_REACTION_FIELD) {
780            ri2 = riji * riji;
781            ri3 = ri2 * riji;
782            ri4 = ri2 * ri2;
# Line 869 | Line 961 | namespace OpenMD {
961  
962      // the rest of this function should only be necessary for reaction field.
963  
964 <    if (summationMethod_ == REACTION_FIELD) {
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;
# Line 950 | Line 1042 | namespace OpenMD {
1042      bool i_is_Charge = data.is_Charge;
1043      bool i_is_Dipole = data.is_Dipole;
1044  
1045 <    if (summationMethod_ == REACTION_FIELD) {
1045 >    if (summationMethod_ == esm_REACTION_FIELD) {
1046        if (i_is_Dipole) {
1047          mu1 = data.dipole_moment;          
1048          preVal = pre22_ * preRF2_ * mu1 * mu1;
# Line 963 | Line 1055 | namespace OpenMD {
1055          // This looks very wrong.  A vector crossed with itself is zero.
1056          scdat.t -= cross(uz_i, ei);
1057        }
1058 <    } else if (summationMethod_ == SHIFTED_FORCE || summationMethod_ == SHIFTED_POTENTIAL) {
1058 >    } else if (summationMethod_ == esm_SHIFTED_FORCE || summationMethod_ == esm_SHIFTED_POTENTIAL) {
1059        if (i_is_Charge) {        
1060          chg1 = data.charge;
1061          if (screeningMethod_ == DAMPED) {
# Line 975 | Line 1067 | namespace OpenMD {
1067        }
1068      }
1069    }
1070 +
1071 +  RealType Electrostatic::getSuggestedCutoffRadius(AtomType* at1, AtomType* at2) {
1072 +    // This seems to work moderately well as a default.  There's no
1073 +    // inherent scale for 1/r interactions that we can standardize.
1074 +    // 12 angstroms seems to be a reasonably good guess for most
1075 +    // cases.
1076 +    return 12.0;
1077 +  }
1078   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines