--- trunk/src/primitives/GhostTorsion.cpp 2010/05/10 17:28:26 1442 +++ trunk/src/primitives/GhostTorsion.cpp 2010/06/17 14:48:02 1446 @@ -56,19 +56,24 @@ namespace OpenMD { Vector3d r21 = pos1 - pos2; Vector3d r32 = pos2 - pos3; - Vector3d r43 = ghostAtom->getElectroFrame().getColumn(2); + Vector3d r43 = ghostAtom->getA().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) ;