#!/usr/bin/python import os, string, sys from openeye.oechem import * try: ifs = oemolistream() ifs.open('b4.3'+sys.argv[1]+'_ln_out.ism') ofs_1 = oemolostream() ofs_1.open('b4.4'+sys.argv[1][string.find(sys.argv[1], '_'):string.find(sys.argv[1], '_ln')]+'_lp_out.ism') except IndexError: print '\nUsage: b4.4_rxn_amidine_aromatic.py molfile\n' raise SystemExit() mol_hyd = OEGraphMol() OEParseSmiles(mol_hyd, "[H]") # Reaction 4: Protonation of all possible leaving groups (amines) of reaction 3 - not doable in one step, # because in case of 2 Ns each needs to be protonated one time # protonation of leaving amine - will generate identical molecules if similar N:2 twice bonded to C:4 libgen2 = OELibraryGen("[CX4v4:1]([N:2])[O-:100].[H:99]>>[C:1]([N+:2][H:99])[O-:100]") libgen2.SetExplicitHydrogens(True) libgen2.SetValenceCorrection(False) for mol in ifs.GetOEMols(): libgen2.AddStartingMaterial(mol, 0) libgen2.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('b4_titles.txt', 'a') product_smiles = [] for products in libgen2.GetProducts(): if OECreateIsoSmiString(products) in product_smiles: continue else: product_smiles.append(OECreateIsoSmiString(products)) 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_1, products) title_f.write(title+'\n') ofs_1.close() ifs.close() title_f.close()