#!/usr/local2/bin/python import os, sys from openeye.oechem import * #---------------------------------------------- def remove_covalent_metals(inf, outf): ifs = oemolistream(inf) ofs = oemolostream(outf) pat = OESubSearch() pat.Init('[K,Na,Ca]') for mol in ifs.GetOEMols(): if pat.SingleMatch(mol): # libgen1 = OELibraryGen("[Na,K:2][*:1]>>[*-:1]") # libgen2 = OELibraryGen("[*:2][Mg,Ca:3][*:1]>>[*-:1].[*-:2]") # libgen1.SetExplicitHydrogens(True) # libgen1.SetValenceCorrection(False) #libgen2.SetExplicitHydrogens(True) # libgen2.SetValenceCorrection(False) # for mol in ifs.GetOEMols(): # libgen1.AddStartingMaterial(mol, 0) # libgen2.AddStartingMaterial(mol, 0) # mol.Clear() # for products in libgen1.GetProducts(): # title = products.GetTitle()[:-1] # products.SetTitle(title) # OEWriteMolecule(outf, products) # for products in libgen2.GetProducts(): # title = products.GetTitle()[:-1] # products.SetTitle(title) # OEWriteMolecule(outf, products) rxn_1 = OEUniMolecularRxn("[Na,K:2][*:1]>>[*-:1]") # Have to do Zn, Mg, Ni by hand rxn_2 = OEUniMolecularRxn("[*:2][Ca:3][*:1]>>[*-:1].[*-:2]") #rxn_1 = OEUniMolecularRxn("[Na,K:2][*:1].[H:3]>>[*:1][H:3]") #rxn_2 = OEUniMolecularRxn("[*:2][Mg,Ca:3][*:1].[H:4][H:5]>>[*:1][H:4].[*:2][H:5]") # prot = OEGraphMol() # OEParseSmiles(prot, "H") # hydr = OEGraphMol() # OEParseSmiles(hydr, "HH") rxn_1(mol) rxn_2(mol) OEWriteMolecule(ofs, mol) else: OEWriteMolecule(ofs, mol) ofs.close() #---------------------------------------------- def a3_f2f(inf, outf): ifs = oemolistream(inf) ofs = oemolostream(outf) ofs.SetFormat(OEFormat_ISM) for mol in ifs.GetOEMols(): heavy_atom = 0 for atom in mol.GetAtoms(): if atom.IsHydrogen() != 1: heavy_atom+=1 if heavy_atom <= 48 and heavy_atom > 4: OEWriteMolecule(ofs, mol) else: pass ifs.close() ofs.close() #---------------------------------------------- remove_covalent_metals('ORIGINAL_MOLS/a2_kegg_012506.ism', 'ORIGINAL_MOLS/a3.1_kegg_012506.ism') #will do a3.1_kegg_012506.ism by hand #a3_f2f('ORIGINAL_MOLS/a3.1_kegg_012506.ism', 'ORIGINAL_MOLS/a3_kegg_012506.ism')