| 1 |
gezelter |
1501 |
/* |
| 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 |
gezelter |
1664 |
#include "types/MorseInteractionType.hpp" |
| 49 |
gezelter |
1501 |
|
| 50 |
|
|
using namespace std; |
| 51 |
|
|
|
| 52 |
|
|
namespace OpenMD { |
| 53 |
|
|
|
| 54 |
gezelter |
1583 |
Morse::Morse() : name_("Morse"), initialized_(false), forceField_(NULL) {} |
| 55 |
gezelter |
1501 |
|
| 56 |
|
|
void Morse::initialize() { |
| 57 |
|
|
|
| 58 |
|
|
ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes(); |
| 59 |
|
|
ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j; |
| 60 |
|
|
NonBondedInteractionType* nbt; |
| 61 |
gezelter |
1664 |
ForceField::NonBondedInteractionTypeContainer::KeyType keys; |
| 62 |
gezelter |
1501 |
|
| 63 |
|
|
for (nbt = nbiTypes->beginType(j); nbt != NULL; |
| 64 |
|
|
nbt = nbiTypes->nextType(j)) { |
| 65 |
|
|
|
| 66 |
|
|
if (nbt->isMorse()) { |
| 67 |
gezelter |
1664 |
keys = nbiTypes->getKeys(j); |
| 68 |
|
|
AtomType* at1 = forceField_->getAtomType(keys[0]); |
| 69 |
|
|
AtomType* at2 = forceField_->getAtomType(keys[1]); |
| 70 |
gezelter |
1501 |
|
| 71 |
gezelter |
1664 |
MorseInteractionType* mit = dynamic_cast<MorseInteractionType*>(nbt); |
| 72 |
gezelter |
1501 |
|
| 73 |
gezelter |
1664 |
if (mit == NULL) { |
| 74 |
gezelter |
1501 |
sprintf( painCave.errMsg, |
| 75 |
gezelter |
1664 |
"Morse::initialize could not convert NonBondedInteractionType\n" |
| 76 |
|
|
"\tto MorseInteractionType for %s - %s interaction.\n", |
| 77 |
|
|
at1->getName().c_str(), |
| 78 |
|
|
at2->getName().c_str()); |
| 79 |
gezelter |
1501 |
painCave.severity = OPENMD_ERROR; |
| 80 |
|
|
painCave.isFatal = 1; |
| 81 |
|
|
simError(); |
| 82 |
|
|
} |
| 83 |
gezelter |
1664 |
|
| 84 |
|
|
RealType De = mit->getD(); |
| 85 |
|
|
RealType Re = mit->getR(); |
| 86 |
|
|
RealType beta = mit->getBeta(); |
| 87 |
|
|
|
| 88 |
|
|
MorseType variant = mit->getInteractionType(); |
| 89 |
|
|
addExplicitInteraction(at1, at2, De, Re, beta, variant ); |
| 90 |
gezelter |
1501 |
} |
| 91 |
|
|
} |
| 92 |
|
|
initialized_ = true; |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
|
|
void Morse::addExplicitInteraction(AtomType* atype1, AtomType* atype2, |
| 96 |
|
|
RealType De, RealType Re, RealType beta, |
| 97 |
gezelter |
1664 |
MorseType mt) { |
| 98 |
gezelter |
1501 |
|
| 99 |
|
|
MorseInteractionData mixer; |
| 100 |
|
|
mixer.De = De; |
| 101 |
|
|
mixer.Re = Re; |
| 102 |
|
|
mixer.beta = beta; |
| 103 |
gezelter |
1664 |
mixer.variant = mt; |
| 104 |
gezelter |
1501 |
|
| 105 |
|
|
pair<AtomType*, AtomType*> key1, key2; |
| 106 |
|
|
key1 = make_pair(atype1, atype2); |
| 107 |
|
|
key2 = make_pair(atype2, atype1); |
| 108 |
|
|
|
| 109 |
|
|
MixingMap[key1] = mixer; |
| 110 |
|
|
if (key2 != key1) { |
| 111 |
|
|
MixingMap[key2] = mixer; |
| 112 |
|
|
} |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
gezelter |
1536 |
void Morse::calcForce(InteractionData &idat) { |
| 116 |
gezelter |
1501 |
|
| 117 |
|
|
if (!initialized_) initialize(); |
| 118 |
|
|
|
| 119 |
gezelter |
1505 |
map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it; |
| 120 |
gezelter |
1571 |
it = MixingMap.find( idat.atypes ); |
| 121 |
gezelter |
1505 |
if (it != MixingMap.end()) { |
| 122 |
|
|
MorseInteractionData mixer = (*it).second; |
| 123 |
|
|
|
| 124 |
|
|
RealType myPot = 0.0; |
| 125 |
|
|
RealType myPotC = 0.0; |
| 126 |
|
|
RealType myDeriv = 0.0; |
| 127 |
|
|
RealType myDerivC = 0.0; |
| 128 |
|
|
|
| 129 |
|
|
RealType De = mixer.De; |
| 130 |
|
|
RealType Re = mixer.Re; |
| 131 |
|
|
RealType beta = mixer.beta; |
| 132 |
gezelter |
1664 |
MorseType variant = mixer.variant; |
| 133 |
gezelter |
1505 |
|
| 134 |
|
|
// V(r) = D_e exp(-a(r-re)(exp(-a(r-re))-2) |
| 135 |
|
|
|
| 136 |
gezelter |
1554 |
RealType expt = -beta*( *(idat.rij) - Re); |
| 137 |
gezelter |
1505 |
RealType expfnc = exp(expt); |
| 138 |
|
|
RealType expfnc2 = expfnc*expfnc; |
| 139 |
|
|
|
| 140 |
|
|
RealType exptC = 0.0; |
| 141 |
|
|
RealType expfncC = 0.0; |
| 142 |
|
|
RealType expfnc2C = 0.0; |
| 143 |
|
|
|
| 144 |
gezelter |
1583 |
if (idat.shiftedPot || idat.shiftedForce) { |
| 145 |
gezelter |
1554 |
exptC = -beta*( *(idat.rcut) - Re); |
| 146 |
gezelter |
1505 |
expfncC = exp(exptC); |
| 147 |
|
|
expfnc2C = expfncC*expfncC; |
| 148 |
gezelter |
1501 |
} |
| 149 |
gezelter |
1505 |
|
| 150 |
|
|
|
| 151 |
gezelter |
1664 |
switch(variant) { |
| 152 |
|
|
case mtShifted : { |
| 153 |
gezelter |
1505 |
|
| 154 |
|
|
myPot = De * (expfnc2 - 2.0 * expfnc); |
| 155 |
|
|
myDeriv = 2.0 * De * beta * (expfnc - expfnc2); |
| 156 |
|
|
|
| 157 |
gezelter |
1583 |
if (idat.shiftedPot) { |
| 158 |
gezelter |
1505 |
myPotC = De * (expfnc2C - 2.0 * expfncC); |
| 159 |
|
|
myDerivC = 0.0; |
| 160 |
gezelter |
1583 |
} else if (idat.shiftedForce) { |
| 161 |
gezelter |
1505 |
myPotC = De * (expfnc2C - 2.0 * expfncC); |
| 162 |
|
|
myDerivC = 2.0 * De * beta * (expfnc2C - expfnc2C); |
| 163 |
gezelter |
1554 |
myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut) ); |
| 164 |
gezelter |
1505 |
} else { |
| 165 |
|
|
myPotC = 0.0; |
| 166 |
|
|
myDerivC = 0.0; |
| 167 |
|
|
} |
| 168 |
|
|
|
| 169 |
|
|
break; |
| 170 |
gezelter |
1501 |
} |
| 171 |
gezelter |
1664 |
case mtRepulsive : { |
| 172 |
gezelter |
1505 |
|
| 173 |
|
|
myPot = De * expfnc2; |
| 174 |
|
|
myDeriv = -2.0 * De * beta * expfnc2; |
| 175 |
|
|
|
| 176 |
gezelter |
1583 |
if (idat.shiftedPot) { |
| 177 |
gezelter |
1505 |
myPotC = De * expfnc2C; |
| 178 |
|
|
myDerivC = 0.0; |
| 179 |
gezelter |
1583 |
} else if (idat.shiftedForce) { |
| 180 |
gezelter |
1505 |
myPotC = De * expfnc2C; |
| 181 |
|
|
myDerivC = -2.0 * De * beta * expfnc2C; |
| 182 |
gezelter |
1554 |
myPotC += myDerivC * ( *(idat.rij) - *(idat.rcut)); |
| 183 |
gezelter |
1505 |
} else { |
| 184 |
|
|
myPotC = 0.0; |
| 185 |
|
|
myDerivC = 0.0; |
| 186 |
|
|
} |
| 187 |
|
|
|
| 188 |
|
|
break; |
| 189 |
|
|
} |
| 190 |
gezelter |
1664 |
case mtUnknown: { |
| 191 |
|
|
// don't know what to do so don't do anything |
| 192 |
|
|
break; |
| 193 |
gezelter |
1505 |
} |
| 194 |
gezelter |
1664 |
} |
| 195 |
gezelter |
1505 |
|
| 196 |
gezelter |
1554 |
RealType pot_temp = *(idat.vdwMult) * (myPot - myPotC); |
| 197 |
|
|
*(idat.vpair) += pot_temp; |
| 198 |
gezelter |
1505 |
|
| 199 |
gezelter |
1554 |
RealType dudr = *(idat.sw) * *(idat.vdwMult) * (myDeriv - myDerivC); |
| 200 |
gezelter |
1505 |
|
| 201 |
gezelter |
1582 |
(*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp; |
| 202 |
gezelter |
1554 |
*(idat.f1) = *(idat.d) * dudr / *(idat.rij); |
| 203 |
gezelter |
1501 |
} |
| 204 |
gezelter |
1505 |
return; |
| 205 |
gezelter |
1501 |
|
| 206 |
gezelter |
1505 |
} |
| 207 |
|
|
|
| 208 |
gezelter |
1545 |
RealType Morse::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
| 209 |
gezelter |
1505 |
if (!initialized_) initialize(); |
| 210 |
|
|
map<pair<AtomType*, AtomType*>, MorseInteractionData>::iterator it; |
| 211 |
gezelter |
1545 |
it = MixingMap.find(atypes); |
| 212 |
gezelter |
1505 |
if (it == MixingMap.end()) |
| 213 |
|
|
return 0.0; |
| 214 |
|
|
else { |
| 215 |
|
|
MorseInteractionData mixer = (*it).second; |
| 216 |
gezelter |
1501 |
|
| 217 |
gezelter |
1505 |
RealType Re = mixer.Re; |
| 218 |
|
|
RealType beta = mixer.beta; |
| 219 |
|
|
// This value of the r corresponds to an energy about 1.48% of |
| 220 |
|
|
// the energy at the bottom of the Morse well. For comparison, the |
| 221 |
|
|
// Lennard-Jones function is about 1.63% of it's minimum value at |
| 222 |
|
|
// a distance of 2.5 sigma. |
| 223 |
|
|
return (4.9 + beta * Re) / beta; |
| 224 |
|
|
} |
| 225 |
gezelter |
1501 |
} |
| 226 |
|
|
} |
| 227 |
|
|
|