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

Comparing branches/development/src/nonbonded/SHAPES.cpp (file contents):
Revision 1501 by gezelter, Wed Sep 15 19:32:10 2010 UTC vs.
Revision 1665 by gezelter, Tue Nov 22 20:38:56 2011 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 49 | Line 50 | namespace OpenMD {
50  
51   using namespace std;
52   namespace OpenMD {
53 <  
54 <  bool SHAPES::initialized_ = false;
55 <  int SHAPES::lMax_ = 64;
56 <  int SHAPES::mMax_ = 64;
57 <  ForceField* SHAPES::forceField_ = NULL;
58 <  map<int, AtomType*> SHAPES::ShapesMap;
58 <  map<pair<AtomType*, AtomType*>, SHAPESInteractionData> SHAPES::MixingMap;
59 <  
60 <  SHAPES* SHAPES::_instance = NULL;
61 <
62 <  SHAPES* SHAPES::Instance() {
63 <    if (!_instance) {
64 <      _instance = new SHAPES();
65 <    }
66 <    return _instance;
53 >
54 >  SHAPES::SHAPES() {
55 >    initialized_ = false;
56 >    lMax_ = 64;
57 >    mMax_ = 64;
58 >    forceField_ = NULL;
59    }
60 <
60 >  
61    void SHAPES::initialize() {    
62      
63      ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
# Line 75 | Line 67 | namespace OpenMD {
67  
68      // SHAPES handles all of the SHAPES-SHAPES interactions as well as
69      // SHAPES-LJ cross interactions:
70 <
70 >    
71      for (at = atomTypes->beginType(i); at != NULL;
72           at = atomTypes->nextType(i)) {
73        
74 <      if (at->isShape() || at->isLennardJones())
75 <        addType(at);
74 >      if (at->isShape())
75 >        addShape(dynamic_cast<ShapeAtomType*>(at));
76 >
77 >      if (at->isLennardJones())
78 >        addLJ(at);
79 >      
80      }
81 <  
81 >    
82      initialized_ = true;
83    }
84 <      
85 <  void SHAPES::addType(AtomType* atomType){
84 >  
85 >  void SHAPES::addShape(ShapeAtomType* atomType){
86      // add it to the map:
87      AtomTypeProperties atp = atomType->getATP();    
88  
89 <    pair<map<int,AtomType*>::iterator,bool> ret;    
90 <    ret = ShapesMap.insert( pair<int, AtomType*>(atp.ident, atomType) );
91 <    if (ret.second == false) {
92 <      sprintf( painCave.errMsg,
93 <               "SHAPES already had a previous entry with ident %d\n",
94 <               atp.ident);
95 <      painCave.severity = OPENMD_INFO;
96 <      painCave.isFatal = 0;
97 <      simError();        
98 <    }  
99 <    
100 <    if (atomType->isShape()) {
101 <      ShapeAtomType* sAtomType = dynamic_cast<ShapeAtomType*>(atomType);
102 <      if (sAtomType == NULL) {
107 <        sprintf(painCave.errMsg,
108 <                "SHAPES:: Can't cast to ShapeAtomType");
109 <        painCave.severity = OPENMD_ERROR;
110 <        painCave.isFatal = 1;
111 <        simError();
112 <      }
113 <      ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, sAtomType) );
114 <
89 >    if (atomType->isShape() ) {
90 >      pair<map<int,ShapeAtomType*>::iterator, bool> ret;
91 >      ret = ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, atomType));
92 >      if (ret.second == false) {
93 >        sprintf( painCave.errMsg,
94 >                 "SHAPES already had a previous entry with ident %d\n",
95 >                 atp.ident);
96 >        painCave.severity = OPENMD_INFO;
97 >        painCave.isFatal = 0;
98 >        simError();        
99 >      }  
100 >      
101 >      ShapesMap.insert( pair<int, ShapeAtomType*>(atp.ident, static_cast<ShapeAtomType*>(atomType)) );
102 >      
103      } else if (atomType->isLennardJones()) {
104 <      d1 = LJ::Instance()->getSigma(atomType) / sqrt(2.0);
105 <      e1 = LJ::Instance()->getEpsilon(atomType);
104 >      RealType d1 = getLJSigma(atomType) / sqrt(2.0);
105 >      RealType e1 = getLJEpsilon(atomType);
106      } else {
107        sprintf( painCave.errMsg,
108                 "SHAPES::addType was passed an atomType (%s) that does not\n"
109 <               "\tappear to be a Gay-Berne or Lennard-Jones atom.\n",
109 >               "\tappear to be a SHAPES or Lennard-Jones atom.\n",
110                 atomType->getName().c_str());
111        painCave.severity = OPENMD_ERROR;
112        painCave.isFatal = 1;
113        simError();
114 <    }
115 <      
114 >    }  
115 >  }
116 >  
117  
118 <    // Now, iterate over all known types and add to the mixing map:
118 >  LJParam SHAPES::getLJParam(AtomType* atomType) {
119      
120 <    map<int, AtomType*>::iterator it;
121 <    for( it = ShapesMap.begin(); it != SHAPESMap.end(); ++it) {
122 <      
123 <      AtomType* atype2 = (*it).second;
124 <      
125 <      RealType d2, l2, e2, er2, dw2;
126 <      
127 <      if (atype2->isGayBerne()) {
128 <        GayBerneParam gb2 = getGayBerneParam(atype2);
129 <        d2 = gb2.SHAPES_d;
130 <        l2 = gb2.SHAPES_l;
131 <        e2 = gb2.SHAPES_eps;
132 <        er2 = gb2.SHAPES_eps_ratio;
133 <        dw2 = gb2.SHAPES_dw;
134 <      } else if (atype2->isLennardJones()) {
135 <        d2 = LJ::Instance()->getSigma(atype2) / sqrt(2.0);
136 <        e2 = LJ::Instance()->getEpsilon(atype2);
137 <        l2 = d2;
138 <        er2 = 1.0;
139 <        dw2 = 1.0;
140 <      }
141 <                      
142 <      SHAPESInteractionData mixer;        
143 <      
144 <      //  Cleaver paper uses sqrt of squares to get sigma0 for
145 <      //  mixed interactions.
146 <            
147 <      mixer.sigma0 = sqrt(d1*d1 + d2*d2);
148 <      mixer.xa2 = (l1*l1 - d1*d1)/(l1*l1 + d2*d2);
149 <      mixer.xai2 = (l2*l2 - d2*d2)/(l2*l2 + d1*d1);
150 <      mixer.x2 = (l1*l1 - d1*d1) * (l2*l2 - d2*d2) /
151 <        ((l2*l2 + d1*d1) * (l1*l1 + d2*d2));
163 <
164 <      // assumed LB mixing rules for now:
165 <
166 <      mixer.dw = 0.5 * (dw1 + dw2);
167 <      mixer.eps0 = sqrt(e1 * e2);
168 <      
169 <      RealType er = sqrt(er1 * er2);
170 <      RealType ermu = pow(er,(1.0 / mu_));
171 <      RealType xp = (1.0 - ermu) / (1.0 + ermu);
172 <      RealType ap2 = 1.0 / (1.0 + ermu);
173 <      
174 <      mixer.xp2 = xp * xp;
175 <      mixer.xpap2 = xp * ap2;
176 <      mixer.xpapi2 = xp / ap2;
177 <
178 <      // only add this pairing if at least one of the atoms is a Gay-Berne atom
179 <
180 <      if (atomType->isGayBerne() || atype2->isGayBerne()) {
181 <
182 <        pair<AtomType*, AtomType*> key1, key2;
183 <        key1 = make_pair(atomType, atype2);
184 <        key2 = make_pair(atype2, atomType);
185 <        
186 <        MixingMap[key1] = mixer;
187 <        if (key2 != key1) {
188 <          MixingMap[key2] = mixer;
189 <        }
190 <      }
191 <    }      
120 >    // Do sanity checking on the AtomType we were passed before
121 >    // building any data structures:
122 >    if (!atomType->isLennardJones()) {
123 >      sprintf( painCave.errMsg,
124 >               "SHAPES::getLJParam was passed an atomType (%s) that does not\n"
125 >               "\tappear to be a Lennard-Jones atom.\n",
126 >               atomType->getName().c_str());
127 >      painCave.severity = OPENMD_ERROR;
128 >      painCave.isFatal = 1;
129 >      simError();
130 >    }
131 >    
132 >    GenericData* data = atomType->getPropertyByName("LennardJones");
133 >    if (data == NULL) {
134 >      sprintf( painCave.errMsg, "SHAPES::getLJParam could not find Lennard-Jones\n"
135 >               "\tparameters for atomType %s.\n", atomType->getName().c_str());
136 >      painCave.severity = OPENMD_ERROR;
137 >      painCave.isFatal = 1;
138 >      simError();
139 >    }
140 >    
141 >    LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
142 >    if (ljData == NULL) {
143 >      sprintf( painCave.errMsg,
144 >               "SHAPES::getLJParam could not convert GenericData to LJParam for\n"
145 >               "\tatom type %s\n", atomType->getName().c_str());
146 >      painCave.severity = OPENMD_ERROR;
147 >      painCave.isFatal = 1;
148 >      simError();          
149 >    }
150 >    
151 >    return ljData->getData();
152    }
153    
154 +  RealType SHAPES::getLJEpsilon(AtomType* atomType) {    
155 +    LJParam ljParam = getLJParam(atomType);
156 +    return ljParam.epsilon;
157 +  }
158 +  RealType SHAPES::getLJSigma(AtomType* atomType) {    
159 +    LJParam ljParam = getLJParam(atomType);
160 +    return ljParam.sigma;
161 +  }
162  
163    RealType SHAPES::getGayBerneCut(int atid) {
164      if (!initialized_) initialize();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines