54#include "utils/Constants.hpp"
69 void Torsion::calcForce(RealType& angle,
bool doParticlePot) {
70 Vector3d pos1 = atoms_[0]->getPos();
71 Vector3d pos2 = atoms_[1]->getPos();
72 Vector3d pos3 = atoms_[2]->getPos();
73 Vector3d pos4 = atoms_[3]->getPos();
75 Vector3d r21 = pos1 - pos2;
76 snapshotMan_->getCurrentSnapshot()->wrapVector(r21);
77 Vector3d r32 = pos2 - pos3;
78 snapshotMan_->getCurrentSnapshot()->wrapVector(r32);
79 Vector3d r43 = pos3 - pos4;
80 snapshotMan_->getCurrentSnapshot()->wrapVector(r43);
83 Vector3d A =
cross(r21, r32);
84 RealType rA = A.length();
85 Vector3d B =
cross(r32, r43);
86 RealType rB = B.length();
94 if (rA * rB < OpenMD::epsilon)
return;
100 RealType cos_phi =
dot(A, B);
101 if (cos_phi > 1.0) cos_phi = 1.0;
102 if (cos_phi < -1.0) cos_phi = -1.0;
105 torsionType_->calcForce(cos_phi, potential_, dVdcosPhi);
110 Vector3d dcosdA = (cos_phi * A - B) / rA;
111 Vector3d dcosdB = (cos_phi * B - A) / rB;
113 f1 = dVdcosPhi *
cross(r32, dcosdA);
114 f2 = dVdcosPhi * (
cross(r43, dcosdB) -
cross(r21, dcosdA));
115 f3 = dVdcosPhi *
cross(dcosdB, r32);
117 atoms_[0]->addFrc(f1);
118 atoms_[1]->addFrc(f2 - f1);
119 atoms_[2]->addFrc(f3 - f2);
120 atoms_[3]->addFrc(-f3);
123 atoms_[0]->addParticlePot(potential_);
124 atoms_[1]->addParticlePot(potential_);
125 atoms_[2]->addParticlePot(potential_);
126 atoms_[3]->addParticlePot(potential_);
129 angle = acos(cos_phi) / Constants::PI * 180.0;
A ShortRangeInteraction holds some bookeeping data for bonded interactions (e.g.
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.