--- branches/development/src/nonbonded/LJ.cpp 2010/10/02 19:53:32 1502 +++ branches/development/src/nonbonded/LJ.cpp 2012/02/29 20:33:01 1683 @@ -36,7 +36,8 @@ * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include @@ -45,11 +46,11 @@ #include #include "nonbonded/LJ.hpp" #include "utils/simError.h" +#include "types/LennardJonesInteractionType.hpp" namespace OpenMD { - LJ::LJ() : name_("LJ"), initialized_(false), shiftedPot_(false), - shiftedFrc_(false), forceField_(NULL) {} + LJ::LJ() : name_("LJ"), initialized_(false), forceField_(NULL) {} LJParam LJ::getLJParam(AtomType* atomType) { @@ -124,51 +125,40 @@ namespace OpenMD { for (at = atomTypes->beginType(i); at != NULL; at = atomTypes->nextType(i)) { - - if (at->isLennardJones()) - addType(at); + if (at->isLennardJones()){ + addType(at); + } } - ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes(); ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j; NonBondedInteractionType* nbt; + ForceField::NonBondedInteractionTypeContainer::KeyType keys; + for (nbt = nbiTypes->beginType(j); nbt != NULL; nbt = nbiTypes->nextType(j)) { - + if (nbt->isLennardJones()) { - - pair atypes = nbt->getAtomTypes(); - - GenericData* data = nbt->getPropertyByName("LennardJones"); - if (data == NULL) { - sprintf( painCave.errMsg, "LJ::rebuildMixingMap could not find\n" - "\tLennard-Jones parameters for %s - %s interaction.\n", - atypes.first->getName().c_str(), - atypes.second->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - LJParamGenericData* ljData = dynamic_cast(data); - if (ljData == NULL) { + keys = nbiTypes->getKeys(j); + AtomType* at1 = forceField_->getAtomType(keys[0]); + AtomType* at2 = forceField_->getAtomType(keys[1]); + + LennardJonesInteractionType* ljit = dynamic_cast(nbt); + + if (ljit == NULL) { sprintf( painCave.errMsg, - "LJ::rebuildMixingMap could not convert GenericData to\n" - "\tLJParam for %s - %s interaction.\n", - atypes.first->getName().c_str(), - atypes.second->getName().c_str()); + "LJ::initialize could not convert NonBondedInteractionType\n" + "\tto LennardJonesInteractionType for %s - %s interaction.\n", + at1->getName().c_str(), + at2->getName().c_str()); painCave.severity = OPENMD_ERROR; painCave.isFatal = 1; simError(); } - - LJParam ljParam = ljData->getData(); - RealType sigma = ljParam.sigma; - RealType epsilon = ljParam.epsilon; - - addExplicitInteraction(atypes.first, atypes.second, sigma, epsilon); + RealType sigma = ljit->getSigma(); + RealType epsilon = ljit->getEpsilon(); + addExplicitInteraction(at1, at2, sigma, epsilon); } } initialized_ = true; @@ -220,10 +210,6 @@ namespace OpenMD { void LJ::addExplicitInteraction(AtomType* atype1, AtomType* atype2, RealType sigma, RealType epsilon){ - // in case these weren't already in the map - addType(atype1); - addType(atype2); - LJInteractionData mixer; mixer.sigma = sigma; mixer.epsilon = epsilon; @@ -240,53 +226,52 @@ namespace OpenMD { } } - void LJ::calcForce(InteractionData idat) { - + void LJ::calcForce(InteractionData &idat) { if (!initialized_) initialize(); - - RealType ros; - RealType rcos; - RealType myPot = 0.0; - RealType myPotC = 0.0; - RealType myDeriv = 0.0; - RealType myDerivC = 0.0; - - std::pair key = std::make_pair(idat.atype1, - idat.atype2); - LJInteractionData mixer = MixingMap[key]; - - RealType sigmai = mixer.sigmai; - RealType epsilon = mixer.epsilon; + map, LJInteractionData>::iterator it; + it = MixingMap.find( idat.atypes ); + if (it != MixingMap.end()) { + + LJInteractionData mixer = (*it).second; + + RealType sigmai = mixer.sigmai; + RealType epsilon = mixer.epsilon; + + RealType ros; + RealType rcos; + RealType myPot = 0.0; + RealType myPotC = 0.0; + RealType myDeriv = 0.0; + RealType myDerivC = 0.0; + + ros = *(idat.rij) * sigmai; + + getLJfunc(ros, myPot, myDeriv); + + if (idat.shiftedPot) { + rcos = *(idat.rcut) * sigmai; + getLJfunc(rcos, myPotC, myDerivC); + myDerivC = 0.0; + } else if (idat.shiftedForce) { + rcos = *(idat.rcut) * sigmai; + getLJfunc(rcos, myPotC, myDerivC); + myPotC = myPotC + myDerivC * (*(idat.rij) - *(idat.rcut)) * sigmai; + } else { + myPotC = 0.0; + myDerivC = 0.0; + } - ros = idat.rij * sigmai; + RealType pot_temp = *(idat.vdwMult) * epsilon * (myPot - myPotC); + *(idat.vpair) += pot_temp; + + RealType dudr = *(idat.sw) * *(idat.vdwMult) * epsilon * (myDeriv - + myDerivC)*sigmai; - getLJfunc(ros, myPot, myDeriv); - - if (shiftedPot_) { - rcos = idat.rcut * sigmai; - getLJfunc(rcos, myPotC, myDerivC); - myDerivC = 0.0; - } else if (LJ::shiftedFrc_) { - rcos = idat.rcut * sigmai; - getLJfunc(rcos, myPotC, myDerivC); - myPotC = myPotC + myDerivC * (idat.rij - idat.rcut) * sigmai; - } else { - myPotC = 0.0; - myDerivC = 0.0; + (*(idat.pot))[VANDERWAALS_FAMILY] += *(idat.sw) * pot_temp; + *(idat.f1) += *(idat.d) * dudr / *(idat.rij); } - - RealType pot_temp = idat.vdwMult * epsilon * (myPot - myPotC); - idat.vpair += pot_temp; - - RealType dudr = idat.sw * idat.vdwMult * epsilon * (myDeriv - - myDerivC)*sigmai; - - idat.pot += idat.sw * pot_temp; - idat.f1 = idat.d * dudr / idat.rij; - return; - } void LJ::getLJfunc(RealType r, RealType &pot, RealType &deriv) { @@ -304,5 +289,16 @@ namespace OpenMD { return; } + RealType LJ::getSuggestedCutoffRadius(pair atypes) { + if (!initialized_) initialize(); + map, LJInteractionData>::iterator it; + it = MixingMap.find(atypes); + if (it == MixingMap.end()) + return 0.0; + else { + LJInteractionData mixer = (*it).second; + return 2.5 * mixer.sigma; + } + } }