| 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> |
| 46 |
|
#include <cmath> |
| 47 |
|
#include "nonbonded/LJ.hpp" |
| 48 |
|
#include "utils/simError.h" |
| 49 |
+ |
#include "types/LennardJonesAdapter.hpp" |
| 50 |
+ |
#include "types/LennardJonesInteractionType.hpp" |
| 51 |
|
|
| 52 |
|
namespace OpenMD { |
| 53 |
|
|
| 54 |
|
LJ::LJ() : name_("LJ"), initialized_(false), forceField_(NULL) {} |
| 55 |
|
|
| 56 |
< |
LJParam LJ::getLJParam(AtomType* atomType) { |
| 54 |
< |
|
| 55 |
< |
// Do sanity checking on the AtomType we were passed before |
| 56 |
< |
// building any data structures: |
| 57 |
< |
if (!atomType->isLennardJones()) { |
| 58 |
< |
sprintf( painCave.errMsg, |
| 59 |
< |
"LJ::getLJParam was passed an atomType (%s) that does not\n" |
| 60 |
< |
"\tappear to be a Lennard-Jones atom.\n", |
| 61 |
< |
atomType->getName().c_str()); |
| 62 |
< |
painCave.severity = OPENMD_ERROR; |
| 63 |
< |
painCave.isFatal = 1; |
| 64 |
< |
simError(); |
| 65 |
< |
} |
| 66 |
< |
|
| 67 |
< |
GenericData* data = atomType->getPropertyByName("LennardJones"); |
| 68 |
< |
if (data == NULL) { |
| 69 |
< |
sprintf( painCave.errMsg, "LJ::getLJParam could not find Lennard-Jones\n" |
| 70 |
< |
"\tparameters for atomType %s.\n", atomType->getName().c_str()); |
| 71 |
< |
painCave.severity = OPENMD_ERROR; |
| 72 |
< |
painCave.isFatal = 1; |
| 73 |
< |
simError(); |
| 74 |
< |
} |
| 75 |
< |
|
| 76 |
< |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
| 77 |
< |
if (ljData == NULL) { |
| 78 |
< |
sprintf( painCave.errMsg, |
| 79 |
< |
"LJ::getLJParam could not convert GenericData to LJParam for\n" |
| 80 |
< |
"\tatom type %s\n", atomType->getName().c_str()); |
| 81 |
< |
painCave.severity = OPENMD_ERROR; |
| 82 |
< |
painCave.isFatal = 1; |
| 83 |
< |
simError(); |
| 84 |
< |
} |
| 85 |
< |
|
| 86 |
< |
return ljData->getData(); |
| 87 |
< |
} |
| 56 |
> |
RealType LJ::getSigma(AtomType* atomType1, AtomType* atomType2) { |
| 57 |
|
|
| 58 |
< |
RealType LJ::getSigma(AtomType* atomType) { |
| 59 |
< |
LJParam ljParam = getLJParam(atomType); |
| 60 |
< |
return ljParam.sigma; |
| 61 |
< |
} |
| 93 |
< |
|
| 94 |
< |
RealType LJ::getSigma(AtomType* atomType1, AtomType* atomType2) { |
| 95 |
< |
RealType sigma1 = getSigma(atomType1); |
| 96 |
< |
RealType sigma2 = getSigma(atomType2); |
| 58 |
> |
LennardJonesAdapter lja1 = LennardJonesAdapter(atomType1); |
| 59 |
> |
LennardJonesAdapter lja2 = LennardJonesAdapter(atomType2); |
| 60 |
> |
RealType sigma1 = lja1.getSigma(); |
| 61 |
> |
RealType sigma2 = lja2.getSigma(); |
| 62 |
|
|
| 63 |
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
| 64 |
|
string DistanceMix = fopts.getDistanceMixingRule(); |
| 70 |
|
return 0.5 * (sigma1 + sigma2); |
| 71 |
|
} |
| 72 |
|
|
| 73 |
< |
RealType LJ::getEpsilon(AtomType* atomType) { |
| 74 |
< |
LJParam ljParam = getLJParam(atomType); |
| 75 |
< |
return ljParam.epsilon; |
| 76 |
< |
} |
| 77 |
< |
|
| 78 |
< |
RealType LJ::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
| 114 |
< |
RealType epsilon1 = getEpsilon(atomType1); |
| 115 |
< |
RealType epsilon2 = getEpsilon(atomType2); |
| 73 |
> |
RealType LJ::getEpsilon(AtomType* atomType1, AtomType* atomType2) { |
| 74 |
> |
LennardJonesAdapter lja1 = LennardJonesAdapter(atomType1); |
| 75 |
> |
LennardJonesAdapter lja2 = LennardJonesAdapter(atomType2); |
| 76 |
> |
|
| 77 |
> |
RealType epsilon1 = lja1.getEpsilon(); |
| 78 |
> |
RealType epsilon2 = lja2.getEpsilon(); |
| 79 |
|
return sqrt(epsilon1 * epsilon2); |
| 80 |
|
} |
| 81 |
|
|
| 86 |
|
|
| 87 |
|
for (at = atomTypes->beginType(i); at != NULL; |
| 88 |
|
at = atomTypes->nextType(i)) { |
| 89 |
< |
|
| 90 |
< |
if (at->isLennardJones()) |
| 91 |
< |
addType(at); |
| 89 |
> |
LennardJonesAdapter lja = LennardJonesAdapter(at); |
| 90 |
> |
if (lja.isLennardJones()){ |
| 91 |
> |
addType(at); |
| 92 |
> |
} |
| 93 |
|
} |
| 130 |
– |
|
| 94 |
|
ForceField::NonBondedInteractionTypeContainer* nbiTypes = forceField_->getNonBondedInteractionTypes(); |
| 95 |
|
ForceField::NonBondedInteractionTypeContainer::MapTypeIterator j; |
| 96 |
|
NonBondedInteractionType* nbt; |
| 97 |
+ |
ForceField::NonBondedInteractionTypeContainer::KeyType keys; |
| 98 |
|
|
| 99 |
+ |
|
| 100 |
|
for (nbt = nbiTypes->beginType(j); nbt != NULL; |
| 101 |
|
nbt = nbiTypes->nextType(j)) { |
| 102 |
< |
|
| 102 |
> |
|
| 103 |
|
if (nbt->isLennardJones()) { |
| 104 |
< |
|
| 105 |
< |
pair<AtomType*, AtomType*> atypes = nbt->getAtomTypes(); |
| 106 |
< |
|
| 107 |
< |
GenericData* data = nbt->getPropertyByName("LennardJones"); |
| 108 |
< |
if (data == NULL) { |
| 109 |
< |
sprintf( painCave.errMsg, "LJ::rebuildMixingMap could not find\n" |
| 110 |
< |
"\tLennard-Jones parameters for %s - %s interaction.\n", |
| 146 |
< |
atypes.first->getName().c_str(), |
| 147 |
< |
atypes.second->getName().c_str()); |
| 148 |
< |
painCave.severity = OPENMD_ERROR; |
| 149 |
< |
painCave.isFatal = 1; |
| 150 |
< |
simError(); |
| 151 |
< |
} |
| 152 |
< |
|
| 153 |
< |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
| 154 |
< |
if (ljData == NULL) { |
| 104 |
> |
keys = nbiTypes->getKeys(j); |
| 105 |
> |
AtomType* at1 = forceField_->getAtomType(keys[0]); |
| 106 |
> |
AtomType* at2 = forceField_->getAtomType(keys[1]); |
| 107 |
> |
|
| 108 |
> |
LennardJonesInteractionType* ljit = dynamic_cast<LennardJonesInteractionType*>(nbt); |
| 109 |
> |
|
| 110 |
> |
if (ljit == NULL) { |
| 111 |
|
sprintf( painCave.errMsg, |
| 112 |
< |
"LJ::rebuildMixingMap could not convert GenericData to\n" |
| 113 |
< |
"\tLJParam for %s - %s interaction.\n", |
| 114 |
< |
atypes.first->getName().c_str(), |
| 115 |
< |
atypes.second->getName().c_str()); |
| 112 |
> |
"LJ::initialize could not convert NonBondedInteractionType\n" |
| 113 |
> |
"\tto LennardJonesInteractionType for %s - %s interaction.\n", |
| 114 |
> |
at1->getName().c_str(), |
| 115 |
> |
at2->getName().c_str()); |
| 116 |
|
painCave.severity = OPENMD_ERROR; |
| 117 |
|
painCave.isFatal = 1; |
| 118 |
|
simError(); |
| 119 |
|
} |
| 164 |
– |
|
| 165 |
– |
LJParam ljParam = ljData->getData(); |
| 120 |
|
|
| 121 |
< |
RealType sigma = ljParam.sigma; |
| 122 |
< |
RealType epsilon = ljParam.epsilon; |
| 123 |
< |
|
| 170 |
< |
addExplicitInteraction(atypes.first, atypes.second, sigma, epsilon); |
| 121 |
> |
RealType sigma = ljit->getSigma(); |
| 122 |
> |
RealType epsilon = ljit->getEpsilon(); |
| 123 |
> |
addExplicitInteraction(at1, at2, sigma, epsilon); |
| 124 |
|
} |
| 125 |
|
} |
| 126 |
|
initialized_ = true; |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
void LJ::addType(AtomType* atomType){ |
| 132 |
< |
RealType sigma1 = getSigma(atomType); |
| 133 |
< |
RealType epsilon1 = getEpsilon(atomType); |
| 132 |
> |
LennardJonesAdapter lja1 = LennardJonesAdapter(atomType); |
| 133 |
> |
|
| 134 |
> |
RealType sigma1 = lja1.getSigma(); |
| 135 |
> |
RealType epsilon1 = lja1.getEpsilon(); |
| 136 |
|
|
| 137 |
|
// add it to the map: |
| 183 |
– |
AtomTypeProperties atp = atomType->getATP(); |
| 138 |
|
|
| 139 |
|
pair<map<int,AtomType*>::iterator,bool> ret; |
| 140 |
< |
ret = LJMap.insert( pair<int, AtomType*>(atp.ident, atomType) ); |
| 140 |
> |
ret = LJMap.insert( pair<int, AtomType*>(atomType->getIdent(), atomType) ); |
| 141 |
|
if (ret.second == false) { |
| 142 |
|
sprintf( painCave.errMsg, |
| 143 |
|
"LJ already had a previous entry with ident %d\n", |
| 144 |
< |
atp.ident); |
| 144 |
> |
atomType->getIdent()); |
| 145 |
|
painCave.severity = OPENMD_INFO; |
| 146 |
|
painCave.isFatal = 0; |
| 147 |
|
simError(); |
| 173 |
|
|
| 174 |
|
void LJ::addExplicitInteraction(AtomType* atype1, AtomType* atype2, RealType sigma, RealType epsilon){ |
| 175 |
|
|
| 222 |
– |
// in case these weren't already in the map |
| 223 |
– |
addType(atype1); |
| 224 |
– |
addType(atype2); |
| 225 |
– |
|
| 176 |
|
LJInteractionData mixer; |
| 177 |
|
mixer.sigma = sigma; |
| 178 |
|
mixer.epsilon = epsilon; |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
void LJ::calcForce(InteractionData &idat) { |
| 243 |
– |
|
| 193 |
|
if (!initialized_) initialize(); |
| 245 |
– |
|
| 194 |
|
map<pair<AtomType*, AtomType*>, LJInteractionData>::iterator it; |
| 195 |
|
it = MixingMap.find( idat.atypes ); |
| 196 |
|
|