OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
MAW.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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48#include "nonbonded/MAW.hpp"
49
50#include <cmath>
51#include <cstdio>
52#include <cstring>
53
54#include "utils/simError.h"
55
56using namespace std;
57
58namespace OpenMD {
59
60 MAW::MAW() : initialized_(false), forceField_(NULL), name_("MAW") {}
61
62 void MAW::initialize() {
63 MAWtypes.clear();
64 MAWtids.clear();
65 MixingMap.clear();
66 MAWtids.resize(forceField_->getNAtomType(), -1);
67
68 ForceField::NonBondedInteractionTypeContainer* nbiTypes =
69 forceField_->getNonBondedInteractionTypes();
70 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
71 ForceField::NonBondedInteractionTypeContainer::KeyType keys;
72 NonBondedInteractionType* nbt;
73 int mtid1, mtid2;
74
75 for (nbt = nbiTypes->beginType(j); nbt != NULL;
76 nbt = nbiTypes->nextType(j)) {
77 if (nbt->isMAW()) {
78 keys = nbiTypes->getKeys(j);
79 AtomType* at1 = forceField_->getAtomType(keys[0]);
80 if (at1 == NULL) {
81 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
82 "MAW::initialize could not find AtomType %s\n"
83 "\tto for for %s - %s interaction.\n",
84 keys[0].c_str(), keys[0].c_str(), keys[1].c_str());
85 painCave.severity = OPENMD_ERROR;
86 painCave.isFatal = 1;
87 simError();
88 }
89
90 AtomType* at2 = forceField_->getAtomType(keys[1]);
91 if (at2 == NULL) {
92 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
93 "MAW::initialize could not find AtomType %s\n"
94 "\tfor %s - %s nonbonded interaction.\n",
95 keys[1].c_str(), keys[0].c_str(), keys[1].c_str());
96 painCave.severity = OPENMD_ERROR;
97 painCave.isFatal = 1;
98 simError();
99 }
100
101 int atid1 = at1->getIdent();
102 if (MAWtids[atid1] == -1) {
103 mtid1 = MAWtypes.size();
104 MAWtypes.insert(atid1);
105 MAWtids[atid1] = mtid1;
106 }
107 int atid2 = at2->getIdent();
108 if (MAWtids[atid2] == -1) {
109 mtid2 = MAWtypes.size();
110 MAWtypes.insert(atid2);
111 MAWtids[atid2] = mtid2;
112 }
113
114 MAWInteractionType* mit = dynamic_cast<MAWInteractionType*>(nbt);
115
116 if (mit == NULL) {
117 snprintf(
118 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
119 "MAW::initialize could not convert NonBondedInteractionType\n"
120 "\tto MAWInteractionType for %s - %s interaction.\n",
121 at1->getName().c_str(), at2->getName().c_str());
122 painCave.severity = OPENMD_ERROR;
123 painCave.isFatal = 1;
124 simError();
125 }
126
127 RealType De = mit->getD();
128 RealType beta = mit->getBeta();
129 RealType Re = mit->getR();
130 RealType ca1 = mit->getCA1();
131 RealType cb1 = mit->getCB1();
132
133 addExplicitInteraction(at1, at2, De, beta, Re, ca1, cb1);
134 }
135 }
136 initialized_ = true;
137 }
138
139 void MAW::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
140 RealType De, RealType beta, RealType Re,
141 RealType ca1, RealType cb1) {
142 MAWInteractionData mixer;
143 mixer.De = De;
144 mixer.beta = beta;
145 mixer.Re = Re;
146 mixer.ca1 = ca1;
147 mixer.cb1 = cb1;
148 mixer.j_is_Metal = atype2->isMetal();
149
150 int mtid1 = MAWtids[atype1->getIdent()];
151 int mtid2 = MAWtids[atype2->getIdent()];
152 int nM = MAWtypes.size();
153
154 MixingMap.resize(nM);
155 MixingMap[mtid1].resize(nM);
156
157 MixingMap[mtid1][mtid2] = mixer;
158 if (mtid2 != mtid1) {
159 MixingMap[mtid2].resize(nM);
160 mixer.j_is_Metal = atype1->isMetal();
161 MixingMap[mtid2][mtid1] = mixer;
162 }
163 }
164
165 void MAW::calcForce(InteractionData& idat) {
166 if (!initialized_) initialize();
167
168 MAWInteractionData& mixer =
169 MixingMap[MAWtids[idat.atid1]][MAWtids[idat.atid2]];
170
171 RealType myPot = 0.0;
172 RealType myPotC = 0.0;
173 RealType myDeriv = 0.0;
174 RealType myDerivC = 0.0;
175
176 RealType D_e = mixer.De;
177 RealType R_e = mixer.Re;
178 RealType beta = mixer.beta;
179 RealType ca1 = mixer.ca1;
180 RealType cb1 = mixer.cb1;
181
182 Vector3d r;
183 RotMat3x3d Atrans;
184 if (mixer.j_is_Metal) {
185 // rotate the inter-particle separation into the two different
186 // body-fixed coordinate systems:
187 r = idat.A1 * idat.d;
188 Atrans = idat.A1.transpose();
189 } else {
190 // negative sign because this is the vector from j to i:
191 r = -idat.A2 * idat.d;
192 Atrans = idat.A2.transpose();
193 }
194
195 // V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2)
196
197 RealType expt = -beta * (idat.rij - R_e);
198 RealType expfnc = exp(expt);
199 RealType expfnc2 = expfnc * expfnc;
200
201 RealType exptC = 0.0;
202 RealType expfncC = 0.0;
203 RealType expfnc2C = 0.0;
204
205 myPot = D_e * (expfnc2 - 2.0 * expfnc);
206 myDeriv = 2.0 * D_e * beta * (expfnc - expfnc2);
207
208 if (idat.shiftedPot || idat.shiftedForce) {
209 exptC = -beta * (idat.rcut - R_e);
210 expfncC = exp(exptC);
211 expfnc2C = expfncC * expfncC;
212 }
213
214 if (idat.shiftedPot) {
215 myPotC = D_e * (expfnc2C - 2.0 * expfncC);
216 myDerivC = 0.0;
217 } else if (idat.shiftedForce) {
218 myPotC = D_e * (expfnc2C - 2.0 * expfncC);
219 myDerivC = 2.0 * D_e * beta * (expfncC - expfnc2C);
220 myPotC += myDerivC * (idat.rij - idat.rcut);
221 } else {
222 myPotC = 0.0;
223 myDerivC = 0.0;
224 }
225
226 RealType x = r.x();
227 RealType y = r.y();
228 RealType z = r.z();
229 RealType x2 = x * x;
230 RealType z2 = z * z;
231
232 RealType r3 = idat.r2 * idat.rij;
233 RealType r4 = idat.r2 * idat.r2;
234
235 // angular modulation of morse part of potential to approximate
236 // the squares of the two HOMO lone pair orbitals in water:
237 //********************** old form*************************
238 // s = 1 / (4 pi)
239 // ta1 = (s - pz)^2 = (1 - sqrt(3)*cos(theta))^2 / (4 pi)
240 // b1 = px^2 = 3 * (sin(theta)*cos(phi))^2 / (4 pi)
241 //********************** old form*************************
242 // we'll leave out the 4 pi for now
243
244 // new functional form just using the p orbitals.
245 // Vmorse(r)*[a*p_x + b p_z + (1-a-b)]
246 // which is
247 // Vmorse(r)*[a sin^2(theta) cos^2(phi) + b cos(theta) + (1-a-b)]
248 // Vmorse(r)*[a*x2/r2 + b*z/r + (1-a-b)]
249
250 RealType Vmorse = (myPot - myPotC);
251 RealType Vang = ca1 * x2 / idat.r2 + cb1 * z / idat.rij + (0.8 - ca1 / 3.0);
252
253 RealType pot_temp = idat.vdwMult * Vmorse * Vang;
254 idat.vpair += pot_temp;
255 idat.pot[VANDERWAALS_FAMILY] += idat.sw * pot_temp;
256 if (idat.isSelected) idat.selePot[VANDERWAALS_FAMILY] += idat.sw * pot_temp;
257 Vector3d dVmorsedr = (myDeriv - myDerivC) * Vector3d(x, y, z) / idat.rij;
258
259 Vector3d dVangdr = Vector3d(
260 -2.0 * ca1 * x2 * x / r4 + 2.0 * ca1 * x / idat.r2 - cb1 * x * z / r3,
261 -2.0 * ca1 * x2 * y / r4 - cb1 * z * y / r3,
262 -2.0 * ca1 * x2 * z / r4 + cb1 / idat.rij - cb1 * z2 / r3);
263
264 // chain rule to put these back on x, y, z
265
266 Vector3d dvdr = Vang * dVmorsedr + Vmorse * dVangdr;
267
268 // Torques for Vang using method of Price:
269 // S. L. Price, A. J. Stone, and M. Alderton, Mol. Phys. 52, 987 (1984).
270
271 Vector3d dVangdu = Vector3d(
272 cb1 * y / idat.rij, 2.0 * ca1 * x * z / idat.r2 - cb1 * x / idat.rij,
273 -2.0 * ca1 * y * x / idat.r2);
274
275 // do the torques first since they are easy:
276 // remember that these are still in the body fixed axes
277
278 Vector3d trq = idat.vdwMult * Vmorse * dVangdu * idat.sw;
279
280 // go back to lab frame using transpose of rotation matrix:
281
282 if (mixer.j_is_Metal) {
283 idat.t1 += Atrans * trq;
284 } else {
285 idat.t2 += Atrans * trq;
286 }
287
288 // Now, on to the forces (still in body frame of water)
289
290 Vector3d ftmp = idat.vdwMult * idat.sw * dvdr;
291
292 // rotate the terms back into the lab frame:
293 Vector3d flab;
294 if (mixer.j_is_Metal) {
295 flab = Atrans * ftmp;
296 } else {
297 flab = -Atrans * ftmp;
298 }
299
300 idat.f1 += flab;
301
302 return;
303 }
304
305 RealType MAW::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
306 if (!initialized_) initialize();
307 int atid1 = atypes.first->getIdent();
308 int atid2 = atypes.second->getIdent();
309 int mtid1 = MAWtids[atid1];
310 int mtid2 = MAWtids[atid2];
311
312 if (mtid1 == -1 || mtid2 == -1)
313 return 0.0;
314 else {
315 MAWInteractionData mixer = MixingMap[mtid1][mtid2];
316 RealType R_e = mixer.Re;
317 RealType beta = mixer.beta;
318 // This value of the r corresponds to an energy about 1.48% of
319 // the energy at the bottom of the Morse well. For comparison, the
320 // Lennard-Jones function is about 1.63% of it's minimum value at
321 // a distance of 2.5 sigma.
322 return (4.9 + beta * R_e) / beta;
323 }
324 }
325} // namespace OpenMD
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
@ VANDERWAALS_FAMILY
Long-range dispersion and short-range pauli repulsion.