#!/usr/bin/python # for THIOphosphate-esters # 1) Create dictionaries; per possible leaving group with its ligands # {title_1:{leaving_group1: [ligands in triangular plane...], leaving_group2 (if existent): [ligands in triangular plane...]...} # 2) Dicitonary for chirality of the three ligands in plane (per leaving group) => are at least two of them identical => no chirality from openeye.oechem import * import os, string, sys try: date = sys.argv[1] ifs = oemolistream() ifs.open('b8.1'+date+'_ln.ism') outf1 = open('b8.2'+date+'_dicts1_temp.txt', 'w') outf2 = open('b8.2'+date+'_dicts2.txt', 'w') except IndexError: print '\nUsage: b8.2_parts_split_2.py file-identifier(e.g. mol_32007)\n' raise SystemExit() leaving_group = OESubSearch() leaving_group.Init('[Cu][O&X2&!H1&!-,N&X3&!-,S&X2&!H1&!-,F,C&X2]') phos_pat = OESubSearch() phos_pat.Init('[PX1]=[S]') leavings = {} for mol in ifs.GetOEMols(): title = mol.GetTitle() leavings[title] = {} count,parts = OEDetermineComponents(mol) pred = OEPartPred(parts) for i in xrange(1,count+1): pred.SelectPart(i) newlig = OEGraphMol() OESubsetMol(newlig, mol, pred) smiles = OECreateIsoSmiString(newlig) if phos_pat.SingleMatch(newlig) != 1 and leaving_group.SingleMatch(newlig) == 1: if smiles not in leavings[title].values(): leavings[title][smiles] = [] for j in xrange(i+1, count+1): pred.SelectPart(j) potlig = OEGraphMol() OESubsetMol(potlig, mol, pred) smiles2 = OECreateIsoSmiString(potlig) if phos_pat.SingleMatch(potlig) != 1: leavings[title][smiles].append(smiles2) for j in xrange(1, i): pred.SelectPart(j) potlig = OEGraphMol() OESubsetMol(potlig, mol, pred) smiles2 = OECreateIsoSmiString(potlig) if phos_pat.SingleMatch(newlig) != 1: leavings[title][smiles].append(smiles2) ifs.close() #print leavings ox_cop = OESubSearch() ox_cop.Init('[O-X1][Cu]') # refers to the attacking OH! # have to write files for dicts, since command OEPartPred needs different OEchem-version than the rxn-commands (might be fixed in v1.3.3) title_list = [] for title in leavings.keys(): for key in leavings[title].keys(): num = 1 newtitle = title+'_1' while newtitle in title_list: num+=1 newtitle = title+'_'+str(num) title_list.append(newtitle) outf1.write(newtitle+' '+key+' '+leavings[title][key][0]+' '+leavings[title][key][1]+'\n') old_chiral = 0 for lig in leavings[title][key]: chiral = 0 for lig2 in leavings[title][key]: lig2_smi = OEGraphMol() OEParseSmiles(lig2_smi, lig2) # if ox_cop.SingleMatch(lig2_smi) == 1: # print OECreateIsoSmiString(lig2_smi) if lig2 == lig or ox_cop.SingleMatch(lig2_smi) == 1: chiral+=1 # print chiral, old_chiral if chiral > old_chiral: old_chiral = chiral outf2.write(newtitle+' '+key+' '+str(old_chiral)+'\n') outf1.close() outf2.close() os.system('mv b8.2'+date+'_dicts1_temp.txt b8.2'+date+'_dicts1.txt') print '\nNOW:\nsource ~/login_OE_RXN_CHP\nthen invoke\nb8.3_thio_parts_connect_1.py '+date+'\n' raise SystemExit() # Ensure correct protonation inf1 = open('b8.2'+date+'_dicts1_temp.txt', 'r') outf1 = open('b8.2'+date+'_dicts1.txt', 'w') for line in inf1.readlines(): newline1 = string.replace(line, ' O[Cu] ',' [O-][Cu] ') newline2 = string.replace(newline1, ' O[Cu]\n',' [O-][Cu]\n') outf1.write(newline2) outf1.close() inf1.close() os.system('rm -f b8.2'+date+'_dicts1_temp.txt') print '\nNOW:\nsource ~/login_OE_RXN_CHP\nthen invoke\nb8.3_thio_parts_connect_1.py '+date+'\n'