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

Comparing branches/development/src/nonbonded/Sticky.cpp (file contents):
Revision 1502 by gezelter, Sat Oct 2 19:53:32 2010 UTC vs.
Revision 1710 by gezelter, Fri May 18 21:44:02 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/Sticky.hpp"
48   #include "nonbonded/LJ.hpp"
49 + #include "types/StickyAdapter.hpp"
50   #include "utils/simError.h"
51  
52   using namespace std;
53   namespace OpenMD {
54    
55    Sticky::Sticky() : name_("Sticky"), initialized_(false), forceField_(NULL) {}
54  
55  StickyParam Sticky::getStickyParam(AtomType* atomType) {
56      
57    // Do sanity checking on the AtomType we were passed before
58    // building any data structures:
59    if (!atomType->isSticky() && !atomType->isStickyPower()) {
60      sprintf( painCave.errMsg,
61               "Sticky::getStickyParam was passed an atomType (%s) that does\n"
62               "\tnot appear to be a Sticky atom.\n",
63               atomType->getName().c_str());
64      painCave.severity = OPENMD_ERROR;
65      painCave.isFatal = 1;
66      simError();
67    }
68    
69    DirectionalAtomType* daType = dynamic_cast<DirectionalAtomType*>(atomType);
70    GenericData* data = daType->getPropertyByName("Sticky");
71    if (data == NULL) {
72      sprintf( painCave.errMsg, "Sticky::getStickyParam could not find\n"
73               "\tSticky parameters for atomType %s.\n",
74               daType->getName().c_str());
75      painCave.severity = OPENMD_ERROR;
76      painCave.isFatal = 1;
77      simError();
78    }
79    
80    StickyParamGenericData* stickyData = dynamic_cast<StickyParamGenericData*>(data);
81    if (stickyData == NULL) {
82      sprintf( painCave.errMsg,
83               "Sticky::getStickyParam could not convert GenericData to\n"
84               "\tStickyParamGenericData for atom type %s\n",
85               daType->getName().c_str());
86      painCave.severity = OPENMD_ERROR;
87      painCave.isFatal = 1;
88      simError();          
89    }
90    
91    return stickyData->getData();
92  }
93  
57    void Sticky::initialize() {    
58      
59      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
# Line 103 | Line 66 | namespace OpenMD {
66      for (at = atomTypes->beginType(i); at != NULL;
67           at = atomTypes->nextType(i)) {
68        
69 <      if (at->isSticky() || at->isStickyPower())
70 <        addType(at);
69 >      StickyAdapter sa = StickyAdapter(at);
70 >      if (sa.isSticky()) addType(at);
71      }
72      
73      initialized_ = true;
# Line 112 | Line 75 | namespace OpenMD {
75        
76    void Sticky::addType(AtomType* atomType){
77      // add it to the map:
115    AtomTypeProperties atp = atomType->getATP();    
78      
79      pair<map<int,AtomType*>::iterator,bool> ret;    
80 <    ret = StickyMap.insert( pair<int, AtomType*>(atp.ident, atomType) );
80 >    ret = StickyMap.insert( pair<int, AtomType*>(atomType->getIdent(),
81 >                                                 atomType) );
82      if (ret.second == false) {
83        sprintf( painCave.errMsg,
84                 "Sticky already had a previous entry with ident %d\n",
85 <               atp.ident);
85 >               atomType->getIdent() );
86        painCave.severity = OPENMD_INFO;
87        painCave.isFatal = 0;
88        simError();        
# Line 127 | Line 90 | namespace OpenMD {
90      
91      RealType w0i, v0i, v0pi, rli, rui, rlpi, rupi;
92      
93 <    StickyParam sticky1 = getStickyParam(atomType);
93 >    StickyAdapter sticky1 = StickyAdapter(atomType);
94  
95      // Now, iterate over all known types and add to the mixing map:
96      
# Line 135 | Line 98 | namespace OpenMD {
98      for( it = StickyMap.begin(); it != StickyMap.end(); ++it) {
99        
100        AtomType* atype2 = (*it).second;
101 <    
102 <      StickyParam sticky2 = getStickyParam(atype2);
101 >      
102 >      StickyAdapter sticky2 = StickyAdapter(atype2);
103  
104        StickyInteractionData mixer;        
105            
# Line 145 | Line 108 | namespace OpenMD {
108        // Lorentz- Berthelot mixing rules (which happen to do the right thing
109        // when atomType and atype2 happen to be the same.
110        
111 <      mixer.rl   = 0.5 * ( sticky1.rl + sticky2.rl );
112 <      mixer.ru   = 0.5 * ( sticky1.ru + sticky2.ru );
113 <      mixer.rlp  = 0.5 * ( sticky1.rlp + sticky2.rlp );
114 <      mixer.rup  = 0.5 * ( sticky1.rup + sticky2.rup );
111 >      mixer.rl   = 0.5 * ( sticky1.getRl() + sticky2.getRl() );
112 >      mixer.ru   = 0.5 * ( sticky1.getRu() + sticky2.getRu() );
113 >      mixer.rlp  = 0.5 * ( sticky1.getRlp() + sticky2.getRlp() );
114 >      mixer.rup  = 0.5 * ( sticky1.getRup() + sticky2.getRup() );
115        mixer.rbig = max(mixer.ru, mixer.rup);
116 <      mixer.w0  = sqrt( sticky1.w0   * sticky2.w0  );
117 <      mixer.v0  = sqrt( sticky1.v0   * sticky2.v0  );
118 <      mixer.v0p = sqrt( sticky1.v0p  * sticky2.v0p );
119 <      mixer.isPower = atomType->isStickyPower() && atype2->isStickyPower();
116 >      mixer.w0  = sqrt( sticky1.getW0()   * sticky2.getW0()  );
117 >      mixer.v0  = sqrt( sticky1.getW0()   * sticky2.getV0()  );
118 >      mixer.v0p = sqrt( sticky1.getV0p()  * sticky2.getV0p() );
119 >      mixer.isPower = sticky1.isStickyPower() && sticky2.isStickyPower();
120  
121        CubicSpline* s = new CubicSpline();
122        s->addPoint(mixer.rl, 1.0);
# Line 186 | Line 149 | namespace OpenMD {
149     * idat structure.
150     */
151    
152 <  void Sticky::calcForce(InteractionData idat) {
152 >  void Sticky::calcForce(InteractionData &idat) {
153    
154      if (!initialized_) initialize();
155      
156 <    pair<AtomType*, AtomType*> key = make_pair(idat.atype1, idat.atype2);
157 <    StickyInteractionData mixer = MixingMap[key];
156 >    map<pair<AtomType*, AtomType*>, StickyInteractionData>::iterator it;
157 >    it = MixingMap.find(idat.atypes);
158 >    if (it != MixingMap.end()) {
159  
160 <    RealType w0  = mixer.w0;
197 <    RealType v0  = mixer.v0;
198 <    RealType v0p = mixer.v0p;
199 <    RealType rl  = mixer.rl;
200 <    RealType ru  = mixer.ru;
201 <    RealType rlp = mixer.rlp;
202 <    RealType rup = mixer.rup;
203 <    RealType rbig = mixer.rbig;
204 <    bool isPower = mixer.isPower;
205 <
206 <    if (idat.rij <= rbig) {
207 <
208 <      RealType r3 = idat.r2 * idat.rij;
209 <      RealType r5 = r3 * idat.r2;
210 <          
211 <      RotMat3x3d A1trans = idat.A1.transpose();
212 <      RotMat3x3d A2trans = idat.A2.transpose();
213 <
214 <      // rotate the inter-particle separation into the two different
215 <      // body-fixed coordinate systems:
216 <
217 <      Vector3d ri = idat.A1 * idat.d;
218 <
219 <      // negative sign because this is the vector from j to i:
220 <
221 <      Vector3d rj = - idat.A2 * idat.d;
222 <
223 <      RealType xi = ri.x();
224 <      RealType yi = ri.y();
225 <      RealType zi = ri.z();
226 <
227 <      RealType xj = rj.x();
228 <      RealType yj = rj.y();
229 <      RealType zj = rj.z();
230 <
231 <      RealType xi2 = xi * xi;
232 <      RealType yi2 = yi * yi;
233 <      RealType zi2 = zi * zi;
234 <
235 <      RealType xj2 = xj * xj;
236 <      RealType yj2 = yj * yj;
237 <      RealType zj2 = zj * zj;    
238 <
239 <      // calculate the switching info. from the splines
240 <
241 <      RealType s = 0.0;
242 <      RealType dsdr = 0.0;
243 <      RealType sp = 0.0;
244 <      RealType dspdr = 0.0;
245 <
246 <      if (idat.rij < ru) {
247 <        if (idat.rij < rl) {
248 <          s = 1.0;
249 <          dsdr = 0.0;
250 <        } else {          
251 <          // we are in the switching region
252 <
253 <          pair<RealType, RealType> res = mixer.s->getValueAndDerivativeAt(idat.rij);
254 <          s = res.first;
255 <          dsdr = res.second;
256 <        }
257 <      }
258 <
259 <      if (idat.rij < rup) {
260 <        if (idat.rij < rlp) {
261 <          sp = 1.0;
262 <          dspdr = 0.0;
263 <        } else {
264 <          // we are in the switching region
265 <
266 <          pair<RealType, RealType> res =mixer.sp->getValueAndDerivativeAt(idat.rij);
267 <          sp = res.first;
268 <          dspdr = res.second;
269 <        }
270 <      }
271 <
272 <      RealType wi = 2.0*(xi2-yi2)*zi / r3;
273 <      RealType wj = 2.0*(xj2-yj2)*zj / r3;
274 <      RealType w = wi+wj;
275 <
276 <
277 <      RealType zif = zi/idat.rij - 0.6;
278 <      RealType zis = zi/idat.rij + 0.8;
279 <
280 <      RealType zjf = zj/idat.rij - 0.6;
281 <      RealType zjs = zj/idat.rij + 0.8;
282 <
283 <      RealType wip = zif*zif*zis*zis - w0;
284 <      RealType wjp = zjf*zjf*zjs*zjs - w0;
285 <      RealType wp = wip + wjp;
286 <
287 <      Vector3d dwi(4.0*xi*zi/r3  - 6.0*xi*zi*(xi2-yi2)/r5,
288 <                   - 4.0*yi*zi/r3  - 6.0*yi*zi*(xi2-yi2)/r5,
289 <                   2.0*(xi2-yi2)/r3  - 6.0*zi2*(xi2-yi2)/r5);
160 >      StickyInteractionData mixer = (*it).second;
161        
162 <      Vector3d dwj(4.0*xj*zj/r3  - 6.0*xj*zj*(xj2-yj2)/r5,
163 <                   - 4.0*yj*zj/r3  - 6.0*yj*zj*(xj2-yj2)/r5,
164 <                   2.0*(xj2-yj2)/r3  - 6.0*zj2*(xj2-yj2)/r5);
165 <
166 <      RealType uglyi = zif*zif*zis + zif*zis*zis;
167 <      RealType uglyj = zjf*zjf*zjs + zjf*zjs*zjs;
168 <
169 <      Vector3d dwip(-2.0*xi*zi*uglyi/r3,
170 <                    -2.0*yi*zi*uglyi/r3,
300 <                    2.0*(1.0/idat.rij - zi2/r3)*uglyi);
301 <
302 <      Vector3d dwjp(-2.0*xj*zj*uglyj/r3,
303 <                    -2.0*yj*zj*uglyj/r3,
304 <                    2.0*(1.0/idat.rij - zj2/r3)*uglyj);
305 <
306 <      Vector3d dwidu(4.0*(yi*zi2 + 0.5*yi*(xi2-yi2))/r3,
307 <                     4.0*(xi*zi2 - 0.5*xi*(xi2-yi2))/r3,
308 <                     - 8.0*xi*yi*zi/r3);
309 <
310 <      Vector3d dwjdu(4.0*(yj*zj2 + 0.5*yj*(xj2-yj2))/r3,
311 <                     4.0*(xj*zj2 - 0.5*xj*(xj2-yj2))/r3,
312 <                     - 8.0*xj*yj*zj/r3);
162 >      RealType w0  = mixer.w0;
163 >      RealType v0  = mixer.v0;
164 >      RealType v0p = mixer.v0p;
165 >      RealType rl  = mixer.rl;
166 >      RealType ru  = mixer.ru;
167 >      RealType rlp = mixer.rlp;
168 >      RealType rup = mixer.rup;
169 >      RealType rbig = mixer.rbig;
170 >      bool isPower = mixer.isPower;
171        
172 <      Vector3d dwipdu(2.0*yi*uglyi/idat.rij,
173 <                      -2.0*xi*uglyi/idat.rij,
174 <                      0.0);
175 <
176 <      Vector3d dwjpdu(2.0*yj*uglyj/idat.rij,
177 <                      -2.0*xj*uglyj/idat.rij,
178 <                      0.0);
172 >      if ( *(idat.rij) <= rbig) {
173 >        
174 >        RealType r3 = *(idat.r2) * *(idat.rij);
175 >        RealType r5 = r3 * *(idat.r2);
176 >        
177 >        RotMat3x3d A1trans = idat.A1->transpose();
178 >        RotMat3x3d A2trans = idat.A2->transpose();
179 >        
180 >        // rotate the inter-particle separation into the two different
181 >        // body-fixed coordinate systems:
182 >        
183 >        Vector3d ri = *(idat.A1) * *(idat.d);
184 >        
185 >        // negative sign because this is the vector from j to i:
186 >        
187 >        Vector3d rj = - *(idat.A2) * *(idat.d);
188 >        
189 >        RealType xi = ri.x();
190 >        RealType yi = ri.y();
191 >        RealType zi = ri.z();
192 >        
193 >        RealType xj = rj.x();
194 >        RealType yj = rj.y();
195 >        RealType zj = rj.z();
196 >        
197 >        RealType xi2 = xi * xi;
198 >        RealType yi2 = yi * yi;
199 >        RealType zi2 = zi * zi;
200 >        
201 >        RealType xj2 = xj * xj;
202 >        RealType yj2 = yj * yj;
203 >        RealType zj2 = zj * zj;    
204 >        
205 >        // calculate the switching info. from the splines
206 >        
207 >        RealType s = 0.0;
208 >        RealType dsdr = 0.0;
209 >        RealType sp = 0.0;
210 >        RealType dspdr = 0.0;
211 >        
212 >        if ( *(idat.rij) < ru) {
213 >          if ( *(idat.rij) < rl) {
214 >            s = 1.0;
215 >            dsdr = 0.0;
216 >          } else {          
217 >            // we are in the switching region
218 >            
219 >            pair<RealType, RealType> res = mixer.s->getValueAndDerivativeAt(*(idat.rij));
220 >            s = res.first;
221 >            dsdr = res.second;
222 >          }
223 >        }
224 >        
225 >        if (*(idat.rij) < rup) {
226 >          if ( *(idat.rij) < rlp) {
227 >            sp = 1.0;
228 >            dspdr = 0.0;
229 >          } else {
230 >            // we are in the switching region
231 >            
232 >            pair<RealType, RealType> res =mixer.sp->getValueAndDerivativeAt( *(idat.rij));
233 >            sp = res.first;
234 >            dspdr = res.second;
235 >          }
236 >        }
237 >        
238 >        RealType wi = 2.0*(xi2-yi2)*zi / r3;
239 >        RealType wj = 2.0*(xj2-yj2)*zj / r3;
240 >        RealType w = wi+wj;
241 >        
242 >        
243 >        RealType zif = zi/ *(idat.rij)  - 0.6;
244 >        RealType zis = zi/ *(idat.rij)  + 0.8;
245 >        
246 >        RealType zjf = zj/ *(idat.rij)  - 0.6;
247 >        RealType zjs = zj/ *(idat.rij)  + 0.8;
248 >        
249 >        RealType wip = zif*zif*zis*zis - w0;
250 >        RealType wjp = zjf*zjf*zjs*zjs - w0;
251 >        RealType wp = wip + wjp;
252 >        
253 >        Vector3d dwi(4.0*xi*zi/r3  - 6.0*xi*zi*(xi2-yi2)/r5,
254 >                     - 4.0*yi*zi/r3  - 6.0*yi*zi*(xi2-yi2)/r5,
255 >                     2.0*(xi2-yi2)/r3  - 6.0*zi2*(xi2-yi2)/r5);
256 >        
257 >        Vector3d dwj(4.0*xj*zj/r3  - 6.0*xj*zj*(xj2-yj2)/r5,
258 >                     - 4.0*yj*zj/r3  - 6.0*yj*zj*(xj2-yj2)/r5,
259 >                     2.0*(xj2-yj2)/r3  - 6.0*zj2*(xj2-yj2)/r5);
260 >        
261 >        RealType uglyi = zif*zif*zis + zif*zis*zis;
262 >        RealType uglyj = zjf*zjf*zjs + zjf*zjs*zjs;
263  
264 <      if (isPower) {
265 <        RealType frac1 = 0.25;
266 <        RealType frac2 = 0.75;      
267 <        RealType wi2 = wi*wi;
268 <        RealType wj2 = wj*wj;
269 <        // sticky power has no w' function:
270 <        w = frac1 * wi * wi2 + frac2*wi + frac1*wj*wj2 + frac2*wj + v0p;
271 <        wp = 0.0;
272 <        dwi = frac1*3.0*wi2*dwi + frac2*dwi;
273 <        dwj = frac1*3.0*wj2*dwi + frac2*dwi;
274 <        dwip = V3Zero;
275 <        dwjp = V3Zero;
276 <        dwidu = frac1*3.0*wi2*dwidu + frac2*dwidu;
277 <        dwidu = frac1*3.0*wj2*dwjdu + frac2*dwjdu;
278 <        dwipdu = V3Zero;
279 <        dwjpdu = V3Zero;
280 <        sp = 0.0;
281 <        dspdr = 0.0;
264 >        Vector3d dwip(-2.0*xi*zi*uglyi/r3,
265 >                      -2.0*yi*zi*uglyi/r3,
266 >                      2.0*(1.0/ *(idat.rij)  - zi2/r3)*uglyi);
267 >        
268 >        Vector3d dwjp(-2.0*xj*zj*uglyj/r3,
269 >                      -2.0*yj*zj*uglyj/r3,
270 >                      2.0*(1.0/ *(idat.rij)  - zj2/r3)*uglyj);
271 >        
272 >        Vector3d dwidu(4.0*(yi*zi2 + 0.5*yi*(xi2-yi2))/r3,
273 >                       4.0*(xi*zi2 - 0.5*xi*(xi2-yi2))/r3,
274 >                       - 8.0*xi*yi*zi/r3);
275 >        
276 >        Vector3d dwjdu(4.0*(yj*zj2 + 0.5*yj*(xj2-yj2))/r3,
277 >                       4.0*(xj*zj2 - 0.5*xj*(xj2-yj2))/r3,
278 >                       - 8.0*xj*yj*zj/r3);
279 >        
280 >        Vector3d dwipdu(2.0*yi*uglyi/ *(idat.rij) ,
281 >                        -2.0*xi*uglyi/ *(idat.rij) ,
282 >                        0.0);
283 >        
284 >        Vector3d dwjpdu(2.0*yj*uglyj/ *(idat.rij) ,
285 >                        -2.0*xj*uglyj/ *(idat.rij) ,
286 >                        0.0);
287 >        
288 >        if (isPower) {
289 >          RealType frac1 = 0.25;
290 >          RealType frac2 = 0.75;      
291 >          RealType wi2 = wi*wi;
292 >          RealType wj2 = wj*wj;
293 >          // sticky power has no w' function:
294 >          w = frac1 * wi * wi2 + frac2*wi + frac1*wj*wj2 + frac2*wj + v0p;
295 >          wp = 0.0;
296 >          dwi = frac1*RealType(3.0)*wi2*dwi + frac2*dwi;
297 >          dwj = frac1*RealType(3.0)*wj2*dwi + frac2*dwi;
298 >          dwip = V3Zero;
299 >          dwjp = V3Zero;
300 >          dwidu = frac1*RealType(3.0)*wi2*dwidu + frac2*dwidu;
301 >          dwidu = frac1*RealType(3.0)*wj2*dwjdu + frac2*dwjdu;
302 >          dwipdu = V3Zero;
303 >          dwjpdu = V3Zero;
304 >          sp = 0.0;
305 >          dspdr = 0.0;
306 >        }
307 >        
308 >        *(idat.vpair) += RealType(0.5)*(v0*s*w + v0p*sp*wp);
309 >        (*(idat.pot))[HYDROGENBONDING_FAMILY] += RealType(0.5)*(v0*s*w + v0p*sp*wp)* *(idat.sw) ;
310 >        
311 >        // do the torques first since they are easy:
312 >        // remember that these are still in the body-fixed axes
313 >        
314 >        Vector3d ti = RealType(0.5)* *(idat.sw) *(v0*s*dwidu + v0p*sp*dwipdu);
315 >        Vector3d tj = RealType(0.5)* *(idat.sw) *(v0*s*dwjdu + v0p*sp*dwjpdu);
316 >        
317 >        // go back to lab frame using transpose of rotation matrix:
318 >        
319 >        *(idat.t1) += A1trans * ti;
320 >        *(idat.t2) += A2trans * tj;
321 >        
322 >        // Now, on to the forces:
323 >        
324 >        // first rotate the i terms back into the lab frame:
325 >        
326 >        Vector3d radcomi = (v0 * s * dwi + v0p * sp * dwip) *  *(idat.sw);
327 >        Vector3d radcomj = (v0 * s * dwj + v0p * sp * dwjp) *  *(idat.sw);
328 >        
329 >        Vector3d fii = A1trans * radcomi;
330 >        Vector3d fjj = A2trans * radcomj;
331 >        
332 >        // now assemble these with the radial-only terms:
333 >        
334 >        *(idat.f1) += RealType(0.5) * ((v0*dsdr*w + v0p*dspdr*wp) * *(idat.d) /
335 >                                       *(idat.rij)  + fii - fjj);
336 >        
337        }
341
342      idat.vpair += 0.5*(v0*s*w + v0p*sp*wp);
343      idat.pot += 0.5*(v0*s*w + v0p*sp*wp)*idat.sw;
344
345      // do the torques first since they are easy:
346      // remember that these are still in the body-fixed axes
347
348      Vector3d ti = 0.5*idat.sw*(v0*s*dwidu + v0p*sp*dwipdu);
349      Vector3d tj = 0.5*idat.sw*(v0*s*dwjdu + v0p*sp*dwjpdu);
350
351      // go back to lab frame using transpose of rotation matrix:
352
353      idat.t1 += A1trans * ti;
354      idat.t2 += A2trans * tj;
355
356      // Now, on to the forces:
357
358      // first rotate the i terms back into the lab frame:
359
360      Vector3d radcomi = (v0 * s * dwi + v0p * sp * dwip) * idat.sw;
361      Vector3d radcomj = (v0 * s * dwj + v0p * sp * dwjp) * idat.sw;
362
363      Vector3d fii = A1trans * radcomi;
364      Vector3d fjj = A2trans * radcomj;
365      
366      // now assemble these with the radial-only terms:
367      
368      idat.f1 += 0.5 * ((v0*dsdr*w + v0p*dspdr*wp) * idat.d /
369                        idat.rij + fii - fjj);
370
338      }
372      
373    return;
339      
340 +    return;      
341    }
342 +
343 +  RealType Sticky::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
344 +    if (!initialized_) initialize();  
345 +    map<pair<AtomType*, AtomType*>, StickyInteractionData>::iterator it;
346 +    it = MixingMap.find(atypes);
347 +    if (it == MixingMap.end())
348 +      return 0.0;
349 +    else  {
350 +      StickyInteractionData mixer = (*it).second;
351 +      return mixer.rbig;
352 +    }
353 +  }
354   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines