Skip to content

AutoREACTER v0.3: Functional group detection refactor and reaction library expansion - #103

Open
janitha-mahanthe wants to merge 175 commits into
mainfrom
0.3-dev
Open

AutoREACTER v0.3: Functional group detection refactor and reaction library expansion#103
janitha-mahanthe wants to merge 175 commits into
mainfrom
0.3-dev

Conversation

@janitha-mahanthe

@janitha-mahanthe janitha-mahanthe commented Jul 28, 2026

Copy link
Copy Markdown
Member

This pull request introduces AutoREACTER v0.3, featuring a major overhaul of the reaction progression system, advanced index-based detection, and significantly expanded polymer reaction libraries.

[0.3.0] - 2026-08-21

Added

  • Reaction progression workflow: Added iterative reaction-product generation so AutoREACTER can generate templates from products formed in earlier reaction steps. This improves support for multistage reactions, copolymerizations, and small-molecule systems where the initial monomers alone are not sufficient to generate all required polymerization templates.
  • Reaction iteration control: Added reaction_iteration_depth to control how many reaction-product iterations are attempted. The default value is 5, and the loop can be disabled by setting reaction_iteration_depth to false.
  • Index-based functional-group detection: Added index-based functional-group detection to track reactive atom positions more accurately during reaction progression.
  • Index-based reaction detection: Added index-based reaction detection so products generated in earlier reaction steps can be checked for additional valid reactions.
  • RDKit/NetworkX reaction deduplication: Added graph-based reaction deduplication to reduce redundant reaction pathways during reaction progression.
  • LAMMPS template deduplication: Added NetworkX-based LAMMPS template deduplication using generated pre-reaction templates, post-reaction templates, and map files.
  • Wildcard template support: Added support for LAMMPS wildcard map generation to reduce duplicate edge-template cases when using supported LAMMPS versions.
  • Expanded reaction libraries: Added and reorganized polymer reaction libraries for epoxy-amine, polyamide, polyester, polycarbonate, polysiloxane, polyurea, polyurethane, vinyl, and related polymerization chemistries.
  • Expanded functional-group libraries: Added modular functional-group libraries for nitrogen, oxygen, carboxyl/carbonyl, vinyl/alkene, sulfur, silicon, ring, active-center, and mixed AB-type groups.
  • TFE/vinyl support: Added support for tetrafluoroethylene and additional vinyl polymerization workflows.
  • Public API session access: Added arx.session() to expose the active AutoREACTER session for workflow inspection.
  • Unit tests: Added broader unit-test coverage for input parsing, ARX CLI behavior, reaction preparation, LUNAR client utilities, force-field wrapper components, walkers, and LAMMPS writers.
  • Documentation pages: Added new documentation pages for advanced options and template deduplication.

Changed

  • Input parser: Refactored input parsing and validation, including cleaner handling of workflow options, simulation setup fields, force-field aliases, and input schema checks.
  • Reaction-library organization: Refactored reaction libraries into dedicated modules and registries instead of relying on one monolithic reaction-library file.
  • Functional-group organization: Refactored functional-group definitions into modular registry-based libraries.
  • Reaction preparation: Refactored reaction preparation to support reaction progression, deduplication, inactive-template filtering, and clearer error handling.
  • REACTER file handling: Simplified REACTER file metadata storage by storing LAMMPS molecule paths directly on monomer entries and template/map paths directly on reaction metadata.
  • LAMMPS writers: Updated LAMMPS input writers to use the refactored REACTER metadata and filter inactive reaction templates.
  • 3D molecule preparation: Improved 3D embedding and repair handling for congested or difficult polymer structures.
  • Examples: Replaced older test-style example JSON files with cleaner v0.3 example inputs.
  • Documentation structure: Reorganized documentation into clearer user-facing and developer-facing pages.

Fixed

  • Fixed reaction progression issues where products from earlier steps were not correctly reused for later reaction detection.
  • Fixed index-alignment issues during functional-group and reaction detection.
  • Fixed radical handling for vinyl polymerization products and reaction deduplication.
  • Fixed duplicate-template detection behavior for both RDKit-level reaction metadata and LAMMPS-level template files.
  • Fixed handling of inactive or duplicate reaction templates so they are skipped in later workflow stages.
  • Fixed empty-reaction cases so AutoREACTER raises clearer errors when no valid reaction instances are found.
  • Fixed LAMMPS molecule/template file path handling after the REACTER metadata refactor.
  • Fixed cache staging behavior during output directory preparation.
  • Fixed documentation heading and toctree issues for cleaner Sphinx builds.

Removed

  • Removed legacy compatibility shims.
  • Removed unused placeholder detector, fragment-comparison, and legacy library files.
  • Removed older cluttered example JSON files in favor of focused v0.3 examples.

Closes #27, closes #28, closes #30, closes #63, closes #64, closes #101, closes #104, closes #105, closes #106.

Introduces scaffold code for upcoming reaction workflow features: a new `ReactionProgression` processor module with a configurable `MAX_LOOP` constant and placeholder `reaction_progression` method, plus an `index_based_functional_groups_detector` placeholder in `FunctionalGroupsDetector`. These changes establish integration points without altering current behavior yet.
Introduce a new `species_pool.py` module with a `PoolSpecies` dataclass to represent reaction pool entries, including monomer flags, SMILES, RDKit molecule objects, and template atom indices. Add `_populate_mols(pool)` to build RDKit molecules from monomer SMILES and initialize `template_idxes` from atom indices, centralizing species preparation logic for downstream reaction processing.
Expand `PoolSpecies` docstring to list its key attributes, and clarify `_populate_mols` documentation to note that it fills both `mol` and `template_idxes` for monomer species derived from SMILES.
- Add fg_1_indexes and fg_2_indexes fields to FunctionalGroupInfo for storing matched atom indices
- Expand functional group library with epoxy-amine polymerization entries (diepoxy, primary amine, secondary amine) with improved SMARTS and documentation
- Update reaction_rules.json with required_fgs field for epoxy_polymerization
- Add _add_progessive_chemistries stub in detected_chemistry_filter.py
- Add warning_asci.py with ASCII warning banner for reaction progression beta loop
Copy loop monomer roles before extending them, and strip atom maps/isotopes from product molecules before sanitizing or generating SMILES.
Clean up whitespace, trailing spaces, and newlines throughout the file. Reorganize section comments for better clarity (e.g., rename '--- PUBLIC ---' and '--- PIPELINE STEPS (PRIVATE) ---' to more descriptive headers). Reorder `_detect_duplicates` and `_flatten_fg_indexes` methods. Add missing newline at end of file.
Refactors _get_product_index into _get_product_idxs, which now also returns the (possibly trimmed) product molecule. When a reaction produces multiple disconnected fragments, only the largest heavy-atom fragment is kept and product atom indices are remapped accordingly. Also fixes _clean_product to operate on a copy so the original molecule is not mutated, and updates _get_product_smiles to use the cleaned copy. Adds a glycine test example JSON.
Delete placeholder/incomplete files: empty functional_groups_rules.json, reaction_rules.json, detected_chemistry_filter.py (contained unfinished logic with syntax errors), and species_pool.py.
Introduces DeduplicationDetector, which converts LAMMPS molecule-template files to NetworkX graphs and uses graph isomorphism (matching atom and bond types) to identify duplicate pre/post reaction pairs.
Reworks deduplication to compare coupled pre/post graphs using normalized atom/bond labels, adds separate LAMMPS and RDKit comparison caches, and introduces RDKit molecule graph conversion for in-memory reaction metadata. Reaction progression now accumulates reactions across iterations, disables duplicates via dedup checks, skips inactive reactions downstream, and uses a session-level monotonic reaction ID counter so generated reaction CSV IDs remain globally unique across loop passes. Also updates LUNAR config to a concrete local root path and refreshes notebook debug output.
Clean up imports, variable names, docstrings, and formatting throughout reaction_progression.py. Replace debug prints with informative log messages, improve inline comments, and apply consistent style (trailing newline, line-length wrapping).
- Move MAX_LOOP constant below imports for clarity
- Add MolSanitizeException import and improve sanitization error logging
- Instantiate DeduplicationDetector once in __init__ instead of per-loop
- Initialize all_prepared_reactions from session state to support resumption
- Rename _set_is_monomer_flag to _set_is_looped_flag with proper scoping
- Rename _length_of_active_reactions to _count_active_reactions with explicit parameter
- Add _store_reactions helper to reduce duplication
- Sync session.monomer_roles and session.reaction_metadata incrementally
- Fix loop break condition to use pre-iteration pool size
- Condense docstrings throughout
Updates the progression loop to track reactions through a single `all_prepared_reactions` list, keep `session.reaction_metadata` synchronized before and after deduplication, and base loop-break checks on the updated pool. It also simplifies list initialization typing, rewrites the method docstring for clarity, adds per-iteration reaction count logging, and replaces early return with a clean loop break followed by a single final return.
Introduces is_duplicate_pair() for topology-only comparison of (reactant, product) graph pairs without coupling them into a single graph or requiring cross-phase atom mapping. Updates compare_graphs_mol() to use this simpler approach and adds index_source parameter supporting 'template' or 'first_shell' atom-index selection. Also clears the new seen_reaction_pairs cache in reset_seen_reactions().
Remove redundant AddHs calls and mol copies for mol_reactant_1/2 in forced-reaction mode, and add swapped ordering for same-reactant cases so both orientations are tried.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@janitha-mahanthe
janitha-mahanthe requested a lite review from Copilot August 19, 2026 23:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

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

Labels

bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

4 participants