Lib Calculations and math

Mathemical calculations.

idpconfgen.libs.libcalc.calc_MSMV(data)[source]

Calculate Mean, STD, Median, and Variance.

idpconfgen.libs.libcalc.calc_all_vs_all_dists(coords)[source]

Calculate the upper half of all vs. all distances.

Reproduces the operations of scipy.spatial.distance.pdist.

Parameters:

coords (np.ndarray, shape (N, 3), dtype=np.float64)

Returns:

np.ndarray, shape ((N * N - N) // 2,), dytpe=np.float64

idpconfgen.libs.libcalc.calc_angle(v1, v2, ARCCOS=<ufunc 'arccos'>, CLIP=<function clip>, DOT=<function dot>, NORM=<function norm>)[source]

Calculate the angle between two vectors.

idpconfgen.libs.libcalc.calc_torsion_angles(coords, ARCTAN2=<ufunc 'arctan2'>, CROSS=<function cross>, DIAGONAL=<function diagonal>, MATMUL=<ufunc 'matmul'>, NORM=<function norm>)[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-C), [::3]

  • omega (C-N), [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.

idpconfgen.libs.libcalc.make_axis_vectors(A, B, C)[source]

Make axis vectors.

For np.array([x,y,z]) of connected atoms A->B->C.

Example

>>> av = np.array([0.000, 0.000, 0.000])
>>> bv = np.array([1.458, 0.000, 0.000])
>>> cv = np.array([2.009, 1.420, 0.000])
>>> make_axis_vectors(av, bv, cv)
>>> (array([ 0.,  0., -1.]),
>>>  array([-1.,  0.,  0.]),
>>>  array([-0., -1., -0.]))
Parameters:

A, B, C (np.array of shape (3,).) – 3D coordinate points in space.

Returns:

tuple – Three vectors defining the of ABC plane.

idpconfgen.libs.libcalc.make_coord(theta, phi, distance, parent, xaxis, yaxis)[source]

Make a new coordinate in space.

Parameters:
  • theta (float) – The angle in radians between parent and yaxis.

  • phi (float) – The torsion angles in radians between parent-xaxis-yaxis plane and new coordinate.

  • distance (float) – The distance between parent and the new coordinate.

  • parent (np.array of shape (3,)) – The coordinate in space of the parent atom (point). The parent atom is the one that preceeds the newly added coordinate.

  • xaxis (np.array of shape (3,)) – The coordinate in space that defines the xaxis of the parent-xaxis-yaxis coordinates plane.

  • yaxis (np.array of shape (3,)) – The coordinate in space that defines the yaxis of the parent-xaxis-yaxis coordinates plane.

Returns:

np.array of shape (3,) – The new coordinate in space.

idpconfgen.libs.libcalc.make_coord_from_angles(theta, phi, distance)[source]

Make axis components from angles.

Performs:
np.array([

distance * math.cos(phi), distance * math.sin(phi) * math.cos(theta), distance * math.sin(phi) * math.sin(theta), ])

Returns:

np.array of shape (3,)

idpconfgen.libs.libcalc.make_seq_probabilities(seq, reverse=False)[source]

Make probabilites from a sequence of numbers.

Sum of probabilities is 1.

idpconfgen.libs.libcalc.multiply_upper_diagonal_raw(data, result)[source]

Calculate the upper diagonal multiplication with for loops.

The use of for-loop based calculation avoids the creation of very large arrays using numpy outer derivatives. This function is thought to be njit compiled.

Does not create new data structure. It requires the output structure to be provided. Hence, modifies in place. This was decided so because this function is thought to be jit compiled and errors with the creation of very large arrays were rising. By passing the output array as a function argument, errors related to memory freeing are avoided.

Parameters:
  • data (an interable of Numbers, of length N)

  • result (a mutable sequence, either list of np.ndarray,) – of length N*(N-1)//2

idpconfgen.libs.libcalc.rotate_coordinates_Q(coords, rot_vec, angle_rad, ARRAY=<built-in function array>, HMQ=<Mock name='mock.njit()' id='139777571626128'>, VSTACK=<function vstack>)[source]

Rotate coordinates by radians along an axis.

Rotates using quaternion operations.

Parameters:
  • coords (nd.array (N, 3), dtype=np.float64) – The coordinates to rotate.

  • rot_vec ((,3)) – A 3D space vector around which to rotate coords. Rotation vector must be a unitary vector.

  • angle_rad (float) – The angle in radians to rotate the coords.

Returns:

nd.array shape (N, 3), dtype=np.float64 – The rotated coordinates

idpconfgen.libs.libcalc.rotation_to_plane(A, B, C)[source]

Define rotations matricex for planar orientation.

Where, A->B determine the X axis, Y is the normal vector to the ABC

plane, and A is defined at 0,0,0.

Parameters:

A, B, C (np.array of shape (3,)) – The 3D coordinates, where A is the parent coordinate, B is the Xaxis and C the Yaxis.

Returns:

np.array of shape (3,3) – Rotational matrix

idpconfgen.libs.libcalc.round_radian_to_degree_bin_10(x0)[source]

Round RADIAN to the nearest 10 degree bin.

23 degrees round to 20 degrees. 27 degrees round to 30 degrees.

Parameters:

x0 (float) – The angle in radians.

Returns:

int – The nearest bind of 10 degrees according to rounding rules.

idpconfgen.libs.libcalc.sum_upper_diagonal_raw(data, result)[source]

Calculate outer sum for upper diagonal with for loops.

The use of for-loop based calculation avoids the creation of very large arrays using numpy outer derivates. This function is thought to be jut compiled.

Does not create new data structure. It requires the output structure to be provided. Hence, modifies in place. This was decided so because this function is thought to be jit compiled and errors with the creation of very large arrays were rising. By passing the output array as a function argument, errors related to memory freeing are avoided.

Parameters:
  • data (an interable of Numbers, of length N)

  • result (a mutable sequence, either list of np.ndarray,) – of length N*(N-1)//2

idpconfgen.libs.libcalc.unit_vector(vector)[source]

Calculate the unitary vector.