Skip to content

Fix hydrogen mask mismatch in check_intermolecular_distance#1

Merged
SergeiNikolenko merged 2 commits into
LigandPro:mainfrom
SergeiNikolenko:fix/hydrogen-mask-mismatch
Feb 13, 2026
Merged

Fix hydrogen mask mismatch in check_intermolecular_distance#1
SergeiNikolenko merged 2 commits into
LigandPro:mainfrom
SergeiNikolenko:fix/hydrogen-mask-mismatch

Conversation

@SergeiNikolenko

Copy link
Copy Markdown
Member

Summary

  • Bug: check_intermolecular_distance() filters hydrogen atoms from torch tensors (coords_protein, atoms_protein_all) but does not filter the corresponding numpy arrays (atom_names_cond, pos_cond). A downstream boolean mask (ids_cond) derived from the filtered tensor is then used to index the unfiltered numpy arrays, causing an IndexError whenever the protein PDB contains explicit hydrogen atoms.
  • Fix: Apply the same H-filtering mask to atom_names_cond and pos_cond so all arrays stay in sync.
  • Test: Added regression test that verifies the function works with protein atoms containing explicit hydrogens.

Reproduction

This occurs with any prepared protein PDB that contains explicit H atoms (common in MD/docking pipelines). For example, loading with Chem.MolFromPDBFile(path, removeHs=True) often retains explicit H from prepared structures.

# Minimal reproduction
import numpy as np
from posebench_fast.filters.fast_filters import check_intermolecular_distance

atom_names_cond = np.array(["C", "N", "O", "C", "N", "H", "H", "H"])  # 5 heavy + 3 H
pos_cond = np.random.randn(8, 3).astype(np.float32)
# ... set up mol, pos_pred, atom_names_pred ...
# Raises: IndexError: boolean index did not match indexed array along axis 0;
#         size of axis is 8 but size of corresponding boolean axis is 5

Error traceback

fast_filters.py:295: in check_intermolecular_distance
    atom_names_cond[ids_cond], pos_cond[ids_cond]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: boolean index did not match indexed array along axis 0;
            size of axis is 8 but size of corresponding boolean axis is 5

Test plan

  • New test test_check_intermolecular_distance_with_protein_hydrogens passes with fix, fails without
  • Existing test suite (test_rmsd.py) continues to pass
  • Verified on real docking data (324 molecules, PDB with 2668 atoms including 1322 H)

When `ignore_types={"H"}`, the hydrogen atoms were filtered from the
torch tensors (`coords_protein`, `atoms_protein_all`) but not from the
corresponding numpy arrays (`atom_names_cond`, `pos_cond`). A downstream
boolean mask (`ids_cond`) derived from the filtered tensor was then used
to index the unfiltered numpy arrays, causing an IndexError whenever the
input protein PDB contained explicit hydrogen atoms.

This is common with prepared protein structures (e.g., from molecular
dynamics or docking pipelines) where explicit H atoms are present in the
PDB file.

The fix applies the same H-filtering mask to `atom_names_cond` and
`pos_cond` so that all arrays stay in sync.

Added regression test that verifies the function works correctly when
protein atoms include explicit hydrogens.
Remove unused `import pytest` (F401) and apply ruff format to
test_fast_filters.py so CI lint + format checks pass.
@SergeiNikolenko
SergeiNikolenko merged commit 51bdffb into LigandPro:main Feb 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant