Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pyrosetta_toolkit.py
Go to the documentation of this file.
1 #!/usr/bin/env 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/pyrosetta_toolkit.py
10 ## @brief Main window for the toolkit.
11 ## @author Jared Adolf-Bryfogle (jadolfbr@gmail.com)
12 
13 
14 #Rosetta Imports
15 from rosetta import *
16 
17 import functools
18 
19 #Python Imports
20 from os import listdir
21 from os import getcwd
22 from shutil import copy
23 from os import remove
24 from os import environ
25 from os import path
26 from os import system
27 import glob
28 import signal
29 import sys
30 
31 #Append Python Path
32 #p = os.path.split(os.path.abspath(__file__))[0]
33 #p2 = p.split("/"); p2.pop()
34 #sys.path.append("/".join(p2)); #Allows all Window_Modules to use Modules and the use of python GUIs from main GUI directory
35 
36 #Tk Imports
37 from Tkinter import *
38 from Tkinter import Frame as FrameTk
39 import tkFileDialog
40 import tkMessageBox
41 import tkSimpleDialog
42 import tkFont
43 
44 #Toolkit Imports
45 from app.pyrosetta_toolkit.modules import tools
47 from app.pyrosetta_toolkit.window_main import global_variables
54 
57 
58 from app.pyrosetta_toolkit.modules.Region import Region
59 
61  def __init__(self):
62  """
63  Initializes the main window.
64  Sets common global variables.
65  """
66  self._tk_ = Tk()
67  self.pose = Pose()
68  self.native_pose = Pose()
69  self.current_directory = global_variables.current_directory = getcwd()
70  self.toolkit_home = self.location()[0]
71  self.DesignDic = dict()
72 
73 
74  ### Init ###
75  self._initialize_GUI()
76  self._initialize_Frames()
77 
78  ### TextBox ###
79 
80  self.textbox_frame = Frame(self._tk_, bd=3, relief=GROOVE)
81  outfont = tkFont.Font(family="Helvetica", size=11)
82  self.output_textbox= Text(self.textbox_frame,wrap="word", height=8,width=113,font = outfont)
83  self.output_scrollbar = Scrollbar(self.textbox_frame)
84  self.output_textbox.configure(yscrollcommand = self.output_scrollbar.set)
85  self.output_scrollbar.configure(command = self.output_textbox.yview)
86 
87  self.old_stdout = sys.stdout
88 
89  self.output_class.terminal_output.trace_variable('w', self.output_tracer)
90  self.output_class.terminal_output.set(0)
91 
92  self.input_class.options_manager.print_current_options()
93 
94 
95  print "\nRegion Selection Tips: No regions added = Full structure selected. \nAdding Regions: For N-terminus omit start; For C-terminus omit end; For whole Chain omit start + end"
96  print "For additional protocol options, please use the Option System Manager.\n"
97  print "Please see RosettaCommons for full documentation and references for all protocols and tools utilized in the GUI\n"
98 
99  def quit(self):
100  self._tk_.destroy()
101 
102  def _initialize_GUI(self):
103  """
104  Creates object for the GUI
105  """
106  #self.options_class = OptionSystemManager(global_variables.current_directory)Relocated to input_class
107  self.input_class = GUIInput(self)
108  self.output_class = GUIOutput(self)
109 
110  ####Sequence#####
111  self.residue_string = StringVar()
112  self.input_class.region_sequence.trace_variable('w', self.clear_num_string_on_new_input)
113  self.sequence_output = Entry(self._tk_, textvariable = self.input_class.region_sequence)
114  #self.sequence_output.bind('<FocusIn>', self.print_numbering)
115  self.sequence_output.bind('<ButtonRelease-1>', self.print_numbering)
116  self.sequence_output.bind('<KeyRelease>', self.print_numbering)
117  self.seq_scroll = Scrollbar(self._tk_, orient=HORIZONTAL, command=self.__scrollHandler)
118  self.num_label = Label(self._tk_, textvariable = self.residue_string, justify=CENTER)
119  ####Sequence#####
120  self.score_class = ScoreFxnControl(); #Main Score Function Object. Holds Score. Controls switching scorefunctions, etc.
121  self.pymol_class = AdvancedPyMOL(self.pose); #PyMOL Object for advanced visualization.
122 
123 
124  def clear_num_string_on_new_input(self, name, index, mode):
125  self.residue_string.set("")
126  self.input_class.set_residue_of_interest("", "", "")
127 
128  def print_numbering(self, event):
129  if not self.pose.total_residue():return
130  #print self.sequence_output.index(INSERT)
131  rosetta_num=0
132  pdb_num=""
133  if self.pose.total_residue()==len(self.input_class.region_sequence.get()):
134  rosetta_num = 1+self.sequence_output.index(INSERT)
135  try:
136  pdb_num = self.pose.pdb_info().pose2pdb(rosetta_num)
137  except PyRosettaException:
138  #Catches the the LAST index
139  return
140  #print self.num_string
141 
142  else:
143  region = self.input_frame.return_region_from_entry()
144  rosetta_num = region.get_rosetta_start(self.pose)+self.sequence_output.index(INSERT)
145  try:
146  pdb_num = self.pose.pdb_info().pose2pdb(rosetta_num)
147  except PyRosettaException:
148  return
149 
150  pdbSP = pdb_num.split()
151  self.input_class.set_residue_of_interest(pdbSP[0], pdbSP[1], repr(rosetta_num))
152  self.input_class.residue_string.set(pdb_num+' - '+repr(rosetta_num))
153  self.residue_string.set(pdb_num+' - '+repr(rosetta_num))
154  self.input_class.residue_rosetta_resnum.set(repr(rosetta_num))
155 
156  if self.pymol_class.auto_send_residue_colors.get():
157  self.pymol_class.color_residue(int(rosetta_num))
158  #self.fullcontrol_class.shoInfo(pdbSP[0], pdbSP[1])
159 
160  def __scrollHandler(self, *L):
161  """
162  Handles scrolling of entry.
163  CODE: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/entry-scrolling.html
164  """
165  try:
166  op, howMany = L[0], L[1]
167  except IndexError:
168  return
169 
170  if op =='scroll':
171  units = L[2]
172  self.sequence_output.xview_scroll(howMany, units)
173  elif op=='moveto':
174  self.sequence_output.xview_moveto(howMany)
175 
177  """
178  Creates the Frame Objects that will go in the main window
179  """
180  self.input_frame = InputFrame(self._tk_, self, self.input_class, bd=1, relief=SUNKEN)
181  self.output_frame = OutputFrame(self._tk_, self, self.output_class, bd=1, relief = SUNKEN)
182 
183  self.protocol_frame = QuickProtocolsFrame(self._tk_, self, self.output_class, bd=1, relief=SUNKEN)
184  self.simple_analysis_frame = SimpleAnalysisFrame(self._tk_, self, bd=2, relief=SUNKEN)
185  self.menu_class = Menus(self._tk_, self)
186 
187 
188 
189  def show_gui(self):
190  """
191  Shows each piece of the main GUI.
192  Does not do anything with the Window Modules, just each individual main component of the main window.
193  These Inhereit from the Frame class. See one of these for an example.
194  Window Modules should be initialized through the Menus class in /window_main/menu.py
195  """
196  #6x4 Grid Pain in the ass. At some point, everything will move to Qt - Either in Python or C++
197 
198  #Grid:
199  self.menu_class.setTk(); self.menu_class.shoTk()
200 
201  self.input_frame.grid(row=1, column=0, rowspan=7, padx=15, pady=15);
202  self.output_frame.grid(row=0, column=1, rowspan=2, pady=3);
203 
204  self.protocol_frame.grid(row=3, column=1, rowspan=4, padx=5)
205  self.simple_analysis_frame.grid(row=0, column=0, padx=5, pady=5)
206 
207 
208  ### Text Output ###
209  self.num_label.grid(column=0, row=8, columnspan=2, pady=2, padx=2)
210  self.seq_scroll.grid(column=0, row=9, columnspan=3, sticky=W+E)
211  self.sequence_output.grid(column=0, row=10, columnspan=3, sticky=W+E)
212  self.sequence_output['xscrollcommand']=self.seq_scroll.set
213  self.output_textbox.grid(column=0, row = 11, rowspan=2, columnspan=3,sticky=W+E)
214  self.output_scrollbar.grid(column=3, row=11, rowspan=2, sticky=E+N+S)
215  self.textbox_frame.grid(column=0, row=11, rowspan=2, columnspan=3, sticky=W+E, pady=3, padx=6)
216 
217  #self.Photo.grid(row = 0, column = 2, rowspan=4)
218 
219  """
220  #Pack:
221  self.menu_class.setTk(); self.menu_class.shoTk()
222  self.input_class.pack(side=LEFT, padx=3, pady=3)
223  self.output_class.pack(padx=3, pady=3)
224 
225  self.simple_analysis_frame.pack(padx=3, pady=3)
226  self.protocol_frame.pack(padx=3, pady=3)
227  #self.output_textbox.pack(side=BOTTOM, padx=3, pady=3)
228  #self.output_frame.pack(side=BOTTOM, padx=3, pady=3)
229  """
230 
231  def run(self, run_event_loop=True):
232  self._tk_.title("PyRosetta Toolkit")
233  self.show_gui()
234  self._tk_.grid_columnconfigure(ALL, weight=1)
235  #self._tk_.grid_rowconfigure(ALL, weight=1)
236  if run_event_loop:
237  self._tk_.mainloop()
238 
240  print "Redirect stdout to textbox"
241  sys.stdout = self; #Set stdout to be redirected to textbox using the write function override.
242 
243 
245  print "Redirect stdout to default"
246  sys.stdout = self.old_stdout
247 
248 
249  def write(self, text):
250  self.output_textbox.insert(END, text)
251  self.output_textbox.yview(END)
252 
253  def output_tracer(self, name, index, mode):
254  """
255  Controls where stdout goes. Textbox or Terminal.
256  Does not override Tracer for now.
257  """
258 
259  varvalue = self.output_class.terminal_output.get()
260 
261  if (varvalue):
263  else:
265 
266  def location(self):
267  """
268  Allows the script to be self-aware of it's path.
269  So that it can be imported/ran from anywhere.
270  """
271 
272  p = os.path.abspath(__file__)
273  pathSP = os.path.split(p)
274  return pathSP
275 
276 class MainTracer(rosetta.basic.PyTracer):
277  def __init__(self, textbox):
278  rosetta.basic.PyTracer.__init__(self)
279  self.textbox = textbox
280  def output_callback(self, s):
281  s = " "+s
282  self.textbox.insert(END, s)
283  #print s
284 
285 
286 
287 
288 if __name__ == '__main__':
289  rosetta.init()
290  main_window_class = main_window()
291  main_window_class.TR = MainTracer(main_window_class.output_textbox)
292  rosetta.basic.Tracer.set_ios_hook(main_window_class.TR, rosetta.basic.Tracer.get_all_channels_string(), False)
293  #rosetta.init(extra_options="-mute all")
294 
295  main_window_class.run()
Fstring::size_type len(Fstring const &s)
Length.
Definition: Fstring.hh:2207