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

Comparing:
branches/development/src/nonbonded/GB.cpp (file contents), Revision 1483 by gezelter, Tue Jul 27 21:17:31 2010 UTC vs.
trunk/src/nonbonded/GB.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 44 | Line 45
45  
46   #include <cmath>
47   #include "nonbonded/GB.hpp"
47 #include "nonbonded/LJ.hpp"
48   #include "utils/simError.h"
49 + #include "types/LennardJonesAdapter.hpp"
50 + #include "types/GayBerneAdapter.hpp"
51  
52   using namespace std;
53   namespace OpenMD {
54  
55 <  bool GB::initialized_ = false;
56 <  RealType GB::mu_ = 2.0;
57 <  RealType GB::nu_ = 1.0;
58 <  ForceField* GB::forceField_ = NULL;
59 <  map<int, AtomType*> GB::GBMap;
60 <  map<pair<AtomType*, AtomType*>, GBInteractionData> GB::MixingMap;
61 <  
62 <  GB* GB::_instance = NULL;
55 >  /* GB is the Gay-Berne interaction for ellipsoidal particles.  The original
56 >   * paper (for identical uniaxial particles) is:
57 >   *    J. G. Gay and B. J. Berne, J. Chem. Phys., 74, 3316-3319 (1981).
58 >   * A more-general GB potential for dissimilar uniaxial particles:
59 >   *    D. J. Cleaver, C. M. Care, M. P. Allen and M. P. Neal, Phys. Rev. E,
60 >   *    54, 559-567 (1996).
61 >   * Further parameterizations can be found in:
62 >   *    A. P. J. Emerson, G. R. Luckhurst and S. G. Whatling, Mol. Phys.,
63 >   *    82, 113-124 (1994).
64 >   * And a nice force expression:
65 >   *    G. R. Luckhurst and R. A. Stephens, Liq. Cryst. 8, 451-464 (1990).
66 >   * Even clearer force and torque expressions:
67 >   *    P. A. Golubkov and P. Y. Ren, J. Chem. Phys., 125, 64103 (2006).
68 >   * New expressions for cross interactions of strength parameters:
69 >   *    J. Wu, X. Zhen, H. Shen, G. Li, and P. Ren, J. Chem. Phys.,
70 >   *    135, 155104 (2011).
71 >   *
72 >   * In this version of the GB interaction, each uniaxial ellipsoidal type
73 >   * is described using a set of 6 parameters:
74 >   *  d:  range parameter for side-by-side (S) and cross (X) configurations
75 >   *  l:  range parameter for end-to-end (E) configuration
76 >   *  epsilon_X:  well-depth parameter for cross (X) configuration
77 >   *  epsilon_S:  well-depth parameter for side-by-side (S) configuration
78 >   *  epsilon_E:  well depth parameter for end-to-end (E) configuration
79 >   *  dw: "softness" of the potential
80 >   *
81 >   * Additionally, there are two "universal" paramters to govern the overall
82 >   * importance of the purely orientational (nu) and the mixed
83 >   * orientational / translational (mu) parts of strength of the interactions.
84 >   * These parameters have default or "canonical" values, but may be changed
85 >   * as a force field option:
86 >   * nu_: purely orientational part : defaults to 1
87 >   * mu_: mixed orientational / translational part : defaults to 2
88 >   */
89  
62  GB* GB::Instance() {
63    if (!_instance) {
64      _instance = new GB();
65    }
66    return _instance;
67  }
90  
91 <  GayBerneParam GB::getGayBerneParam(AtomType* atomType) {
91 >  GB::GB() : initialized_(false), name_("GB"), forceField_(NULL),
92 >             mu_(2.0), nu_(1.0) {}
93      
94 <    // Do sanity checking on the AtomType we were passed before
72 <    // building any data structures:
73 <    if (!atomType->isGayBerne()) {
74 <      sprintf( painCave.errMsg,
75 <               "GB::getGayBerneParam was passed an atomType (%s) that does\n"
76 <               "\tnot appear to be a Gay-Berne atom.\n",
77 <               atomType->getName().c_str());
78 <      painCave.severity = OPENMD_ERROR;
79 <      painCave.isFatal = 1;
80 <      simError();
81 <    }
94 >  void GB::initialize() {    
95      
96 <    DirectionalAtomType* daType = dynamic_cast<DirectionalAtomType*>(atomType);
97 <    GenericData* data = daType->getPropertyByName("GayBerne");
98 <    if (data == NULL) {
99 <      sprintf( painCave.errMsg, "GB::getGayBerneParam could not find\n"
87 <               "\tGay-Berne parameters for atomType %s.\n",
88 <               daType->getName().c_str());
89 <      painCave.severity = OPENMD_ERROR;
90 <      painCave.isFatal = 1;
91 <      simError();
92 <    }
93 <    
94 <    GayBerneParamGenericData* gbData = dynamic_cast<GayBerneParamGenericData*>(data);
95 <    if (gbData == NULL) {
96 <      sprintf( painCave.errMsg,
97 <               "GB::getGayBerneParam could not convert GenericData to\n"
98 <               "\tGayBerneParamGenericData for atom type %s\n",
99 <               daType->getName().c_str());
100 <      painCave.severity = OPENMD_ERROR;
101 <      painCave.isFatal = 1;
102 <      simError();          
103 <    }
104 <    
105 <    return gbData->getData();
106 <  }
96 >    GBtypes.clear();
97 >    GBtids.clear();
98 >    MixingMap.clear();
99 >    nGB_ = 0;
100  
101 <  void GB::initialize() {    
109 <    ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
110 <    ForceField::AtomTypeContainer::MapTypeIterator i;
111 <    AtomType* at;
101 >    GBtids.resize( forceField_->getNAtomType(), -1);
102  
103 +    ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
104 +    mu_ = fopts.getGayBerneMu();
105 +    nu_ = fopts.getGayBerneNu();
106 +
107      // GB handles all of the GB-GB interactions as well as GB-LJ cross
108      // interactions:
109 +    set<AtomType*>::iterator at;
110 +    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
111 +      if ((*at)->isGayBerne()) nGB_++;
112 +      if ((*at)->isLennardJones()) nGB_++;
113 +    }
114  
115 <    for (at = atomTypes->beginType(i); at != NULL;
116 <         at = atomTypes->nextType(i)) {
117 <      
119 <      if (at->isGayBerne() || at->isLennardJones())
120 <        addType(at);
115 >    MixingMap.resize(nGB_);
116 >    for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
117 >      if ((*at)->isGayBerne() || (*at)->isLennardJones()) addType( *at );
118      }
119 <  
119 >    
120      initialized_ = true;
121    }
122        
123    void GB::addType(AtomType* atomType){
127    // add it to the map:
128    AtomTypeProperties atp = atomType->getATP();    
124  
125 <    pair<map<int,AtomType*>::iterator,bool> ret;    
126 <    ret = GBMap.insert( pair<int, AtomType*>(atp.ident, atomType) );
125 >    // add it to the map:
126 >    int atid = atomType->getIdent();
127 >    int gbtid = GBtypes.size();
128 >  
129 >    pair<set<int>::iterator,bool> ret;    
130 >    ret = GBtypes.insert( atid );
131      if (ret.second == false) {
132        sprintf( painCave.errMsg,
133                 "GB already had a previous entry with ident %d\n",
134 <               atp.ident);
134 >               atid) ;
135        painCave.severity = OPENMD_INFO;
136        painCave.isFatal = 0;
137        simError();        
138      }
139 +
140 +    GBtids[atid] = gbtid;
141 +    MixingMap[gbtid].resize( nGB_ );
142      
143 <    RealType d1, l1, e1, er1, dw1;
143 >    RealType d1(0.0), l1(0.0), eX1(0.0), eS1(0.0), eE1(0.0), dw1(0.0);
144      
145 <    if (atomType->isGayBerne()) {
146 <      GayBerneParam gb1 = getGayBerneParam(atomType);
147 <      d1 = gb1.GB_d;
148 <      l1 = gb1.GB_l;
149 <      e1 = gb1.GB_eps;
150 <      er1 = gb1.GB_eps_ratio;
151 <      dw1 = gb1.GB_dw;
152 <    } else if (atomType->isLennardJones()) {
153 <      d1 = LJ::Instance()->getSigma(atomType) / sqrt(2.0);
154 <      e1 = LJ::Instance()->getEpsilon(atomType);
145 >    LennardJonesAdapter lja1 = LennardJonesAdapter(atomType);
146 >    GayBerneAdapter gba1 = GayBerneAdapter(atomType);
147 >    if (gba1.isGayBerne()) {
148 >      d1 = gba1.getD();
149 >      l1 = gba1.getL();
150 >      eX1 = gba1.getEpsX();
151 >      eS1 = gba1.getEpsS();
152 >      eE1 = gba1.getEpsE();
153 >      dw1 = gba1.getDw();
154 >    } else if (lja1.isLennardJones()) {
155 >      d1 = lja1.getSigma() / sqrt(2.0);
156        l1 = d1;
157 <      er1 = 1.0;
157 >      eX1 = lja1.getEpsilon();
158 >      eS1 = eX1;
159 >      eE1 = eX1;
160        dw1 = 1.0;      
161      } else {
162        sprintf( painCave.errMsg,
# Line 163 | Line 168 | namespace OpenMD {
168        simError();
169      }
170        
171 <
171 >    
172      // Now, iterate over all known types and add to the mixing map:
173      
174 <    map<int, AtomType*>::iterator it;
175 <    for( it = GBMap.begin(); it != GBMap.end(); ++it) {
174 >    std::set<int>::iterator it;
175 >    for( it = GBtypes.begin(); it != GBtypes.end(); ++it) {
176        
177 <      AtomType* atype2 = (*it).second;
177 >      int gbtid2 = GBtids[ (*it) ];
178 >      AtomType* atype2 = forceField_->getAtomType( (*it) );
179 >
180 >      LennardJonesAdapter lja2 = LennardJonesAdapter(atype2);
181 >      GayBerneAdapter gba2 = GayBerneAdapter(atype2);
182 >      RealType d2(0.0), l2(0.0), eX2(0.0), eS2(0.0), eE2(0.0), dw2(0.0);
183        
184 <      RealType d2, l2, e2, er2, dw2;
185 <      
186 <      if (atype2->isGayBerne()) {
187 <        GayBerneParam gb2 = getGayBerneParam(atype2);
188 <        d2 = gb2.GB_d;
189 <        l2 = gb2.GB_l;
190 <        e2 = gb2.GB_eps;
191 <        er2 = gb2.GB_eps_ratio;
192 <        dw2 = gb2.GB_dw;
183 <      } else if (atype2->isLennardJones()) {
184 <        d2 = LJ::Instance()->getSigma(atype2) / sqrt(2.0);
185 <        e2 = LJ::Instance()->getEpsilon(atype2);
184 >      if (gba2.isGayBerne()) {
185 >        d2 = gba2.getD();
186 >        l2 = gba2.getL();
187 >        eX2 = gba2.getEpsX();
188 >        eS2 = gba2.getEpsS();
189 >        eE2 = gba2.getEpsE();
190 >        dw2 = gba2.getDw();
191 >      } else if (lja2.isLennardJones()) {
192 >        d2 = lja2.getSigma() / sqrt(2.0);
193          l2 = d2;
194 <        er2 = 1.0;
194 >        eX2 = lja2.getEpsilon();
195 >        eS2 = eX2;
196 >        eE2 = eX2;
197          dw2 = 1.0;
198 <      }
199 <                      
200 <      GBInteractionData mixer;        
198 >      } else {
199 >        sprintf( painCave.errMsg,
200 >                 "GB::addType found an atomType (%s) that does not\n"
201 >                 "\tappear to be a Gay-Berne or Lennard-Jones atom.\n",
202 >                 atype2->getName().c_str());
203 >        painCave.severity = OPENMD_ERROR;
204 >        painCave.isFatal = 1;
205 >        simError();
206 >      }
207        
208 +      
209 +      GBInteractionData mixer1, mixer2;    
210 +      
211        //  Cleaver paper uses sqrt of squares to get sigma0 for
212        //  mixed interactions.
213 <            
214 <      mixer.sigma0 = sqrt(d1*d1 + d2*d2);
215 <      mixer.xa2 = (l1*l1 - d1*d1)/(l1*l1 + d2*d2);
216 <      mixer.xai2 = (l2*l2 - d2*d2)/(l2*l2 + d1*d1);
217 <      mixer.x2 = (l1*l1 - d1*d1) * (l2*l2 - d2*d2) /
213 >      
214 >      mixer1.sigma0 = sqrt(d1*d1 + d2*d2);
215 >      mixer1.xa2 = (l1*l1 - d1*d1)/(l1*l1 + d2*d2);
216 >      mixer1.xai2 = (l2*l2 - d2*d2)/(l2*l2 + d1*d1);
217 >      mixer1.x2 = (l1*l1 - d1*d1) * (l2*l2 - d2*d2) /
218          ((l2*l2 + d1*d1) * (l1*l1 + d2*d2));
201
202      // assumed LB mixing rules for now:
203
204      mixer.dw = 0.5 * (dw1 + dw2);
205      mixer.eps0 = sqrt(e1 * e2);
219        
220 <      RealType er = sqrt(er1 * er2);
221 <      RealType ermu = pow(er,(1.0 / mu_));
222 <      RealType xp = (1.0 - ermu) / (1.0 + ermu);
223 <      RealType ap2 = 1.0 / (1.0 + ermu);
220 >      mixer2.sigma0 = mixer1.sigma0;
221 >      // xa2 and xai2 for j-i pairs are reversed from the same i-j pairing.
222 >      // Swapping the particles reverses the anisotropy parameters:
223 >      mixer2.xa2 = mixer1.xai2;
224 >      mixer2.xai2 = mixer1.xa2;
225 >      mixer2.x2 = mixer1.x2;
226        
227 <      mixer.xp2 = xp * xp;
228 <      mixer.xpap2 = xp * ap2;
229 <      mixer.xpapi2 = xp / ap2;
227 >      // assumed LB mixing rules for now:
228 >      
229 >      mixer1.dw = 0.5 * (dw1 + dw2);
230 >      mixer1.eps0 = sqrt(eX1 * eX2);
231  
232 <      // only add this pairing if at least one of the atoms is a Gay-Berne atom
232 >      mixer2.dw = mixer1.dw;
233 >      mixer2.eps0 = mixer1.eps0;
234 >      
235 >      RealType mi = RealType(1.0)/mu_;
236 >      
237 >      mixer1.xpap2  = (pow(eS1, mi) - pow(eE1, mi)) / (pow(eS1, mi) + pow(eE2, mi));
238 >      mixer1.xpapi2 = (pow(eS2, mi) - pow(eE2, mi)) / (pow(eS2, mi) + pow(eE1, mi));
239 >      mixer1.xp2    = (pow(eS1, mi) - pow(eE1, mi)) * (pow(eS2, mi) - pow(eE2, mi))  /
240 >        (pow(eS2, mi) + pow(eE1, mi)) / (pow(eS1, mi) + pow(eE2, mi)) ;
241 >      
242 >      // xpap2 and xpapi2 for j-i pairs are reversed from the same i-j pairing.
243 >      // Swapping the particles reverses the anisotropy parameters:
244 >      mixer2.xpap2 = mixer1.xpapi2;
245 >      mixer2.xpapi2 = mixer1.xpap2;
246 >      mixer2.xp2 = mixer1.xp2;
247 >      // keep track of who is the LJ atom:
248 >      mixer1.i_is_LJ = atomType->isLennardJones();
249 >      mixer1.j_is_LJ = atype2->isLennardJones();
250 >      mixer2.i_is_LJ = mixer1.j_is_LJ;
251 >      mixer2.j_is_LJ = mixer1.i_is_LJ;
252  
218      if (atomType->isGayBerne() || atype2->isGayBerne()) {
253  
254 <        pair<AtomType*, AtomType*> key1, key2;
221 <        key1 = make_pair(atomType, atype2);
222 <        key2 = make_pair(atype2, atomType);
223 <        
224 <        MixingMap[key1] = mixer;
225 <        if (key2 != key1) {
226 <          MixingMap[key2] = mixer;
227 <        }
228 <      }
229 <    }      
230 <  }
231 <  
254 >      // only add this pairing if at least one of the atoms is a Gay-Berne atom
255  
256 <  RealType GB::getGayBerneCut(int atid) {
257 <    if (!initialized_) initialize();
258 <    std::map<int, AtomType*> :: const_iterator it;
259 <    it = GBMap.find(atid);
260 <    if (it == GBMap.end()) {
261 <      sprintf( painCave.errMsg,
262 <               "GB::getGayBerneCut could not find atid %d in GBMap\n",
240 <               (atid));
241 <      painCave.severity = OPENMD_ERROR;
242 <      painCave.isFatal = 1;
243 <      simError();          
256 >      if (gba1.isGayBerne() || gba2.isGayBerne()) {
257 >        MixingMap[gbtid2].resize( nGB_ );        
258 >        MixingMap[gbtid][gbtid2] = mixer1;
259 >        if (gbtid2 != gbtid)  {
260 >          MixingMap[gbtid2][gbtid] = mixer2;
261 >        }          
262 >      }
263      }
245
246    AtomType* atype = it->second;
247
248    RealType gbCut;
249    
250    if (atype->isGayBerne()) {
251      GayBerneParam gb = getGayBerneParam(atype);
252
253      // sigma is actually sqrt(2) * l for prolate ellipsoids
254      gbCut = 2.5 * sqrt(2.0) * max(gb.GB_l, gb.GB_d);
255
256    } else if (atype->isLennardJones()) {
257      gbCut = 2.5 * LJ::Instance()->getSigma(atype);
258    }
259    
260    return gbCut;
264    }
265 +  
266 +  void GB::calcForce(InteractionData &idat) {
267  
263
264  void GB::calcForce(AtomType* at1, AtomType* at2, Vector3d d,
265                     RealType r, RealType r2, RealType sw,
266                     RealType vdwMult, RealType &vpair, RealType &pot,
267                     RotMat3x3d A1, RotMat3x3d A2, Vector3d &f1,
268                     Vector3d &t1, Vector3d &t2) {
269
268      if (!initialized_) initialize();
269      
270 <    pair<AtomType*, AtomType*> key = make_pair(at1, at2);
273 <    GBInteractionData mixer = MixingMap[key];
270 >    GBInteractionData &mixer = MixingMap[GBtids[idat.atid1]][GBtids[idat.atid2]];
271  
272      RealType sigma0 = mixer.sigma0;
273      RealType dw     = mixer.dw;
# Line 282 | Line 279 | namespace OpenMD {
279      RealType xpap2  = mixer.xpap2;
280      RealType xpapi2 = mixer.xpapi2;
281  
282 <    Vector3d ul1 = A1.getColumn(2);
283 <    Vector3d ul2 = A2.getColumn(2);
282 >    Vector3d ul1 = idat.A1->getRow(2);
283 >    Vector3d ul2 = idat.A2->getRow(2);
284  
285      RealType a, b, g;
286 <
287 <    bool i_is_LJ = at1->isLennardJones();
291 <    bool j_is_LJ = at2->isLennardJones();
292 <
293 <    if (i_is_LJ) {
286 >    
287 >    if (mixer.i_is_LJ) {
288        a = 0.0;
289        ul1 = V3Zero;
290      } else {
291 <      a = dot(d, ul1);
291 >      a = dot(*(idat.d), ul1);
292      }
293  
294 <    if (j_is_LJ) {
294 >    if (mixer.j_is_LJ) {
295        b = 0.0;
296        ul2 = V3Zero;
297      } else {
298 <      b = dot(d, ul2);
298 >      b = dot(*(idat.d), ul2);
299      }
300  
301 <    if (i_is_LJ || j_is_LJ)
301 >    if (mixer.i_is_LJ || mixer.j_is_LJ)
302        g = 0.0;
303      else
304        g = dot(ul1, ul2);
305  
306 <    RealType au = a / r;
307 <    RealType bu = b / r;
306 >    RealType au = a / *(idat.rij);
307 >    RealType bu = b / *(idat.rij);
308      
309      RealType au2 = au * au;
310      RealType bu2 = bu * bu;
311      RealType g2 = g * g;
312 <    
312 >
313      RealType H  = (xa2 * au2 + xai2 * bu2 - 2.0*x2*au*bu*g)  / (1.0 - x2*g2);
314      RealType Hp = (xpap2*au2 + xpapi2*bu2 - 2.0*xp2*au*bu*g) / (1.0 - xp2*g2);
315  
# Line 323 | Line 317 | namespace OpenMD {
317      RealType e1 = 1.0 / sqrt(1.0 - x2*g2);
318      RealType e2 = 1.0 - Hp;
319      RealType eps = eps0 * pow(e1,nu_) * pow(e2,mu_);
320 <    RealType BigR = dw*sigma0 / (r - sigma + dw*sigma0);
320 >    RealType BigR = dw*sigma0 / (*(idat.rij) - sigma + dw*sigma0);
321      
322      RealType R3 = BigR*BigR*BigR;
323      RealType R6 = R3*R3;
# Line 331 | Line 325 | namespace OpenMD {
325      RealType R12 = R6*R6;
326      RealType R13 = R6*R7;
327  
328 <    RealType U = vdwMult * 4.0 * eps * (R12 - R6);
328 >    RealType U = *(idat.vdwMult) * 4.0 * eps * (R12 - R6);
329  
330      RealType s3 = sigma*sigma*sigma;
331      RealType s03 = sigma0*sigma0*sigma0;
332  
333 <    RealType pref1 = - vdwMult * 8.0 * eps * mu_ * (R12 - R6) / (e2 * r);
333 >    RealType pref1 = - *(idat.vdwMult) * 8.0 * eps * mu_ * (R12 - R6) /
334 >      (e2 * *(idat.rij));
335  
336 <    RealType pref2 = vdwMult * 8.0 * eps * s3 * (6.0*R13 - 3.0*R7) /(dw*r*s03);
336 >    RealType pref2 = *(idat.vdwMult) * 8.0 * eps * s3 * (6.0*R13 - 3.0*R7) /
337 >      (dw*  *(idat.rij) * s03);
338  
339 <    RealType dUdr = - (pref1 * Hp + pref2 * (sigma0*sigma0*r/s3 + H));
339 >    RealType dUdr = - (pref1 * Hp + pref2 * (sigma0 * sigma0 *  
340 >                                             *(idat.rij) / s3 + H));
341      
342      RealType dUda = pref1 * (xpap2*au - xp2*bu*g) / (1.0 - xp2 * g2)
343        + pref2 * (xa2 * au - x2 *bu*g) / (1.0 - x2 * g2);
344      
345      RealType dUdb = pref1 * (xpapi2*bu - xp2*au*g) / (1.0 - xp2 * g2)
346        + pref2 * (xai2 * bu - x2 *au*g) / (1.0 - x2 * g2);
347 <
347 >    
348      RealType dUdg = 4.0 * eps * nu_ * (R12 - R6) * x2 * g / (1.0 - x2*g2)
349        + 8.0 * eps * mu_ * (R12 - R6) * (xp2*au*bu - Hp*xp2*g) /
350        (1.0 - xp2 * g2) / e2 + 8.0 * eps * s3 * (3.0 * R7 - 6.0 * R13) *
351        (x2 * au * bu - H * x2 * g) / (1.0 - x2 * g2) / (dw * s03);
352      
353 <
354 <    Vector3d rhat = d / r;  
355 <    Vector3d rxu1 = cross(d, ul1);
359 <    Vector3d rxu2 = cross(d, ul2);
353 >    Vector3d rhat = *(idat.d) / *(idat.rij);  
354 >    Vector3d rxu1 = cross(*(idat.d), ul1);
355 >    Vector3d rxu2 = cross(*(idat.d), ul2);
356      Vector3d uxu = cross(ul1, ul2);
357      
358 <    pot += U*sw;
359 <    f1 += dUdr * rhat + dUda * ul1 + dUdb * ul2;    
360 <    t1 += dUda * rxu1 - dUdg * uxu;
361 <    t2 += dUdb * rxu2 - dUdg * uxu;
362 <    vpair += U*sw;
358 >    (*(idat.pot))[VANDERWAALS_FAMILY] += U *  *(idat.sw);
359 >    *(idat.f1) += (dUdr * rhat + dUda * ul1 + dUdb * ul2) * *(idat.sw);
360 >    *(idat.t1) += (dUda * rxu1 - dUdg * uxu) * *(idat.sw);
361 >    *(idat.t2) += (dUdb * rxu2 + dUdg * uxu) * *(idat.sw);
362 >    *(idat.vpair) += U;
363  
364      return;
365  
366    }
367  
368 <  void GB::do_gb_pair(int *atid1, int *atid2, RealType *d, RealType *r,
369 <                      RealType *r2, RealType *sw, RealType *vdwMult,
374 <                      RealType *vpair, RealType *pot, RealType *A1,
375 <                      RealType *A2, RealType *f1, RealType *t1, RealType *t2) {
376 <    
377 <    if (!initialized_) initialize();
378 <    
379 <    AtomType* atype1 = GBMap[*atid1];
380 <    AtomType* atype2 = GBMap[*atid2];
381 <    
382 <    Vector3d disp(d);
383 <    Vector3d frc(f1);
384 <    Vector3d trq1(t1);
385 <    Vector3d trq2(t2);
386 <    RotMat3x3d Ai(A1);
387 <    RotMat3x3d Aj(A2);
388 <  
389 <    // Fortran has the opposite matrix ordering from c++, so we'll use
390 <    // transpose here.  When we finish the conversion to C++, this wrapper
391 <    // will disappear, as will the transpose below:
368 >  RealType GB::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
369 >    if (!initialized_) initialize();  
370  
371 <    calcForce(atype1, atype2, disp, *r, *r2, *sw, *vdwMult, *vpair, *pot,
394 <              Ai.transpose(), Aj.transpose(), frc, trq1, trq1);
395 <      
396 <    f1[0] = frc.x();
397 <    f1[1] = frc.y();
398 <    f1[2] = frc.z();
371 >    RealType cut = 0.0;
372  
373 <    t1[0] = trq1.x();
374 <    t1[1] = trq1.y();
375 <    t1[2] = trq1.z();
373 >    LennardJonesAdapter lja1 = LennardJonesAdapter(atypes.first);
374 >    GayBerneAdapter gba1 = GayBerneAdapter(atypes.first);
375 >    LennardJonesAdapter lja2 = LennardJonesAdapter(atypes.second);
376 >    GayBerneAdapter gba2 = GayBerneAdapter(atypes.second);
377  
378 <    t2[0] = trq2.x();
379 <    t2[1] = trq2.y();
380 <    t2[2] = trq2.z();
378 >    if (gba1.isGayBerne()) {
379 >      RealType d1 = gba1.getD();
380 >      RealType l1 = gba1.getL();
381 >      // sigma is actually sqrt(2)*l  for prolate ellipsoids
382 >      cut = max(cut, RealType(2.5) * sqrt(RealType(2.0)) * max(d1, l1));
383 >    } else if (lja1.isLennardJones()) {
384 >      cut = max(cut, RealType(2.5) * lja1.getSigma());
385 >    }
386  
387 <    return;    
387 >    if (gba2.isGayBerne()) {
388 >      RealType d2 = gba2.getD();
389 >      RealType l2 = gba2.getL();
390 >      cut = max(cut, RealType(2.5) * sqrt(RealType(2.0)) * max(d2, l2));
391 >    } else if (lja2.isLennardJones()) {
392 >      cut = max(cut, RealType(2.5) * lja2.getSigma());
393 >    }
394 >  
395 >    return cut;
396    }
397   }
398  
412 extern "C" {
413  
414 #define fortranGetGayBerneCut FC_FUNC(getgaybernecut, GETGAYBERNECUT)
415 #define fortranDoGBPair FC_FUNC(do_gb_pair, DO_GB_PAIR)
416  
417  RealType fortranGetGayBerneCut(int* atid) {
418    return OpenMD::GB::Instance()->getGayBerneCut(*atid);
419  }
420
421  void fortranDoGBPair(int *atid1, int *atid2, RealType *d, RealType *r,
422                       RealType *r2, RealType *sw, RealType *vdwMult,
423                       RealType *vpair, RealType *pot, RealType *A1,
424                       RealType *A2, RealType *f1, RealType *t1, RealType *t2){
425    
426    return OpenMD::GB::Instance()->do_gb_pair(atid1, atid2, d, r, r2, sw,
427                                              vdwMult, vpair, pot, A1, A2, f1,
428                                              t1, t2);
429  }
430 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines