libcalc

Calculate parameters from Molecular Dynamics data.

This module contains functions to calculate MD parameters such as:

  1. RMSDs

  2. RMSFs

  3. plane angle variation

  4. axes rotation decomposition

It contains also other functions that help on the calculation of the desirables. Those functions are also avaible for independent use.

This library contains functions that operate on different Molecular Dynamics data types. When special data types (MD analysis libraries) are used, a prefix to the function name is used, and its docstring explicitly refers to it.

When using these functions, you should always cite taurenmd together with the other library(ies) used. Read our citing reference page.

taurenmd.libs.libcalc.calc_plane_eq(p1, p2, p3)[source]

Calculate equation that defines the (p1, p2, p3) plane.

Further reading.

Parameters

p1, p2, p3 (numpy.ndarray of shape (3,)) – The three 3D coordinate points that define the plane.

Returns

tuple of length 4 – The four parameters (a, b, c, d) that defined the plane equation:

\[ax + by + cz = d\]

taurenmd.libs.libcalc.calc_plane_normal(p1, p2, p3)[source]

Calculate the normal vector for the (p1, p2, p3) plane.

Given 3 XYZ space coordinate points, calculates the normal vector of the plane defined by those points.

Parameters

p1, p2, p3 (numpy.ndarray of shape (3,)) – The three 3D coordinate points that define the plane.

Returns

Numpy array of shape (3,) – The normal vector to the (p1, p2, p3) plane. This vector is NOT an unitary vector.

taurenmd.libs.libcalc.calc_planes_angle(a1, b1, c1, a2, b2, c2, aunit='radians')[source]

Calculate the angle between two planes.

Plane 1 is defined by a1, b1, c1 plane parameters, plane 2 is defined by a2, b2, c2, where:

\[ \begin{align}\begin{aligned}a1*x + b1*y + c1*z + d = 0\\a2*x + b2*y + c2*z + d = 0\end{aligned}\end{align} \]

Read further.

Parameters
  • a1, b1, c1, a2, b2, c2 (float) – Plane parameters

  • angle (str, optional) – degrees returns angle quantity in degrees, else returns in radians.

Returns

float – The angle between plane 1 and plane 2.

taurenmd.libs.libcalc.calc_torsion_angles(coords)[source]

Calculate torsion angles from sequential coordinates.

Uses NumPy to compute angles in a vectorized fashion. Sign of the torsion angle is also calculated.

Uses Prof. Azevedo implementation: https://azevedolab.net/resources/dihedral_angle.pdf

Example

Given the sequential coords that represent a dummy molecule of four atoms:

>>> xyz = numpy.array([
>>>     [0.06360, -0.79573, 1.21644],
>>>     [-0.47370, -0.10913, 0.77737],
>>>     [-1.75288, -0.51877, 1.33236],
>>>     [-2.29018, 0.16783, 0.89329],
>>>     ])
A1—A2

A3—A4

Calculates the torsion angle in A2-A3 that would place A4 in respect to the plane (A1, A2, A3).

Likewise, for a chain of N atoms A1, …, An, calculates the torsion angles in (A2, A3) to (An-2, An-1). (A1, A2) and (An-1, An) do not have torsion angles.

If coords represent a protein backbone consisting of N, CA, and C atoms and starting at the N-terminal, the torsion angles are given by the following slices to the resulting array:

  • phi (N-CA), [2::3]

  • psi (CA-N), [::3]

  • omega (N-C), [1::3]

Parameters

coords (numpy.ndarray of shape (N>=4, 3)) – Where N is the number of atoms, must be equal or above 4.

Returns

numpy.ndarray of shape (N - 3,) – The torsion angles in radians. If you want to convert those to degrees just apply np.degrees to the returned result.

taurenmd.libs.libcalc.mda_rmsd(universe, frame_slice=None, selection='all', ref_frame=0)[source]

Calculate RMSDs observed for a selection.

Uses MDAnalysis RMSD.

Example

  • Calculate RMSDs observed for the whole system along the whole trajectory.

    >>> mda_rmsd(universe)
    
  • Calculate the RMSDs observed for selection segid A for every 10 frames.

    >>> mda_rmsd(universe, slice(0, None, 10), selection='segid A')
    
Parameters
  • MDAnalysis Universe – The MDAnalysis universe.

  • frame_slice (any, optional) – The frames in the trajectory to consider. If None considers all frames. Accepts any argument that taurenmd.libs.libio.evaluate_to_slice() can receive. Defaults to None.

  • selection (str, optional) – The selection upon which calculate the RMSDs. Defaults to 'all'.

  • ref_frames (int, optional) – The reference frame against which calculate the RMSDs. Defaults to 0.

Returns

Numpy Array – The array containing the calculated RMSDs of shape (N,), where N is the number of frames.

Raises
  • ValueError – If frame_slice is not None or slice object.

  • MDAnalysis Exceptions – Any exceptions that could come from MDAnalysis RMSF computation.

taurenmd.libs.libcalc.mda_rmsf(atom_group, frame_slice=None)[source]

Calculate RMSFs.

Uses MDAnalysis RMSF.

Parameters
Returns

Numpy Array – With the calculated RMSFs values, of shape (N,) where N are the frames sliced from frame_slice.

Raises

MDAnalysis Exceptions – Any exceptions that could come from MDAnalysis RMSF computation.

taurenmd.libs.libcalc.torsion_set(p1, p2, p3, p4_vecs)[source]

Calculate torsion angles of set torwards three initial vectors.

Same implementation as calc_torsion_angles but A1, A2, and A3 are fixed and A4 is an array of vectors. The torsion angles are calculated for A4s with respect to the fixed A1, A2, and A3.

Example

>>> torsion_set(
    [x1, y1, z1],
    [x2, y2, z2],
    [x3, y3, z3],
    [
        [x4_1, y4_1, z4_1],
        [x4_2, y4_2, z4_2],
        [x4_3, y4_3, z4_3],
        [x4_4, y4_4, z4_4],
        ...
        ],
    )
Returns

numpy.ndarray of shape (N,) – The anges in radians. Where N is the length of A4.