Skip to content

refactor(core): Decouple Graph and Topology Bond Orders and Enforce Strict Resonance#14

Merged
TKanX merged 74 commits intomainfrom
feature/13-decouple-bond-order-logic-and-implement-strict-resonance-perception
Dec 4, 2025
Merged

refactor(core): Decouple Graph and Topology Bond Orders and Enforce Strict Resonance#14
TKanX merged 74 commits intomainfrom
feature/13-decouple-bond-order-logic-and-implement-strict-resonance-perception

Conversation

@TKanX
Copy link
Copy Markdown
Member

@TKanX TKanX commented Dec 4, 2025

Summary:

Refactors the core bond representation to explicitly distinguish between input bond orders (GraphBondOrder) and final topology bond orders (TopologyBondOrder). This decoupling allows for precise control over how aromatic and resonant systems are perceived and represented in the output. Additionally, the integration test suite has been significantly enhanced to strictly verify these final bond orders, ensuring that resonance systems (like carboxylates, amides, and aromatic rings) are correctly identified and assigned the Resonant bond order.

Changes:

  • Decoupled Bond Order Types:

    • Introduced GraphBondOrder (Single, Double, Triple, Aromatic) for input MolecularGraph construction.
    • Introduced TopologyBondOrder (Single, Double, Triple, Resonant) for output MolecularTopology.
    • Updated all core data structures and public APIs (add_bond, Bond) to use these specific types, preventing ambiguity.
  • Implemented Strict Resonance Perception:

    • Updated the perception pipeline to correctly promote bonds within detected resonance systems (aromatic rings, carboxylates, nitro groups, etc.) to TopologyBondOrder::Resonant.
    • Non-resonant bonds retain their localized Kekulé orders (Single/Double).
  • Enhanced Test Suite:

    • Updated the MoleculeTestCase harness to include expected_bonds, allowing rigorous verification of final bond orders.
    • Refactored all existing integration tests (amino acids, nucleic acids, DREIDING paper examples) to specify both input GraphBondOrder and expected output TopologyBondOrder.
    • Added a new test case for Diglycine to verify peptide bond resonance handling.
  • Documentation and Examples:

    • Updated README.md and crate-level documentation to reflect the new GraphBondOrder API and provide correct usage examples.
    • Refined architectural documentation (01_pipeline.md) to clarify the distinction between graph and topology representations.

TKanX added 30 commits November 30, 2025 14:17
TKanX added 21 commits December 3, 2025 22:01
…on behavior in carbonyl and thioester structures
@TKanX TKanX self-assigned this Dec 4, 2025
Copilot AI review requested due to automatic review settings December 4, 2025 08:44
@TKanX TKanX added the enhancement ✨ New feature or request label Dec 4, 2025
@TKanX TKanX linked an issue Dec 4, 2025 that may be closed by this pull request
27 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

This PR refactors the core bond representation to explicitly separate input bond orders (GraphBondOrder) from output topology bond orders (TopologyBondOrder). The key innovation is replacing a generalized conjugation detection system with strict substructure matching for specific resonance motifs (carboxylates, nitro groups, amides, etc.). This ensures that aromatic and resonant systems are precisely identified and marked with TopologyBondOrder::Resonant in the final topology.

Key Changes:

  • Introduced dual bond order types: GraphBondOrder (input) and TopologyBondOrder (output) with Resonant replacing Aromatic
  • Replaced generalized Pauling-library-based resonance detection with targeted functional group matchers
  • Enhanced test harness to verify both input and expected output bond orders for all integration tests

Reviewed changes

Copilot reviewed 26 out of 28 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/core/properties.rs Added GraphBondOrder and TopologyBondOrder enums with appropriate parsing
src/core/topology.rs New file defining output topology structures using TopologyBondOrder
src/core/mod.rs Added topology module export
src/perception/resonance.rs Complete rewrite replacing Pauling integration with strict functional group detection
src/perception/model.rs Added ResonanceSystem struct, removed Pauling trait implementations
src/perception/kekulize.rs Updated to use GraphBondOrder, added has_aromatic_edge tracking
src/perception/hybridization.rs Enhanced with iterative resonance propagation logic
src/perception/mod.rs Updated tests to check is_resonant flag
tests/harness.rs Split into InputBondBlueprint and OutputBondBlueprint with verification
tests/cases/*.rs Comprehensive updates adding expected bond orders for all test cases
src/lib.rs Updated documentation examples and public API exports

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

@TKanX TKanX merged commit 0263924 into main Dec 4, 2025
8 checks passed
@TKanX TKanX deleted the feature/13-decouple-bond-order-logic-and-implement-strict-resonance-perception branch December 4, 2025 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement ✨ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decouple Bond Order Logic and Implement Strict Resonance Perception

2 participants