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