--- trunk/src/UseTheForce/ForceField.cpp 2010/05/10 17:28:26 1442 +++ branches/development/src/UseTheForce/ForceField.cpp 2011/11/22 20:38:56 1665 @@ -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). */ /** @@ -51,34 +52,44 @@ #include "UseTheForce/ForceField.hpp" #include "utils/simError.h" #include "utils/Tuple.hpp" -#include "UseTheForce/DarkSide/atype_interface.h" -#include "UseTheForce/DarkSide/fForceOptions_interface.h" -#include "UseTheForce/DarkSide/switcheroo_interface.h" namespace OpenMD { ForceField::ForceField() { + char* tempPath; tempPath = getenv("FORCE_PARAM_PATH"); - + if (tempPath == NULL) { - ffPath_ = "ORNULL(FRC_PATH)"; + //convert a macro from compiler to a string in c++ + STR_DEFINE(ffPath_, FRC_PATH ); } else { ffPath_ = tempPath; } } - - ForceField::~ForceField() { - deleteAtypes(); - deleteSwitch(); - } - + /** + * getAtomType by string + * + * finds the requested atom type in this force field using the string + * name of the atom type. + */ AtomType* ForceField::getAtomType(const std::string &at) { std::vector keys; keys.push_back(at); return atomTypeCont_.find(keys); } + /** + * getAtomType by ident + * + * finds the requested atom type in this force field using the + * integer ident instead of the string name of the atom type. + */ + AtomType* ForceField::getAtomType(int ident) { + std::string at = atypeIdentToName.find(ident)->second; + return getAtomType(at); + } + BondType* ForceField::getBondType(const std::string &at1, const std::string &at2) { std::vector keys; @@ -438,6 +449,7 @@ namespace OpenMD { } NonBondedInteractionType* ForceField::getNonBondedInteractionType(const std::string &at1, const std::string &at2) { + std::vector keys; keys.push_back(at1); keys.push_back(at2); @@ -447,9 +459,63 @@ namespace OpenMD { if (nbiType) { return nbiType; } else { - //if no exact match found, try wild card match - return nonBondedInteractionTypeCont_.find(keys, wildCardAtomTypeName_); - } + AtomType* atype1; + AtomType* atype2; + std::vector at1key; + at1key.push_back(at1); + atype1 = atomTypeCont_.find(at1key); + + std::vector at2key; + at2key.push_back(at2); + atype2 = atomTypeCont_.find(at2key); + + // query atom types for their chains of responsibility + std::vector at1Chain = atype1->allYourBase(); + std::vector at2Chain = atype2->allYourBase(); + + std::vector::iterator i; + std::vector::iterator j; + + int ii = 0; + int jj = 0; + int nbiTypeScore; + + std::vector > > foundNBI; + + for (i = at1Chain.begin(); i != at1Chain.end(); i++) { + jj = 0; + for (j = at2Chain.begin(); j != at2Chain.end(); j++) { + + nbiTypeScore = ii + jj; + + std::vector myKeys; + myKeys.push_back((*i)->getName()); + myKeys.push_back((*j)->getName()); + + NonBondedInteractionType* nbiType = nonBondedInteractionTypeCont_.find(myKeys); + if (nbiType) { + foundNBI.push_back(std::make_pair(nbiTypeScore, myKeys)); + } + jj++; + } + ii++; + } + + + if (foundNBI.size() > 0) { + // sort the foundNBI by the score: + std::sort(foundNBI.begin(), foundNBI.end()); + + int bestScore = foundNBI[0].first; + std::vector theKeys = foundNBI[0].second; + + NonBondedInteractionType* bestType = nonBondedInteractionTypeCont_.find(theKeys); + return bestType; + } else { + //if no exact match found, try wild card match + return nonBondedInteractionTypeCont_.find(keys, wildCardAtomTypeName_); + } + } } BondType* ForceField::getExactBondType(const std::string &at1, @@ -505,12 +571,14 @@ namespace OpenMD { bool ForceField::addAtomType(const std::string &at, AtomType* atomType) { std::vector keys; keys.push_back(at); + atypeIdentToName[atomType->getIdent()] = at; return atomTypeCont_.add(keys, atomType); } bool ForceField::replaceAtomType(const std::string &at, AtomType* atomType) { std::vector keys; keys.push_back(at); + atypeIdentToName[atomType->getIdent()] = at; return atomTypeCont_.replace(keys, atomType); } @@ -629,9 +697,4 @@ namespace OpenMD { return ffStream; } - void ForceField::setFortranForceOptions(){ - ForceOptions theseFortranOptions; - forceFieldOptions_.makeFortranOptions(theseFortranOptions); - setfForceOptions(&theseFortranOptions); - } } //end namespace OpenMD