1 |
/* |
2 |
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
* |
4 |
* The University of Notre Dame grants you ("Licensee") a |
5 |
* non-exclusive, royalty free, license to use, modify and |
6 |
* redistribute this software in source and binary code form, provided |
7 |
* that the following conditions are met: |
8 |
* |
9 |
* 1. Redistributions of source code must retain the above copyright |
10 |
* notice, this list of conditions and the following disclaimer. |
11 |
* |
12 |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
* notice, this list of conditions and the following disclaimer in the |
14 |
* documentation and/or other materials provided with the |
15 |
* distribution. |
16 |
* |
17 |
* This software is provided "AS IS," without a warranty of any |
18 |
* kind. All express or implied conditions, representations and |
19 |
* warranties, including any implied warranty of merchantability, |
20 |
* fitness for a particular purpose or non-infringement, are hereby |
21 |
* excluded. The University of Notre Dame and its licensors shall not |
22 |
* be liable for any damages suffered by licensee as a result of |
23 |
* using, modifying or distributing the software or its |
24 |
* derivatives. In no event will the University of Notre Dame or its |
25 |
* licensors be liable for any lost revenue, profit or data, or for |
26 |
* direct, indirect, special, consequential, incidental or punitive |
27 |
* damages, however caused and regardless of the theory of liability, |
28 |
* arising out of the use of or inability to use software, even if the |
29 |
* University of Notre Dame has been advised of the possibility of |
30 |
* such damages. |
31 |
* |
32 |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
* research, please cite the appropriate papers when you publish your |
34 |
* work. Good starting points are: |
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, 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> |
44 |
#include <string.h> |
45 |
#include <cmath> |
46 |
|
47 |
#include "nonbonded/MAW.hpp" |
48 |
#include "utils/simError.h" |
49 |
|
50 |
using namespace std; |
51 |
|
52 |
namespace OpenMD { |
53 |
|
54 |
MAW::MAW() : name_("MAW"), initialized_(false), forceField_(NULL) {} |
55 |
|
56 |
void MAW::initialize() { |
57 |
|
58 |
ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes(); |
59 |
ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j; |
60 |
NonBondedInteractionType* nbt; |
61 |
ForceField::NonBondedInteractionTypeContainer::KeyType keys; |
62 |
|
63 |
for (nbt = nbiTypes->beginType(j); nbt != NULL; |
64 |
nbt = nbiTypes->nextType(j)) { |
65 |
|
66 |
if (nbt->isMAW()) { |
67 |
keys = nbiTypes->getKeys(j); |
68 |
AtomType* at1 = forceField_->getAtomType(keys[0]); |
69 |
AtomType* at2 = forceField_->getAtomType(keys[1]); |
70 |
|
71 |
MAWInteractionType* mit = dynamic_cast<MAWInteractionType*>(nbt); |
72 |
|
73 |
if (mit == NULL) { |
74 |
sprintf( painCave.errMsg, |
75 |
"MAW::initialize could not convert NonBondedInteractionType\n" |
76 |
"\tto MAWInteractionType for %s - %s interaction.\n", |
77 |
at1->getName().c_str(), |
78 |
at2->getName().c_str()); |
79 |
painCave.severity = OPENMD_ERROR; |
80 |
painCave.isFatal = 1; |
81 |
simError(); |
82 |
} |
83 |
|
84 |
RealType De = mit->getD(); |
85 |
RealType beta = mit->getBeta(); |
86 |
RealType Re = mit->getR(); |
87 |
RealType ca1 = mit->getCA1(); |
88 |
RealType cb1 = mit->getCB1(); |
89 |
|
90 |
addExplicitInteraction(at1, at2, |
91 |
De, beta, Re, ca1, cb1); |
92 |
} |
93 |
} |
94 |
initialized_ = true; |
95 |
} |
96 |
|
97 |
void MAW::addExplicitInteraction(AtomType* atype1, AtomType* atype2, |
98 |
RealType De, RealType beta, RealType Re, |
99 |
RealType ca1, RealType cb1) { |
100 |
|
101 |
MAWInteractionData mixer; |
102 |
mixer.De = De; |
103 |
mixer.beta = beta; |
104 |
mixer.Re = Re; |
105 |
mixer.ca1 = ca1; |
106 |
mixer.cb1 = cb1; |
107 |
|
108 |
pair<AtomType*, AtomType*> key1, key2; |
109 |
key1 = make_pair(atype1, atype2); |
110 |
key2 = make_pair(atype2, atype1); |
111 |
|
112 |
MixingMap[key1] = mixer; |
113 |
if (key2 != key1) { |
114 |
MixingMap[key2] = mixer; |
115 |
} |
116 |
} |
117 |
|
118 |
void MAW::calcForce(InteractionData &idat) { |
119 |
|
120 |
if (!initialized_) initialize(); |
121 |
|
122 |
map<pair<AtomType*, AtomType*>, MAWInteractionData>::iterator it; |
123 |
it = MixingMap.find( idat.atypes ); |
124 |
if (it != MixingMap.end()) { |
125 |
MAWInteractionData mixer = (*it).second; |
126 |
|
127 |
RealType myPot = 0.0; |
128 |
RealType myPotC = 0.0; |
129 |
RealType myDeriv = 0.0; |
130 |
RealType myDerivC = 0.0; |
131 |
|
132 |
RealType D_e = mixer.De; |
133 |
RealType R_e = mixer.Re; |
134 |
RealType beta = mixer.beta; |
135 |
RealType ca1 = mixer.ca1; |
136 |
RealType cb1 = mixer.cb1; |
137 |
|
138 |
bool j_is_Metal = idat.atypes.second->isMetal(); |
139 |
|
140 |
Vector3d r; |
141 |
RotMat3x3d Atrans; |
142 |
if (j_is_Metal) { |
143 |
// rotate the inter-particle separation into the two different |
144 |
// body-fixed coordinate systems: |
145 |
r = *(idat.A1) * *(idat.d); |
146 |
Atrans = idat.A1->transpose(); |
147 |
} else { |
148 |
// negative sign because this is the vector from j to i: |
149 |
r = -*(idat.A2) * *(idat.d); |
150 |
Atrans = idat.A2->transpose(); |
151 |
} |
152 |
|
153 |
// V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2) |
154 |
|
155 |
RealType expt = -beta*( *(idat.rij) - R_e); |
156 |
RealType expfnc = exp(expt); |
157 |
RealType expfnc2 = expfnc*expfnc; |
158 |
|
159 |
RealType exptC = 0.0; |
160 |
RealType expfncC = 0.0; |
161 |
RealType expfnc2C = 0.0; |
162 |
|
163 |
myPot = D_e * (expfnc2 - 2.0 * expfnc); |
164 |
myDeriv = 2.0 * D_e * beta * (expfnc - expfnc2); |
165 |
|
166 |
if (idat.shiftedPot || idat.shiftedForce) { |
167 |
exptC = -beta*( *(idat.rcut) - R_e); |
168 |
expfncC = exp(exptC); |
169 |
expfnc2C = expfncC*expfncC; |
170 |
} |
171 |
|
172 |
if (idat.shiftedPot) { |
173 |
myPotC = D_e * (expfnc2C - 2.0 * expfncC); |
174 |
myDerivC = 0.0; |
175 |
} else if (idat.shiftedForce) { |
176 |
myPotC = D_e * (expfnc2C - 2.0 * expfncC); |
177 |
myDerivC = 2.0 * D_e * beta * (expfncC - expfnc2C); |
178 |
myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut) ); |
179 |
} else { |
180 |
myPotC = 0.0; |
181 |
myDerivC = 0.0; |
182 |
} |
183 |
|
184 |
RealType x = r.x(); |
185 |
RealType y = r.y(); |
186 |
RealType z = r.z(); |
187 |
RealType x2 = x * x; |
188 |
RealType z2 = z * z; |
189 |
|
190 |
RealType r3 = *(idat.r2) * *(idat.rij) ; |
191 |
RealType r4 = *(idat.r2) * *(idat.r2); |
192 |
|
193 |
// angular modulation of morse part of potential to approximate |
194 |
// the squares of the two HOMO lone pair orbitals in water: |
195 |
//********************** old form************************* |
196 |
// s = 1 / (4 pi) |
197 |
// ta1 = (s - pz)^2 = (1 - sqrt(3)*cos(theta))^2 / (4 pi) |
198 |
// b1 = px^2 = 3 * (sin(theta)*cos(phi))^2 / (4 pi) |
199 |
//********************** old form************************* |
200 |
// we'll leave out the 4 pi for now |
201 |
|
202 |
// new functional form just using the p orbitals. |
203 |
// Vmorse(r)*[a*p_x + b p_z + (1-a-b)] |
204 |
// which is |
205 |
// Vmorse(r)*[a sin^2(theta) cos^2(phi) + b cos(theta) + (1-a-b)] |
206 |
// Vmorse(r)*[a*x2/r2 + b*z/r + (1-a-b)] |
207 |
|
208 |
RealType Vmorse = (myPot - myPotC); |
209 |
RealType Vang = ca1 * x2 / *(idat.r2) + |
210 |
cb1 * z / *(idat.rij) + (0.8 - ca1 / 3.0); |
211 |
|
212 |
RealType pot_temp = *(idat.vdwMult) * Vmorse * Vang; |
213 |
*(idat.vpair) += pot_temp; |
214 |
(*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp; |
215 |
|
216 |
Vector3d dVmorsedr = (myDeriv - myDerivC) * Vector3d(x, y, z) / *(idat.rij) ; |
217 |
|
218 |
Vector3d dVangdr = Vector3d(-2.0 * ca1 * x2 * x / r4 + 2.0 * ca1 * x / *(idat.r2) - cb1 * x * z / r3, |
219 |
-2.0 * ca1 * x2 * y / r4 - cb1 * z * y / r3, |
220 |
-2.0 * ca1 * x2 * z / r4 + cb1 / *(idat.rij) - cb1 * z2 / r3); |
221 |
|
222 |
// chain rule to put these back on x, y, z |
223 |
|
224 |
Vector3d dvdr = Vang * dVmorsedr + Vmorse * dVangdr; |
225 |
|
226 |
// Torques for Vang using method of Price: |
227 |
// S. L. Price, A. J. Stone, and M. Alderton, Mol. Phys. 52, 987 (1984). |
228 |
|
229 |
Vector3d dVangdu = Vector3d(cb1 * y / *(idat.rij) , |
230 |
2.0 * ca1 * x * z / *(idat.r2) - cb1 * x / *(idat.rij), |
231 |
-2.0 * ca1 * y * x / *(idat.r2)); |
232 |
|
233 |
// do the torques first since they are easy: |
234 |
// remember that these are still in the body fixed axes |
235 |
|
236 |
Vector3d trq = *(idat.vdwMult) * Vmorse * dVangdu * *(idat.sw); |
237 |
|
238 |
// go back to lab frame using transpose of rotation matrix: |
239 |
|
240 |
if (j_is_Metal) { |
241 |
*(idat.t1) += Atrans * trq; |
242 |
} else { |
243 |
*(idat.t2) += Atrans * trq; |
244 |
} |
245 |
|
246 |
// Now, on to the forces (still in body frame of water) |
247 |
|
248 |
Vector3d ftmp = *(idat.vdwMult) * *(idat.sw) * dvdr; |
249 |
|
250 |
// rotate the terms back into the lab frame: |
251 |
Vector3d flab; |
252 |
if (j_is_Metal) { |
253 |
flab = Atrans * ftmp; |
254 |
} else { |
255 |
flab = - Atrans * ftmp; |
256 |
} |
257 |
|
258 |
*(idat.f1) += flab; |
259 |
} |
260 |
return; |
261 |
|
262 |
} |
263 |
|
264 |
RealType MAW::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
265 |
if (!initialized_) initialize(); |
266 |
map<pair<AtomType*, AtomType*>, MAWInteractionData>::iterator it; |
267 |
it = MixingMap.find(atypes); |
268 |
if (it == MixingMap.end()) |
269 |
return 0.0; |
270 |
else { |
271 |
MAWInteractionData mixer = (*it).second; |
272 |
|
273 |
RealType R_e = mixer.Re; |
274 |
RealType beta = mixer.beta; |
275 |
// This value of the r corresponds to an energy about 1.48% of |
276 |
// the energy at the bottom of the Morse well. For comparison, the |
277 |
// Lennard-Jones function is about 1.63% of it's minimum value at |
278 |
// a distance of 2.5 sigma. |
279 |
return (4.9 + beta * R_e) / beta; |
280 |
} |
281 |
} |
282 |
} |
283 |
|