Skip to content

Decouple Bond Order Logic and Implement Strict Resonance Perception #13

@TKanX

Description

@TKanX

Description:

This task executes a major architectural refactor to distinguish between the chemical connectivity provided by the user and the physical force field topology required for simulation. Currently, "Aromatic" is treated as a bond type that persists through the pipeline, and resonance detection relies on a broad, third-party algorithm that often over-assigns conjugation. This update separates InputBondOrder from TopologyBondOrder, ensuring that "Resonant" bonds are treated strictly as a derived property. Furthermore, the resonance perception logic will be rewritten to remove external dependencies and rely on a strict "allowlist" of motifs (Aromatic systems, Carboxylates, Nitro groups, Guanidinium, and Amides). This ensures that only chemically significant delocalization results in a partial bond order in the final topology.

Tasks:

  • Phase 1: Refactor Core Data Structures

    • In src/core/properties.rs, replace the single BondOrder enum with two distinct types:
      • InputBondOrder: Variants Single, Double, Triple, Aromatic. Used by MolecularGraph.
      • TopologyBondOrder: Variants Single, Double, Triple, Resonant. Used by MolecularTopology.
    • Update src/core/graph.rs to use InputBondOrder in MolecularGraph and BondEdge.
    • Update src/core/graph.rs to use TopologyBondOrder in the final Bond struct within MolecularTopology.
    • Update src/perception/model.rs so AnnotatedMolecule uses InputBondOrder (or a Kekulized equivalent) for internal adjacency, while preparing to store resonance metadata separately.
  • Phase 2: Reimplement Resonance Perception

    • Remove the pauling crate dependency from Cargo.toml.
    • In src/perception/model.rs, add a resonance_systems: Vec<ResonanceSystem> field to AnnotatedMolecule. A ResonanceSystem should track both atom IDs and bond IDs involved.
    • Rewrite src/perception/resonance.rs to implement Strict Resonance Detection:
      • Aromatic Import: Automatically treat all atoms and internal bonds of detected aromatic rings as a resonance system. (Note: Inter-ring bonds like in biphenyl must remain single).
      • Carboxylate Detector: Identify C(=O)O- motifs.
      • Nitro Detector: Identify N(=O)O- motifs.
      • Guanidinium Detector: Identify C(N)3+ motifs.
      • Amide Detector: Identify O=C-N motifs.
    • Ensure that is_in_conjugated_system and is_resonant atom flags are updated based solely on membership in these strict systems.
  • Phase 3: Upgrade Topology Builder

    • In src/builder/mod.rs, update the build_bonds function.
    • Logic Change: Instead of copying bond orders directly:
      • Check if a bond ID belongs to any ResonanceSystem identified in Phase 2.
      • If yes, assign TopologyBondOrder::Resonant.
      • If no, map the Kekulized InputBondOrder (Single/Double/Triple) to the corresponding TopologyBondOrder.
  • Phase 4: Verification and Cleanup

    • Update all integration tests in tests/cases/ to use the new InputBondOrder enum variants in their blueprints.
    • Verify that biphenyl-like structures correctly produce Resonant bonds within rings but a Single bond between rings.
    • Verify that Amides and Carboxylates correctly generate Resonant bond orders in the final topology.

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions