Search code examples
pythongeometrycomputational-geometryangle

Fixing dihedral angles beyond 180 degrees limit to create smooth curves


I have an output from a commercial program that contains the dihedral angles of a molecule in time. The problem comes from apparently a known quadrant issue when taking cosines, that your interval is -180 to 180, and I am not familiar with. If the dihedral would be bigger than 180, this commercial program (SHARC, for molecular dynamics simulations) understands that it is bigger than -180, creating jumps on the plots (you can see an example in the figure bellow). enter image description here Is there a correct mathematical way to convert these plots to smooth curves, even if it means to go to dihedrals higher than 180? What I am trying is to create an python program to deal with each special case, when going from 180 to -180 or vice versa, how to deal with cases near 90 or 0 degrees, by using sines and cosines... But it is becoming extremely complex, with more than 12 nested if commands inside a for loop running through the X axis. If it was only one figure, I could do it by hand, but I will have dozens of similar plots. I attach an ascii file with the that for plotting this figure.

What I would like it to look like is this: enter image description here

Thank you very much,

Cayo Gonçalves


Solution

  • Ok, I've found a pretty easy solution.

    Numpy has the unwrap function. I just need to feed the function with a vector with the angles in radians. Thank you Yves for giving me the name of the problem. This helped me find the solution.