Skip to content

filter_polymer does not work with AtomArrayStack though it is documented as such. #865

@k-chrispens

Description

@k-chrispens

I am using biotite.structure.filter_polymer, and it says in the docs it should work with an AtomArrayStack, but it currently doesn't:

>>> from biotite.structure import AtomArray, stack, filter_polymer
>>> import numpy as np
>>> arrays = []
>>> for i in range(2):
...     atom_array = AtomArray(3)
...     base_coords = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
...     atom_array.coord = base_coords + i * 0.1
...     atom_array.set_annotation("chain_id", np.array(["A"] * 3))
...     atom_array.set_annotation("res_id", np.array([1, 2, 3]))
...     atom_array.set_annotation("element", np.array(["C", "C", "C"]))
...     atom_array.set_annotation("b_factor", np.array([20.0, 20.0, 20.0]))
...     atom_array.set_annotation("occupancy", np.array([1.0, 1.0, 1.0]))
...     arrays.append(atom_array)
... 
>>> atom_array_stack = stack(arrays)
>>> filter_polymer(atom_array_stack)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/python3.12/site-packages/biotite/structure/filter.py", line 380, in filter_polymer
    return np.concatenate(list(bool_idx))
                          ^^^^^^^^^^^^^^
  File "[...]/python3.12/site-packages/biotite/structure/filter.py", line 377, in <lambda>
    lambda a: np.full(len(a), check_pol(atom_array(a)), dtype=bool),
                                        ^^^^^^^^^^^^^
  File "[...]/python3.12/site-packages/biotite/structure/atoms.py", line 1192, in array
    names = sorted(atoms[0]._annot.keys())
                   ^^^^^^^^^^^^^^^
AttributeError: 'numpy.ndarray' object has no attribute '_annot'

Looking a bit deeper it seems that the np.split in filter_atoms is returning a np.ndarray rather than an Atom as expected by the downstream code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions