#!/usr/local2/bin/python2.3 # transform sdfs to mol2 and give new titles import sys, string, os from openeye.oechem import * title_list = [] dir = os.listdir('.') for file in dir: if string.find(file, 'sdf2mol2') != -1 and file[-4:] == '.txt': title_listf = open(file, 'r') for line in title_listf.readlines(): title_list.append(line[:-1]) title_listf.close() else: pass ifs = oemolistream() ofs = oemolostream() molecule = None try: if sys.argv[2] == 'stereo': stereo = 1 print 'only chiral compounds are processed' else: stereo = 0 if sys.argv[3] == 'GS': gsorhe = '_GS' else: gsorhe = '' except IndexError: print '\nusage:\nf_sdf2mol2_singles_phopsphates.py sdf-file stereo (or xxx -> no only stereo) GS (or xxx -> no GS)\n' raise SystemExit() try: title_listf = open(sys.argv[1][:string.find(sys.argv[1], '_corina_')]+'_titles_sdf2mol2.txt', 'a') file_list = [sys.argv[1]] except IndexError: print 'usage: f_sdf2mol2_singles_phopsphates.py molfilename stereo(not mandatory)' for file in file_list: if string.find(sys.argv[1], '_p1') != -1: p1 = '1' else: p1 = '0' if string.find(file, '_lp_') != -1: ti_path = 'LP' elif string.find(file, '_ln_') != 1: ti_path = 'LN' else: ti_path = 'LN' if stereo == 1: chiral_list = [] if ti_path == 'LP': sfile = open(file[:string.find(file, '_lp')]+'_parts_split_2_dicts2.txt', 'r') elif ti_path == 'LN': sfile = open(file[:string.find(file, '_ln')]+'_parts_split_2_dicts2.txt', 'r') for line in sfile.readlines(): if string.split(line)[-1] == '1': chiral_list.append(string.split(line)[0][4:12]) ifs.open(file) for mol in ifs.GetOEMols(): if mol.NumAtoms() < 71: if stereo == 1: temp_title = mol.GetTitle() if temp_title[4:string.find(temp_title, '_')] in chiral_list: pass else: continue else: pass 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 if string.find(mol.GetTitle(), 'ZINC') != -1: pretitle = string.replace(mol.GetTitle(), 'ZINC', 'MFCD') else: pretitle =('MFCD'+mol.GetTitle()) title = pretitle+'_p'+p1+'01_'+string.lower(ring_path)+'_'+string.lower(ti_path) num = 1 ## # while title in 'titles_RING_'+ring_path+'_'+ti_path: while title in title_list: num+=1 title = pretitle+'_p'+p1+'0'+str(num)+'_'+string.lower(ring_path)+'_'+string.lower(ti_path) # 'titles_RING_'+ring_path+'_'+ti_path.append(title) mol.SetTitle(title) title_list.append(title) if os.path.exists('MOLS/RING_'+ring_path+'_SUBS_PHOS'+gsorhe+'/OH_'+ti_path+'/'+title+'.mol2') or os.path.exists('MOLS/RING_'+ring_path+'_SUBS_PHOS/OH_'+ti_path+'/'+title+'.mol2.gz'): print title, 'exists already ..... skipping !' continue else: pass ofs.open('MOLS/RING_'+ring_path+'_SUBS_PHOS'+gsorhe+'/OH_'+ti_path+'/'+title+'.mol2') OEWriteMol2File(ofs,mol) ofs.close() else: continue title_listf.write(title+'\n') title_listf.close()