| 46 |
|
#include <cmath> |
| 47 |
|
#include "nonbonded/GB.hpp" |
| 48 |
|
#include "utils/simError.h" |
| 49 |
+ |
#include "types/LennardJonesAdapter.hpp" |
| 50 |
+ |
#include "types/GayBerneAdapter.hpp" |
| 51 |
|
|
| 52 |
|
using namespace std; |
| 53 |
|
namespace OpenMD { |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
GB::GB() : name_("GB"), initialized_(false), mu_(2.0), nu_(1.0), forceField_(NULL) {} |
| 90 |
– |
|
| 91 |
– |
GayBerneParam GB::getGayBerneParam(AtomType* atomType) { |
| 92 |
|
|
| 93 |
– |
// Do sanity checking on the AtomType we were passed before |
| 94 |
– |
// building any data structures: |
| 95 |
– |
if (!atomType->isGayBerne()) { |
| 96 |
– |
sprintf( painCave.errMsg, |
| 97 |
– |
"GB::getGayBerneParam was passed an atomType (%s) that does\n" |
| 98 |
– |
"\tnot appear to be a Gay-Berne atom.\n", |
| 99 |
– |
atomType->getName().c_str()); |
| 100 |
– |
painCave.severity = OPENMD_ERROR; |
| 101 |
– |
painCave.isFatal = 1; |
| 102 |
– |
simError(); |
| 103 |
– |
} |
| 104 |
– |
|
| 105 |
– |
DirectionalAtomType* daType = dynamic_cast<DirectionalAtomType*>(atomType); |
| 106 |
– |
GenericData* data = daType->getPropertyByName("GayBerne"); |
| 107 |
– |
if (data == NULL) { |
| 108 |
– |
sprintf( painCave.errMsg, "GB::getGayBerneParam could not find\n" |
| 109 |
– |
"\tGay-Berne parameters for atomType %s.\n", |
| 110 |
– |
daType->getName().c_str()); |
| 111 |
– |
painCave.severity = OPENMD_ERROR; |
| 112 |
– |
painCave.isFatal = 1; |
| 113 |
– |
simError(); |
| 114 |
– |
} |
| 115 |
– |
|
| 116 |
– |
GayBerneParamGenericData* gbData = dynamic_cast<GayBerneParamGenericData*>(data); |
| 117 |
– |
if (gbData == NULL) { |
| 118 |
– |
sprintf( painCave.errMsg, |
| 119 |
– |
"GB::getGayBerneParam could not convert GenericData to\n" |
| 120 |
– |
"\tGayBerneParamGenericData for atom type %s\n", |
| 121 |
– |
daType->getName().c_str()); |
| 122 |
– |
painCave.severity = OPENMD_ERROR; |
| 123 |
– |
painCave.isFatal = 1; |
| 124 |
– |
simError(); |
| 125 |
– |
} |
| 126 |
– |
|
| 127 |
– |
return gbData->getData(); |
| 128 |
– |
} |
| 129 |
– |
|
| 130 |
– |
LJParam GB::getLJParam(AtomType* atomType) { |
| 131 |
– |
|
| 132 |
– |
// Do sanity checking on the AtomType we were passed before |
| 133 |
– |
// building any data structures: |
| 134 |
– |
if (!atomType->isLennardJones()) { |
| 135 |
– |
sprintf( painCave.errMsg, |
| 136 |
– |
"GB::getLJParam was passed an atomType (%s) that does not\n" |
| 137 |
– |
"\tappear to be a Lennard-Jones atom.\n", |
| 138 |
– |
atomType->getName().c_str()); |
| 139 |
– |
painCave.severity = OPENMD_ERROR; |
| 140 |
– |
painCave.isFatal = 1; |
| 141 |
– |
simError(); |
| 142 |
– |
} |
| 143 |
– |
|
| 144 |
– |
GenericData* data = atomType->getPropertyByName("LennardJones"); |
| 145 |
– |
if (data == NULL) { |
| 146 |
– |
sprintf( painCave.errMsg, "GB::getLJParam could not find Lennard-Jones\n" |
| 147 |
– |
"\tparameters for atomType %s.\n", atomType->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) { |
| 155 |
– |
sprintf( painCave.errMsg, |
| 156 |
– |
"GB::getLJParam could not convert GenericData to LJParam for\n" |
| 157 |
– |
"\tatom type %s\n", atomType->getName().c_str()); |
| 158 |
– |
painCave.severity = OPENMD_ERROR; |
| 159 |
– |
painCave.isFatal = 1; |
| 160 |
– |
simError(); |
| 161 |
– |
} |
| 162 |
– |
|
| 163 |
– |
return ljData->getData(); |
| 164 |
– |
} |
| 165 |
– |
|
| 166 |
– |
RealType GB::getLJEpsilon(AtomType* atomType) { |
| 167 |
– |
LJParam ljParam = getLJParam(atomType); |
| 168 |
– |
return ljParam.epsilon; |
| 169 |
– |
} |
| 170 |
– |
RealType GB::getLJSigma(AtomType* atomType) { |
| 171 |
– |
LJParam ljParam = getLJParam(atomType); |
| 172 |
– |
return ljParam.sigma; |
| 173 |
– |
} |
| 174 |
– |
|
| 93 |
|
void GB::initialize() { |
| 94 |
|
|
| 95 |
|
ForceFieldOptions& fopts = forceField_->getForceFieldOptions(); |
| 105 |
|
for (at = atomTypes->beginType(i); at != NULL; |
| 106 |
|
at = atomTypes->nextType(i)) { |
| 107 |
|
|
| 108 |
< |
if (at->isGayBerne() || at->isLennardJones()) |
| 108 |
> |
LennardJonesAdapter lja = LennardJonesAdapter(at); |
| 109 |
> |
GayBerneAdapter gba = GayBerneAdapter(at); |
| 110 |
> |
|
| 111 |
> |
if (gba.isGayBerne() || lja.isLennardJones()) |
| 112 |
|
addType(at); |
| 113 |
|
} |
| 114 |
|
|
| 117 |
|
|
| 118 |
|
void GB::addType(AtomType* atomType){ |
| 119 |
|
// add it to the map: |
| 199 |
– |
AtomTypeProperties atp = atomType->getATP(); |
| 120 |
|
|
| 121 |
|
pair<map<int,AtomType*>::iterator,bool> ret; |
| 122 |
< |
ret = GBMap.insert( pair<int, AtomType*>(atp.ident, atomType) ); |
| 122 |
> |
ret = GBMap.insert( pair<int, AtomType*>(atomType->getIdent(), atomType) ); |
| 123 |
|
if (ret.second == false) { |
| 124 |
|
sprintf( painCave.errMsg, |
| 125 |
|
"GB already had a previous entry with ident %d\n", |
| 126 |
< |
atp.ident); |
| 126 |
> |
atomType->getIdent() ); |
| 127 |
|
painCave.severity = OPENMD_INFO; |
| 128 |
|
painCave.isFatal = 0; |
| 129 |
|
simError(); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
RealType d1, l1, eX1, eS1, eE1, dw1; |
| 133 |
< |
|
| 134 |
< |
if (atomType->isGayBerne()) { |
| 135 |
< |
GayBerneParam gb1 = getGayBerneParam(atomType); |
| 136 |
< |
d1 = gb1.GB_d; |
| 137 |
< |
l1 = gb1.GB_l; |
| 138 |
< |
eX1 = gb1.GB_eps_X; |
| 139 |
< |
eS1 = gb1.GB_eps_S; |
| 140 |
< |
eE1 = gb1.GB_eps_E; |
| 141 |
< |
dw1 = gb1.GB_dw; |
| 142 |
< |
} else if (atomType->isLennardJones()) { |
| 143 |
< |
d1 = getLJSigma(atomType) / sqrt(2.0); |
| 133 |
> |
|
| 134 |
> |
LennardJonesAdapter lja1 = LennardJonesAdapter(atomType); |
| 135 |
> |
GayBerneAdapter gba1 = GayBerneAdapter(atomType); |
| 136 |
> |
if (gba1.isGayBerne()) { |
| 137 |
> |
d1 = gba1.getD(); |
| 138 |
> |
l1 = gba1.getL(); |
| 139 |
> |
eX1 = gba1.getEpsX(); |
| 140 |
> |
eS1 = gba1.getEpsS(); |
| 141 |
> |
eE1 = gba1.getEpsE(); |
| 142 |
> |
dw1 = gba1.getDw(); |
| 143 |
> |
} else if (lja1.isLennardJones()) { |
| 144 |
> |
d1 = lja1.getSigma() / sqrt(2.0); |
| 145 |
|
l1 = d1; |
| 146 |
< |
eX1 = getLJEpsilon(atomType); |
| 146 |
> |
eX1 = lja1.getEpsilon(); |
| 147 |
|
eS1 = eX1; |
| 148 |
|
eE1 = eX1; |
| 149 |
|
dw1 = 1.0; |
| 164 |
|
for( it = GBMap.begin(); it != GBMap.end(); ++it) { |
| 165 |
|
|
| 166 |
|
AtomType* atype2 = (*it).second; |
| 167 |
< |
|
| 167 |
> |
LennardJonesAdapter lja2 = LennardJonesAdapter(atype2); |
| 168 |
> |
GayBerneAdapter gba2 = GayBerneAdapter(atype2); |
| 169 |
|
RealType d2, l2, eX2, eS2, eE2, dw2; |
| 170 |
|
|
| 171 |
< |
if (atype2->isGayBerne()) { |
| 172 |
< |
GayBerneParam gb2 = getGayBerneParam(atype2); |
| 173 |
< |
d2 = gb2.GB_d; |
| 174 |
< |
l2 = gb2.GB_l; |
| 175 |
< |
eX2 = gb2.GB_eps_X; |
| 176 |
< |
eS2 = gb2.GB_eps_S; |
| 177 |
< |
eE2 = gb2.GB_eps_E; |
| 178 |
< |
dw2 = gb2.GB_dw; |
| 179 |
< |
} else if (atype2->isLennardJones()) { |
| 258 |
< |
d2 = getLJSigma(atype2) / sqrt(2.0); |
| 171 |
> |
if (gba2.isGayBerne()) { |
| 172 |
> |
d2 = gba2.getD(); |
| 173 |
> |
l2 = gba2.getL(); |
| 174 |
> |
eX2 = gba2.getEpsX(); |
| 175 |
> |
eS2 = gba2.getEpsS(); |
| 176 |
> |
eE2 = gba2.getEpsE(); |
| 177 |
> |
dw2 = gba2.getDw(); |
| 178 |
> |
} else if (lja2.isLennardJones()) { |
| 179 |
> |
d2 = lja2.getSigma() / sqrt(2.0); |
| 180 |
|
l2 = d2; |
| 181 |
< |
eX2 = getLJEpsilon(atype2); |
| 181 |
> |
eX2 = lja2.getEpsilon(); |
| 182 |
|
eS2 = eX2; |
| 183 |
|
eE2 = eX2; |
| 184 |
|
dw2 = 1.0; |
| 225 |
|
|
| 226 |
|
// only add this pairing if at least one of the atoms is a Gay-Berne atom |
| 227 |
|
|
| 228 |
< |
if (atomType->isGayBerne() || atype2->isGayBerne()) { |
| 228 |
> |
if (gba1.isGayBerne() || gba2.isGayBerne()) { |
| 229 |
|
|
| 230 |
|
pair<AtomType*, AtomType*> key1, key2; |
| 231 |
|
key1 = make_pair(atomType, atype2); |
| 274 |
|
|
| 275 |
|
RealType a, b, g; |
| 276 |
|
|
| 277 |
+ |
// This is not good. We should store this in the mixing map, and not |
| 278 |
+ |
// query atom types in calc force. |
| 279 |
|
bool i_is_LJ = idat.atypes.first->isLennardJones(); |
| 280 |
|
bool j_is_LJ = idat.atypes.second->isLennardJones(); |
| 281 |
|
|
| 392 |
|
|
| 393 |
|
RealType cut = 0.0; |
| 394 |
|
|
| 395 |
< |
if (atypes.first->isGayBerne()) { |
| 396 |
< |
GayBerneParam gb1 = getGayBerneParam(atypes.first); |
| 397 |
< |
RealType d1 = gb1.GB_d; |
| 398 |
< |
RealType l1 = gb1.GB_l; |
| 395 |
> |
LennardJonesAdapter lja1 = LennardJonesAdapter(atypes.first); |
| 396 |
> |
GayBerneAdapter gba1 = GayBerneAdapter(atypes.first); |
| 397 |
> |
LennardJonesAdapter lja2 = LennardJonesAdapter(atypes.second); |
| 398 |
> |
GayBerneAdapter gba2 = GayBerneAdapter(atypes.second); |
| 399 |
> |
|
| 400 |
> |
if (gba1.isGayBerne()) { |
| 401 |
> |
RealType d1 = gba1.getD(); |
| 402 |
> |
RealType l1 = gba1.getL(); |
| 403 |
|
// sigma is actually sqrt(2)*l for prolate ellipsoids |
| 404 |
|
cut = max(cut, RealType(2.5) * sqrt(RealType(2.0)) * max(d1, l1)); |
| 405 |
< |
} else if (atypes.first->isLennardJones()) { |
| 406 |
< |
cut = max(cut, RealType(2.5) * getLJSigma(atypes.first)); |
| 405 |
> |
} else if (lja1.isLennardJones()) { |
| 406 |
> |
cut = max(cut, RealType(2.5) * lja1.getSigma()); |
| 407 |
|
} |
| 408 |
|
|
| 409 |
< |
if (atypes.second->isGayBerne()) { |
| 410 |
< |
GayBerneParam gb2 = getGayBerneParam(atypes.second); |
| 411 |
< |
RealType d2 = gb2.GB_d; |
| 485 |
< |
RealType l2 = gb2.GB_l; |
| 409 |
> |
if (gba2.isGayBerne()) { |
| 410 |
> |
RealType d2 = gba2.getD(); |
| 411 |
> |
RealType l2 = gba2.getL(); |
| 412 |
|
cut = max(cut, RealType(2.5) * sqrt(RealType(2.0)) * max(d2, l2)); |
| 413 |
< |
} else if (atypes.second->isLennardJones()) { |
| 414 |
< |
cut = max(cut, RealType(2.5) * getLJSigma(atypes.second)); |
| 413 |
> |
} else if (lja2.isLennardJones()) { |
| 414 |
> |
cut = max(cut, RealType(2.5) * lja2.getSigma()); |
| 415 |
|
} |
| 416 |
|
|
| 417 |
|
return cut; |