#!/usr/bin/python import os, string, sys from openeye.oechem import * #----------------------------------------------------------------------- # Check if wrong pattern (5-bonded Carbon from rxn 2) is found def get_arom_right(mol, log, ofs1): pat = OESubSearch() pat.Init('[r]([OH])([O-])') if pat.SingleMatch(mol) == 1: for atom in mol.GetAtoms(): if atom.IsCarbon() == 1: if atom.GetExplicitValence() == 5: atom.SetAromatic(0) idx_five_valent = atom.GetIdx() for bond in mol.GetBonds(): begin = bond.GetBgn() end = bond.GetEnd() if begin.GetIdx() == idx_five_valent: begin.SetAromatic(0) end.SetAromatic(0) bond.SetOrder(1) elif end.GetIdx() == idx_five_valent: begin.SetAromatic(0) end.SetAromatic(0) bond.SetOrder(1) OEWriteMolecule(ofs1, mol) log.write(mol.GetTitle()+' transformed!\n') else: OEWriteMolecule(ofs1, mol) log.write(mol.GetTitle()+' unchanged!\n') #------------------------------------------------------------------------- ifs = oemolistream() ofs_1 = oemolostream() ofs_2 = oemolostream() ofs_1.open('b2.2'+sys.argv[1]+'_ln_out.ism') ofs_2.open('b2.2'+sys.argv[1]+'_lp_out.ism') logfile = open('b2.2_filter.log','w') ifs.open('b2.1'+sys.argv[1]+'_ln.ism') for molecule in ifs.GetOEMols(): get_arom_right(molecule, logfile, ofs_1) ofs_1.close() ifs.close() ifs.open('b2.1'+sys.argv[1]+'_lp.ism') for molecule in ifs.GetOEMols(): get_arom_right(molecule, logfile, ofs_2) logfile.close() ofs_2.close() ifs.close()