Improve Monomer Input Schema#42
Improve Monomer Input Schema#42janitha-mahanthe merged 13 commits intorefactor-into-class-based-structurefrom
Conversation
Add typing, docstrings and refactor ReactionDetector and related dataclasses
Insert a DeprecationWarning in AutoREACTER/detectors/detector.py to inform users the script is deprecated and will be changed in v0.2.
Update deprecation message in detectors/detector.py to clarify the CLI has been removed and clean up wording. Change SimulationSetup.force_field in input_parser.py from str | None to ForceFieldType | None and provide a sensible default value (PCFF) so simulations have an explicit default force field.
Introduce EmptyReactionListError in reaction_detector as a safeguard when no reaction instances are present. Update ReactionDetector.reaction_selection to raise this error if the list is empty and to automatically select the single detected reaction (with an informational print). In input_parser, remove the implicit default for SimulationSetup.force_field (previously defaulted to "PCFF") by setting force_field to None, requiring explicit specification. Also fix a line-wrapping/syntax issue in examples/example_1.ipynb for the functional_groups_detector call.
Introduce NonReactantsDetector (AutoREACTER/detectors/non_monomer_detector.py) to identify monomers that do not participate in detected reactions, visualize them with RDKit, and provide an interactive selection flow to retain or discard non-reactant monomers in SimulationSetup. The detector includes helpers for canonical SMILES comparison, visualization (MolsToGridImage), and a user prompt to mark monomer.status as 'discarded'. Update examples/example_1.ipynb to import and call the new detector, adding cells to generate and display non-reactants and to update the validated inputs based on user selection.
Add NonReactantsDetector that identifies monomers not participating in detected reactions using RDKit (canonical SMILES comparisons and H removal), generates grid visualizations, and provides an interactive selection UI to mark non-reactant monomers as discarded. non_monomer_detector now returns a List[MonomerEntry] of non-reactants and helper methods (_same_molecule, _same_molecule_for_initaials) were added/refactored. Also tidy imports and type formatting in input_parser (ForceFieldType/CompositionMethodType). Update examples: remove a duplicated monomer from example_1_inputs_count_mode.json and add example_1_inputs_count_mode_with_non_monomers.json demonstrating a case with non-reactant monomers.
Refactor input parsing to use a new 'replicas' section (temperatures, density, systems) instead of the old top-level composition format. Added _validate_replicas to validate replica targets and moved composition mode detection to read 'method' from replicas (supports 'counts' and 'ratio' mapped internally to existing logic). Normalized temperature and density to lists, updated SimulationSetup typing accordingly, and adjusted monomer validation to consume per-system monomer_counts or monomer_ratios (including duplicate-SMILES checks and RDKit-derived properties). Also added force_field handling and updated example JSON files to the new schema (deleted several old examples and added a ratio-mode example). Overall this change unifies replicas/target handling and enables both counts and stoichiometric ratio workflows.
There was a problem hiding this comment.
Pull request overview
This PR updates AutoREACTER’s input format to a replicas-based schema (moving monomer quantities into replicas.systems) and extends the detection workflow with a new non-reactant monomer detector, alongside refactors/documentation improvements in the reaction detector.
Changes:
- Refactors input parsing to support
replicas.systems.{monomer_counts|monomer_ratios}and updates examples accordingly. - Adds
NonReactantsDetectorand wires it into the example notebook workflow. - Refactors/documentation updates in
reaction_detector.py, plus a deprecation warning in the legacy CLI detector script.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/example_1_inputs_stoichiometry_mode.json | Removes old stoichiometry-mode example. |
| examples/example_1_inputs_ratio_mode.json | Adds new replicas-based ratio-mode example. |
| examples/example_1_inputs_count_mode_with_non_monomers.json | Adds new replicas-based counts-mode example (intended to demonstrate non-reactants). |
| examples/example_1_inputs_count_mode_FF.json | Updates force-field counts example to replicas schema. |
| examples/example_1_inputs_count_mode.json | Updates counts-mode example to replicas schema. |
| examples/example_1_inputs.json | Removes legacy v0.1-style example input. |
| examples/example_1.ipynb | Updates notebook to import/use NonReactantsDetector and new flow. |
| AutoREACTER/reaction_template_builder/run_reaction_template_pipeline.py | Removes large stale TODO/comment blocks. |
| AutoREACTER/input_parser.py | Implements replicas-based parsing + validation changes. |
| AutoREACTER/detectors/reaction_detector.py | Adds docstrings, refactors matching logic, adds new exceptions. |
| AutoREACTER/detectors/non_monomer_detector.py | Adds new detector for identifying/visualizing/selecting non-reactant monomers. |
| AutoREACTER/detectors/detector.py | Adds module-level deprecation warning for the legacy script/CLI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| from .functional_groups_detector import FunctionalGroupInfo, MonomerRole | ||
| except (ImportError, ModuleNotFoundError): | ||
| from functional_groups_detector import FunctionalGroupInfo, MonomerRole | ||
|
|
There was a problem hiding this comment.
This module imports FunctionalGroupInfo / MonomerRole from functional_groups_detector, but then redefines classes with the same names below, overriding the imports. That redundancy is confusing and can lead to subtle type mismatches across modules. Consider deleting the import and using the local definitions, or (preferably) deleting the local redefinitions and re-exporting/using the shared types from functional_groups_detector.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
@janitha-mahanthe I've opened a new pull request, #43, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@janitha-mahanthe I've opened a new pull request, #44, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@janitha-mahanthe I've opened a new pull request, #45, to work on those changes. Once the pull request is ready, I'll request review from you. |
This pull request introduces significant improvements and new functionality to the polymerization reaction detection system. The main changes include the addition of a new detector for identifying non-reacting monomers, extensive documentation and refactoring for clarity, and enhanced error handling. These updates improve the usability, maintainability, and robustness of the codebase.
Addressed issue #32 to aligns with the new replicas-based system configuration.
Key changes
replicas.systemsusingmonomer_countsormonomer_ratios.nameis now required and acts as the unique identifier used to reference monomers throughout the input file.This removes ambiguity in monomer referencing and enables reliable JSON Schema validation for user inputs.
Example
New Functionality
NonReactantsDetectorclass innon_monomer_detector.pyto identify monomers that do not participate in any detected reactions, visualize them, and provide user interaction for retaining or discarding these monomers.Documentation and Refactoring
reaction_detector.py, clarifying the purpose and attributes ofFunctionalGroupInfo,MonomerRole,ReactionTemplate,ReactionInstance, andReactionDetector. [1] [2] [3] [4]_matching_fgsmethod inReactionDetectorto use list comprehensions and type annotations for improved readability and correctness.Error Handling Improvements
SMARTSerrorfor developer-defined SMARTS pattern errors, andEmptyReactionListErrorfor handling cases where no reactions are detected but user selection is attempted.Deprecation Notice
detector.pyto inform users that the script and CLI will be removed in future versions, and to recommend using the Jupyter notebook interface.Dependency and Import Updates
reaction_detector.pyfor consistency and added missing imports for new functionality.These changes collectively enhance the detection workflow, improve user interaction, and make the codebase easier to maintain and extend.