Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
interfaces.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 # (c) Copyright Rosetta Commons Member Institutions.
4 # (c) This file is part of the Rosetta software suite and is made available under license.
5 # (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
6 # (c) For more information, see http://www.rosettacommons.org. Questions about this can be
7 # (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
8 
9 ## @file /GUIs/pyrosetta_toolkit/modules/tools/interfaces.py
10 ## @brief original interface functions, before I found them in Rosetta. Still may be usefull...
11 ## @author Jared Adolf-Bryfogle (jadolfbr@gmail.com)
12 
13 #Python Imports
14 from time import clock
15 from shutil import rmtree
16 import os
17 
18 #Toolkit Imports
19 from app.pyrosetta_toolkit.modules.PythonPDB import PythonPDB
21 import general_tools
22 
23 pwd = os.getcwd()
24 
25 class around():
26  """
27  Basic vacinity and interface class...
28  """
29 
30  def getVicinity(self, p, LisLoop, infile, cutoff = 5.0):
31  """
32  Get vaccinity around each loop/residue/chain specified in LisLoop.
33  Returns a VacDic: ([res:chain]=atomic contact #)
34  Needs to be rewritten using Evan's way of finding neighbors.
35  """
36  pdb_map = dict()
37  pdb_map = PythonPDB(infile).get_pdb_map()
38  #Get individual residues in LisLoop
39  resList = [] #List of residues to compute vacinity. Res:chain
40  resList = loops.loopArea(p, LisLoop, 0)
41  pdbResCoord = dict() #This is a dictionary with [res:chain] for each residue we need to find the vacinity for. Dictionary is a list (x, y, z)
42  for i in pdb_map:
43  for res in resList:
44  res = res.split(":")
45  resNum = res[0]; resChain = res[1]
46  if pdb_map[i]["resNum"]==resNum and pdb_map[i]["chain"]==resChain:
47  #This is where we do get the coordinates of each residue.
48  pdbResCoord[resNum+":"+resChain] = (float(pdb_map[i]["x"]), float(pdb_map[i]["y"]), float(pdb_map[i]["z"]))
49 
50  #Now we measure every atom in pdb_map. Adding it if it is within x of the residues in the list.
51  vacDic = dict() #This is a dictionary with [contact]=# seen (in case we need to use it later...)
52  for res in pdbResCoord:
53  for i in pdb_map:
54  xyz2 = (float(pdb_map[i]["x"]), float(pdb_map[i]["y"]), float(pdb_map[i]["z"]))
55  res_chain = pdb_map[i]["resNum"]+":"+pdb_map[i]["chain"]
56  d = tools.general_tools.getDistGen(pdbResCoord[res], xyz2)
57  if d <= cutoff:
58  #print "Cutoff:"+repr(cutoff); print d
59  #check_button_ck to make sure this is not BS due to python craptastical numbering.
60 
61  if vacDic.has_key(res_chain):
62  vacDic[res_chain]+=1 #check_button_ck that this works
63  else:
64  vacDic[res_chain]=1
65  for res in pdbResCoord:
66  vacDic.pop(res)
67  for key in vacDic:
68  print "Residues in Vacinity:"
69  print "Residue: " +key
70  #print "AtomContacts: "+ repr(vacDic[key])
71  print "Total Residues in Vicinity: " +repr(len(vacDic))
72  return vacDic
73 
74  def getDimerInterface(self, p, chainA, chainB, infile, interDic, cutoff = 5.0):
75  """
76  Gets residues common to your interface of chainA and chainB
77  Returns a VacDic: ([res:chain]=atomic contact #)
78  """
79 
80  #Get pdb_map without Whitespace
81  pdb_map = dict()
82  pdb_map = PythonPDB(infile).get_pdb_map()
83  #Get individual residues in LisLoop
84  resList = [] #List of residues to compute vacinity. Res:chain
85  chain = "::"+chainA
86  chainList = []; chainList.append(chain)
87  print chain
88  resList = loops.loopArea(p, chainList, 0)
89  pdbResCoord = dict() #This is a dictionary with [res:chain] for each residue we need to find the vacinity for. Dictionary is a list (x, y, z)
90  for i in pdb_map:
91  for res in resList:
92  res = res.split(":")
93  resNum = res[0]; resChain = res[1]
94  if pdb_map[i]["resNum"]==resNum and pdb_map[i]["chain"]==resChain:
95  #This is where we do get the coordinates of each residue.
96  pdbResCoord[resNum+":"+resChain] = (float(pdb_map[i]["x"]), float(pdb_map[i]["y"]), float(pdb_map[i]["z"]))
97 
98  #Now we measure every atom in pdb_map. Adding it if it is within x of the residues in the list, and part of the interface between only the two.
99  print "Calculating Distances...."
100  for res in pdbResCoord:
101  for i in pdb_map:
102  xyz2 = (float(pdb_map[i]["x"]), float(pdb_map[i]["y"]), float(pdb_map[i]["z"]))
103  res_chain = pdb_map[i]["resNum"]+":"+pdb_map[i]["chain"]
104  #res_chainB= res+":"+chainA
105  d = tools.general_tools.getDistGen(pdbResCoord[res], xyz2)
106  if (d <= cutoff) and pdb_map[i]["chain"]==chainB:
107  #print "Cutoff:"+repr(cutoff); print d
108  #check_button_ck to make sure this is not BS due to python craptastical numbering.
109 
110  if interDic.has_key(res_chain):
111  interDic[res_chain]+=1 #check_button_ck that this works
112  else:
113  interDic[res_chain]=1
114 
115  if interDic.has_key(res):
116  interDic[res]+=1
117  else:
118  interDic[res]=1
119  #for res in pdbResCoord:
120  #interDic.pop(res)
121  for key in interDic:
122  print "Residues in interface between chain"+chainA+"and chain "+chainB+":"
123  print "Residue: " +key
124  #print "AtomContacts: "+ repr(vacDic[key])
125  print "Total Residues in half interface: " +repr(len(interDic))
126  return interDic
127 
128  def getInterface(self, p, interface, cutoff = 5.0):
129  interfaceDic = dict(); #Dictionary: [::chain] = (res:chain, res:chain, etc.).
130  #Represents interfaces between chain and other chains. Can be parsed for more info later down the line...
131  #An interface is defined like this: 'A:CD' or A:B:EF'
132 
133  interfaceSP = interface.split(":")
134  if len(interfaceSP)==1:
135  print "Please specify an actual interface..."
136  return
137  #Dumps PDB so we can read it and find out what is in the vaccinity through good old python.
138  t = clock()
139  tempdir = pwd + "/temp2/" + "_"+repr(t)
140  os.mkdir(tempdir)
141  temp = tempdir + "/temp.pdb"; p.dump_pdb(temp)
142 
143  #Here, we will specify all the combinations we need to make in order to return the interface.
144  #Then, we parse the data as needed?
145  comboInterface = []
146  #This is basically the card sorting algorithm...
147  tempinterface = interfaceSP
148  interfaceDic = dict(); #This is the final interface dictionary used by everything else. I know. It doesn't look too good.
149  interDic = dict(); #This is the dictionary with keys as res:chain pairs = counts. Thats it.
150  while len(tempinterface) >1:
151  for chains in interfaceSP:
152  tempinterface.remove(chains)
153  for chainA in chains:
154  for x in tempinterface:
155  for chainB in x:
156  print chainA+":"+chainB
157  interDic = self.getDimerInterface(p, chainA, chainB, temp, interDic, cutoff)
158 
159  allchains = ""
160  for chains in interfaceSP:
161  allchains = chains+allchains
162  LisLoop = []
163  for chain in allchains:
164  LisLoop.append("::"+chain)
165  for item in LisLoop:
166  interfaceDic[item] = []
167  tempLoop = []
168  tempLoop.append(item); #Spits the LisLoop into individual chains.
169  itemSP = item.split(":")
170  chain = itemSP[2]
171  for key in interDic:
172  keySP = key.split(":")
173  if keySP[1] != chain:
174  interfaceDic[item].append(key)
175 
176  #Removes temp files
177  rmtree(tempdir)
178  return interfaceDic; #Interface dictionary is a simple dictionary with each chain as key, and the corresponding residues that that chain makes as interface as value (not including itself)
179 
181  def __init__(self):
182  self.cdrDic = dict()
183  self.cdrDic["L1"]=(24, 42)
184  self.cdrDic["L2"]=(57, 72)
185  self.cdrDic["L3"]=(107, 138)
186 
187  self.cdrDic["H1"]=(24, 42)
188  self.cdrDic["H2"]=(57, 69)
189  self.cdrDic["H3"]=(107, 138)
190 
191  def getContactCDRs(self, p, cutoff):
192  """
193  This function gets the residues making contact - any contact - with other residues not in H or L.
194  It returns the residues within the CDR's for use in other things.
195  Must be renumbered antibodies.
196  Should be expanded to get more data and help in analysis of individual CDR residue contacts with other CDRs and the framework/dimer interface.
197  """
198  #First - Find chain(s) making contact with the CDR's.
199  #Make LisLoop, measure with vaccinity, then test whether the vaccinity has any non H or L chains.
200  contactResidues = dict()
201  for key in self.cdrDic:
202  print key
203  start = p.pdb_info().pdb2pose(key[0], self.cdrDic[key][0])
204  end = p.pdb_info().pdb2pose(key[0], self.cdrDic[key][1])
205  for i in range(start, end+1):
206  LisLoop = []
207  x = (p.pdb_info().pose2pdb(i)).split()
208  LisLoop.append(x[0]+":"+x[0]+":"+x[1])
209  residue = x[0]+":"+x[0]+":"+x[1]
210  vacDic = tools.input.load_vicinity(p, LisLoop, cutoff)
211  for key in vacDic:
212  keySP = key.split(":")
213  if (keySP[1]!="H") and (keySP[1]!="L"):
214  if contactResidues.has_key(residue):
215  contactResidues[residue]+=1
216  else:
217  contactResidues[residue]=1
218  print "CDR Residues in Contact with Antigen: "+repr(contactResidues)
219  return contactResidues
Fstring::size_type len(Fstring const &s)
Length.
Definition: Fstring.hh:2207
utility::vector1< std::string > split(const std::string &s)
split given std::string using ' ' symbol.
Definition: string_util.cc:59