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