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-2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax 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 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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 relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  import numpy 
 25  from os import F_OK, access, sep 
 26  import wx 
 27   
 28  # relax module imports. 
 29  from data import Relax_data_store; ds = Relax_data_store() 
 30  from generic_fns.mol_res_spin import spin_loop 
 31  from generic_fns.pipes import cdp_name 
 32  from status import Status; status = Status() 
 33  from test_suite.gui_tests.base_classes import GuiTestCase 
 34   
 35  # relax GUI imports. 
 36  from gui.analyses import auto_model_free 
 37  from gui.interpreter import Interpreter; interpreter = Interpreter() 
 38  from gui.string_conv import float_to_gui, str_to_gui 
 39  from gui.uf_objects import Uf_storage; uf_store = Uf_storage() 
 40  from gui.wizard import Wiz_window 
 41   
 42   
43 -class Mf(GuiTestCase):
44 """Class for testing various aspects specific to the model-free auto-analysis.""" 45
46 - def test_mf_auto_analysis(self):
47 """Test the model-free auto-analysis.""" 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 = 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 + 'sphere' + sep 72 73 # Open and close the about window (mimicking user behaviour). 74 analysis._about() 75 analysis.about_dialog.Close() 76 77 # Launch the spin viewer window. 78 self.app.gui.show_tree() 79 80 # Run through the spin loading wizard. 81 self.app.gui.spin_viewer.load_spins_wizard() 82 self.app.gui.spin_viewer.wizard._go_next() 83 page = self.app.gui.spin_viewer.wizard.get_page(1) 84 page.SetValue('file', data_path+'noe.500.out') 85 self.app.gui.spin_viewer.wizard._go_next() 86 self.app.gui.spin_viewer.wizard._go_next() 87 88 # Close the spin viewer window. 89 self.app.gui.spin_viewer.handler_close() 90 91 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 92 interpreter.flush() 93 94 # Load the relaxation data. 95 data = [ 96 ['noe.500.out', 'noe_500', 'NOE', 500e6], 97 ['r1.500.out', 'r1_500', 'R1', 500e6], 98 ['r2.500.out', 'r2_500', 'R2', 500e6], 99 ['noe.900.out', 'noe_900', 'NOE', 900e6], 100 ['r1.900.out', 'r1_900', 'R1', 900e6], 101 ['r2.900.out', 'r2_900', 'R2', 900e6] 102 ] 103 for i in range(len(data)): 104 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) 105 106 # Set the values, using the methods behind the buttons to set up the user functions with default values, and then manually executing the user function. 107 analysis.value_set_csa() 108 uf_store['value.set'].wizard._ok() 109 interpreter.flush() # Required because of the asynchronous uf call. 110 analysis.value_set_r() 111 uf_store['value.set'].wizard._ok() 112 interpreter.flush() # Required because of the asynchronous uf call. 113 analysis.value_set_heteronuc_type() 114 uf_store['value.set'].wizard._ok() 115 interpreter.flush() # Required because of the asynchronous uf call. 116 analysis.value_set_proton_type() 117 uf_store['value.set'].wizard._ok() 118 interpreter.flush() # Required because of the asynchronous uf call. 119 120 # The unit vector loading wizard. 121 analysis.load_unit_vectors() 122 123 # The PDB file. 124 page = analysis.vect_wizard.get_page(0) 125 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')) 126 analysis.vect_wizard._go_next() 127 interpreter.flush() # Required because of the asynchronous uf call. 128 129 # The unit vectors. 130 analysis.vect_wizard._go_next() 131 interpreter.flush() # Required because of the asynchronous uf call. 132 133 # Select only the tm0 and tm1 local tm models. 134 analysis.local_tm_model_field.select = [True, True, False, False, False, False, False, False, False, False] 135 analysis.local_tm_model_field.modify() 136 137 # Select only the m1 and m2 model-free models. 138 analysis.mf_model_field.select = [False, True, True, False, False, False, False, False, False, False] 139 analysis.mf_model_field.modify() 140 141 # Change the grid increments. 142 analysis.grid_inc.SetValue(3) 143 analysis.data.diff_tensor_grid_inc = {'sphere': 5, 'prolate': 5, 'oblate': 5, 'ellipsoid': 3} 144 145 # Set the number of Monte Carlo simulations. 146 analysis.mc_sim_num.SetValue(2) 147 148 # Set the maximum number of iterations (changing the allowed values). 149 analysis.max_iter.control.SetRange(0, 100) 150 analysis.max_iter.SetValue(1) 151 152 # Set the protocol mode to automatic. 153 analysis.mode_win.select_full_analysis() 154 analysis.mode_dialog() 155 156 # Check that the data has been correctly updated prior to execution. 157 analysis.sync_ds(upload=True) 158 self.assertEqual(analysis.data.save_dir, ds.tmpdir) 159 self.assertEqual(analysis.data.local_tm_models, ['tm0', 'tm1']) 160 self.assertEqual(analysis.data.mf_models, ['m1', 'm2']) 161 self.assertEqual(analysis.data.grid_inc, 3) 162 self.assertEqual(analysis.data.mc_sim_num, 2) 163 self.assertEqual(analysis.data.max_iter, 1) 164 self.assertEqual(analysis.data.diff_tensor_grid_inc['sphere'], 5) 165 self.assertEqual(analysis.data.diff_tensor_grid_inc['prolate'], 5) 166 self.assertEqual(analysis.data.diff_tensor_grid_inc['oblate'], 5) 167 self.assertEqual(analysis.data.diff_tensor_grid_inc['ellipsoid'], 3) 168 169 # Modify some of the class variables to speed up optimisation. 170 auto_model_free.dauvergne_protocol.dAuvergne_protocol.opt_func_tol = 1e-5 171 auto_model_free.dauvergne_protocol.dAuvergne_protocol.opt_max_iterations = 1000 172 173 # Execute relax. 174 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 175 176 # Wait for execution to complete. 177 analysis.thread.join() 178 179 # Flush all wx events. 180 wx.Yield() 181 182 # Exceptions in the thread. 183 self.check_exceptions() 184 185 # Check the relax controller. 186 if status.relax_mode != 'gui': 187 self.assertEqual(self.app.gui.controller.mc_gauge_mf.GetValue(), 100) 188 self.assertEqual(self.app.gui.controller.progress_gauge_mf.GetValue(), 100) 189 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100) 190 191 # Check the diffusion tensor. 192 self.assertEqual(cdp.diff_tensor.type, 'sphere') 193 self.assertAlmostEqual(cdp.diff_tensor.tm, 1e-8) 194 self.assertEqual(cdp.diff_tensor.fixed, True) 195 196 # The global minimisation info. 197 self.assertAlmostEqual(cdp.chi2, 4e-19) 198 199 # The spin ID info. 200 mol_names = ["sphere_mol1"] * 9 201 res_names = ["GLY"] * 9 202 res_nums = range(1, 10) 203 spin_names = ["N"] * 9 204 spin_nums = numpy.array(range(9)) * 2 + 1 205 206 # Check the spin data. 207 i = 0 208 for spin, mol_name, res_num, res_name in spin_loop(full_info=True): 209 # The ID info. 210 self.assertEqual(mol_name, mol_names[i]) 211 self.assertEqual(res_name, res_names[i]) 212 self.assertEqual(res_num, res_nums[i]) 213 self.assertEqual(spin.name, spin_names[i]) 214 self.assertEqual(spin.num, spin_nums[i]) 215 216 # The data. 217 self.assertEqual(spin.select, True) 218 self.assertEqual(spin.fixed, False) 219 self.assertEqual(spin.proton_type, '1H') 220 self.assertEqual(spin.heteronuc_type, '15N') 221 self.assertEqual(spin.attached_proton, None) 222 self.assertAlmostEqual(spin.r, 1.02 * 1e-10) 223 self.assertAlmostEqual(spin.csa, -172e-6) 224 225 # The model-free data. 226 self.assertEqual(spin.model, 'm2') 227 self.assertEqual(spin.equation, 'mf_orig') 228 self.assertEqual(len(spin.params), 2) 229 self.assertEqual(spin.params[0], 's2') 230 self.assertEqual(spin.params[1], 'te') 231 self.assertAlmostEqual(spin.s2, 0.8) 232 self.assertEqual(spin.s2f, None) 233 self.assertEqual(spin.s2s, None) 234 self.assertEqual(spin.local_tm, None) 235 self.assertAlmostEqual(spin.te, 20e-12) 236 self.assertEqual(spin.tf, None) 237 self.assertEqual(spin.ts, None) 238 self.assertEqual(spin.rex, None) 239 240 # The spin minimisation info. 241 self.assertEqual(spin.chi2, None) 242 self.assertEqual(spin.iter, None) 243 self.assertEqual(spin.f_count, None) 244 self.assertEqual(spin.g_count, None) 245 self.assertEqual(spin.h_count, None) 246 self.assertEqual(spin.warning, None) 247 248 # Increment the index. 249 i += 1
250