#!/usr/local2/bin/python2.3 # transform sdfs to mol2 and give new titles import sys, string, os from openeye.oechem import * import MySQLdb #----------------------------------------------------------------------------- #Creates a list of already created names for mol2-files def lookup_proc_codes(): db = MySQLdb.connect(host='newelvis.ucsf.edu',passwd='secret',db='joha') c = db.cursor() c.execute('select Proc_Name from PROC_NAMES') mysql_proc_name_tupel = c.fetchall() c.close() db.close() proc_name_list = [] for namet in mysql_proc_name_tupel: for pn in namet: proc_name_list.append(pn) print 'Got Existing File Names' return proc_name_list #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- #Creates a new title for a mol def create_ntitle(ot, titles, en): db = MySQLdb.connect(host='newelvis.ucsf.edu',passwd='secret',db='joha') c = db.cursor() counter = 1 nt = 'MFCDZ'+ot+'_p00'+str(counter)+en while nt in titles: counter+=1 nt = 'MFCDZ'+ot+'_p00'+str(counter)+en print nt c.execute('insert into PROC_NAMES (Proc_Name) Values (%s)' , nt) c.close() db.close() return nt #----------------------------------------------------------------------------- try: file = sys.argv[1] except IndexError: print 'usage: sdf2mol2_mysql_names.py sdf-file(from corina+ionizer) \'_\'suffix(for Folders after ring, e.g. SUBS)' raise SystemExit() try: suffix = '_'+sys.argv[2] except IndexError: suffix = '' title_list = lookup_proc_codes() ifs = oemolistream() ofs = oemolostream() if string.find(file, '_lp_') != -1: ti_path = 'LP' elif string.find(file, '_ln_') != 1: ti_path = 'LN' else: print 'something wrong with the pattern!' raise SystemExit() ifs.open(file) for mol in ifs.GetOEMols(): OEPerceiveChiral(mol) OEFindRingAtomsAndBonds(mol) OETriposAtomTypes(mol) OETriposAtomTypeNames(mol) OETriposBondTypeNames(mol) OETriposAtomNames(mol) OEAssignAromaticFlags(mol) OEGasteigerPartialCharges(mol) count, parts = OEDetermineRingSystems(mol) if count == 0: ring_path = 'NO' elif count == 1: ring_path = 'ONE' elif count > 1: ring_path = 'MORE' else: print 'something wrong with the rings!' raise SystemExit() # Generate title, evtl new ionization state out of ionizer title = create_ntitle(mol.GetTitle(), title_list, '_'+string.lower(ring_path)+'_'+string.lower(ti_path)) title_list.append(title) mol.SetTitle(title) if os.path.exists('../MOLS/RING_'+ring_path+suffix+'/OH_'+ti_path+'/'+title+'.mol2'): print 'Error: title', title, 'not in title-list, but in mol folder ???!!!' raise SystemExit() # Are target folders existent ? if os.path.exists('../MOLS'): if os.path.exists('../MOLS/RING_'+ring_path+suffix): if os.path.exists('../MOLS/RING_'+ring_path+suffix+'/OH_'+ti_path): pass else: os.mkdir('../MOLS/RING_'+ring_path+suffix+'/OH_'+ti_path) else: os.mkdir('MOLS/RING_'+ring_path+suffix) os.mkdir('MOLS/RING_'+ring_path+suffix+'/OH_'+ti_path) else: os.mkdir('MOLS') os.mkdir('MOLS/RING_'+ring_path+suffix) os.mkdir('MOLS/RING_'+ring_path+suffix+'/OH_'+ti_path) ofs.open('../MOLS/RING_'+ring_path+suffix+'/OH_'+ti_path+'/'+title+'.mol2') OEWriteMol2File(ofs,mol) ofs.close()