Example #1
0
 def set_rotatable_bonds_from_file(self, mol):
     assert mol.allAtoms.bonds[0]
     assert hasattr(self, 'activeInFile')
     mol.allAtoms.bonds[0].possibleTors = 0
     mol.allAtoms.bonds[0].activeTors = 0
     for ll in self.activeInFile:
         #            0        1    2      3         4        5        6       7
         #ex: ll = ['REMARK', '1', 'A', 'between', 'atoms:', 'N1_1', 'and', 'C31_39']
         name1, index1 = ll[5].split(
             '_')  #index1 is NOT usable ['N1','1']@@
         name2, index2 = ll[7].split('_')  #index2 is NOT ['C31','39']
         #at1 = mol.allAtoms[int(index1)-1]
         at1 = mol.allAtoms.get(name1)[0]
         #if len(ats1)==1:
         #    at1 = ats1[0]
         #else:
         #?WHAT TO DO IF more than one?
         # ?check for bonded atom named at2
         ATS2 = mol.allAtoms.get(name2)
         if len(ATS2) == 1:
             at2 = ATS2[0]
         else:
             for at in ATS2:
                 if at.isBonded(at1):
                     at2 = at
                     break
         #at2 = mol.allAtoms[int(index2)-1]
         bnd = AtomSet([at1, at2]).bonds[0]
         bnd.possibleTors = 1
         bnd.activeTors = 1  #?verify 'A'
         if ll[2] == 'I':
             bnd.activeTors = 0
Example #2
0
 def set_rotatable_bonds_from_file(self,mol):
     assert mol.allAtoms.bonds[0]
     assert hasattr(self, 'activeInFile') 
     mol.allAtoms.bonds[0].possibleTors = 0
     mol.allAtoms.bonds[0].activeTors = 0
     for ll in self.activeInFile:
          #            0        1    2      3         4        5        6       7
          #ex: ll = ['REMARK', '1', 'A', 'between', 'atoms:', 'N1_1', 'and', 'C31_39']
          name1, index1 = ll[5].split('_') #index1 is NOT usable ['N1','1']@@
          name2, index2 = ll[7].split('_') #index2 is NOT ['C31','39']
          #at1 = mol.allAtoms[int(index1)-1]
          at1 = mol.allAtoms.get(name1)[0]
          #if len(ats1)==1:
          #    at1 = ats1[0]
          #else:
          #?WHAT TO DO IF more than one?
          # ?check for bonded atom named at2
          ATS2 = mol.allAtoms.get(name2)
          if len(ATS2)==1:
             at2 = ATS2[0]
          else:   
             for at in ATS2:
                 if at.isBonded(at1):
                     at2 = at
                     break
          #at2 = mol.allAtoms[int(index2)-1]
          bnd = AtomSet([at1,at2]).bonds[0]
          bnd.possibleTors = 1
          bnd.activeTors = 1 #?verify 'A'
          if ll[2]=='I':
             bnd.activeTors = 0     
Example #3
0
 def getCations(self, atoms):
     #select atoms in ARG and LYS residues
     arg_cations = atoms.get(lambda x: (x.parent.type=='ARG' and \
                             x.name in ['CZ']))
     lys_cations = atoms.get(lambda x: (x.parent.type=='LYS' and \
                             x.name in ['NZ', 'HZ1', 'HZ2', 'HZ3']))
     #select any positively-charged metal ions... cannot include CA here
     metal_cations = atoms.get(lambda x: x.name in ['Mn','MN', 'Mg',\
                             'MG', 'FE', 'Fe', 'Zn', 'ZN'])
     ca_cations = atoms.get(lambda x: x.name in ['CA', 'Ca'] and x.parent.type=='CA')
     cations = AtomSet() 
     #cations.extend(arg_cations)
     for a in arg_cations:
         cations.append(a)
     #cations.extend(lys_cations)
     for a in lys_cations:
         cations.append(a)
     #cations.extend(metal_cations)
     # including metal_cations and calcium optional
     if self.include_metal_cations:
         for a in metal_cations:
             cations.append(a)
         #cations.extend(ca_cations)
         for a in ca_cations:
             cations.append(a)
     return cations
Example #4
0
 def get_leaf_atoms(self, mol):
     atom_nums = self.get_leaves(self.rootNode, [])
     atoms = AtomSet()
     if len(atom_nums):
         atoms = mol.allAtoms.get(str(atom_nums[0]))
         for atnum in atom_nums[1:]:
             atoms.append(mol.allAtoms[atnum])
     return atoms
Example #5
0
 def get_leaf_atoms(self, mol):
     atom_nums = self.get_leaves(self.rootNode, []) 
     atoms = AtomSet()
     if len(atom_nums):
         atoms = mol.allAtoms.get(str(atom_nums[0]))
         for atnum in atom_nums[1:]:
             atoms.append(mol.allAtoms[atnum])
     return atoms
 def getCations(self, atoms):
     #select atoms in ARG and LYS residues
     arg_cations = atoms.get(lambda x: (x.parent.type=='ARG' and \
                             x.name in ['CZ']))
     lys_cations = atoms.get(lambda x: (x.parent.type=='LYS' and \
                             x.name in ['NZ', 'HZ1', 'HZ2', 'HZ3']))
     #select any positively-charged metal ions... cannot include CA here
     metal_cations = atoms.get(lambda x: x.name in ['Mn','MN', 'Mg',\
                             'MG', 'FE', 'Fe', 'Zn', 'ZN'])
     ca_cations = atoms.get(lambda x: x.name in ['CA', 'Ca'] and x.parent.type=='CA')
     cations = AtomSet() 
     #cations.extend(arg_cations)
     for a in arg_cations:
         cations.append(a)
     #cations.extend(lys_cations)
     for a in lys_cations:
         cations.append(a)
     #cations.extend(metal_cations)
     # including metal_cations and calcium optional
     if self.include_metal_cations:
         for a in metal_cations:
             cations.append(a)
         #cations.extend(ca_cations)
         for a in ca_cations:
             cations.append(a)
     return cations
 def buildCloseContactAtoms(self, percentCutoff):
     pairDict = self.distanceSelector.select(self.lig_atoms, 
                     self.macro_atoms, percentCutoff=percentCutoff)
     self.pairDict = pairDict
     #reset here
     lig_close_ats = AtomSet()
     macro_close_ats = AtomSet()
     closeAtoms = AtomSet()  #both sets
     cdict = {}
     for k,v in pairDict.items():
         if len(v):
             cdict[k] = 1
         for at in v:
             if at not in macro_close_ats:
                 cdict[at] = 1
     closeAtoms = AtomSet(cdict.keys())
     
     #macro_close_ats = closeAtoms.get(lambda x: x.top==self.macro)
     #lig_close_ats = closeAtoms.get(lambda x: x.top==self.lig)
     lig_close_ats = closeAtoms.get(lambda x: x in self.lig_atoms)
     macro_close_ats = closeAtoms.get(lambda x: x in self.macro_atoms)
     rdict = self.results
     rdict['lig_close_atoms'] = lig_close_ats
     rdict['lig_close_res'] = lig_close_ats.parent.uniq()
     rdict['lig_close_carbons'] = lig_close_ats.get(lambda x: x.element=='C')
     rdict['lig_close_non_hb'] = lig_close_ats - rdict['lig_hb_atoms']
     rdict['macro_close_atoms'] = macro_close_ats
     rdict['macro_close_res'] = ResidueSet(macro_close_ats.parent.uniq())
     rdict['macro_close_carbons'] = macro_close_ats.get(lambda x: x.element=='C')
     rdict['macro_close_non_hb'] = macro_close_ats - rdict['macro_hb_atoms']
     #deprecate this
     rdict['macro_close_only'] = macro_close_ats - rdict['macro_hb_atoms']
Example #8
0
 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)
 def buildHydrogenBonds(self):
     self.results = d = {}
     h_pairDict = self.hydrogen_bond_builder.build(self.lig_atoms, self.macro_atoms)
     self.h_pairDict = h_pairDict
     #keys should be from lig, values from macro 
     #sometimes are not...@@check this@@
     h_results = {}
     for k, v in h_pairDict.items():
         h_results[k] = 1
         for at in v:
             h_results[at] = 1
     all_hb_ats = AtomSet(h_results.keys())  #all
     macro_hb_ats = d['macro_hb_atoms'] = all_hb_ats.get(lambda x: x.top==self.macro)
     # process lig
     lig_hb_res = d['lig_hb_res'] = ResidueSet()
     lig_hb_sidechains = d['lig_hb_sidechains'] = AtomSet()
     lig_gly_atoms = AtomSet()
     lig_hb_ats = d['lig_hb_atoms'] = all_hb_ats.get(lambda x: x in self.lig_atoms)
     if len(lig_hb_ats):
         d['lig_hb_res'] = lig_hb_res = lig_hb_ats.parent.uniq()
         d['lig_hb_sidechains'] = lig_hb_sidechains = lig_hb_res.atoms.get('sidechain')
         #to visualize hbonding involving GLY residues which have no side chains, show backbone atoms
         lig_gly_res = d['lig_hb_gly_res'] = lig_hb_res.get(lambda x: x.type=='GLY')
         if len(lig_gly_res):
             lig_gly_atoms = lig_gly_res.atoms
     # build extended set of hbonding_atoms_to_show as lines, just in case
     lig_hbas = AtomSet(lig_hb_sidechains + lig_gly_atoms + lig_hb_ats) #all from lig
     extraAts = AtomSet()
     for at in lig_hbas:
         for b in at.bonds:
             at2 = b.atom1
             if at2==at: 
                 at2 = b.atom2
             #add it to the atomset
             if at2 not in lig_hbas:
                 extraAts.append(at2)
     if len(lig_hbas):
         for at in extraAts:
             lig_hbas.append(at)
     d['lig_hbas'] = lig_hbas
     # process macro
     macro_hb_res =  ResidueSet()
     d['macro_hb_res'] = macro_hb_res
     d['macro_hb_sidechains'] = AtomSet()
     d['macro_hb_gly_res'] = ResidueSet()
     if len(macro_hb_ats):
         macro_hb_res = macro_hb_ats.parent.uniq()
     #4. display sidechains of hbonding residues as sticksNballs
         macro_hb_sidechains = d['macro_hb_sidechains'] = macro_hb_res.atoms.get('sidechain')
         macro_hb_gly_res = d['macro_hb_gly_res'] = macro_hb_res.get(lambda x: x.type=='GLY')
     macro_hb_gly_res = ResidueSet()
     macro_hb_gly_atoms = AtomSet()
     if len(macro_hb_gly_res): 
         macro_hb_gly_atoms = macro_hb_gly_res.atoms
     d['macro_hb_gly_atoms'] = macro_hb_gly_atoms
     # build extended set of hbonding_atoms_to_show as lines
     macro_hbas = d['macro_hbas'] = AtomSet()
     if len(macro_hb_ats):
         macro_hbas = d['macro_hbas'] = AtomSet(macro_hb_sidechains + macro_hb_gly_atoms + macro_hb_ats) #all from macro
     #add atoms bonded to hb atoms to make lines displayed more reasonable
     extraAts = AtomSet()
     for at in macro_hbas:
         for b in at.bonds:
             at2 = b.atom1
             if at2==at: 
                 at2 = b.atom2
             #add it to the atomset
             if at2 not in macro_hbas:
                 extraAts.append(at2)
     if len(macro_hbas):
         for at in extraAts:
             macro_hbas.append(at)
     d['hbas_macro'] = macro_hbas
Example #11
0
 def buildHydrogenBonds(self):
     self.results = d = {}
     h_pairDict = self.hydrogen_bond_builder.build(self.lig_atoms, self.macro_atoms)
     self.h_pairDict = h_pairDict
     #keys should be from lig, values from macro 
     #sometimes are not...@@check this@@
     h_results = {}
     for k, v in h_pairDict.items():
         h_results[k] = 1
         for at in v:
             h_results[at] = 1
     all_hb_ats = AtomSet(h_results.keys())  #all
     macro_hb_ats = d['macro_hb_atoms'] = all_hb_ats.get(lambda x: x.top==self.macro)
     # process lig
     lig_hb_res = d['lig_hb_res'] = ResidueSet()
     lig_hb_sidechains = d['lig_hb_sidechains'] = AtomSet()
     lig_gly_atoms = AtomSet()
     lig_hb_ats = d['lig_hb_atoms'] = all_hb_ats.get(lambda x: x in self.lig_atoms)
     if len(lig_hb_ats):
         d['lig_hb_res'] = lig_hb_res = lig_hb_ats.parent.uniq()
         d['lig_hb_sidechains'] = lig_hb_sidechains = lig_hb_res.atoms.get('sidechain')
         #to visualize hbonding involving GLY residues which have no side chains, show backbone atoms
         lig_gly_res = d['lig_hb_gly_res'] = lig_hb_res.get(lambda x: x.type=='GLY')
         if len(lig_gly_res):
             lig_gly_atoms = lig_gly_res.atoms
     # build extended set of hbonding_atoms_to_show as lines, just in case
     lig_hbas = AtomSet(lig_hb_sidechains + lig_gly_atoms + lig_hb_ats) #all from lig
     extraAts = AtomSet()
     for at in lig_hbas:
         for b in at.bonds:
             at2 = b.atom1
             if at2==at: 
                 at2 = b.atom2
             #add it to the atomset
             if at2 not in lig_hbas:
                 extraAts.append(at2)
     if len(lig_hbas):
         for at in extraAts:
             lig_hbas.append(at)
     d['lig_hbas'] = lig_hbas
     # process macro
     macro_hb_res =  ResidueSet()
     d['macro_hb_res'] = macro_hb_res
     d['macro_hb_sidechains'] = AtomSet()
     d['macro_hb_gly_res'] = ResidueSet()
     if len(macro_hb_ats):
         macro_hb_res = macro_hb_ats.parent.uniq()
     #4. display sidechains of hbonding residues as sticksNballs
         macro_hb_sidechains = d['macro_hb_sidechains'] = macro_hb_res.atoms.get('sidechain')
         macro_hb_gly_res = d['macro_hb_gly_res'] = macro_hb_res.get(lambda x: x.type=='GLY')
     macro_hb_gly_res = ResidueSet()
     macro_hb_gly_atoms = AtomSet()
     if len(macro_hb_gly_res): 
         macro_hb_gly_atoms = macro_hb_gly_res.atoms
     d['macro_hb_gly_atoms'] = macro_hb_gly_atoms
     # build extended set of hbonding_atoms_to_show as lines
     macro_hbas = d['macro_hbas'] = AtomSet()
     if len(macro_hb_ats):
         macro_hbas = d['macro_hbas'] = AtomSet(macro_hb_sidechains + macro_hb_gly_atoms + macro_hb_ats) #all from macro
     #add atoms bonded to hb atoms to make lines displayed more reasonable
     extraAts = AtomSet()
     for at in macro_hbas:
         for b in at.bonds:
             at2 = b.atom1
             if at2==at: 
                 at2 = b.atom2
             #add it to the atomset
             if at2 not in macro_hbas:
                 extraAts.append(at2)
     if len(macro_hbas):
         for at in extraAts:
             macro_hbas.append(at)
     d['hbas_macro'] = macro_hbas
Example #12
0
 def buildCloseContactAtoms(self, percentCutoff):
     pairDict = self.distanceSelector.select(self.lig_atoms, 
                     self.macro_atoms, percentCutoff=percentCutoff)
     self.pairDict = pairDict
     #reset here
     lig_close_ats = AtomSet()
     macro_close_ats = AtomSet()
     closeAtoms = AtomSet()  #both sets
     cdict = {}
     for k,v in pairDict.items():
         if len(v):
             cdict[k] = 1
         for at in v:
             if at not in macro_close_ats:
                 cdict[at] = 1
     closeAtoms = AtomSet(cdict.keys())
     
     #macro_close_ats = closeAtoms.get(lambda x: x.top==self.macro)
     #lig_close_ats = closeAtoms.get(lambda x: x.top==self.lig)
     lig_close_ats = closeAtoms.get(lambda x: x in self.lig_atoms)
     macro_close_ats = closeAtoms.get(lambda x: x in self.macro_atoms)
     rdict = self.results
     rdict['lig_close_atoms'] = lig_close_ats
     rdict['lig_close_res'] = lig_close_ats.parent.uniq()
     rdict['lig_close_carbons'] = lig_close_ats.get(lambda x: x.element=='C')
     rdict['lig_close_non_hb'] = lig_close_ats - rdict['lig_hb_atoms']
     rdict['macro_close_atoms'] = macro_close_ats
     rdict['macro_close_res'] = ResidueSet(macro_close_ats.parent.uniq())
     rdict['macro_close_carbons'] = macro_close_ats.get(lambda x: x.element=='C')
     rdict['macro_close_non_hb'] = macro_close_ats - rdict['macro_hb_atoms']
     #deprecate this
     rdict['macro_close_only'] = macro_close_ats - rdict['macro_hb_atoms']
Example #13
0
 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)