Skip to content

Lost string annotations because of array monkey patch #77

@francois-rozet

Description

@francois-rozet

The array monkey patch leads to atom names being lost during processing.

In [1]: import atomworks

In [2]: from biotite import structure as struct

In [3]: atoms = [struct.Atom([1, 2, 3], atom_name="C"), struct.Atom([2, 3, 4], atom_name="CA")]

In [4]: struct.array(atoms)
Out[4]: 
AtomArray([
        Atom(np.array([1., 2., 3.], dtype=float32), chain_id="", res_id=0, ins_code="", res_name="", hetero=False, atom_name="C", element=""),
        Atom(np.array([2., 3., 4.], dtype=float32), chain_id="", res_id=0, ins_code="", res_name="", hetero=False, atom_name="CA", element="")
])

In [5]: struct.array(list(struct.array(atoms)))
Out[5]: 
AtomArray([
        Atom(np.array([1., 2., 3.], dtype=float32), chain_id="", res_id=0, ins_code="", res_name="", hetero=False, atom_name="C", element=""),
        Atom(np.array([2., 3., 4.], dtype=float32), chain_id="", res_id=0, ins_code="", res_name="", hetero=False, atom_name="C", element="")
])

The issue is here:

if hasattr(atoms[0]._annot[name], "dtype"):
# (Preserve dtype if possible)
dtype = atoms[0]._annot[name].dtype
else:
dtype = type(atoms[0]._annot[name])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions