Fix hydrogen mask mismatch in check_intermolecular_distance#1
Merged
SergeiNikolenko merged 2 commits intoFeb 13, 2026
Merged
Conversation
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.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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 anIndexErrorwhenever the protein PDB contains explicit hydrogen atoms.atom_names_condandpos_condso all arrays stay in sync.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.Error traceback
Test plan
test_check_intermolecular_distance_with_protein_hydrogenspasses with fix, fails withouttest_rmsd.py) continues to pass