#!/usr/local2/bin/python import os, sys, string 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): # Monovalent Cations rxn_1 = OEUniMolecularRxn("[Na,K:2][*:1]>>[*-:1]") # Divalent cations rxn_2 = OEUniMolecularRxn("[*:2][Ca:3][*:1]>>[*-:1].[*-:2]") 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() #---------------------------------------------- try: inputfile = sys.argv[1] outputfile = 'a3.1'+sys.argv[1][string.find(sys.argv[1], '_'):string.find(sys.argv[1], '_out')]+'_out.ism' except IndexError: print '\Usage: a3.1_sdf2ism_filter.py Molfile(sdf) -> will remove Cations !\n' raise SystemExit() remove_covalent_metals(inputfile, outputfile)