51#include "utils/Constants.hpp"
55 Inversion::Inversion(Atom* atom1, Atom* atom2, Atom* atom3, Atom* atom4,
57 ShortRangeInteraction(),
65 inversionKey_ = inversionType_->getKey();
68 void Inversion::calcForce(RealType& angle,
bool doParticlePot) {
74 Vector3d pos1 = atoms_[1]->getPos();
75 Vector3d pos2 = atoms_[2]->getPos();
76 Vector3d pos3 = atoms_[0]->getPos();
77 Vector3d pos4 = atoms_[3]->getPos();
79 Vector3d r31 = pos1 - pos3;
80 snapshotMan_->getCurrentSnapshot()->wrapVector(r31);
81 Vector3d r23 = pos3 - pos2;
82 snapshotMan_->getCurrentSnapshot()->wrapVector(r23);
83 Vector3d r43 = pos3 - pos4;
84 snapshotMan_->getCurrentSnapshot()->wrapVector(r43);
87 Vector3d A =
cross(r31, r43);
88 RealType rA = A.length();
89 Vector3d B =
cross(r43, r23);
90 RealType rB = B.length();
96 RealType cos_phi =
dot(A, B);
97 if (cos_phi > 1.0) cos_phi = 1.0;
98 if (cos_phi < -1.0) cos_phi = -1.0;
101 switch (inversionKey_) {
103 inversionType_->calcForce(cos_phi, potential_, dVdcosPhi);
106 RealType phi = acos(cos_phi);
108 inversionType_->calcForce(phi, potential_, dVdPhi);
109 RealType sin_phi = sqrt(1.0 - cos_phi * cos_phi);
110 if (fabs(sin_phi) < 1.0E-6) { sin_phi = 1.0E-6; }
111 dVdcosPhi = -dVdPhi / sin_phi;
120 Vector3d dcosdA = (cos_phi * A - B) / rA;
121 Vector3d dcosdB = (cos_phi * B - A) / rB;
123 f1 = dVdcosPhi *
cross(r43, dcosdA);
124 f2 = dVdcosPhi * (
cross(r23, dcosdB) -
cross(r31, dcosdA));
125 f3 = dVdcosPhi *
cross(dcosdB, r43);
137 atoms_[1]->addFrc(f1);
138 atoms_[0]->addFrc(f2 - f1 + f3);
139 atoms_[3]->addFrc(-f2);
140 atoms_[2]->addFrc(-f3);
143 atoms_[0]->addParticlePot(potential_);
144 atoms_[1]->addParticlePot(potential_);
145 atoms_[2]->addParticlePot(potential_);
146 atoms_[3]->addParticlePot(potential_);
149 angle = acos(cos_phi) / Constants::PI * 180.0;
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.