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

Comparing:
branches/development/src/nonbonded/EAM.cpp (file contents), Revision 1629 by gezelter, Wed Sep 14 21:15:17 2011 UTC vs.
trunk/src/nonbonded/EAM.cpp (file contents), Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 35 | Line 35
35   *                                                                      
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).                        
38 > * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
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 50 | Line 51 | namespace OpenMD {
51  
52   namespace OpenMD {
53  
54 <  EAM::EAM() : name_("EAM"), initialized_(false), forceField_(NULL),
55 <               mixMeth_(eamJohnson), eamRcut_(0.0), haveCutoffRadius_(false) {}
54 >  EAM::EAM() : initialized_(false), haveCutoffRadius_(false),
55 >               forceField_(NULL), eamRcut_(0.0), mixMeth_(eamJohnson),
56 >               name_("EAM") {}
57    
58 <  EAMParam EAM::getEAMParam(AtomType* atomType) {
59 <    
60 <    // Do sanity checking on the AtomType we were passed before
61 <    // building any data structures:
62 <    if (!atomType->isEAM()) {
61 <      sprintf( painCave.errMsg,
62 <               "EAM::getEAMParam was passed an atomType (%s) that does not\n"
63 <               "\tappear to be an embedded atom method (EAM) atom.\n",
64 <               atomType->getName().c_str());
65 <      painCave.severity = OPENMD_ERROR;
66 <      painCave.isFatal = 1;
67 <      simError();
68 <    }
69 <    
70 <    GenericData* data = atomType->getPropertyByName("EAM");
71 <    if (data == NULL) {
72 <      sprintf( painCave.errMsg, "EAM::getEAMParam could not find EAM\n"
73 <               "\tparameters for atomType %s.\n",
74 <               atomType->getName().c_str());
75 <      painCave.severity = OPENMD_ERROR;
76 <      painCave.isFatal = 1;
77 <      simError();
78 <    }
79 <    
80 <    EAMParamGenericData* eamData = dynamic_cast<EAMParamGenericData*>(data);
81 <    if (eamData == NULL) {
82 <      sprintf( painCave.errMsg,
83 <               "EAM::getEAMParam could not convert GenericData to EAMParam for\n"
84 <               "\tatom type %s\n", atomType->getName().c_str());
85 <      painCave.severity = OPENMD_ERROR;
86 <      painCave.isFatal = 1;
87 <      simError();          
88 <    }
89 <    
90 <    return eamData->getData();
91 <  }
58 >  CubicSpline* EAM::getPhi(AtomType* atomType1, AtomType* atomType2) {  
59 >    EAMAdapter ea1 = EAMAdapter(atomType1);
60 >    EAMAdapter ea2 = EAMAdapter(atomType2);
61 >    CubicSpline* z1 = ea1.getZ();
62 >    CubicSpline* z2 = ea2.getZ();
63  
64 <  CubicSpline* EAM::getZ(AtomType* atomType) {    
65 <    EAMParam eamParam = getEAMParam(atomType);
66 <    int nr = eamParam.nr;
67 <    RealType dr = eamParam.dr;
68 <    vector<RealType> rvals;
98 <    
99 <    for (int i = 0; i < nr; i++) rvals.push_back(RealType(i) * dr);
100 <      
101 <    CubicSpline* cs = new CubicSpline();
102 <    cs->addPoints(rvals, eamParam.Z);
103 <    return cs;
104 <  }
105 <
106 <  RealType EAM::getRcut(AtomType* atomType) {    
107 <    EAMParam eamParam = getEAMParam(atomType);
108 <    return eamParam.rcut;
109 <  }
110 <
111 <  CubicSpline* EAM::getRho(AtomType* atomType) {    
112 <    EAMParam eamParam = getEAMParam(atomType);
113 <    int nr = eamParam.nr;
114 <    RealType dr = eamParam.dr;
115 <    vector<RealType> rvals;
116 <    
117 <    for (int i = 0; i < nr; i++) rvals.push_back(RealType(i) * dr);
118 <      
119 <    CubicSpline* cs = new CubicSpline();
120 <    cs->addPoints(rvals, eamParam.rho);
121 <    return cs;
122 <  }
123 <
124 <  CubicSpline* EAM::getF(AtomType* atomType) {    
125 <    EAMParam eamParam = getEAMParam(atomType);
126 <    int nrho = eamParam.nrho;
127 <    RealType drho = eamParam.drho;
128 <    vector<RealType> rhovals;
129 <    vector<RealType> scaledF;
130 <    
131 <    for (int i = 0; i < nrho; i++) {
132 <      rhovals.push_back(RealType(i) * drho);
133 <      scaledF.push_back( eamParam.F[i] * 23.06054 );
134 <    }
135 <      
136 <    CubicSpline* cs = new CubicSpline();
137 <    cs->addPoints(rhovals, scaledF);
138 <    return cs;
139 <  }
140 <  
141 <  CubicSpline* EAM::getPhi(AtomType* atomType1, AtomType* atomType2) {    
142 <    EAMParam eamParam1 = getEAMParam(atomType1);
143 <    EAMParam eamParam2 = getEAMParam(atomType2);
144 <    CubicSpline* z1 = getZ(atomType1);
145 <    CubicSpline* z2 = getZ(atomType2);
64 >    // Thise prefactors convert the charge-charge interactions into
65 >    // kcal / mol all were computed assuming distances are measured in
66 >    // angstroms Charge-Charge, assuming charges are measured in
67 >    // electrons.  Matches value in Electrostatics.cpp
68 >    pre11_ = 332.0637778;
69  
70      // make the r grid:
71  
149
72      // we need phi out to the largest value we'll encounter in the radial space;
73      
74      RealType rmax = 0.0;
75 <    rmax = max(rmax, eamParam1.rcut);
76 <    rmax = max(rmax, eamParam1.nr * eamParam1.dr);
75 >    rmax = max(rmax, ea1.getRcut());
76 >    rmax = max(rmax, ea1.getNr() * ea1.getDr());
77  
78 <    rmax = max(rmax, eamParam2.rcut);
79 <    rmax = max(rmax, eamParam2.nr * eamParam2.dr);
78 >    rmax = max(rmax, ea2.getRcut());
79 >    rmax = max(rmax, ea2.getNr() * ea2.getDr());
80  
81      // use the smallest dr (finest grid) to build our grid:
82  
83 <    RealType dr = min(eamParam1.dr, eamParam2.dr);
83 >    RealType dr = min(ea1.getDr(), ea2.getDr());
84  
85      int nr = int(rmax/dr + 0.5);
86  
# Line 174 | Line 96 | namespace OpenMD {
96  
97      phivals.push_back(0.0);
98  
99 <    for (int i = 1; i < rvals.size(); i++ ) {
99 >    for (unsigned int i = 1; i < rvals.size(); i++ ) {
100        r = rvals[i];
101  
102        // only use z(r) if we're inside this atom's cutoff radius,
# Line 182 | Line 104 | namespace OpenMD {
104        // means that our phi grid goes out beyond the cutoff of the
105        // pair potential
106  
107 <      zi = r <= eamParam1.rcut ? z1->getValueAt(r) : 0.0;
108 <      zj = r <= eamParam2.rcut ? z2->getValueAt(r) : 0.0;
107 >      zi = r <= ea1.getRcut() ? z1->getValueAt(r) : 0.0;
108 >      zj = r <= ea2.getRcut() ? z2->getValueAt(r) : 0.0;
109  
110 <      phi = 331.999296 * (zi * zj) / r;
111 <
110 >      phi = pre11_ * (zi * zj) / r;
111 >      
112        phivals.push_back(phi);
113      }
192      
114      CubicSpline* cs = new CubicSpline();
115      cs->addPoints(rvals, phivals);
116      return cs;
# Line 201 | Line 122 | namespace OpenMD {
122    }
123  
124    void EAM::initialize() {
204
125      // set up the mixing method:
126      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
127      string EAMMixMeth = fopts.getEAMMixingMethod();
# Line 215 | Line 135 | namespace OpenMD {
135        mixMeth_ = eamUnknown;
136        
137      // find all of the EAM atom Types:
138 <    ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
139 <    ForceField::AtomTypeContainer::MapTypeIterator i;
140 <    AtomType* at;
138 >    EAMtypes.clear();
139 >    EAMtids.clear();
140 >    EAMdata.clear();
141 >    MixingMap.clear();
142 >    nEAM_ = 0;
143 >    
144 >    EAMtids.resize( forceField_->getNAtomType(), -1);
145  
146 <    for (at = atomTypes->beginType(i); at != NULL;
147 <         at = atomTypes->nextType(i)) {
148 <      
225 <      if (at->isEAM())
226 <        addType(at);
146 >    set<AtomType*>::iterator at;
147 >    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
148 >      if ((*at)->isEAM()) nEAM_++;
149      }
150 +    EAMdata.resize(nEAM_);
151 +    MixingMap.resize(nEAM_);
152 +
153 +    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
154 +      if ((*at)->isEAM()) addType(*at);
155 +    }
156      
157      // find all of the explicit EAM interactions (setfl):
158      ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes();
# Line 277 | Line 205 | namespace OpenMD {
205  
206    void EAM::addType(AtomType* atomType){
207  
208 +    EAMAdapter ea = EAMAdapter(atomType);
209      EAMAtomData eamAtomData;
281    
282    eamAtomData.rho = getRho(atomType);
283    eamAtomData.F = getF(atomType);
284    eamAtomData.Z = getZ(atomType);
285    eamAtomData.rcut = getRcut(atomType);
210  
211 +    eamAtomData.rho = ea.getRho();
212 +    eamAtomData.F = ea.getF();
213 +    eamAtomData.Z = ea.getZ();
214 +    eamAtomData.rcut = ea.getRcut();
215 +      
216      // add it to the map:
217 <    AtomTypeProperties atp = atomType->getATP();    
217 >    int atid = atomType->getIdent();
218 >    int eamtid = EAMtypes.size();
219  
220 <    pair<map<int,AtomType*>::iterator,bool> ret;    
221 <    ret = EAMlist.insert( pair<int, AtomType*>(atp.ident, atomType) );
220 >    pair<set<int>::iterator,bool> ret;    
221 >    ret = EAMtypes.insert( atid );
222      if (ret.second == false) {
223        sprintf( painCave.errMsg,
224                 "EAM already had a previous entry with ident %d\n",
225 <               atp.ident);
225 >               atid);
226        painCave.severity = OPENMD_INFO;
227        painCave.isFatal = 0;
228        simError();        
229      }
230  
231 <    EAMMap[atomType] = eamAtomData;
231 >
232 >    EAMtids[atid] = eamtid;
233 >    EAMdata[eamtid] = eamAtomData;
234 >    MixingMap[eamtid].resize(nEAM_);
235      
236      // Now, iterate over all known types and add to the mixing map:
237      
238 <    map<AtomType*, EAMAtomData>::iterator it;
239 <    for( it = EAMMap.begin(); it != EAMMap.end(); ++it) {
238 >    std::set<int>::iterator it;
239 >    for( it = EAMtypes.begin(); it != EAMtypes.end(); ++it) {
240        
241 <      AtomType* atype2 = (*it).first;
241 >      int eamtid2 = EAMtids[ (*it) ];
242 >      AtomType* atype2 = forceField_->getAtomType( (*it) );
243  
244        EAMInteractionData mixer;
245        mixer.phi = getPhi(atomType, atype2);
246 +      mixer.rcut = mixer.phi->getLimits().second;
247        mixer.explicitlySet = false;
248  
249 <      pair<AtomType*, AtomType*> key1, key2;
315 <      key1 = make_pair(atomType, atype2);
316 <      key2 = make_pair(atype2, atomType);
249 >      MixingMap[eamtid2].resize( nEAM_ );
250        
251 <      MixingMap[key1] = mixer;
252 <      if (key2 != key1) {
253 <        MixingMap[key2] = mixer;
251 >      MixingMap[eamtid][eamtid2] = mixer;
252 >      if (eamtid2 != eamtid) {
253 >        MixingMap[eamtid2][eamtid] = mixer;
254        }
255      }      
256      return;
# Line 339 | Line 272 | namespace OpenMD {
272  
273      cs->addPoints(rVals, phiVals);
274      mixer.phi = cs;
275 +    mixer.rcut = mixer.phi->getLimits().second;
276      mixer.explicitlySet = true;
277  
278 <    pair<AtomType*, AtomType*> key1, key2;
279 <    key1 = make_pair(atype1, atype2);
346 <    key2 = make_pair(atype2, atype1);
278 >    int eamtid1 = EAMtids[ atype1->getIdent() ];
279 >    int eamtid2 = EAMtids[ atype2->getIdent() ];
280      
281 <    MixingMap[key1] = mixer;
282 <    if (key2 != key1) {
283 <      MixingMap[key2] = mixer;
281 >    MixingMap[eamtid1][eamtid2] = mixer;
282 >    if (eamtid2 != eamtid1) {
283 >      MixingMap[eamtid2][eamtid1] = mixer;
284      }    
285      return;
286    }
# Line 356 | Line 289 | namespace OpenMD {
289      
290      if (!initialized_) initialize();
291      
292 <    EAMAtomData data1 = EAMMap[idat.atypes.first];
293 <    EAMAtomData data2 = EAMMap[idat.atypes.second];
294 <    
292 >    EAMAtomData &data1 = EAMdata[EAMtids[idat.atid1]];
293 >    EAMAtomData &data2 = EAMdata[EAMtids[idat.atid2]];
294 >
295      if (haveCutoffRadius_)
296        if ( *(idat.rij) > eamRcut_) return;
297      
298 <    if ( *(idat.rij) < data1.rcut)
299 <      *(idat.rho1) += data1.rho->getValueAt( *(idat.rij));
300 <    
298 >    if ( *(idat.rij) < data1.rcut) {
299 >      *(idat.rho2) += data1.rho->getValueAt( *(idat.rij));
300 >    }
301        
302 <    if ( *(idat.rij) < data2.rcut)
303 <      *(idat.rho2) += data2.rho->getValueAt( *(idat.rij));
302 >    if ( *(idat.rij) < data2.rcut) {
303 >      *(idat.rho1) += data2.rho->getValueAt( *(idat.rij));
304 >    }
305      
306      return;  
307    }
# Line 375 | Line 309 | namespace OpenMD {
309    void EAM::calcFunctional(SelfData &sdat) {
310      
311      if (!initialized_) initialize();
312 +    EAMAtomData &data1 = EAMdata[ EAMtids[sdat.atid] ];
313 +            
314 +    data1.F->getValueAndDerivativeAt( *(sdat.rho), *(sdat.frho),
315 +                                      *(sdat.dfrhodrho) );
316  
317 <    EAMAtomData data1 = EAMMap[ sdat.atype ];
318 <        
319 <    pair<RealType, RealType> result = data1.F->getValueAndDerivativeAt( *(sdat.rho) );
317 >    (*(sdat.pot))[METALLIC_FAMILY] += *(sdat.frho);
318 >    if (sdat.doParticlePot) {
319 >      *(sdat.particlePot) += *(sdat.frho);
320 >    }
321  
383    *(sdat.frho) = result.first;
384    *(sdat.dfrhodrho) = result.second;
385
386    (*(sdat.pot))[METALLIC_FAMILY] += result.first;
387    *(sdat.particlePot) += result.first;
388
322      return;
323    }
324  
# Line 397 | Line 330 | namespace OpenMD {
330      if (haveCutoffRadius_)
331        if ( *(idat.rij) > eamRcut_) return;
332    
333 <    pair<RealType, RealType> res;
333 >
334 >    int eamtid1 = EAMtids[idat.atid1];
335 >    int eamtid2 = EAMtids[idat.atid2];
336 >    EAMAtomData &data1 = EAMdata[eamtid1];
337 >    EAMAtomData &data2 = EAMdata[eamtid2];
338      
402    EAMAtomData data1 = EAMMap[idat.atypes.first];
403    EAMAtomData data2 = EAMMap[idat.atypes.second];
404    
339      // get type-specific cutoff radii
340      
341      RealType rci = data1.rcut;
342      RealType rcj = data2.rcut;
343 +
344      
345      RealType rha(0.0), drha(0.0), rhb(0.0), drhb(0.0);
346      RealType pha(0.0), dpha(0.0), phb(0.0), dphb(0.0);
# Line 413 | Line 348 | namespace OpenMD {
348      RealType drhoidr, drhojdr, dudr;
349      
350      if ( *(idat.rij) < rci) {
351 <      res = data1.rho->getValueAndDerivativeAt( *(idat.rij));
352 <      rha = res.first;
353 <      drha = res.second;
419 <      
420 <      res = MixingMap[make_pair(idat.atypes.first, idat.atypes.first)].phi->getValueAndDerivativeAt( *(idat.rij) );
421 <      pha = res.first;
422 <      dpha = res.second;
351 >      data1.rho->getValueAndDerivativeAt( *(idat.rij), rha, drha);
352 >      CubicSpline* phi = MixingMap[eamtid1][eamtid1].phi;
353 >      phi->getValueAndDerivativeAt( *(idat.rij), pha, dpha);
354      }
355      
356      if ( *(idat.rij) < rcj) {
357 <      res = data2.rho->getValueAndDerivativeAt( *(idat.rij) );
358 <      rhb = res.first;
359 <      drhb = res.second;
429 <      
430 <      res = MixingMap[make_pair(idat.atypes.second, idat.atypes.second)].phi->getValueAndDerivativeAt( *(idat.rij) );
431 <      phb = res.first;
432 <      dphb = res.second;
357 >      data2.rho->getValueAndDerivativeAt( *(idat.rij), rhb, drhb );
358 >      CubicSpline* phi = MixingMap[eamtid2][eamtid2].phi;
359 >      phi->getValueAndDerivativeAt( *(idat.rij), phb, dphb);
360      }
434
361      switch(mixMeth_) {
362      case eamJohnson:
437      
363        if ( *(idat.rij) < rci) {
364          phab = phab + 0.5 * (rhb / rha) * pha;
365          dvpdr = dvpdr + 0.5*((rhb/rha)*dpha +
366                               pha*((drhb/rha) - (rhb*drha/rha/rha)));
367        }
368 <      
444 <      
445 <      
368 >                
369        if ( *(idat.rij) < rcj) {
370          phab = phab + 0.5 * (rha / rhb) * phb;
371          dvpdr = dvpdr + 0.5 * ((rha/rhb)*dphb +
372                                 phb*((drha/rhb) - (rha*drhb/rhb/rhb)));
373        }
451      
374        break;
453      
375      case eamDaw:
376 <      res = MixingMap[idat.atypes].phi->getValueAndDerivativeAt( *(idat.rij));
377 <      phab = res.first;
378 <      dvpdr = res.second;
379 <      
376 >      if ( *(idat.rij) <  MixingMap[eamtid1][eamtid2].rcut) {
377 >        MixingMap[eamtid1][eamtid2].phi->getValueAndDerivativeAt( *(idat.rij),
378 >                                                                  phab, dvpdr);
379 >      }
380        break;
381      case eamUnknown:
382      default:
# Line 475 | Line 396 | namespace OpenMD {
396      dudr = drhojdr* *(idat.dfrho1) + drhoidr* *(idat.dfrho2) + dvpdr;
397      
398      *(idat.f1) += *(idat.d) * dudr / *(idat.rij);
399 <        
400 <    // particlePot is the difference between the full potential and
401 <    // the full potential without the presence of a particular
402 <    // particle (atom1).
403 <    //
404 <    // This reduces the density at other particle locations, so we
405 <    // need to recompute the density at atom2 assuming atom1 didn't
406 <    // contribute.  This then requires recomputing the density
407 <    // functional for atom2 as well.
399 >
400 >    if (idat.doParticlePot) {
401 >      // particlePot is the difference between the full potential and
402 >      // the full potential without the presence of a particular
403 >      // particle (atom1).
404 >      //
405 >      // This reduces the density at other particle locations, so we
406 >      // need to recompute the density at atom2 assuming atom1 didn't
407 >      // contribute.  This then requires recomputing the density
408 >      // functional for atom2 as well.
409 >      
410 >      *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
411 >        - *(idat.frho2);
412 >      
413 >      *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
414 >        - *(idat.frho1);
415 >    }
416      
417 <    *(idat.particlePot1) += data2.F->getValueAt( *(idat.rho2) - rha )
418 <      - *(idat.frho2);
419 <    
491 <    *(idat.particlePot2) += data1.F->getValueAt( *(idat.rho1) - rhb)
492 <      - *(idat.frho1);
493 <    
494 <    (*(idat.pot))[METALLIC_FAMILY] += phab;
495 <    
496 <    *(idat.vpair) += phab;
497 <  
498 <    return;
499 <    
417 >    (*(idat.pot))[METALLIC_FAMILY] += phab;    
418 >    *(idat.vpair) += phab;  
419 >    return;    
420    }
421  
422    RealType EAM::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
# Line 504 | Line 424 | namespace OpenMD {
424  
425      RealType cut = 0.0;
426  
427 <    map<AtomType*, EAMAtomData>::iterator it;
428 <
429 <    it = EAMMap.find(atypes.first);
430 <    if (it != EAMMap.end()) {
431 <      EAMAtomData data1 = (*it).second;
427 >    int atid1 = atypes.first->getIdent();
428 >    int atid2 = atypes.second->getIdent();
429 >    int eamtid1 = EAMtids[atid1];
430 >    int eamtid2 = EAMtids[atid2];
431 >    
432 >    if (eamtid1 != -1) {
433 >      EAMAtomData data1 = EAMdata[eamtid1];
434        cut = data1.rcut;
435      }
436  
437 <    it = EAMMap.find(atypes.second);
438 <    if (it != EAMMap.end()) {
517 <      EAMAtomData data2 = (*it).second;
437 >    if (eamtid2 != -1) {
438 >      EAMAtomData data2 = EAMdata[eamtid2];
439        if (data2.rcut > cut)
440          cut = data2.rcut;
441      }
442 <
442 >    
443      return cut;
444    }
445   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines