48#include "nonbonded/SC.hpp"
55#include "utils/simError.h"
59 SC::SC() : name_(
"SC"), initialized_(false), forceField_(NULL), np_(3000) {}
70 RealType SC::getM(AtomType* atomType1, AtomType* atomType2) {
71 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
72 SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
73 RealType m1 = sca1.getM();
74 RealType m2 = sca2.getM();
75 return 0.5 * (m1 + m2);
78 RealType SC::getN(AtomType* atomType1, AtomType* atomType2) {
79 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
80 SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
81 RealType n1 = sca1.getN();
82 RealType n2 = sca2.getN();
83 return 0.5 * (n1 + n2);
86 RealType SC::getAlpha(AtomType* atomType1, AtomType* atomType2) {
87 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
88 SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
89 RealType alpha1 = sca1.getAlpha();
90 RealType alpha2 = sca2.getAlpha();
92 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
93 std::string DistanceMix = fopts.getDistanceMixingRule();
96 if (DistanceMix ==
"GEOMETRIC")
97 return sqrt(alpha1 * alpha2);
99 return 0.5 * (alpha1 + alpha2);
102 RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) {
103 SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1);
104 SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2);
105 RealType epsilon1 = sca1.getEpsilon();
106 RealType epsilon2 = sca2.getEpsilon();
107 return sqrt(epsilon1 * epsilon2);
110 void SC::initialize() {
118 SCtids.resize(forceField_->getNAtomType(), -1);
120 AtomTypeSet::iterator at;
121 for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
122 if ((*at)->isSC()) nSC_++;
125 MixingMap.resize(nSC_);
126 for (at = simTypes_.begin(); at != simTypes_.end(); ++at) {
127 if ((*at)->isSC()) addType((*at));
132 void SC::addType(AtomType* atomType) {
133 SuttonChenAdapter sca = SuttonChenAdapter(atomType);
134 SCAtomData scAtomData;
136 scAtomData.c = sca.getC();
137 scAtomData.m = sca.getM();
138 scAtomData.n = sca.getN();
139 scAtomData.alpha = sca.getAlpha();
140 scAtomData.epsilon = sca.getEpsilon();
141 scAtomData.rCut = 2.0 * scAtomData.alpha;
144 int atid = atomType->getIdent();
145 int sctid = SCtypes.size();
147 pair<set<int>::iterator,
bool> ret;
148 ret = SCtypes.insert(atid);
149 if (ret.second ==
false) {
150 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
151 "SC already had a previous entry with ident %d\n", atid);
152 painCave.severity = OPENMD_INFO;
153 painCave.isFatal = 0;
157 SCtids[atid] = sctid;
158 SCdata[sctid] = scAtomData;
159 MixingMap[sctid].resize(nSC_);
163 std::set<int>::iterator it;
164 for (it = SCtypes.begin(); it != SCtypes.end(); ++it) {
165 int sctid2 = SCtids[(*it)];
166 AtomType* atype2 = forceField_->getAtomType((*it));
168 SCInteractionData mixer;
170 mixer.alpha = getAlpha(atomType, atype2);
171 mixer.rCut = 2.0 * mixer.alpha;
172 mixer.epsilon = getEpsilon(atomType, atype2);
173 mixer.m = getM(atomType, atype2);
174 mixer.n = getN(atomType, atype2);
176 RealType dr = mixer.rCut / (np_ - 1);
177 vector<RealType> rvals;
178 vector<RealType> vvals;
179 vector<RealType> phivals;
181 rvals.push_back(0.0);
182 vvals.push_back(0.0);
183 phivals.push_back(0.0);
185 for (
int k = 1; k < np_; k++) {
188 vvals.push_back(mixer.epsilon * pow(mixer.alpha / r, mixer.n));
189 phivals.push_back(pow(mixer.alpha / r, mixer.m));
192 mixer.vCut = mixer.epsilon * pow(mixer.alpha / mixer.rCut, mixer.n);
194 CubicSpline* V =
new CubicSpline();
195 V->addPoints(rvals, vvals);
197 CubicSpline* phi =
new CubicSpline();
198 phi->addPoints(rvals, phivals);
203 mixer.explicitlySet =
false;
205 MixingMap[sctid2].resize(nSC_);
207 MixingMap[sctid][sctid2] = mixer;
208 if (sctid2 != sctid) { MixingMap[sctid2][sctid] = mixer; }
213 void SC::addExplicitInteraction(AtomType* atype1, AtomType* atype2,
214 RealType epsilon, RealType m, RealType n,
220 SCInteractionData mixer;
222 mixer.epsilon = epsilon;
226 mixer.rCut = 2.0 * mixer.alpha;
228 RealType dr = mixer.rCut / (np_ - 1);
229 vector<RealType> rvals;
230 vector<RealType> vvals;
231 vector<RealType> phivals;
233 rvals.push_back(0.0);
234 vvals.push_back(0.0);
235 phivals.push_back(0.0);
237 for (
int k = 1; k < np_; k++) {
240 vvals.push_back(mixer.epsilon * pow(mixer.alpha / r, mixer.n));
241 phivals.push_back(pow(mixer.alpha / r, mixer.m));
244 mixer.vCut = mixer.epsilon * pow(mixer.alpha / mixer.rCut, mixer.n);
246 CubicSpline* V =
new CubicSpline();
247 V->addPoints(rvals, vvals);
249 CubicSpline* phi =
new CubicSpline();
250 phi->addPoints(rvals, phivals);
255 mixer.explicitlySet =
true;
257 int sctid1 = SCtids[atype1->getIdent()];
258 int sctid2 = SCtids[atype2->getIdent()];
260 MixingMap[sctid1][sctid2] = mixer;
261 if (sctid2 != sctid1) { MixingMap[sctid2][sctid1] = mixer; }
265 void SC::calcDensity(InteractionData& idat) {
266 if (!initialized_) initialize();
267 int sctid1 = SCtids[idat.atid1];
268 int sctid2 = SCtids[idat.atid2];
270 SCInteractionData& mixer = MixingMap[sctid1][sctid2];
272 RealType rcij = mixer.rCut;
274 if (idat.rij < rcij) {
275 RealType rho = mixer.phi->getValueAt(idat.rij);
283 void SC::calcFunctional(SelfData& sdat) {
284 if (!initialized_) initialize();
286 SCAtomData& data1 = SCdata[SCtids[sdat.atid]];
288 RealType u = -data1.c * data1.epsilon * sqrt(sdat.rho);
290 sdat.dfrhodrho = 0.5 * sdat.frho / sdat.rho;
296 if (sdat.doParticlePot) { sdat.particlePot += u; }
301 void SC::calcForce(InteractionData& idat) {
302 if (!initialized_) initialize();
304 int& sctid1 = SCtids[idat.atid1];
305 int& sctid2 = SCtids[idat.atid2];
307 SCAtomData& data1 = SCdata[sctid1];
308 SCAtomData& data2 = SCdata[sctid2];
310 SCInteractionData& mixer = MixingMap[sctid1][sctid2];
312 RealType rcij = mixer.rCut;
314 if (idat.rij < rcij) {
315 RealType vcij = mixer.vCut;
316 RealType rhtmp, drhodr, vptmp, dvpdr;
318 mixer.phi->getValueAndDerivativeAt(idat.rij, rhtmp, drhodr);
319 mixer.V->getValueAndDerivativeAt(idat.rij, vptmp, dvpdr);
321 RealType pot_temp = vptmp - vcij;
322 idat.vpair += pot_temp;
324 RealType dudr = drhodr * (idat.dfrho1 + idat.dfrho2) + dvpdr;
326 idat.f1 += idat.d * dudr / idat.rij;
328 if (idat.doParticlePot) {
339 data2.c * data2.epsilon * sqrt(idat.rho2 - rhtmp) + idat.frho2;
342 data1.c * data1.epsilon * sqrt(idat.rho1 - rhtmp) + idat.frho1;
353 RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) {
354 if (!initialized_) initialize();
356 int atid1 = atypes.first->getIdent();
357 int atid2 = atypes.second->getIdent();
358 int& sctid1 = SCtids[atid1];
359 int& sctid2 = SCtids[atid2];
361 if (sctid1 == -1 || sctid2 == -1) {
364 return MixingMap[sctid1][sctid2].rCut;
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
@ METALLIC_EMBEDDING_FAMILY
Transition metal interactions involving electron density.
@ METALLIC_PAIR_FAMILY
Transition metal interactions involving pair potentials.