#!/usr/local2/bin/python2.3 import os, string from openeye.oechem import * rxn = 5 ifs = oemolistream() ifs.open('bb'+str(rxn-1)+'_ln.ism') ofs_1 = oemolostream() ofs_1.open('bb'+str(rxn)+'_lp.ism') mol_hyd = OEGraphMol() OEParseSmiles(mol_hyd, "[H]") # Reaction 3b: 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 = [] rxn_n = 1 while rxn_n < rxn: try: old_title_file = open('bb'+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: print 'bb'+str(rxn_n)+'_ln.ism not existent\n' try: old_title_file = open('bb'+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: print 'bb'+str(rxn_n)+'_lp.ism not existent\n' rxn_n+=1 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) ofs_1.close() ifs.close()