You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
check_in_box(): returns atoms inside instead of outside the box #1049
check_in_box() is documented to return the indices of atoms outside the box, but it returns the indices of the atoms inside the box (the mask is not inverted).
importnumpyasnpimportbiotite.structureasstrucatoms=struc.AtomArray(3)
# Atom 0 is inside the box, atoms 1 and 2 are outsideatoms.coord=np.array([[1, 1, 1], [20, 1, 1], [-1, 1, 1]])
atoms.box=np.eye(3) *10print(struc.check_in_box(atoms))
Actual output: [0]
Expected: [1 2]
Proposed fix
Invert the mask.
The condition fractions < 1 is kept, as it is consistent with move_inside_box(), which moves an atom at a fraction of exactly 1 to 0.
Instead the docstring is corrected from 0 <= a_i <= 1 to 0 <= a_i < 1.
--- a/src/biotite/structure/integrity.py+++ b/src/biotite/structure/integrity.py
@@ def check_in_box(array: AtomArray[N]) -> NDArray1[K, np.integer]:
Coordinates are outside the box, when they cannot be represented by
a linear combination of the box vectors with scalar factors
- :math:`0 \le a_i \le 1`.+ :math:`0 \le a_i \lt 1`.
@@
box = array.box
fractions = coord_to_fraction(array.coord, box)
- return np.where(((fractions >= 0) & (fractions < 1)).all(axis=-1))[0]+ return np.where(~((fractions >= 0) & (fractions < 1)).all(axis=-1))[0]
The function returns the opposite set of atoms from its documented validation contract. A caller using it to identify, reject, or repair out-of-box atoms will act on the wrong atoms, even for a simple orthogonal box. This is a systematic correctness failure in a validation utility, not a rare boundary-only discrepancy.
Activity
padix-key commentedon Nov 26, 2026
Triage: high priority.
The function returns the opposite set of atoms from its documented validation contract. A caller using it to identify, reject, or repair out-of-box atoms will act on the wrong atoms, even for a simple orthogonal box. This is a systematic correctness failure in a validation utility, not a rare boundary-only discrepancy.
Authored by Codex