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,2017 Edward d'Auvergne                                   # 
  4  # Copyright (C) 2013-2015 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
195 """Catch an Attribute error when the replicated spectra are specified via the spectrum list rather than the wizard.""" 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 201 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 202 analysis = self.new_analysis_wizard(analysis_type='disp') 203 204 # Change the results directory. 205 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 206 207 # Load the sequence. 208 file = data_path + 'fake_sequence.in' 209 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) 210 211 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 212 interpreter.flush() 213 214 # Set up the nuclear isotopes. 215 analysis.spin_isotope() 216 uf_store['spin.isotope'].page.SetValue('spin_id', '') 217 uf_store['spin.isotope'].wizard._go_next() 218 interpreter.flush() # Required because of the asynchronous uf call. 219 220 # The spectral data - spectrum ID, peak list file name, CPMG frequency (Hz), spectrometer frequency in Hertz. 221 data = [ 222 ['500_reference.in', '500_MHz'+sep+'reference.in', None, 500e6], 223 ['500_66.667.in', '500_MHz'+sep+'66.667.in', 66.6666, 500e6], 224 ['500_133.33.in', '500_MHz'+sep+'133.33.in', 133.3333, 500e6], 225 ['500_133.33.in.bis', '500_MHz'+sep+'133.33.in.bis', 133.3333, 500e6], 226 ] 227 228 # Set up the peak intensity wizard. 229 analysis.peak_wizard_launch(None) 230 wizard = analysis.peak_wizard 231 232 # Spin naming. 233 wizard.setup_page(page='name', name="N", force=True) 234 wizard._go_next(None) 235 236 # The spectrum. 237 for id, file, cpmg_frq, H_frq in data: 238 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) 239 wizard._apply(None) 240 wizard._skip(None) 241 242 # The error type. 243 page = wizard.get_page(wizard.page_indices['err_type']) 244 page.selection = 'repl' 245 wizard._go_next(None) 246 247 # Replicated spectra (skip). 248 wizard._go_next(None) 249 250 # Set the experiment types. 251 for id, file, cpmg_frq, H_frq in data: 252 wizard.setup_page(page='exp_type', spectrum_id=id, exp_type='SQ CPMG') 253 wizard._apply(None) 254 wizard._skip(None) 255 256 # Set the spectrometer frequencies. 257 for id, file, cpmg_frq, H_frq in data: 258 wizard.setup_page(page='spectrometer_frequency', id=id, frq=H_frq) 259 wizard._apply(None) 260 wizard._skip(None) 261 262 # Set the relaxation time. 263 for id, file, cpmg_frq, H_frq in data: 264 wizard.setup_page(page='relax_time', spectrum_id=id, time=0.03) 265 wizard._apply(None) 266 wizard._skip(None) 267 268 # Set the CPMG frequencies. 269 for id, file, cpmg_frq, H_frq in data: 270 wizard.setup_page(page='cpmg_setup', spectrum_id=id, cpmg_frq=cpmg_frq) 271 wizard._apply(None) 272 wizard._skip(None) 273 274 # Flush all wx events (to allow the spectrum list GUI element to populate all its rows). 275 wx.Yield() 276 277 # Simulate setting replicated spectra via the spectrum list element. 278 analysis.peak_intensity.action_spectrum_replicated(item=0)
279 280
281 - def test_hansen_trunc_data(self):
282 """Test the GUI analysis with Flemming Hansen's CPMG data truncated to residues 70 and 71.""" 283 284 # The paths to the data files. 285 data_path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'dispersion' + sep + 'Hansen' + sep 286 data_path_500 = data_path + sep + '500_MHz' + sep 287 data_path_800 = data_path + sep + '800_MHz' + sep 288 289 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 290 analysis = self.new_analysis_wizard(analysis_type='disp') 291 292 # Change the results directory. 293 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 294 295 # Load the sequence. 296 file = data_path + 'fake_sequence.in' 297 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) 298 299 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 300 interpreter.flush() 301 302 # Set up the nuclear isotopes. 303 analysis.spin_isotope() 304 uf_store['spin.isotope'].page.SetValue('spin_id', '') 305 uf_store['spin.isotope'].wizard._go_next() 306 interpreter.flush() # Required because of the asynchronous uf call. 307 308 # The spectral data - spectrum ID, peak list file name, CPMG frequency (Hz), spectrometer frequency in Hertz. 309 data = [ 310 ['500_reference.in', '500_MHz'+sep+'reference.in', None, 500e6], 311 ['500_66.667.in', '500_MHz'+sep+'66.667.in', 66.6666, 500e6], 312 ['500_133.33.in', '500_MHz'+sep+'133.33.in', 133.3333, 500e6], 313 ['500_133.33.in.bis', '500_MHz'+sep+'133.33.in.bis', 133.3333, 500e6], 314 ['500_200.in', '500_MHz'+sep+'200.in', 200.0000, 500e6], 315 ['500_266.67.in', '500_MHz'+sep+'266.67.in', 266.6666, 500e6], 316 ['500_333.33.in', '500_MHz'+sep+'333.33.in', 333.3333, 500e6], 317 ['500_400.in', '500_MHz'+sep+'400.in', 400.0000, 500e6], 318 ['500_466.67.in', '500_MHz'+sep+'466.67.in', 466.6666, 500e6], 319 ['500_533.33.in', '500_MHz'+sep+'533.33.in', 533.3333, 500e6], 320 ['500_533.33.in.bis', '500_MHz'+sep+'533.33.in.bis', 533.3333, 500e6], 321 ['500_600.in', '500_MHz'+sep+'600.in', 600.0000, 500e6], 322 ['500_666.67.in', '500_MHz'+sep+'666.67.in', 666.6666, 500e6], 323 ['500_733.33.in', '500_MHz'+sep+'733.33.in', 733.3333, 500e6], 324 ['500_800.in', '500_MHz'+sep+'800.in', 800.0000, 500e6], 325 ['500_866.67.in', '500_MHz'+sep+'866.67.in', 866.6666, 500e6], 326 ['500_933.33.in', '500_MHz'+sep+'933.33.in', 933.3333, 500e6], 327 ['500_933.33.in.bis', '500_MHz'+sep+'933.33.in.bis', 933.3333, 500e6], 328 ['500_1000.in', '500_MHz'+sep+'1000.in', 1000.0000, 500e6], 329 ['800_reference.in', '800_MHz'+sep+'reference.in', None, 800e6], 330 ['800_66.667.in', '800_MHz'+sep+'66.667.in', 66.6666, 800e6], 331 ['800_133.33.in', '800_MHz'+sep+'133.33.in', 133.3333, 800e6], 332 ['800_133.33.in.bis', '800_MHz'+sep+'133.33.in.bis', 133.3333, 800e6], 333 ['800_200.in', '800_MHz'+sep+'200.in', 200.0000, 800e6], 334 ['800_266.67.in', '800_MHz'+sep+'266.67.in', 266.6666, 800e6], 335 ['800_333.33.in', '800_MHz'+sep+'333.33.in', 333.3333, 800e6], 336 ['800_400.in', '800_MHz'+sep+'400.in', 400.0000, 800e6], 337 ['800_466.67.in', '800_MHz'+sep+'466.67.in', 466.6666, 800e6], 338 ['800_533.33.in', '800_MHz'+sep+'533.33.in', 533.3333, 800e6], 339 ['800_533.33.in.bis', '800_MHz'+sep+'533.33.in.bis', 533.3333, 800e6], 340 ['800_600.in', '800_MHz'+sep+'600.in', 600.0000, 800e6], 341 ['800_666.67.in', '800_MHz'+sep+'666.67.in', 666.6666, 800e6], 342 ['800_733.33.in', '800_MHz'+sep+'733.33.in', 733.3333, 800e6], 343 ['800_800.in', '800_MHz'+sep+'800.in', 800.0000, 800e6], 344 ['800_866.67.in', '800_MHz'+sep+'866.67.in', 866.6666, 800e6], 345 ['800_933.33.in', '800_MHz'+sep+'933.33.in', 933.3333, 800e6], 346 ['800_933.33.in.bis', '800_MHz'+sep+'933.33.in.bis', 933.3333, 800e6], 347 ['800_1000.in', '800_MHz'+sep+'1000.in', 1000.0000, 800e6] 348 ] 349 350 # Replicated spectra. 351 replicated = [ 352 ['500_133.33.in', '500_133.33.in.bis'], 353 ['500_533.33.in', '500_533.33.in.bis'], 354 ['500_933.33.in', '500_933.33.in.bis'], 355 ['800_133.33.in', '800_133.33.in.bis'], 356 ['800_533.33.in', '800_533.33.in.bis'], 357 ['800_933.33.in', '800_933.33.in.bis'] 358 ] 359 360 # Set up the peak intensity wizard. 361 analysis.peak_wizard_launch(None) 362 wizard = analysis.peak_wizard 363 364 # Spin naming. 365 wizard.setup_page(page='name', name="N", force=True) 366 wizard._go_next(None) 367 368 # The spectrum. 369 for id, file, cpmg_frq, H_frq in data: 370 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) 371 wizard._apply(None) 372 wizard._skip(None) 373 374 # The error type. 375 page = wizard.get_page(wizard.page_indices['err_type']) 376 page.selection = 'repl' 377 wizard._go_next(None) 378 379 # Replicated spectra: 380 for id1, id2 in replicated: 381 wizard.setup_page(page='repl', spectrum_ids=[id1, id2]) 382 wizard._apply(None) 383 wizard._skip(None) 384 385 # Set the experiment types. 386 for id, file, cpmg_frq, H_frq in data: 387 wizard.setup_page(page='exp_type', spectrum_id=id, exp_type='SQ CPMG') 388 wizard._apply(None) 389 wizard._skip(None) 390 391 # Set the spectrometer frequencies. 392 for id, file, cpmg_frq, H_frq in data: 393 wizard.setup_page(page='spectrometer_frequency', id=id, frq=H_frq) 394 wizard._apply(None) 395 wizard._skip(None) 396 397 # Set the relaxation time. 398 for id, file, cpmg_frq, H_frq in data: 399 wizard.setup_page(page='relax_time', spectrum_id=id, time=0.03) 400 wizard._apply(None) 401 wizard._skip(None) 402 403 # Set the CPMG frequencies. 404 for id, file, cpmg_frq, H_frq in data: 405 wizard.setup_page(page='cpmg_setup', spectrum_id=id, cpmg_frq=cpmg_frq) 406 wizard._apply(None) 407 wizard._skip(None) 408 409 # Flush all wx events (to allow the spectrum list GUI element to populate all its rows). 410 wx.Yield() 411 412 # Simulate right clicking in the spectrum list element to test the popup menu. 413 analysis.peak_intensity.on_right_click(Fake_right_click()) 414 415 # Simulate the popup menu entries to catch bugs there (just apply the user functions with the currently set values). 416 # FIXME: skipping the checks for certain wxPython bugs. 417 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 418 analysis.peak_intensity.action_relax_disp_cpmg_setup(item=4) 419 uf_store['relax_disp.cpmg_setup'].wizard._go_next() 420 interpreter.flush() 421 analysis.peak_intensity.action_relax_disp_exp_type(item=5) 422 uf_store['relax_disp.exp_type'].wizard._go_next() 423 interpreter.flush() 424 analysis.peak_intensity.action_relax_disp_relax_time(item=0) 425 uf_store['relax_disp.relax_time'].wizard._go_next() 426 interpreter.flush() 427 analysis.peak_intensity.action_spectrometer_frq(item=10) 428 uf_store['spectrometer.frequency'].wizard._go_next() 429 interpreter.flush() 430 431 # Set up the models to use. 432 models = [MODEL_R2EFF, MODEL_NOREX, MODEL_LM63, MODEL_CR72, MODEL_IT99, MODEL_NS_CPMG_2SITE_EXPANDED] 433 for i in range(len(analysis.model_field.models_stripped)): 434 if analysis.model_field.models_stripped[i] in models: 435 analysis.model_field.select[i] = True 436 else: 437 analysis.model_field.select[i] = False 438 analysis.model_field.modify() 439 440 # Set the grid search size and number of MC sims. 441 analysis.grid_inc.SetValue(4) 442 analysis.mc_sim_num.SetValue(3) 443 444 # Optimisation speedups. 445 analysis.opt_func_tol = 1e-5 446 analysis.opt_max_iterations = 1000 447 448 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'] 449 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'] 450 451 # Perform the error analysis. 452 self._execute_uf(uf_name='spectrum.error_analysis', subset=subset_500) 453 self._execute_uf(uf_name='spectrum.error_analysis', subset=subset_800) 454 455 # Do check of std calculation for 500 MHz 456 sum_var_500 = 0.0 457 for id_500 in subset_500: 458 sum_var_500 += cdp.var_I[id_500] 459 460 # Calculate std 461 std_500 = math.sqrt((sum_var_500)/len(subset_500)) 462 463 print("Manually calculated standard deviation for 500 MHz: %f"%std_500) 464 for id_500 in subset_500: 465 self.assertAlmostEqual(cdp.sigma_I[id_500], std_500) 466 467 # Do check of std calculation for 800 MHz 468 sum_var_800 = 0.0 469 for id_800 in subset_800: 470 sum_var_800 += cdp.var_I[id_800] 471 472 # Calculate std 473 std_800 = math.sqrt((sum_var_800)/len(subset_800)) 474 475 print("Manually calculated standard deviation for 800 MHz: %f"%std_800) 476 for id_800 in subset_800: 477 self.assertAlmostEqual(cdp.sigma_I[id_800], std_800) 478 479 # Delete all residues but :4, :70 and :71. 480 for i in range(1, 100): 481 if i in [4, 70, 71]: 482 continue 483 self._execute_uf(uf_name='residue.delete', res_id=":%s" % i) 484 485 # Execute relax. 486 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 487 488 # Wait for execution to complete. 489 analysis.thread.join() 490 491 # Flush all wx events. 492 wx.Yield() 493 494 # Exceptions in the thread. 495 self.check_exceptions() 496 497 # Check the relax controller. 498 # FIXME: skipping the checks for certain wxPython bugs. 499 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 500 self.assertEqual(self.app.gui.controller.mc_gauge_rx.GetValue(), 100) 501 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100)
502 503
505 """This test truncated private data which was provided by Paul Schanda. This systemtest uncovers some unfortunate problems when 506 running an analysis and reading points by the R2eff method. 507 """ 508 509 # Data path. 510 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Paul_Schanda_2015_Nov' 511 file_1 = data_path + sep + '1_prepare_data.py' 512 file_2 = data_path + sep + '2_load_data_GUI.py' 513 514 ## Store the out 515 outdir = ds.tmpdir 516 status.outdir = outdir 517 518 # Simulate the dispersion analysis wizard. 519 analysis = self.new_analysis_wizard(analysis_type='disp') 520 521 ## Run script to make data. 522 self._execute_uf(uf_name='script', file=file_1, dir=None) 523 524 ## Run script to make setup of data data. 525 self._execute_uf(uf_name='script', file=file_2, dir=None) 526 527 # Change the results directory. 528 analysis.field_results_dir.SetValue(str_to_gui(outdir)) 529 530 # Now load the state 531 state_file = outdir + sep + "temp_state.bz2" 532 self.app.gui.state_load(file_name=state_file)
533 534
536 """Test the GUI load spins from a spectrum formatted file.""" 537 538 # The path to the files. 539 path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'peak_lists' + sep 540 541 # Simulate the dispersion analysis wizard. 542 analysis = self.new_analysis_wizard(analysis_type='disp') 543 544 # Change the results directory. 545 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 546 547 # Launch the spin viewer window. 548 self.app.gui.show_tree() 549 550 # Spin loading wizard: Initialisation. 551 self.app.gui.spin_viewer.load_spins_wizard() 552 553 # Spin loading wizard: The spectrum.read_spins page. 554 page = self.app.gui.spin_viewer.wizard.get_page(0) 555 page.selection = 'new spectrum' 556 self.app.gui.spin_viewer.wizard._go_next() 557 page = self.app.gui.spin_viewer.wizard.get_page(self.app.gui.spin_viewer.wizard._current_page) 558 page.uf_args['file'].SetValue(str_to_gui(path + 'seriesTab.ser')) 559 self.app.gui.spin_viewer.wizard._go_next() 560 interpreter.flush() # Required because of the asynchronous uf call. 561 562 # Spin loading wizard: The spin loading. 563 self.app.gui.spin_viewer.wizard._go_next() 564 interpreter.flush() # Required because of the asynchronous uf call. 565 566 # Close the spin viewer window. 567 self.app.gui.spin_viewer.handler_close() 568 569 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 570 interpreter.flush() 571 572 # Test some of the sequence. 573 self.assertEqual(len(cdp.mol), 1) 574 self.assertEqual(cdp.mol[0].name, None) 575 self.assertEqual(len(cdp.mol[0].res), 3) 576 577 # 1st residue. 578 self.assertEqual(cdp.mol[0].res[0].num, 62) 579 self.assertEqual(cdp.mol[0].res[0].name, 'W') 580 self.assertEqual(len(cdp.mol[0].res[0].spin), 1) 581 self.assertEqual(cdp.mol[0].res[0].spin[0].num, None) 582 self.assertEqual(cdp.mol[0].res[0].spin[0].name, 'NE1') 583 584 # 2nd residue. 585 self.assertEqual(cdp.mol[0].res[1].num, 10) 586 self.assertEqual(cdp.mol[0].res[1].name, 'L') 587 self.assertEqual(len(cdp.mol[0].res[1].spin), 1) 588 self.assertEqual(cdp.mol[0].res[1].spin[0].num, None) 589 self.assertEqual(cdp.mol[0].res[1].spin[0].name, 'N') 590 591 # 3rd residue. 592 self.assertEqual(cdp.mol[0].res[2].num, 6) 593 self.assertEqual(cdp.mol[0].res[2].name, 'V') 594 self.assertEqual(len(cdp.mol[0].res[2].spin), 1) 595 self.assertEqual(cdp.mol[0].res[2].spin[0].num, None) 596 self.assertEqual(cdp.mol[0].res[2].spin[0].name, 'N')
597 598
599 - def test_r2eff_err_estimate(self):
600 """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..""" 601 602 # The paths to the data files. 603 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 604 605 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 606 analysis = self.new_analysis_wizard(analysis_type='disp') 607 608 # Change the results directory. 609 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 610 611 # Load the sequence. 612 file = data_path + '1_setup_r1rho_GUI.py' 613 self._execute_uf(uf_name='script', file=file, dir=None) 614 615 # De select spins 616 self._execute_uf(uf_name='deselect.spin', spin_id=":1-100") 617 self._execute_uf(uf_name='select.spin', spin_id=":52@N") 618 619 # Deselect all but the few models. 620 models = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94] 621 for i in range(len(analysis.model_field.models_stripped)): 622 if analysis.model_field.models_stripped[i] in models: 623 analysis.model_field.select[i] = True 624 else: 625 analysis.model_field.select[i] = False 626 analysis.model_field.modify() 627 628 # Set the grid search size and number of MC sims. 629 analysis.grid_inc.SetValue(0) 630 analysis.mc_sim_num.SetValue(3) 631 analysis.exp_mc_sim_num.SetValue(-1) 632 633 # Do fitting of R1. 634 analysis.r1_fit.SetValue(bool(True)) 635 636 # Execute relax. 637 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 638 639 # Wait for execution to complete. 640 analysis.thread.join() 641 642 # Flush all wx events. 643 wx.Yield() 644 645 # Exceptions in the thread. 646 self.check_exceptions()
647 648
649 - def test_tp02_data_to_tp02(self):
650 """Test the GUI analysis with the relaxation dispersion 'TP02' model fitting to the 'TP02' synthetic data.""" 651 652 # The paths to the data files. 653 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02'+sep 654 655 # Simulate the new analysis wizard, selecting the fixed time CPMG experiment. 656 analysis = self.new_analysis_wizard(analysis_type='disp') 657 658 # Change the results directory. 659 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 660 661 # Create the sequence data. 662 self._execute_uf(uf_name='spin.create', res_name='Trp', res_num=1, spin_name='N') 663 interpreter.flush() 664 self._execute_uf(uf_name='spin.create', res_name='Trp', res_num=2, spin_name='N') 665 interpreter.flush() 666 self._execute_uf(uf_name='sequence.display') 667 interpreter.flush() 668 669 # Set up the nuclear isotopes. 670 analysis.spin_isotope() 671 uf_store['spin.isotope'].page.SetValue('spin_id', '') 672 uf_store['spin.isotope'].wizard._go_next() 673 interpreter.flush() # Required because of the asynchronous uf call. 674 675 # Load the chemical shift data. 676 self._execute_uf(uf_name='chemical_shift.read', file='ref_500MHz.list', dir=data_path) 677 interpreter.flush() 678 679 # The spectral data. 680 frq = [500, 800] 681 frq_label = ['500MHz', '800MHz'] 682 error = 200000.0 683 data = [] 684 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] 685 for frq_index in range(len(frq)): 686 for spin_lock_index in range(len(spin_lock)): 687 # The reference. 688 if spin_lock[spin_lock_index] == None: 689 id = 'ref_%s' % frq_label[frq_index] 690 file = "ref_%s.list" % frq_label[frq_index] 691 692 # Normal data. 693 else: 694 id = "nu_%s_%s" % (spin_lock[spin_lock_index], frq_label[frq_index]) 695 file = "nu_%s_%s.list" % (spin_lock[spin_lock_index], frq_label[frq_index]) 696 697 # Append the data. 698 data.append([id, file, spin_lock[spin_lock_index], frq[frq_index]]) 699 700 # Load the R1 data. 701 for frq_index in range(len(frq)): 702 label = 'R1_%s' % frq_label[frq_index] 703 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) 704 interpreter.flush() 705 706 # Set up the peak intensity wizard. 707 analysis.peak_wizard_launch(None) 708 wizard = analysis.peak_wizard 709 710 # The spectra. 711 for id, file, field, H_frq in data: 712 wizard.setup_page(page='read', file=data_path+file, spectrum_id=id, int_method='height', dim=1) 713 wizard._apply(None) 714 wizard._skip(None) 715 716 # The error type. 717 page = wizard.get_page(wizard.page_indices['err_type']) 718 page.selection = 'rmsd' 719 wizard._go_next(None) 720 721 # Baseplane RMSD. 722 for id, file, field, H_frq in data: 723 wizard.setup_page(page='rmsd', spectrum_id=id, error=error) 724 wizard._apply(None) 725 wizard._skip(None) 726 727 # The experiment type. 728 for id, file, field, H_frq in data: 729 wizard.setup_page(page='exp_type', spectrum_id=id, exp_type='R1rho') 730 wizard._apply(None) 731 wizard._skip(None) 732 733 # Set the spectrometer frequency. 734 for id, file, field, H_frq in data: 735 wizard.setup_page(page='spectrometer_frequency', id=id, frq=H_frq, units='MHz') 736 wizard._apply(None) 737 wizard._skip(None) 738 739 # Set the relaxation times. 740 for id, file, field, H_frq in data: 741 wizard.setup_page(page='relax_time', spectrum_id=id, time=0.1) 742 wizard._apply(None) 743 wizard._skip(None) 744 745 # Set the relaxation dispersion spin-lock field strength (nu1). 746 for id, file, field, H_frq in data: 747 wizard.setup_page(page='spin_lock_field', spectrum_id=id, field=field) 748 wizard._apply(None) 749 wizard._skip(None) 750 751 # Set the spin-lock offset. 752 for id, file, field, H_frq in data: 753 wizard.setup_page(page='spin_lock_offset', spectrum_id=id, offset=110.0) 754 wizard._apply(None) 755 wizard._skip(None) 756 757 # Flush all wx events (to allow the spectrum list GUI element to populate all its rows). 758 wx.Yield() 759 760 # Simulate right clicking in the spectrum list element to test the popup menu. 761 analysis.peak_intensity.on_right_click(Fake_right_click()) 762 763 # Simulate the popup menu entries to catch bugs there (just apply the user functions with the currently set values). 764 # FIXME: skipping the checks for certain wxPython bugs. 765 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 766 analysis.peak_intensity.action_relax_disp_spin_lock_field(item=4) 767 uf_store['relax_disp.spin_lock_field'].wizard._go_next() 768 interpreter.flush() 769 analysis.peak_intensity.action_relax_disp_exp_type(item=5) 770 uf_store['relax_disp.exp_type'].wizard._go_next() 771 interpreter.flush() 772 analysis.peak_intensity.action_relax_disp_relax_time(item=0) 773 uf_store['relax_disp.relax_time'].wizard._go_next() 774 interpreter.flush() 775 analysis.peak_intensity.action_spectrometer_frq(item=10) 776 uf_store['spectrometer.frequency'].wizard._go_next() 777 interpreter.flush() 778 779 # Deselect all but the 'TP02' model. 780 models = [MODEL_R2EFF, MODEL_NOREX, MODEL_TP02] 781 for i in range(len(analysis.model_field.models_stripped)): 782 if analysis.model_field.models_stripped[i] in models: 783 analysis.model_field.select[i] = True 784 else: 785 analysis.model_field.select[i] = False 786 analysis.model_field.modify() 787 788 # Set the grid search size and number of MC sims. 789 analysis.grid_inc.SetValue(4) 790 analysis.mc_sim_num.SetValue(3) 791 792 # Optimisation speedups. 793 analysis.opt_func_tol = 1e-10 794 analysis.opt_max_iterations = 10000 795 796 # Execute relax. 797 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 798 799 # Wait for execution to complete. 800 analysis.thread.join() 801 802 # Flush all wx events. 803 wx.Yield() 804 805 # Exceptions in the thread. 806 self.check_exceptions() 807 808 # Check the relax controller. 809 # FIXME: skipping the checks for certain wxPython bugs. 810 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 811 self.assertEqual(self.app.gui.controller.mc_gauge_rx.GetValue(), 100) 812 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100) 813 814 # The original parameters. 815 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 816 pA = 0.7654321 817 kex = 1234.56789 818 delta_omega = [7.0, 9.0] 819 820 # The R20 keys. 821 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 822 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 823 824 # Switch to the 'TP02' model data pipe, then check for each spin. 825 switch("%s - %s" % ('TP02', get_bundle())) 826 spin_index = 0 827 for spin, spin_id in spin_loop(return_id=True): 828 # Printout. 829 print("\nSpin %s." % spin_id) 830 831 # Check the fitted parameters. 832 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 833 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 834 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 835 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 836 837 # Increment the spin index. 838 spin_index += 1
839 840 841
842 -class Fake_right_click:
843 """Simulate a grid_cell_right_click event .""" 844
845 - def GetPosition(self):
846 """Overwrite the GetPosition() method.""" 847 848 # Return roughly the position of the forth row. 849 return wx.Point(10, 65)
850