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) { |
56 |
< |
|
57 |
< |
// Do sanity checking on the AtomType we were passed before |
58 |
< |
// building any data structures: |
59 |
< |
if (!atomType->isLennardJones()) { |
60 |
< |
sprintf( painCave.errMsg, |
61 |
< |
"LJ::getLJParam was passed an atomType (%s) that does not\n" |
62 |
< |
"\tappear to be a Lennard-Jones atom.\n", |
63 |
< |
atomType->getName().c_str()); |
64 |
< |
painCave.severity = OPENMD_ERROR; |
65 |
< |
painCave.isFatal = 1; |
66 |
< |
simError(); |
67 |
< |
} |
68 |
< |
|
69 |
< |
GenericData* data = atomType->getPropertyByName("LennardJones"); |
70 |
< |
if (data == NULL) { |
71 |
< |
sprintf( painCave.errMsg, "LJ::getLJParam could not find Lennard-Jones\n" |
72 |
< |
"\tparameters for atomType %s.\n", atomType->getName().c_str()); |
73 |
< |
painCave.severity = OPENMD_ERROR; |
74 |
< |
painCave.isFatal = 1; |
75 |
< |
simError(); |
76 |
< |
} |
77 |
< |
|
78 |
< |
LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data); |
79 |
< |
if (ljData == NULL) { |
80 |
< |
sprintf( painCave.errMsg, |
81 |
< |
"LJ::getLJParam could not convert GenericData to LJParam for\n" |
82 |
< |
"\tatom type %s\n", atomType->getName().c_str()); |
83 |
< |
painCave.severity = OPENMD_ERROR; |
84 |
< |
painCave.isFatal = 1; |
85 |
< |
simError(); |
86 |
< |
} |
87 |
< |
|
88 |
< |
return ljData->getData(); |
89 |
< |
} |
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 |
< |
} |
95 |
< |
|
96 |
< |
RealType LJ::getSigma(AtomType* atomType1, AtomType* atomType2) { |
97 |
< |
RealType sigma1 = getSigma(atomType1); |
98 |
< |
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) { |
116 |
< |
RealType epsilon1 = getEpsilon(atomType1); |
117 |
< |
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 |
< |
if (at->isLennardJones()){ |
89 |
> |
LennardJonesAdapter lja = LennardJonesAdapter(at); |
90 |
> |
if (lja.isLennardJones()){ |
91 |
|
addType(at); |
92 |
|
} |
93 |
|
} |
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: |
174 |
– |
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(); |