48#include "primitives/GhostTorsion.hpp"
54#include "utils/Constants.hpp"
58 GhostTorsion::GhostTorsion(
Atom* atom1,
Atom* atom2,
60 Torsion(atom1, atom2, ghostAtom, ghostAtom, tt) {}
62 void GhostTorsion::calcForce(RealType& angle,
bool doParticlePot) {
63 DirectionalAtom* ghostAtom =
static_cast<DirectionalAtom*
>(atoms_[2]);
65 Vector3d pos1 = atoms_[0]->getPos();
66 Vector3d pos2 = atoms_[1]->getPos();
67 Vector3d pos3 = ghostAtom->getPos();
69 Vector3d r21 = pos1 - pos2;
70 snapshotMan_->getCurrentSnapshot()->wrapVector(r21);
71 Vector3d r32 = pos2 - pos3;
72 snapshotMan_->getCurrentSnapshot()->wrapVector(r32);
73 Vector3d r43 = ghostAtom->getA().transpose().getColumn(2);
76 Vector3d A =
cross(r21, r32);
77 RealType rA = A.length();
78 Vector3d B =
cross(r32, r43);
79 RealType rB = B.length();
87 if (rA * rB < OpenMD::epsilon)
return;
93 RealType cos_phi =
dot(A, B);
96 torsionType_->calcForce(cos_phi, potential_, dVdcosPhi);
98 Vector3d dcosdA = (cos_phi * A - B) / rA;
99 Vector3d dcosdB = (cos_phi * B - A) / rB;
101 Vector3d f1 = dVdcosPhi *
cross(r32, dcosdA);
102 Vector3d f2 = dVdcosPhi * (
cross(r43, dcosdB) -
cross(r21, dcosdA));
103 Vector3d f3 = dVdcosPhi *
cross(dcosdB, r32);
105 atoms_[0]->addFrc(f1);
106 atoms_[1]->addFrc(f2 - f1);
108 ghostAtom->addFrc(-f2);
111 ghostAtom->addTrq(
cross(r43, f3));
114 atoms_[0]->addParticlePot(potential_);
115 atoms_[1]->addParticlePot(potential_);
116 ghostAtom->addParticlePot(potential_);
119 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.