Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ResfileDesignWindow.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/window_modules/design_window/resfile_design.py
10 ## @brief Main resfile design window.
11 ## @author Jared Adolf-Bryfogle (jadolfbr@gmail.com)
12 
13 #Rosetta Imports
14 from rosetta import *
15 
16 #Python Imports
17 import os
18 
19 #Tkinter Imports
20 from Tkinter import *
21 import tkFileDialog
22 
23 #Toolkit Imports
24 from app.pyrosetta_toolkit.modules.tools import output as output_tools
26 from app.pyrosetta_toolkit.window_main import global_variables
27 
29  def __init__(self, main, DesignDic, pose):
30  self.main=main
31  self.main.title("Design Toolbox")
32 
33  self.pwd = self.location()[0]
34  self.DesignDic = DesignDic; #Main dictionary for saving the resfile info. Can be empty upon construction of window.
35  #current and design are labeled opposite . need to fix.
36  self.current_accessible_sa = StringVar(); self.current_relative_mutability = StringVar(); self.current_surface_probability = StringVar()
37  self.design_accessible_sa = StringVar(); self.design_relative_mutability = StringVar(); self.design_surface_probability = StringVar()
38  self.current_residue_name = StringVar(); #Split three letter aa code.
39  self.current_residue_name_full = StringVar(); #Full rosetta code including variants.
40 
41  self.current_residue = StringVar();
42  self.current_chain = StringVar();
43  self.pose = pose
44  self.TypeCurSelection = StringVar(); #Current selection of restype
45  self.residue_definitions = definitions(); #Defines all residue type information.
46 
47 
48  def setTk(self):
49  #self.entry_Res = Entry(self.main, textvariable=addRes, justify=CENTER)
50  #self.entry_Chain = Entry(self.main, textvariable=DesignChain, justify=CENTER)
51 
52  self.label_Chain = Label(self.main, text = "Chain")
53  self.shoRes = Label(self.main, textvariable=self.current_residue_name_full)
54  self.label_Res = Label(self.main, text = "Residue or Start:End")
55  self.listbox_restypes = Listbox(self.main)
56  self.listbox_residues = Listbox(self.main)
57  self.entry_residue = Entry(self.main, textvariable=self.current_residue, justify=CENTER)
58  self.entry_chain = Entry(self.main, textvariable=self.current_chain, justify=CENTER)
59  self.button_check_residue = Button(self.main, text="Check Residue", command=lambda: self.check_residue_callback())
60  self.button_next_residue = Button(self.main, text="Next Res", command=lambda: self.nextRes())
61  self.button_previous_residue= Button(self.main, text="Previous Res", command=lambda: self.prevRes())
62  self.listbox_current_designs = Listbox(self.main)
63  self.button_save_resfile = Button(self.main, text="Write Resfile", command=lambda: self.saveDesign())
64  self.button_clear_resfile = Button(self.main, text="Clear Data", command = lambda: self.clearResData())
65  self.button_ClearRes = Button(self.main, text = "Clear Residue", command=lambda: self.clearCurrentResidue())
66  self.button_load_resfile = Button(self.main, text="Load Resfile")
67 
68  #### Mutability Data ####
69  self.label_accessible_SA = Label(self.main, text="Accesible SA");
70  self.label_relative_mutability = Label(self.main, text="Rel. Mutability");
71  self.label_surface_probability = Label(self.main, text = "Surface Probability");
72 
73  self.active_label_current_accessible_sa = Label(self.main, textvariable=self.current_accessible_sa)
76 
77  self.active_label_design_accessible_sa = Label(self.main, textvariable=self.design_accessible_sa)
80 
81  #### Photo ####
82  InterfacePhoto =PhotoImage(file = (self.pwd+"/Media/InterfaceDesignSmall.gif"))
83  self.Photo = Label(self.main, image=InterfacePhoto)
84  self.Photo.image = InterfacePhoto
85 
86  def shoTk(self):
87  #self.entry_Res.grid(row=1, column=1)
88  self.label_Chain.grid(row=2, column=0)
89  self.listbox_restypes.grid(row=0, column=4, rowspan=10)
90  self.listbox_residues.grid(row=0, column=5, rowspan=10)
91  #self.entry_Chain.grid(row=3, column=1)
92  self.label_Res.grid(row=1, column=0)
93  self.shoRes.grid(row=0, column=1)
94  self.entry_residue.grid(row=1, column=1)
95  self.button_check_residue.grid(row=3, column=1)
96  self.button_previous_residue.grid(row=3, column=0)
97  self.button_next_residue.grid(row=3, column=2)
98  self.listbox_current_designs.grid(row=12, column=4, rowspan=10)
99  self.entry_chain.grid(row=2, column=1)
100  self.button_save_resfile.grid(row=12, column=5, sticky=W+E)
101  #self.button_load_resfile.grid(row=13, column=5, sticky=W+E); #Load resfile does not work yet.
102  self.button_clear_resfile.grid(row=14, column=5, sticky=W+E)
103  #self.button_ClearRes.grid(row=15, column=5, sticky=W+E)
104  self.label_accessible_SA.grid(row=4, column=0); self.active_label_current_accessible_sa.grid(row=6, column=0); self.active_label_design_accessible_sa.grid(row=5, column=0)
105  self.label_relative_mutability.grid(row=4, column=1); self.active_label_current_relative_mutability.grid(row=6, column=1); self.active_label_design_relative_mutability.grid(row=5, column=1)
106  self.label_surface_probability.grid(row=4, column=2); self.active_label_current_surface_probability.grid(row=6, column=2); self.active_label_design_surface_probability.grid(row=5, column=2)
107  #ListBox Behavior
108  self.listbox_restypes.bind("<ButtonRelease-1>", lambda event: self.click_restype_callback(self.listbox_restypes, self.listbox_residues))
109  self.listbox_residues.bind("<Double-Button-1>", lambda event: self.add_to_current_designs_callback(self.listbox_residues, self.listbox_current_designs))
110  self.listbox_residues.bind("<ButtonRelease-1>", lambda event: self.updateInfo(self.listbox_residues))
111  self.listbox_current_designs.bind("<Double-Button-1>", lambda event: self.remove_from_current_designs_callback(self.listbox_current_designs))
112  #Photo
113  self.Photo.grid(row =12, column = 6, rowspan=5)
114  self.main.grid_columnconfigure(ALL, weight=1)
115 #### GUI FUNCTIONS ####
116 
117  #### 'CALLBACKS' ####
118 
120  """
121  What happens when you click check residue. Should be a callback, but need both res and chain specified before update.
122  """
123 
124  if not self.check_for_residue_existance():
125  return
126 
127  self.listbox_current_designs.delete(0, END)
128  self.current_residueFull = self.current_residue.get().split(":")
129 
130  if len(self.current_residueFull) > 1:
131  self.listbox_restypes.delete(9)
132  self.listbox_restypes.insert(9, "Conserved")
133  else:
134  res = self.current_residueFull[0] +":"+self.current_chain.get()
135  #print res
136  if not self.pose.total_residue():
137  return
138 
139  resType = self.pose.pdb_info().pdb2pose(self.current_chain.get(), int(self.current_residue.get()))
140  try:
141  resName = self.pose.residue(resType).name()
142  except PyRosettaException:
143  print "Residue does not exist in PDB..."
144  return
145 
146 
147  self.current_residue_name_full.set(resName)
148  three_letter_name = resName.split("_")[0]; #Fix for Rosetta designated chain endings, His_d
149  self.current_residue_name.set(resName)
150 
151  #Fix for not having data for certain residue types:
152  try:
153  self.design_accessible_sa.set(self.residue_definitions.resinfo[three_letter_name][0])
154  self.design_relative_mutability.set(self.residue_definitions.resinfo[three_letter_name][1])
155  self.design_surface_probability.set(self.residue_definitions.resinfo[three_letter_name][2])
156  except KeyError:
157  print "No Data for restype"
158  self.design_accessible_sa.set("")
159  self.design_relative_mutability.set("")
160  self.design_surface_probability.set("")
161 
162  con = "Conserved:" +three_letter_name
163  self.listbox_restypes.delete(9)
164  self.listbox_restypes.insert(9, con)
165  if self.DesignDic.has_key(res):
166  for residues in self.DesignDic[res]:
167  self.listbox_current_designs.insert(END, residues)
168 
169  def click_restype_callback(self, ListTypes, ListTypesFull):
170  """
171  What happens when you click a design type (conserved, polar, etc.)
172  """
173 
174  #Ropulate if more then 1 residue
175  #if self.current_residue.get().split(":")>1:
176  #self.check_residue_callback()
177 
178  ListTypesFull.delete(0, END)
179  type = ListTypes.get(ListTypes.curselection())
180  self.TypeCurSelection.set(type)
181  ListTypesFull.insert(END, "All")
182  ListTypesFull.insert(END, "All+Self")
183  try:
184  for res in self.residue_definitions.restype_info[type]:
185  ListTypesFull.insert(END, res)
186  except KeyError:
187  return
188 
189  def add_to_current_designs_callback(self, ListTypesFull, check_button_ckList):
190  """
191  What happens when you add a residue type to the design. Updates other listboxes, etc.
192  """
193 
194  if not self.check_for_residue_existance():
195  return
196 
197  self.current_chainFull = self.current_residue.get().split(":")
198  if len(self.current_chainFull) > 1:
199  ResStart = int(self.current_chainFull[0]); ResEnd = int(self.current_chainFull[1])
200  if (ListTypesFull.get(ListTypesFull.curselection()))=="All":
201  for ResType in self.residue_definitions.restype_info[self.TypeCurSelection.get()]:
202  print ResType
203  for i in range(ResStart, ResEnd+1):
204  res = repr(i) + ":"+self.current_chain.get()
205  if self.DesignDic.has_key(res):
206  self.DesignDic[res].append(ResType)
207  else:
208  self.DesignDic[res] = [ResType, ]
209  if (ListTypesFull.get(ListTypesFull.curselection()))=="All+Self":
210  start = self.pose.pdb_info().pdb2pose(self.current_chain.get(), ResStart)
211  end = self.pose.pdb_info().pdb2pose(self.current_chain.get(), ResEnd)
212  for ResType in self.residue_definitions.restype_info[self.TypeCurSelection.get()]:
213  for i in range(ResStart, ResEnd+1):
214  res = repr(i) + ":"+self.current_chain.get()
215  if self.DesignDic.has_key(res):
216  self.DesignDic[res].append(ResType)
217  else:
218  self.DesignDic[res] = [ResType, ]
219  #Gets number according to rosetta
220  resType = self.pose.pdb_info().pdb2pose(self.current_chain.get(), i)
221  #Gets name according to rosetta
222  resType = self.pose.residue(resType).name()
223  resType = resType.split("_")[0];
224  for y in self.residue_definitions.restype_info["All"]:
225  z = y.split(":")
226  if resType == z[1]:
227  self.DesignDic[res].append(y)
228  elif (ListTypesFull.get(ListTypesFull.curselection()))=="NATRO":
229  for i in range(ResStart, ResEnd+1):
230  res = repr(i) + ":"+self.current_chain.get()
231  self.DesignDic[res] = ["NATRO", ]
232  elif (ListTypesFull.get(ListTypesFull.curselection()))=="NATAA":
233  for i in range(ResStart, ResEnd+1):
234  res = repr(i) + ":"+self.current_chain.get()
235  self.DesignDic[res] = ["NATAA", ]
236 
237  elif (ListTypesFull.get(ListTypesFull.curselection()))=="ALLAA":
238  for i in range(ResStart, ResEnd+1):
239  res = repr(i) + ":"+self.current_chain.get()
240  self.DesignDic[res] = ["ALLAA", ]
241  elif (ListTypesFull.get(ListTypesFull.curselection()))=="All Conserved Mutations":
242  start = self.pose.pdb_info().pdb2pose(self.current_chain.get(), ResStart)
243  end = self.pose.pdb_info().pdb2pose(self.current_chain.get(), ResEnd)
244  print repr(start); print repr(end)
245  for i in range(start, end+1):
246  print i
247  resType = i
248  resType = self.pose.residue(resType).name()
249  resType = resType.split("_")[0];
250  resType = "Conserved:"+resType
251  res = self.pose.pdb_info().pose2pdb(i).split()[0]+":"+self.current_chain.get()
252  for types in self.residue_definitions.restype_info[resType]:
253  if self.DesignDic.has_key(res):
254  self.DesignDic[res].append(types)
255  else:
256  self.DesignDic[res] = [types, ]
257  elif (ListTypesFull.get(ListTypesFull.curselection()))=="All Conserved Mutations+Self":
258  print "4"
259  start = self.pose.pdb_info().pdb2pose(self.current_chain.get(), ResStart)
260  end = self.pose.pdb_info().pdb2pose(self.current_chain.get(), ResEnd)
261  for i in range(start, end+1):
262  resType = i
263  resType = self.pose.residue(resType).name()
264  resType = resType.split("_")[0];
265  res = self.pose.pdb_info().pose2pdb(i).split()[0]+":"+self.current_chain.get()
266  resType = "Conserved:"+resType
267  for types in self.residue_definitions.restype_info[resType]:
268  if self.DesignDic.has_key(res):
269  self.DesignDic[res].append(types)
270  else:
271  self.DesignDic[res] = [types, ]
272 
273  resTypei = self.pose.residue(i).name()
274  for y in self.residue_definitions.restype_info["All"]:
275  z = y.split(":")
276  if resTypei == z[1]:
277  self.DesignDic[res].append(y)
278  else:
279  ResType= ListTypesFull.get(ListTypesFull.curselection())
280  for i in range(ResStart, ResEnd+1):
281  res = repr(i) + ":"+ self.current_chain.get()
282  if self.DesignDic.has_key(res):
283  self.DesignDic[res].append(ResType)
284  else:
285  self.DesignDic[res] = [ResType, ]
286  #self.updateInfo(ListTypesFull)
287  check_button_ckList.delete(0, END)
288  res = repr(ResStart) + ":" + self.current_chain.get()
289  for residues in self.DesignDic[res]:
290  check_button_ckList.insert(END, residues)
291  else:
292  resType = self.pose.pdb_info().pdb2pose(self.current_chain.get(), int(self.current_residue.get()))
293  res = self.pose.residue(resType).name()
294 
295  self.current_residue_name_full.set(res)
296  res= res.split("_")[0];
297  self.current_residue_name.set(res)
298  try:
299  self.design_accessible_sa.set(self.residue_definitions.resinfo[self.pose.residue(resType).name()][0])
300  self.design_relative_mutability.set(self.residue_definitions.resinfo[self.pose.residue(resType).name()][1])
301  self.design_surface_probability.set(self.residue_definitions.resinfo[self.pose.residue(resType).name()][2])
302  except KeyError:
303  pass
304  res = self.current_residue.get() +":" + self.current_chain.get()
305  if (ListTypesFull.get(ListTypesFull.curselection()))=="All":
306  for ResType in self.residue_definitions.restype_info[self.TypeCurSelection.get()]:
307  if self.DesignDic.has_key(res):
308  self.DesignDic[res].append(ResType)
309  else:
310  self.DesignDic[res] = [ResType, ]
311  elif (ListTypesFull.get(ListTypesFull.curselection()))=="All+Self":
312  for ResType in self.residue_definitions.restype_info[self.TypeCurSelection.get()]:
313  if self.DesignDic.has_key(res):
314  self.DesignDic[res].append(ResType)
315  else:
316  self.DesignDic[res] = [ResType, ]
317  for y in self.residue_definitions.restype_info["All"]:
318  z = y.split(":")
319  if self.current_residue_name.get() == z[1]:
320  self.DesignDic[res].append(y)
321 
322  elif (ListTypesFull.get(ListTypesFull.curselection()))=="NATRO":
323  self.DesignDic[res] = ["NATRO", ]
324  elif (ListTypesFull.get(ListTypesFull.curselection()))=="NATAA":
325  self.DesignDic[res] = ["NATAA", ]
326 
327  elif (ListTypesFull.get(ListTypesFull.curselection()))=="ALLAA":
328  self.DesignDic[res] = ["ALLAA", ]
329  else:
330  ResType= ListTypesFull.get(ListTypesFull.curselection())
331  if self.DesignDic.has_key(res):
332  self.DesignDic[res].append(ResType)
333  else:
334  self.DesignDic[res] = [ResType, ]
335  self.updateInfo(ListTypesFull)
336  check_button_ckList.delete(0, END)
337  for residues in self.DesignDic[res]:
338  check_button_ckList.insert(END, residues)
339 
340  def remove_from_current_designs_callback(self, check_button_ckList):
341  """
342  What happens when you double click the bottom listbox to remove a residue.
343  """
344 
345  self.current_residueFull = self.current_residue.get().split(":")
346  if len(self.current_residueFull) > 1:
347  ResStart = int(self.current_residueFull[0]); ResEnd = int(self.current_residueFull[1])
348  for i in range(ResStart, ResEnd +1):
349  res = repr(i) + ":" +self.current_chain.get()
350  self.DesignDic[res].remove(check_button_ckList.get(check_button_ckList.curselection()))
351  check_button_ckList.delete(0, END)
352  res = repr(ResStart) + ":" +self.current_chain.get()
353  for residues in self.DesignDic[res]:
354  check_button_ckList.insert(END, residues)
355  else:
356  res = self.current_residue.get() +":" + self.current_chain.get()
357  self.DesignDic[res].remove(check_button_ckList.get(check_button_ckList.curselection()))
358  check_button_ckList.delete(0, END)
359  for residues in self.DesignDic[res]:
360  check_button_ckList.insert(END, residues)
361 
363  """
364  Checks to make sure residue/residues exist before adding to the residue checkbox.
365  Returns False if something is wrong.
366  """
367  if not self.pose.total_residue():
368  print "No pose Loaded."
369  return False
370 
371  if not self.current_chain.get() or not self.current_residue.get():
372  print "Chain or residue not set"
373  return False
374 
375  current_region = self.current_residue.get().split(":")
376  if len(current_region)>1:
377  ResStart = int(current_region[0]); ResEnd = int(self.current_region[1])
378 
379 
380  if self.pose.pdb_info().pdb2pose(self.current_chain.get(), ResStart)==0 or self.pose.pdb_info().pdb2pose(self.current_chain.get(), ResEnd)==0:
381  print "Region not found in pose"
382  return False
383  else:
384  if self.pose.pdb_info().pdb2pose(self.current_chain.get(), int(self.current_residue.get())) ==0:
385 
386  print "Residue not found in pose"
387  return False
388 
389  #If everythig is good then:
390  return True
391 
392  def updateInfo(self, ListTypesFull):
393  Restype = ListTypesFull.get(ListTypesFull.curselection())
394  typefull = Restype.split(":")
395  self.current_residueFull = self.current_residue.get().split(":")
396 
397  if (len(self.current_residueFull) < 2) and (len(typefull)==3):
398  self.current_accessible_sa.set(self.residue_definitions.resinfo[typefull[1]][0])
399  self.current_relative_mutability.set(self.residue_definitions.resinfo[typefull[1]][1])
400  self.current_surface_probability.set(self.residue_definitions.resinfo[typefull[1]][2])
401 
402  #### Other GUI Functions ####
403 
404  def nextRes(self):
405  """
406  Update functions when residue is +1
407  """
408 
409  self.current_residueFull = self.current_residue.get().split(":")
410  if len(self.current_residueFull) < 2:
411  res = int(self.current_residue.get())+1
412  self.current_residue.set(res)
414  else:
415  print "Please Change selection to get info..."
416 
417  def prevRes(self):
418  """
419  Update functions when residue is -1
420  """
421 
422  self.current_residueFull = self.current_residue.get().split(":")
423  if len(self.current_residueFull) < 2:
424  res = int(self.current_residue.get())-1
425  self.current_residue.set(res)
427  else:
428  print "Please Change selection to get info..."
429 
430  def setTypes(self):
431  for type in self.residue_definitions.restypes:
432  self.listbox_restypes.insert(END, type)
433 
434  def clearResData(self):
435  self.DesignDic.clear()
437  print "Design Data Cleared..."
438  print self.DesignDic
439 
441  pass
442 
443 
444 #### FUNCTIONS ####
445  def saveDesign(self):
446  out = tkFileDialog.asksaveasfilename(initialdir = global_variables.current_directory, title ="Save As...")
447  if not out: return
448  output_tools.save_resfile_w_designdic(self.pose, self.DesignDic, out)
449  outSP = out.split("/")
450  length = len(outSP)
451  folder = outSP[length-2]
452  if folder == "FragSets_Designs":
453  prot.LisProt1Frag.insert(END, outSP[length-1])
454 
455  def location(self):
456  """
457  Allows the script to be self-aware of it's path.
458  So that it can be imported/ran from anywhere.
459  """
460 
461  p = os.path.abspath(__file__)
462  pathSP = os.path.split(p)
463  return pathSP
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:38
rule< Scanner, string_closure::context_t > name
Definition: Tag.cc:376