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

Source Code for Module gui.user_functions.spectrum

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011-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 spectrum user function GUI elements.""" 
 25   
 26  # Python module imports. 
 27  from os import sep 
 28  import wx 
 29   
 30  # GUI module imports. 
 31  from base import UF_base, UF_page 
 32  from gui.misc import gui_to_float, gui_to_int, gui_to_str, str_to_gui 
 33  from gui.paths import WIZARD_IMAGE_PATH 
 34   
 35   
 36  # The container class. 
37 -class Spectrum(UF_base):
38 """The container class for holding all GUI elements.""" 39
40 - def baseplane_rmsd(self):
41 """The spectrum.baseplane_rmsd user function.""" 42 43 # Execute the wizard. 44 wizard = self.create_wizard(size_x=800, size_y=500, name='spectrum.baseplane_rmsd', uf_page=Baseplane_rmsd_page) 45 wizard.run()
46 47
48 - def delete(self, spectrum_id=None):
49 """The spectrum.delete user function. 50 51 @keyword spectrum_id: The starting spectrum ID string. 52 @type spectrum_id: str 53 """ 54 55 # Create the wizard. 56 wizard, page = self.create_wizard(size_x=700, size_y=400, name='spectrum.delete', uf_page=Delete_page, return_page=True) 57 58 # Default ID. 59 if spectrum_id: 60 page.spectrum_id.SetValue(str_to_gui(spectrum_id)) 61 62 # Execute the wizard. 63 wizard.run()
64 65
66 - def error_analysis(self):
67 """The spectrum.error_analysis user function.""" 68 69 # Execute the wizard. 70 wizard = self.create_wizard(size_x=1000, size_y=700, name='spectrum.error_analysis', uf_page=Error_analysis_page, apply_button=False) 71 wizard.run()
72 73
74 - def integration_points(self):
75 """The spectrum.integration_points user function.""" 76 77 # Execute the wizard. 78 wizard = self.create_wizard(size_x=800, size_y=600, name='spectrum.integration_points', uf_page=Integration_points_page) 79 wizard.run()
80 81
82 - def read_intensities(self):
83 """The spectrum.read_intensities user function.""" 84 85 # Execute the wizard. 86 wizard = self.create_wizard(size_x=1000, size_y=800, name='spectrum.read_intensities', uf_page=Read_intensities_page) 87 wizard.run()
88 89
90 - def replicated(self):
91 """The spectrum.replicated user function.""" 92 93 # Execute the wizard. 94 wizard = self.create_wizard(size_x=800, size_y=600, name='spectrum.replicated', uf_page=Replicated_page) 95 wizard.run()
96 97 98
99 -class Baseplane_rmsd_page(UF_page):
100 """The spectrum.baseplane_rmsd() user function page.""" 101 102 # Some class variables. 103 image_path = WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png' 104 uf_path = ['spectrum', 'baseplane_rmsd'] 105
106 - def add_contents(self, sizer):
107 """Add the specific GUI elements. 108 109 @param sizer: A sizer object. 110 @type sizer: wx.Sizer instance 111 """ 112 113 # The error. 114 self.error = self.input_field(sizer, "The error:", tooltip=self.uf._doc_args_dict['error']) 115 116 # The spectrum ID. 117 self.spectrum_id = self.combo_box(sizer, "The spectrum ID:", tooltip=self.uf._doc_args_dict['spectrum_id']) 118 119 # The spin ID restriction. 120 self.spin_id = self.spin_id_element(sizer, desc="Restrict the error setting to certain spins:")
121 122
123 - def on_display(self):
124 """Update the UI.""" 125 126 # Clear the previous data. 127 self.spectrum_id.Clear() 128 129 # Set the spectrum ID names. 130 if hasattr(cdp, 'spectrum_ids'): 131 for id in cdp.spectrum_ids: 132 self.spectrum_id.Append(str_to_gui(id))
133 134
135 - def on_execute(self):
136 """Execute the user function.""" 137 138 # Get the values. 139 error = gui_to_float(self.error.GetValue()) 140 spectrum_id = gui_to_str(self.spectrum_id.GetValue()) 141 spin_id = gui_to_str(self.spin_id.GetValue()) 142 143 # Execute. 144 self.execute('spectrum.baseplane_rmsd', error=error, spectrum_id=spectrum_id, spin_id=spin_id)
145 146 147
148 -class Delete_page(UF_page):
149 """The spectrum.read() user function page.""" 150 151 # Some class variables. 152 image_path = WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png' 153 uf_path = ['spectrum', 'delete'] 154
155 - def add_contents(self, sizer):
156 """Add the spectral data deletion specific GUI elements. 157 158 @param sizer: A sizer object. 159 @type sizer: wx.Sizer instance 160 """ 161 162 # The ID. 163 self.spectrum_id = self.combo_box(sizer, "The spectrum ID:", tooltip=self.uf._doc_args_dict['spectrum_id'])
164 165
166 - def on_execute(self):
167 """Execute the user function.""" 168 169 # The ID. 170 spectrum_id = gui_to_str(self.spectrum_id.GetValue()) 171 172 # Delete the spectral data. 173 self.execute('spectrum.delete', spectrum_id=spectrum_id)
174 175
176 - def on_display(self):
177 """Clear previous data and update the label lists.""" 178 179 # Clear the previous data. 180 self.spectrum_id.Clear() 181 182 # No data, so don't try to fill the combo boxes. 183 if not hasattr(cdp, 'spectrum_ids'): 184 return 185 186 # The spectrum IDs. 187 for i in range(len(cdp.spectrum_ids)): 188 self.spectrum_id.Append(str_to_gui(cdp.spectrum_ids[i]))
189 190 191
192 -class Error_analysis_page(UF_page):
193 """The spectrum.error_analysis() user function page.""" 194 195 # Some class variables. 196 image_path = WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png' 197 uf_path = ['spectrum', 'error_analysis'] 198 height_desc = 550 199
200 - def add_contents(self, sizer):
201 """Add the specific GUI elements. 202 203 @param sizer: A sizer object. 204 @type sizer: wx.Sizer instance 205 """
206
207 - def on_execute(self):
208 """Execute the user function.""" 209 210 # Execute. 211 self.execute('spectrum.error_analysis')
212 213 214
215 -class Integration_points_page(UF_page):
216 """The spectrum.integration_points() user function page.""" 217 218 # Some class variables. 219 image_path = WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png' 220 uf_path = ['spectrum', 'integration_points'] 221
222 - def add_contents(self, sizer):
223 """Add the specific GUI elements. 224 225 @param sizer: A sizer object. 226 @type sizer: wx.Sizer instance 227 """ 228 229 # The number of points. 230 self.N = self.input_field(sizer, "The number of points:", tooltip=self.uf._doc_args_dict['N']) 231 232 # The spectrum ID. 233 self.spectrum_id = self.combo_box(sizer, "The spectrum ID:", tooltip=self.uf._doc_args_dict['spectrum_id']) 234 235 # The spin ID restriction. 236 self.spin_id = self.spin_id_element(sizer, desc="Restrict setting the number to certain spins:")
237 238
239 - def on_display(self):
240 """Update the UI.""" 241 242 # Clear the previous data. 243 self.spectrum_id.Clear() 244 245 # Set the spectrum ID names. 246 if hasattr(cdp, 'spectrum_ids'): 247 for id in cdp.spectrum_ids: 248 self.spectrum_id.Append(str_to_gui(id))
249 250
251 - def on_execute(self):
252 """Execute the user function.""" 253 254 # Get the values. 255 N = gui_to_int(self.N.GetValue()) 256 spectrum_id = gui_to_str(self.spectrum_id.GetValue()) 257 spin_id = gui_to_str(self.spin_id.GetValue()) 258 259 # Execute. 260 self.execute('spectrum.integration_points', N=N, spectrum_id=spectrum_id, spin_id=spin_id)
261 262 263
264 -class Read_intensities_page(UF_page):
265 """The spectrum.read_intensities() user function page.""" 266 267 # Some class variables. 268 height_desc = 140 269 image_path = WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png' 270 uf_path = ['spectrum', 'read_intensities'] 271
272 - def add_contents(self, sizer):
273 """Add the specific GUI elements. 274 275 @param sizer: A sizer object. 276 @type sizer: wx.Sizer instance 277 """ 278 279 # Add a file selection. 280 self.file = self.file_selection(sizer, "The peak intensity file:", message="Peak intensity file selection", style=wx.FD_OPEN, tooltip=self.uf._doc_args_dict['file'], preview=True) 281 282 # The spectrum ID. 283 self.spectrum_id = self.input_field(sizer, "The spectrum ID:", tooltip=self.uf._doc_args_dict['spectrum_id']) 284 285 # The heteronucleus and proton. 286 self.heteronuc = self.input_field(sizer, "The heternucleus name:", tooltip=self.uf._doc_args_dict['heteronuc']) 287 self.proton = self.input_field(sizer, "The heternucleus name:", tooltip=self.uf._doc_args_dict['proton']) 288 self.heteronuc.SetValue(str_to_gui('N')) 289 self.proton.SetValue(str_to_gui('H')) 290 291 # The integration method. 292 self.int_method = self.combo_box(sizer, "The peak integration method:", tooltip=self.uf._doc_args_dict['int_method'], choices=['height', 'point sum', 'other']) 293 self.int_method.SetValue(str_to_gui('height')) 294 295 # The integration column. 296 self.int_col = self.input_field(sizer, "The integration column:", tooltip=self.uf._doc_args_dict['int_col']) 297 298 # The spin ID restriction. 299 self.spin_id = self.spin_id_element(sizer, desc="Restrict data loading to certain spins:") 300 301 # The integration column. 302 self.ncproc = self.input_field(sizer, "The Bruker ncproc value:", tooltip=self.uf._doc_args_dict['ncproc']) 303 304 # The parameter file settings. 305 self.free_file_format(sizer, data_cols=False, padding=3, spacer=0)
306 307
308 - def on_execute(self):
309 """Execute the user function.""" 310 311 # The file name. 312 file = gui_to_str(self.file.GetValue()) 313 314 # The values. 315 spectrum_id = gui_to_str(self.spectrum_id.GetValue()) 316 heteronuc = gui_to_str(self.heteronuc.GetValue()) 317 proton = gui_to_str(self.proton.GetValue()) 318 int_method = gui_to_str(self.int_method.GetValue()) 319 ncproc = gui_to_int(self.ncproc.GetValue()) 320 321 # Get the column numbers. 322 int_col = gui_to_int(self.int_col.GetValue()) 323 spin_id_col = gui_to_int(self.spin_id_col.GetValue()) 324 mol_name_col = gui_to_int(self.mol_name_col.GetValue()) 325 res_num_col = gui_to_int(self.res_num_col.GetValue()) 326 res_name_col = gui_to_int(self.res_name_col.GetValue()) 327 spin_num_col = gui_to_int(self.spin_num_col.GetValue()) 328 spin_name_col = gui_to_int(self.spin_name_col.GetValue()) 329 330 # The column separator. 331 sep = gui_to_str(self.sep.GetValue()) 332 if sep == 'white space': 333 sep = None 334 335 # The spin ID. 336 spin_id = gui_to_str(self.spin_id.GetValue()) 337 338 # Read the peak intensities. 339 self.execute('spectrum.read_intensities', file=file, spectrum_id=spectrum_id, heteronuc=heteronuc, proton=proton, int_method=int_method, int_col=int_col, spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep, spin_id=spin_id, ncproc=ncproc)
340 341 342
343 -class Replicated_page(UF_page):
344 """The spectrum.replicated() user function page.""" 345 346 # Some class variables. 347 image_path = WIZARD_IMAGE_PATH + 'spectrum' + sep + 'spectrum_200.png' 348 uf_path = ['spectrum', 'replicated'] 349
350 - def add_contents(self, sizer):
351 """Add the specific GUI elements. 352 353 @param sizer: A sizer object. 354 @type sizer: wx.Sizer instance 355 """ 356 357 # The spectrum IDs. 358 self.spectrum_id_boxes = [] 359 self.spectrum_id_boxes.append(self.combo_box(sizer, "The 1st spectrum ID:", tooltip="The ID string of the first of the replicated spectra.")) 360 self.spectrum_id_boxes.append(self.combo_box(sizer, "The 2nd spectrum ID:", tooltip="The ID string of the second spectrum which is a replicate of the first spectrum.")) 361 self.spectrum_id_boxes.append(self.combo_box(sizer, "The 3rd spectrum ID:", tooltip="The ID string of the third spectrum which is a replicate of the first spectrum.")) 362 self.spectrum_id_boxes.append(self.combo_box(sizer, "The 4th spectrum ID:", tooltip="The ID string of the fourth spectrum which is a replicate of the first spectrum.")) 363 self.spectrum_id_boxes.append(self.combo_box(sizer, "The 5th spectrum ID:", tooltip="The ID string of the fifth spectrum which is a replicate of the first spectrum."))
364 365
366 - def on_display(self):
367 """Update the UI.""" 368 369 # Loop over each box. 370 for i in range(len(self.spectrum_id_boxes)): 371 # First clear all data. 372 self.spectrum_id_boxes[i].Clear() 373 374 # Set the spectrum ID names. 375 if hasattr(cdp, 'spectrum_ids'): 376 for id in cdp.spectrum_ids: 377 self.spectrum_id_boxes[i].Append(str_to_gui(id))
378 379
380 - def on_execute(self):
381 """Execute the user function.""" 382 383 # Loop over each box. 384 spectrum_ids = [] 385 for i in range(len(self.spectrum_id_boxes)): 386 # No selection (fix for Mac OS X). 387 if self.spectrum_id_boxes[i].GetSelection() == -1: 388 continue 389 390 # Get the value. 391 val = gui_to_str(self.spectrum_id_boxes[i].GetValue()) 392 393 # Add the value to the list if not None. 394 if val != None: 395 spectrum_ids.append(val) 396 397 # Execute (only if more than one ID is given). 398 if len(spectrum_ids) > 1: 399 self.execute('spectrum.replicated', spectrum_ids=spectrum_ids)
400