45#include "nonbonded/Buckingham.hpp"
51#include "types/BuckinghamInteractionType.hpp"
52#include "utils/simError.h"
58 Buckingham::Buckingham() :
59 initialized_(false), forceField_(NULL), name_(
"Buckingham") {}
61 void Buckingham::initialize() {
65 Btids.resize(forceField_->getNAtomType(), -1);
67 ForceField::NonBondedInteractionTypeContainer* nbiTypes =
68 forceField_->getNonBondedInteractionTypes();
69 ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j;
70 ForceField::NonBondedInteractionTypeContainer::KeyType keys;
71 NonBondedInteractionType* nbt;
74 for (nbt = nbiTypes->beginType(j); nbt != NULL;
75 nbt = nbiTypes->nextType(j)) {
76 if (nbt->isBuckingham()) {
77 keys = nbiTypes->getKeys(j);
78 AtomType* at1 = forceField_->getAtomType(keys[0]);
80 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
81 "Buckingham::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 "Buckingham::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 int atid1 = at1->getIdent();
101 if (Btids[atid1] == -1) {
102 btid1 = Btypes.size();
103 Btypes.insert(atid1);
104 Btids[atid1] = btid1;
106 int atid2 = at2->getIdent();
107 if (Btids[atid2] == -1) {
108 btid2 = Btypes.size();
109 Btypes.insert(atid2);
110 Btids[atid2] = btid2;
113 BuckinghamInteractionType* bit =
114 dynamic_cast<BuckinghamInteractionType*
>(nbt);
117 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
118 "Buckingham::initialize could not convert "
119 "NonBondedInteractionType\n"
120 "\tto BuckinghamInteractionType for %s - %s interaction.\n",
121 at1->getName().c_str(), at2->getName().c_str());
122 painCave.severity = OPENMD_ERROR;
123 painCave.isFatal = 1;
127 RealType A = bit->getA();
128 RealType B = bit->getB();
129 RealType C = bit->getC();
131 BuckinghamType variant = bit->getInteractionType();
132 addExplicitInteraction(at1, at2, A, B, C, variant);
138 void Buckingham::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
139 RealType A, RealType B, RealType C,
141 BuckinghamInteractionData mixer;
147 int btid1 = Btids[atype1->getIdent()];
148 int btid2 = Btids[atype2->getIdent()];
149 int nB = Btypes.size();
151 MixingMap.resize(nB);
152 MixingMap[btid1].resize(nB);
154 MixingMap[btid1][btid2] = mixer;
155 if (btid2 != btid1) {
156 MixingMap[btid2].resize(nB);
157 MixingMap[btid2][btid1] = mixer;
161 void Buckingham::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
162 RealType A, RealType B, RealType C,
163 RealType sigma, RealType epsilon,
165 BuckinghamInteractionData mixer;
170 mixer.epsilon = epsilon;
173 int btid1 = Btids[atype1->getIdent()];
174 int btid2 = Btids[atype2->getIdent()];
175 int nB = Btypes.size();
177 MixingMap.resize(nB);
178 MixingMap[btid1].resize(nB);
180 MixingMap[btid1][btid2] = mixer;
181 if (btid2 != btid1) {
182 MixingMap[btid2].resize(nB);
183 MixingMap[btid2][btid1] = mixer;
187 void Buckingham::calcForce(InteractionData& idat) {
188 if (!initialized_) initialize();
190 BuckinghamInteractionData& mixer =
191 MixingMap[Btids[idat.atid1]][Btids[idat.atid2]];
193 RealType myPot = 0.0;
194 RealType myPotC = 0.0;
195 RealType myDeriv = 0.0;
196 RealType myDerivC = 0.0;
198 RealType A = mixer.A;
199 RealType B = mixer.B;
200 RealType C = mixer.C;
201 RealType sigma = mixer.sigma;
202 RealType epsilon = mixer.epsilon;
203 BuckinghamType variant = mixer.variant;
205 RealType expt = -B * idat.rij;
206 RealType expfnc = exp(expt);
207 RealType fnc6 = 1.0 / pow(idat.rij, 6);
208 RealType fnc7 = fnc6 / idat.rij;
210 RealType exptC = 0.0;
211 RealType expfncC = 0.0;
212 RealType fnc6C = 0.0;
213 RealType fnc7C = 0.0;
215 if (idat.shiftedPot || idat.shiftedForce) {
216 exptC = -B * idat.rcut;
217 expfncC = exp(exptC);
218 fnc6C = 1.0 / pow(idat.rcut, 6);
219 fnc7C = fnc6C / idat.rcut;
223 case btTraditional: {
225 myPot = A * expfnc - C * fnc6;
226 myDeriv = -A * B * expfnc + C * fnc7;
228 if (idat.shiftedPot) {
229 myPotC = A * expfncC - C * fnc6C;
231 }
else if (idat.shiftedForce) {
232 myPotC = A * expfncC - C * fnc6C;
233 myDerivC = -A * B * expfncC + C * fnc7C;
234 myPotC += myDerivC * (idat.rij - idat.rcut);
242 RealType s6 = pow(sigma, 6);
243 RealType s7 = pow(sigma, 7);
244 RealType fnc30 = pow(sigma / idat.rij, 30);
245 RealType fnc31 = fnc30 * sigma / idat.rij;
246 RealType fnc30C = 0.0;
247 RealType fnc31C = 0.0;
249 if (idat.shiftedPot || idat.shiftedForce) {
250 fnc30C = pow(sigma / idat.rcut, 30);
251 fnc31C = fnc30C * sigma / idat.rcut;
255 myPot = A * expfnc - C * fnc6 + 4.0 * epsilon * (fnc30 - s6 * fnc6);
256 myDeriv = -A * B * expfnc + C * fnc7 +
257 4.0 * epsilon * (-30.0 * fnc31 + 6.0 * s7 * fnc7) / sigma;
259 if (idat.shiftedPot) {
261 A * expfncC - C * fnc6C + 4.0 * epsilon * (fnc30C - s6 * fnc6C);
263 }
else if (idat.shiftedForce) {
265 A * expfncC - C * fnc6C + 4.0 * epsilon * (fnc30C - s6 * fnc6C);
266 myDeriv = -A * B * expfncC + C * fnc7C +
267 4.0 * epsilon * (-30.0 * fnc31C + 6.0 * s7 * fnc7C) / sigma;
268 myPotC += myDerivC * (idat.rij - idat.rcut);
282 RealType pot_temp = idat.vdwMult * (myPot - myPotC);
283 idat.vpair += pot_temp;
285 RealType dudr = idat.sw * idat.vdwMult * (myDeriv - myDerivC);
290 idat.f1 += idat.d * dudr / idat.rij;
295 RealType Buckingham::getSuggestedCutoffRadius(
296 pair<AtomType*, AtomType*> atypes) {
297 if (!initialized_) initialize();
299 int atid1 = atypes.first->getIdent();
300 int atid2 = atypes.second->getIdent();
301 int btid1 = Btids[atid1];
302 int btid2 = Btids[atid2];
304 if (btid1 == -1 || btid2 == -1)
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.