openbabel/openbabel — pull request #48 by andersx (2013-12-05 18:41:43+00:00)
Title: Fixing numerical instability in CalcTorsionAngle and updating OB::Set/GetTorsion accordingly

There were numerical instability in the way dihedral angles were calculated. The formula used relied on acos(x), which is ill-posed for several values of x. The old implementation also needed a workaround for a possible division by zero.
As a result it was for instance not possible to set a dihedral angle to 180, but only 179.974376548 at best. This means that errors can accumulate when setting and getting torsion angles multiple times.

This update uses atan2 instead of acos and thus does not need any checks or thresholds since there are no divisions and relevant issues regarding numerical stability are resolved in .

See for instance this discussion of torsion angles on stackexchange:
http://math.stackexchange.com/questions/47059/how-do-i-calculate-a-dihedral-angle-given-cartesian-coordinates.