def _run_at_all_rct(rxn, mol1, mol2): library = [] rxn = rdChemReactions.ReactionFromSmarts(rdChemReactions.ReactionToSmarts(rxn)) # display(rxn) m1 = rxn.GetReactantTemplate(0) m2 = rxn.GetReactantTemplate(1) mol1_valid = mol1 is not None mol2_valid = mol2 is not None isR1 = mol1_valid and mol1.HasSubstructMatch(m1) isR2 = mol1_valid and mol1.HasSubstructMatch(m2) if isR1 and mol2_valid and mol2.HasSubstructMatch(m2): library.extend(rxn.RunReactants((mol1, mol2))) if isR2 and mol2_valid and mol2.HasSubstructMatch(m1): library.extend(rxn.RunReactants((mol2, mol1))) if library: library = list(itertools.chain(*library)) for m in library: mol = None mSmi = "" try: mSmi = Chem.MolToSmiles(m) mol = dm.to_mol(mSmi) except: pass if mol is None: try: mol.UpdatePropertyCache() mol = dm.sanitize_mol(mol) mSmi = Chem.MolToSmiles(m) mol = dm.to_mol(mSmi) except: pass if mSmi: yield mol, mSmi
def testRoundTripException(self): smarts = '[C:1]([C@:3]1([OH:24])[CH2:8][CH2:7][C@H:6]2[C@H:9]3[C@H:19]([C@@H:20]([F:22])[CH2:21][C@:4]12[CH3:5])[C@:17]1([CH3:18])[C:12](=[CH:13][C:14](=[O:23])[CH2:15][CH2:16]1)[CH:11]=[CH:10]3)#[CH:2].C(Cl)CCl.ClC1C=CC=C(C(OO)=[O:37])C=1.C(O)(C)(C)C>C(OCC)(=O)C>[C:1]([C@:3]1([OH:24])[CH2:8][CH2:7][C@H:6]2[C@H:9]3[C@H:19]([C@@H:20]([F:22])[CH2:21][C@:4]12[CH3:5])[C@:17]1([CH3:18])[C:12](=[CH:13][C:14](=[O:23])[CH2:15][CH2:16]1)[C@H:11]1[O:37][C@@H:10]31)#[CH:2]' rxn = rdChemReactions.ReactionFromSmarts(smarts) # this shouldn't throw an exception smarts = rdChemReactions.ReactionToSmarts(rxn)