Skip to content

Commit 9f29bda

Browse files
Build/numpy version (#10)
* refactor: disentangle CLI from package code * docs: update readme with PDB training example * docs: further documentation improvements * build: enable numpy 2.x, pandas 2.3 * chore: ruff
1 parent c610172 commit 9f29bda

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ dependencies = [
2929
# ... CLI & config management
3030
"typer>=0.12.5,<1", # Modern CLI framework
3131
# ... linear algebra, maths & ml
32-
"numpy>=1.25.0,<2", # TODO: Enable numpy 2.x
32+
"numpy>=1.25.0,<3",
3333
"scipy>=1.13.1,<2",
3434
# ... data tools
35-
"pandas>=2.2,<2.3", # Data manipulation and analysis # TODO: Test upper bound
35+
"pandas>=2.2,<2.4", # Data manipulation and analysis
3636
"pyarrow==17.0.0", # Columnar data format for efficient data storage and processing # TODO: Test later versions
3737
# ... bioinformatics
3838
"py3Dmol>=2.2.1,<3", # Python wrapper for 3Dmol.js

src/atomworks/io/transforms/atom_array.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,19 @@ def update_nonpoly_seq_ids(atom_array: AtomArray, chain_info_dict: dict) -> Atom
332332
return atom_array
333333

334334

335+
def _safe_to_int(x: str | int | None) -> int:
336+
"""Robustly convert values to integers: map '.', empty strings, and None to -1; parse numerics otherwise"""
337+
if x is None:
338+
return -1
339+
s = str(x).strip()
340+
if s in (".", ""):
341+
return -1
342+
try:
343+
return int(s)
344+
except Exception:
345+
return -1
346+
347+
335348
def replace_negative_res_ids_with_auth_seq_id(atom_array: AtomArray) -> AtomArray:
336349
"""
337350
Replaces res_id values of -1 with the corresponding auth_seq_id values.
@@ -350,8 +363,7 @@ def replace_negative_res_ids_with_auth_seq_id(atom_array: AtomArray) -> AtomArra
350363

351364
# Convert auth_seq_ids to int if they are strings (as they are sometimes from AF-3 predictions)
352365
if author_seq_ids.dtype.kind in "UO": # Unicode or Object (string-like)
353-
# Handle '.' values by replacing with -1, then convert to int
354-
author_seq_ids = np.where(author_seq_ids == ".", -1, author_seq_ids).astype(int)
366+
author_seq_ids = np.frompyfunc(_safe_to_int, 1, 1)(author_seq_ids).astype(int)
355367

356368
atom_array.res_id[negative_res_id_mask] = author_seq_ids[negative_res_id_mask]
357369

0 commit comments

Comments
 (0)