| 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). |
| 38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
| 39 |
> |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
> |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
|
*/ |
| 42 |
|
|
| 43 |
|
#include <stdio.h> |
| 54 |
|
SC::SC() : name_("SC"), initialized_(false), forceField_(NULL), |
| 55 |
|
scRcut_(0.0), np_(3000) {} |
| 56 |
|
|
| 57 |
< |
SCParam SC::getSCParam(AtomType* atomType) { |
| 58 |
< |
|
| 58 |
< |
// Do sanity checking on the AtomType we were passed before |
| 59 |
< |
// building any data structures: |
| 60 |
< |
if (!atomType->isSC()) { |
| 61 |
< |
sprintf( painCave.errMsg, |
| 62 |
< |
"SC::getSCParam was passed an atomType (%s) that does not\n" |
| 63 |
< |
"\tappear to be a Sutton-Chen (SC) atom.\n", |
| 64 |
< |
atomType->getName().c_str()); |
| 65 |
< |
painCave.severity = OPENMD_ERROR; |
| 66 |
< |
painCave.isFatal = 1; |
| 67 |
< |
simError(); |
| 68 |
< |
} |
| 69 |
< |
|
| 70 |
< |
GenericData* data = atomType->getPropertyByName("SC"); |
| 71 |
< |
if (data == NULL) { |
| 72 |
< |
sprintf( painCave.errMsg, "SC::getSCParam could not find SC\n" |
| 73 |
< |
"\tparameters for atomType %s.\n", |
| 74 |
< |
atomType->getName().c_str()); |
| 75 |
< |
painCave.severity = OPENMD_ERROR; |
| 76 |
< |
painCave.isFatal = 1; |
| 77 |
< |
simError(); |
| 78 |
< |
} |
| 79 |
< |
|
| 80 |
< |
SCParamGenericData* scData = dynamic_cast<SCParamGenericData*>(data); |
| 81 |
< |
if (scData == NULL) { |
| 82 |
< |
sprintf( painCave.errMsg, |
| 83 |
< |
"SC::getSCParam could not convert GenericData to SCParamGenericData\n" |
| 84 |
< |
"\tfor atom type %s\n", atomType->getName().c_str()); |
| 85 |
< |
painCave.severity = OPENMD_ERROR; |
| 86 |
< |
painCave.isFatal = 1; |
| 87 |
< |
simError(); |
| 88 |
< |
} |
| 89 |
< |
|
| 90 |
< |
return scData->getData(); |
| 91 |
< |
} |
| 57 |
> |
SC::~SC() { |
| 58 |
> |
initialized_ = false; |
| 59 |
|
|
| 60 |
< |
RealType SC::getC(AtomType* atomType) { |
| 61 |
< |
SCParam scParam = getSCParam(atomType); |
| 62 |
< |
return scParam.c; |
| 60 |
> |
MixingMap.clear(); |
| 61 |
> |
SCtypes.clear(); |
| 62 |
> |
SCdata.clear(); |
| 63 |
> |
SCtids.clear(); |
| 64 |
|
} |
| 65 |
< |
|
| 98 |
< |
RealType SC::getM(AtomType* atomType) { |
| 99 |
< |
SCParam scParam = getSCParam(atomType); |
| 100 |
< |
return scParam.m; |
| 101 |
< |
} |
| 102 |
< |
|
| 65 |
> |
|
| 66 |
|
RealType SC::getM(AtomType* atomType1, AtomType* atomType2) { |
| 67 |
< |
RealType m1 = getM(atomType1); |
| 68 |
< |
RealType m2 = getM(atomType2); |
| 67 |
> |
SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1); |
| 68 |
> |
SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2); |
| 69 |
> |
RealType m1 = sca1.getM(); |
| 70 |
> |
RealType m2 = sca2.getM(); |
| 71 |
|
return 0.5 * (m1 + m2); |
| 72 |
|
} |
| 73 |
|
|
| 109 |
– |
RealType SC::getN(AtomType* atomType) { |
| 110 |
– |
SCParam scParam = getSCParam(atomType); |
| 111 |
– |
return scParam.n; |
| 112 |
– |
} |
| 113 |
– |
|
| 74 |
|
RealType SC::getN(AtomType* atomType1, AtomType* atomType2) { |
| 75 |
< |
RealType n1 = getN(atomType1); |
| 76 |
< |
RealType n2 = getN(atomType2); |
| 75 |
> |
SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1); |
| 76 |
> |
SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2); |
| 77 |
> |
RealType n1 = sca1.getN(); |
| 78 |
> |
RealType n2 = sca2.getN(); |
| 79 |
|
return 0.5 * (n1 + n2); |
| 80 |
|
} |
| 81 |
|
|
| 120 |
– |
RealType SC::getAlpha(AtomType* atomType) { |
| 121 |
– |
SCParam scParam = getSCParam(atomType); |
| 122 |
– |
return scParam.alpha; |
| 123 |
– |
} |
| 124 |
– |
|
| 82 |
|
RealType SC::getAlpha(AtomType* atomType1, AtomType* atomType2) { |
| 83 |
< |
RealType alpha1 = getAlpha(atomType1); |
| 84 |
< |
RealType alpha2 = getAlpha(atomType2); |
| 83 |
> |
SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1); |
| 84 |
> |
SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2); |
| 85 |
> |
RealType alpha1 = sca1.getAlpha(); |
| 86 |
> |
RealType alpha2 = sca2.getAlpha(); |
| 87 |
|
|
| 88 |
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
| 89 |
|
std::string DistanceMix = fopts.getDistanceMixingRule(); |
| 95 |
|
return 0.5 * (alpha1 + alpha2); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
< |
RealType SC::getEpsilon(AtomType* atomType) { |
| 99 |
< |
SCParam scParam = getSCParam(atomType); |
| 100 |
< |
return scParam.epsilon; |
| 101 |
< |
} |
| 102 |
< |
|
| 144 |
< |
RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
| 145 |
< |
RealType epsilon1 = getEpsilon(atomType1); |
| 146 |
< |
RealType epsilon2 = getEpsilon(atomType2); |
| 98 |
> |
RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
| 99 |
> |
SuttonChenAdapter sca1 = SuttonChenAdapter(atomType1); |
| 100 |
> |
SuttonChenAdapter sca2 = SuttonChenAdapter(atomType2); |
| 101 |
> |
RealType epsilon1 = sca1.getEpsilon(); |
| 102 |
> |
RealType epsilon2 = sca2.getEpsilon(); |
| 103 |
|
return sqrt(epsilon1 * epsilon2); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
< |
void SC::initialize() { |
| 106 |
> |
void SC::initialize() { |
| 107 |
|
// find all of the SC atom Types: |
| 108 |
< |
ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes(); |
| 109 |
< |
ForceField::AtomTypeContainer::MapTypeIterator i; |
| 110 |
< |
AtomType* at; |
| 108 |
> |
SCtypes.clear(); |
| 109 |
> |
SCtids.clear(); |
| 110 |
> |
SCdata.clear(); |
| 111 |
> |
MixingMap.clear(); |
| 112 |
> |
nSC_ = 0; |
| 113 |
|
|
| 114 |
< |
for (at = atomTypes->beginType(i); at != NULL; |
| 115 |
< |
at = atomTypes->nextType(i)) { |
| 116 |
< |
if (at->isSC()) |
| 117 |
< |
addType(at); |
| 118 |
< |
} |
| 114 |
> |
SCtids.resize( forceField_->getNAtomType(), -1); |
| 115 |
> |
|
| 116 |
> |
set<AtomType*>::iterator at; |
| 117 |
> |
for (at = simTypes_.begin(); at != simTypes_.end(); ++at) { |
| 118 |
> |
if ((*at)->isSC()) nSC_++; |
| 119 |
> |
} |
| 120 |
> |
SCdata.resize(nSC_); |
| 121 |
> |
MixingMap.resize(nSC_); |
| 122 |
> |
for (at = simTypes_.begin(); at != simTypes_.end(); ++at) { |
| 123 |
> |
if ((*at)->isSC()) addType((*at)); |
| 124 |
> |
} |
| 125 |
|
initialized_ = true; |
| 126 |
|
} |
| 127 |
|
|
| 129 |
|
|
| 130 |
|
void SC::addType(AtomType* atomType){ |
| 131 |
|
|
| 132 |
+ |
SuttonChenAdapter sca = SuttonChenAdapter(atomType); |
| 133 |
|
SCAtomData scAtomData; |
| 134 |
|
|
| 135 |
< |
scAtomData.c = getC(atomType); |
| 136 |
< |
scAtomData.m = getM(atomType); |
| 137 |
< |
scAtomData.n = getN(atomType); |
| 138 |
< |
scAtomData.alpha = getAlpha(atomType); |
| 139 |
< |
scAtomData.epsilon = getEpsilon(atomType); |
| 135 |
> |
scAtomData.c = sca.getC(); |
| 136 |
> |
scAtomData.m = sca.getM(); |
| 137 |
> |
scAtomData.n = sca.getN(); |
| 138 |
> |
scAtomData.alpha = sca.getAlpha(); |
| 139 |
> |
scAtomData.epsilon = sca.getEpsilon(); |
| 140 |
|
scAtomData.rCut = 2.0 * scAtomData.alpha; |
| 141 |
< |
|
| 141 |
> |
|
| 142 |
|
// add it to the map: |
| 143 |
< |
AtomTypeProperties atp = atomType->getATP(); |
| 143 |
> |
int atid = atomType->getIdent(); |
| 144 |
> |
int sctid = SCtypes.size(); |
| 145 |
|
|
| 146 |
< |
pair<map<int,AtomType*>::iterator,bool> ret; |
| 147 |
< |
ret = SClist.insert( pair<int, AtomType*>(atp.ident, atomType) ); |
| 146 |
> |
pair<set<int>::iterator,bool> ret; |
| 147 |
> |
ret = SCtypes.insert( atid ); |
| 148 |
|
if (ret.second == false) { |
| 149 |
|
sprintf( painCave.errMsg, |
| 150 |
|
"SC already had a previous entry with ident %d\n", |
| 151 |
< |
atp.ident); |
| 151 |
> |
atid ); |
| 152 |
|
painCave.severity = OPENMD_INFO; |
| 153 |
|
painCave.isFatal = 0; |
| 154 |
|
simError(); |
| 155 |
|
} |
| 190 |
– |
|
| 191 |
– |
SCMap[atomType] = scAtomData; |
| 156 |
|
|
| 157 |
+ |
SCtids[atid] = sctid; |
| 158 |
+ |
SCdata[sctid] = scAtomData; |
| 159 |
+ |
MixingMap[sctid].resize(nSC_); |
| 160 |
+ |
|
| 161 |
|
// Now, iterate over all known types and add to the mixing map: |
| 162 |
|
|
| 163 |
< |
map<AtomType*, SCAtomData>::iterator it; |
| 164 |
< |
for( it = SCMap.begin(); it != SCMap.end(); ++it) { |
| 163 |
> |
std::set<int>::iterator it; |
| 164 |
> |
for( it = SCtypes.begin(); it != SCtypes.end(); ++it) { |
| 165 |
|
|
| 166 |
< |
AtomType* atype2 = (*it).first; |
| 166 |
> |
int sctid2 = SCtids[ (*it) ]; |
| 167 |
> |
AtomType* atype2 = forceField_->getAtomType( (*it) ); |
| 168 |
|
|
| 169 |
|
SCInteractionData mixer; |
| 170 |
|
|
| 203 |
|
|
| 204 |
|
mixer.explicitlySet = false; |
| 205 |
|
|
| 206 |
< |
pair<AtomType*, AtomType*> key1, key2; |
| 238 |
< |
key1 = make_pair(atomType, atype2); |
| 239 |
< |
key2 = make_pair(atype2, atomType); |
| 206 |
> |
MixingMap[sctid2].resize( nSC_ ); |
| 207 |
|
|
| 208 |
< |
MixingMap[key1] = mixer; |
| 209 |
< |
if (key2 != key1) { |
| 210 |
< |
MixingMap[key2] = mixer; |
| 208 |
> |
MixingMap[sctid][sctid2] = mixer; |
| 209 |
> |
if (sctid2 != sctid) { |
| 210 |
> |
MixingMap[sctid2][sctid] = mixer; |
| 211 |
|
} |
| 212 |
|
} |
| 213 |
|
return; |
| 258 |
|
|
| 259 |
|
mixer.explicitlySet = true; |
| 260 |
|
|
| 261 |
< |
pair<AtomType*, AtomType*> key1, key2; |
| 262 |
< |
key1 = make_pair(atype1, atype2); |
| 263 |
< |
key2 = make_pair(atype2, atype1); |
| 264 |
< |
|
| 265 |
< |
MixingMap[key1] = mixer; |
| 266 |
< |
if (key2 != key1) { |
| 300 |
< |
MixingMap[key2] = mixer; |
| 261 |
> |
int sctid1 = SCtids[ atype1->getIdent() ]; |
| 262 |
> |
int sctid2 = SCtids[ atype2->getIdent() ]; |
| 263 |
> |
|
| 264 |
> |
MixingMap[sctid1][sctid2] = mixer; |
| 265 |
> |
if (sctid2 != sctid1) { |
| 266 |
> |
MixingMap[sctid2][sctid1] = mixer; |
| 267 |
|
} |
| 268 |
|
return; |
| 269 |
|
} |
| 271 |
|
void SC::calcDensity(InteractionData &idat) { |
| 272 |
|
|
| 273 |
|
if (!initialized_) initialize(); |
| 274 |
+ |
int sctid1 = SCtids[idat.atid1]; |
| 275 |
+ |
int sctid2 = SCtids[idat.atid2]; |
| 276 |
|
|
| 277 |
< |
SCInteractionData mixer = MixingMap[ idat.atypes ]; |
| 277 |
> |
SCInteractionData &mixer = MixingMap[sctid1][sctid2]; |
| 278 |
|
|
| 279 |
|
RealType rcij = mixer.rCut; |
| 280 |
|
|
| 291 |
|
|
| 292 |
|
if (!initialized_) initialize(); |
| 293 |
|
|
| 294 |
< |
SCAtomData data1 = SCMap[sdat.atype]; |
| 294 |
> |
SCAtomData &data1 = SCdata[SCtids[sdat.atid]]; |
| 295 |
|
|
| 296 |
|
RealType u = - data1.c * data1.epsilon * sqrt( *(sdat.rho) ); |
| 297 |
|
*(sdat.frho) = u; |
| 298 |
|
*(sdat.dfrhodrho) = 0.5 * *(sdat.frho) / *(sdat.rho); |
| 299 |
|
|
| 300 |
< |
sdat.pot[METALLIC_FAMILY] += u; |
| 301 |
< |
*(sdat.particlePot) += u; |
| 302 |
< |
|
| 300 |
> |
(*(sdat.pot))[METALLIC_FAMILY] += u; |
| 301 |
> |
if (sdat.doParticlePot) { |
| 302 |
> |
*(sdat.particlePot) += u; |
| 303 |
> |
} |
| 304 |
> |
|
| 305 |
|
return; |
| 306 |
|
} |
| 307 |
|
|
| 310 |
|
|
| 311 |
|
if (!initialized_) initialize(); |
| 312 |
|
|
| 313 |
< |
SCAtomData data1 = SCMap[idat.atypes.first]; |
| 314 |
< |
SCAtomData data2 = SCMap[idat.atypes.second]; |
| 313 |
> |
int &sctid1 = SCtids[idat.atid1]; |
| 314 |
> |
int &sctid2 = SCtids[idat.atid2]; |
| 315 |
|
|
| 316 |
< |
SCInteractionData mixer = MixingMap[idat.atypes]; |
| 316 |
> |
SCAtomData &data1 = SCdata[sctid1]; |
| 317 |
> |
SCAtomData &data2 = SCdata[sctid2]; |
| 318 |
|
|
| 319 |
+ |
SCInteractionData &mixer = MixingMap[sctid1][sctid2]; |
| 320 |
+ |
|
| 321 |
|
RealType rcij = mixer.rCut; |
| 322 |
|
|
| 323 |
|
if ( *(idat.rij) < rcij) { |
| 324 |
< |
RealType vcij = mixer.vCut; |
| 324 |
> |
RealType vcij = mixer.vCut; |
| 325 |
> |
RealType rhtmp, drhodr, vptmp, dvpdr; |
| 326 |
|
|
| 327 |
< |
pair<RealType, RealType> res; |
| 327 |
> |
mixer.phi->getValueAndDerivativeAt( *(idat.rij), rhtmp, drhodr ); |
| 328 |
> |
mixer.V->getValueAndDerivativeAt( *(idat.rij), vptmp, dvpdr); |
| 329 |
|
|
| 355 |
– |
res = mixer.phi->getValueAndDerivativeAt( *(idat.rij) ); |
| 356 |
– |
RealType rhtmp = res.first; |
| 357 |
– |
RealType drhodr = res.second; |
| 358 |
– |
|
| 359 |
– |
res = mixer.V->getValueAndDerivativeAt( *(idat.rij) ); |
| 360 |
– |
RealType vptmp = res.first; |
| 361 |
– |
RealType dvpdr = res.second; |
| 362 |
– |
|
| 330 |
|
RealType pot_temp = vptmp - vcij; |
| 331 |
|
*(idat.vpair) += pot_temp; |
| 332 |
|
|
| 334 |
|
|
| 335 |
|
*(idat.f1) += *(idat.d) * dudr / *(idat.rij) ; |
| 336 |
|
|
| 337 |
< |
// particlePot is the difference between the full potential and |
| 338 |
< |
// the full potential without the presence of a particular |
| 339 |
< |
// particle (atom1). |
| 340 |
< |
// |
| 341 |
< |
// This reduces the density at other particle locations, so we |
| 342 |
< |
// need to recompute the density at atom2 assuming atom1 didn't |
| 343 |
< |
// contribute. This then requires recomputing the density |
| 344 |
< |
// functional for atom2 as well. |
| 345 |
< |
|
| 346 |
< |
*(idat.particlePot1) -= data2.c * data2.epsilon * |
| 347 |
< |
sqrt( *(idat.rho2) - rhtmp) + *(idat.frho2); |
| 337 |
> |
if (idat.doParticlePot) { |
| 338 |
> |
// particlePot is the difference between the full potential and |
| 339 |
> |
// the full potential without the presence of a particular |
| 340 |
> |
// particle (atom1). |
| 341 |
> |
// |
| 342 |
> |
// This reduces the density at other particle locations, so we |
| 343 |
> |
// need to recompute the density at atom2 assuming atom1 didn't |
| 344 |
> |
// contribute. This then requires recomputing the density |
| 345 |
> |
// functional for atom2 as well. |
| 346 |
> |
|
| 347 |
> |
*(idat.particlePot1) -= data2.c * data2.epsilon * |
| 348 |
> |
sqrt( *(idat.rho2) - rhtmp) + *(idat.frho2); |
| 349 |
|
|
| 350 |
< |
*(idat.particlePot1) -= data1.c * data1.epsilon * |
| 351 |
< |
sqrt( *(idat.rho1) - rhtmp) + *(idat.frho1); |
| 350 |
> |
*(idat.particlePot2) -= data1.c * data1.epsilon * |
| 351 |
> |
sqrt( *(idat.rho1) - rhtmp) + *(idat.frho1); |
| 352 |
> |
} |
| 353 |
|
|
| 354 |
< |
idat.pot[METALLIC_FAMILY] += pot_temp; |
| 354 |
> |
(*(idat.pot))[METALLIC_FAMILY] += pot_temp; |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
return; |
| 360 |
|
RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
| 361 |
|
if (!initialized_) initialize(); |
| 362 |
|
|
| 363 |
< |
map<pair<AtomType*, AtomType*>, SCInteractionData>::iterator it; |
| 364 |
< |
it = MixingMap.find(atypes); |
| 365 |
< |
if (it == MixingMap.end()) |
| 363 |
> |
int atid1 = atypes.first->getIdent(); |
| 364 |
> |
int atid2 = atypes.second->getIdent(); |
| 365 |
> |
int &sctid1 = SCtids[atid1]; |
| 366 |
> |
int &sctid2 = SCtids[atid2]; |
| 367 |
> |
|
| 368 |
> |
if (sctid1 == -1 || sctid2 == -1) { |
| 369 |
|
return 0.0; |
| 370 |
< |
else { |
| 371 |
< |
SCInteractionData mixer = (*it).second; |
| 400 |
< |
return mixer.rCut; |
| 370 |
> |
} else { |
| 371 |
> |
return MixingMap[sctid1][sctid2].rCut; |
| 372 |
|
} |
| 373 |
|
} |
| 374 |
|
} |