45#include "nonbonded/GB.hpp"
51#include "types/GayBerneAdapter.hpp"
52#include "types/LennardJonesAdapter.hpp"
53#include "utils/simError.h"
94 initialized_(false), name_(
"GB"), forceField_(NULL), mu_(2.0), nu_(1.0) {}
96 void GB::initialize() {
102 GBtids.resize(forceField_->getNAtomType(), -1);
104 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
105 mu_ = fopts.getGayBerneMu();
106 nu_ = fopts.getGayBerneNu();
110 AtomTypeSet::iterator at;
111 for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
112 if ((*at)->isGayBerne()) nGB_++;
113 if ((*at)->isLennardJones()) nGB_++;
116 MixingMap.resize(nGB_);
117 for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
118 if ((*at)->isGayBerne() || (*at)->isLennardJones()) addType(*at);
124 void GB::addType(AtomType* atomType) {
126 int atid = atomType->getIdent();
127 int gbtid = GBtypes.size();
129 pair<set<int>::iterator,
bool> ret;
130 ret = GBtypes.insert(atid);
131 if (ret.second ==
false) {
132 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
133 "GB already had a previous entry with ident %d\n", atid);
134 painCave.severity = OPENMD_INFO;
135 painCave.isFatal = 0;
139 GBtids[atid] = gbtid;
140 MixingMap[gbtid].resize(nGB_);
142 RealType d1(0.0), l1(0.0), eX1(0.0), eS1(0.0), eE1(0.0), dw1(0.0);
144 LennardJonesAdapter lja1 = LennardJonesAdapter(atomType);
145 GayBerneAdapter gba1 = GayBerneAdapter(atomType);
146 if (gba1.isGayBerne()) {
149 eX1 = gba1.getEpsX();
150 eS1 = gba1.getEpsS();
151 eE1 = gba1.getEpsE();
153 }
else if (lja1.isLennardJones()) {
154 d1 = lja1.getSigma() / sqrt(2.0);
156 eX1 = lja1.getEpsilon();
161 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
162 "GB::addType was passed an atomType (%s) that does not\n"
163 "\tappear to be a Gay-Berne or Lennard-Jones atom.\n",
164 atomType->getName().c_str());
165 painCave.severity = OPENMD_ERROR;
166 painCave.isFatal = 1;
172 std::set<int>::iterator it;
173 for (it = GBtypes.begin(); it != GBtypes.end(); ++it) {
174 int gbtid2 = GBtids[(*it)];
175 AtomType* atype2 = forceField_->getAtomType((*it));
177 LennardJonesAdapter lja2 = LennardJonesAdapter(atype2);
178 GayBerneAdapter gba2 = GayBerneAdapter(atype2);
179 RealType d2(0.0), l2(0.0), eX2(0.0), eS2(0.0), eE2(0.0), dw2(0.0);
181 if (gba2.isGayBerne()) {
184 eX2 = gba2.getEpsX();
185 eS2 = gba2.getEpsS();
186 eE2 = gba2.getEpsE();
188 }
else if (lja2.isLennardJones()) {
189 d2 = lja2.getSigma() / sqrt(2.0);
191 eX2 = lja2.getEpsilon();
196 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
197 "GB::addType found an atomType (%s) that does not\n"
198 "\tappear to be a Gay-Berne or Lennard-Jones atom.\n",
199 atype2->getName().c_str());
200 painCave.severity = OPENMD_ERROR;
201 painCave.isFatal = 1;
205 GBInteractionData mixer1, mixer2;
209 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
210 string DistanceMix = fopts.getDistanceMixingRule();
211 toUpper(DistanceMix);
213 if (DistanceMix ==
"ARITHMETIC")
214 mixer1.sigma0 = 0.5 * (d1 + d2);
216 mixer1.sigma0 = sqrt(d1 * d1 + d2 * d2);
218 mixer1.xa2 = (l1 * l1 - d1 * d1) / (l1 * l1 + d2 * d2);
219 mixer1.xai2 = (l2 * l2 - d2 * d2) / (l2 * l2 + d1 * d1);
220 mixer1.x2 = (l1 * l1 - d1 * d1) * (l2 * l2 - d2 * d2) /
221 ((l2 * l2 + d1 * d1) * (l1 * l1 + d2 * d2));
223 mixer2.sigma0 = mixer1.sigma0;
226 mixer2.xa2 = mixer1.xai2;
227 mixer2.xai2 = mixer1.xa2;
228 mixer2.x2 = mixer1.x2;
232 mixer1.dw = 0.5 * (dw1 + dw2);
233 mixer1.eps0 = sqrt(eX1 * eX2);
235 mixer2.dw = mixer1.dw;
236 mixer2.eps0 = mixer1.eps0;
238 RealType mi = RealType(1.0) / mu_;
241 (pow(eS1, mi) - pow(eE1, mi)) / (pow(eS1, mi) + pow(eE2, mi));
243 (pow(eS2, mi) - pow(eE2, mi)) / (pow(eS2, mi) + pow(eE1, mi));
245 (pow(eS1, mi) - pow(eE1, mi)) * (pow(eS2, mi) - pow(eE2, mi)) /
246 (pow(eS2, mi) + pow(eE1, mi)) / (pow(eS1, mi) + pow(eE2, mi));
250 mixer2.xpap2 = mixer1.xpapi2;
251 mixer2.xpapi2 = mixer1.xpap2;
252 mixer2.xp2 = mixer1.xp2;
254 mixer1.i_is_LJ = atomType->isLennardJones();
255 mixer1.j_is_LJ = atype2->isLennardJones();
256 mixer2.i_is_LJ = mixer1.j_is_LJ;
257 mixer2.j_is_LJ = mixer1.i_is_LJ;
261 if (gba1.isGayBerne() || gba2.isGayBerne()) {
262 MixingMap[gbtid2].resize(nGB_);
263 MixingMap[gbtid][gbtid2] = mixer1;
264 if (gbtid2 != gbtid) { MixingMap[gbtid2][gbtid] = mixer2; }
269 void GB::calcForce(InteractionData& idat) {
270 if (!initialized_) initialize();
272 GBInteractionData& mixer =
273 MixingMap[GBtids[idat.atid1]][GBtids[idat.atid2]];
275 RealType sigma0 = mixer.sigma0;
276 RealType dw = mixer.dw;
277 RealType eps0 = mixer.eps0;
278 RealType x2 = mixer.x2;
279 RealType xa2 = mixer.xa2;
280 RealType xai2 = mixer.xai2;
281 RealType xp2 = mixer.xp2;
282 RealType xpap2 = mixer.xpap2;
283 RealType xpapi2 = mixer.xpapi2;
285 Vector3d ul1 = idat.A1.getRow(2);
286 Vector3d ul2 = idat.A2.getRow(2);
294 a =
dot(idat.d, ul1);
301 b =
dot(idat.d, ul2);
304 if (mixer.i_is_LJ || mixer.j_is_LJ)
309 RealType au = a / idat.rij;
310 RealType bu = b / idat.rij;
312 RealType au2 = au * au;
313 RealType bu2 = bu * bu;
317 (xa2 * au2 + xai2 * bu2 - 2.0 * x2 * au * bu * g) / (1.0 - x2 * g2);
318 RealType Hp = (xpap2 * au2 + xpapi2 * bu2 - 2.0 * xp2 * au * bu * g) /
321 RealType sigma = sigma0 / sqrt(1.0 - H);
322 RealType e1 = 1.0 / sqrt(1.0 - x2 * g2);
323 RealType e2 = 1.0 - Hp;
324 RealType eps = eps0 * pow(e1, nu_) * pow(e2, mu_);
325 RealType BigR = dw * sigma0 / (idat.rij - sigma + dw * sigma0);
327 RealType R3 = BigR * BigR * BigR;
328 RealType R6 = R3 * R3;
329 RealType R7 = R6 * BigR;
330 RealType R12 = R6 * R6;
331 RealType R13 = R6 * R7;
333 RealType U = idat.vdwMult * 4.0 * eps * (R12 - R6);
335 RealType s3 = sigma * sigma * sigma;
336 RealType s03 = sigma0 * sigma0 * sigma0;
339 -idat.vdwMult * 8.0 * eps * mu_ * (R12 - R6) / (e2 * idat.rij);
341 RealType pref2 = idat.vdwMult * 8.0 * eps * s3 * (6.0 * R13 - 3.0 * R7) /
342 (dw * idat.rij * s03);
345 -(pref1 * Hp + pref2 * (sigma0 * sigma0 * idat.rij / s3 + H));
347 RealType dUda = pref1 * (xpap2 * au - xp2 * bu * g) / (1.0 - xp2 * g2) +
348 pref2 * (xa2 * au - x2 * bu * g) / (1.0 - x2 * g2);
350 RealType dUdb = pref1 * (xpapi2 * bu - xp2 * au * g) / (1.0 - xp2 * g2) +
351 pref2 * (xai2 * bu - x2 * au * g) / (1.0 - x2 * g2);
353 RealType dUdg = 4.0 * eps * nu_ * (R12 - R6) * x2 * g / (1.0 - x2 * g2) +
354 8.0 * eps * mu_ * (R12 - R6) *
355 (xp2 * au * bu - Hp * xp2 * g) / (1.0 - xp2 * g2) / e2 +
356 8.0 * eps * s3 * (3.0 * R7 - 6.0 * R13) *
357 (x2 * au * bu - H * x2 * g) / (1.0 - x2 * g2) /
360 Vector3d rhat = idat.d / idat.rij;
361 Vector3d rxu1 =
cross(idat.d, ul1);
362 Vector3d rxu2 =
cross(idat.d, ul2);
363 Vector3d uxu =
cross(ul1, ul2);
368 idat.f1 += (dUdr * rhat + dUda * ul1 + dUdb * ul2) * idat.sw;
369 idat.t1 += (dUda * rxu1 - dUdg * uxu) * idat.sw;
370 idat.t2 += (dUdb * rxu2 + dUdg * uxu) * idat.sw;
375 RealType GB::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
376 if (!initialized_) initialize();
380 LennardJonesAdapter lja1 = LennardJonesAdapter(atypes.first);
381 GayBerneAdapter gba1 = GayBerneAdapter(atypes.first);
382 LennardJonesAdapter lja2 = LennardJonesAdapter(atypes.second);
383 GayBerneAdapter gba2 = GayBerneAdapter(atypes.second);
385 if (gba1.isGayBerne()) {
386 RealType d1 = gba1.getD();
387 RealType l1 = gba1.getL();
389 cut = max(cut, RealType(2.5) * sqrt(RealType(2.0)) * max(d1, l1));
390 }
else if (lja1.isLennardJones()) {
391 cut = max(cut, RealType(2.5) * lja1.getSigma());
394 if (gba2.isGayBerne()) {
395 RealType d2 = gba2.getD();
396 RealType l2 = gba2.getL();
397 cut = max(cut, RealType(2.5) * sqrt(RealType(2.0)) * max(d2, l2));
398 }
else if (lja2.isLennardJones()) {
399 cut = max(cut, RealType(2.5) * lja2.getSigma());
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Vector3< Real > cross(const Vector3< Real > &v1, const Vector3< Real > &v2)
Returns the cross product of two Vectors.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.
@ VANDERWAALS_FAMILY
Long-range dispersion and short-range pauli repulsion.