From: John Stone (
Date: Thu Aug 04 2005 - 11:08:08 CDT

  Your code looks good, and it ought to be much faster than the old
code. A quick test fed with a few million random coordinates gives
good results so far so I'm inclined to put it in. I think the old
implementation was written that way as a result of one of the old
platforms VMD was originally written on having a deficient math
library, but I think that's long since past now so the atan2 method
should be faster and more reliable.

  John Stone

On Thu, Aug 04, 2005 at 08:09:38AM -0700, Alexei Podtelezhnikov wrote:
> Hi vmd-l!
> May I suggest the following optimization to dihedral angle calculations that relies on atan2f, rather than signed_angle. It's just faster and cleaner.
> float dihedral(const float *a1,const float *a2,const float *a3,const float *a4)
> {
> float r1[3], r2[3], r3[3], n1[3], n2[3];
> vec_sub(r1, a2, a1);
> vec_sub(r2, a3, a2);
> vec_sub(r3, a4, a3);
> cross_prod(n1, r1, r2);
> cross_prod(n2, r2, r3);
> float psin = dot_prod(n1, r3) * sqrtf(dot_prod(r2, r2));
> float pcos = dot_prod(n1, n2);
> return 57.2958f * atan2f(psin, pcos);
> }
> and we're done. I would drop signed_angle if nothing else uses it.
> Thanks for vmd,
> Alexei Podtelezhnikov, Ph.D.

NIH Resource for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
Email:                 Phone: 217-244-3349
  WWW:      Fax: 217-244-6078