--- trunk/src/primitives/GhostTorsion.cpp 2010/05/10 17:28:26 1442 +++ trunk/src/primitives/GhostTorsion.cpp 2013/06/16 15:15:42 1879 @@ -35,10 +35,14 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ +#include "config.h" +#include + #include "primitives/GhostTorsion.hpp" namespace OpenMD { @@ -47,7 +51,7 @@ namespace OpenMD { DirectionalAtom* ghostAtom, TorsionType *tt) : Torsion(atom1, atom2, ghostAtom, ghostAtom, tt) {} - void GhostTorsion::calcForce(RealType& angle) { + void GhostTorsion::calcForce(RealType& angle, bool doParticlePot) { DirectionalAtom* ghostAtom = static_cast(atom3_); Vector3d pos1 = atom1_->getPos(); @@ -56,19 +60,24 @@ namespace OpenMD { Vector3d r21 = pos1 - pos2; Vector3d r32 = pos2 - pos3; - Vector3d r43 = ghostAtom->getElectroFrame().getColumn(2); + Vector3d r43 = ghostAtom->getA().transpose().getColumn(2); // Calculate the cross products and distances Vector3d A = cross(r21, r32); RealType rA = A.length(); Vector3d B = cross(r32, r43); RealType rB = B.length(); - Vector3d C = cross(r32, A); - RealType rC = C.length(); + + /* + If either of the two cross product vectors is tiny, that means + the three atoms involved are colinear, and the torsion angle is + going to be undefined. The easiest check for this problem is + to use the product of the two lengths. + */ + if (rA * rB < OpenMD::epsilon) return; A.normalize(); B.normalize(); - C.normalize(); // Calculate the sin and cos RealType cos_phi = dot(A, B) ; @@ -91,9 +100,11 @@ namespace OpenMD { f3.negate(); ghostAtom->addTrq(cross(r43, f3)); - atom1_->addParticlePot(potential_); - atom2_->addParticlePot(potential_); - ghostAtom->addParticlePot(potential_); + if (doParticlePot) { + atom1_->addParticlePot(potential_); + atom2_->addParticlePot(potential_); + ghostAtom->addParticlePot(potential_); + } angle = acos(cos_phi) /M_PI * 180.0; }