#!/usr/local2/bin/python2.3 import os, string from openeye.oechem import * rxn = 4 ifs = oemolistream() ifs.open('b'+str(rxn)+'.1_ln.ism') ofs_1 = oemolostream() ofs_1.open('b'+str(rxn)+'.2_ln.ism') logfile = open('b'+str(rxn)+'.2_filter.log','w') # Check if pattern (5-bonded Carbon from rxn 1) is found for mol in ifs.GetOEMols(): pat = OESubSearch() # pat.Init('[r*][r#6]([N])([OH])=[r!#8&!#6]') << don't know why, but is not recognized reliably! >> pat.Init('[r]([N])([O-])') if pat.SingleMatch(mol) == 1: for atom in mol.GetAtoms(): if atom.IsCarbon() == 1: if atom.GetExplicitValence() == 5: atom.SetAromatic(0) # degree = atom.GetExplicitDegree() # print 'degree', degree # valence = atom.GetExplicitValence() # print 'valence', valence idx_five_valent = atom.GetIdx() # print 'index', idx_five_valent # every bond, which connects an atom to the identified C, is reduced (or kept) to the order of 1 # the involved atoms are all set non-aromatic (also the C itself several times) 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) # print 'set begin', end.GetIdx(), begin.GetIdx() elif end.GetIdx() == idx_five_valent: begin.SetAromatic(0) end.SetAromatic(0) bond.SetOrder(1) # print 'set end', end.GetIdx(), begin.GetIdx() OEWriteMolecule(ofs_1, mol) logfile.write(mol.GetTitle()+' transformed!\n') # for Debugging # count_total = 0 # count = 0 # for atom in mol.GetAtoms(): # count_total+=1 # if atom.IsAromatic() == 1: # print 'aromatic' # degree = atom.GetExplicitDegree() # print 'degree', degree # valence = atom.GetExplicitValence() # print 'valence', valence # idx_five_valent = atom.GetIdx() # print 'index', idx_five_valent # elif atom.IsAromatic() == 0 and atom.IsInRing() == 1: # count+=1 # print 'non aromatic' # degree = atom.GetExplicitDegree() # print 'degree', degree # valence = atom.GetExplicitValence() # print 'valence', valence # idx_five_valent = atom.GetIdx() # print 'index', idx_five_valent # print count, count_total else: OEWriteMolecule(ofs_1, mol) logfile.write(mol.GetTitle()+' unchanged!\n') logfile.close() ofs_1.close() ifs.close()