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

Source Code for Module test_suite.gui_tests.model_free

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-2013 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Python module imports. 
 23  from os import sep 
 24  import wx 
 25   
 26  # relax module imports. 
 27  from data_store import Relax_data_store; ds = Relax_data_store() 
 28  from pipe_control.interatomic import interatomic_loop 
 29  from pipe_control.mol_res_spin import spin_loop 
 30  from status import Status; status = Status() 
 31  from test_suite.gui_tests.base_classes import GuiTestCase 
 32   
 33  # relax GUI imports. 
 34  from gui.analyses import auto_model_free 
 35  from gui.interpreter import Interpreter; interpreter = Interpreter() 
 36  from gui.string_conv import str_to_gui 
 37  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 38   
 39   
40 -class Mf(GuiTestCase):
41 """Class for testing various aspects specific to the model-free auto-analysis.""" 42
44 """Catch U{bug #20479<https://web.archive.org/web/https://gna.org/bugs/?20479>}, the failure to load a relax state in the GUI. 45 46 This was reported by U{Stanislava Panova<https://web.archive.org/web/https://gna.org/users/stacy>}. 47 """ 48 49 # Simulate the new analysis wizard. 50 self.app.gui.analysis.menu_new(None) 51 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 52 page.select_mf(None) 53 page.analysis_name.SetValue(str_to_gui("Model-free test")) 54 self.app.gui.analysis.new_wizard.wizard._go_next(None) 55 page = self.app.gui.analysis.new_wizard.wizard.get_page(1) 56 self.app.gui.analysis.new_wizard.wizard._go_next(None) 57 58 # Get the data. 59 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data() 60 61 # Set up the analysis. 62 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle) 63 64 # Alias the analysis. 65 analysis = self.app.gui.analysis.get_page_from_name("Model-free test") 66 67 # Change the results directory. 68 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 69 70 # The data path. 71 data_path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'model_free' + sep + 'bug_20479_gui_final_pipe' + sep 72 73 # Launch the spin viewer window. 74 self.app.gui.show_tree() 75 76 # Spin loading wizard: Initialisation. 77 self.app.gui.spin_viewer.load_spins_wizard() 78 79 # Spin loading wizard: The NOE data file. 80 page = self.app.gui.spin_viewer.wizard.get_page(0) 81 page.selection = 'sequence' 82 self.app.gui.spin_viewer.wizard._go_next() 83 page = self.app.gui.spin_viewer.wizard.get_page(self.app.gui.spin_viewer.wizard._current_page) 84 page.uf_args['file'].SetValue(str_to_gui(data_path + 'NoeRelN')) 85 self.app.gui.spin_viewer.wizard._go_next() 86 interpreter.flush() # Required because of the asynchronous uf call. 87 88 # Spin loading wizard: The spin loading. 89 self.app.gui.spin_viewer.wizard._go_next() 90 interpreter.flush() # Required because of the asynchronous uf call. 91 92 # Close the spin viewer window. 93 self.app.gui.spin_viewer.handler_close() 94 95 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 96 interpreter.flush() 97 98 # Set the element type. 99 self._execute_uf(uf_name='spin.element', element='N') 100 101 # Load the relaxation data. 102 data = [ 103 ['NoeRelN', 'noe_800', 'NOE', 800000031.0], 104 ['R1850', 'r1_800', 'R1', 800000031.0], 105 ['R2863', 'r2_800', 'R2', 800000031.0], 106 ['R2604', 'r2_600', 'R2', 599999000.0] 107 ] 108 for i in range(len(data)): 109 self._execute_uf(uf_name='relax_data.read', file=data_path+data[i][0], ri_id=data[i][1], ri_type=data[i][2], frq=data[i][3], 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) 110 111 # Attach the protons. 112 self._execute_uf(uf_name='sequence.attach_protons') 113 114 # Dipole-dipole interaction wizard. 115 analysis.setup_dipole_pair() # Initialisation. 116 analysis.dipole_wizard._skip() # Skip the structure.read_pdb user function. 117 analysis.dipole_wizard._skip() # Skip the structure.get_pos user function. 118 analysis.dipole_wizard._go_next() # The interatom.define user function. 119 interpreter.flush() # Required because of the asynchronous uf call. 120 analysis.dipole_wizard._go_next() # The interatom.set_dist user function. 121 interpreter.flush() # Required because of the asynchronous uf call. 122 analysis.dipole_wizard._skip() # Skip the interatom.unit_vectors user function. 123 124 # Set up the CSA interaction. 125 analysis.value_set_csa() 126 uf_store['value.set'].wizard._go_next() 127 interpreter.flush() # Required because of the asynchronous uf call. 128 129 # Set up the nuclear isotopes. 130 analysis.spin_isotope_heteronuc() 131 uf_store['spin.isotope'].wizard._go_next() 132 interpreter.flush() # Required because of the asynchronous uf call. 133 analysis.spin_isotope_proton() 134 uf_store['spin.isotope'].wizard._go_next() 135 interpreter.flush() # Required because of the asynchronous uf call. 136 137 # Select only the tm0 and tm1 local tm models. 138 analysis.local_tm_model_field.select = [True, True, False, False, False, False, False, False, False, False] 139 analysis.local_tm_model_field.modify() 140 141 # Select only the m1 and m2 model-free models. 142 analysis.mf_model_field.select = [False, True, True, False, False, False, False, False, False, False] 143 analysis.mf_model_field.modify() 144 145 # Change the grid increments. 146 analysis.grid_inc.SetValue(3) 147 analysis.data.diff_tensor_grid_inc = {'sphere': 5, 'prolate': 5, 'oblate': 5, 'ellipsoid': 3} 148 149 # Set the number of Monte Carlo simulations. 150 analysis.mc_sim_num.SetValue(2) 151 152 # Set the maximum number of iterations (changing the allowed values). 153 analysis.max_iter.control.SetRange(0, 100) 154 analysis.max_iter.SetValue(1) 155 156 # Modify some of the class variables to speed up optimisation. 157 auto_model_free.dauvergne_protocol.dAuvergne_protocol.opt_func_tol = 1e-5 158 auto_model_free.dauvergne_protocol.dAuvergne_protocol.opt_max_iterations = 1000 159 160 # Execute the 'local_tm', 'sphere' and 'final' protocol stages sequentially. 161 for protocol in ['local_tm', 'sphere', 'final']: 162 # Print out. 163 text = "Sequential global model optimisation: %s" % protocol 164 char = "%" 165 print("\n\n\n\n%s\n%s %s %s\n%s\n\n\n" % (char*(len(text)+4), char, text, char, char*(len(text)+4))) 166 167 # Set the protocol mode. 168 if protocol == 'local_tm': 169 analysis.mode_win.select_local_tm() 170 elif protocol == 'sphere': 171 analysis.mode_win.select_sphere() 172 else: 173 analysis.mode_win.select_final() 174 analysis.mode_dialog() 175 176 # Execute relax. 177 state = analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 178 179 # Wait for execution to complete. 180 if hasattr(analysis, 'thread'): 181 analysis.thread.join() 182 183 # Flush all wx events. 184 wx.Yield() 185 186 # Exceptions in the thread. 187 self.check_exceptions()
188 189
190 - def test_mf_auto_analysis(self):
191 """Test the model-free auto-analysis. 192 193 This now catches U{bug #20603<https://web.archive.org/web/https://gna.org/bugs/?20603>}. 194 """ 195 196 # Simulate the new analysis wizard. 197 self.app.gui.analysis.menu_new(None) 198 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 199 page.select_mf(None) 200 page.analysis_name.SetValue(str_to_gui("Model-free test")) 201 self.app.gui.analysis.new_wizard.wizard._go_next(None) 202 page = self.app.gui.analysis.new_wizard.wizard.get_page(1) 203 self.app.gui.analysis.new_wizard.wizard._go_next(None) 204 205 # Get the data. 206 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data() 207 208 # Set up the analysis. 209 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle) 210 211 # Alias the analysis. 212 analysis = self.app.gui.analysis.get_page_from_name("Model-free test") 213 214 # Change the results directory. 215 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 216 217 # The data path. 218 data_path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'model_free' + sep + 'sphere' + sep 219 220 # Open and close the about window (mimicking user behaviour). 221 analysis._about() 222 analysis.about_dialog.Close() 223 224 # Launch the spin viewer window. 225 self.app.gui.show_tree() 226 227 # Spin loading wizard: Initialisation. 228 self.app.gui.spin_viewer.load_spins_wizard() 229 230 # Spin loading wizard: The PDB file. 231 page = self.app.gui.spin_viewer.wizard.get_page(0) 232 page.selection = 'new pdb' 233 self.app.gui.spin_viewer.wizard._go_next() 234 page = self.app.gui.spin_viewer.wizard.get_page(self.app.gui.spin_viewer.wizard._current_page) 235 page.uf_args['file'].SetValue(str_to_gui(status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'model_free' + sep + 'sphere' + sep + 'sphere.pdb')) 236 self.app.gui.spin_viewer.wizard._go_next() 237 interpreter.flush() # Required because of the asynchronous uf call. 238 239 # Spin loading wizard: The spin loading. 240 self.app.gui.spin_viewer.wizard._go_next() 241 interpreter.flush() # Required because of the asynchronous uf call. 242 243 # Close the spin viewer window. 244 self.app.gui.spin_viewer.handler_close() 245 246 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 247 interpreter.flush() 248 249 # Load the relaxation data. 250 data = [ 251 ['noe.500.out', 'noe_500', 'NOE', 500e6], 252 ['r1.500.out', 'r1_500', 'R1', 500e6], 253 ['r2.500.out', 'r2_500', 'R2', 500e6], 254 ['noe.900.out', 'noe_900', 'NOE', 900e6], 255 ['r1.900.out', 'r1_900', 'R1', 900e6], 256 ['r2.900.out', 'r2_900', 'R2', 900e6] 257 ] 258 for i in range(len(data)): 259 self._execute_uf(uf_name='relax_data.read', file=data_path+data[i][0], ri_id=data[i][1], ri_type=data[i][2], frq=data[i][3], 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) 260 261 # Simulate right clicking on the NOE to test the pop up menu (bug #20603, https://web.archive.org/web/https://gna.org/bugs/?20603). 262 analysis.relax_data.on_right_click(Fake_right_click()) 263 264 # Dipole-dipole interaction wizard: Initialisation. 265 analysis.setup_dipole_pair() 266 267 # Dipole-dipole interaction wizard: The interatom.define, interatom.set_dist, and interatom.unit_vectors user functions. 268 analysis.dipole_wizard._apply() 269 interpreter.flush() # Required because of the asynchronous uf call. 270 page = analysis.dipole_wizard.get_page(0) 271 page.uf_args['spin_id1'].SetValue(str_to_gui("@NE1")) 272 page.uf_args['spin_id2'].SetValue(str_to_gui("@HE1")) 273 analysis.dipole_wizard._go_next() 274 interpreter.flush() # Required because of the asynchronous uf call. 275 analysis.dipole_wizard._go_next() 276 interpreter.flush() # Required because of the asynchronous uf call. 277 analysis.dipole_wizard._go_next() 278 interpreter.flush() # Required because of the asynchronous uf call. 279 280 # Set up the CSA interaction. 281 analysis.value_set_csa() 282 uf_store['value.set'].wizard._go_next() 283 interpreter.flush() # Required because of the asynchronous uf call. 284 285 # Set up the nuclear isotopes. 286 analysis.spin_isotope_heteronuc() 287 uf_store['spin.isotope'].wizard._go_next() 288 interpreter.flush() # Required because of the asynchronous uf call. 289 analysis.spin_isotope_proton() 290 uf_store['spin.isotope'].wizard._go_next() 291 interpreter.flush() # Required because of the asynchronous uf call. 292 293 # Select only the tm0 and tm1 local tm models. 294 analysis.local_tm_model_field.select = [True, True, False, False, False, False, False, False, False, False] 295 analysis.local_tm_model_field.modify() 296 297 # Select only the m1 and m2 model-free models. 298 analysis.mf_model_field.select = [False, True, True, False, False, False, False, False, False, False] 299 analysis.mf_model_field.modify() 300 301 # Change the grid increments. 302 analysis.grid_inc.SetValue(3) 303 analysis.data.diff_tensor_grid_inc = {'sphere': 5, 'prolate': 5, 'oblate': 5, 'ellipsoid': 3} 304 305 # Set the number of Monte Carlo simulations. 306 analysis.mc_sim_num.SetValue(2) 307 308 # Set the maximum number of iterations (changing the allowed values). 309 analysis.max_iter.control.SetRange(0, 100) 310 analysis.max_iter.SetValue(1) 311 312 # Set the protocol mode to automatic. 313 analysis.mode_win.select_full_analysis() 314 analysis.mode_dialog() 315 316 # Check that the data has been correctly updated prior to execution. 317 analysis.sync_ds(upload=True) 318 self.assertEqual(analysis.data.save_dir, ds.tmpdir) 319 self.assertEqual(analysis.data.local_tm_models, ['tm0', 'tm1']) 320 self.assertEqual(analysis.data.mf_models, ['m1', 'm2']) 321 self.assertEqual(analysis.data.grid_inc, 3) 322 self.assertEqual(analysis.data.mc_sim_num, 2) 323 self.assertEqual(analysis.data.max_iter, 1) 324 self.assertEqual(analysis.data.diff_tensor_grid_inc['sphere'], 5) 325 self.assertEqual(analysis.data.diff_tensor_grid_inc['prolate'], 5) 326 self.assertEqual(analysis.data.diff_tensor_grid_inc['oblate'], 5) 327 self.assertEqual(analysis.data.diff_tensor_grid_inc['ellipsoid'], 3) 328 329 # Modify some of the class variables to speed up optimisation. 330 auto_model_free.dauvergne_protocol.dAuvergne_protocol.opt_func_tol = 1e-5 331 auto_model_free.dauvergne_protocol.dAuvergne_protocol.opt_max_iterations = 1000 332 333 # Execute relax. 334 state = analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 335 336 # Wait for execution to complete. 337 if hasattr(analysis, 'thread'): 338 analysis.thread.join() 339 340 # Flush all wx events. 341 wx.Yield() 342 343 # Exceptions in the thread. 344 self.check_exceptions() 345 346 # Check the relax controller. 347 # FIXME: skipping the checks for certain wxPython bugs. 348 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 349 self.assertEqual(self.app.gui.controller.mc_gauge_mf.GetValue(), 100) 350 self.assertEqual(self.app.gui.controller.progress_gauge_mf.GetValue(), 100) 351 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100) 352 353 # Check the diffusion tensor. 354 self.assertEqual(cdp.diff_tensor.type, 'sphere') 355 self.assertAlmostEqual(cdp.diff_tensor.tm, 1e-8) 356 self.assertEqual(cdp.diff_tensor.fixed, True) 357 358 # The global minimisation info. 359 self.assertAlmostEqual(cdp.chi2, 4e-19) 360 361 # The spin ID info. 362 mol_names = ["sphere_mol1"] * 20 363 res_names = ["GLY"] * 20 364 res_nums = [] 365 for i in range(1, 10): 366 res_nums.append(i) 367 res_nums.append(i) 368 res_nums.append(i) 369 res_nums.append(i) 370 spin_names = ["N", "H"] * 9 + ["NE1", "HE1"] 371 spin_nums = list(range(1, 21)) 372 isotopes = ["15N", "1H"] * 10 373 csa = [-172e-6, None] * 10 374 select = [True, False] * 10 375 fixed = [False, False] * 10 376 s2 = [0.8, None] * 10 377 te = [20e-12, None] * 10 378 379 # Check the spin data. 380 i = 0 381 for spin, mol_name, res_num, res_name in spin_loop(full_info=True): 382 # The ID info. 383 self.assertEqual(mol_name, mol_names[i]) 384 self.assertEqual(res_name, res_names[i]) 385 self.assertEqual(res_num, res_nums[i]) 386 self.assertEqual(spin.name, spin_names[i]) 387 self.assertEqual(spin.num, spin_nums[i]) 388 389 # The data. 390 self.assertEqual(spin.select, select[i]) 391 self.assertEqual(spin.fixed, fixed[i]) 392 self.assertEqual(spin.isotope, isotopes[i]) 393 if csa[i] == None: 394 self.assertEqual(spin.csa, None) 395 else: 396 self.assertAlmostEqual(spin.csa, csa[i]) 397 398 # The model-free data. 399 self.assertEqual(spin.model, 'm2') 400 self.assertEqual(spin.equation, 'mf_orig') 401 self.assertEqual(len(spin.params), 2) 402 self.assertEqual(spin.params[0], 's2') 403 self.assertEqual(spin.params[1], 'te') 404 if s2[i] == None: 405 self.assertEqual(spin.s2, None) 406 else: 407 self.assertAlmostEqual(spin.s2, 0.8) 408 self.assertEqual(spin.s2f, None) 409 self.assertEqual(spin.s2s, None) 410 self.assertEqual(spin.local_tm, None) 411 if te[i] == None: 412 self.assertEqual(spin.te, None) 413 else: 414 self.assertAlmostEqual(spin.te, 20e-12) 415 self.assertEqual(spin.tf, None) 416 self.assertEqual(spin.ts, None) 417 self.assertEqual(spin.rex, None) 418 419 # The spin minimisation info. 420 self.assertEqual(spin.chi2, None) 421 self.assertEqual(spin.iter, None) 422 self.assertEqual(spin.f_count, None) 423 self.assertEqual(spin.g_count, None) 424 self.assertEqual(spin.h_count, None) 425 self.assertEqual(spin.warning, None) 426 427 # Increment the index. 428 i += 1 429 430 # Check the interatomic data. 431 i = 0 432 for interatom in interatomic_loop(): 433 self.assertAlmostEqual(interatom.r, 1.02 * 1e-10)
434 435 436
437 -class Fake_right_click:
438 """Simulate a grid_cell_right_click event .""" 439
440 - def GetRow(self):
441 """Overwrite the GetRow() method.""" 442 443 # Return the first row. 444 return 0
445