OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
GB.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45#include "nonbonded/GB.hpp"
46
47#include <cmath>
48#include <cstdio>
49#include <cstring>
50
51#include "types/GayBerneAdapter.hpp"
52#include "types/LennardJonesAdapter.hpp"
53#include "utils/simError.h"
54
55using namespace std;
56namespace OpenMD {
57
58 /* GB is the Gay-Berne interaction for ellipsoidal particles. The original
59 * paper (for identical uniaxial particles) is:
60 * J. G. Gay and B. J. Berne, J. Chem. Phys., 74, 3316-3319 (1981).
61 * A more-general GB potential for dissimilar uniaxial particles:
62 * D. J. Cleaver, C. M. Care, M. P. Allen and M. P. Neal, Phys. Rev. E,
63 * 54, 559-567 (1996).
64 * Further parameterizations can be found in:
65 * A. P. J. Emerson, G. R. Luckhurst and S. G. Whatling, Mol. Phys.,
66 * 82, 113-124 (1994).
67 * And a nice force expression:
68 * G. R. Luckhurst and R. A. Stephens, Liq. Cryst. 8, 451-464 (1990).
69 * Even clearer force and torque expressions:
70 * P. A. Golubkov and P. Y. Ren, J. Chem. Phys., 125, 64103 (2006).
71 * New expressions for cross interactions of strength parameters:
72 * J. Wu, X. Zhen, H. Shen, G. Li, and P. Ren, J. Chem. Phys.,
73 * 135, 155104 (2011).
74 *
75 * In this version of the GB interaction, each uniaxial ellipsoidal type
76 * is described using a set of 6 parameters:
77 * d: range parameter for side-by-side (S) and cross (X) configurations
78 * l: range parameter for end-to-end (E) configuration
79 * epsilon_X: well-depth parameter for cross (X) configuration
80 * epsilon_S: well-depth parameter for side-by-side (S) configuration
81 * epsilon_E: well depth parameter for end-to-end (E) configuration
82 * dw: "softness" of the potential
83 *
84 * Additionally, there are two "universal" paramters to govern the overall
85 * importance of the purely orientational (nu) and the mixed
86 * orientational / translational (mu) parts of strength of the interactions.
87 * These parameters have default or "canonical" values, but may be changed
88 * as a force field option:
89 * nu_: purely orientational part : defaults to 1
90 * mu_: mixed orientational / translational part : defaults to 2
91 */
92
93 GB::GB() :
94 initialized_(false), name_("GB"), forceField_(NULL), mu_(2.0), nu_(1.0) {}
95
96 void GB::initialize() {
97 GBtypes.clear();
98 GBtids.clear();
99 MixingMap.clear();
100 nGB_ = 0;
101
102 GBtids.resize(forceField_->getNAtomType(), -1);
103
104 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
105 mu_ = fopts.getGayBerneMu();
106 nu_ = fopts.getGayBerneNu();
107
108 // GB handles all of the GB-GB interactions as well as GB-LJ cross
109 // interactions:
110 AtomTypeSet::iterator at;
111 for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
112 if ((*at)->isGayBerne()) nGB_++;
113 if ((*at)->isLennardJones()) nGB_++;
114 }
115
116 MixingMap.resize(nGB_);
117 for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
118 if ((*at)->isGayBerne() || (*at)->isLennardJones()) addType(*at);
119 }
120
121 initialized_ = true;
122 }
123
124 void GB::addType(AtomType* 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 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;
136 simError();
137 }
138
139 GBtids[atid] = gbtid;
140 MixingMap[gbtid].resize(nGB_);
141
142 RealType d1(0.0), l1(0.0), eX1(0.0), eS1(0.0), eE1(0.0), dw1(0.0);
143
144 LennardJonesAdapter lja1 = LennardJonesAdapter(atomType);
145 GayBerneAdapter gba1 = GayBerneAdapter(atomType);
146 if (gba1.isGayBerne()) {
147 d1 = gba1.getD();
148 l1 = gba1.getL();
149 eX1 = gba1.getEpsX();
150 eS1 = gba1.getEpsS();
151 eE1 = gba1.getEpsE();
152 dw1 = gba1.getDw();
153 } else if (lja1.isLennardJones()) {
154 d1 = lja1.getSigma() / sqrt(2.0);
155 l1 = d1;
156 eX1 = lja1.getEpsilon();
157 eS1 = eX1;
158 eE1 = eX1;
159 dw1 = 1.0;
160 } else {
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;
167 simError();
168 }
169
170 // Now, iterate over all known types and add to the mixing map:
171
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));
176
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);
180
181 if (gba2.isGayBerne()) {
182 d2 = gba2.getD();
183 l2 = gba2.getL();
184 eX2 = gba2.getEpsX();
185 eS2 = gba2.getEpsS();
186 eE2 = gba2.getEpsE();
187 dw2 = gba2.getDw();
188 } else if (lja2.isLennardJones()) {
189 d2 = lja2.getSigma() / sqrt(2.0);
190 l2 = d2;
191 eX2 = lja2.getEpsilon();
192 eS2 = eX2;
193 eE2 = eX2;
194 dw2 = 1.0;
195 } else {
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;
202 simError();
203 }
204
205 GBInteractionData mixer1, mixer2;
206
207 // Cleaver paper uses sqrt of squares to get sigma0 for
208 // mixed interactions.
209 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
210 string DistanceMix = fopts.getDistanceMixingRule();
211 toUpper(DistanceMix);
212
213 if (DistanceMix == "ARITHMETIC")
214 mixer1.sigma0 = 0.5 * (d1 + d2);
215 else
216 mixer1.sigma0 = sqrt(d1 * d1 + d2 * d2);
217
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));
222
223 mixer2.sigma0 = mixer1.sigma0;
224 // xa2 and xai2 for j-i pairs are reversed from the same i-j pairing.
225 // Swapping the particles reverses the anisotropy parameters:
226 mixer2.xa2 = mixer1.xai2;
227 mixer2.xai2 = mixer1.xa2;
228 mixer2.x2 = mixer1.x2;
229
230 // assumed LB mixing rules for now:
231
232 mixer1.dw = 0.5 * (dw1 + dw2);
233 mixer1.eps0 = sqrt(eX1 * eX2);
234
235 mixer2.dw = mixer1.dw;
236 mixer2.eps0 = mixer1.eps0;
237
238 RealType mi = RealType(1.0) / mu_;
239
240 mixer1.xpap2 =
241 (pow(eS1, mi) - pow(eE1, mi)) / (pow(eS1, mi) + pow(eE2, mi));
242 mixer1.xpapi2 =
243 (pow(eS2, mi) - pow(eE2, mi)) / (pow(eS2, mi) + pow(eE1, mi));
244 mixer1.xp2 =
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));
247
248 // xpap2 and xpapi2 for j-i pairs are reversed from the same i-j pairing.
249 // Swapping the particles reverses the anisotropy parameters:
250 mixer2.xpap2 = mixer1.xpapi2;
251 mixer2.xpapi2 = mixer1.xpap2;
252 mixer2.xp2 = mixer1.xp2;
253 // keep track of who is the LJ atom:
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;
258
259 // only add this pairing if at least one of the atoms is a Gay-Berne atom
260
261 if (gba1.isGayBerne() || gba2.isGayBerne()) {
262 MixingMap[gbtid2].resize(nGB_);
263 MixingMap[gbtid][gbtid2] = mixer1;
264 if (gbtid2 != gbtid) { MixingMap[gbtid2][gbtid] = mixer2; }
265 }
266 }
267 }
268
269 void GB::calcForce(InteractionData& idat) {
270 if (!initialized_) initialize();
271
272 GBInteractionData& mixer =
273 MixingMap[GBtids[idat.atid1]][GBtids[idat.atid2]];
274
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;
284
285 Vector3d ul1 = idat.A1.getRow(2);
286 Vector3d ul2 = idat.A2.getRow(2);
287
288 RealType a, b, g;
289
290 if (mixer.i_is_LJ) {
291 a = 0.0;
292 ul1 = V3Zero;
293 } else {
294 a = dot(idat.d, ul1);
295 }
296
297 if (mixer.j_is_LJ) {
298 b = 0.0;
299 ul2 = V3Zero;
300 } else {
301 b = dot(idat.d, ul2);
302 }
303
304 if (mixer.i_is_LJ || mixer.j_is_LJ)
305 g = 0.0;
306 else
307 g = dot(ul1, ul2);
308
309 RealType au = a / idat.rij;
310 RealType bu = b / idat.rij;
311
312 RealType au2 = au * au;
313 RealType bu2 = bu * bu;
314 RealType g2 = g * g;
315
316 RealType H =
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) /
319 (1.0 - xp2 * g2);
320
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);
326
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;
332
333 RealType U = idat.vdwMult * 4.0 * eps * (R12 - R6);
334
335 RealType s3 = sigma * sigma * sigma;
336 RealType s03 = sigma0 * sigma0 * sigma0;
337
338 RealType pref1 =
339 -idat.vdwMult * 8.0 * eps * mu_ * (R12 - R6) / (e2 * idat.rij);
340
341 RealType pref2 = idat.vdwMult * 8.0 * eps * s3 * (6.0 * R13 - 3.0 * R7) /
342 (dw * idat.rij * s03);
343
344 RealType dUdr =
345 -(pref1 * Hp + pref2 * (sigma0 * sigma0 * idat.rij / s3 + H));
346
347 RealType dUda = pref1 * (xpap2 * au - xp2 * bu * g) / (1.0 - xp2 * g2) +
348 pref2 * (xa2 * au - x2 * bu * g) / (1.0 - x2 * g2);
349
350 RealType dUdb = pref1 * (xpapi2 * bu - xp2 * au * g) / (1.0 - xp2 * g2) +
351 pref2 * (xai2 * bu - x2 * au * g) / (1.0 - x2 * g2);
352
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) /
358 (dw * s03);
359
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);
364
365 idat.pot[VANDERWAALS_FAMILY] += U * idat.sw;
366 if (idat.isSelected) idat.selePot[VANDERWAALS_FAMILY] += U * idat.sw;
367
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;
371 idat.vpair += U;
372 return;
373 }
374
375 RealType GB::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
376 if (!initialized_) initialize();
377
378 RealType cut = 0.0;
379
380 LennardJonesAdapter lja1 = LennardJonesAdapter(atypes.first);
381 GayBerneAdapter gba1 = GayBerneAdapter(atypes.first);
382 LennardJonesAdapter lja2 = LennardJonesAdapter(atypes.second);
383 GayBerneAdapter gba2 = GayBerneAdapter(atypes.second);
384
385 if (gba1.isGayBerne()) {
386 RealType d1 = gba1.getD();
387 RealType l1 = gba1.getL();
388 // sigma is actually sqrt(2)*l for prolate ellipsoids
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());
392 }
393
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());
400 }
401
402 return cut;
403 }
404} // namespace OpenMD
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.
Definition Vector3.hpp:136
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.