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

Comparing branches/development/src/nonbonded/LJ.cpp (file contents):
Revision 1502 by gezelter, Sat Oct 2 19:53:32 2010 UTC vs.
Revision 1683 by jmichalk, Wed Feb 29 20:33:01 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 45 | Line 46
46   #include <cmath>
47   #include "nonbonded/LJ.hpp"
48   #include "utils/simError.h"
49 + #include "types/LennardJonesInteractionType.hpp"
50  
51   namespace OpenMD {
52  
53 <  LJ::LJ() : name_("LJ"), initialized_(false), shiftedPot_(false),
52 <             shiftedFrc_(false), forceField_(NULL) {}
53 >  LJ::LJ() : name_("LJ"), initialized_(false), forceField_(NULL) {}
54  
55    LJParam LJ::getLJParam(AtomType* atomType) {
56      
# Line 124 | Line 125 | namespace OpenMD {
125  
126      for (at = atomTypes->beginType(i); at != NULL;
127           at = atomTypes->nextType(i)) {
128 <      
129 <      if (at->isLennardJones())
130 <        addType(at);
128 >      if (at->isLennardJones()){
129 >         addType(at);
130 >      }
131      }
131
132      ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
133      ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
134      NonBondedInteractionType* nbt;
135 +    ForceField::NonBondedInteractionTypeContainer::KeyType keys;
136  
137 +
138      for (nbt = nbiTypes->beginType(j); nbt != NULL;
139           nbt = nbiTypes->nextType(j)) {
140 <      
140 >
141        if (nbt->isLennardJones()) {
142 <        
143 <        pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
144 <        
145 <        GenericData* data = nbt->getPropertyByName("LennardJones");
146 <        if (data == NULL) {
147 <          sprintf( painCave.errMsg, "LJ::rebuildMixingMap could not find\n"
148 <               "\tLennard-Jones parameters for %s - %s interaction.\n",
147 <                   atypes.first->getName().c_str(),
148 <                   atypes.second->getName().c_str());
149 <          painCave.severity = OPENMD_ERROR;
150 <          painCave.isFatal = 1;
151 <          simError();
152 <        }
153 <    
154 <        LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
155 <        if (ljData == NULL) {
142 >        keys = nbiTypes->getKeys(j);
143 >        AtomType* at1 = forceField_->getAtomType(keys[0]);
144 >        AtomType* at2 = forceField_->getAtomType(keys[1]);
145 >
146 >        LennardJonesInteractionType* ljit = dynamic_cast<LennardJonesInteractionType*>(nbt);
147 >
148 >        if (ljit == NULL) {
149            sprintf( painCave.errMsg,
150 <                   "LJ::rebuildMixingMap could not convert GenericData to\n"
151 <                   "\tLJParam for %s - %s interaction.\n",
152 <                   atypes.first->getName().c_str(),
153 <                   atypes.second->getName().c_str());
150 >                   "LJ::initialize could not convert NonBondedInteractionType\n"
151 >                   "\tto LennardJonesInteractionType for %s - %s interaction.\n",
152 >                   at1->getName().c_str(),
153 >                   at2->getName().c_str());
154            painCave.severity = OPENMD_ERROR;
155            painCave.isFatal = 1;
156            simError();          
157          }
165        
166        LJParam ljParam = ljData->getData();
158  
159 <        RealType sigma = ljParam.sigma;
160 <        RealType epsilon = ljParam.epsilon;
161 <
171 <        addExplicitInteraction(atypes.first, atypes.second, sigma, epsilon);
159 >        RealType sigma = ljit->getSigma();
160 >        RealType epsilon = ljit->getEpsilon();
161 >        addExplicitInteraction(at1, at2, sigma, epsilon);
162        }
163      }  
164      initialized_ = true;
# Line 220 | Line 210 | namespace OpenMD {
210    
211    void LJ::addExplicitInteraction(AtomType* atype1, AtomType* atype2, RealType sigma, RealType epsilon){
212      
223    // in case these weren't already in the map
224    addType(atype1);
225    addType(atype2);
226
213      LJInteractionData mixer;
214      mixer.sigma = sigma;
215      mixer.epsilon = epsilon;
# Line 240 | Line 226 | namespace OpenMD {
226      }    
227    }
228  
229 <  void LJ::calcForce(InteractionData idat) {
244 <    
229 >  void LJ::calcForce(InteractionData &idat) {
230      if (!initialized_) initialize();
231 <    
232 <    RealType ros;
248 <    RealType rcos;
249 <    RealType myPot = 0.0;
250 <    RealType myPotC = 0.0;
251 <    RealType myDeriv = 0.0;
252 <    RealType myDerivC = 0.0;
253 <
254 <    std::pair<AtomType*, AtomType*> key = std::make_pair(idat.atype1,
255 <                                                         idat.atype2);
256 <    LJInteractionData mixer = MixingMap[key];
257 <
258 <    RealType sigmai = mixer.sigmai;
259 <    RealType epsilon = mixer.epsilon;
231 >    map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it;
232 >    it = MixingMap.find( idat.atypes );
233      
234 +    if (it != MixingMap.end())  {
235 +      
236 +      LJInteractionData mixer = (*it).second;
237 +      
238 +      RealType sigmai = mixer.sigmai;
239 +      RealType epsilon = mixer.epsilon;
240 +      
241 +      RealType ros;
242 +      RealType rcos;
243 +      RealType myPot = 0.0;
244 +      RealType myPotC = 0.0;
245 +      RealType myDeriv = 0.0;
246 +      RealType myDerivC = 0.0;
247 +    
248 +      ros = *(idat.rij) * sigmai;    
249 +      
250 +      getLJfunc(ros, myPot, myDeriv);
251 +      
252 +      if (idat.shiftedPot) {
253 +        rcos = *(idat.rcut) * sigmai;
254 +        getLJfunc(rcos, myPotC, myDerivC);
255 +        myDerivC = 0.0;
256 +      } else if (idat.shiftedForce) {
257 +        rcos = *(idat.rcut) * sigmai;
258 +        getLJfunc(rcos, myPotC, myDerivC);
259 +        myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai;
260 +      } else {
261 +        myPotC = 0.0;
262 +        myDerivC = 0.0;        
263 +      }
264  
265 <    ros = idat.rij * sigmai;
265 >      RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC);
266 >      *(idat.vpair) += pot_temp;
267 >      
268 >      RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv -
269 >                                                                myDerivC)*sigmai;      
270  
271 <    getLJfunc(ros, myPot, myDeriv);
272 <
266 <    if (shiftedPot_) {
267 <      rcos = idat.rcut * sigmai;
268 <      getLJfunc(rcos, myPotC, myDerivC);
269 <      myDerivC = 0.0;
270 <    } else if (LJ::shiftedFrc_) {
271 <      rcos = idat.rcut * sigmai;
272 <      getLJfunc(rcos, myPotC, myDerivC);
273 <      myPotC = myPotC + myDerivC * (idat.rij - idat.rcut) * sigmai;
274 <    } else {
275 <      myPotC = 0.0;
276 <      myDerivC = 0.0;
271 >      (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
272 >      *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
273      }
278
279    RealType pot_temp = idat.vdwMult * epsilon * (myPot - myPotC);
280    idat.vpair += pot_temp;
281
282    RealType dudr = idat.sw * idat.vdwMult * epsilon * (myDeriv -
283                                                        myDerivC)*sigmai;
284    
285    idat.pot += idat.sw * pot_temp;
286    idat.f1 = idat.d * dudr / idat.rij;
287
274      return;
289
275    }
276    
277    void LJ::getLJfunc(RealType r, RealType &pot, RealType &deriv) {
# Line 304 | Line 289 | namespace OpenMD {
289      return;
290    }
291    
292 +  RealType LJ::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
293 +    if (!initialized_) initialize();  
294 +    map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it;
295 +    it = MixingMap.find(atypes);
296 +    if (it == MixingMap.end())
297 +      return 0.0;
298 +    else  {
299 +      LJInteractionData mixer = (*it).second;
300 +      return 2.5 * mixer.sigma;
301 +    }
302 +  }
303  
304   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines