45#include "nonbonded/Morse.hpp"
51#include "types/MorseInteractionType.hpp"
52#include "utils/simError.h"
58 Morse::Morse() : initialized_(false), forceField_(NULL), name_(
"Morse") {}
60 void Morse::initialize() {
66 Mtids.resize(forceField_->getNAtomType(), -1);
68 ForceField::NonBondedInteractionTypeContainer* nbiTypes =
69 forceField_->getNonBondedInteractionTypes();
70 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
71 ForceField::NonBondedInteractionTypeContainer::KeyType keys;
72 NonBondedInteractionType* nbt;
74 for (nbt = nbiTypes->beginType(j); nbt != NULL;
75 nbt = nbiTypes->nextType(j)) {
77 keys = nbiTypes->getKeys(j);
78 AtomType* at1 = forceField_->getAtomType(keys[0]);
80 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
81 "Morse::initialize could not find AtomType %s\n"
82 "\tto for for %s - %s interaction.\n",
83 keys[0].c_str(), keys[0].c_str(), keys[1].c_str());
84 painCave.severity = OPENMD_ERROR;
89 AtomType* at2 = forceField_->getAtomType(keys[1]);
91 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
92 "Morse::initialize could not find AtomType %s\n"
93 "\tfor %s - %s nonbonded interaction.\n",
94 keys[1].c_str(), keys[0].c_str(), keys[1].c_str());
95 painCave.severity = OPENMD_ERROR;
100 MorseInteractionType* mit =
dynamic_cast<MorseInteractionType*
>(nbt);
104 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
105 "Morse::initialize could not convert NonBondedInteractionType\n"
106 "\tto MorseInteractionType for %s - %s interaction.\n",
107 at1->getName().c_str(), at2->getName().c_str());
108 painCave.severity = OPENMD_ERROR;
109 painCave.isFatal = 1;
113 RealType De = mit->getD();
114 RealType Re = mit->getR();
115 RealType beta = mit->getBeta();
117 MorseType variant = mit->getInteractionType();
118 addExplicitInteraction(at1, at2, De, Re, beta, variant);
124 void Morse::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
125 RealType De, RealType Re, RealType beta,
127 MorseInteractionData mixer;
133 int atid1 = atype1->getIdent();
134 int atid2 = atype2->getIdent();
138 pair<set<int>::iterator,
bool> ret;
139 ret = Mtypes.insert(atid1);
140 if (ret.second ==
false) {
142 mtid1 = Mtids[atid1];
149 ret = Mtypes.insert(atid2);
150 if (ret.second ==
false) {
152 mtid2 = Mtids[atid2];
160 MixingMap.resize(nM_);
161 MixingMap[mtid1].resize(nM_);
162 MixingMap[mtid1][mtid2] = mixer;
163 if (mtid2 != mtid1) {
164 MixingMap[mtid2].resize(nM_);
165 MixingMap[mtid2][mtid1] = mixer;
169 void Morse::calcForce(InteractionData& idat) {
170 if (!initialized_) initialize();
172 MorseInteractionData& mixer =
173 MixingMap[Mtids[idat.atid1]][Mtids[idat.atid2]];
175 RealType myPot = 0.0;
176 RealType myPotC = 0.0;
177 RealType myDeriv = 0.0;
178 RealType myDerivC = 0.0;
180 RealType De = mixer.De;
181 RealType Re = mixer.Re;
182 RealType beta = mixer.beta;
183 MorseType variant = mixer.variant;
187 RealType expt = -beta * (idat.rij - Re);
188 RealType expfnc = exp(expt);
189 RealType expfnc2 = expfnc * expfnc;
191 RealType exptC = 0.0;
192 RealType expfncC = 0.0;
193 RealType expfnc2C = 0.0;
195 if (idat.shiftedPot || idat.shiftedForce) {
196 exptC = -beta * (idat.rcut - Re);
197 expfncC = exp(exptC);
198 expfnc2C = expfncC * expfncC;
203 myPot = De * (expfnc2 - 2.0 * expfnc);
204 myDeriv = 2.0 * De * beta * (expfnc - expfnc2);
206 if (idat.shiftedPot) {
207 myPotC = De * (expfnc2C - 2.0 * expfncC);
209 }
else if (idat.shiftedForce) {
210 myPotC = De * (expfnc2C - 2.0 * expfncC);
211 myDerivC = 2.0 * De * beta * (expfncC - expfnc2C);
212 myPotC += myDerivC * (idat.rij - idat.rcut);
221 myPot = De * expfnc2;
222 myDeriv = -2.0 * De * beta * expfnc2;
224 if (idat.shiftedPot) {
225 myPotC = De * expfnc2C;
227 }
else if (idat.shiftedForce) {
228 myPotC = De * expfnc2C;
229 myDerivC = -2.0 * De * beta * expfnc2C;
230 myPotC += myDerivC * (idat.rij - idat.rcut);
244 RealType pot_temp = idat.vdwMult * (myPot - myPotC);
245 idat.vpair += pot_temp;
247 RealType dudr = idat.sw * idat.vdwMult * (myDeriv - myDerivC);
252 idat.f1 += idat.d * dudr / idat.rij;
257 RealType Morse::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
258 if (!initialized_) initialize();
260 int atid1 = atypes.first->getIdent();
261 int atid2 = atypes.second->getIdent();
262 int mtid1 = Mtids[atid1];
263 int mtid2 = Mtids[atid2];
265 if (mtid1 == -1 || mtid2 == -1)
268 MorseInteractionData mixer = MixingMap[mtid1][mtid2];
269 RealType Re = mixer.Re;
270 RealType beta = mixer.beta;
275 return (4.9 + beta * Re) / beta;
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.