Package gui :: Module export_bmrb
[hide private]
[frames] | no frames]

Source Code for Module gui.export_bmrb

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2012 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """The BMRB export wizard.""" 
 25   
 26  # Python module imports. 
 27  import wx 
 28   
 29  # relax module imports. 
 30  from generic_fns.mol_res_spin import molecule_loop 
 31  from generic_fns.pipes import cdp_name, pipe_names, switch 
 32  from graphics import IMAGE_PATH, fetch_icon 
 33  from status import Status; status = Status() 
 34   
 35  # relax GUI module imports. 
 36  from gui.components.citations import Citations 
 37  from gui.components.molecule import Molecule 
 38  from gui.components.relax_data_meta import Relax_data_meta_list 
 39  from gui.components.scripts import Scripts 
 40  from gui.components.software import Software 
 41  from gui.message import Missing_data 
 42  from gui.fonts import font 
 43  from gui.icons import relax_icons 
 44  from gui.input_elements.value import Value 
 45  from gui.misc import add_border 
 46  from gui.string_conv import gui_to_str, str_to_gui 
 47  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 48   
 49   
50 -class Export_bmrb_window(wx.Frame):
51 """The BMRB export window.""" 52
53 - def __init__(self, gui):
54 """Set up the export window. 55 56 @param gui: The GUI object. 57 @type gui: wx.Frame instance 58 """ 59 60 # The window style. 61 style = wx.DEFAULT_FRAME_STYLE 62 if not status.debug and status.wx_info["os"] != 'darwin': 63 style = style | wx.MAXIMIZE 64 65 # Initialise the base class, setting the main GUI window as the parent. 66 super(Export_bmrb_window, self).__init__(gui, -1, style=style) 67 68 # Some default values. 69 self.size = (1200, 900) 70 self.size_min = (900, 700) 71 self.border = 5 72 self.spacer = 10 73 self.button_size = (200, 40) 74 self.button_spacing = 10 75 self.main_spacing = 20 76 77 # Set up the frame. 78 sizer = self.setup_frame() 79 80 # Add the header. 81 self.add_header(sizer) 82 83 # Top spacing. 84 sizer.AddSpacer(10) 85 86 # Add the data pipe selection element. 87 self.add_pipe(sizer) 88 89 # Spacing. 90 sizer.AddSpacer(self.main_spacing) 91 92 # Add the relaxation data metadata list GUI element. 93 self.relax_data = Relax_data_meta_list(parent=self.main_panel, box=sizer, id='BMRB export', proportion=2) 94 95 # Spacing. 96 sizer.AddSpacer(self.main_spacing) 97 98 # Add the molecule GUI element. 99 self.molecule = Molecule(parent=self.main_panel, box=sizer, id='BMRB export', proportion=1) 100 101 # Spacing. 102 sizer.AddSpacer(self.main_spacing) 103 104 # Create a horizontal layout for the software, script and citations GUI elements. 105 sub_sizer = wx.BoxSizer(wx.HORIZONTAL) 106 107 # Add the software GUI element. 108 self.software = Software(parent=self.main_panel, box=sub_sizer, id='BMRB export', proportion=1) 109 110 # Vertical spacing. 111 sub_sizer.AddSpacer(self.main_spacing) 112 113 # Add the scripts GUI element. 114 self.scripts = Scripts(parent=self.main_panel, box=sub_sizer, id='BMRB export', proportion=1) 115 116 # Vertical spacing. 117 sub_sizer.AddSpacer(self.main_spacing) 118 119 # Add the citation GUI element. 120 self.citation = Citations(parent=self.main_panel, box=sub_sizer, id='BMRB export', proportion=1) 121 122 # Add the sizer. 123 sizer.Add(sub_sizer, 2, wx.ALL|wx.EXPAND, 0) 124 125 # Bottom spacing. 126 sizer.AddSpacer(10) 127 128 # Add the buttons. 129 self.add_buttons(sizer) 130 131 # Open the window. 132 if status.show_gui: 133 self.Show()
134 135
136 - def action_cancel(self, event=None):
137 """Cancel the export. 138 139 @keyword event: The wx event. 140 @type event: wx event 141 """ 142 143 # Close the window. 144 self.Close()
145 146
147 - def action_export(self, event=None):
148 """Write out the NMR-STAR formatted data. 149 150 @keyword event: The wx event. 151 @type event: wx event 152 """ 153 154 # Checks. 155 missing = self.is_complete() 156 157 # Missing data. 158 if len(missing): 159 Missing_data(missing, parent=self) 160 return 161 162 # Execute the user function. 163 uf_store['bmrb.write'](wx_parent=self, wx_wizard_sync=True, wx_wizard_modal=True) 164 165 # Close the window. 166 self.Close()
167 168
169 - def action_preview(self, event=None):
170 """Preview the NMR-STAR formatted data. 171 172 @keyword event: The wx event. 173 @type event: wx event 174 """ 175 176 # Execute the user function. 177 uf_store['bmrb.display'](wx_parent=self)
178 179
180 - def add_buttons(self, sizer):
181 """Build and add the bottom buttons. 182 183 @param sizer: The sizer element to pack the buttons into. 184 @type sizer: wx.Sizer instance 185 """ 186 187 # Button sizer. 188 button_sizer = wx.BoxSizer(wx.HORIZONTAL) 189 sizer.Add(button_sizer, 0, wx.ALIGN_RIGHT, 0) 190 191 # Preview button. 192 button = wx.lib.buttons.ThemedGenBitmapTextButton(self.main_panel, -1, None, " Preview") 193 button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.document-preview', "32x32"), wx.BITMAP_TYPE_ANY)) 194 button.SetFont(font.normal) 195 button.SetMinSize(self.button_size) 196 button_sizer.Add(button, 0, 0, 0) 197 self.Bind(wx.EVT_BUTTON, self.action_preview, button) 198 button.SetToolTipString("Preview the NMR-STAR formatted data.") 199 200 # Spacing. 201 button_sizer.AddSpacer(self.button_spacing) 202 203 # Export button. 204 button = wx.lib.buttons.ThemedGenBitmapTextButton(self.main_panel, -1, None, " Export") 205 button.SetBitmapLabel(wx.Bitmap(fetch_icon('relax.bmrb', "32x32"), wx.BITMAP_TYPE_ANY)) 206 button.SetFont(font.normal) 207 button.SetMinSize(self.button_size) 208 button_sizer.Add(button, 0, 0, 0) 209 self.Bind(wx.EVT_BUTTON, self.action_export, button) 210 button.SetToolTipString("Preview the NMR-STAR formatted data.") 211 212 # Spacing. 213 button_sizer.AddSpacer(self.button_spacing) 214 215 # Cancel button. 216 button = wx.lib.buttons.ThemedGenBitmapTextButton(self.main_panel, -1, None, " Cancel") 217 button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.dialog-cancel', "32x32"), wx.BITMAP_TYPE_ANY)) 218 button.SetFont(font.normal) 219 button.SetMinSize(self.button_size) 220 button_sizer.Add(button, 0, 0, 0) 221 self.Bind(wx.EVT_BUTTON, self.action_cancel, button) 222 button.SetToolTipString("Cancel the BMRB export.")
223 224
225 - def add_header(self, sizer):
226 """Build and add the header to the sizer. 227 228 @param sizer: The sizer element to pack the header into. 229 @type sizer: wx.Sizer instance 230 """ 231 232 # Create a horizontal layout. 233 sub_sizer = wx.BoxSizer(wx.HORIZONTAL) 234 235 # Left spacing. 236 sub_sizer.AddStretchSpacer(3) 237 238 # Add the BMRB logo (left side). 239 logo = wx.StaticBitmap(self.main_panel, -1, wx.Bitmap(IMAGE_PATH+"bmrb_100x100.png", wx.BITMAP_TYPE_ANY)) 240 sub_sizer.Add(logo, 0, wx.TOP|wx.ALIGN_CENTER_HORIZONTAL, 0) 241 242 # Spacing. 243 sub_sizer.AddStretchSpacer() 244 245 # The text sizer. 246 text_sizer = wx.BoxSizer(wx.VERTICAL) 247 248 # The title. 249 text = wx.StaticText(self.main_panel, -1, 'Data export for BMRB deposition', style=wx.ALIGN_LEFT) 250 text.SetFont(font.title) 251 text_sizer.Add(text, 0, wx.ALIGN_CENTER_HORIZONTAL, 0) 252 253 # Spacing. 254 text_sizer.AddSpacer(15) 255 256 # The text. 257 main_text = 'This wizard will help in executing all of the relevant user functions required to convert the contents of the selected data pipe to the NMR-STAR format for deposition within the BioMagResBank. Note that this is currently only for the deposition of model-free analysis results or simple NMR relaxation data.' 258 text = wx.StaticText(self.main_panel, -1, main_text, style=wx.ALIGN_LEFT) 259 text.Wrap(600) 260 text.SetFont(font.normal) 261 text_sizer.Add(text, 0, 0, 0) 262 263 # Add the text sizer. 264 sub_sizer.Add(text_sizer, 0, 0, 0) 265 266 # Spacing. 267 sub_sizer.AddStretchSpacer() 268 269 # Add the BMRB logo (right side). 270 logo = wx.StaticBitmap(self.main_panel, -1, wx.Bitmap(IMAGE_PATH+"bmrb_100x100.png", wx.BITMAP_TYPE_ANY)) 271 sub_sizer.Add(logo, 0, wx.TOP|wx.ALIGN_CENTER_HORIZONTAL, 0) 272 273 # Right spacing. 274 sub_sizer.AddStretchSpacer(3) 275 276 # Add the sizer. 277 sizer.Add(sub_sizer, 0, wx.ALL|wx.EXPAND, 0) 278 279 # A line with spacing. 280 sizer.AddSpacer(10) 281 sizer.Add(wx.StaticLine(self.main_panel, -1), 0, wx.EXPAND|wx.ALL, 0) 282 sizer.AddSpacer(10)
283 284
285 - def add_pipe(self, sizer):
286 """Build and add the data pipe selection element. 287 288 @param sizer: The sizer element to pack the buttons into. 289 @type sizer: wx.Sizer instance 290 """ 291 292 # A sizer for the element. 293 pipe_sizer = wx.BoxSizer(wx.HORIZONTAL) 294 sizer.Add(pipe_sizer, 0, wx.ALIGN_LEFT, 0) 295 296 # The pipe text. 297 text = wx.StaticText(self.main_panel, -1, ' The data pipe to export: ', style=wx.ALIGN_LEFT) 298 tooltip = "The name of the data pipe to export to NMR-STAR format for BMRB export." 299 text.SetFont(font.normal) 300 text.SetToolTipString(tooltip) 301 pipe_sizer.Add(text, 0, wx.ALIGN_CENTER_VERTICAL, 0) 302 303 # Spacing. 304 pipe_sizer.AddSpacer(20) 305 306 # The pipe selection. 307 self.pipe_name = wx.ComboBox(self.main_panel, -1, "", style=wx.CB_DROPDOWN|wx.CB_READONLY, choices=[]) 308 self.pipe_name.SetToolTipString(tooltip) 309 self.Bind(wx.EVT_COMBOBOX, self.update_pipes, self.pipe_name) 310 pipe_sizer.Add(self.pipe_name, 0, wx.ALIGN_CENTER_VERTICAL, 0) 311 312 # Update the pipe selection. 313 self.update_pipes()
314 315
316 - def handler_close(self, event):
317 """Event handler for the close window action. 318 319 @param event: The wx event. 320 @type event: wx event 321 """ 322 323 # Unregister the observers. 324 self.observer_register(remove=True) 325 326 # Close the window. 327 event.Skip()
328 329
330 - def is_complete(self):
331 """Determine if the data input is complete. 332 333 @return: A list of all the missing components. 334 @rtype: list of str 335 """ 336 337 # Initialise. 338 missing = [] 339 340 # Relaxation data metadata. 341 if hasattr(cdp, 'ri_ids'): 342 # Loop over the data. 343 for i in range(len(cdp.ri_ids)): 344 # Check the peak intensity types. 345 if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'peak_intensity_type') or not cdp.ri_ids[i] in cdp.exp_info.peak_intensity_type.keys(): 346 missing.append("The peak intensity type for the relaxation data ID '%s'." % cdp.ri_ids[i]) 347 348 # Check the temperature calibration methods. 349 if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_calibration') or not cdp.ri_ids[i] in cdp.exp_info.temp_calibration.keys(): 350 missing.append("The temperature calibration method for the relaxation data ID '%s'." % cdp.ri_ids[i]) 351 352 # Check the temperature control methods. 353 if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'temp_control') or not cdp.ri_ids[i] in cdp.exp_info.temp_control.keys(): 354 missing.append("The temperature control method for the relaxation data ID '%s'." % cdp.ri_ids[i]) 355 356 357 # Loop over the molecules. 358 for mol, mol_id in molecule_loop(return_id=True): 359 # No name. 360 if mol.name == None: 361 missing.append("The name of the molecule for %s." % mol_id) 362 continue 363 364 # No molecule type. 365 if not hasattr(mol, 'type') or mol.type == None: 366 missing.append("The type of the molecule %s." % mol_id) 367 368 # No thiol state. 369 if not hasattr(cdp, 'exp_info') or not hasattr(cdp.exp_info, 'thiol_state'): 370 missing.append("The thiol state of the molecule %s." % mol_id) 371 372 # Return the list of missing data. 373 return missing
374 375
376 - def observer_register(self, remove=False):
377 """Register and unregister methods with the observer objects. 378 379 @keyword remove: If set to True, then the methods will be unregistered. 380 @type remove: False 381 """ 382 383 # Register. 384 if not remove: 385 status.observers.pipe_alteration.register('BMRB export', self.update_pipes) 386 387 # Unregister. 388 else: 389 # The class methods. 390 status.observers.pipe_alteration.unregister('BMRB export') 391 392 # The embedded objects methods. 393 self.relax_data.observer_register(remove=True) 394 self.molecule.observer_register(remove=True) 395 self.software.observer_register(remove=True) 396 self.scripts.observer_register(remove=True) 397 self.citation.observer_register(remove=True)
398 399
400 - def setup_frame(self):
401 """Set up the relax controller frame. 402 @return: The sizer object. 403 @rtype: wx.Sizer instance 404 """ 405 406 # Set the frame title. 407 self.SetTitle("BMRB export window") 408 409 # Set up the window icon. 410 self.SetIcons(relax_icons) 411 412 # Place all elements within a panel (to remove the dark grey in MS Windows). 413 self.main_panel = wx.Panel(self, -1) 414 415 # Use a grid sizer for packing the main elements. 416 main_sizer = wx.BoxSizer(wx.VERTICAL) 417 self.main_panel.SetSizer(main_sizer) 418 419 # Build the central sizer, with borders. 420 sizer = add_border(main_sizer, border=self.border, packing=wx.VERTICAL) 421 422 # Close the window cleanly (unregistering observers). 423 self.Bind(wx.EVT_CLOSE, self.handler_close) 424 425 # Set the default size of the controller. 426 self.SetSize(self.size) 427 self.SetMinSize(self.size_min) 428 429 # Centre the frame. 430 self.Centre() 431 432 # Return the central sizer. 433 return sizer
434 435
436 - def update_pipes(self, event=None):
437 """Update the spin view data pipe selector. 438 439 @keyword event: The wx event. 440 @type event: wx event 441 """ 442 443 # Change the cursor to busy. 444 wx.BeginBusyCursor() 445 446 # Init. 447 pipe_switch = False 448 449 # The selected pipe. 450 if event: 451 # The name of the selected pipe. 452 pipe = gui_to_str(self.pipe_name.GetString(event.GetSelection())) 453 454 # A pipe change. 455 if pipe != cdp_name(): 456 pipe_switch = True 457 else: 458 pipe = cdp_name() 459 if not pipe: 460 pipe = '' 461 462 # Clear the previous data. 463 self.pipe_name.Clear() 464 465 # The list of pipe names. 466 for name in pipe_names(): 467 self.pipe_name.Append(str_to_gui(name)) 468 469 # Switch data pipes. 470 if pipe_switch: 471 switch(pipe) 472 473 # Set the pipe name to the cdp. 474 self.pipe_name.SetValue(str_to_gui(pipe)) 475 476 # Reset the cursor. 477 if wx.IsBusy(): 478 wx.EndBusyCursor()
479