Skip to content

Commit

Permalink
fix string lengths in AtomArray annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
davegrays committed Feb 14, 2025
1 parent d7df095 commit 1effc13
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/biotite/structure/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,9 +1195,18 @@ def array(atoms):
f"annotation categories as the atom at index 0"
)
array = AtomArray(len(atoms))

# Add all (also optional) annotation categories
for name in names:
array.add_annotation(name, dtype=type(atoms[0]._annot[name]))
value = atoms[0]._annot[name]
if isinstance(value, str):
# Find maximum string length across all atoms for this annotation
max_len = max(len(str(atom._annot[name])) for atom in atoms)
dtype = f"<U{max_len}"
else:
dtype = type(value)
array.add_annotation(name, dtype=dtype)

# Add all atoms to AtomArray
for i in range(len(atoms)):
for name in names:
Expand Down

0 comments on commit 1effc13

Please sign in to comment.