mythos.utils.math
Math utilities for DNA sequence analysis.
Functions
Convert principal axes to Tait-Bryan Euler angles. |
|
Convert Euler angles to quaternions. |
|
|
A smooth absolute value function. |
|
Clamp a value between two values. |
|
Element-wise multiplication of two arrays w/ sum reduction. |
Module Contents
- mythos.utils.math.principal_axes_to_euler_angles(x: mythos.utils.types.Arr_Nucleotide_3, y: mythos.utils.types.Arr_Nucleotide_3, z: mythos.utils.types.Arr_Nucleotide_3) tuple[mythos.utils.types.Arr_Nucleotide, mythos.utils.types.Arr_Nucleotide, mythos.utils.types.Arr_Nucleotide][source]
Convert principal axes to Tait-Bryan Euler angles.
A utility function for converting a set of principal axes (that define a rotation matrix) to a commonly used set of Tait-Bryan Euler angles.
There are two options to compute the Tait-Bryan angles. Each can be seen at the respective links: (1) From wikipedia (under Tait-Bryan angles): https://en.wikipedia.org/wiki/Euler_angles (2) Equation 10A-C: https://danceswithcode.net/engineeringnotes/rotations_in_3d/rotations_in_3d_part1.html
However, note that the definition from Wikipedia (i.e. the one using arcsin) has numerical stability issues, so we use the definition from (2) (i.e. the one using arctan2)
Note that if we were following (1), we would do: psi = onp.arcsin(x[1] / onp.sqrt(1 - x[2]**2)) theta = onp.arcsin(-x[2]) phi = onp.arcsin(y[2] / onp.sqrt(1 - x[2]**2))
Note that Tait-Bryan (i.e. Cardan) angles are not proper euler angles
- mythos.utils.math.euler_angles_to_quaternion(psi: mythos.utils.types.Arr_Nucleotide, theta: mythos.utils.types.Arr_Nucleotide, phi: mythos.utils.types.Arr_Nucleotide) mythos.utils.types.Arr_Nucleotide_4[source]
Convert Euler angles to quaternions.
A utility function for converting euler angles to quaternions. Used when converting a trajectory DataFrame to a set of states.
We follow the ZYX convention. For details, see page A-11 in https://ntrs.nasa.gov/api/citations/19770024290/downloads/19770024290.pdf from the following set of documentation: https://ntrs.nasa.gov/citations/19770024290
- mythos.utils.math.smooth_abs(x: mythos.utils.types.ARR_OR_SCALAR, eps: mythos.utils.types.Scalar = 1e-10) mythos.utils.types.ARR_OR_SCALAR[source]
A smooth absolute value function.
Note that a non-zero eps gives continuous first dervatives.