| 1 |
gezelter |
1489 |
/* |
| 2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
|
|
* |
| 4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
| 5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
| 6 |
|
|
* redistribute this software in source and binary code form, provided |
| 7 |
|
|
* that the following conditions are met: |
| 8 |
|
|
* |
| 9 |
|
|
* 1. Redistributions of source code must retain the above copyright |
| 10 |
|
|
* notice, this list of conditions and the following disclaimer. |
| 11 |
|
|
* |
| 12 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
|
|
* notice, this list of conditions and the following disclaimer in the |
| 14 |
|
|
* documentation and/or other materials provided with the |
| 15 |
|
|
* distribution. |
| 16 |
|
|
* |
| 17 |
|
|
* This software is provided "AS IS," without a warranty of any |
| 18 |
|
|
* kind. All express or implied conditions, representations and |
| 19 |
|
|
* warranties, including any implied warranty of merchantability, |
| 20 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
| 21 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
| 22 |
|
|
* be liable for any damages suffered by licensee as a result of |
| 23 |
|
|
* using, modifying or distributing the software or its |
| 24 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
| 25 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
| 26 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
| 27 |
|
|
* damages, however caused and regardless of the theory of liability, |
| 28 |
|
|
* arising out of the use of or inability to use software, even if the |
| 29 |
|
|
* University of Notre Dame has been advised of the possibility of |
| 30 |
|
|
* such damages. |
| 31 |
|
|
* |
| 32 |
|
|
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
| 33 |
|
|
* research, please cite the appropriate papers when you publish your |
| 34 |
|
|
* work. Good starting points are: |
| 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). |
| 40 |
|
|
*/ |
| 41 |
|
|
|
| 42 |
|
|
#include <stdio.h> |
| 43 |
|
|
#include <string.h> |
| 44 |
|
|
|
| 45 |
|
|
#include <cmath> |
| 46 |
|
|
#include "nonbonded/SC.hpp" |
| 47 |
|
|
#include "utils/simError.h" |
| 48 |
|
|
#include "types/NonBondedInteractionType.hpp" |
| 49 |
|
|
|
| 50 |
|
|
namespace OpenMD { |
| 51 |
|
|
|
| 52 |
|
|
|
| 53 |
gezelter |
1502 |
SC::SC() : name_("SC"), initialized_(false), forceField_(NULL), |
| 54 |
|
|
scRcut_(0.0), np_(3000) {} |
| 55 |
gezelter |
1489 |
|
| 56 |
|
|
SCParam SC::getSCParam(AtomType* atomType) { |
| 57 |
|
|
|
| 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 |
|
|
} |
| 92 |
|
|
|
| 93 |
|
|
RealType SC::getC(AtomType* atomType) { |
| 94 |
|
|
SCParam scParam = getSCParam(atomType); |
| 95 |
|
|
return scParam.c; |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
RealType SC::getM(AtomType* atomType) { |
| 99 |
|
|
SCParam scParam = getSCParam(atomType); |
| 100 |
|
|
return scParam.m; |
| 101 |
|
|
} |
| 102 |
|
|
|
| 103 |
|
|
RealType SC::getM(AtomType* atomType1, AtomType* atomType2) { |
| 104 |
|
|
RealType m1 = getM(atomType1); |
| 105 |
|
|
RealType m2 = getM(atomType2); |
| 106 |
|
|
return 0.5 * (m1 + m2); |
| 107 |
|
|
} |
| 108 |
|
|
|
| 109 |
|
|
RealType SC::getN(AtomType* atomType) { |
| 110 |
|
|
SCParam scParam = getSCParam(atomType); |
| 111 |
|
|
return scParam.n; |
| 112 |
|
|
} |
| 113 |
|
|
|
| 114 |
|
|
RealType SC::getN(AtomType* atomType1, AtomType* atomType2) { |
| 115 |
|
|
RealType n1 = getN(atomType1); |
| 116 |
|
|
RealType n2 = getN(atomType2); |
| 117 |
|
|
return 0.5 * (n1 + n2); |
| 118 |
|
|
} |
| 119 |
|
|
|
| 120 |
|
|
RealType SC::getAlpha(AtomType* atomType) { |
| 121 |
|
|
SCParam scParam = getSCParam(atomType); |
| 122 |
|
|
return scParam.alpha; |
| 123 |
|
|
} |
| 124 |
|
|
|
| 125 |
|
|
RealType SC::getAlpha(AtomType* atomType1, AtomType* atomType2) { |
| 126 |
|
|
RealType alpha1 = getAlpha(atomType1); |
| 127 |
|
|
RealType alpha2 = getAlpha(atomType2); |
| 128 |
|
|
|
| 129 |
|
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
| 130 |
|
|
std::string DistanceMix = fopts.getDistanceMixingRule(); |
| 131 |
|
|
toUpper(DistanceMix); |
| 132 |
|
|
|
| 133 |
|
|
if (DistanceMix == "GEOMETRIC") |
| 134 |
|
|
return sqrt(alpha1 * alpha2); |
| 135 |
|
|
else |
| 136 |
|
|
return 0.5 * (alpha1 + alpha2); |
| 137 |
|
|
} |
| 138 |
|
|
|
| 139 |
|
|
RealType SC::getEpsilon(AtomType* atomType) { |
| 140 |
|
|
SCParam scParam = getSCParam(atomType); |
| 141 |
|
|
return scParam.epsilon; |
| 142 |
|
|
} |
| 143 |
|
|
|
| 144 |
|
|
RealType SC::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
| 145 |
|
|
RealType epsilon1 = getEpsilon(atomType1); |
| 146 |
|
|
RealType epsilon2 = getEpsilon(atomType2); |
| 147 |
|
|
return sqrt(epsilon1 * epsilon2); |
| 148 |
|
|
} |
| 149 |
|
|
|
| 150 |
|
|
void SC::initialize() { |
| 151 |
|
|
// find all of the SC atom Types: |
| 152 |
|
|
ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes(); |
| 153 |
|
|
ForceField::AtomTypeContainer::MapTypeIterator i; |
| 154 |
|
|
AtomType* at; |
| 155 |
|
|
|
| 156 |
|
|
for (at = atomTypes->beginType(i); at != NULL; |
| 157 |
|
|
at = atomTypes->nextType(i)) { |
| 158 |
|
|
if (at->isSC()) |
| 159 |
|
|
addType(at); |
| 160 |
|
|
} |
| 161 |
|
|
initialized_ = true; |
| 162 |
|
|
} |
| 163 |
|
|
|
| 164 |
|
|
|
| 165 |
|
|
|
| 166 |
|
|
void SC::addType(AtomType* atomType){ |
| 167 |
|
|
|
| 168 |
|
|
SCAtomData scAtomData; |
| 169 |
|
|
|
| 170 |
|
|
scAtomData.c = getC(atomType); |
| 171 |
|
|
scAtomData.m = getM(atomType); |
| 172 |
|
|
scAtomData.n = getN(atomType); |
| 173 |
|
|
scAtomData.alpha = getAlpha(atomType); |
| 174 |
|
|
scAtomData.epsilon = getEpsilon(atomType); |
| 175 |
|
|
scAtomData.rCut = 2.0 * scAtomData.alpha; |
| 176 |
|
|
|
| 177 |
|
|
// add it to the map: |
| 178 |
|
|
AtomTypeProperties atp = atomType->getATP(); |
| 179 |
|
|
|
| 180 |
|
|
pair<map<int,AtomType*>::iterator,bool> ret; |
| 181 |
|
|
ret = SClist.insert( pair<int, AtomType*>(atp.ident, atomType) ); |
| 182 |
|
|
if (ret.second == false) { |
| 183 |
|
|
sprintf( painCave.errMsg, |
| 184 |
|
|
"SC already had a previous entry with ident %d\n", |
| 185 |
|
|
atp.ident); |
| 186 |
|
|
painCave.severity = OPENMD_INFO; |
| 187 |
|
|
painCave.isFatal = 0; |
| 188 |
|
|
simError(); |
| 189 |
|
|
} |
| 190 |
|
|
|
| 191 |
|
|
SCMap[atomType] = scAtomData; |
| 192 |
|
|
|
| 193 |
|
|
// Now, iterate over all known types and add to the mixing map: |
| 194 |
|
|
|
| 195 |
|
|
map<AtomType*, SCAtomData>::iterator it; |
| 196 |
|
|
for( it = SCMap.begin(); it != SCMap.end(); ++it) { |
| 197 |
|
|
|
| 198 |
|
|
AtomType* atype2 = (*it).first; |
| 199 |
|
|
|
| 200 |
|
|
SCInteractionData mixer; |
| 201 |
|
|
|
| 202 |
|
|
mixer.alpha = getAlpha(atomType, atype2); |
| 203 |
|
|
mixer.rCut = 2.0 * mixer.alpha; |
| 204 |
|
|
mixer.epsilon = getEpsilon(atomType, atype2); |
| 205 |
|
|
mixer.m = getM(atomType, atype2); |
| 206 |
|
|
mixer.n = getN(atomType, atype2); |
| 207 |
|
|
|
| 208 |
|
|
RealType dr = mixer.rCut / (np_ - 1); |
| 209 |
|
|
vector<RealType> rvals; |
| 210 |
|
|
vector<RealType> vvals; |
| 211 |
|
|
vector<RealType> phivals; |
| 212 |
|
|
|
| 213 |
|
|
rvals.push_back(0.0); |
| 214 |
|
|
vvals.push_back(0.0); |
| 215 |
|
|
phivals.push_back(0.0); |
| 216 |
|
|
|
| 217 |
|
|
for (int k = 1; k < np_; k++) { |
| 218 |
|
|
RealType r = dr * k; |
| 219 |
|
|
rvals.push_back(r); |
| 220 |
|
|
vvals.push_back( mixer.epsilon * pow(mixer.alpha/r, mixer.n) ); |
| 221 |
|
|
phivals.push_back( pow(mixer.alpha/r, mixer.m) ); |
| 222 |
|
|
} |
| 223 |
|
|
|
| 224 |
|
|
mixer.vCut = mixer.epsilon * pow(mixer.alpha/mixer.rCut, mixer.n); |
| 225 |
|
|
|
| 226 |
|
|
CubicSpline* V = new CubicSpline(); |
| 227 |
|
|
V->addPoints(rvals, vvals); |
| 228 |
|
|
|
| 229 |
|
|
CubicSpline* phi = new CubicSpline(); |
| 230 |
|
|
phi->addPoints(rvals, phivals); |
| 231 |
|
|
|
| 232 |
|
|
mixer.V = V; |
| 233 |
|
|
mixer.phi = phi; |
| 234 |
|
|
|
| 235 |
|
|
mixer.explicitlySet = false; |
| 236 |
|
|
|
| 237 |
|
|
pair<AtomType*, AtomType*> key1, key2; |
| 238 |
|
|
key1 = make_pair(atomType, atype2); |
| 239 |
|
|
key2 = make_pair(atype2, atomType); |
| 240 |
|
|
|
| 241 |
|
|
MixingMap[key1] = mixer; |
| 242 |
|
|
if (key2 != key1) { |
| 243 |
|
|
MixingMap[key2] = mixer; |
| 244 |
|
|
} |
| 245 |
|
|
} |
| 246 |
|
|
return; |
| 247 |
|
|
} |
| 248 |
|
|
|
| 249 |
|
|
void SC::addExplicitInteraction(AtomType* atype1, AtomType* atype2, |
| 250 |
|
|
RealType epsilon, RealType m, RealType n, |
| 251 |
|
|
RealType alpha) { |
| 252 |
|
|
|
| 253 |
|
|
// in case these weren't already in the map |
| 254 |
|
|
addType(atype1); |
| 255 |
|
|
addType(atype2); |
| 256 |
|
|
|
| 257 |
|
|
SCInteractionData mixer; |
| 258 |
|
|
|
| 259 |
|
|
mixer.epsilon = epsilon; |
| 260 |
|
|
mixer.m = m; |
| 261 |
|
|
mixer.n = n; |
| 262 |
|
|
mixer.alpha = alpha; |
| 263 |
|
|
mixer.rCut = 2.0 * mixer.alpha; |
| 264 |
|
|
|
| 265 |
|
|
RealType dr = mixer.rCut / (np_ - 1); |
| 266 |
|
|
vector<RealType> rvals; |
| 267 |
|
|
vector<RealType> vvals; |
| 268 |
|
|
vector<RealType> phivals; |
| 269 |
|
|
|
| 270 |
|
|
rvals.push_back(0.0); |
| 271 |
|
|
vvals.push_back(0.0); |
| 272 |
|
|
phivals.push_back(0.0); |
| 273 |
|
|
|
| 274 |
|
|
for (int k = 1; k < np_; k++) { |
| 275 |
|
|
RealType r = dr * k; |
| 276 |
|
|
rvals.push_back(r); |
| 277 |
|
|
vvals.push_back( mixer.epsilon * pow(mixer.alpha/r, mixer.n) ); |
| 278 |
|
|
phivals.push_back( pow(mixer.alpha/r, mixer.m) ); |
| 279 |
|
|
} |
| 280 |
|
|
|
| 281 |
|
|
mixer.vCut = mixer.epsilon * pow(mixer.alpha/mixer.rCut, mixer.n); |
| 282 |
|
|
|
| 283 |
|
|
CubicSpline* V = new CubicSpline(); |
| 284 |
|
|
V->addPoints(rvals, vvals); |
| 285 |
|
|
|
| 286 |
|
|
CubicSpline* phi = new CubicSpline(); |
| 287 |
|
|
phi->addPoints(rvals, phivals); |
| 288 |
|
|
|
| 289 |
|
|
mixer.V = V; |
| 290 |
|
|
mixer.phi = phi; |
| 291 |
|
|
|
| 292 |
|
|
mixer.explicitlySet = true; |
| 293 |
|
|
|
| 294 |
|
|
pair<AtomType*, AtomType*> key1, key2; |
| 295 |
|
|
key1 = make_pair(atype1, atype2); |
| 296 |
|
|
key2 = make_pair(atype2, atype1); |
| 297 |
|
|
|
| 298 |
|
|
MixingMap[key1] = mixer; |
| 299 |
|
|
if (key2 != key1) { |
| 300 |
|
|
MixingMap[key2] = mixer; |
| 301 |
|
|
} |
| 302 |
|
|
return; |
| 303 |
|
|
} |
| 304 |
|
|
|
| 305 |
gezelter |
1545 |
void SC::calcDensity(InteractionData &idat) { |
| 306 |
gezelter |
1489 |
|
| 307 |
|
|
if (!initialized_) initialize(); |
| 308 |
|
|
|
| 309 |
gezelter |
1571 |
SCInteractionData mixer = MixingMap[ idat.atypes ]; |
| 310 |
gezelter |
1489 |
|
| 311 |
gezelter |
1502 |
RealType rcij = mixer.rCut; |
| 312 |
gezelter |
1489 |
|
| 313 |
gezelter |
1554 |
if ( *(idat.rij) < rcij) { |
| 314 |
gezelter |
1575 |
RealType rho = mixer.phi->getValueAt( *(idat.rij) ); |
| 315 |
|
|
*(idat.rho1) += rho; |
| 316 |
|
|
*(idat.rho2) += rho; |
| 317 |
|
|
} |
| 318 |
gezelter |
1554 |
|
| 319 |
gezelter |
1489 |
return; |
| 320 |
|
|
} |
| 321 |
|
|
|
| 322 |
gezelter |
1545 |
void SC::calcFunctional(SelfData &sdat) { |
| 323 |
gezelter |
1489 |
|
| 324 |
|
|
if (!initialized_) initialize(); |
| 325 |
|
|
|
| 326 |
gezelter |
1545 |
SCAtomData data1 = SCMap[sdat.atype]; |
| 327 |
gezelter |
1575 |
|
| 328 |
|
|
RealType u = - data1.c * data1.epsilon * sqrt( *(sdat.rho) ); |
| 329 |
|
|
*(sdat.frho) = u; |
| 330 |
gezelter |
1554 |
*(sdat.dfrhodrho) = 0.5 * *(sdat.frho) / *(sdat.rho); |
| 331 |
gezelter |
1575 |
|
| 332 |
gezelter |
1583 |
(*(sdat.pot))[METALLIC_FAMILY] += u; |
| 333 |
gezelter |
1575 |
*(sdat.particlePot) += u; |
| 334 |
gezelter |
1489 |
|
| 335 |
|
|
return; |
| 336 |
|
|
} |
| 337 |
gezelter |
1502 |
|
| 338 |
gezelter |
1489 |
|
| 339 |
gezelter |
1536 |
void SC::calcForce(InteractionData &idat) { |
| 340 |
gezelter |
1489 |
|
| 341 |
|
|
if (!initialized_) initialize(); |
| 342 |
|
|
|
| 343 |
gezelter |
1571 |
SCAtomData data1 = SCMap[idat.atypes.first]; |
| 344 |
|
|
SCAtomData data2 = SCMap[idat.atypes.second]; |
| 345 |
gezelter |
1489 |
|
| 346 |
gezelter |
1571 |
SCInteractionData mixer = MixingMap[idat.atypes]; |
| 347 |
gezelter |
1489 |
|
| 348 |
|
|
RealType rcij = mixer.rCut; |
| 349 |
|
|
|
| 350 |
gezelter |
1554 |
if ( *(idat.rij) < rcij) { |
| 351 |
gezelter |
1502 |
RealType vcij = mixer.vCut; |
| 352 |
|
|
|
| 353 |
|
|
pair<RealType, RealType> res; |
| 354 |
|
|
|
| 355 |
gezelter |
1554 |
res = mixer.phi->getValueAndDerivativeAt( *(idat.rij) ); |
| 356 |
gezelter |
1502 |
RealType rhtmp = res.first; |
| 357 |
|
|
RealType drhodr = res.second; |
| 358 |
|
|
|
| 359 |
gezelter |
1554 |
res = mixer.V->getValueAndDerivativeAt( *(idat.rij) ); |
| 360 |
gezelter |
1502 |
RealType vptmp = res.first; |
| 361 |
|
|
RealType dvpdr = res.second; |
| 362 |
|
|
|
| 363 |
|
|
RealType pot_temp = vptmp - vcij; |
| 364 |
gezelter |
1554 |
*(idat.vpair) += pot_temp; |
| 365 |
gezelter |
1502 |
|
| 366 |
gezelter |
1554 |
RealType dudr = drhodr * ( *(idat.dfrho1) + *(idat.dfrho2) ) + dvpdr; |
| 367 |
gezelter |
1502 |
|
| 368 |
gezelter |
1554 |
*(idat.f1) += *(idat.d) * dudr / *(idat.rij) ; |
| 369 |
gezelter |
1489 |
|
| 370 |
gezelter |
1575 |
// particlePot is the difference between the full potential and |
| 371 |
|
|
// the full potential without the presence of a particular |
| 372 |
gezelter |
1502 |
// particle (atom1). |
| 373 |
|
|
// |
| 374 |
gezelter |
1575 |
// This reduces the density at other particle locations, so we |
| 375 |
|
|
// need to recompute the density at atom2 assuming atom1 didn't |
| 376 |
|
|
// contribute. This then requires recomputing the density |
| 377 |
|
|
// functional for atom2 as well. |
| 378 |
|
|
|
| 379 |
|
|
*(idat.particlePot1) -= data2.c * data2.epsilon * |
| 380 |
|
|
sqrt( *(idat.rho2) - rhtmp) + *(idat.frho2); |
| 381 |
|
|
|
| 382 |
gezelter |
1586 |
*(idat.particlePot2) -= data1.c * data1.epsilon * |
| 383 |
gezelter |
1575 |
sqrt( *(idat.rho1) - rhtmp) + *(idat.frho1); |
| 384 |
gezelter |
1489 |
|
| 385 |
gezelter |
1582 |
(*(idat.pot))[METALLIC_FAMILY] += pot_temp; |
| 386 |
gezelter |
1502 |
} |
| 387 |
|
|
|
| 388 |
gezelter |
1489 |
return; |
| 389 |
|
|
} |
| 390 |
gezelter |
1505 |
|
| 391 |
gezelter |
1545 |
RealType SC::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
| 392 |
gezelter |
1505 |
if (!initialized_) initialize(); |
| 393 |
gezelter |
1545 |
|
| 394 |
gezelter |
1505 |
map<pair<AtomType*, AtomType*>, SCInteractionData>::iterator it; |
| 395 |
gezelter |
1545 |
it = MixingMap.find(atypes); |
| 396 |
gezelter |
1505 |
if (it == MixingMap.end()) |
| 397 |
|
|
return 0.0; |
| 398 |
|
|
else { |
| 399 |
|
|
SCInteractionData mixer = (*it).second; |
| 400 |
|
|
return mixer.rCut; |
| 401 |
|
|
} |
| 402 |
|
|
} |
| 403 |
gezelter |
1489 |
} |