48#include "nonbonded/SHAPES.hpp"
54#include "nonbonded/LJ.hpp"
55#include "utils/simError.h"
67 void SHAPES::initialize() {
68 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
69 ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
70 ForceField::AtomTypeContainer::MapTypeIterator i;
76 for (at = atomTypes->beginType(i); at != NULL;
77 at = atomTypes->nextType(i)) {
78 if (at->isShape()) addShape(
dynamic_cast<ShapeAtomType*
>(at));
80 if (at->isLennardJones()) addLJ(at);
88 AtomTypeProperties atp = atomType->getATP();
90 if (atomType->isShape()) {
91 pair<map<int, ShapeAtomType*>::iterator,
bool> ret;
92 ret = ShapesMap.insert(pair<int, ShapeAtomType*>(atp.ident, atomType));
93 if (ret.second ==
false) {
94 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
95 "SHAPES already had a previous entry with ident %d\n",
97 painCave.severity = OPENMD_INFO;
102 ShapesMap.insert(pair<int, ShapeAtomType*>(
103 atp.ident,
static_cast<ShapeAtomType*
>(atomType)));
105 }
else if (atomType->isLennardJones()) {
106 RealType d1 = getLJSigma(atomType) / sqrt(2.0);
107 RealType e1 = getLJEpsilon(atomType);
109 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
110 "SHAPES::addType was passed an atomType (%s) that does not\n"
111 "\tappear to be a SHAPES or Lennard-Jones atom.\n",
112 atomType->getName().c_str());
113 painCave.severity = OPENMD_ERROR;
114 painCave.isFatal = 1;
119 LJParam SHAPES::getLJParam(
AtomType* atomType) {
122 if (!atomType->isLennardJones()) {
123 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
124 "SHAPES::getLJParam was passed an atomType (%s) that does not\n"
125 "\tappear to be a Lennard-Jones atom.\n",
126 atomType->getName().c_str());
127 painCave.severity = OPENMD_ERROR;
128 painCave.isFatal = 1;
132 GenericData* data = atomType->getPropertyByName(
"LennardJones");
134 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
135 "SHAPES::getLJParam could not find Lennard-Jones\n"
136 "\tparameters for atomType %s.\n",
137 atomType->getName().c_str());
138 painCave.severity = OPENMD_ERROR;
139 painCave.isFatal = 1;
143 LJParamGenericData* ljData =
dynamic_cast<LJParamGenericData*
>(data);
144 if (ljData == NULL) {
146 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
147 "SHAPES::getLJParam could not convert GenericData to LJParam for\n"
149 atomType->getName().c_str());
150 painCave.severity = OPENMD_ERROR;
151 painCave.isFatal = 1;
155 return ljData->getData();
158 RealType SHAPES::getLJEpsilon(
AtomType* atomType) {
159 LJParam ljParam = getLJParam(atomType);
160 return ljParam.epsilon;
162 RealType SHAPES::getLJSigma(
AtomType* atomType) {
163 LJParam ljParam = getLJParam(atomType);
164 return ljParam.sigma;
167 RealType SHAPES::getGayBerneCut(
int atid) {
168 if (!initialized_) initialize();
169 std::map<int, AtomType*>::const_iterator it;
170 it = SHAPESMap.find(atid);
171 if (it == SHAPESMap.end()) {
172 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
173 "SHAPES::getGayBerneCut could not find atid %d in SHAPESMap\n",
175 painCave.severity = OPENMD_ERROR;
176 painCave.isFatal = 1;
180 AtomType* atype = it->second;
184 if (atype->isGayBerne()) {
185 GayBerneParam gb = getGayBerneParam(atype);
188 gbCut = 2.5 * sqrt(2.0) * max(gb.SHAPES_l, gb.SHAPES_d);
190 }
else if (atype->isLennardJones()) {
191 gbCut = 2.5 * LJ::Instance()->getSigma(atype);
197 void SHAPES::calcForce(
AtomType* at1,
AtomType* at2, Vector3d d, RealType r,
198 RealType r2, RealType sw, RealType& vpair,
199 RealType& pot, RotMat3x3d A1, RotMat3x3d A2,
200 Vector3d& f1, Vector3d& t1, Vector3d& t2) {
201 if (!initialized_) initialize();
203 pair<AtomType*, AtomType*> key = make_pair(at1, at2);
204 SHAPESInteractionData mixer = MixingMap[key];
206 RealType r3 = r2 * r;
207 RealType r5 = r3 * r2;
209 Vector3d drdi = -d / r;
210 Vector3d drdui = V3Zero;
211 Vector3d drdj = d / r;
212 Vector3d drduj = V3Zero;
214 bool i_is_LJ = at1->isLennardJones();
215 bool j_is_LJ = at2->isLennardJones();
228 sigma_i = LJ::Instance()->getSigma(at1);
230 epsilon_i = LJ::Instance()->getEpsilon(at1);
241 Vector3d ri = A1 * d;
243 RealType xi = ri.
x() / r;
244 RealType yi = ri.y() / r;
245 RealType zi = ri.z() / r;
246 RealType xi2 = xi * xi;
247 RealType yi2 = yi * yi;
248 RealType zi2 = zi * zi;
249 RealType cti = zi / r;
251 if (cti > 1.0) cti = 1.0;
252 if (cti < -1.0_dp) cti = -1.0;
254 Vector3d dctidr(-zi * xi / r3, -zi * yi / r3, 1.0 / r - zi2 / r3);
256 Vector3d dctidu(yi / r, -zi / r, 0.0);
261 RealType sti2 = 1.0 - cti * cti;
263 Vector3d dcpidr, dcpidu, dspidr, dspidu;
264 if (fabs(sti2) < 1.0e-12) {
265 proji = sqrt(r * 1.0e-12);
266 dcpidr = Vector3d(1.0 / proji, 0.0, 0.0);
267 dcpidu = Vector3d(xi / proji, 0.0, 0.0);
268 dspidr = Vector3d(0.0, 1.0 / proji, 0.0);
269 dspidu = Vector3d(0.0, yi / proji, 0.0);
271 proji = sqrt(xi2 + yi2);
272 RealType proji3 = proji * proji * proji;
274 Vector3d(1.0_dp / proji - xi2 / proji3, -xi * yi / proji3, 0.0);
275 dcpidu = Vector3d(xi / proji - (xi2 * xi) / proji3,
276 -(xi * yi2) / proji3, 0.0);
278 Vector3d(-xi * yi / proji3, 1.0_dp / proji - yi2 / proji3, 0.0);
279 dspidu = Vector3d(-(yi * xi2) / proji3,
280 yi / proji - (yi2 * yi) / proji3, 0.0);
291 RealType sigma0 = mixer.sigma0;
292 RealType dw = mixer.dw;
293 RealType eps0 = mixer.eps0;
294 RealType x2 = mixer.x2;
295 RealType xa2 = mixer.xa2;
296 RealType xai2 = mixer.xai2;
297 RealType xp2 = mixer.xp2;
298 RealType xpap2 = mixer.xpap2;
299 RealType xpapi2 = mixer.xpapi2;
301 Vector3d ul1 = A1.getRow(2);
302 Vector3d ul2 = A2.getRow(2);
320 if (i_is_LJ || j_is_LJ)
328 RealType au2 = au * au;
329 RealType bu2 = bu * bu;
333 (xa2 * au2 + xai2 * bu2 - 2.0 * x2 * au * bu * g) / (1.0 - x2 * g2);
334 RealType Hp = (xpap2 * au2 + xpapi2 * bu2 - 2.0 * xp2 * au * bu * g) /
337 RealType sigma = sigma0 / sqrt(1.0 - H);
338 RealType e1 = 1.0 / sqrt(1.0 - x2 * g2);
339 RealType e2 = 1.0 - Hp;
340 RealType eps = eps0 * pow(e1, nu_) * pow(e2, mu_);
341 RealType BigR = dw * sigma0 / (r - sigma + dw * sigma0);
343 RealType R3 = BigR * BigR * BigR;
344 RealType R6 = R3 * R3;
345 RealType R7 = R6 * BigR;
346 RealType R12 = R6 * R6;
347 RealType R13 = R6 * R7;
349 RealType U = vdwMult * 4.0 * eps * (R12 - R6);
351 RealType s3 = sigma * sigma * sigma;
352 RealType s03 = sigma0 * sigma0 * sigma0;
354 RealType pref1 = -vdwMult * 8.0 * eps * mu_ * (R12 - R6) / (e2 * r);
357 vdwMult * 8.0 * eps * s3 * (6.0 * R13 - 3.0 * R7) / (dw * r * s03);
359 RealType dUdr = -(pref1 * Hp + pref2 * (sigma0 * sigma0 * r / s3 + H));
361 RealType dUda = pref1 * (xpap2 * au - xp2 * bu * g) / (1.0 - xp2 * g2) +
362 pref2 * (xa2 * au - x2 * bu * g) / (1.0 - x2 * g2);
364 RealType dUdb = pref1 * (xpapi2 * bu - xp2 * au * g) / (1.0 - xp2 * g2) +
365 pref2 * (xai2 * bu - x2 * au * g) / (1.0 - x2 * g2);
368 4.0 * eps * nu_ * (R12 - R6) * x2 * g / (1.0 - x2 * g2) +
369 8.0 * eps * mu_ * (R12 - R6) * (xp2 * au * bu - Hp * xp2 * g) /
370 (1.0 - xp2 * g2) / e2 +
371 8.0 * eps * s3 * (3.0 * R7 - 6.0 * R13) *
372 (x2 * au * bu - H * x2 * g) / (1.0 - x2 * g2) / (dw * s03);
374 Vector3d rhat = d / r;
375 Vector3d rxu1 =
cross(d, ul1);
376 Vector3d rxu2 =
cross(d, ul2);
377 Vector3d uxu =
cross(ul1, ul2);
380 f1 += dUdr * rhat + dUda * ul1 + dUdb * ul2;
381 t1 += dUda * rxu1 - dUdg * uxu;
382 t2 += dUdb * rxu2 - dUdg * uxu;
AtomType is what OpenMD looks to for unchanging data about an atom.
Real & z()
Returns reference of the third element of Vector3.
Real & x()
Returns reference of the first element of Vector3.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Vector3< Real > cross(const Vector3< Real > &v1, const Vector3< Real > &v2)
Returns the cross product of two Vectors.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.