51#include "utils/Constants.hpp"
55 Torsion::Torsion(Atom* atom1, Atom* atom2, Atom* atom3, Atom* atom4,
57 ShortRangeInteraction(),
66 void Torsion::calcForce(RealType& angle,
bool doParticlePot) {
67 Vector3d pos1 = atoms_[0]->getPos();
68 Vector3d pos2 = atoms_[1]->getPos();
69 Vector3d pos3 = atoms_[2]->getPos();
70 Vector3d pos4 = atoms_[3]->getPos();
72 Vector3d r21 = pos1 - pos2;
73 snapshotMan_->getCurrentSnapshot()->wrapVector(r21);
74 Vector3d r32 = pos2 - pos3;
75 snapshotMan_->getCurrentSnapshot()->wrapVector(r32);
76 Vector3d r43 = pos3 - pos4;
77 snapshotMan_->getCurrentSnapshot()->wrapVector(r43);
80 Vector3d A =
cross(r21, r32);
81 RealType rA = A.length();
82 Vector3d B =
cross(r32, r43);
83 RealType rB = B.length();
91 if (rA * rB < OpenMD::epsilon)
return;
97 RealType cos_phi =
dot(A, B);
98 if (cos_phi > 1.0) cos_phi = 1.0;
99 if (cos_phi < -1.0) cos_phi = -1.0;
102 torsionType_->calcForce(cos_phi, potential_, dVdcosPhi);
107 Vector3d dcosdA = (cos_phi * A - B) / rA;
108 Vector3d dcosdB = (cos_phi * B - A) / rB;
110 f1 = dVdcosPhi *
cross(r32, dcosdA);
111 f2 = dVdcosPhi * (
cross(r43, dcosdB) -
cross(r21, dcosdA));
112 f3 = dVdcosPhi *
cross(dcosdB, r32);
114 atoms_[0]->addFrc(f1);
115 atoms_[1]->addFrc(f2 - f1);
116 atoms_[2]->addFrc(f3 - f2);
117 atoms_[3]->addFrc(-f3);
120 atoms_[0]->addParticlePot(potential_);
121 atoms_[1]->addParticlePot(potential_);
122 atoms_[2]->addParticlePot(potential_);
123 atoms_[3]->addParticlePot(potential_);
126 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.