Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a5304ff
Rename reaction_template_builder package
janitha-mahanthe Mar 11, 2026
b289ea8
Implement reaction mapping pipeline
janitha-mahanthe Mar 11, 2026
11cc7ff
Integrate walker, add template mapping & image grid
janitha-mahanthe Mar 11, 2026
972b3ca
Update prepare_reactions.py
janitha-mahanthe Mar 11, 2026
2cbae0f
Update example_1.ipynb
janitha-mahanthe Mar 11, 2026
b7dd6e5
Fix utils imports, SMILES parsing and reactant names
janitha-mahanthe Mar 12, 2026
c4a192d
Refactor reaction preparation and clean debug logs
janitha-mahanthe Mar 12, 2026
933c700
Refactor prepare_reactions: typing & validations
janitha-mahanthe Mar 12, 2026
5b081aa
Update example_1.ipynb
janitha-mahanthe Mar 12, 2026
c01db2c
Refactor reaction preparation pipeline
janitha-mahanthe Mar 24, 2026
6a5b672
Refactor ReactionMetadata fields and callers
janitha-mahanthe Mar 24, 2026
302c3dd
Refactor reaction processing and validation
janitha-mahanthe Mar 24, 2026
9d55976
Use mapping dict to detect byproducts
janitha-mahanthe Mar 24, 2026
4bcf277
Refactor reaction processor and utils
janitha-mahanthe Mar 24, 2026
dab7742
Move same_reactants to ReactionInstance
janitha-mahanthe Mar 25, 2026
456473f
Refactor atom-mapping and add helpers
janitha-mahanthe Mar 30, 2026
f671ca0
Sync atom map numbers and clear isotopes
janitha-mahanthe Mar 30, 2026
efbfbb7
Refactor reaction mapping and helper functions
janitha-mahanthe Mar 30, 2026
568dcb7
Update prepare_reactions.py
janitha-mahanthe Mar 30, 2026
837fee9
Update prepare_reactions.py
janitha-mahanthe Mar 30, 2026
d7c947d
Refactor PrepareReactions: privatize helpers
janitha-mahanthe Mar 30, 2026
f11464c
Improve mapping validation and add type hints
janitha-mahanthe Mar 30, 2026
99e5e99
Refactor reaction preparation and mapping
janitha-mahanthe Mar 31, 2026
bde496f
Update AutoREACTER/reaction_preparation/reaction_processor/utils.py
janitha-mahanthe Mar 31, 2026
2aaa6bf
Clear LUNAR_ROOT_DIR variable in config.py
janitha-mahanthe Mar 31, 2026
4f34fa4
Update AutoREACTER/reaction_preparation/reaction_processor/prepare_re…
janitha-mahanthe Mar 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"python-envs.defaultEnvManager": "ms-python.python:system",
"python-envs.defaultPackageManager": "ms-python.python:pip",
"python-envs.pythonProjects": []
"python-envs.defaultEnvManager": "ms-python.python:conda",
"python-envs.defaultPackageManager": "ms-python.python:conda"
}
2 changes: 1 addition & 1 deletion AutoREACTER/detectors/functional_groups_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class MonomerEntry:
# TODO: Add more functional groups as needed from literature/user requirements.


@dataclass(slots=True, frozen=True)
@dataclass(slots=True)
class FunctionalGroupInfo:
"""
Immutable dataclass storing information about a detected functional group.
Expand Down
64 changes: 24 additions & 40 deletions AutoREACTER/detectors/reaction_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,8 @@ class EmptyReactionListError(Exception):
This should be prevented by the reaction_selection method, but this error serves as a safeguard."""
pass

@dataclass(slots=True, frozen=True)
class ReactionTemplate:
"""
Defines a generic template for a polymerization reaction.
"""
reaction_name: str
reactant_1: str # functional group name
reactant_2: Optional[str] # functional group name or None
reaction_smarts: str
same_reactants: bool
delete_atom: bool
references: dict

@dataclass(slots=True, frozen=True)
@dataclass(slots=True)
class ReactionInstance:
"""
Represents a specific instance of a reaction between identified monomers.
Expand All @@ -90,6 +78,7 @@ class ReactionInstance:
reaction_smarts: str
delete_atom: bool
references: dict
same_reactants: bool
monomer_1: MonomerRole
functional_group_1: FunctionalGroupInfo
monomer_2: Optional[MonomerRole] = None
Expand Down Expand Up @@ -118,35 +107,27 @@ def _matching_fgs(self, monomer_entry: MonomerRole, target_group_name: str) -> L
return [fg for fg in monomer_entry.functionalities if fg.fg_name == target_group_name]

def _seen_pair_key(
self,
reaction_name: str,
monomer_role_1: MonomerRole,
fg_1: FunctionalGroupInfo,
monomer_role_2: Optional[MonomerRole] = None,
fg_2: Optional[FunctionalGroupInfo] = None,
) -> Tuple:
"""
Generates a unique, order-independent key for a reaction pair to avoid duplicates.

Args:
reaction_name: Name of the reaction.
monomer_role_1: First monomer.
fg_1: First functional group.
monomer_role_2: Second monomer (optional).
fg_2: Second functional group (optional).

Returns:
A tuple representing the unique state of this reaction instance.
"""
self,
reaction_name: str,
monomer_role_1: MonomerRole,
fg_1: FunctionalGroupInfo,
monomer_role_2: Optional[MonomerRole] = None,
fg_2: Optional[FunctionalGroupInfo] = None,
) -> Tuple:

if monomer_role_2 is None or fg_2 is None:
return (reaction_name, monomer_role_1, fg_1)
return (
reaction_name,
monomer_role_1.smiles,
fg_1.fg_name
)

pair1 = (monomer_role_1.smiles, fg_1.fg_name)
pair2 = (monomer_role_2.smiles, fg_2.fg_name)

ordered = tuple(sorted([pair1, pair2]))

# Sort reactants by memory ID to ensure (A, B) and (B, A) produce the same key
ordered = tuple(sorted(
[(monomer_role_1, fg_1), (monomer_role_2, fg_2)],
key=lambda x: (id(x[0]), id(x[1]))
))
return (reaction_name, ordered[0], ordered[1])
return (reaction_name, ordered)

def reaction_detector(self, monomer_roles: List[MonomerRole]) -> List[ReactionInstance]:
"""
Expand Down Expand Up @@ -180,6 +161,7 @@ def reaction_detector(self, monomer_roles: List[MonomerRole]) -> List[ReactionIn
reaction_smarts=reaction_info["reaction"],
delete_atom=reaction_info["delete_atom"],
references=reaction_info["reference"],
same_reactants=same_reactants,
monomer_1=monomer_role,
functional_group_1=fg
)
Expand Down Expand Up @@ -210,6 +192,7 @@ def reaction_detector(self, monomer_roles: List[MonomerRole]) -> List[ReactionIn
reaction_smarts=reaction_info["reaction"],
delete_atom=reaction_info["delete_atom"],
references=reaction_info["reference"],
same_reactants=same_reactants,
monomer_1=monomer_role_i,
functional_group_1=fg_i,
monomer_2=monomer_role_j,
Expand Down Expand Up @@ -243,6 +226,7 @@ def reaction_detector(self, monomer_roles: List[MonomerRole]) -> List[ReactionIn
reaction_smarts=reaction_info["reaction"],
delete_atom=reaction_info["delete_atom"],
references=reaction_info["reference"],
same_reactants=same_reactants,
monomer_1=monomer_role,
functional_group_1=fg_1,
monomer_2=monomer_role,
Expand Down
6 changes: 3 additions & 3 deletions AutoREACTER/detectors/reactions_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def __init__(self):
},
"Hydroxy Acid Halides Hydroxy Acid Halides Polycondensation(Polyesterification)": {
"same_reactants": False,
"reactant_1": "hydroxy_acid_halides_monomer",
"reactant_2": "hydroxy_acid_halides_monomer",
"reactant_1": "hydroxy_acid_halide",
"reactant_2": "hydroxy_acid_halide",
"product": "polyester_chain",
"delete_atom": True,
"reaction": "[O;!$(OC=*):1]-[H:3].[CX3:2](=[O:5])[Cl,Br,I:4]>>[OX2:1]-[CX3:2](=[O:5]).[Cl,Br,I:4]-[H:3]",
Expand All @@ -62,7 +62,7 @@ def __init__(self):
},
"Hydroxy Acid Halides Polycondensation(Polyesterification)": {
"same_reactants": True,
"reactant_1": "hydroxy_acid_halides_monomer",
"reactant_1": "hydroxy_acid_halide",
"product": "polyester_chain",
"delete_atom": True,
"reaction": "[O;!$(OC=*):1]-[H:3].[CX3:2](=[O:5])[Cl,Br,I:4]>>[OX2:1]-[CX3:2](=[O:5]).[Cl,Br,I:4]-[H:3]",
Expand Down
Loading
Loading