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

Comparing branches/development/src/nonbonded/MAW.cpp (file contents):
Revision 1549 by gezelter, Wed Apr 27 18:38:15 2011 UTC vs.
Revision 1664 by gezelter, Tue Nov 22 14:37:41 2011 UTC

# Line 50 | Line 50 | namespace OpenMD {
50  
51   namespace OpenMD {
52  
53 <  MAW::MAW() : name_("MAW"), initialized_(false), forceField_(NULL),
54 <                   shiftedPot_(false), shiftedFrc_(false) {}
53 >  MAW::MAW() : name_("MAW"), initialized_(false), forceField_(NULL) {}
54    
55    void MAW::initialize() {    
56  
57      ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
58      ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
59      NonBondedInteractionType* nbt;
60 +    ForceField::NonBondedInteractionTypeContainer::KeyType keys;
61  
62      for (nbt = nbiTypes->beginType(j); nbt != NULL;
63           nbt = nbiTypes->nextType(j)) {
64        
65        if (nbt->isMAW()) {
66 <        pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes();
67 <        
68 <        GenericData* data = nbt->getPropertyByName("MAW");
69 <        if (data == NULL) {
70 <          sprintf( painCave.errMsg, "MAW::initialize could not find\n"
71 <                   "\tMAW parameters for %s - %s interaction.\n",
72 <                   atypes.first->getName().c_str(),
73 <                   atypes.second->getName().c_str());
74 <          painCave.severity = OPENMD_ERROR;
75 <          painCave.isFatal = 1;
76 <          simError();
77 <        }
78 <        
79 <        MAWData* mawData = dynamic_cast<MAWData*>(data);
80 <        if (mawData == NULL) {
66 >        keys = nbiTypes->getKeys(j);
67 >        AtomType* at1 = forceField_->getAtomType(keys[0]);
68 >        AtomType* at2 = forceField_->getAtomType(keys[1]);
69 >
70 >        MAWInteractionType* mit = dynamic_cast<MAWInteractionType*>(nbt);
71 >
72 >        if (mit == NULL) {
73            sprintf( painCave.errMsg,
74 <                   "MAW::initialize could not convert GenericData to\n"
75 <                   "\tMAWData for %s - %s interaction.\n",
76 <                   atypes.first->getName().c_str(),
77 <                   atypes.second->getName().c_str());
74 >                   "MAW::initialize could not convert NonBondedInteractionType\n"
75 >                   "\tto MAWInteractionType for %s - %s interaction.\n",
76 >                   at1->getName().c_str(),
77 >                   at2->getName().c_str());
78            painCave.severity = OPENMD_ERROR;
79            painCave.isFatal = 1;
80            simError();          
81          }
82          
83 <        MAWParam mawParam = mawData->getData();
84 <
85 <        RealType De = mawParam.De;
86 <        RealType beta = mawParam.beta;
87 <        RealType Re = mawParam.Re;
96 <        RealType ca1 = mawParam.ca1;
97 <        RealType cb1 = mawParam.cb1;
83 >        RealType De = mit->getD();
84 >        RealType beta = mit->getBeta();
85 >        RealType Re = mit->getR();
86 >        RealType ca1 = mit->getCA1();
87 >        RealType cb1 = mit->getCB1();
88          
89 <        addExplicitInteraction(atypes.first, atypes.second,
89 >        addExplicitInteraction(at1, at2,
90                                 De, beta, Re, ca1, cb1);
91        }
92      }  
# Line 129 | Line 119 | namespace OpenMD {
119      if (!initialized_) initialize();
120      
121      map<pair<AtomType*, AtomType*>, MAWInteractionData>::iterator it;
122 <    it = MixingMap.find(idat.atypes);
122 >    it = MixingMap.find( idat.atypes );
123      if (it != MixingMap.end()) {
124        MAWInteractionData mixer = (*it).second;
125        
# Line 151 | Line 141 | namespace OpenMD {
141        if (j_is_Metal) {
142          // rotate the inter-particle separation into the two different
143          // body-fixed coordinate systems:
144 <        r = idat.A1 * idat.d;
145 <        Atrans = idat.A1.transpose();
144 >        r = *(idat.A1) * *(idat.d);
145 >        Atrans = idat.A1->transpose();
146        } else {
147          // negative sign because this is the vector from j to i:      
148 <        r = -idat.A2 * idat.d;
149 <        Atrans = idat.A2.transpose();
148 >        r = -*(idat.A2) * *(idat.d);
149 >        Atrans = idat.A2->transpose();
150        }
151        
152        // V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2)
153        
154 <      RealType expt     = -beta*(idat.rij - R_e);
154 >      RealType expt     = -beta*( *(idat.rij) - R_e);
155        RealType expfnc   = exp(expt);
156        RealType expfnc2  = expfnc*expfnc;
157        
# Line 172 | Line 162 | namespace OpenMD {
162        myPot  = D_e * (expfnc2  - 2.0 * expfnc);
163        myDeriv   = 2.0 * D_e * beta * (expfnc - expfnc2);
164        
165 <      if (MAW::shiftedPot_ || MAW::shiftedFrc_) {
166 <        exptC     = -beta*(idat.rcut - R_e);
165 >      if (idat.shiftedPot || idat.shiftedForce) {
166 >        exptC     = -beta*( *(idat.rcut)  - R_e);
167          expfncC   = exp(exptC);
168          expfnc2C  = expfncC*expfncC;
169        }
170        
171 <      if (MAW::shiftedPot_) {
171 >      if (idat.shiftedPot) {
172          myPotC = D_e * (expfnc2C - 2.0 * expfncC);
173          myDerivC = 0.0;
174 <      } else if (MAW::shiftedFrc_) {
174 >      } else if (idat.shiftedForce) {
175          myPotC = D_e * (expfnc2C - 2.0 * expfncC);
176          myDerivC  = 2.0 * D_e * beta * (expfnc2C - expfnc2C);
177 <        myPotC += myDerivC * (idat.rij - idat.rcut);
177 >        myPotC += myDerivC * ( *(idat.rij)  -  *(idat.rcut) );
178        } else {
179          myPotC = 0.0;
180          myDerivC = 0.0;
# Line 197 | Line 187 | namespace OpenMD {
187        RealType y2 = y * y;
188        RealType z2 = z * z;
189  
190 <      RealType r3 = idat.r2 * idat.rij;
191 <      RealType r4 = idat.r2 * idat.r2;
190 >      RealType r3 = *(idat.r2) *  *(idat.rij) ;
191 >      RealType r4 = *(idat.r2) *  *(idat.r2);
192  
193        // angular modulation of morse part of potential to approximate
194        // the squares of the two HOMO lone pair orbitals in water:
# Line 216 | Line 206 | namespace OpenMD {
206        // Vmorse(r)*[a*x2/r2 + b*z/r + (1-a-b)]
207        
208        RealType Vmorse = (myPot - myPotC);
209 <      RealType Vang = ca1 * x2 / idat.r2 + cb1 * z / idat.rij + (0.8 - ca1 / 3.0);
210 <        
211 <      RealType pot_temp = idat.vdwMult * Vmorse * Vang;
212 <      idat.vpair += pot_temp;
213 <      idat.pot[0] += idat.sw * pot_temp;
209 >      RealType Vang = ca1 * x2 / *(idat.r2) +
210 >        cb1 * z /  *(idat.rij)  + (0.8 - ca1 / 3.0);
211 >      
212 >      RealType pot_temp = *(idat.vdwMult) * Vmorse * Vang;
213 >      *(idat.vpair) += pot_temp;
214 >      (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp;
215            
216 <      Vector3d dVmorsedr = (myDeriv - myDerivC) * Vector3d(x, y, z) / idat.rij;
226 <    
227 <      Vector3d dVangdr = Vector3d(-2.0 * ca1 * x2 * x / r4 + 2.0 * ca1 * x / idat.r2 - cb1 * x * z / r3,
228 <                                  -2.0 * ca1 * x2 * y / r4                           - cb1 * z * y / r3,
229 <                                  -2.0 * ca1 * x2 * z / r4 + cb1 / idat.rij          - cb1 * z2  / r3);
216 >      Vector3d dVmorsedr = (myDeriv - myDerivC) * Vector3d(x, y, z) /  *(idat.rij) ;
217        
218 +      Vector3d dVangdr = Vector3d(-2.0 * ca1 * x2 * x / r4 + 2.0 * ca1 * x / *(idat.r2) - cb1 * x * z / r3,
219 +                                  -2.0 * ca1 * x2 * y / r4 - cb1 * z * y / r3,
220 +                                  -2.0 * ca1 * x2 * z / r4 + cb1 /  *(idat.rij)           - cb1 * z2  / r3);
221 +      
222        // chain rule to put these back on x, y, z
223  
224        Vector3d dvdr = Vang * dVmorsedr + Vmorse * dVangdr;
# Line 235 | Line 226 | namespace OpenMD {
226        // Torques for Vang using method of Price:
227        // S. L. Price, A. J. Stone, and M. Alderton, Mol. Phys. 52, 987 (1984).
228        
229 <      Vector3d dVangdu = Vector3d(cb1 * y / idat.rij,
230 <                                  2.0 * ca1 * x * z / idat.r2 - cb1 * x / idat.rij,
231 <                                  -2.0 * ca1 * y * x / idat.r2);
229 >      Vector3d dVangdu = Vector3d(cb1 * y /  *(idat.rij) ,
230 >                                  2.0 * ca1 * x * z / *(idat.r2) - cb1 * x /  *(idat.rij),
231 >                                  -2.0 * ca1 * y * x / *(idat.r2));
232  
233        // do the torques first since they are easy:
234        // remember that these are still in the body fixed axes    
235  
236 <      Vector3d trq = idat.vdwMult * Vmorse * dVangdu * idat.sw;
236 >      Vector3d trq = *(idat.vdwMult) * Vmorse * dVangdu * *(idat.sw);
237  
238        // go back to lab frame using transpose of rotation matrix:
239        
240        if (j_is_Metal) {
241 <        idat.t1 += Atrans * trq;
241 >        *(idat.t1) += Atrans * trq;
242        } else {
243 <        idat.t2 += Atrans * trq;
243 >        *(idat.t2) += Atrans * trq;
244        }
245  
246        // Now, on to the forces (still in body frame of water)
247  
248 <      Vector3d ftmp = idat.vdwMult * idat.sw * dvdr;
248 >      Vector3d ftmp = *(idat.vdwMult) * *(idat.sw) * dvdr;
249  
250        // rotate the terms back into the lab frame:
251        Vector3d flab;
# Line 264 | Line 255 | namespace OpenMD {
255          flab = - Atrans * ftmp;
256        }
257        
258 <      idat.f1 += flab;
258 >      *(idat.f1) += flab;
259      }
260      return;
261      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines