Skip to content

fix(io): Remap Bond Indices in Topology Conversion for Non-Contiguous Atoms#24

Merged
TKanX merged 1 commit intomainfrom
bugfix/23-non-residue-contiguous-system-atoms-in-to-bio-topology-corrupts-bf-bond-flat-indices
Mar 30, 2026
Merged

fix(io): Remap Bond Indices in Topology Conversion for Non-Contiguous Atoms#24
TKanX merged 1 commit intomainfrom
bugfix/23-non-residue-contiguous-system-atoms-in-to-bio-topology-corrupts-bf-bond-flat-indices

Conversation

@TKanX
Copy link
Copy Markdown
Member

@TKanX TKanX commented Mar 30, 2026

Summary:

Resolved an issue in the to_bio_topology conversion function where Bond indices became corrupted if the input System::atoms array was not strictly ordered by residue. Because bio-forge regroups atoms into a hierarchical chain-residue structure, the flat atom indices change during conversion. This fix introduces an index remapping mechanism that translates the original atom indices to the new flat indices expected by the bio-forge topology, ensuring correct bond connectivity regardless of the initial atom ordering (e.g., when structures are constructed programmatically by tools like dreid-pack).

Changes:

  • Implemented Bond Index Remapping:

    • Modified to_bio_topology in src/io/util.rs to track the original indices of atoms as they are grouped into residues via a residue_members map.
    • Created an old_to_new mapping vector that sequentially assigns new flat indices based on the final chain and residue traversal order.
    • Updated the bf::Bond construction loop to use the remapped indices (old_to_new[bond.i] and old_to_new[bond.j]) instead of the raw input indices.
  • Added Regression Testing:

    • Introduced the to_bio_topology_remaps_bonds_for_non_contiguous_atoms unit test.
    • Verified that a System with interleaved atoms from different chains/residues correctly translates its bonds into the expected bio-forge flat indices without losing connectivity.

@TKanX TKanX self-assigned this Mar 30, 2026
Copilot AI review requested due to automatic review settings March 30, 2026 08:22
@TKanX TKanX added the bug 🐛 Something isn't working label Mar 30, 2026
@TKanX TKanX linked an issue Mar 30, 2026 that may be closed by this pull request
2 tasks
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes bond index corruption when converting a dreid-forge::System to a bio-forge::Topology if System::atoms are not contiguous by residue/chain (since bio-forge re-flattens atoms in chain→residue order).

Changes:

  • Track original atom indices while grouping atoms into residues/chains during to_bio_topology.
  • Build an old_to_new mapping based on the final traversal order and remap Bond atom indices accordingly.
  • Add a regression test covering interleaved (non-contiguous) atoms across chains/residues.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TKanX TKanX merged commit dd26d44 into main Mar 30, 2026
6 checks passed
@TKanX TKanX deleted the bugfix/23-non-residue-contiguous-system-atoms-in-to-bio-topology-corrupts-bf-bond-flat-indices branch March 30, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-Residue-Contiguous System::atoms in to_bio_topology Corrupts bf::Bond Flat Indices

2 participants