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 """Test the GUI load spins from a spectrum formatted file.""" 419 420 # The path to the files. 421 path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'peak_lists' + sep 422 423 # Simulate the dispersion analysis wizard. 424 analysis = self.new_analysis_wizard(analysis_type='disp') 425 426 # Change the results directory. 427 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 428 429 # Launch the spin viewer window. 430 self.app.gui.show_tree() 431 432 # Spin loading wizard: Initialisation. 433 self.app.gui.spin_viewer.load_spins_wizard() 434 435 # Spin loading wizard: The spectrum.read_spins page. 436 page = self.app.gui.spin_viewer.wizard.get_page(0) 437 page.selection = 'new spectrum' 438 self.app.gui.spin_viewer.wizard._go_next() 439 page = self.app.gui.spin_viewer.wizard.get_page(self.app.gui.spin_viewer.wizard._current_page) 440 page.uf_args['file'].SetValue(str_to_gui(path + 'seriesTab.ser')) 441 self.app.gui.spin_viewer.wizard._go_next() 442 interpreter.flush() # Required because of the asynchronous uf call. 443 444 # Spin loading wizard: The spin loading. 445 self.app.gui.spin_viewer.wizard._go_next() 446 interpreter.flush() # Required because of the asynchronous uf call. 447 448 # Close the spin viewer window. 449 self.app.gui.spin_viewer.handler_close() 450 451 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 452 interpreter.flush() 453 454 # Test some of the sequence. 455 self.assertEqual(len(cdp.mol), 1) 456 self.assertEqual(cdp.mol[0].name, None) 457 self.assertEqual(len(cdp.mol[0].res), 3) 458 459 # 1st residue. 460 self.assertEqual(cdp.mol[0].res[0].num, 62) 461 self.assertEqual(cdp.mol[0].res[0].name, 'W') 462 self.assertEqual(len(cdp.mol[0].res[0].spin), 1) 463 self.assertEqual(cdp.mol[0].res[0].spin[0].num, None) 464 self.assertEqual(cdp.mol[0].res[0].spin[0].name, 'NE1') 465 466 # 2nd residue. 467 self.assertEqual(cdp.mol[0].res[1].num, 10) 468 self.assertEqual(cdp.mol[0].res[1].name, 'L') 469 self.assertEqual(len(cdp.mol[0].res[1].spin), 1) 470 self.assertEqual(cdp.mol[0].res[1].spin[0].num, None) 471 self.assertEqual(cdp.mol[0].res[1].spin[0].name, 'N') 472 473 # 3rd residue. 474 self.assertEqual(cdp.mol[0].res[2].num, 6) 475 self.assertEqual(cdp.mol[0].res[2].name, 'V') 476 self.assertEqual(len(cdp.mol[0].res[2].spin), 1) 477 self.assertEqual(cdp.mol[0].res[2].spin[0].num, None) 478 self.assertEqual(cdp.mol[0].res[2].spin[0].name, 'N')
479 480
481 - def test_r2eff_err_estimate(self):
482 """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..""" 483 484 # The paths to the data files. 485 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 486 487 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 488 analysis = self.new_analysis_wizard(analysis_type='disp') 489 490 # Change the results directory. 491 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 492 493 # Load the sequence. 494 file = data_path + '1_setup_r1rho_GUI.py' 495 self._execute_uf(uf_name='script', file=file, dir=None) 496 497 # De select spins 498 self._execute_uf(uf_name='deselect.spin', spin_id=":1-100") 499 self._execute_uf(uf_name='select.spin', spin_id=":52@N") 500 501 # Deselect all but the few models. 502 models = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94] 503 for i in range(len(analysis.model_field.models_stripped)): 504 if analysis.model_field.models_stripped[i] in models: 505 analysis.model_field.select[i] = True 506 else: 507 analysis.model_field.select[i] = False 508 analysis.model_field.modify() 509 510 # Set the grid search size and number of MC sims. 511 analysis.grid_inc.SetValue(0) 512 analysis.mc_sim_num.SetValue(3) 513 analysis.exp_mc_sim_num.SetValue(-1) 514 515 # Do fitting of R1. 516 analysis.r1_fit.SetValue(bool(True)) 517 518 # Execute relax. 519 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 520 521 # Wait for execution to complete. 522 analysis.thread.join() 523 524 # Flush all wx events. 525 wx.Yield() 526 527 # Exceptions in the thread. 528 self.check_exceptions()
529 530
531 - def test_tp02_data_to_tp02(self):
532 """Test the GUI analysis with the relaxation dispersion 'TP02' model fitting to the 'TP02' synthetic data.""" 533 534 # The paths to the data files. 535 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02'+sep 536 537 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 538 analysis = self.new_analysis_wizard(analysis_type='disp') 539 540 # Change the results directory. 541 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 542 543 # Create the sequence data. 544 self._execute_uf(uf_name='spin.create', res_name='Trp', res_num=1, spin_name='N') 545 interpreter.flush() 546 self._execute_uf(uf_name='spin.create', res_name='Trp', res_num=2, spin_name='N') 547 interpreter.flush() 548 self._execute_uf(uf_name='sequence.display') 549 interpreter.flush() 550 551 # Set up the nuclear isotopes. 552 analysis.spin_isotope() 553 uf_store['spin.isotope'].page.SetValue('spin_id', '') 554 uf_store['spin.isotope'].wizard._go_next() 555 interpreter.flush() # Required because of the asynchronous uf call. 556 557 # Load the chemical shift data. 558 self._execute_uf(uf_name='chemical_shift.read', file='ref_500MHz.list', dir=data_path) 559 interpreter.flush() 560 561 # The spectral data. 562 frq = [500, 800] 563 frq_label = ['500MHz', '800MHz'] 564 error = 200000.0 565 data = [] 566 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] 567 for frq_index in range(len(frq)): 568 for spin_lock_index in range(len(spin_lock)): 569 # The reference. 570 if spin_lock[spin_lock_index] == None: 571 id = 'ref_%s' % frq_label[frq_index] 572 file = "ref_%s.list" % frq_label[frq_index] 573 574 # Normal data. 575 else: 576 id = "nu_%s_%s" % (spin_lock[spin_lock_index], frq_label[frq_index]) 577 file = "nu_%s_%s.list" % (spin_lock[spin_lock_index], frq_label[frq_index]) 578 579 # Append the data. 580 data.append([id, file, spin_lock[spin_lock_index], frq[frq_index]]) 581 582 # Load the R1 data. 583 for frq_index in range(len(frq)): 584 label = 'R1_%s' % frq_label[frq_index] 585 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) 586 interpreter.flush() 587 588 # Set up the peak intensity wizard. 589 analysis.peak_wizard_launch(None) 590 wizard = analysis.peak_wizard 591 592 # The spectra. 593 for id, file, field, H_frq in data: 594 wizard.setup_page(page='read', file=data_path+file, spectrum_id=id, int_method='height', dim=1) 595 wizard._apply(None) 596 wizard._skip(None) 597 598 # The error type. 599 page = wizard.get_page(wizard.page_indices['err_type']) 600 page.selection = 'rmsd' 601 wizard._go_next(None) 602 603 # Baseplane RMSD. 604 for id, file, field, H_frq in data: 605 wizard.setup_page(page='rmsd', spectrum_id=id, error=error) 606 wizard._apply(None) 607 wizard._skip(None) 608 609 # The experiment type. 610 for id, file, field, H_frq in data: 611 wizard.setup_page(page='exp_type', spectrum_id=id, exp_type='R1rho') 612 wizard._apply(None) 613 wizard._skip(None) 614 615 # Set the spectrometer frequency. 616 for id, file, field, H_frq in data: 617 wizard.setup_page(page='spectrometer_frequency', id=id, frq=H_frq, units='MHz') 618 wizard._apply(None) 619 wizard._skip(None) 620 621 # Set the relaxation times. 622 for id, file, field, H_frq in data: 623 wizard.setup_page(page='relax_time', spectrum_id=id, time=0.1) 624 wizard._apply(None) 625 wizard._skip(None) 626 627 # Set the relaxation dispersion spin-lock field strength (nu1). 628 for id, file, field, H_frq in data: 629 wizard.setup_page(page='spin_lock_field', spectrum_id=id, field=field) 630 wizard._apply(None) 631 wizard._skip(None) 632 633 # Set the spin-lock offset. 634 for id, file, field, H_frq in data: 635 wizard.setup_page(page='spin_lock_offset', spectrum_id=id, offset=110.0) 636 wizard._apply(None) 637 wizard._skip(None) 638 639 # Flush all wx events (to allow the spectrum list GUI element to populate all its rows). 640 wx.Yield() 641 642 # Simulate right clicking in the spectrum list element to test the popup menu. 643 analysis.peak_intensity.on_right_click(Fake_right_click()) 644 645 # Simulate the popup menu entries to catch bugs there (just apply the user functions with the currently set values). 646 # FIXME: skipping the checks for certain wxPython bugs. 647 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 648 analysis.peak_intensity.action_relax_disp_spin_lock_field(item=4) 649 uf_store['relax_disp.spin_lock_field'].wizard._go_next() 650 interpreter.flush() 651 analysis.peak_intensity.action_relax_disp_exp_type(item=5) 652 uf_store['relax_disp.exp_type'].wizard._go_next() 653 interpreter.flush() 654 analysis.peak_intensity.action_relax_disp_relax_time(item=0) 655 uf_store['relax_disp.relax_time'].wizard._go_next() 656 interpreter.flush() 657 analysis.peak_intensity.action_spectrometer_frq(item=10) 658 uf_store['spectrometer.frequency'].wizard._go_next() 659 interpreter.flush() 660 661 # Deselect all but the 'TP02' model. 662 models = [MODEL_R2EFF, MODEL_NOREX, MODEL_TP02] 663 for i in range(len(analysis.model_field.models_stripped)): 664 if analysis.model_field.models_stripped[i] in models: 665 analysis.model_field.select[i] = True 666 else: 667 analysis.model_field.select[i] = False 668 analysis.model_field.modify() 669 670 # Set the grid search size and number of MC sims. 671 analysis.grid_inc.SetValue(4) 672 analysis.mc_sim_num.SetValue(3) 673 674 # Optimisation speedups. 675 analysis.opt_func_tol = 1e-10 676 analysis.opt_max_iterations = 10000 677 678 # Execute relax. 679 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 680 681 # Wait for execution to complete. 682 analysis.thread.join() 683 684 # Flush all wx events. 685 wx.Yield() 686 687 # Exceptions in the thread. 688 self.check_exceptions() 689 690 # Check the relax controller. 691 # FIXME: skipping the checks for certain wxPython bugs. 692 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 693 self.assertEqual(self.app.gui.controller.mc_gauge_rx.GetValue(), 100) 694 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100) 695 696 # The original parameters. 697 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 698 pA = 0.7654321 699 kex = 1234.56789 700 delta_omega = [7.0, 9.0] 701 702 # The R20 keys. 703 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 704 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 705 706 # Switch to the 'TP02' model data pipe, then check for each spin. 707 switch("%s - %s" % ('TP02', get_bundle())) 708 spin_index = 0 709 for spin, spin_id in spin_loop(return_id=True): 710 # Printout. 711 print("\nSpin %s." % spin_id) 712 713 # Check the fitted parameters. 714 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 715 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 716 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 717 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 718 719 # Increment the spin index. 720 spin_index += 1
721 722 723
724 -class Fake_right_click:
725 """Simulate a grid_cell_right_click event .""" 726
727 - def GetPosition(self):
728 """Overwrite the GetPosition() method.""" 729 730 # Return roughly the position of the forth row. 731 return wx.Point(10, 65)
732