45#include "nonbonded/RepulsivePower.hpp"
51#include "types/RepulsivePowerInteractionType.hpp"
52#include "utils/simError.h"
58 RepulsivePower::RepulsivePower() :
59 initialized_(false), forceField_(NULL), name_(
"RepulsivePower") {}
61 void RepulsivePower::initialize() {
65 RPtids.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->isRepulsivePower()) {
77 keys = nbiTypes->getKeys(j);
78 AtomType* at1 = forceField_->getAtomType(keys[0]);
80 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
81 "RepulsivePower::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 "RepulsivePower::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 (RPtids[atid1] == -1) {
102 rptid1 = RPtypes.size();
103 RPtypes.insert(atid1);
104 RPtids[atid1] = rptid1;
106 int atid2 = at2->getIdent();
107 if (RPtids[atid2] == -1) {
108 rptid2 = RPtypes.size();
109 RPtypes.insert(atid2);
110 RPtids[atid2] = rptid2;
113 RepulsivePowerInteractionType* rpit =
114 dynamic_cast<RepulsivePowerInteractionType*
>(nbt);
117 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
118 "RepulsivePower::initialize could not convert "
119 "NonBondedInteractionType\n"
120 "\tto RepulsivePowerInteractionType 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 sigma = rpit->getSigma();
128 RealType epsilon = rpit->getEpsilon();
129 int nRep = rpit->getNrep();
131 addExplicitInteraction(at1, at2, sigma, epsilon, nRep);
137 void RepulsivePower::addExplicitInteraction(AtomType* atype1,
138 AtomType* atype2, RealType sigma,
139 RealType epsilon,
int nRep) {
140 RPInteractionData mixer;
142 mixer.epsilon = epsilon;
143 mixer.sigmai = 1.0 / mixer.sigma;
146 int nRP = RPtypes.size();
147 int atid1 = atype1->getIdent();
148 int atid2 = atype2->getIdent();
151 pair<set<int>::iterator,
bool> ret;
152 ret = RPtypes.insert(atid1);
153 if (ret.second ==
false) {
155 rptid1 = RPtids[atid1];
163 ret = RPtypes.insert(atid2);
164 if (ret.second ==
false) {
166 rptid2 = RPtids[atid2];
174 MixingMap.resize(nRP);
175 MixingMap[rptid1].resize(nRP);
177 MixingMap[rptid1][rptid2] = mixer;
178 if (rptid2 != rptid1) {
179 MixingMap[rptid2].resize(nRP);
180 MixingMap[rptid2][rptid1] = mixer;
184 void RepulsivePower::calcForce(InteractionData& idat) {
185 if (!initialized_) initialize();
187 RPInteractionData& mixer =
188 MixingMap[RPtids[idat.atid1]][RPtids[idat.atid2]];
189 RealType sigmai = mixer.sigmai;
190 RealType epsilon = mixer.epsilon;
191 int nRep = mixer.nRep;
195 RealType myPot = 0.0;
196 RealType myPotC = 0.0;
197 RealType myDeriv = 0.0;
198 RealType myDerivC = 0.0;
200 ros = idat.rij * sigmai;
202 getNRepulsionFunc(ros, nRep, myPot, myDeriv);
204 if (idat.shiftedPot) {
205 rcos = idat.rcut * sigmai;
206 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
208 }
else if (idat.shiftedForce) {
209 rcos = idat.rcut * sigmai;
210 getNRepulsionFunc(rcos, nRep, myPotC, myDerivC);
211 myPotC = myPotC + myDerivC * (idat.rij - idat.rcut) * sigmai;
217 RealType pot_temp = idat.vdwMult * epsilon * (myPot - myPotC);
218 idat.vpair += pot_temp;
221 idat.sw * idat.vdwMult * epsilon * (myDeriv - myDerivC) * sigmai;
226 idat.f1 += idat.d * dudr / idat.rij;
231 void RepulsivePower::getNRepulsionFunc(
const RealType& r,
int& n,
232 RealType& pot, RealType& deriv) {
233 RealType ri = 1.0 / r;
234 RealType rin = pow(ri, n);
235 RealType rin1 = rin * ri;
243 RealType RepulsivePower::getSuggestedCutoffRadius(
244 pair<AtomType*, AtomType*> atypes) {
245 if (!initialized_) initialize();
247 int atid1 = atypes.first->getIdent();
248 int atid2 = atypes.second->getIdent();
249 int rptid1 = RPtids[atid1];
250 int rptid2 = RPtids[atid2];
252 if (rptid1 == -1 || rptid2 == -1)
255 RPInteractionData mixer = MixingMap[rptid1][rptid2];
256 return 2.5 * mixer.sigma;
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.