Package gui :: Package components :: Module spectrum
[hide private]
[frames] | no frames]

Source Code for Module gui.components.spectrum

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2011 Michael Bieri                                       # 
  4  # Copyright (C) 2010-2012 Edward d'Auvergne                                   # 
  5  #                                                                             # 
  6  # This file is part of the program relax.                                     # 
  7  #                                                                             # 
  8  # relax is free software; you can redistribute it and/or modify               # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation; either version 2 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # relax is distributed in the hope that it will be useful,                    # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with relax; if not, write to the Free Software                        # 
 20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Module docstring. 
 25  """Module containing the classes for GUI components involving spectral data.""" 
 26   
 27  # Python module imports. 
 28  import wx 
 29  import wx.lib.buttons 
 30   
 31  # relax module imports. 
 32  from status import Status; status = Status() 
 33  from generic_fns.spectrum import replicated_flags, replicated_ids 
 34  from graphics import fetch_icon 
 35  from user_functions.data import Uf_info; uf_info = Uf_info() 
 36   
 37  # relax GUI module imports. 
 38  from gui.components.base_list import Base_list 
 39  from gui.components.menu import build_menu_item 
 40  from gui.fonts import font 
 41  from gui.misc import add_border 
 42  from gui.string_conv import float_to_gui, gui_to_str, str_to_gui 
 43  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 44   
 45   
46 -class Spectra_list(Base_list):
47 """The GUI element for listing loaded spectral data.""" 48
49 - def __init__(self, gui=None, parent=None, box=None, id=None, fn_add=None, proportion=0, button_placement='default'):
50 """Build the spectral list GUI element. 51 52 @keyword gui: The main GUI object. 53 @type gui: wx.Frame instance 54 @keyword parent: The parent GUI element that this is to be attached to (the panel object). 55 @type parent: wx object 56 @keyword data: The data storage container. 57 @type data: class instance 58 @keyword box: The vertical box sizer to pack this GUI component into. 59 @type box: wx.BoxSizer instance 60 @keyword id: A unique identification string. This is used to register the update method with the GUI user function observer object. 61 @type id: str 62 @keyword fn_add: The function to execute when clicking on the 'Add' button. 63 @type fn_add: func 64 @keyword proportion: The window proportion parameter. 65 @type proportion: bool 66 @keyword button_placement: Override the button visibility and placement. The value of 'default' will leave the buttons at the default setting. The value of 'top' will place the buttons at the top, 'bottom' will place them at the bottom, and None will turn off the buttons. 67 @type button_placement: str or None 68 """ 69 70 # Store the arguments. 71 self.fn_add = fn_add 72 73 # Initialise the base class. 74 super(Spectra_list, self).__init__(gui=gui, parent=parent, box=box, id=id, proportion=proportion, button_placement=button_placement)
75 76
77 - def action_relax_fit_relax_time(self, event):
78 """Launch the relax_fit.relax_time user function. 79 80 @param event: The wx event. 81 @type event: wx event 82 """ 83 84 # The current selection. 85 item = self.element.GetFirstSelected() 86 87 # The spectrum ID. 88 id = gui_to_str(self.element.GetItemText(item)) 89 90 # The current time. 91 time = None 92 if hasattr(cdp, 'relax_times') and id in cdp.relax_times.keys(): 93 time = cdp.relax_times[id] 94 95 # Launch the dialog. 96 if time == None: 97 uf_store['relax_fit.relax_time'](spectrum_id=id) 98 else: 99 uf_store['relax_fit.relax_time'](time=time, spectrum_id=id)
100 101
102 - def action_spectrum_baseplane_rmsd(self, event):
103 """Launch the spectrum.baseplane_rmsd user function. 104 105 @param event: The wx event. 106 @type event: wx event 107 """ 108 109 # The current selection. 110 item = self.element.GetFirstSelected() 111 112 # The spectrum ID. 113 id = gui_to_str(self.element.GetItemText(item)) 114 115 # Launch the dialog. 116 uf_store['spectrum.baseplane_rmsd'](spectrum_id=id)
117 118
119 - def action_spectrum_delete(self, event):
120 """Launch the spectrum.delete user function. 121 122 @param event: The wx event. 123 @type event: wx event 124 """ 125 126 # The current selection. 127 item = self.element.GetFirstSelected() 128 129 # No selection. 130 if item == -1: 131 id = None 132 133 # Selected item. 134 else: 135 # The spectrum ID. 136 id = gui_to_str(self.element.GetItemText(item)) 137 138 # Launch the dialog. 139 uf_store['spectrum.delete'](spectrum_id=id)
140 141
142 - def action_spectrum_integration_points(self, event):
143 """Launch the spectrum.integration_points user function. 144 145 @param event: The wx event. 146 @type event: wx event 147 """ 148 149 # The current selection. 150 item = self.element.GetFirstSelected() 151 152 # The spectrum ID. 153 id = gui_to_str(self.element.GetItemText(item)) 154 155 # Launch the dialog. 156 uf_store['spectrum.integration_points'](spectrum_id=id)
157 158
159 - def action_spectrum_replicated(self, event):
160 """Launch the spectrum.replicated user function. 161 162 @param event: The wx event. 163 @type event: wx event 164 """ 165 166 # The current selection. 167 item = self.element.GetFirstSelected() 168 169 # The spectrum ID. 170 id = gui_to_str(self.element.GetItemText(item)) 171 172 # The current replicates. 173 replicates = replicated_ids(id) 174 175 # Launch the dialog. 176 if replicates == []: 177 uf_store['spectrum.replicated'](spectrum_ids=id) 178 else: 179 uf_store['spectrum.replicated'](spectrum_ids=replicates)
180 181
182 - def noe_spectrum_type(self, index):
183 """Add the NOE spectral type info to the element. 184 185 @param index: The column index for the data. 186 @type index: int 187 @return: True if a spectrum type exists, False otherwise. 188 @rtype: bool 189 """ 190 191 # No type info. 192 if not hasattr(cdp, 'spectrum_type') or not len(cdp.spectrum_type): 193 return False 194 195 # Append a column. 196 self.element.InsertColumn(index, str_to_gui("NOE spectrum type")) 197 198 # Translation table. 199 table = { 200 'sat': 'Saturated', 201 'ref': 'Reference' 202 } 203 204 # Set the values. 205 for i in range(len(cdp.spectrum_ids)): 206 # No value. 207 if cdp.spectrum_ids[i] not in cdp.spectrum_type.keys(): 208 continue 209 210 # Set the value. 211 self.element.SetStringItem(i, index, str_to_gui(table[cdp.spectrum_type[cdp.spectrum_ids[i]]])) 212 213 # Successful. 214 return True
215 216
217 - def relax_times(self, index):
218 """Add the relaxation delay time info to the element. 219 220 @param index: The column index for the data. 221 @type index: int 222 @return: True if relaxation times exist, False otherwise. 223 @rtype: bool 224 """ 225 226 # No type info. 227 if not hasattr(cdp, 'relax_times') or not len(cdp.relax_times): 228 return False 229 230 # Append a column. 231 self.element.InsertColumn(index, str_to_gui("Delay times")) 232 233 # Set the values. 234 for i in range(len(cdp.spectrum_ids)): 235 # No value. 236 if cdp.spectrum_ids[i] not in cdp.relax_times.keys(): 237 continue 238 239 # Set the value. 240 self.element.SetStringItem(i, index, float_to_gui(cdp.relax_times[cdp.spectrum_ids[i]])) 241 242 # Successful. 243 return True
244 245
246 - def replicates(self, index):
247 """Add the replicated spectra info to the element. 248 249 @param index: The column index for the data. 250 @type index: int 251 @return: True if relaxation times exist, False otherwise. 252 @rtype: bool 253 """ 254 255 # No type info. 256 if not hasattr(cdp, 'replicates') or not len(cdp.replicates): 257 return False 258 259 # Replicated spectra. 260 repl = replicated_flags() 261 262 # Append a column. 263 self.element.InsertColumn(index, str_to_gui("Replicate IDs")) 264 265 # Set the values. 266 for i in range(len(cdp.spectrum_ids)): 267 # No replicates. 268 if not repl[cdp.spectrum_ids[i]]: 269 continue 270 271 # The replicated spectra. 272 id_list = replicated_ids(cdp.spectrum_ids[i]) 273 274 # Convert to a string. 275 text = '' 276 for j in range(len(id_list)): 277 # Add the id. 278 text = "%s%s" % (text, id_list[j]) 279 280 # Separator. 281 if j < len(id_list)-1: 282 text = "%s, " % text 283 284 # Set the value. 285 self.element.SetStringItem(i, index, str_to_gui(text)) 286 287 # Successful. 288 return True
289 290
291 - def setup(self):
292 """Override the base variables.""" 293 294 # GUI variables. 295 self.title = "Spectra list" 296 self.observer_base_name = "spectra list" 297 298 # The column titles. 299 self.columns = [] 300 301 # Button set up. 302 self.button_placement = 'top' 303 self.button_info = [ 304 { 305 'object': 'button_add', 306 'label': ' Add', 307 'icon': fetch_icon('oxygen.actions.list-add-relax-blue', "22x22"), 308 'method': self.fn_add, 309 'tooltip': "Read a spectral data file." 310 }, { 311 'object': 'button_delete', 312 'label': ' Delete', 313 'icon': fetch_icon('oxygen.actions.list-remove', "22x22"), 314 'method': self.action_spectrum_delete, 315 'tooltip': "Delete loaded relaxation data from the relax data store." 316 } 317 ] 318 319 # The right click popup menu. 320 self.popup_menus = [ 321 { 322 'id': wx.NewId(), 323 'text': "Set the &baseplane RMSD", 324 'icon': fetch_icon(uf_info.get_uf('spectrum.baseplane_rmsd').gui_icon), 325 'method': self.action_relax_fit_relax_time 326 }, { 327 'id': wx.NewId(), 328 'text': "&Delete the peak intensities", 329 'icon': fetch_icon(uf_info.get_uf('spectrum.delete').gui_icon), 330 'method': self.action_spectrum_baseplane_rmsd 331 }, { 332 'id': wx.NewId(), 333 'text': "Set the number of integration &points", 334 'icon': fetch_icon(uf_info.get_uf('spectrum.integration_points').gui_icon), 335 'method': self.action_spectrum_delete 336 }, { 337 'id': wx.NewId(), 338 'text': "Specify which spectra are &replicated", 339 'icon': fetch_icon(uf_info.get_uf('spectrum.replicated').gui_icon), 340 'method': self.action_spectrum_integration_points 341 }, { 342 'id': wx.NewId(), 343 'text': "Set the relaxation &time", 344 'icon': fetch_icon(uf_info.get_uf('relax_fit.relax_time').gui_icon), 345 'method': self.action_spectrum_replicated 346 } 347 ]
348 349
350 - def update_data(self):
351 """Method called from self.build_element_safe() to update the list data.""" 352 353 # Initialise the column index for the data. 354 index = 1 355 356 # Delete the rows and columns. 357 self.element.DeleteAllItems() 358 self.element.DeleteAllColumns() 359 360 # Initialise to a single column. 361 self.element.InsertColumn(0, str_to_gui("Spectrum ID string")) 362 363 # Expand the number of rows to match the number of spectrum IDs, and add the IDs. 364 n = 0 365 if hasattr(cdp, 'spectrum_ids'): 366 # The number of IDs. 367 n = len(cdp.spectrum_ids) 368 369 # Set the IDs. 370 for i in range(n): 371 self.element.InsertStringItem(i, str_to_gui(cdp.spectrum_ids[i])) 372 373 # The NOE spectrum type. 374 if self.noe_spectrum_type(index): 375 index += 1 376 377 # The relaxation times. 378 if self.relax_times(index): 379 index += 1 380 381 # The replicated spectra. 382 if self.replicates(index): 383 index += 1
384