Description:
This task refactors the core perception pipeline to eliminate the need for users to supply formal_charge as an input. The library's API will be simplified to accept a MolecularGraph containing only elemental identities and bond connectivity. A new, advanced perception stage will be implemented to automatically infer formal charges and lone pair counts based on established chemical principles (octet rule, valence, and common bonding patterns). This change will make the library more robust, user-friendly, and chemically intelligent, as it will be able to correctly interpret ionic species like zwitterionic amino acids, carboxylates, and ammonium groups directly from their topological structure. This evolution shifts the burden of chemical correctness from the user to the library, representing a major step towards a fully automated parameterization tool.
Tasks:
Description:
This task refactors the core perception pipeline to eliminate the need for users to supply
formal_chargeas an input. The library's API will be simplified to accept aMolecularGraphcontaining only elemental identities and bond connectivity. A new, advanced perception stage will be implemented to automatically infer formal charges and lone pair counts based on established chemical principles (octet rule, valence, and common bonding patterns). This change will make the library more robust, user-friendly, and chemically intelligent, as it will be able to correctly interpret ionic species like zwitterionic amino acids, carboxylates, and ammonium groups directly from their topological structure. This evolution shifts the burden of chemical correctness from the user to the library, representing a major step towards a fully automated parameterization tool.Tasks:
Phase 1: Update Core Data Structures and Public API
src/core/graph.rs, remove theformal_charge: i8field from theAtomNodestruct.MolecularGraph::add_atommethod signature topub fn add_atom(&mut self, element: Element) -> usize.src/processor/graph.rs, modify theAtomViewstruct to retain theformal_chargefield, as this will now be a perceived property, not an input.ProcessingGraph::newto initializeformal_chargeto a default value (e.g., 0), to be correctly populated during the perception stage.README.md,lib.rs) to reflect the new, simpleradd_atomAPI.Phase 2: Implement Charge and Lone Pair Perception Logic
src/processor/perception.rs, create a new private functionperceive_charge_and_lone_pairs(atom: &AtomView, graph: &ProcessingGraph) -> (i8, u8).+1charge.-1charge.-1charge.formal_chargeand the correspondinglone_pairscount.perceive_electron_countsto be a two-pass process: first calculate valence and bonding electrons for all atoms, then in a second pass, callperceive_charge_and_lone_pairsfor each atom. This ensures all bonding information is available for context-dependent charge inference.Phase 3: Update Downstream Logic and Templates
src/processor/templates.rs, review allFunctionalGroupTemplatedefinitions.formal_charge. For example, theCarboxylatetemplate should now match based on the newly perceivedlone_pairscount (e.g.,lone_pairs == 3for the O⁻ atom) instead offormal_charge == -1.Phase 4: Update and Expand Integration Tests
tests/harness.rs, remove thechargefield fromAtomBlueprintand updatebuild_from_blueprintto use the newadd_atomsignature.tests/cases/to remove the now-obsolete charge information.GLYCINE_ZWITTERION, etc.), nucleic acid backbones (DINUCLEOTIDE_BACKBONE), and nitro compounds (TRINITROBENZENE), must pass without modification to their expected atom types. This validates that the new perception logic is correct.N⁺perception.