Do the templates need the same atom mapping numbers in the reactant part and the product part?
The retrosynthesis template was extracted by RDChiral, and its atom mapping numbers in the reactant (2, 3, 4) and the product (1, 2, 3, 4) part are different. The smarts string of the template is "[O;D1;H0:4]=[C:3]-[OH;D1;+0:2]>>[CH3;D1;+0:1]-[O;H0;D2;+0:2]-[C:3]=[O;D1;H0:4]".
Then I used this template to generate a reaction for the molecule "OC(C1=CC(CC)=CC=C1)=O", which led to a KeyError (atoms_rt = {a.GetAtomMapNum(): atoms_rt_map[a.GetIntProp('old_mapno')]). It seems that the problem results from inconsistent atom mapping numbers in the template. I deleted the extra atom mapping "1" in the right part of the template ("[O;D1;H0:4]=[C:3]-[OH;D1;+0:2]>>[CH3;D1;+0:1]-[O;H0;D2;+0:2]-[C:3]=[O;D1;H0:4]"), and then the code can run successfully.
Here's my code:
import rdkit.Chem as Chem
from rdchiral.template_extractor import extract_from_reaction
from rdchiral.main import rdchiralRunText
rxn_smi = '[CH3:1][C:2](=[O:3])[c:4]1[cH:5][cH:6][cH:7][cH:8][c:9]1[O:10][c:11]1[cH:12][n:13][n:14]([CH:15]([CH2:16][CH:17]2[CH2:18][CH2:19][CH2:20][CH2:21]2)[C:22](=[O:23])[O:24][CH3:28])[c:25](=[O:26])[cH:27]1>>[CH3:1][C:2](=[O:3])[c:4]1[cH:5][cH:6][cH:7][cH:8][c:9]1[O:10][c:11]1[cH:12][n:13][n:14]([CH:15]([CH2:16][CH:17]2[CH2:18][CH2:19][CH2:20][CH2:21]2)[C:22](=[O:23])[OH:24])[c:25](=[O:26])[cH:27]1'
parts = rxn_smi.split('>>')
reactants = parts[0]
products = parts[1]
rxn_id = 1
reaction_input = {
'_id': rxn_id,
'reactants': reactants,
'products': products
}
template = extract_from_reaction(reaction_input)
if template and template.get('reaction_smarts'):
smarts_str = template['reaction_smarts']
print("expected template: [O;D1;H0:4]=[C:3]-[OH;D1;+0:2]>>[CH3;D1;+0:1]-[O;H0;D2;+0:2]-[C:3]=[O;D1;H0:4]")
print(smarts_str)
outcome = rdchiralRunText(smarts_str, "OC(C1=CC(CC)=CC=C1)=O")
print(outcome_1)
#if deleting the atom mapping number "1" in the template, the outcome can be generated successfully
outcome = rdchiralRunText("[O;D1;H0:4]=[C:3]-[OH;D1;+0:2]>>[CH3;D1;+0]-[O;H0;D2;+0:2]-[C:3]=[O;D1;H0:4]", "OC(C1=CC(CC)=CC=C1)=O")
print(outcome)
Do the templates need the same atom mapping numbers in the reactant part and the product part?
The retrosynthesis template was extracted by RDChiral, and its atom mapping numbers in the reactant (2, 3, 4) and the product (1, 2, 3, 4) part are different. The smarts string of the template is "[O;D1;H0:4]=[C:3]-[OH;D1;+0:2]>>[CH3;D1;+0:1]-[O;H0;D2;+0:2]-[C:3]=[O;D1;H0:4]".
Then I used this template to generate a reaction for the molecule "OC(C1=CC(CC)=CC=C1)=O", which led to a KeyError (atoms_rt = {a.GetAtomMapNum(): atoms_rt_map[a.GetIntProp('old_mapno')]). It seems that the problem results from inconsistent atom mapping numbers in the template. I deleted the extra atom mapping "1" in the right part of the template ("[O;D1;H0:4]=[C:3]-[OH;D1;+0:2]>>[CH3;D1;+0:1]-[O;H0;D2;+0:2]-[C:3]=[O;D1;H0:4]"), and then the code can run successfully.
Here's my code: