1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module containing the classes for GUI components involving spectral data."""
25
26
27 import wx
28 import wx.lib.buttons
29
30
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
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
67 self.fn_add = fn_add
68 self.relax_times_flag = relax_times
69
70
71 super(Spectra_list, self).__init__(gui=gui, parent=parent, box=box, id=id, proportion=proportion, button_placement=button_placement)
72
73
75 """Launch the relax_fit.relax_time user function.
76
77 @param event: The wx event.
78 @type event: wx event
79 """
80
81
82 item = self.element.GetFirstSelected()
83
84
85 id = gui_to_str(self.element.GetItemText(item))
86
87
88 time = None
89 if hasattr(cdp, 'relax_times') and id in cdp.relax_times.keys():
90 time = cdp.relax_times[id]
91
92
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
100 """Launch the spectrum.baseplane_rmsd user function.
101
102 @param event: The wx event.
103 @type event: wx event
104 """
105
106
107 item = self.element.GetFirstSelected()
108
109
110 id = gui_to_str(self.element.GetItemText(item))
111
112
113 uf_store['spectrum.baseplane_rmsd'](spectrum_id=id)
114
115
117 """Launch the spectrum.delete user function.
118
119 @param event: The wx event.
120 @type event: wx event
121 """
122
123
124 item = self.element.GetFirstSelected()
125
126
127 if item == -1:
128 id = None
129
130
131 else:
132
133 id = gui_to_str(self.element.GetItemText(item))
134
135
136 uf_store['spectrum.delete'](spectrum_id=id)
137
138
140 """Launch the spectrum.integration_points user function.
141
142 @param event: The wx event.
143 @type event: wx event
144 """
145
146
147 item = self.element.GetFirstSelected()
148
149
150 id = gui_to_str(self.element.GetItemText(item))
151
152
153 uf_store['spectrum.integration_points'](spectrum_id=id)
154
155
157 """Launch the spectrum.replicated user function.
158
159 @param event: The wx event.
160 @type event: wx event
161 """
162
163
164 item = self.element.GetFirstSelected()
165
166
167 id = gui_to_str(self.element.GetItemText(item))
168
169
170 replicates = replicated_ids(id)
171
172
173 if replicates == []:
174 uf_store['spectrum.replicated'](spectrum_ids=id)
175 else:
176 uf_store['spectrum.replicated'](spectrum_ids=replicates)
177
178
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
189 if not hasattr(cdp, 'spectrum_type') or not len(cdp.spectrum_type):
190 return False
191
192
193 self.element.InsertColumn(index, str_to_gui("NOE spectrum type"))
194
195
196 table = {
197 'sat': 'Saturated',
198 'ref': 'Reference'
199 }
200
201
202 for i in range(len(cdp.spectrum_ids)):
203
204 if cdp.spectrum_ids[i] not in cdp.spectrum_type.keys():
205 continue
206
207
208 self.element.SetStringItem(i, index, str_to_gui(table[cdp.spectrum_type[cdp.spectrum_ids[i]]]))
209
210
211 return True
212
213
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
224 if not hasattr(cdp, 'relax_times') or not len(cdp.relax_times):
225 return False
226
227
228 self.element.InsertColumn(index, str_to_gui("Delay times (s)"))
229
230
231 for i in range(len(cdp.spectrum_ids)):
232
233 if cdp.spectrum_ids[i] not in cdp.relax_times.keys():
234 continue
235
236
237 self.element.SetStringItem(i, index, float_to_gui(cdp.relax_times[cdp.spectrum_ids[i]]))
238
239
240 return True
241
242
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
253 if not hasattr(cdp, 'replicates') or not len(cdp.replicates):
254 return False
255
256
257 repl = replicated_flags()
258
259
260 self.element.InsertColumn(index, str_to_gui("Replicate IDs"))
261
262
263 for i in range(len(cdp.spectrum_ids)):
264
265 if not repl[cdp.spectrum_ids[i]]:
266 continue
267
268
269 id_list = replicated_ids(cdp.spectrum_ids[i])
270
271
272 text = ''
273 for j in range(len(id_list)):
274
275 text = "%s%s" % (text, id_list[j])
276
277
278 if j < len(id_list)-1:
279 text = "%s, " % text
280
281
282 self.element.SetStringItem(i, index, str_to_gui(text))
283
284
285 return True
286
287
289 """Override the base variables."""
290
291
292 self.title = "Spectra list"
293 self.observer_base_name = "spectra list"
294
295
296 self.columns = []
297
298
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
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
350 """Method called from self.build_element_safe() to update the list data."""
351
352
353 index = 1
354
355
356 self.element.DeleteAllItems()
357 self.element.DeleteAllColumns()
358
359
360 self.element.InsertColumn(0, str_to_gui("Spectrum ID"))
361
362
363 n = 0
364 if hasattr(cdp, 'spectrum_ids'):
365
366 n = len(cdp.spectrum_ids)
367
368
369 for i in range(n):
370 self.element.InsertStringItem(i, str_to_gui(cdp.spectrum_ids[i]))
371
372
373 if self.noe_spectrum_type(index):
374 index += 1
375
376
377 if self.relax_times_flag and self.relax_times(index):
378 index += 1
379
380
381 if self.replicates(index):
382 index += 1
383