--- branches/development/src/nonbonded/LJ.cpp 2011/11/22 20:38:56 1665 +++ branches/development/src/nonbonded/LJ.cpp 2012/05/18 21:44:02 1710 @@ -46,55 +46,19 @@ #include #include "nonbonded/LJ.hpp" #include "utils/simError.h" +#include "types/LennardJonesAdapter.hpp" +#include "types/LennardJonesInteractionType.hpp" namespace OpenMD { LJ::LJ() : name_("LJ"), initialized_(false), forceField_(NULL) {} - LJParam LJ::getLJParam(AtomType* atomType) { - - // Do sanity checking on the AtomType we were passed before - // building any data structures: - if (!atomType->isLennardJones()) { - sprintf( painCave.errMsg, - "LJ::getLJParam was passed an atomType (%s) that does not\n" - "\tappear to be a Lennard-Jones atom.\n", - atomType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - GenericData* data = atomType->getPropertyByName("LennardJones"); - if (data == NULL) { - sprintf( painCave.errMsg, "LJ::getLJParam could not find Lennard-Jones\n" - "\tparameters for atomType %s.\n", atomType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - LJParamGenericData* ljData = dynamic_cast(data); - if (ljData == NULL) { - sprintf( painCave.errMsg, - "LJ::getLJParam could not convert GenericData to LJParam for\n" - "\tatom type %s\n", atomType->getName().c_str()); - painCave.severity = OPENMD_ERROR; - painCave.isFatal = 1; - simError(); - } - - return ljData->getData(); - } + RealType LJ::getSigma(AtomType* atomType1, AtomType* atomType2) { - RealType LJ::getSigma(AtomType* atomType) { - LJParam ljParam = getLJParam(atomType); - return ljParam.sigma; - } - - RealType LJ::getSigma(AtomType* atomType1, AtomType* atomType2) { - RealType sigma1 = getSigma(atomType1); - RealType sigma2 = getSigma(atomType2); + LennardJonesAdapter lja1 = LennardJonesAdapter(atomType1); + LennardJonesAdapter lja2 = LennardJonesAdapter(atomType2); + RealType sigma1 = lja1.getSigma(); + RealType sigma2 = lja2.getSigma(); ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); string DistanceMix = fopts.getDistanceMixingRule(); @@ -106,14 +70,12 @@ namespace OpenMD { return 0.5 * (sigma1 + sigma2); } - RealType LJ::getEpsilon(AtomType* atomType) { - LJParam ljParam = getLJParam(atomType); - return ljParam.epsilon; - } - - RealType LJ::getEpsilon(AtomType* atomType1, AtomType* atomType2) { - RealType epsilon1 = getEpsilon(atomType1); - RealType epsilon2 = getEpsilon(atomType2); + RealType LJ::getEpsilon(AtomType* atomType1, AtomType* atomType2) { + LennardJonesAdapter lja1 = LennardJonesAdapter(atomType1); + LennardJonesAdapter lja2 = LennardJonesAdapter(atomType2); + + RealType epsilon1 = lja1.getEpsilon(); + RealType epsilon2 = lja2.getEpsilon(); return sqrt(epsilon1 * epsilon2); } @@ -124,51 +86,41 @@ namespace OpenMD { for (at = atomTypes->beginType(i); at != NULL; at = atomTypes->nextType(i)) { - - if (at->isLennardJones()) - addType(at); + LennardJonesAdapter lja = LennardJonesAdapter(at); + if (lja.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; @@ -177,18 +129,19 @@ namespace OpenMD { void LJ::addType(AtomType* atomType){ - RealType sigma1 = getSigma(atomType); - RealType epsilon1 = getEpsilon(atomType); + LennardJonesAdapter lja1 = LennardJonesAdapter(atomType); + + RealType sigma1 = lja1.getSigma(); + RealType epsilon1 = lja1.getEpsilon(); // add it to the map: - AtomTypeProperties atp = atomType->getATP(); pair::iterator,bool> ret; - ret = LJMap.insert( pair(atp.ident, atomType) ); + ret = LJMap.insert( pair(atomType->getIdent(), atomType) ); if (ret.second == false) { sprintf( painCave.errMsg, "LJ already had a previous entry with ident %d\n", - atp.ident); + atomType->getIdent()); painCave.severity = OPENMD_INFO; painCave.isFatal = 0; simError(); @@ -220,10 +173,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; @@ -241,9 +190,7 @@ namespace OpenMD { } void LJ::calcForce(InteractionData &idat) { - if (!initialized_) initialize(); - map, LJInteractionData>::iterator it; it = MixingMap.find( idat.atypes );