45#include "nonbonded/SHAPES.hpp"
51#include "nonbonded/LJ.hpp"
52#include "utils/simError.h"
64 void SHAPES::initialize() {
65 ForceFieldOptions& fopts = forceField_->getForceFieldOptions();
66 ForceField::AtomTypeContainer* atomTypes = forceField_->getAtomTypes();
67 ForceField::AtomTypeContainer::MapTypeIterator i;
73 for (at = atomTypes->beginType(i); at != NULL;
74 at = atomTypes->nextType(i)) {
75 if (at->isShape()) addShape(
dynamic_cast<ShapeAtomType*
>(at));
77 if (at->isLennardJones()) addLJ(at);
83 void SHAPES::addShape(ShapeAtomType* atomType) {
85 AtomTypeProperties atp = atomType->getATP();
87 if (atomType->isShape()) {
88 pair<map<int, ShapeAtomType*>::iterator,
bool> ret;
89 ret = ShapesMap.insert(pair<int, ShapeAtomType*>(atp.ident, atomType));
90 if (ret.second ==
false) {
91 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
92 "SHAPES already had a previous entry with ident %d\n",
94 painCave.severity = OPENMD_INFO;
99 ShapesMap.insert(pair<int, ShapeAtomType*>(
100 atp.ident,
static_cast<ShapeAtomType*
>(atomType)));
102 }
else if (atomType->isLennardJones()) {
103 RealType d1 = getLJSigma(atomType) / sqrt(2.0);
104 RealType e1 = getLJEpsilon(atomType);
106 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
107 "SHAPES::addType was passed an atomType (%s) that does not\n"
108 "\tappear to be a SHAPES or Lennard-Jones atom.\n",
109 atomType->getName().c_str());
110 painCave.severity = OPENMD_ERROR;
111 painCave.isFatal = 1;
116 LJParam SHAPES::getLJParam(AtomType* atomType) {
119 if (!atomType->isLennardJones()) {
120 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
121 "SHAPES::getLJParam was passed an atomType (%s) that does not\n"
122 "\tappear to be a Lennard-Jones atom.\n",
123 atomType->getName().c_str());
124 painCave.severity = OPENMD_ERROR;
125 painCave.isFatal = 1;
129 GenericData* data = atomType->getPropertyByName(
"LennardJones");
131 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
132 "SHAPES::getLJParam could not find Lennard-Jones\n"
133 "\tparameters for atomType %s.\n",
134 atomType->getName().c_str());
135 painCave.severity = OPENMD_ERROR;
136 painCave.isFatal = 1;
140 LJParamGenericData* ljData =
dynamic_cast<LJParamGenericData*
>(data);
141 if (ljData == NULL) {
143 painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
144 "SHAPES::getLJParam could not convert GenericData to LJParam for\n"
146 atomType->getName().c_str());
147 painCave.severity = OPENMD_ERROR;
148 painCave.isFatal = 1;
152 return ljData->getData();
155 RealType SHAPES::getLJEpsilon(AtomType* atomType) {
156 LJParam ljParam = getLJParam(atomType);
157 return ljParam.epsilon;
159 RealType SHAPES::getLJSigma(AtomType* atomType) {
160 LJParam ljParam = getLJParam(atomType);
161 return ljParam.sigma;
164 RealType SHAPES::getGayBerneCut(
int atid) {
165 if (!initialized_) initialize();
166 std::map<int, AtomType*>::const_iterator it;
167 it = SHAPESMap.find(atid);
168 if (it == SHAPESMap.end()) {
169 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
170 "SHAPES::getGayBerneCut could not find atid %d in SHAPESMap\n",
172 painCave.severity = OPENMD_ERROR;
173 painCave.isFatal = 1;
177 AtomType* atype = it->second;
181 if (atype->isGayBerne()) {
182 GayBerneParam gb = getGayBerneParam(atype);
185 gbCut = 2.5 * sqrt(2.0) * max(gb.SHAPES_l, gb.SHAPES_d);
187 }
else if (atype->isLennardJones()) {
188 gbCut = 2.5 * LJ::Instance()->getSigma(atype);
194 void SHAPES::calcForce(AtomType* at1, AtomType* at2, Vector3d d, RealType r,
195 RealType r2, RealType sw, RealType& vpair,
196 RealType& pot, RotMat3x3d A1, RotMat3x3d A2,
197 Vector3d& f1, Vector3d& t1, Vector3d& t2) {
198 if (!initialized_) initialize();
200 pair<AtomType*, AtomType*> key = make_pair(at1, at2);
201 SHAPESInteractionData mixer = MixingMap[key];
203 RealType r3 = r2 * r;
204 RealType r5 = r3 * r2;
206 Vector3d drdi = -d / r;
207 Vector3d drdui = V3Zero;
208 Vector3d drdj = d / r;
209 Vector3d drduj = V3Zero;
211 bool i_is_LJ = at1->isLennardJones();
212 bool j_is_LJ = at2->isLennardJones();
225 sigma_i = LJ::Instance()->getSigma(at1);
227 epsilon_i = LJ::Instance()->getEpsilon(at1);
238 Vector3d ri = A1 * d;
240 RealType xi = ri.
x() / r;
241 RealType yi = ri.y() / r;
242 RealType zi = ri.z() / r;
243 RealType xi2 = xi * xi;
244 RealType yi2 = yi * yi;
245 RealType zi2 = zi * zi;
246 RealType cti = zi / r;
248 if (cti > 1.0) cti = 1.0;
249 if (cti < -1.0_dp) cti = -1.0;
251 Vector3d dctidr(-zi * xi / r3, -zi * yi / r3, 1.0 / r - zi2 / r3);
253 Vector3d dctidu(yi / r, -zi / r, 0.0);
258 RealType sti2 = 1.0 - cti * cti;
260 Vector3d dcpidr, dcpidu, dspidr, dspidu;
261 if (fabs(sti2) < 1.0e-12) {
262 proji = sqrt(r * 1.0e-12);
263 dcpidr = Vector3d(1.0 / proji, 0.0, 0.0);
264 dcpidu = Vector3d(xi / proji, 0.0, 0.0);
265 dspidr = Vector3d(0.0, 1.0 / proji, 0.0);
266 dspidu = Vector3d(0.0, yi / proji, 0.0);
268 proji = sqrt(xi2 + yi2);
269 RealType proji3 = proji * proji * proji;
271 Vector3d(1.0_dp / proji - xi2 / proji3, -xi * yi / proji3, 0.0);
272 dcpidu = Vector3d(xi / proji - (xi2 * xi) / proji3,
273 -(xi * yi2) / proji3, 0.0);
275 Vector3d(-xi * yi / proji3, 1.0_dp / proji - yi2 / proji3, 0.0);
276 dspidu = Vector3d(-(yi * xi2) / proji3,
277 yi / proji - (yi2 * yi) / proji3, 0.0);
288 RealType sigma0 = mixer.sigma0;
289 RealType dw = mixer.dw;
290 RealType eps0 = mixer.eps0;
291 RealType x2 = mixer.x2;
292 RealType xa2 = mixer.xa2;
293 RealType xai2 = mixer.xai2;
294 RealType xp2 = mixer.xp2;
295 RealType xpap2 = mixer.xpap2;
296 RealType xpapi2 = mixer.xpapi2;
298 Vector3d ul1 = A1.getRow(2);
299 Vector3d ul2 = A2.getRow(2);
317 if (i_is_LJ || j_is_LJ)
325 RealType au2 = au * au;
326 RealType bu2 = bu * bu;
330 (xa2 * au2 + xai2 * bu2 - 2.0 * x2 * au * bu * g) / (1.0 - x2 * g2);
331 RealType Hp = (xpap2 * au2 + xpapi2 * bu2 - 2.0 * xp2 * au * bu * g) /
334 RealType sigma = sigma0 / sqrt(1.0 - H);
335 RealType e1 = 1.0 / sqrt(1.0 - x2 * g2);
336 RealType e2 = 1.0 - Hp;
337 RealType eps = eps0 * pow(e1, nu_) * pow(e2, mu_);
338 RealType BigR = dw * sigma0 / (r - sigma + dw * sigma0);
340 RealType R3 = BigR * BigR * BigR;
341 RealType R6 = R3 * R3;
342 RealType R7 = R6 * BigR;
343 RealType R12 = R6 * R6;
344 RealType R13 = R6 * R7;
346 RealType U = vdwMult * 4.0 * eps * (R12 - R6);
348 RealType s3 = sigma * sigma * sigma;
349 RealType s03 = sigma0 * sigma0 * sigma0;
351 RealType pref1 = -vdwMult * 8.0 * eps * mu_ * (R12 - R6) / (e2 * r);
354 vdwMult * 8.0 * eps * s3 * (6.0 * R13 - 3.0 * R7) / (dw * r * s03);
356 RealType dUdr = -(pref1 * Hp + pref2 * (sigma0 * sigma0 * r / s3 + H));
358 RealType dUda = pref1 * (xpap2 * au - xp2 * bu * g) / (1.0 - xp2 * g2) +
359 pref2 * (xa2 * au - x2 * bu * g) / (1.0 - x2 * g2);
361 RealType dUdb = pref1 * (xpapi2 * bu - xp2 * au * g) / (1.0 - xp2 * g2) +
362 pref2 * (xai2 * bu - x2 * au * g) / (1.0 - x2 * g2);
365 4.0 * eps * nu_ * (R12 - R6) * x2 * g / (1.0 - x2 * g2) +
366 8.0 * eps * mu_ * (R12 - R6) * (xp2 * au * bu - Hp * xp2 * g) /
367 (1.0 - xp2 * g2) / e2 +
368 8.0 * eps * s3 * (3.0 * R7 - 6.0 * R13) *
369 (x2 * au * bu - H * x2 * g) / (1.0 - x2 * g2) / (dw * s03);
371 Vector3d rhat = d / r;
372 Vector3d rxu1 =
cross(d, ul1);
373 Vector3d rxu2 =
cross(d, ul2);
374 Vector3d uxu =
cross(ul1, ul2);
377 f1 += dUdr * rhat + dUda * ul1 + dUdb * ul2;
378 t1 += dUda * rxu1 - dUdg * uxu;
379 t2 += dUdb * rxu2 - dUdg * uxu;
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.