Package test_suite :: Package gui_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.gui_tests.relax_disp

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2013-2014 Edward d'Auvergne                                   # 
  4  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
  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  """GUI tests for the relaxation dispersion analyses.""" 
 25   
 26  # Python module imports. 
 27  from os import sep 
 28  import math 
 29  import wx 
 30   
 31  # relax module imports. 
 32  from data_store import Relax_data_store; ds = Relax_data_store() 
 33  import dep_check 
 34  from gui.interpreter import Interpreter; interpreter = Interpreter() 
 35  from gui.string_conv import float_to_gui, str_to_gui 
 36  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 37  from pipe_control.mol_res_spin import spin_loop 
 38  from pipe_control.pipes import switch 
 39  from specific_analyses.relax_disp.data import generate_r20_key 
 40  from specific_analyses.relax_disp.variables import EXP_TYPE_R1RHO, MODEL_CR72, MODEL_IT99, MODEL_LM63, MODEL_NOREX, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_R2EFF, MODEL_TP02 
 41  from status import Status; status = Status() 
 42  from test_suite.gui_tests.base_classes import GuiTestCase 
 43   
 44   
45 -class Relax_disp(GuiTestCase):
46 """GUI test case class for testing various aspects of the relaxation dispersion analyses.""" 47
48 - def __init__(self, methodName='runTest'):
49 """Skip the tests if the C modules are non-functional or for wxPython bugs. 50 51 @keyword methodName: The name of the test. 52 @type methodName: str 53 """ 54 55 # Execute the base class method. 56 super(Relax_disp, self).__init__(methodName) 57 58 # Missing module. 59 if not dep_check.C_module_exp_fn: 60 # Store in the status object. 61 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type])
62 63
65 """Test catching U{bug #20889<https://web.archive.org/web/https://gna.org/bugs/?20889>}, the custom peak intensity reading with a list of spectrum_ids submitted by Troels E. Linnet.""" 66 67 # The path to the files. 68 path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'peak_lists' + sep 69 70 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 71 self.app.gui.analysis.menu_new(None) 72 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 73 page.select_disp(None) 74 self.app.gui.analysis.new_wizard.wizard._go_next(None) 75 self.app.gui.analysis.new_wizard.wizard._go_next(None) 76 77 # Get the data. 78 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data() 79 80 # Set up the analysis. 81 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle, uf_exec=uf_exec) 82 83 # Alias the analysis. 84 analysis = self.app.gui.analysis.get_page_from_name("Relaxation dispersion") 85 86 # Change the results directory. 87 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 88 89 # Load the sequence. 90 file = path + 'test.seq' 91 self._execute_uf(uf_name='sequence.read', file=file, mol_name_col=1, res_name_col=3, res_num_col=2, spin_name_col=5, spin_num_col=4) 92 93 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 94 interpreter.flush() 95 96 # Set up the nuclear isotopes. 97 analysis.spin_isotope() 98 uf_store['spin.isotope'].page.SetValue('spin_id', '') 99 uf_store['spin.isotope'].wizard._go_next() 100 interpreter.flush() # Required because of the asynchronous uf call. 101 102 # Set up the peak intensity wizard. 103 analysis.peak_wizard_launch(None) 104 wizard = analysis.peak_wizard 105 106 # The spectrum. 107 page = wizard.get_page(wizard.page_indices['read']) 108 page.uf_args['file'].SetValue(str_to_gui("%stest.seq" % path)) 109 page.uf_args['spectrum_id'].SetValue(['0_2', '1_0']) 110 page.uf_args['int_col'].SetValue([6, 7]) 111 wizard._go_next(None) 112 113 # The error type. 114 page = wizard.get_page(wizard.page_indices['err_type']) 115 page.selection = 'rmsd' 116 wizard._go_next(None) 117 118 # Set the RMSD. 119 page = wizard.get_page(wizard.page_indices['rmsd']) 120 page.uf_args['error'].SetValue(float_to_gui(3000.0)) 121 wizard._ok(None) 122 123 # The peak intensities. 124 data_2 = [337765.90000000002, 1697771.0, 867389.80000000005, 2339480.0, 2574062.0, 1609356.0, 2179341.0, 1563795.0, 1535896.0, 3578841.0] 125 data_0 = [636244.59999999998, 3015788.0, 1726064.0, 4039142.0, 4313824.0, 2927111.0, 4067343.0, 2921316.0, 3005234.0, 6352595.0] 126 127 # Data checks. 128 for i in range(len(cdp.mol[0].res)): 129 # Alias the spin. 130 spin = cdp.mol[0].res[i].spin[0] 131 132 # The intensities. 133 self.assertEqual(spin.peak_intensity['1_0'], data_0[i]) 134 self.assertEqual(spin.peak_intensity['0_2'], data_2[i]) 135 136 # The errors. 137 self.assert_(hasattr(spin, 'baseplane_rmsd')) 138 self.assertEqual(spin.baseplane_rmsd['0_2'], 3000.0)
139 140
142 """Test catching U{bug #21076<https://web.archive.org/web/https://gna.org/bugs/?21076>}, loading a multi-spectra NMRPipe seriesTab file through the GUI, Error messages occur.""" 143 144 # The paths to the data files. 145 data_path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'dispersion' + sep + 'KTeilum_FMPoulsen_MAkke_2006' + sep + 'acbp_cpmg_disp_101MGuHCl_40C_041223' + sep 146 147 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 148 self.app.gui.analysis.menu_new(None) 149 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 150 page.select_disp(None) 151 self.app.gui.analysis.new_wizard.wizard._go_next(None) 152 self.app.gui.analysis.new_wizard.wizard._go_next(None) 153 154 # Get the data. 155 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data() 156 157 # Set up the analysis. 158 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle, uf_exec=uf_exec) 159 160 # Alias the analysis. 161 analysis = self.app.gui.analysis.get_page_from_name("Relaxation dispersion") 162 163 # Change the results directory. 164 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 165 166 # Load the sequence. 167 file = data_path + 'relax_2_spins_trunc.py' 168 self._execute_uf(uf_name='script', file=file, dir=None) 169 170 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 171 interpreter.flush() 172 173 # Set up the nuclear isotopes. 174 analysis.spin_isotope() 175 uf_store['spin.isotope'].page.SetValue('spin_id', '') 176 uf_store['spin.isotope'].wizard._go_next() 177 interpreter.flush() # Required because of the asynchronous uf call. 178 179 # Set up the peak intensity wizard. 180 analysis.peak_wizard_launch(None) 181 wizard = analysis.peak_wizard 182 183 # The spectrum, where the use of Keyword auto will auto-assign spectra Z_A{i}. 184 page = wizard.get_page(wizard.page_indices['read']) 185 page.uf_args['file'].SetValue(str_to_gui("%sfolded_sparky_corr_final_max_standard_trunc.ser" % data_path)) 186 page.uf_args['spectrum_id'].SetValue('auto') 187 wizard._go_next(None) 188 189 # The error type window. 190 page = wizard.get_page(wizard.page_indices['err_type']) 191 page.selection = 'rmsd' 192 wizard._go_next(None) 193 194 # Get ID from RMSD window. 195 page = wizard.get_page(wizard.page_indices['rmsd']) 196 197 # Flush all wx events (to allow the spectrum list GUI element to populate all its rows). 198 wx.Yield() 199 200 # Get the first ID from list. 201 cur_id = page.uf_args['spectrum_id'].GetValue() 202 203 # Now check that the first is set to 'Z_A0', since the keyword 'auto' was used for spectrum_id. 204 self.assertEqual(cur_id, 'Z_A0') 205 206 # Finally close the wizard to allow subsequent tests to be able to operate cleanly. 207 wizard.Close()
208 209
210 - def test_hansen_trunc_data(self):
211 """Test the GUI analysis with Flemming Hansen's CPMG data truncated to residues 70 and 71.""" 212 213 # The paths to the data files. 214 data_path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'dispersion' + sep + 'Hansen' + sep 215 data_path_500 = data_path + sep + '500_MHz' + sep 216 data_path_800 = data_path + sep + '800_MHz' + sep 217 218 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 219 self.app.gui.analysis.menu_new(None) 220 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 221 page.select_disp(None) 222 self.app.gui.analysis.new_wizard.wizard._go_next(None) 223 self.app.gui.analysis.new_wizard.wizard._go_next(None) 224 225 # Get the data. 226 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data() 227 228 # Set up the analysis. 229 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle, uf_exec=uf_exec) 230 231 # Alias the analysis. 232 analysis = self.app.gui.analysis.get_page_from_name("Relaxation dispersion") 233 234 # Change the results directory. 235 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 236 237 # Load the sequence. 238 file = data_path + 'fake_sequence.in' 239 self._execute_uf(uf_name='sequence.read', file=file, mol_name_col=None, res_num_col=1, res_name_col=2, spin_name_col=None, spin_num_col=None) 240 241 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 242 interpreter.flush() 243 244 # Set up the nuclear isotopes. 245 analysis.spin_isotope() 246 uf_store['spin.isotope'].page.SetValue('spin_id', '') 247 uf_store['spin.isotope'].wizard._go_next() 248 interpreter.flush() # Required because of the asynchronous uf call. 249 250 # The spectral data - spectrum ID, peak list file name, CPMG frequency (Hz), spectrometer frequency in Hertz. 251 data = [ 252 ['500_reference.in', '500_MHz'+sep+'reference.in', None, 500e6], 253 ['500_66.667.in', '500_MHz'+sep+'66.667.in', 66.6666, 500e6], 254 ['500_133.33.in', '500_MHz'+sep+'133.33.in', 133.3333, 500e6], 255 ['500_133.33.in.bis', '500_MHz'+sep+'133.33.in.bis', 133.3333, 500e6], 256 ['500_200.in', '500_MHz'+sep+'200.in', 200.0000, 500e6], 257 ['500_266.67.in', '500_MHz'+sep+'266.67.in', 266.6666, 500e6], 258 ['500_333.33.in', '500_MHz'+sep+'333.33.in', 333.3333, 500e6], 259 ['500_400.in', '500_MHz'+sep+'400.in', 400.0000, 500e6], 260 ['500_466.67.in', '500_MHz'+sep+'466.67.in', 466.6666, 500e6], 261 ['500_533.33.in', '500_MHz'+sep+'533.33.in', 533.3333, 500e6], 262 ['500_533.33.in.bis', '500_MHz'+sep+'533.33.in.bis', 533.3333, 500e6], 263 ['500_600.in', '500_MHz'+sep+'600.in', 600.0000, 500e6], 264 ['500_666.67.in', '500_MHz'+sep+'666.67.in', 666.6666, 500e6], 265 ['500_733.33.in', '500_MHz'+sep+'733.33.in', 733.3333, 500e6], 266 ['500_800.in', '500_MHz'+sep+'800.in', 800.0000, 500e6], 267 ['500_866.67.in', '500_MHz'+sep+'866.67.in', 866.6666, 500e6], 268 ['500_933.33.in', '500_MHz'+sep+'933.33.in', 933.3333, 500e6], 269 ['500_933.33.in.bis', '500_MHz'+sep+'933.33.in.bis', 933.3333, 500e6], 270 ['500_1000.in', '500_MHz'+sep+'1000.in', 1000.0000, 500e6], 271 ['800_reference.in', '800_MHz'+sep+'reference.in', None, 800e6], 272 ['800_66.667.in', '800_MHz'+sep+'66.667.in', 66.6666, 800e6], 273 ['800_133.33.in', '800_MHz'+sep+'133.33.in', 133.3333, 800e6], 274 ['800_133.33.in.bis', '800_MHz'+sep+'133.33.in.bis', 133.3333, 800e6], 275 ['800_200.in', '800_MHz'+sep+'200.in', 200.0000, 800e6], 276 ['800_266.67.in', '800_MHz'+sep+'266.67.in', 266.6666, 800e6], 277 ['800_333.33.in', '800_MHz'+sep+'333.33.in', 333.3333, 800e6], 278 ['800_400.in', '800_MHz'+sep+'400.in', 400.0000, 800e6], 279 ['800_466.67.in', '800_MHz'+sep+'466.67.in', 466.6666, 800e6], 280 ['800_533.33.in', '800_MHz'+sep+'533.33.in', 533.3333, 800e6], 281 ['800_533.33.in.bis', '800_MHz'+sep+'533.33.in.bis', 533.3333, 800e6], 282 ['800_600.in', '800_MHz'+sep+'600.in', 600.0000, 800e6], 283 ['800_666.67.in', '800_MHz'+sep+'666.67.in', 666.6666, 800e6], 284 ['800_733.33.in', '800_MHz'+sep+'733.33.in', 733.3333, 800e6], 285 ['800_800.in', '800_MHz'+sep+'800.in', 800.0000, 800e6], 286 ['800_866.67.in', '800_MHz'+sep+'866.67.in', 866.6666, 800e6], 287 ['800_933.33.in', '800_MHz'+sep+'933.33.in', 933.3333, 800e6], 288 ['800_933.33.in.bis', '800_MHz'+sep+'933.33.in.bis', 933.3333, 800e6], 289 ['800_1000.in', '800_MHz'+sep+'1000.in', 1000.0000, 800e6] 290 ] 291 292 # Replicated spectra. 293 replicated = [ 294 ['500_133.33.in', '500_133.33.in.bis'], 295 ['500_533.33.in', '500_533.33.in.bis'], 296 ['500_933.33.in', '500_933.33.in.bis'], 297 ['800_133.33.in', '800_133.33.in.bis'], 298 ['800_533.33.in', '800_533.33.in.bis'], 299 ['800_933.33.in', '800_933.33.in.bis'] 300 ] 301 302 # Set up the peak intensity wizard. 303 analysis.peak_wizard_launch(None) 304 wizard = analysis.peak_wizard 305 306 # Spin naming. 307 wizard.setup_page(page='name', name="N", force=True) 308 wizard._go_next(None) 309 310 # The spectrum. 311 for id, file, cpmg_frq, H_frq in data: 312 wizard.setup_page(page='read', file=data_path+file, spectrum_id=id, int_method='height', int_col=2, mol_name_col=None, res_num_col=1, res_name_col=None, spin_num_col=None, spin_name_col=None) 313 wizard._apply(None) 314 wizard._skip(None) 315 316 # The error type. 317 page = wizard.get_page(wizard.page_indices['err_type']) 318 page.selection = 'repl' 319 wizard._go_next(None) 320 321 # Replicated spectra: 322 for id1, id2 in replicated: 323 wizard.setup_page(page='repl', spectrum_ids=[id1, id2]) 324 wizard._apply(None) 325 wizard._skip(None) 326 327 # Set the experiment types. 328 for id, file, cpmg_frq, H_frq in data: 329 wizard.setup_page(page='exp_type', spectrum_id=id, exp_type='SQ CPMG') 330 wizard._apply(None) 331 wizard._skip(None) 332 333 # Set the spectrometer frequencies. 334 for id, file, cpmg_frq, H_frq in data: 335 wizard.setup_page(page='spectrometer_frequency', id=id, frq=H_frq) 336 wizard._apply(None) 337 wizard._skip(None) 338 339 # Set the relaxation time. 340 for id, file, cpmg_frq, H_frq in data: 341 wizard.setup_page(page='relax_time', spectrum_id=id, time=0.03) 342 wizard._apply(None) 343 wizard._skip(None) 344 345 # Set the CPMG frequencies. 346 for id, file, cpmg_frq, H_frq in data: 347 wizard.setup_page(page='cpmg_setup', spectrum_id=id, cpmg_frq=cpmg_frq) 348 wizard._apply(None) 349 wizard._skip(None) 350 351 # Flush all wx events (to allow the spectrum list GUI element to populate all its rows). 352 wx.Yield() 353 354 # Simulate right clicking in the spectrum list element to test the popup menu. 355 analysis.peak_intensity.on_right_click(Fake_right_click()) 356 357 # Simulate the popup menu entries to catch bugs there (just apply the user functions with the currently set values). 358 # FIXME: skipping the checks for certain wxPython bugs. 359 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 360 analysis.peak_intensity.action_relax_disp_cpmg_setup(item=4) 361 uf_store['relax_disp.cpmg_setup'].wizard._go_next() 362 interpreter.flush() 363 analysis.peak_intensity.action_relax_disp_exp_type(item=5) 364 uf_store['relax_disp.exp_type'].wizard._go_next() 365 interpreter.flush() 366 analysis.peak_intensity.action_relax_disp_relax_time(item=0) 367 uf_store['relax_disp.relax_time'].wizard._go_next() 368 interpreter.flush() 369 analysis.peak_intensity.action_spectrometer_frq(item=10) 370 uf_store['spectrometer.frequency'].wizard._go_next() 371 interpreter.flush() 372 373 # Set up the models to use. 374 models = [MODEL_R2EFF, MODEL_NOREX, MODEL_LM63, MODEL_CR72, MODEL_IT99, MODEL_NS_CPMG_2SITE_EXPANDED] 375 for i in range(len(analysis.model_field.models_stripped)): 376 if analysis.model_field.models_stripped[i] in models: 377 analysis.model_field.select[i] = True 378 else: 379 analysis.model_field.select[i] = False 380 analysis.model_field.modify() 381 382 # Set the grid search size and number of MC sims. 383 analysis.grid_inc.SetValue(4) 384 analysis.mc_sim_num.SetValue(3) 385 386 # Optimisation speedups. 387 analysis.opt_func_tol = 1e-5 388 analysis.opt_max_iterations = 1000 389 390 subset_500 = ['500_reference.in', '500_66.667.in', '500_133.33.in', '500_133.33.in.bis', '500_200.in', '500_266.67.in', '500_333.33.in', '500_400.in', '500_466.67.in', '500_533.33.in', '500_533.33.in.bis', '500_600.in', '500_666.67.in', '500_733.33.in', '500_800.in', '500_866.67.in', '500_933.33.in', '500_933.33.in.bis', '500_1000.in'] 391 subset_800 = ['800_reference.in', '800_66.667.in', '800_133.33.in', '800_133.33.in.bis', '800_200.in', '800_266.67.in', '800_333.33.in', '800_400.in', '800_466.67.in', '800_533.33.in', '800_533.33.in.bis', '800_600.in', '800_666.67.in', '800_733.33.in', '800_800.in', '800_866.67.in', '800_933.33.in', '800_933.33.in.bis', '800_1000.in'] 392 393 # Perform the error analysis. 394 self._execute_uf(uf_name='spectrum.error_analysis', subset=subset_500) 395 self._execute_uf(uf_name='spectrum.error_analysis', subset=subset_800) 396 397 # Do check of std calculation for 500 MHz 398 sum_var_500 = 0.0 399 for id_500 in subset_500: 400 sum_var_500 += cdp.var_I[id_500] 401 402 # Calculate std 403 std_500 = math.sqrt((sum_var_500)/len(subset_500)) 404 405 print("Manually calculated standard deviation for 500 MHz: %f"%std_500) 406 for id_500 in subset_500: 407 self.assertAlmostEqual(cdp.sigma_I[id_500], std_500) 408 409 # Do check of std calculation for 800 MHz 410 sum_var_800 = 0.0 411 for id_800 in subset_800: 412 sum_var_800 += cdp.var_I[id_800] 413 414 # Calculate std 415 std_800 = math.sqrt((sum_var_800)/len(subset_800)) 416 417 print("Manually calculated standard deviation for 800 MHz: %f"%std_800) 418 for id_800 in subset_800: 419 self.assertAlmostEqual(cdp.sigma_I[id_800], std_800) 420 421 # Delete all residues but :4, :70 and :71. 422 for i in range(1, 100): 423 if i in [4, 70, 71]: 424 continue 425 self._execute_uf(uf_name='residue.delete', res_id=":%s" % i) 426 427 # Execute relax. 428 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 429 430 # Wait for execution to complete. 431 analysis.thread.join() 432 433 # Flush all wx events. 434 wx.Yield() 435 436 # Exceptions in the thread. 437 self.check_exceptions() 438 439 # Check the relax controller. 440 # FIXME: skipping the checks for certain wxPython bugs. 441 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 442 self.assertEqual(self.app.gui.controller.mc_gauge_rx.GetValue(), 100) 443 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100)
444 445
447 """Test the GUI load spins from a spectrum formatted file.""" 448 449 # The path to the files. 450 path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'peak_lists' + sep 451 452 # Simulate the dispersion analysis wizard. 453 self.app.gui.analysis.menu_new(None) 454 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 455 page.select_disp(None) 456 self.app.gui.analysis.new_wizard.wizard._go_next(None) 457 self.app.gui.analysis.new_wizard.wizard._go_next(None) 458 459 # Get the data. 460 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data() 461 462 # Set up the analysis. 463 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle, uf_exec=uf_exec) 464 465 # Alias the analysis. 466 analysis = self.app.gui.analysis.get_page_from_name("Relaxation dispersion") 467 468 # Change the results directory. 469 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 470 471 # Launch the spin viewer window. 472 self.app.gui.show_tree() 473 474 # Spin loading wizard: Initialisation. 475 self.app.gui.spin_viewer.load_spins_wizard() 476 477 # Spin loading wizard: The spectrum.read_spins page. 478 page = self.app.gui.spin_viewer.wizard.get_page(0) 479 page.selection = 'new spectrum' 480 self.app.gui.spin_viewer.wizard._go_next() 481 page = self.app.gui.spin_viewer.wizard.get_page(self.app.gui.spin_viewer.wizard._current_page) 482 page.uf_args['file'].SetValue(str_to_gui(path + 'seriesTab.ser')) 483 self.app.gui.spin_viewer.wizard._go_next() 484 interpreter.flush() # Required because of the asynchronous uf call. 485 486 # Spin loading wizard: The spin loading. 487 self.app.gui.spin_viewer.wizard._go_next() 488 interpreter.flush() # Required because of the asynchronous uf call. 489 490 # Close the spin viewer window. 491 self.app.gui.spin_viewer.handler_close() 492 493 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 494 interpreter.flush() 495 496 # Test some of the sequence. 497 self.assertEqual(len(cdp.mol), 1) 498 self.assertEqual(cdp.mol[0].name, None) 499 self.assertEqual(len(cdp.mol[0].res), 3) 500 501 # 1st residue. 502 self.assertEqual(cdp.mol[0].res[0].num, 62) 503 self.assertEqual(cdp.mol[0].res[0].name, 'W') 504 self.assertEqual(len(cdp.mol[0].res[0].spin), 1) 505 self.assertEqual(cdp.mol[0].res[0].spin[0].num, None) 506 self.assertEqual(cdp.mol[0].res[0].spin[0].name, 'NE1') 507 508 # 2nd residue. 509 self.assertEqual(cdp.mol[0].res[1].num, 10) 510 self.assertEqual(cdp.mol[0].res[1].name, 'L') 511 self.assertEqual(len(cdp.mol[0].res[1].spin), 1) 512 self.assertEqual(cdp.mol[0].res[1].spin[0].num, None) 513 self.assertEqual(cdp.mol[0].res[1].spin[0].name, 'N') 514 515 # 3rd residue. 516 self.assertEqual(cdp.mol[0].res[2].num, 6) 517 self.assertEqual(cdp.mol[0].res[2].name, 'V') 518 self.assertEqual(len(cdp.mol[0].res[2].spin), 1) 519 self.assertEqual(cdp.mol[0].res[2].spin[0].num, None) 520 self.assertEqual(cdp.mol[0].res[2].spin[0].name, 'N')
521 522
523 - def test_tp02_data_to_tp02(self):
524 """Test the GUI analysis with the relaxation dispersion 'TP02' model fitting to the 'TP02' synthetic data.""" 525 526 # The paths to the data files. 527 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02'+sep 528 529 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 530 self.app.gui.analysis.menu_new(None) 531 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 532 page.select_disp(None) 533 self.app.gui.analysis.new_wizard.wizard._go_next(None) 534 self.app.gui.analysis.new_wizard.wizard._go_next(None) 535 536 # Get the data. 537 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data() 538 539 # Set up the analysis. 540 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle, uf_exec=uf_exec) 541 542 # Alias the analysis. 543 analysis = self.app.gui.analysis.get_page_from_name("Relaxation dispersion") 544 545 # Change the results directory. 546 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 547 548 # Create the sequence data. 549 self._execute_uf(uf_name='spin.create', res_name='Trp', res_num=1, spin_name='N') 550 interpreter.flush() 551 self._execute_uf(uf_name='spin.create', res_name='Trp', res_num=2, spin_name='N') 552 interpreter.flush() 553 self._execute_uf(uf_name='sequence.display') 554 interpreter.flush() 555 556 # Set up the nuclear isotopes. 557 analysis.spin_isotope() 558 uf_store['spin.isotope'].page.SetValue('spin_id', '') 559 uf_store['spin.isotope'].wizard._go_next() 560 interpreter.flush() # Required because of the asynchronous uf call. 561 562 # Load the chemical shift data. 563 self._execute_uf(uf_name='chemical_shift.read', file='ref_500MHz.list', dir=data_path) 564 interpreter.flush() 565 566 # The spectral data. 567 frq = [500, 800] 568 frq_label = ['500MHz', '800MHz'] 569 error = 200000.0 570 data = [] 571 spin_lock = [None, 1000.0, 1500.0, 2000.0, 2500.0, 3000.0, 3500.0, 4000.0, 4500.0, 5000.0, 5500.0, 6000.0] 572 for frq_index in range(len(frq)): 573 for spin_lock_index in range(len(spin_lock)): 574 # The reference. 575 if spin_lock[spin_lock_index] == None: 576 id = 'ref_%s' % frq_label[frq_index] 577 file = "ref_%s.list" % frq_label[frq_index] 578 579 # Normal data. 580 else: 581 id = "nu_%s_%s" % (spin_lock[spin_lock_index], frq_label[frq_index]) 582 file = "nu_%s_%s.list" % (spin_lock[spin_lock_index], frq_label[frq_index]) 583 584 # Append the data. 585 data.append([id, file, spin_lock[spin_lock_index], frq[frq_index]]) 586 587 # Load the R1 data. 588 for frq_index in range(len(frq)): 589 label = 'R1_%s' % frq_label[frq_index] 590 self._execute_uf(uf_name='relax_data.read', ri_id=label, ri_type='R1', frq=frq[frq_index]*1e6, file='%s.out'%label, dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 591 interpreter.flush() 592 593 # Set up the peak intensity wizard. 594 analysis.peak_wizard_launch(None) 595 wizard = analysis.peak_wizard 596 597 # The spectra. 598 for id, file, field, H_frq in data: 599 wizard.setup_page(page='read', file=data_path+file, spectrum_id=id, int_method='height', dim=1) 600 wizard._apply(None) 601 wizard._skip(None) 602 603 # The error type. 604 page = wizard.get_page(wizard.page_indices['err_type']) 605 page.selection = 'rmsd' 606 wizard._go_next(None) 607 608 # Baseplane RMSD. 609 for id, file, field, H_frq in data: 610 wizard.setup_page(page='rmsd', spectrum_id=id, error=error) 611 wizard._apply(None) 612 wizard._skip(None) 613 614 # The experiment type. 615 for id, file, field, H_frq in data: 616 wizard.setup_page(page='exp_type', spectrum_id=id, exp_type='R1rho') 617 wizard._apply(None) 618 wizard._skip(None) 619 620 # Set the spectrometer frequency. 621 for id, file, field, H_frq in data: 622 wizard.setup_page(page='spectrometer_frequency', id=id, frq=H_frq, units='MHz') 623 wizard._apply(None) 624 wizard._skip(None) 625 626 # Set the relaxation times. 627 for id, file, field, H_frq in data: 628 wizard.setup_page(page='relax_time', spectrum_id=id, time=0.1) 629 wizard._apply(None) 630 wizard._skip(None) 631 632 # Set the relaxation dispersion spin-lock field strength (nu1). 633 for id, file, field, H_frq in data: 634 wizard.setup_page(page='spin_lock_field', spectrum_id=id, field=field) 635 wizard._apply(None) 636 wizard._skip(None) 637 638 # Set the spin-lock offset. 639 for id, file, field, H_frq in data: 640 wizard.setup_page(page='spin_lock_offset', spectrum_id=id, offset=110.0) 641 wizard._apply(None) 642 wizard._skip(None) 643 644 # Flush all wx events (to allow the spectrum list GUI element to populate all its rows). 645 wx.Yield() 646 647 # Simulate right clicking in the spectrum list element to test the popup menu. 648 analysis.peak_intensity.on_right_click(Fake_right_click()) 649 650 # Simulate the popup menu entries to catch bugs there (just apply the user functions with the currently set values). 651 # FIXME: skipping the checks for certain wxPython bugs. 652 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 653 analysis.peak_intensity.action_relax_disp_spin_lock_field(item=4) 654 uf_store['relax_disp.spin_lock_field'].wizard._go_next() 655 interpreter.flush() 656 analysis.peak_intensity.action_relax_disp_exp_type(item=5) 657 uf_store['relax_disp.exp_type'].wizard._go_next() 658 interpreter.flush() 659 analysis.peak_intensity.action_relax_disp_relax_time(item=0) 660 uf_store['relax_disp.relax_time'].wizard._go_next() 661 interpreter.flush() 662 analysis.peak_intensity.action_spectrometer_frq(item=10) 663 uf_store['spectrometer.frequency'].wizard._go_next() 664 interpreter.flush() 665 666 # Deselect all but the 'TP02' model. 667 models = [MODEL_R2EFF, MODEL_NOREX, MODEL_TP02] 668 for i in range(len(analysis.model_field.models_stripped)): 669 if analysis.model_field.models_stripped[i] in models: 670 analysis.model_field.select[i] = True 671 else: 672 analysis.model_field.select[i] = False 673 analysis.model_field.modify() 674 675 # Set the grid search size and number of MC sims. 676 analysis.grid_inc.SetValue(4) 677 analysis.mc_sim_num.SetValue(3) 678 679 # Optimisation speedups. 680 analysis.opt_func_tol = 1e-10 681 analysis.opt_max_iterations = 10000 682 683 # Execute relax. 684 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 685 686 # Wait for execution to complete. 687 analysis.thread.join() 688 689 # Flush all wx events. 690 wx.Yield() 691 692 # Exceptions in the thread. 693 self.check_exceptions() 694 695 # Check the relax controller. 696 # FIXME: skipping the checks for certain wxPython bugs. 697 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 698 self.assertEqual(self.app.gui.controller.mc_gauge_rx.GetValue(), 100) 699 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100) 700 701 # The original parameters. 702 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 703 pA = 0.7654321 704 kex = 1234.56789 705 delta_omega = [7.0, 9.0] 706 707 # The R20 keys. 708 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 709 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 710 711 # Switch to the 'TP02' model data pipe, then check for each spin. 712 switch("%s - %s" % ('TP02', pipe_bundle)) 713 spin_index = 0 714 for spin, spin_id in spin_loop(return_id=True): 715 # Printout. 716 print("\nSpin %s." % spin_id) 717 718 # Check the fitted parameters. 719 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 720 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 721 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 722 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 723 724 # Increment the spin index. 725 spin_index += 1
726 727 728
729 -class Fake_right_click:
730 """Simulate a grid_cell_right_click event .""" 731
732 - def GetPosition(self):
733 """Overwrite the GetPosition() method.""" 734 735 # Return roughly the position of the forth row. 736 return wx.Point(10, 65)
737