#!/usr/bin/python import os, string, sys from openeye.oechem import * try: ifs = oemolistream() ifs.open(sys.argv[1]) ofs_1 = oemolostream() ofs_1.open('b5'+sys.argv[1][string.find(sys.argv[1], '_'):string.find(sys.argv[1], '_out')]+'_ln_out.ism') ofs_2 = oemolostream() ofs_2.open('b5'+sys.argv[1][string.find(sys.argv[1], '_'):string.find(sys.argv[1], '_out')]+'_lp_out.ism') except IndexError: print '\nUsage: b5_rxn_amidine_aromatic.py molfile\n' raise SystemExit() mol_hyd = OEGraphMol() OEParseSmiles(mol_hyd, "[OH]") # Reaction 6: OH-H nucleophilic attack at X:-C(Y)=N endocyclic or chain member) (Imine, Amidine, Guanidine) # Nothing protonated libgen1 = OELibraryGen("[A,H:4][C:1]([*:2])=[N:3].[O:100][H:99]>>[*:4][C:1]([*:2])([O-:100])[N:3][H:99]") libgen1.SetExplicitHydrogens(True) libgen1.SetValenceCorrection(False) for mol in ifs.GetOEMols(): libgen1.AddStartingMaterial(mol, 0) libgen1.AddStartingMaterial(mol_hyd, 1) mol.Clear() mol_hyd.Clear() title_list = [] for title_file in os.listdir('.'): if title_file[-11:] == '_titles.txt': print 'Open & read '+title_file titlef = open(title_file, 'r') for line in titlef.readlines(): title_list.append(line[:-1]) titlef.close() title_f = open('b5_titles.txt', 'w') for products in libgen1.GetProducts(): num = 1 prot = 0 title = products.GetTitle()+str(num)+'p'+str(prot) while title in title_list: num+=1 title = products.GetTitle()+str(num)+'p'+str(prot) title_list.append(title) products.SetTitle(title) OEWriteMolecule(ofs_1, products) title_f.write(title+'\n') ofs_1.close() ifs.close() ifs.open('b5'+sys.argv[1][string.find(sys.argv[1], '_'):string.find(sys.argv[1], '_out')]+'_ln_out.ism') mol_prot = OEGraphMol() OEParseSmiles(mol_prot, "[H]") # Leaving group X,Y: protonated libgen2 = OELibraryGen("[C:1]([!#6;!#1:2])([O-:5])[N:3].[H:98]>>[C:1]([*+:2][H:98])([O-:5])[N:3]") # Leaving group N protonated libgen3 = OELibraryGen("[*:4][C:1]([*:2])([O-:5])[N:3].[H:98]>>[*:4][C:1]([*:2])([O-:5])[N+:3][H:98]") libgen2.SetExplicitHydrogens(True) libgen2.SetValenceCorrection(False) libgen3.SetExplicitHydrogens(True) libgen3.SetValenceCorrection(False) for mol in ifs.GetOEMols(): libgen2.AddStartingMaterial(mol, 0) libgen2.AddStartingMaterial(mol_prot, 1) libgen3.AddStartingMaterial(mol, 0) libgen3.AddStartingMaterial(mol_prot, 1) mol.Clear() mol_prot.Clear() for products in libgen2.GetProducts(): prot = 0 title = products.GetTitle()[:string.find(products.GetTitle(), 'p0')]+'p'+str(prot) while title in title_list: prot+=1 title = products.GetTitle()[:string.find(products.GetTitle(), 'p')]+'p'+str(prot) title_list.append(title) products.SetTitle(title) OEWriteMolecule(ofs_2, products) title_f.write(title+'\n') for products in libgen3.GetProducts(): prot = 0 title = products.GetTitle()[:string.find(products.GetTitle(), 'p0')]+'p'+str(prot) while title in title_list: prot+=1 title = products.GetTitle()[:string.find(products.GetTitle(), 'p')]+'p'+str(prot) title_list.append(title) products.SetTitle(title) OEWriteMolecule(ofs_2, products) title_f.write(title+'\n') ifs.close() title_f.close() ofs_2.close()