Selection Utilities#

Utility functions for selecting segments of an AtomArray

atomworks.io.utils.selection.annot_start_stop_idxs(atom_array: AtomArray | AtomArrayStack, annots: str | list[str], add_exclusive_stop: bool = False) ndarray[source]#

Computes the start and stop indices for segments in an AtomArray where any of the specified annotation(s) change.

Parameters:
  • atom_array (-) – The AtomArray to process.

  • annots (-) – The annotation(s) to consider for determining segment boundaries.

  • add_exclusive_stop (-) – If True, an exclusive stop index (the length of the AtomArray) is added to the result.

Returns:

An array of start and stop indices for segments where the annotations change.

Return type:

  • np.ndarray

Example

>>> atom_array = AtomArray(...)
>>> start_stop_idxs = annot_start_stop_idxs(atom_array, annots="chain_id", add_exclusive_stop=True)
>>> print(start_stop_idxs)
[0, 5, 10, 15]
atomworks.io.utils.selection.get_annotation(atom_array: AtomArray | AtomArrayStack, annot: str, n_body: int | None = None, default: Any = None) ndarray[source]#

Get the annotation for an AtomArray or AtomArrayStack if it exists, otherwise return the default value.

atomworks.io.utils.selection.get_residue_starts(atom_array: AtomArray | AtomArrayStack, add_exclusive_stop: bool = False) ndarray[source]#

Get the start (and optionally stop) indices of residues in an AtomArray.

More robust version of biotite.structure.residues.get_residue_starts that also differentiates between residues resulting from different transformation ids.

Backwards compatible with biotite.structure.residues.get_residue_starts if the transformation_id annotation is not present.

References