Description
The reactions2route function in rxnutils/routes/readers.py encounters a maximum recursion depth exceeded error when processing reaction sequences that involve changes in stereochemistry. This occurs because the smiles2inchikey function is called with ignore_stereo=True, which causes molecules with different stereo configurations to be treated as identical, leading to unintended cycles in the synthesis tree. As a result, the make_dict function is called infinitely.
Example
Consider the following sequence of reactions:
'N#CCc1cnc[nH]1.[C-]#N>>N#CC(N)Cc1cnc[nH]1'
'CI.N#CC(N)Cc1cnc[nH]1>>Cn1cncc1CC(N)C#N'
'O=C[O-].Cn1cncc1CC(N)C#N>>Cn1cncc1C[C@@H](C#N)NC=O'
'Cn1cncc1C[C@@H](C#N)NC=O>>Cn1cncc1C[C@H](N)C#N'
'CC(C)C[C@H](N)C(=O)O.Cn1cncc1C[C@H](N)C#N>>CC(C)C[C@H](N)C(=O)N[C@H](C#N)Cc1cncn1C'
'CC(C)C[C@H](N)C(=O)N[C@H](C#N)Cc1cncn1C.COc1cccc2[nH]c(C(=O)O)cc12>>COc1cccc2[nH]c(C(=O)N[C@@H](CC(C)C)C(=O)N[C@H](C#N)Cc3cncn3C)cc12'
In this sequence, Cn1cncc1CC(N)C#N (achiral) is the reactant of reaction 3, but Cn1cncc1C[C@H](N)C#N (chiral) is the product of reaction 4. The product of reaction 3 is the reactant of reaction 4 thus introducing the dependency. Since ignore_stereo=True, both the chiral/achiral molecule map to the same InChI key, causing the graph to loop back, resulting in recursion.
Steps to Reproduce
- Call
reactions2route with the above list of reaction SMILES.
- Observe the recursion error:
RecursionError: maximum recursion depth exceeded.
Possible Solution
Modify the key generation to account for stereochemistry by setting ignore_stereo=False in smiles2inchikey calls, or implement a stereo-aware comparison to prevent false matches.
Environment
- Python version: 3.12
- RDKit version: 2023.9.6
- rxnutils version: 2.0.0
Description
The
reactions2routefunction inrxnutils/routes/readers.pyencounters a maximum recursion depth exceeded error when processing reaction sequences that involve changes in stereochemistry. This occurs because thesmiles2inchikeyfunction is called withignore_stereo=True, which causes molecules with different stereo configurations to be treated as identical, leading to unintended cycles in the synthesis tree. As a result, themake_dictfunction is called infinitely.Example
Consider the following sequence of reactions:
'N#CCc1cnc[nH]1.[C-]#N>>N#CC(N)Cc1cnc[nH]1''CI.N#CC(N)Cc1cnc[nH]1>>Cn1cncc1CC(N)C#N''O=C[O-].Cn1cncc1CC(N)C#N>>Cn1cncc1C[C@@H](C#N)NC=O''Cn1cncc1C[C@@H](C#N)NC=O>>Cn1cncc1C[C@H](N)C#N''CC(C)C[C@H](N)C(=O)O.Cn1cncc1C[C@H](N)C#N>>CC(C)C[C@H](N)C(=O)N[C@H](C#N)Cc1cncn1C''CC(C)C[C@H](N)C(=O)N[C@H](C#N)Cc1cncn1C.COc1cccc2[nH]c(C(=O)O)cc12>>COc1cccc2[nH]c(C(=O)N[C@@H](CC(C)C)C(=O)N[C@H](C#N)Cc3cncn3C)cc12'In this sequence,
Cn1cncc1CC(N)C#N(achiral) is the reactant of reaction 3, butCn1cncc1C[C@H](N)C#N(chiral) is the product of reaction 4. The product of reaction 3 is the reactant of reaction 4 thus introducing the dependency. Sinceignore_stereo=True, both the chiral/achiral molecule map to the same InChI key, causing the graph to loop back, resulting in recursion.Steps to Reproduce
reactions2routewith the above list of reaction SMILES.RecursionError: maximum recursion depth exceeded.Possible Solution
Modify the key generation to account for stereochemistry by setting
ignore_stereo=Falseinsmiles2inchikeycalls, or implement a stereo-aware comparison to prevent false matches.Environment