biotite.structure.apply_residue_wise

biotite.structure.apply_residue_wise(array, data, function, axis=None)[source]

Apply a function to intervals of data, where each interval corresponds to one residue.

The function takes an atom array (stack) and an data array (ndarray) of the same length. The function iterates through the residue IDs of the atom array (stack) and identifies intervals of the same ID. Then the data is partitioned into the same intervals, and each interval (also an ndarray) is put as parameter into function. Each return value is stored as element in the resulting ndarray, therefore each element corresponds to one residue.

Parameters
arrayAtomArray or AtomArrayStack

The atom array (stack) to determine the residues from.

datandarray

The data, whose intervals are the parameter for function. Must have same length as array.

functionfunction

The function must have either the form f(data) or f(data, axis) in case axis is given. Every function call must return a value with the same shape and data type.

axisint, optional

This value is given to the axis parameter of function.

Returns
processed_datandarray

Residue-wise evaluation of data by function. The size of the first dimension of this array is equal to the amount of residues.

Examples

Calculate residue-wise SASA from atom-wise SASA of a 20 residue peptide.

>>> sasa_per_atom = sasa(atom_array)
>>> print(len(sasa_per_atom))
304
>>> sasa_per_residue = apply_residue_wise(atom_array, sasa_per_atom, np.nansum)
>>> print(len(sasa_per_residue))
20
>>> print(sasa_per_residue)
[157.979 117.136  94.983 115.485 113.583  23.471  93.013 144.173  61.561
  38.885   0.792 114.053 108.568  27.888  83.583 113.016 114.318  74.281
  47.811 172.035]

Calculate the centroids of each residue for the same peptide.

>>> print(len(atom_array))
304
>>> centroids = apply_residue_wise(atom_array, atom_array.coord,
...                                np.average, axis=0)
>>> print(len(centroids))
20
>>> print(centroids)
[[-9.582  3.378 -2.073]
 [-4.670  5.816 -1.860]
 [-2.461  3.060  3.076]
 [-7.211 -0.396  1.013]
 [-4.698 -1.080 -4.284]
 [ 1.172  0.206  1.038]
 [-2.160 -2.245  3.541]
 [-3.682 -5.540 -2.895]
 [ 0.711 -5.409 -2.549]
 [ 2.002 -6.322  1.695]
 [ 2.799 -3.140  2.327]
 [ 5.901 -2.489  4.845]
 [ 6.754 -6.712  3.094]
 [ 5.699 -5.101 -1.209]
 [ 9.295 -2.970 -1.835]
 [ 5.518 -1.521 -3.473]
 [ 7.219  3.673 -0.684]
 [ 4.007  4.364  2.674]
 [ 0.341  5.575 -0.254]
 [ 1.194 10.416  1.130]]