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). |
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> |
47 |
|
#include "nonbonded/LJ.hpp" |
48 |
|
#include "utils/simError.h" |
49 |
|
|
49 |
– |
|
50 |
|
namespace OpenMD { |
51 |
|
|
52 |
< |
bool LJ::initialized_ = false; |
53 |
< |
bool LJ::shiftedPot_ = false; |
54 |
< |
bool LJ::shiftedFrc_ = false; |
55 |
< |
ForceField* LJ::forceField_ = NULL; |
56 |
< |
std::map<int, AtomType*> LJ::LJMap; |
57 |
< |
std::map<std::pair<AtomType*, AtomType*>, LJInteractionData> LJ::MixingMap; |
58 |
< |
|
59 |
< |
LJ* LJ::_instance = NULL; |
52 |
> |
LJ::LJ() : name_("LJ"), initialized_(false), forceField_(NULL) {} |
53 |
|
|
61 |
– |
LJ* LJ::Instance() { |
62 |
– |
if (!_instance) { |
63 |
– |
_instance = new LJ(); |
64 |
– |
} |
65 |
– |
return _instance; |
66 |
– |
} |
67 |
– |
|
54 |
|
LJParam LJ::getLJParam(AtomType* atomType) { |
55 |
|
|
56 |
|
// Do sanity checking on the AtomType we were passed before |
92 |
|
return ljParam.sigma; |
93 |
|
} |
94 |
|
|
109 |
– |
RealType LJ::getSigma(int atid) { |
110 |
– |
if (!initialized_) initialize(); |
111 |
– |
std::map<int, AtomType*> :: const_iterator it; |
112 |
– |
it = LJMap.find(atid); |
113 |
– |
if (it == LJMap.end()) { |
114 |
– |
sprintf( painCave.errMsg, |
115 |
– |
"LJ::getSigma could not find atid %d in LJMap\n", |
116 |
– |
(atid)); |
117 |
– |
painCave.severity = OPENMD_ERROR; |
118 |
– |
painCave.isFatal = 1; |
119 |
– |
simError(); |
120 |
– |
} |
121 |
– |
AtomType* atype = it->second; |
122 |
– |
|
123 |
– |
return getSigma(atype); |
124 |
– |
} |
125 |
– |
|
95 |
|
RealType LJ::getSigma(AtomType* atomType1, AtomType* atomType2) { |
96 |
|
RealType sigma1 = getSigma(atomType1); |
97 |
|
RealType sigma2 = getSigma(atomType2); |
98 |
|
|
99 |
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
100 |
< |
std::string DistanceMix = fopts.getDistanceMixingRule(); |
100 |
> |
string DistanceMix = fopts.getDistanceMixingRule(); |
101 |
|
toUpper(DistanceMix); |
102 |
|
|
103 |
|
if (DistanceMix == "GEOMETRIC") |
111 |
|
return ljParam.epsilon; |
112 |
|
} |
113 |
|
|
145 |
– |
RealType LJ::getEpsilon(int atid) { |
146 |
– |
if (!initialized_) initialize(); |
147 |
– |
std::map<int, AtomType*> :: const_iterator it; |
148 |
– |
it = LJMap.find(atid); |
149 |
– |
if (it == LJMap.end()) { |
150 |
– |
sprintf( painCave.errMsg, |
151 |
– |
"LJ::getEpsilon could not find atid %d in LJMap\n", |
152 |
– |
(atid)); |
153 |
– |
painCave.severity = OPENMD_ERROR; |
154 |
– |
painCave.isFatal = 1; |
155 |
– |
simError(); |
156 |
– |
} |
157 |
– |
AtomType* atype = it->second; |
158 |
– |
|
159 |
– |
return getEpsilon(atype); |
160 |
– |
} |
161 |
– |
|
114 |
|
RealType LJ::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
115 |
|
RealType epsilon1 = getEpsilon(atomType1); |
116 |
|
RealType epsilon2 = getEpsilon(atomType2); |
118 |
|
} |
119 |
|
|
120 |
|
void LJ::initialize() { |
121 |
< |
ForceField::AtomTypeContainer atomTypes = forceField_->getAtomTypes(); |
121 |
> |
ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes(); |
122 |
|
ForceField::AtomTypeContainer::MapTypeIterator i; |
123 |
|
AtomType* at; |
124 |
|
|
125 |
< |
for (at = atomTypes.beginType(i); at != NULL; |
126 |
< |
at = atomTypes.nextType(i)) { |
125 |
> |
for (at = atomTypes->beginType(i); at != NULL; |
126 |
> |
at = atomTypes->nextType(i)) { |
127 |
|
|
128 |
|
if (at->isLennardJones()) |
129 |
|
addType(at); |
130 |
|
} |
131 |
|
|
132 |
< |
ForceField::NonBondedInteractionTypeContainer nbiTypes = forceField_->getNonBondedInteractionTypes(); |
132 |
> |
ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes(); |
133 |
|
ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j; |
134 |
|
NonBondedInteractionType* nbt; |
135 |
|
|
136 |
< |
for (nbt = nbiTypes.beginType(j); nbt != NULL; |
137 |
< |
nbt = nbiTypes.nextType(j)) { |
136 |
> |
for (nbt = nbiTypes->beginType(j); nbt != NULL; |
137 |
> |
nbt = nbiTypes->nextType(j)) { |
138 |
|
|
139 |
|
if (nbt->isLennardJones()) { |
140 |
|
|
141 |
< |
std::pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes(); |
141 |
> |
pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes(); |
142 |
|
|
143 |
|
GenericData* data = nbt->getPropertyByName("LennardJones"); |
144 |
|
if (data == NULL) { |
179 |
|
void LJ::addType(AtomType* atomType){ |
180 |
|
RealType sigma1 = getSigma(atomType); |
181 |
|
RealType epsilon1 = getEpsilon(atomType); |
182 |
< |
|
182 |
> |
|
183 |
|
// add it to the map: |
184 |
|
AtomTypeProperties atp = atomType->getATP(); |
185 |
|
|
186 |
< |
std::pair<std::map<int,AtomType*>::iterator,bool> ret; |
187 |
< |
ret = LJMap.insert( std::pair<int, AtomType*>(atp.ident, atomType) ); |
186 |
> |
pair<map<int,AtomType*>::iterator,bool> ret; |
187 |
> |
ret = LJMap.insert( pair<int, AtomType*>(atp.ident, atomType) ); |
188 |
|
if (ret.second == false) { |
189 |
|
sprintf( painCave.errMsg, |
190 |
|
"LJ already had a previous entry with ident %d\n", |
240 |
|
} |
241 |
|
} |
242 |
|
|
243 |
< |
void LJ::calcForce(AtomType* at1, AtomType* at2, Vector3d d, |
292 |
< |
RealType rij, RealType r2, RealType rcut, RealType sw, |
293 |
< |
RealType vdwMult, RealType &vpair, RealType &pot, |
294 |
< |
Vector3d &f1) { |
295 |
< |
|
296 |
< |
if (!initialized_) initialize(); |
243 |
> |
void LJ::calcForce(InteractionData &idat) { |
244 |
|
|
245 |
< |
RealType ros; |
299 |
< |
RealType rcos; |
300 |
< |
RealType myPot = 0.0; |
301 |
< |
RealType myPotC = 0.0; |
302 |
< |
RealType myDeriv = 0.0; |
303 |
< |
RealType myDerivC = 0.0; |
245 |
> |
if (!initialized_) initialize(); |
246 |
|
|
247 |
< |
std::pair<AtomType*, AtomType*> key = std::make_pair(at1, at2); |
248 |
< |
LJInteractionData mixer = MixingMap[key]; |
307 |
< |
|
308 |
< |
RealType sigmai = mixer.sigmai; |
309 |
< |
RealType epsilon = mixer.epsilon; |
247 |
> |
map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it; |
248 |
> |
it = MixingMap.find( idat.atypes ); |
249 |
|
|
250 |
< |
|
251 |
< |
ros = rij * sigmai; |
252 |
< |
|
253 |
< |
getLJfunc(ros, myPot, myDeriv); |
250 |
> |
if (it != MixingMap.end()) { |
251 |
> |
|
252 |
> |
LJInteractionData mixer = (*it).second; |
253 |
> |
|
254 |
> |
RealType sigmai = mixer.sigmai; |
255 |
> |
RealType epsilon = mixer.epsilon; |
256 |
> |
|
257 |
> |
RealType ros; |
258 |
> |
RealType rcos; |
259 |
> |
RealType myPot = 0.0; |
260 |
> |
RealType myPotC = 0.0; |
261 |
> |
RealType myDeriv = 0.0; |
262 |
> |
RealType myDerivC = 0.0; |
263 |
> |
|
264 |
> |
ros = *(idat.rij) * sigmai; |
265 |
> |
|
266 |
> |
getLJfunc(ros, myPot, myDeriv); |
267 |
> |
|
268 |
> |
if (idat.shiftedPot) { |
269 |
> |
rcos = *(idat.rcut) * sigmai; |
270 |
> |
getLJfunc(rcos, myPotC, myDerivC); |
271 |
> |
myDerivC = 0.0; |
272 |
> |
} else if (idat.shiftedForce) { |
273 |
> |
rcos = *(idat.rcut) * sigmai; |
274 |
> |
getLJfunc(rcos, myPotC, myDerivC); |
275 |
> |
myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai; |
276 |
> |
} else { |
277 |
> |
myPotC = 0.0; |
278 |
> |
myDerivC = 0.0; |
279 |
> |
} |
280 |
|
|
281 |
< |
if (shiftedPot_) { |
282 |
< |
rcos = rcut * sigmai; |
283 |
< |
getLJfunc(rcos, myPotC, myDerivC); |
284 |
< |
myDerivC = 0.0; |
285 |
< |
} else if (LJ::shiftedFrc_) { |
321 |
< |
rcos = rcut * sigmai; |
322 |
< |
getLJfunc(rcos, myPotC, myDerivC); |
323 |
< |
myPotC = myPotC + myDerivC * (rij - rcut) * sigmai; |
324 |
< |
} else { |
325 |
< |
myPotC = 0.0; |
326 |
< |
myDerivC = 0.0; |
327 |
< |
} |
281 |
> |
RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC); |
282 |
> |
*(idat.vpair) += pot_temp; |
283 |
> |
|
284 |
> |
RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv - |
285 |
> |
myDerivC)*sigmai; |
286 |
|
|
287 |
< |
RealType pot_temp = vdwMult * epsilon * (myPot - myPotC); |
288 |
< |
vpair += pot_temp; |
289 |
< |
|
332 |
< |
RealType dudr = sw * vdwMult * epsilon * (myDeriv - myDerivC)*sigmai; |
333 |
< |
|
334 |
< |
pot += sw * pot_temp; |
335 |
< |
f1 = d * dudr / rij; |
336 |
< |
|
287 |
> |
(*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp; |
288 |
> |
*(idat.f1) += *(idat.d) * dudr / *(idat.rij); |
289 |
> |
} |
290 |
|
return; |
338 |
– |
|
339 |
– |
|
340 |
– |
|
291 |
|
} |
342 |
– |
|
343 |
– |
void LJ::do_lj_pair(int *atid1, int *atid2, RealType *d, RealType *rij, |
344 |
– |
RealType *r2, RealType *rcut, RealType *sw, |
345 |
– |
RealType *vdwMult, |
346 |
– |
RealType *vpair, RealType *pot, RealType *f1) { |
347 |
– |
|
348 |
– |
if (!initialized_) initialize(); |
349 |
– |
|
350 |
– |
AtomType* atype1 = LJMap[*atid1]; |
351 |
– |
AtomType* atype2 = LJMap[*atid2]; |
352 |
– |
|
353 |
– |
Vector3d disp(d[0], d[1], d[2]); |
354 |
– |
Vector3d frc(f1[0], f1[1], f1[2]); |
355 |
– |
|
356 |
– |
calcForce(atype1, atype2, disp, *rij, *r2, *rcut, *sw, *vdwMult, *vpair, |
357 |
– |
*pot, frc); |
358 |
– |
|
359 |
– |
f1[0] = frc.x(); |
360 |
– |
f1[1] = frc.y(); |
361 |
– |
f1[2] = frc.z(); |
362 |
– |
|
363 |
– |
return; |
364 |
– |
} |
292 |
|
|
293 |
|
void LJ::getLJfunc(RealType r, RealType &pot, RealType &deriv) { |
294 |
|
|
305 |
|
return; |
306 |
|
} |
307 |
|
|
308 |
< |
|
309 |
< |
void LJ::setLJDefaultCutoff(RealType *thisRcut, int *sP, int *sF) { |
310 |
< |
shiftedPot_ = (bool)(*sP); |
311 |
< |
shiftedFrc_ = (bool)(*sF); |
308 |
> |
RealType LJ::getSuggestedCutoffRadius(pair<AtomType*, AtomType*> atypes) { |
309 |
> |
if (!initialized_) initialize(); |
310 |
> |
map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it; |
311 |
> |
it = MixingMap.find(atypes); |
312 |
> |
if (it == MixingMap.end()) |
313 |
> |
return 0.0; |
314 |
> |
else { |
315 |
> |
LJInteractionData mixer = (*it).second; |
316 |
> |
return 2.5 * mixer.sigma; |
317 |
> |
} |
318 |
|
} |
386 |
– |
} |
319 |
|
|
388 |
– |
extern "C" { |
389 |
– |
|
390 |
– |
#define fortranGetSigma FC_FUNC(getsigma, GETSIGMA) |
391 |
– |
#define fortranGetEpsilon FC_FUNC(getepsilon, GETEPSILON) |
392 |
– |
#define fortranSetLJCutoff FC_FUNC(setljdefaultcutoff, SETLJDEFAULTCUTOFF) |
393 |
– |
#define fortranDoLJPair FC_FUNC(do_lj_pair, DO_LJ_PAIR) |
394 |
– |
|
395 |
– |
RealType fortranGetSigma(int* atid) { |
396 |
– |
return OpenMD::LJ::Instance()->getSigma(*atid); |
397 |
– |
} |
398 |
– |
RealType fortranGetEpsilon(int* atid) { |
399 |
– |
return OpenMD::LJ::Instance()->getEpsilon(*atid); |
400 |
– |
} |
401 |
– |
void fortranSetLJCutoff(RealType *rcut, int *shiftedPot, int *shiftedFrc) { |
402 |
– |
return OpenMD::LJ::Instance()->setLJDefaultCutoff(rcut, shiftedPot, |
403 |
– |
shiftedFrc); |
404 |
– |
} |
405 |
– |
void fortranDoLJPair(int *atid1, int *atid2, RealType *d, RealType *rij, |
406 |
– |
RealType *r2, RealType *rcut, RealType *sw, |
407 |
– |
RealType *vdwMult, RealType* vpair, RealType* pot, |
408 |
– |
RealType *f1){ |
409 |
– |
|
410 |
– |
return OpenMD::LJ::Instance()->do_lj_pair(atid1, atid2, d, rij, r2, rcut, |
411 |
– |
sw, vdwMult, vpair, pot, f1); |
412 |
– |
} |
320 |
|
} |