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