Skip to content

Improve Monomer Input Schema#42

Merged
janitha-mahanthe merged 13 commits intorefactor-into-class-based-structurefrom
25-v02-refactor-into-class-based
Mar 3, 2026
Merged

Improve Monomer Input Schema#42
janitha-mahanthe merged 13 commits intorefactor-into-class-based-structurefrom
25-v02-refactor-into-class-based

Conversation

@janitha-mahanthe
Copy link
Copy Markdown
Member

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

  • Monomer definitions are separated from system composition.
  • Monomer quantities are now defined inside replicas.systems using monomer_counts or monomer_ratios.
  • Monomer name is 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

"monomer_counts": {
  "tmc": 220,
  "mpd": 220,
  "CCO": 110
}

New Functionality

  • Added NonReactantsDetector class in non_monomer_detector.py to 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

  • Added comprehensive docstrings and comments to classes and methods in reaction_detector.py, clarifying the purpose and attributes of FunctionalGroupInfo, MonomerRole, ReactionTemplate, ReactionInstance, and ReactionDetector. [1] [2] [3] [4]
  • Refactored the _matching_fgs method in ReactionDetector to use list comprehensions and type annotations for improved readability and correctness.

Error Handling Improvements

  • Introduced new custom exceptions: SMARTSerror for developer-defined SMARTS pattern errors, and EmptyReactionListError for handling cases where no reactions are detected but user selection is attempted.

Deprecation Notice

  • Added a deprecation warning to detector.py to 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

  • Updated import statements in reaction_detector.py for 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.

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.
@janitha-mahanthe janitha-mahanthe added this to the v0.2-beta milestone Mar 3, 2026
@janitha-mahanthe janitha-mahanthe self-assigned this Mar 3, 2026
@janitha-mahanthe janitha-mahanthe added the enhancement New feature or request label Mar 3, 2026
@janitha-mahanthe janitha-mahanthe requested a review from Copilot March 3, 2026 21:17
Copy link
Copy Markdown

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 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 NonReactantsDetector and 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.

Comment on lines 44 to 48
try:
from .functional_groups_detector import FunctionalGroupInfo, MonomerRole
except (ImportError, ModuleNotFoundError):
from functional_groups_detector import FunctionalGroupInfo, MonomerRole

Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Copy Markdown

Copilot AI commented Mar 3, 2026

@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>
Copy link
Copy Markdown

Copilot AI commented Mar 3, 2026

@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>
@janitha-mahanthe
Copy link
Copy Markdown
Member Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Copy Markdown

Copilot AI commented Mar 3, 2026

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants