You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 bothis_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.
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.
Description:
The current core typing logic in
dreid-typerincorrectly 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_Rtype 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:
-CONH-)-COO⁻)-NO₂)Currently, atoms in these groups are incorrectly assigned generic
_2types (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
_Rtype assignment to theis_aromaticflag 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
_Rtype 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_Rtype 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:
src/processor/graph.rs, add a newpub is_resonant: boolfield to theAtomViewstruct to explicitly track resonance, distinct fromis_aromatic.ChemicalStateLogic: Insrc/processor/templates.rs, introduce a newChemicalState::ResonantPlanarenum variant. Update theapply_state_changefunction to handle this new state by settingis_resonant = trueandis_aromatic = false.src/processor/perception.rs:perceive_generic_aromaticityidentifies an aromatic ring, it must set bothis_aromaticandis_resonanttotrue.perceive_generic_hybridizationfunction must be updated to useis_resonantas the primary condition for assigningHybridization::Resonant.is_resonantproperty:src/rules/mod.rs, add anis_resonant: Option<bool>field to theConditionsstruct.src/processor/typer.rs, update theTyperEngine::match_conditionsfunction to check for theis_resonantcondition from the rule.resources/dreiding.rules.toml:_Rtype rules (e.g.,C_R,N_R) to useis_resonant = trueas their condition, replacingis_aromatic = true.O_Rrule based onis_resonant = true._2type rules (e.g.,C_2,N_2) to useis_resonant = falseas a condition to ensure mutual exclusivity with_Rtypes.H_Donor_On_Sulfurrule.src/processor/templates.rs, update theactionsfor all non-aromatic resonance group templates (Amide,Carboxylate,Guanidinium,Nitro, etc.) to use the newAction::SetState(ChemicalState::ResonantPlanar). KeepAromaticfor true aromatic templates likePurineSkeleton.SulfoxideandSulfoneto correctly handle their pseudo-resonant nature as defined in the DREIDING context (tetrahedral center, resonant terminal oxygens).MoleculeTestCasedefinitions (tests/cases/) to reflect the correctedexpected_typefor all resonant atoms (e.g., changingC_2toC_Rin carboxylates). Ensure the test for Cysteine's thiol hydrogen now expectsH_. Fix any failing unit tests inprocessor/andrules/to align with the new logic.