Skip to content

Recursion Error in reactions2route function #34

@fredhastedt

Description

@fredhastedt

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:

  1. 'N#CCc1cnc[nH]1.[C-]#N>>N#CC(N)Cc1cnc[nH]1'
  2. 'CI.N#CC(N)Cc1cnc[nH]1>>Cn1cncc1CC(N)C#N'
  3. 'O=C[O-].Cn1cncc1CC(N)C#N>>Cn1cncc1C[C@@H](C#N)NC=O'
  4. 'Cn1cncc1C[C@@H](C#N)NC=O>>Cn1cncc1C[C@H](N)C#N'
  5. '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'
  6. '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

  1. Call reactions2route with the above list of reaction SMILES.
  2. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions