#!/usr/local2/bin/python2.3 import os, string from openeye.oechem import * rxn = 7 ifs = oemolistream() ifs.open('a_kegg_filter_1.sdf') ofs_1 = oemolostream() ofs_1.open('b_react_ti_'+str(rxn)+'_ln.sdf') ofs_2 = oemolostream() ofs_2.open('b_react_ti_'+str(rxn)+'_ln.ism') ofs_3 = oemolostream() ofs_3.open('b_react_ti_'+str(rxn)+'_lp.sdf') ofs_4 = oemolostream() ofs_4.open('b_react_ti_'+str(rxn)+'_lp.ism') mol_wat = OEGraphMol() OEParseSmiles(mol_wat, "O(H)H") mol_hyd = OEGraphMol() OEParseSmiles(mol_hyd, "[OH]") # Reaction 6: OH-H nucleophilic attack at X-C=N (X (not C, but c-maybe activating enough?!) endocyclic or chain member) (Imine) # Nothing protonated libgen1 = OELibraryGen("[H,A:4][C:1]([!C:2])=[N:3].[O:100][H:99]>>[H,A:4][C:1]([*:2])([O-:100])[N:3][H:99]") # Leaving group X protonated libgen2 = OELibraryGen("[H,A:4][C:1]([!#6:2])=[N:3].[O:100]([H:99])[H:98]>>[H,A:4][C:1]([*+:2][H:98])([O-:100])[N:3][H:99]") # Leaving group N protonated libgen3 = OELibraryGen("[H,A:4][C:1]([!C:2])=[N:3].[O:100]([H:99])[H:98]>>[H,A:4][C:1]([*:2])([O-:100])[N+:3]([H:98])[H:99]") # Leaving group a:4 protonated (if 3 heteroatoms at the attacked center!) libgen4 = OELibraryGen("[#7,#8,#15,#16:4][C:1]([!#6:2])=[N:3].[O:100]([H:99])[H:98]>>[A+:4]([H:98])[C:1]([*:2])([O-:100])[N:3][H:99]") libgen1.SetExplicitHydrogens(True) libgen1.SetValenceCorrection(False) libgen2.SetExplicitHydrogens(True) libgen2.SetValenceCorrection(False) libgen3.SetExplicitHydrogens(True) libgen3.SetValenceCorrection(False) libgen4.SetExplicitHydrogens(True) libgen4.SetValenceCorrection(False) mol_s = OEGraphMol() for mol in ifs.GetOEMols(): libgen1.AddStartingMaterial(mol, 0) libgen1.AddStartingMaterial(mol_hyd, 1) libgen2.AddStartingMaterial(mol, 0) libgen2.AddStartingMaterial(mol_wat, 1) libgen3.AddStartingMaterial(mol, 0) libgen3.AddStartingMaterial(mol_wat, 1) libgen4.AddStartingMaterial(mol, 0) libgen4.AddStartingMaterial(mol_wat, 1) mol.Clear() mol_wat.Clear() mol_hyd.Clear() title_list = [] rxn_n = 1 while rxn_n < rxn: try: old_title_file = open('b_react_ti_'+str(rxn_n)+'_ln.ism','r') for title in old_title_file.readlines(): title_list.append(string.split(title)[1]) old_title_file.close() except IOError: pass try: old_title_file = open('b_react_ti_'+str(rxn_n)+'_lp.ism','r') for title in old_title_file.readlines(): title_list.append(string.split(title)[1]) old_title_file.close() except IOError: pass rxn_n+=1 for products in libgen1.GetProducts(): if products.NumAtoms() < 76: num = 1 title = products.GetTitle()+str(num) while title in title_list: num+=1 title = products.GetTitle()+str(num) title_list.append(title) products.SetTitle(title) OEWriteMolecule(ofs_1, products) OEWriteMolecule(ofs_2, products) ofs_1.close() ofs_2.close() for products in libgen2.GetProducts(): if products.NumAtoms() < 76: num = 1 title = products.GetTitle()+str(num) while title in title_list: num+=1 title = products.GetTitle()+str(num) title_list.append(title) products.SetTitle(title) OEWriteMolecule(ofs_3, products) OEWriteMolecule(ofs_4, products) for products in libgen3.GetProducts(): if products.NumAtoms() < 76: num = 1 title = products.GetTitle()+str(num) while title in title_list: num+=1 title = products.GetTitle()+str(num) title_list.append(title) products.SetTitle(title) OEWriteMolecule(ofs_3, products) OEWriteMolecule(ofs_4, products) for products in libgen4.GetProducts(): if products.NumAtoms() < 76: num = 1 title = products.GetTitle()+str(num) while title in title_list: num+=1 title = products.GetTitle()+str(num) title_list.append(title) products.SetTitle(title) OEWriteMolecule(ofs_3, products) OEWriteMolecule(ofs_4, products) ofs_3.close() ofs_4.close() ifs.close()