Skip to content

refactor(core): Implement Automatic Charge and Lone Pair Perception#10

Merged
TKanX merged 29 commits intomainfrom
feature/9-evolve-api-to-infer-formal-charges-and-lone-pairs-from-molecular-graph
Oct 19, 2025
Merged

refactor(core): Implement Automatic Charge and Lone Pair Perception#10
TKanX merged 29 commits intomainfrom
feature/9-evolve-api-to-infer-formal-charges-and-lone-pairs-from-molecular-graph

Conversation

@TKanX
Copy link
Copy Markdown
Member

@TKanX TKanX commented Oct 19, 2025

Summary:

Significantly refactors the chemical perception engine to automatically infer formal charges and lone pair counts directly from the molecular graph. This enhancement simplifies the public API by removing the formal_charge parameter from MolecularGraph::add_atom, making the library more user-friendly and robust. The new perception logic uses a combination of VSEPR theory and an expert system of functional group templates to accurately model common chemical structures, including zwitterionic amino acids, oxyacid anions (e.g., carboxylates, phosphates), and hypervalent species.

Changes:

  • Simplified Public API:

    • Removed the formal_charge argument from MolecularGraph::add_atom. Users are no longer required to specify formal charges, as they are now automatically perceived.
    • Updated all documentation and examples (README.md, doc comments) to reflect the new, simpler API.
  • Implemented Advanced Chemical Perception Logic:

    • Developed a new perception algorithm (perceive_charge_and_lone_pairs) that runs during the initial processing stage.
    • The algorithm infers formal charges and lone pairs based on an atom's element, degree, and bonding patterns, assuming charge-minimized Lewis structures.
    • Expert System Integration: Enhanced the functional group template system (processor::templates) to correctly handle resonance-stabilized charged groups like carboxylates, phosphates, and nitro groups, ensuring accurate charge and hybridization assignment.
    • Added specific logic for hypervalent atoms like sulfur (in sulfoxides/sulfones) and chlorine (in perchlorates).
  • Updated Integration Test Suite:

    • Refactored the entire test suite to remove the explicit charge parameter from test case definitions (AtomBlueprint).
    • Added numerous new test cases for charged species, including all standard amino acids in their zwitterionic forms, to validate the new perception engine's accuracy.

TKanX added 29 commits October 18, 2025 16:19
@TKanX TKanX self-assigned this Oct 19, 2025
Copilot AI review requested due to automatic review settings October 19, 2025 06:07
@TKanX TKanX added documentation 📖 Improvements or additions to documentation enhancement ✨ New feature or request labels Oct 19, 2025
@TKanX TKanX linked an issue Oct 19, 2025 that may be closed by this pull request
28 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 implements automatic charge and lone pair perception in the chemical perception engine, simplifying the public API by removing the formal_charge parameter from MolecularGraph::add_atom. The new perception logic uses VSEPR theory and functional group templates to accurately model common chemical structures including zwitterionic amino acids and oxyacid anions.

  • Removed formal_charge parameter from MolecularGraph::add_atom API
  • Implemented advanced chemical perception algorithm for automatic charge/lone pair inference
  • Updated all test cases and documentation to use the simplified API

Reviewed Changes

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

Show a summary per file
File Description
tests/harness.rs Removed charge field from AtomBlueprint and updated test atom creation calls
tests/cases/nucleic_acids.rs Updated all nucleic acid test cases to use new API without charge parameters
tests/cases/dreiding_paper.rs Updated Dreiding paper test cases, including expected atom type changes for dimethyl sulfoxide
tests/cases/amino_acids.rs Updated all amino acid zwitterion test cases to use new API
src/processor/typer.rs Updated all test method calls to remove charge parameters
src/processor/templates.rs Updated template predicates to use lone pairs instead of formal charge for pattern matching
src/processor/pipeline.rs Updated test cases to use new atom creation API
src/processor/perception.rs Added comprehensive charge and lone pair perception logic with helper functions
src/processor/graph.rs Removed formal_charge field initialization in ProcessingGraph constructor
src/lib.rs Updated documentation examples to use new API
src/core/graph.rs Removed formal_charge field from AtomNode and updated add_atom method signature
src/builder/mod.rs Updated test code to remove formal_charge field reference
docs/01_pipeline.md Updated documentation to reflect removal of formal_charge field
README.md Updated example code to use new simplified API

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@TKanX TKanX merged commit 770de0e into main Oct 19, 2025
2 checks passed
@TKanX TKanX deleted the feature/9-evolve-api-to-infer-formal-charges-and-lone-pairs-from-molecular-graph branch October 19, 2025 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation 📖 Improvements or additions to documentation enhancement ✨ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evolve API to Infer Formal Charges and Lone Pairs from Molecular Graph

2 participants