def dictToResidues(self, pairDict): """ The input, 'pairDict', is a dictionary with atoms as keys and lists of atoms close to each key atom as values. This method converts these keys and values to residue sets. The first returned value is a unique ResidueSet of the 'control' or 'key' atoms used for the distance selection and the second a unique ResidueSet of parents of atoms close to the keys """ if not len(pairDict): return ResidueSet(), ResidueSet() from MolKit.molecule import AtomSet #parents of keys key_parents = AtomSet(pairDict.keys()).parent.uniq() key_parents.sort() #parents of values #build unique list of close atoms ats = {} for k in pairDict.keys(): for rec_at in pairDict[k]: ats[rec_at] = 1 close_ats = AtomSet(ats.keys()) close_parents = close_ats.parent.uniq() close_parents.sort() return key_parents, close_parents
def detectPiInteractions(self, tolerance=0.95, debug=False, use_all_cycles=False): if debug: print "in detectPiInteractions" self.results['pi_pi'] = [] #stacked rings...? self.results['t_shaped'] = [] #one ring perpendicular to the other self.results['cation_pi'] = [] # self.results['pi_cation'] = [] # self.results['macro_cations'] = []# self.results['lig_cations'] = [] # #at this point have self.results lig_res = self.results['lig_close_res'] if not len(lig_res): return lig_atoms = lig_res.atoms macro_res = self.results['macro_close_res'] if not len(macro_res): return macro_atoms = macro_res.atoms l_rf = RingFinder() #Ligand l_rf.findRings2(lig_res.atoms, lig_res.atoms.bonds[0]) #rf.rings is list of dictionaries, one per ring, with keys 'bonds' and 'atoms' if debug: print "LIG: len(l_rf.rings)=", len(l_rf.rings) if not len(l_rf.rings): if debug: print "no lig rings found by l_rf!" return acbs = AromaticCycleBondSelector() lig_rings = [] for r in l_rf.rings: ring_bnds = r['bonds'] if use_all_cycles: lig_rings.append(ring_bnds) else: arom_bnds = acbs.select(ring_bnds) if len(arom_bnds)>4: lig_rings.append(arom_bnds) if debug: print "LIG: len(lig_arom_rings)=", len(lig_rings) self.results['lig_rings'] = lig_rings self.results['lig_ring_atoms'] = AtomSet() #only check for pi-cation if lig_rings exist if len(lig_rings): macro_cations = self.results['macro_cations'] = self.getCations(macro_atoms) lig_ring_atoms = AtomSet() u = {} for r in lig_rings: for a in BondSet(r).getAtoms(): u[a] = 1 if len(u): lig_ring_atoms = AtomSet(u.keys()) lig_ring_atoms.sort() self.results['lig_ring_atoms'] = lig_ring_atoms if len(macro_cations): if debug: print "check distances from lig_rings to macro_cations here" #macro cations->lig rings pairDict2 = self.distanceSelector.select(lig_ring_atoms,macro_cations) z = {} for key,v in pairDict2.items(): val = v.tolist()[0] if val in macro_cations: z[val] = [key] if len(z): self.results['pi_cation'] = (z.items()) else: self.results['pi_cation'] = [] #check the distance between the rings and the macro_cations self.results['lig_cations'] = self.getCations(lig_atoms) #Macromolecule m_rf = RingFinder() m_rf.findRings2(macro_res.atoms, macro_res.atoms.bonds[0]) #rf.rings is list of dictionaries, one per ring, with keys 'bonds' and 'atoms' if debug: print "MACRO: len(m_rf.rings)=", len(m_rf.rings) if not len(m_rf.rings): if debug: print "no macro rings found by m_rf!" return macro_rings = [] for r in m_rf.rings: ring_bnds = r['bonds'] if use_all_cycles: macro_rings.append(ring_bnds) else: arom_bnds = acbs.select(ring_bnds) if len(arom_bnds)>4: macro_rings.append(arom_bnds) if debug: print "len(macro_arom_rings)=", len(macro_rings) self.results['macro_rings'] = macro_rings self.results['macro_ring_atoms'] = AtomSet() #only check for pi-cation if macro_rings exist if len(macro_rings): lig_cations = self.results['lig_cations'] = self.getCations(lig_atoms) macro_ring_atoms = AtomSet() u = {} for r in macro_rings: for a in BondSet(r).getAtoms(): #new method of bondSets u[a] = 1 if len(u): macro_ring_atoms = AtomSet(u.keys()) macro_ring_atoms.sort() self.results['macro_ring_atoms'] = macro_ring_atoms if len(lig_cations): if debug: print "check distances from macro_rings to lig_cations here" pairDict3 = self.distanceSelector.select(macro_ring_atoms,lig_cations) z = {} for x in pairDict3.items(): #lig cations->macro rings z.setdefault(x[1].tolist()[0], []).append(x[0]) if len(z): self.results['cation_pi'] = (z.items()) else: self.results['cation_pi'] = [] #macro_pi_atoms = AtomSet(pairDict3.keys()) #l_cations = AtomSet() #for v in pairDict3.values(): # for x in v: # l_cations.append(x) #self.results['cation_pi'] = pairDict3.items() #self.results['cation_pi'] = (l_cations, macro_pi_atoms) #check for intermol distance <6 Angstrom (J.ComputChem 29:275-279, 2009) #compare each lig_ring vs each macro_ring for lig_ring_bnds in lig_rings: lig_atoms = acbs.getAtoms(lig_ring_bnds) lig_atoms.sort() if debug: print "len(lig_atoms)=", len(lig_atoms) #--------------------------------- # compute the normal to lig ring #--------------------------------- a1 = Numeric.array(lig_atoms[0].coords) a2 = Numeric.array(lig_atoms[2].coords) a3 = Numeric.array(lig_atoms[4].coords) if debug: print "a1,a2, a3=", a1.tolist(), a2.tolist(), a3.tolist() for macro_ring_bnds in macro_rings: macro_atoms = acbs.getAtoms(macro_ring_bnds) macro_atoms.sort() if debug: print "len(macro_atoms)=", len(macro_atoms) pD_dist = self.distanceSelectorWithCutoff.select(macro_ring_atoms, lig_atoms, cutoff=self.dist_cutoff) if not len(pD_dist[0]): if debug: print "skipping ligand ring ", lig_rings.index(lig_ring_bnds), " vs ", print "macro ring", macro_rings.index(macro_ring_bnds) continue #--------------------------------- # compute the normal to macro ring #--------------------------------- b1 = Numeric.array(macro_atoms[0].coords) b2 = Numeric.array(macro_atoms[2].coords) b3 = Numeric.array(macro_atoms[4].coords) if debug: print "b1,b2, b3=", b1.tolist(), b2.tolist(), b3.tolist() # check for stacking a2_1 = a2-a1 a3_1 = a3-a1 b2_1 = b2-b1 b3_1 = b3-b1 if debug: print "a2_1 = ", a2-a1 if debug: print "a3_1 = ", a3-a1 if debug: print "b2_1 = ", b2-b1 if debug: print "b3_1 = ", b3-b1 n1 = crossProduct(a3_1,a2_1) #to get the normal for the first ring n2 = crossProduct(b3_1,b2_1) #to get the normal for the second ring if debug: print "n1=", n1 if debug: print "n2=", n2 n1 = Numeric.array(n1) n2 = Numeric.array(n2) n1_dot_n2 = Numeric.dot(n1,n2) if debug: print "n1_dot_n2", Numeric.dot(n1,n2) if abs(n1_dot_n2) >= 1*tolerance: if debug: print "The rings are stacked vertically" new_result = (acbs.getAtoms(lig_ring_bnds), acbs.getAtoms(macro_ring_bnds)) self.results['pi_pi'].append(new_result) if abs(n1_dot_n2) <= 0.01*tolerance: if debug: print "The rings are stacked perpendicularly" new_result = (acbs.getAtoms(lig_ring_bnds), acbs.getAtoms(macro_ring_bnds)) self.results['t_shaped'].append(new_result)