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.misc import float_to_gui, str_to_gui 
 38  from gui.user_functions import relax_data, sequence, value 
 39  from gui.wizard import Wiz_window 
 40   
 41   
42 -class Mf(GuiTestCase):
43 """Class for testing various aspects specific to the model-free auto-analysis.""" 44
45 - def test_mf_auto_analysis(self):
46 """Test the model-free auto-analysis.""" 47 48 # Simulate the new analysis wizard. 49 self.app.gui.analysis.menu_new(None) 50 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 51 page.select_mf(None) 52 page.analysis_name.SetValue(str_to_gui("Model-free test")) 53 self.app.gui.analysis.new_wizard.wizard._go_next(None) 54 page = self.app.gui.analysis.new_wizard.wizard.get_page(1) 55 self.app.gui.analysis.new_wizard.wizard._go_next(None) 56 57 # Get the data. 58 analysis_type, analysis_name, pipe_name = self.app.gui.analysis.new_wizard.get_data() 59 60 # Set up the analysis. 61 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name) 62 63 # Alias the analysis. 64 analysis = self.app.gui.analysis.get_page_from_name("Model-free test") 65 66 # Change the results directory. 67 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 68 69 # Set up a wizard window instance for all of the user function pages. 70 wizard = Wiz_window(self.app.gui) 71 72 # The data path. 73 data_path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'model_free' + sep + 'sphere' + sep 74 75 # Load the sequence. 76 seq_read = sequence.Read_page(wizard) 77 seq_read.file.SetValue(str_to_gui(data_path + 'noe.500.out')) 78 seq_read.on_execute() 79 80 # Load the relaxation data. 81 data = [ 82 ['noe.500.out', 'noe_500', 'NOE', 500e6], 83 ['r1.500.out', 'r1_500', 'R1', 500e6], 84 ['r2.500.out', 'r2_500', 'R2', 500e6], 85 ['noe.900.out', 'noe_900', 'NOE', 900e6], 86 ['r1.900.out', 'r1_900', 'R1', 900e6], 87 ['r2.900.out', 'r2_900', 'R2', 900e6] 88 ] 89 for i in range(len(data)): 90 relax_data_read = relax_data.Read_page(wizard) 91 relax_data_read.file.SetValue(str_to_gui(data_path + data[i][0])) 92 relax_data_read.ri_id.SetValue(str_to_gui(data[i][1])) 93 relax_data_read.ri_type.SetValue(str_to_gui(data[i][2])) 94 relax_data_read.frq.SetValue(float_to_gui(data[i][3])) 95 relax_data_read.on_execute() 96 97 # Set the values. 98 value_set = value.Set_page(wizard) 99 value_set.set_param('csa') 100 value_set.on_execute() 101 value_set.set_param('r') 102 value_set.on_execute() 103 value_set.set_param('heteronuc_type') 104 value_set.on_execute() 105 value_set.set_param('proton_type') 106 value_set.on_execute() 107 108 # The unit vector loading wizard. 109 analysis.load_unit_vectors(None) 110 111 # The PDB file. 112 page = analysis.vect_wizard.get_page(0) 113 page.file.SetValue(str_to_gui(status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'model_free' + sep + 'sphere' + sep + 'sphere.pdb')) 114 analysis.vect_wizard._go_next(None) 115 116 # The unit vectors. 117 analysis.vect_wizard._go_next(None) 118 119 # Select only the tm0 and tm1 local tm models. 120 analysis.local_tm_model_field.select = [True, True, False, False, False, False, False, False, False, False] 121 analysis.local_tm_model_field.modify(None) 122 123 # Select only the m1 and m2 model-free models. 124 analysis.mf_model_field.select = [False, True, True, False, False, False, False, False, False, False] 125 analysis.mf_model_field.modify(None) 126 127 # Change the grid increments. 128 analysis.grid_inc.SetValue(3) 129 analysis.data.diff_tensor_grid_inc = {'sphere': 5, 'prolate': 5, 'oblate': 5, 'ellipsoid': 3} 130 131 # Set the number of Monte Carlo simulations. 132 analysis.mc_sim_num.SetValue(2) 133 134 # Set the maximum number of iterations (changing the allowed values). 135 analysis.max_iter.control.SetRange(0, 100) 136 analysis.max_iter.SetValue(1) 137 138 # Set the protocol mode to automatic. 139 analysis.mode_win.select_full_analysis(None) 140 analysis.mode_dialog(None) 141 142 # Check that the data has been correctly updated prior to execution. 143 analysis.sync_ds(upload=True) 144 self.assertEqual(analysis.data.save_dir, ds.tmpdir) 145 self.assertEqual(analysis.data.local_tm_models, ['tm0', 'tm1']) 146 self.assertEqual(analysis.data.mf_models, ['m1', 'm2']) 147 self.assertEqual(analysis.data.grid_inc, 3) 148 self.assertEqual(analysis.data.mc_sim_num, 2) 149 self.assertEqual(analysis.data.max_iter, 1) 150 self.assertEqual(analysis.data.diff_tensor_grid_inc['sphere'], 5) 151 self.assertEqual(analysis.data.diff_tensor_grid_inc['prolate'], 5) 152 self.assertEqual(analysis.data.diff_tensor_grid_inc['oblate'], 5) 153 self.assertEqual(analysis.data.diff_tensor_grid_inc['ellipsoid'], 3) 154 155 # Modify some of the class variables to speed up optimisation. 156 auto_model_free.dauvergne_protocol.dAuvergne_protocol.opt_func_tol = 1e-5 157 auto_model_free.dauvergne_protocol.dAuvergne_protocol.opt_max_iterations = 1000 158 159 # Execute relax. 160 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 161 162 # Wait for execution to complete. 163 analysis.thread.join() 164 165 # Flush all wx events. 166 wx.Yield() 167 168 # Exceptions in the thread. 169 self.check_exceptions() 170 171 # Check the relax controller. 172 if status.relax_mode != 'gui': 173 self.assertEqual(self.app.gui.controller.mc_gauge_mf.GetValue(), 100) 174 self.assertEqual(self.app.gui.controller.progress_gauge_mf.GetValue(), 100) 175 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100) 176 177 # Check the diffusion tensor. 178 self.assertEqual(cdp.diff_tensor.type, 'sphere') 179 self.assertAlmostEqual(cdp.diff_tensor.tm, 1e-8) 180 self.assertEqual(cdp.diff_tensor.fixed, True) 181 182 # The global minimisation info. 183 self.assertAlmostEqual(cdp.chi2, 4e-19) 184 185 # The spin ID info. 186 mol_names = ["sphere_mol1"] * 9 187 res_names = ["GLY"] * 9 188 res_nums = range(1, 10) 189 spin_names = ["N"] * 9 190 spin_nums = numpy.array(range(9)) * 2 + 1 191 192 # Check the spin data. 193 i = 0 194 for spin, mol_name, res_num, res_name in spin_loop(full_info=True): 195 # The ID info. 196 self.assertEqual(mol_name, mol_names[i]) 197 self.assertEqual(res_name, res_names[i]) 198 self.assertEqual(res_num, res_nums[i]) 199 self.assertEqual(spin.name, spin_names[i]) 200 self.assertEqual(spin.num, spin_nums[i]) 201 202 # The data. 203 self.assertEqual(spin.select, True) 204 self.assertEqual(spin.fixed, False) 205 self.assertEqual(spin.proton_type, '1H') 206 self.assertEqual(spin.heteronuc_type, '15N') 207 self.assertEqual(spin.attached_proton, None) 208 self.assertEqual(spin.nucleus, None) 209 self.assertAlmostEqual(spin.r, 1.02 * 1e-10) 210 self.assertAlmostEqual(spin.csa, -172e-6) 211 212 # The model-free data. 213 self.assertEqual(spin.model, 'm2') 214 self.assertEqual(spin.equation, 'mf_orig') 215 self.assertEqual(len(spin.params), 2) 216 self.assertEqual(spin.params[0], 's2') 217 self.assertEqual(spin.params[1], 'te') 218 self.assertAlmostEqual(spin.s2, 0.8) 219 self.assertEqual(spin.s2f, None) 220 self.assertEqual(spin.s2s, None) 221 self.assertEqual(spin.local_tm, None) 222 self.assertAlmostEqual(spin.te, 20e-12) 223 self.assertEqual(spin.tf, None) 224 self.assertEqual(spin.ts, None) 225 self.assertEqual(spin.rex, None) 226 227 # The spin minimisation info. 228 self.assertEqual(spin.chi2, None) 229 self.assertEqual(spin.iter, None) 230 self.assertEqual(spin.f_count, None) 231 self.assertEqual(spin.g_count, None) 232 self.assertEqual(spin.h_count, None) 233 self.assertEqual(spin.warning, None) 234 235 # Increment the index. 236 i += 1
237