def GetFinger(lig,pro,pts,pdbid): mscore=0.0 #without volumn correction mscorev=0.0 #with volumn correction cutoff=12.0 Finger=[] #without volumn correction Fingerv=[] #with volumn correction #f1=open("%s_GlideAfinger.txt"%pdbid,'wb') f2=open("%s.num"%pdbid,'wb') #for i in range(len(dist.DC_TYPES)): # Finger.append([0]*12) #for i in range(len(dist.DC_TYPES)): # Fingerv.append([0]*12) for a1 in lig.atoms: if a1.OBAtom.IsHydrogen(): continue a1_type=pat.LigAtomTyper(a1.OBAtom) if a1_type == '': continue for a2 in pro.atoms: if a2.OBAtom.IsHydrogen(): continue a2_type=pat.ProAtomTyper(a2.OBAtom) if a2_type in ('OW',''):continue dis_type='%s-%s'%(a1_type,a2_type) if dis_type not in dist.DC_TYPES: print 'Atom pair type %s has not been defined, the following pair has been neglected.'%(dis_type) print a1.OBAtom.GetType(),a1.OBAtom.GetIdx(),a2.OBAtom.GetType(),a2.OBAtom.GetIdx() continue j=dist.DC_TYPES.index(dis_type) d=rpd.GetDistance(a1.OBAtom,a2.OBAtom) if d>=cutoff: continue k=int((d-dist.D_MIN*0.1)/dist.D_DELT*10.0) #print >>f2, "%s,%d,%.6f,%d"%(dis_type,j,d,k) print >>f2, "%s,%d,%s,%d,%.6f"%(a1_type,a1.OBAtom.GetIdx(),a2_type,a2.OBAtom.GetIdx(),d) mscorev += pts.vect[j][k][0] mscore += pts.vect[j][k][1] ''' ascore=pts.vect[j][k][0] ascorev=pts.vect[j][k][1] m=int(d/1.0) Finger[j][m]+=ascore Fingerv[j][m]+=ascorev mscore+=ascore mscorev+=ascorev CFinger=CList(Finger) CFingerv=CList(Fingerv) print CFinger for j in range(len(dist.DC_TYPES)): dist_type=dist.DC_TYPES[j] i=1 while i<12: afinger=CFinger[j][i] afingerv=CFingerv[j][i] f1.write("%s-%d%10.2f\n"%(dist_type,i-1,afinger)) f2.write("%s-%d%10.2f\n"%(dist_type,i-1,afingerv)) i=i+1 f1.close() ''' f2.close() return mscore,mscorev
def dTypeGen(alist, blist, form): sl, sr, dtlist = set(), set(), [] for a in alist: for b in blist: d, a1_type, a2_type = rpd.GetDistance( a.OBAtom, b.OBAtom), pat.LigAtomTyper( a.OBAtom), pat.ProAtomTyper(b.OBAtom) if form(d, a1_type, a2_type): sl.add(a) sr.add(b) dtlist.append((d, a1_type, a2_type)) return dtlist, len(sl), len(sr)
def GetFinger(lig,pro,pts,pdbid): mscore=0.0 #with volumn correction mscorev=0.0 #without volumn correction cutoff=12.0 Finger=[] Fingerv=[] f1=open("%s_GlideCfinger.txt"%pdbid,'wb') f2=open("%s_GlideCfingerv.txt"%pdbid,'wb') for i in range(len(dist.DC_TYPES)): Finger.append([0]*4) for i in range(len(dist.DC_TYPES)): Fingerv.append([0]*4) for a1 in lig.atoms: if a1.OBAtom.IsHydrogen(): continue a1_type=pat.LigAtomTyper(a1.OBAtom) for a2 in pro.atoms: if a2.OBAtom.IsHydrogen(): continue a2_type=pat.ProAtomTyper(a2.OBAtom) if a2_type=='OW':continue dis_type='%s-%s'%(a1_type,a2_type) if dis_type not in dist.DC_TYPES: print 'Atom pair type %s has not been defined, the following pair has been neglected.'%(dis_type) print a1.OBAtom.GetType(),a1.OBAtom.GetIdx(),a2.OBAtom.GetType(),a2.OBAtom.GetIdx() continue j=dist.DC_TYPES.index(dis_type) d=rpd.GetDistance(a1.OBAtom,a2.OBAtom) if d>=cutoff: continue k=int((d-dist.D_MIN*0.1)/dist.D_DELT*10.0) ascore=pts.vect[j][k][0] ascorev=pts.vect[j][k][1] m=int(d/3.0) Finger[j][m]+=ascore Fingerv[j][m]+=ascorev mscore+=ascore mscorev+=ascorev CFinger=CList(Finger) CFingerv=CList(Fingerv) print CFinger for j in range(len(dist.DC_TYPES)): dist_type=dist.DC_TYPES[j] for i in range(4): afinger=CFinger[j][i] afingerv=CFingerv[j][i] f1.write("%s-%d%7.2f\n"%(dist_type,i,afinger)) f2.write("%s-%d%7.2f\n"%(dist_type,i,afingerv)) f1.close() f2.close() return mscore,mscorev
def RawDisPrint(lig, pro): v = [] for a1 in lig.atoms: atom1 = a1.OBAtom ## if a1.OBAtom.IsHydrogen(): ## continue a1_type = pat.LigAtomTyper(atom1) a1_idx = -1 if a1_type in pat.LIG_TYPES: a1_idx = pat.LIG_TYPES.index(a1_type) for a2 in pro.atoms: atom2 = a2.OBAtom ## if a2.OBAtom.IsHydrogen(): ## continue distance = GetDistance(atom1, atom2) if distance >= 12.0: continue a2_type = pat.ProAtomTyper(atom2) a2_idx = -1 if a2_type in pat.PRO_TYPES: a2_idx = pat.PRO_TYPES.index(a2_type) dis_type = '%s-%s' % (a1_type, a2_type) info = FormatedOutput(atom1, atom2) line = '%s,%d,%d,%s,%.4fA\n' % (dis_type, a1_idx, a2_idx, info, distance) v.append(line) for a2 in lig.atoms: atom2 = a2.OBAtom ## if a2.OBAtom.IsHydrogen(): ## continue if atom1.GetIdx() == atom2.GetIdx(): continue distance = GetDistance(atom1, atom2) if distance >= 12.0: continue a2_type = pat.LigAtomTyper(atom2) a2_idx = -1 if a2_type in pat.LIG_TYPES: a2_idx = pat.LIG_TYPES.index(a2_type) dis_type = '#%s-%s' % (a1_type, a2_type) info = FormatedOutput(atom1, atom2) line = '%s,%d,%d,%s,%.4fA\n' % (dis_type, a1_idx, a2_idx, info, distance) v.append(line) return v
def run(self): global mutex, ligand, protein, outf, ap_iter while True: mutex.acquire() try: i, j = ap_iter.next() except StopIteration: break mutex.release() dist = protein.atoms[j].OBAtom.GetDistance(ligand.atoms[i].OBAtom) if dist >= 12.0: continue ltype = pmf_atom_typer.LigAtomTyper(ligand.atoms[i].OBAtom) if ltype == "": continue ptype = pmf_atom_typer.ProAtomTyper(protein.atoms[j].OBAtom) if ptype in ("", "HD"): continue mutex.acquire() print >> outf, "%s,%d,%s,%d,%.6f" % (ltype, i + 1, ptype, j + 1, dist) #outf.flush() mutex.release()
def do_for_each(name): _format = name[name.rfind(".") + 1:] basename = name[:name.rfind(".")] out_name = basename + ".num" pdb_id = basename.split("_")[-1] #if len(pro_atom[pdb_id]) == 0: # print "to do atom typing for %s..."%pdb_id, # sys.stdout.flush() # calc_pro_types(pdb_id) # print " Done" # sys.stdout.flush() pdb_name = "/home/xmluo/jlpeng/cMet/pdb_protein/%s_protein.pdb" % pdb_id lig = pybel.readfile(_format, name).next() pro = pybel.readfile("pdb", pdb_name).next() outf = open(out_name, "w") for al in lig.atoms: if al.OBAtom.IsHydrogen(): continue ltype = pmf_atom_typer.LigAtomTyper(al.OBAtom) lidx = al.OBAtom.GetIdx() if ltype == "": continue for j in xrange(len(pro.atoms)): ap = pro.atoms[j] if ap.OBAtom.IsHydrogen(): continue dist = ap.OBAtom.GetDistance(al.OBAtom) if dist >= cutoff: continue #ptype = pro_atom[pdb_id][j] ptype = pmf_atom_typer.ProAtomTyper(ap.OBAtom) pidx = ap.OBAtom.GetIdx() if ptype in ('', 'OW'): continue print >> outf, "%s,%d,%s,%d,%.6f" % (ltype, lidx, ptype, pidx, dist) outf.close()
def calc_pro_types(pdb_id): name = "/home/xmluo/jlpeng/cMet/pdb_protein/%s_protein.pdb" % pdb_id pro = pybel.readfile("pdb", name).next() pro_atom[pdb_id] = [None] * len(pro.atoms) for i in xrange(len(pro.atoms)): pro_atom[pdb_id][i] = pmf_atom_typer.ProAtomTyper(pro.atoms[i].OBAtom)
def dTypeGen_old(alist, blist): for a in alist: for b in blist: yield rpd.GetDistance(a.OBAtom, b.OBAtom), pat.LigAtomTyper( a.OBAtom), pat.ProAtomTyper(b.OBAtom)
def GetDscrptor(lig, pro, pts): dscrptorDict1 = dict(zip(DESCRIPTOR, [0.0] * len(DESCRIPTOR))) cutoff = 12.0 polar_type = ['CP','AP','CW','CO','CN','NC','NP','NA','ND','NR','N0',\ 'NS','OC','OA','OE','OS','OD','SO','P','SA','SD','CL',\ 'F','Br','I','ME','OW','Se'] np_type = ['CF', 'AF', 'C3'] chg_type = ['NC', 'OC'] def getScore(d, a1_type, a2_type): k = int((d - dist.D_MIN * 0.1) / dist.D_DELT * 10.0) dis_type = '%s-%s' % (a1_type, a2_type) if dis_type not in dist.DC_TYPES: return 0.0 j = dist.DC_TYPES.index(dis_type) nj_bulk = pts.vect[j][0][3] if nj_bulk < 1000: return 0.0 return pts.vect[j][k][0] def form_hbond(d, a1_type, a2_type): if d > 3.2: return False hb_a = [ 'OA', 'OW', 'OE', 'OS', 'OC', 'NA', 'N0', 'NR', 'NP', 'SA', 'SO', 'F' ] hb_d = ['OD', 'OW', 'NS', 'ND', 'NC', 'SD'] if a1_type in hb_a and a2_type in hb_d: return True elif a1_type in hb_d and a2_type in hb_a: return True return False def form_electro(d, a1_type, a2_type): if d > 12.0: return False if a1_type in chg_type and a2_type in chg_type: return True return False def form_polar(d, a1_type, a2_type): if form_hbond(d, a1_type, a2_type): return False if form_electro(d, a1_type, a2_type): return False if d > 9.0: return False if a1_type in polar_type and a2_type in polar_type: return True return False def form_np(d, a1_type, a2_type): return all([d < 6.0, a1_type in np_type, a2_type in np_type]) def dTypeGen_old(alist, blist): for a in alist: for b in blist: yield rpd.GetDistance(a.OBAtom, b.OBAtom), pat.LigAtomTyper( a.OBAtom), pat.ProAtomTyper(b.OBAtom) def dTypeGen(alist, blist, form): sl, sr, dtlist = set(), set(), [] for a in alist: for b in blist: d, a1_type, a2_type = rpd.GetDistance( a.OBAtom, b.OBAtom), pat.LigAtomTyper( a.OBAtom), pat.ProAtomTyper(b.OBAtom) if form(d, a1_type, a2_type): sl.add(a) sr.add(b) dtlist.append((d, a1_type, a2_type)) return dtlist, len(sl), len(sr) def keyResi(num): return [ a2 for a2 in heavyProAtoms if a2.OBAtom.GetResidue().GetNum() == num ] # Functional programming: more independent energy decomposition heavyLigAtoms = [a1 for a1 in lig.atoms if not a1.OBAtom.IsHydrogen()] heavyProAtoms = [a2 for a2 in pro.atoms if not a2.OBAtom.IsHydrogen()] waterOs = [ a2 for a2 in heavyProAtoms if pat.ProAtomTyper(a2.OBAtom) == 'OW' ] # Water interactions dist_type_list_whb, w_hbNl, w_hbNr = dTypeGen(heavyLigAtoms, waterOs, form_hbond) if w_hbNl != 0.0 and w_hbNr != 0.0: score_list_whb = [getScore(*dt) for dt in dist_type_list_whb] dscrptorDict1['w_hb'] += sum(score_list_whb) / w_hbNl # 140 H-bond interactions dist_type_list_140hb, hb140Nl, hb140Nr = dTypeGen(heavyLigAtoms, keyResi(140), form_hbond) if hb140Nl != 0.0 and hb140Nr != 0.0: score_list_140hb = [getScore(*dt) for dt in dist_type_list_140hb] dscrptorDict1['140_hb'] += sum(score_list_140hb) / hb140Nl # Electro interactions dist_type_list_e, eNl, eNr = dTypeGen(heavyLigAtoms, heavyProAtoms, form_electro) if eNl != 0.0 and eNr != 0.0: dscrptorDict1['electro'] += sum( [getScore(*dt) for dt in dist_type_list_e]) / eNl # Others: polar or non-polar interactions for des in DESCRIPTOR[:-3]: num = int(des.split('_')[0]) if des.endswith('np'): dist_type_list_np, npNl, npNr = dTypeGen(heavyLigAtoms, keyResi(num), form_np) if npNl != 0.0 and npNr != 0.0: score_list_np = [getScore(*dt) for dt in dist_type_list_np] dscrptorDict1[des] += sum(score_list_np) / npNl elif des.endswith('polar'): dist_type_list_polar, polarNl, polarNr = dTypeGen( heavyLigAtoms, keyResi(num), form_polar) if polarNl != 0.0 and polarNr != 0.0: score_list_polar = [ getScore(*dt) for dt in dist_type_list_polar ] dscrptorDict1[des] += sum(score_list_polar) / polarNl return dscrptorDict1