Skip to content

Core Typing Logic Incorrectly Equates _R Type with Aromaticity, Failing to Type Non-Aromatic Resonance Systems #11

@TKanX

Description

@TKanX

Description:

The current core typing logic in dreid-typer incorrectly assumes that the DREIDING _R (resonant) atom type is exclusively for atoms within aromatic rings. This is a fundamental misinterpretation of the DREIDING force field paper, which defines the _R type for any sp² atom in a "resonance situation," providing aromatic rings merely as an example (e.g.).

This flaw leads to the systematic mistyping of numerous critical chemical functional groups that are resonant but not aromatic. This includes, but is not limited to:

  • Amide/peptide bonds (-CONH-)
  • Carboxylate groups (-COO⁻)
  • Guanidinium groups (as in Arginine)
  • Nitro groups (-NO₂)

Currently, atoms in these groups are incorrectly assigned generic _2 types (e.g., C_2, N_2, O_2), failing to capture their unique electronic nature. This results in incorrect force field parameter assignment downstream, as the distinct torsional and energetic properties of these resonant systems are lost.

The issue stems from the tight coupling of the _R type assignment to the is_aromatic flag in both the rule files (dreiding.rules.toml) and the chemical perception logic (processor). The perception engine's expert templates correctly identify the geometry of these groups (sp²) but fail to propagate the crucial "resonance" context to the typing engine.

The correct approach is to decouple the _R type from pure aromaticity and base its assignment on a more general "resonance" property. This requires introducing a new internal flag, is_resonant, which will be the sole determinant for _R type assignment. This flag will be set for both aromatic atoms and atoms identified as part of non-aromatic resonance systems by the expert templates.

Tasks:

  • Extend Core Data Structures: In src/processor/graph.rs, add a new pub is_resonant: bool field to the AtomView struct to explicitly track resonance, distinct from is_aromatic.
  • Enhance ChemicalState Logic: In src/processor/templates.rs, introduce a new ChemicalState::ResonantPlanar enum variant. Update the apply_state_change function to handle this new state by setting is_resonant = true and is_aromatic = false.
  • Update Chemical Perception: Modify the generic perception logic in src/processor/perception.rs:
    • When perceive_generic_aromaticity identifies an aromatic ring, it must set both is_aromatic and is_resonant to true.
    • The perceive_generic_hybridization function must be updated to use is_resonant as the primary condition for assigning Hybridization::Resonant.
  • Adapt Rule Engine: Modify the rule system to understand the new is_resonant property:
    • In src/rules/mod.rs, add an is_resonant: Option<bool> field to the Conditions struct.
    • In src/processor/typer.rs, update the TyperEngine::match_conditions function to check for the is_resonant condition from the rule.
  • Rewrite Core Typing Rules: Overhaul resources/dreiding.rules.toml:
    • Change all _R type rules (e.g., C_R, N_R) to use is_resonant = true as their condition, replacing is_aromatic = true.
    • Add a new O_R rule based on is_resonant = true.
    • Update all _2 type rules (e.g., C_2, N_2) to use is_resonant = false as a condition to ensure mutual exclusivity with _R types.
    • [Bug Fix] Remove the chemically incorrect H_Donor_On_Sulfur rule.
  • Correct Expert Templates: In src/processor/templates.rs, update the actions for all non-aromatic resonance group templates (Amide, Carboxylate, Guanidinium, Nitro, etc.) to use the new Action::SetState(ChemicalState::ResonantPlanar). Keep Aromatic for true aromatic templates like PurineSkeleton.
  • Add Missing Templates: Implement new templates for Sulfoxide and Sulfone to correctly handle their pseudo-resonant nature as defined in the DREIDING context (tetrahedral center, resonant terminal oxygens).
  • Update All Unit and Integration Tests: Systematically review and update all MoleculeTestCase definitions (tests/cases/) to reflect the corrected expected_type for all resonant atoms (e.g., changing C_2 to C_R in carboxylates). Ensure the test for Cysteine's thiol hydrogen now expects H_. Fix any failing unit tests in processor/ and rules/ to align with the new logic.

Metadata

Metadata

Assignees

Labels

bug 🐛Something isn't working

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions