fix(structure): reject atom-to-self bonds in BondList and chem_comp_bond writer#884
Open
haoyu-haoyu wants to merge 1 commit intobiotite-dev:mainfrom
Open
fix(structure): reject atom-to-self bonds in BondList and chem_comp_bond writer#884haoyu-haoyu wants to merge 1 commit intobiotite-dev:mainfrom
haoyu-haoyu wants to merge 1 commit intobiotite-dev:mainfrom
Conversation
…ond writer Fixes biotite-dev#812. A `BondList` should encode chemistry, so a bond whose two atom indices refer to the same atom is meaningless and should be rejected at the construction boundary rather than being stored. - `BondList.add_bond` raises `ValueError` when the resolved positive indices are equal, including the case where one index is given positive and the other negative (e.g. `4, -1` with `atom_count=5` both resolve to atom `4`). - `BondList.__init__` performs the same check on the bulk-add path after the per-row sort, so building a `BondList` from a numpy array that contains a self-bond row now raises rather than silently storing it. The companion concern from biotite-dev#812 — that `pdbx.set_structure()` could emit a self-bond into `chem_comp_bond` when two distinct atoms in an `AtomArray` share the same `(res_name, atom_name)` annotations — is also addressed: `_set_intra_residue_bonds` now filters bond rows where the two `atom_name` annotations are equal before deduplication, and returns `None` if no rows remain. Tests cover both `BondList` construction and `add_bond`, including the mixed positive/negative index case. Assisted-by: Claude Code
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.
Fixes #812.
A `BondList` should encode chemistry, so a bond whose two atom indices refer to the same atom is meaningless. Today both the constructor and `add_bond()` accept self-bonds silently.
Changes
Tests