| 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, 24107 (2008). |
| 39 |
* [4] Vardeman & Gezelter, in progress (2009). |
| 40 |
*/ |
| 41 |
|
| 42 |
#include <stdio.h> |
| 43 |
#include <string.h> |
| 44 |
#include <cmath> |
| 45 |
|
| 46 |
#include "nonbonded/MAW.hpp" |
| 47 |
#include "utils/simError.h" |
| 48 |
|
| 49 |
using namespace std; |
| 50 |
|
| 51 |
namespace OpenMD { |
| 52 |
|
| 53 |
MAW::MAW() : name_("MAW"), initialized_(false), forceField_(NULL) {} |
| 54 |
|
| 55 |
void MAW::initialize() { |
| 56 |
|
| 57 |
ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes(); |
| 58 |
ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j; |
| 59 |
NonBondedInteractionType* nbt; |
| 60 |
|
| 61 |
for (nbt = nbiTypes->beginType(j); nbt != NULL; |
| 62 |
nbt = nbiTypes->nextType(j)) { |
| 63 |
|
| 64 |
if (nbt->isMAW()) { |
| 65 |
pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes(); |
| 66 |
|
| 67 |
GenericData* data = nbt->getPropertyByName("MAW"); |
| 68 |
if (data == NULL) { |
| 69 |
sprintf( painCave.errMsg, "MAW::initialize could not find\n" |
| 70 |
"\tMAW parameters for %s - %s interaction.\n", |
| 71 |
atypes.first->getName().c_str(), |
| 72 |
atypes.second->getName().c_str()); |
| 73 |
painCave.severity = OPENMD_ERROR; |
| 74 |
painCave.isFatal = 1; |
| 75 |
simError(); |
| 76 |
} |
| 77 |
|
| 78 |
MAWData* mawData = dynamic_cast<MAWData*>(data); |
| 79 |
if (mawData == NULL) { |
| 80 |
sprintf( painCave.errMsg, |
| 81 |
"MAW::initialize could not convert GenericData to\n" |
| 82 |
"\tMAWData for %s - %s interaction.\n", |
| 83 |
atypes.first->getName().c_str(), |
| 84 |
atypes.second->getName().c_str()); |
| 85 |
painCave.severity = OPENMD_ERROR; |
| 86 |
painCave.isFatal = 1; |
| 87 |
simError(); |
| 88 |
} |
| 89 |
|
| 90 |
MAWParam mawParam = mawData->getData(); |
| 91 |
|
| 92 |
RealType De = mawParam.De; |
| 93 |
RealType beta = mawParam.beta; |
| 94 |
RealType Re = mawParam.Re; |
| 95 |
RealType ca1 = mawParam.ca1; |
| 96 |
RealType cb1 = mawParam.cb1; |
| 97 |
|
| 98 |
addExplicitInteraction(atypes.first, atypes.second, |
| 99 |
De, beta, Re, ca1, cb1); |
| 100 |
} |
| 101 |
} |
| 102 |
initialized_ = true; |
| 103 |
} |
| 104 |
|
| 105 |
void MAW::addExplicitInteraction(AtomType* atype1, AtomType* atype2, |
| 106 |
RealType De, RealType beta, RealType Re, |
| 107 |
RealType ca1, RealType cb1) { |
| 108 |
|
| 109 |
MAWInteractionData mixer; |
| 110 |
mixer.De = De; |
| 111 |
mixer.beta = beta; |
| 112 |
mixer.Re = Re; |
| 113 |
mixer.ca1 = ca1; |
| 114 |
mixer.cb1 = cb1; |
| 115 |
|
| 116 |
pair<AtomType*, AtomType*> key1, key2; |
| 117 |
key1 = make_pair(atype1, atype2); |
| 118 |
key2 = make_pair(atype2, atype1); |
| 119 |
|
| 120 |
MixingMap[key1] = mixer; |
| 121 |
if (key2 != key1) { |
| 122 |
MixingMap[key2] = mixer; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
void MAW::initForce() { |
| 127 |
if (!initialized_) initialize(); |
| 128 |
} |
| 129 |
|
| 130 |
void MAW::calcForce(InteractionData &idat) { |
| 131 |
|
| 132 |
if (!initialized_) initialize(); |
| 133 |
|
| 134 |
map<pair<AtomType*, AtomType*>, MAWInteractionData>::iterator it; |
| 135 |
it = MixingMap.find( idat.atypes ); |
| 136 |
if (it != MixingMap.end()) { |
| 137 |
MAWInteractionData mixer = (*it).second; |
| 138 |
|
| 139 |
RealType myPot = 0.0; |
| 140 |
RealType myPotC = 0.0; |
| 141 |
RealType myDeriv = 0.0; |
| 142 |
RealType myDerivC = 0.0; |
| 143 |
|
| 144 |
RealType D_e = mixer.De; |
| 145 |
RealType R_e = mixer.Re; |
| 146 |
RealType beta = mixer.beta; |
| 147 |
RealType ca1 = mixer.ca1; |
| 148 |
RealType cb1 = mixer.cb1; |
| 149 |
|
| 150 |
bool j_is_Metal = idat.atypes.second->isMetal(); |
| 151 |
|
| 152 |
Vector3d r; |
| 153 |
RotMat3x3d Atrans; |
| 154 |
if (j_is_Metal) { |
| 155 |
// rotate the inter-particle separation into the two different |
| 156 |
// body-fixed coordinate systems: |
| 157 |
r = *(idat.A1) * *(idat.d); |
| 158 |
Atrans = idat.A1->transpose(); |
| 159 |
} else { |
| 160 |
// negative sign because this is the vector from j to i: |
| 161 |
r = -*(idat.A2) * *(idat.d); |
| 162 |
Atrans = idat.A2->transpose(); |
| 163 |
} |
| 164 |
|
| 165 |
// V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2) |
| 166 |
|
| 167 |
RealType expt = -beta*( *(idat.rij) - R_e); |
| 168 |
RealType expfnc = exp(expt); |
| 169 |
RealType expfnc2 = expfnc*expfnc; |
| 170 |
|
| 171 |
RealType exptC = 0.0; |
| 172 |
RealType expfncC = 0.0; |
| 173 |
RealType expfnc2C = 0.0; |
| 174 |
|
| 175 |
myPot = D_e * (expfnc2 - 2.0 * expfnc); |
| 176 |
myDeriv = 2.0 * D_e * beta * (expfnc - expfnc2); |
| 177 |
|
| 178 |
if (idat.shiftedPot || idat.shiftedForce) { |
| 179 |
exptC = -beta*( *(idat.rcut) - R_e); |
| 180 |
expfncC = exp(exptC); |
| 181 |
expfnc2C = expfncC*expfncC; |
| 182 |
} |
| 183 |
|
| 184 |
if (idat.shiftedPot) { |
| 185 |
myPotC = D_e * (expfnc2C - 2.0 * expfncC); |
| 186 |
myDerivC = 0.0; |
| 187 |
} else if (idat.shiftedForce) { |
| 188 |
myPotC = D_e * (expfnc2C - 2.0 * expfncC); |
| 189 |
myDerivC = 2.0 * D_e * beta * (expfnc2C - expfnc2C); |
| 190 |
myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut) ); |
| 191 |
} else { |
| 192 |
myPotC = 0.0; |
| 193 |
myDerivC = 0.0; |
| 194 |
} |
| 195 |
|
| 196 |
RealType x = r.x(); |
| 197 |
RealType y = r.y(); |
| 198 |
RealType z = r.z(); |
| 199 |
RealType x2 = x * x; |
| 200 |
RealType y2 = y * y; |
| 201 |
RealType z2 = z * z; |
| 202 |
|
| 203 |
RealType r3 = *(idat.r2) * *(idat.rij) ; |
| 204 |
RealType r4 = *(idat.r2) * *(idat.r2); |
| 205 |
|
| 206 |
// angular modulation of morse part of potential to approximate |
| 207 |
// the squares of the two HOMO lone pair orbitals in water: |
| 208 |
//********************** old form************************* |
| 209 |
// s = 1 / (4 pi) |
| 210 |
// ta1 = (s - pz)^2 = (1 - sqrt(3)*cos(theta))^2 / (4 pi) |
| 211 |
// b1 = px^2 = 3 * (sin(theta)*cos(phi))^2 / (4 pi) |
| 212 |
//********************** old form************************* |
| 213 |
// we'll leave out the 4 pi for now |
| 214 |
|
| 215 |
// new functional form just using the p orbitals. |
| 216 |
// Vmorse(r)*[a*p_x + b p_z + (1-a-b)] |
| 217 |
// which is |
| 218 |
// Vmorse(r)*[a sin^2(theta) cos^2(phi) + b cos(theta) + (1-a-b)] |
| 219 |
// Vmorse(r)*[a*x2/r2 + b*z/r + (1-a-b)] |
| 220 |
|
| 221 |
RealType Vmorse = (myPot - myPotC); |
| 222 |
RealType Vang = ca1 * x2 / *(idat.r2) + |
| 223 |
cb1 * z / *(idat.rij) + (0.8 - ca1 / 3.0); |
| 224 |
|
| 225 |
RealType pot_temp = *(idat.vdwMult) * Vmorse * Vang; |
| 226 |
*(idat.vpair) += pot_temp; |
| 227 |
(*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp; |
| 228 |
|
| 229 |
Vector3d dVmorsedr = (myDeriv - myDerivC) * Vector3d(x, y, z) / *(idat.rij) ; |
| 230 |
|
| 231 |
Vector3d dVangdr = Vector3d(-2.0 * ca1 * x2 * x / r4 + 2.0 * ca1 * x / *(idat.r2) - cb1 * x * z / r3, |
| 232 |
-2.0 * ca1 * x2 * y / r4 - cb1 * z * y / r3, |
| 233 |
-2.0 * ca1 * x2 * z / r4 + cb1 / *(idat.rij) - cb1 * z2 / r3); |
| 234 |
|
| 235 |
// chain rule to put these back on x, y, z |
| 236 |
|
| 237 |
Vector3d dvdr = Vang * dVmorsedr + Vmorse * dVangdr; |
| 238 |
|
| 239 |
// Torques for Vang using method of Price: |
| 240 |
// S. L. Price, A. J. Stone, and M. Alderton, Mol. Phys. 52, 987 (1984). |
| 241 |
|
| 242 |
Vector3d dVangdu = Vector3d(cb1 * y / *(idat.rij) , |
| 243 |
2.0 * ca1 * x * z / *(idat.r2) - cb1 * x / *(idat.rij), |
| 244 |
-2.0 * ca1 * y * x / *(idat.r2)); |
| 245 |
|
| 246 |
// do the torques first since they are easy: |
| 247 |
// remember that these are still in the body fixed axes |
| 248 |
|
| 249 |
Vector3d trq = *(idat.vdwMult) * Vmorse * dVangdu * *(idat.sw); |
| 250 |
|
| 251 |
// go back to lab frame using transpose of rotation matrix: |
| 252 |
|
| 253 |
if (j_is_Metal) { |
| 254 |
*(idat.t1) += Atrans * trq; |
| 255 |
} else { |
| 256 |
*(idat.t2) += Atrans * trq; |
| 257 |
} |
| 258 |
|
| 259 |
// Now, on to the forces (still in body frame of water) |
| 260 |
|
| 261 |
Vector3d ftmp = *(idat.vdwMult) * *(idat.sw) * dvdr; |
| 262 |
|
| 263 |
// rotate the terms back into the lab frame: |
| 264 |
Vector3d flab; |
| 265 |
if (j_is_Metal) { |
| 266 |
flab = Atrans * ftmp; |
| 267 |
} else { |
| 268 |
flab = - Atrans * ftmp; |
| 269 |
} |
| 270 |
|
| 271 |
*(idat.f1) += flab; |
| 272 |
} |
| 273 |
return; |
| 274 |
|
| 275 |
} |
| 276 |
|
| 277 |
RealType MAW::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
| 278 |
if (!initialized_) initialize(); |
| 279 |
map<pair<AtomType*, AtomType*>, MAWInteractionData>::iterator it; |
| 280 |
it = MixingMap.find(atypes); |
| 281 |
if (it == MixingMap.end()) |
| 282 |
return 0.0; |
| 283 |
else { |
| 284 |
MAWInteractionData mixer = (*it).second; |
| 285 |
|
| 286 |
RealType R_e = mixer.Re; |
| 287 |
RealType beta = mixer.beta; |
| 288 |
// This value of the r corresponds to an energy about 1.48% of |
| 289 |
// the energy at the bottom of the Morse well. For comparison, the |
| 290 |
// Lennard-Jones function is about 1.63% of it's minimum value at |
| 291 |
// a distance of 2.5 sigma. |
| 292 |
return (4.9 + beta * R_e) / beta; |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
|