| 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 |
|
| 45 |
#include <cmath> |
| 46 |
#include "nonbonded/Morse.hpp" |
| 47 |
#include "utils/simError.h" |
| 48 |
#include "types/NonBondedInteractionType.hpp" |
| 49 |
|
| 50 |
using namespace std; |
| 51 |
|
| 52 |
namespace OpenMD { |
| 53 |
|
| 54 |
Morse::Morse() : name_("Morse"), initialized_(false), forceField_(NULL) {} |
| 55 |
|
| 56 |
void Morse::initialize() { |
| 57 |
|
| 58 |
stringToEnumMap_["shiftedMorse"] = shiftedMorse; |
| 59 |
stringToEnumMap_["repulsiveMorse"] = repulsiveMorse; |
| 60 |
|
| 61 |
ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes(); |
| 62 |
ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j; |
| 63 |
NonBondedInteractionType* nbt; |
| 64 |
|
| 65 |
for (nbt = nbiTypes->beginType(j); nbt != NULL; |
| 66 |
nbt = nbiTypes->nextType(j)) { |
| 67 |
|
| 68 |
if (nbt->isMorse()) { |
| 69 |
|
| 70 |
pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes(); |
| 71 |
|
| 72 |
GenericData* data = nbt->getPropertyByName("Morse"); |
| 73 |
if (data == NULL) { |
| 74 |
sprintf( painCave.errMsg, "Morse::initialize could not find\n" |
| 75 |
"\tMorse parameters for %s - %s interaction.\n", |
| 76 |
atypes.first->getName().c_str(), |
| 77 |
atypes.second->getName().c_str()); |
| 78 |
painCave.severity = OPENMD_ERROR; |
| 79 |
painCave.isFatal = 1; |
| 80 |
simError(); |
| 81 |
} |
| 82 |
|
| 83 |
MorseData* morseData = dynamic_cast<MorseData*>(data); |
| 84 |
if (morseData == NULL) { |
| 85 |
sprintf( painCave.errMsg, |
| 86 |
"Morse::initialize could not convert GenericData to\n" |
| 87 |
"\tMorseData for %s - %s interaction.\n", |
| 88 |
atypes.first->getName().c_str(), |
| 89 |
atypes.second->getName().c_str()); |
| 90 |
painCave.severity = OPENMD_ERROR; |
| 91 |
painCave.isFatal = 1; |
| 92 |
simError(); |
| 93 |
} |
| 94 |
|
| 95 |
MorseParam morseParam = morseData->getData(); |
| 96 |
|
| 97 |
RealType De = morseParam.De; |
| 98 |
RealType Re = morseParam.Re; |
| 99 |
RealType beta = morseParam.beta; |
| 100 |
string interactionType = morseParam.interactionType; |
| 101 |
|
| 102 |
toUpper(interactionType); |
| 103 |
map<string, MorseInteractionType>::iterator i; |
| 104 |
i = stringToEnumMap_.find(interactionType); |
| 105 |
if (i != stringToEnumMap_.end()) { |
| 106 |
addExplicitInteraction(atypes.first, atypes.second, |
| 107 |
De, Re, beta, i->second ); |
| 108 |
} else { |
| 109 |
sprintf( painCave.errMsg, |
| 110 |
"Morse::initialize found unknown Morse interaction type\n" |
| 111 |
"\t(%s) for %s - %s interaction.\n", |
| 112 |
morseParam.interactionType.c_str(), |
| 113 |
atypes.first->getName().c_str(), |
| 114 |
atypes.second->getName().c_str()); |
| 115 |
painCave.severity = OPENMD_ERROR; |
| 116 |
painCave.isFatal = 1; |
| 117 |
simError(); |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
initialized_ = true; |
| 122 |
} |
| 123 |
|
| 124 |
void Morse::addExplicitInteraction(AtomType* atype1, AtomType* atype2, |
| 125 |
RealType De, RealType Re, RealType beta, |
| 126 |
MorseInteractionType mit) { |
| 127 |
|
| 128 |
MorseInteractionData mixer; |
| 129 |
mixer.De = De; |
| 130 |
mixer.Re = Re; |
| 131 |
mixer.beta = beta; |
| 132 |
mixer.interactionType = mit; |
| 133 |
|
| 134 |
pair<AtomType*, AtomType*> key1, key2; |
| 135 |
key1 = make_pair(atype1, atype2); |
| 136 |
key2 = make_pair(atype2, atype1); |
| 137 |
|
| 138 |
MixingMap[key1] = mixer; |
| 139 |
if (key2 != key1) { |
| 140 |
MixingMap[key2] = mixer; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
void Morse::initForce() { |
| 145 |
if (!initialized_) initialize(); |
| 146 |
} |
| 147 |
|
| 148 |
void Morse::calcForce(InteractionData &idat) { |
| 149 |
|
| 150 |
if (!initialized_) initialize(); |
| 151 |
|
| 152 |
map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it; |
| 153 |
it = MixingMap.find( idat.atypes ); |
| 154 |
if (it != MixingMap.end()) { |
| 155 |
MorseInteractionData mixer = (*it).second; |
| 156 |
|
| 157 |
RealType myPot = 0.0; |
| 158 |
RealType myPotC = 0.0; |
| 159 |
RealType myDeriv = 0.0; |
| 160 |
RealType myDerivC = 0.0; |
| 161 |
|
| 162 |
RealType De = mixer.De; |
| 163 |
RealType Re = mixer.Re; |
| 164 |
RealType beta = mixer.beta; |
| 165 |
MorseInteractionType interactionType = mixer.interactionType; |
| 166 |
|
| 167 |
// V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2) |
| 168 |
|
| 169 |
RealType expt = -beta*( *(idat.rij) - Re); |
| 170 |
RealType expfnc = exp(expt); |
| 171 |
RealType expfnc2 = expfnc*expfnc; |
| 172 |
|
| 173 |
RealType exptC = 0.0; |
| 174 |
RealType expfncC = 0.0; |
| 175 |
RealType expfnc2C = 0.0; |
| 176 |
|
| 177 |
if (idat.shiftedPot || idat.shiftedForce) { |
| 178 |
exptC = -beta*( *(idat.rcut) - Re); |
| 179 |
expfncC = exp(exptC); |
| 180 |
expfnc2C = expfncC*expfncC; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
switch(interactionType) { |
| 185 |
case shiftedMorse : { |
| 186 |
|
| 187 |
myPot = De * (expfnc2 - 2.0 * expfnc); |
| 188 |
myDeriv = 2.0 * De * beta * (expfnc - expfnc2); |
| 189 |
|
| 190 |
if (idat.shiftedPot) { |
| 191 |
myPotC = De * (expfnc2C - 2.0 * expfncC); |
| 192 |
myDerivC = 0.0; |
| 193 |
} else if (idat.shiftedForce) { |
| 194 |
myPotC = De * (expfnc2C - 2.0 * expfncC); |
| 195 |
myDerivC = 2.0 * De * beta * (expfnc2C - expfnc2C); |
| 196 |
myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut) ); |
| 197 |
} else { |
| 198 |
myPotC = 0.0; |
| 199 |
myDerivC = 0.0; |
| 200 |
} |
| 201 |
|
| 202 |
break; |
| 203 |
} |
| 204 |
case repulsiveMorse : { |
| 205 |
|
| 206 |
myPot = De * expfnc2; |
| 207 |
myDeriv = -2.0 * De * beta * expfnc2; |
| 208 |
|
| 209 |
if (idat.shiftedPot) { |
| 210 |
myPotC = De * expfnc2C; |
| 211 |
myDerivC = 0.0; |
| 212 |
} else if (idat.shiftedForce) { |
| 213 |
myPotC = De * expfnc2C; |
| 214 |
myDerivC = -2.0 * De * beta * expfnc2C; |
| 215 |
myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut)); |
| 216 |
} else { |
| 217 |
myPotC = 0.0; |
| 218 |
myDerivC = 0.0; |
| 219 |
} |
| 220 |
|
| 221 |
break; |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
RealType pot_temp = *(idat.vdwMult) * (myPot - myPotC); |
| 226 |
*(idat.vpair) += pot_temp; |
| 227 |
|
| 228 |
RealType dudr = *(idat.sw) * *(idat.vdwMult) * (myDeriv - myDerivC); |
| 229 |
|
| 230 |
(*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp; |
| 231 |
*(idat.f1) = *(idat.d) * dudr / *(idat.rij); |
| 232 |
} |
| 233 |
return; |
| 234 |
|
| 235 |
} |
| 236 |
|
| 237 |
RealType Morse::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
| 238 |
if (!initialized_) initialize(); |
| 239 |
map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it; |
| 240 |
it = MixingMap.find(atypes); |
| 241 |
if (it == MixingMap.end()) |
| 242 |
return 0.0; |
| 243 |
else { |
| 244 |
MorseInteractionData mixer = (*it).second; |
| 245 |
|
| 246 |
RealType Re = mixer.Re; |
| 247 |
RealType beta = mixer.beta; |
| 248 |
// This value of the r corresponds to an energy about 1.48% of |
| 249 |
// the energy at the bottom of the Morse well. For comparison, the |
| 250 |
// Lennard-Jones function is about 1.63% of it's minimum value at |
| 251 |
// a distance of 2.5 sigma. |
| 252 |
return (4.9 + beta * Re) / beta; |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
|