Skip to content

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

Draft
janitha-mahanthe wants to merge 109 commits into
mainfrom
0.3-dev
Draft

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

Conversation

@janitha-mahanthe

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.

Added

  • Reaction Progression: Multi-stage reaction template generation to handle multi stage reaction progressions, copolymerizations and small molecules which needs few templates for the polymerization reactions.
  • Looping Control: A new loop control parameter in the input file to prevent the explosion of unnecessary reactions. Defaults to 5 loops, but can be optimized by setting loop: <int> or disabled entirely with loop: False.
  • Advanced Detection: Index-based functional group detection and index-based reaction detection to accurately identify reacting atoms post-first reaction.
  • Pathway Deduplication: NetworkX-based deduplication detection to actively filter redundant reaction pathways.
  • Reaction Libraries: Robust library modules for various polymer chemistries, including Epoxies, Polyamides, Polyesters, Polycarbonates, Polysiloxanes, Polyureas, Polyurethanes, and Vinyl polymers.
  • Force Field Parameters: PCFF force field additions, specifically including new s_m sulfone parameters.

Changed

  • Library Organization: Centralized the reaction libraries into dedicated modules to improve maintainability and expandability.
  • Structure Generation: Improved 3D molecule embedding to better handle highly congested polymer structures.

Removed

  • Legacy Code: Removed legacy compatibility shims (_compat.py).

Fixed

  • Improved Error handling when no reaction instances are found for the specified monomer combinations.

Closes #101, Closes #63, Closes #30, Closes #28, Closes #27, Closes #64

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.
janitha-mahanthe and others added 10 commits July 24, 2026 14:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Add vinyl polymerization support and enhance reaction libraries
@janitha-mahanthe janitha-mahanthe added this to the v0.3-beta milestone Jul 28, 2026
@janitha-mahanthe
janitha-mahanthe requested a review from Copilot July 28, 2026 20:16
@janitha-mahanthe janitha-mahanthe self-assigned this Jul 28, 2026
@janitha-mahanthe janitha-mahanthe added bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request labels Jul 28, 2026
@read-the-docs-community

read-the-docs-community Bot commented Jul 28, 2026

Copy link
Copy Markdown

Documentation build overview

📚 AutoREACTER | 🛠️ Build #33967465 | 📁 Comparing 24837c0 against latest (14c029c)

  🔍 Preview build  

3 files changed
± change_log.html
± overview.html
± supported-reactions.html

@janitha-mahanthe
janitha-mahanthe marked this pull request as ready for review July 28, 2026 20:19

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.

Pull request overview

AutoREACTER v0.3 introduces a reaction-progression workflow (iterative, index-based detection + deduplication) and reorganizes/expands the reaction + functional-group libraries, alongside input parsing extensions (loop control) and updated docs/examples/tests.

Changes:

  • Adds reaction progression loop support with index-based functional-group / reaction detection and NetworkX-backed deduplication.
  • Refactors reaction + functional-group libraries into registries/modules and expands supported polymer chemistries (incl. vinyl/TFE, epoxy-amine, siloxanes, etc.).
  • Extends input parsing with loop / max_loop_count, improves reaction-empty failure behavior, and updates docs/examples/tests.

Reviewed changes

Copilot reviewed 63 out of 63 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/test_input_parser.py Expands unit tests for input parsing/validation and loop handling.
test.ipynb Adds a scratch notebook (currently contains invalid cell content).
examples/test.json Adds example input for TFE test.
examples/test_styrene.json Adds example input for styrene test.
examples/test_glycine.json Adds example input for glycine test.
examples/test_ethelene.json Adds example input for ethene test with loop enabled.
examples/test_epoxy.json Adds example input for epoxy/amine system.
docs/source/supported-reactions.md Updates supported reaction documentation for v0.3 scope.
docs/source/change_log.md Adds a v0.3 changelog section.
AutoREACTER/sim_setup/writers/rxn_first_stage_writer.py Updates first-stage reaction LAMMPS writer to use template reaction IDs.
AutoREACTER/reaction_preparation/reaction_processor/warning_asci.py Adds an ASCII warning banner for progression loop usage.
AutoREACTER/reaction_preparation/reaction_processor/reaction_progression.py Adds iterative reaction progression engine (index-based detection + dedup).
AutoREACTER/reaction_preparation/reaction_processor/fragment_comparison.py Removes deprecated placeholder fragment comparison module.
AutoREACTER/reaction_preparation/ff_wrapper/REACTER_files_builder.py Adds LAMMPS-template deduplication during REACTER file build.
AutoREACTER/reaction_preparation/ff_wrapper/molecule_3d_preparation.py Improves 3D embedding/optimization robustness for congested/radical structures.
AutoREACTER/reaction_preparation/ff_wrapper/lunar_client/merge_builder.py Refactors LUNAR merge_input generation (tagging logic changed).
AutoREACTER/reaction_preparation/ff_wrapper/lunar_client/lunar_executor.py Tweaks LUNAR execution flags and adds logging.
AutoREACTER/reaction_preparation/ff_wrapper/ff_wrapper.py Cleans imports / type-checking around FF wrapper.
AutoREACTER/reaction_preparation/deduplication_detector.py Adds NetworkX-based deduplication for RDKit + LAMMPS templates.
AutoREACTER/input_parser.py Adds loop and max_loop_count to validated inputs.
AutoREACTER/detectors/reactions_library/vinyl_polymers.py Adds vinyl + TFE reaction templates.
AutoREACTER/detectors/reactions_library/thiol_ene_polymers.py Adds thiol-ene click polymerization template.
AutoREACTER/detectors/reactions_library/registry.py Aggregates polymer-family reaction modules into one registry.
AutoREACTER/detectors/reactions_library/polyurethanes.py Adds polyurethane / polythiourethane templates.
AutoREACTER/detectors/reactions_library/polyureas.py Adds polyurea templates.
AutoREACTER/detectors/reactions_library/polythioesters.py Adds polythioester and mixed polyester/polythioester templates.
AutoREACTER/detectors/reactions_library/polysulfides.py Adds placeholder polysulfide reactions (commented).
AutoREACTER/detectors/reactions_library/polysiloxanes.py Adds polysiloxane hydrolysis/condensation templates.
AutoREACTER/detectors/reactions_library/polyimides.py Adds placeholder polyimide reactions (commented).
AutoREACTER/detectors/reactions_library/polyethers.py Adds placeholder polyether reactions (commented).
AutoREACTER/detectors/reactions_library/polyesters.py Adds/refactors polyesterification/transesterification templates.
AutoREACTER/detectors/reactions_library/polycarbonates.py Adds polycarbonate templates.
AutoREACTER/detectors/reactions_library/polybenzimidazoles.py Adds placeholder PBI reactions (commented).
AutoREACTER/detectors/reactions_library/polyanhydrides.py Adds polyanhydride templates.
AutoREACTER/detectors/reactions_library/polyamides.py Adds polyamide + caprolactam initiation templates.
AutoREACTER/detectors/reactions_library/phenolic_resins.py Adds placeholder phenolic resin reactions (commented).
AutoREACTER/detectors/reactions_library/metathesis_polymers.py Adds placeholder metathesis reactions (commented).
AutoREACTER/detectors/reactions_library/epoxy_polymers.py Adds epoxy-amine first/second addition templates.
AutoREACTER/detectors/reactions_library/cycloaddition_polymers.py Adds placeholder cycloaddition reactions (commented).
AutoREACTER/detectors/reactions_library/init.py Exposes reactions registry API.
AutoREACTER/detectors/reactions_library.py Removes legacy monolithic reaction library module.
AutoREACTER/detectors/reaction_detector.py Switches to registry-based library + adds index-based reaction detection + errors on empty list.
AutoREACTER/detectors/functional_groups_library/vinyl_and_alkene_groups.py Adds vinyl/diene/TFE functional-group motifs.
AutoREACTER/detectors/functional_groups_library/sulfur_groups.py Adds dithiol functional-group motifs.
AutoREACTER/detectors/functional_groups_library/silicon_groups.py Adds silicon functional-group motifs.
AutoREACTER/detectors/functional_groups_library/ring_groups.py Adds di-epoxide ring motif (and placeholders).
AutoREACTER/detectors/functional_groups_library/registry.py Aggregates functional-group motifs into one registry.
AutoREACTER/detectors/functional_groups_library/oxygen_groups.py Adds diol/water motifs.
AutoREACTER/detectors/functional_groups_library/nitrogen_groups.py Adds amine motifs (primary/secondary/di-amine).
AutoREACTER/detectors/functional_groups_library/mixed_ab_groups.py Adds AB-type motifs (hydroxy-acid, amino-acid, etc.).
AutoREACTER/detectors/functional_groups_library/heterocumulene_groups.py Adds di-isocyanate motif.
AutoREACTER/detectors/functional_groups_library/halide_groups.py Adds placeholder halide motifs (commented).
AutoREACTER/detectors/functional_groups_library/carboxyl_and_carbonyl_groups.py Adds di-acid/acid-halide/ester/phosgene motifs.
AutoREACTER/detectors/functional_groups_library/aromatic_groups.py Adds placeholder aromatic motifs (commented).
AutoREACTER/detectors/functional_groups_library/active_centers.py Adds vinyl chain-end radical active-center motif.
AutoREACTER/detectors/functional_groups_library/init.py Exposes functional-group registry API.
AutoREACTER/detectors/functional_groups_library.py Removes legacy monolithic functional-group library module.
AutoREACTER/detectors/functional_groups_detector.py Switches to registry-based FG library + adds index-based FG detection metadata.
AutoREACTER/arx_cli.py Introduces a custom exception for missing generated reaction images.
AutoREACTER/_compat.py Removes legacy compatibility shims.
AutoREACTER/init.py Bumps package version to 0.3.
Comments suppressed due to low confidence (1)

docs/source/supported-reactions.md:30

  • The duplicated wording in this heading looks accidental and makes the supported-reactions list harder to scan. Consider adding “and” and using the singular/consistent form (Halide vs Halides).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread AutoREACTER/reaction_preparation/ff_wrapper/lunar_client/merge_builder.py Outdated
Comment thread AutoREACTER/sim_setup/writers/rxn_first_stage_writer.py
Comment thread tests/test_input_parser.py
Comment thread AutoREACTER/input_parser.py
Comment thread AutoREACTER/detectors/functional_groups_detector.py Outdated
Comment thread AutoREACTER/reaction_preparation/reaction_processor/warning_asci.py
Comment thread docs/source/supported-reactions.md Outdated
Comment thread test.ipynb
@janitha-mahanthe
janitha-mahanthe marked this pull request as draft July 28, 2026 20:23
janitha-mahanthe and others added 9 commits July 28, 2026 17:27
Add registry-level validation for reaction SMARTS to ensure the reserved AutoREACTER initiator atom maps are present and bonded in products. Update polyanhydride and polysiloxane templates to use the reserved maps consistently and replace legacy comments with notes.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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

3 participants