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

Source Code for Module test_suite.gui_tests.rx

  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 F_OK, access, sep 
 24  import wx 
 25   
 26  # relax module imports. 
 27  from data_store import Relax_data_store; ds = Relax_data_store() 
 28  import dep_check 
 29  from gui.interpreter import Interpreter; interpreter = Interpreter() 
 30  from gui.string_conv import float_to_gui, float_to_gui, str_to_gui 
 31  from pipe_control.mol_res_spin import spin_loop 
 32  from pipe_control.pipes import cdp_name 
 33  from status import Status; status = Status() 
 34  from test_suite.gui_tests.base_classes import GuiTestCase 
 35   
 36   
37 -class Rx(GuiTestCase):
38 """Class for testing various aspects specific to the R1 and R2 analyses.""" 39
40 - def __init__(self, methodName='runTest'):
41 """Skip the tests if the C modules are non-functional or for wxPython bugs. 42 43 @keyword methodName: The name of the test. 44 @type methodName: str 45 """ 46 47 # Execute the base class method. 48 super(Rx, self).__init__(methodName) 49 50 # Missing module. 51 if not dep_check.C_module_exp_fn: 52 # Store in the status object. 53 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type])
54 55
56 - def check_curve_fitting(self):
57 """Check the results of the curve-fitting.""" 58 59 # Data. 60 relax_times = [0.0176, 0.0176, 0.0352, 0.0704, 0.0704, 0.1056, 0.1584, 0.1584, 0.1936, 0.1936] 61 chi2 = [None, None, None, 2.916952651567855, 5.4916923952919632, 16.21182245065274, 4.3591263759462926, 9.8925377583244316, None, None, None, 6.0238341559877782] 62 rx = [None, None, None, 8.0814894819820662, 8.6478971039559642, 9.5710638183013845, 10.716551838066295, 11.143793935455122, None, None, None, 12.82875370075309] 63 i0 = [None, None, None, 1996050.9679875025, 2068490.9458927638, 1611556.5194095275, 1362887.2331948928, 1877670.5623875158, None, None, None, 897044.17382064369] 64 65 # Some checks. 66 self.assertEqual(cdp.curve_type, 'exp') 67 self.assertEqual(cdp.int_method, 'height') 68 self.assertEqual(len(cdp.relax_times), 10) 69 cdp_relax_times = sorted(cdp.relax_times.values()) 70 for i in range(10): 71 self.assertEqual(cdp_relax_times[i], relax_times[i]) 72 73 # Check the errors. 74 for key in cdp.sigma_I: 75 self.assertEqual(cdp.sigma_I[key], 10578.039482421433) 76 self.assertEqual(cdp.var_I[key], 111894919.29166669) 77 78 # Spin data check. 79 i = 0 80 for spin in spin_loop(): 81 # No data present. 82 if chi2[i] == None: 83 self.assert_(not hasattr(spin, 'chi2')) 84 85 # Data present. 86 else: 87 self.assertAlmostEqual(spin.chi2, chi2[i]) 88 self.assertAlmostEqual(spin.rx, rx[i]) 89 self.assertAlmostEqual(spin.i0/1e6, i0[i]/1e6) 90 91 # Increment the spin index. 92 i = i + 1 93 if i >= 12: 94 break
95 96
97 - def test_r1_analysis(self):
98 """Test the r1 analysis.""" 99 100 # The path to the data files. 101 data_path = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'curve_fitting' + sep 102 103 # Simulate the new analysis wizard. 104 self.app.gui.analysis.menu_new(None) 105 page = self.app.gui.analysis.new_wizard.wizard.get_page(0) 106 page.select_r1(None) 107 self.app.gui.analysis.new_wizard.wizard._go_next(None) 108 page = self.app.gui.analysis.new_wizard.wizard.get_page(1) 109 self.app.gui.analysis.new_wizard.wizard._go_next(None) 110 111 # Get the data. 112 analysis_type, analysis_name, pipe_name, pipe_bundle, uf_exec = self.app.gui.analysis.new_wizard.get_data() 113 114 # Set up the analysis. 115 self.app.gui.analysis.new_analysis(analysis_type=analysis_type, analysis_name=analysis_name, pipe_name=pipe_name, pipe_bundle=pipe_bundle) 116 117 # Alias the analysis. 118 analysis = self.app.gui.analysis.get_page_from_name("R1 relaxation") 119 120 # The frequency label. 121 analysis.field_nmr_frq.SetValue(str_to_gui('600')) 122 123 # Change the results directory. 124 analysis.field_results_dir.SetValue(str_to_gui(ds.tmpdir)) 125 126 # Load the sequence. 127 file = status.install_path + sep + 'test_suite' + sep + 'shared_data' + sep + 'Ap4Aase.seq' 128 self._execute_uf(uf_name='sequence.read', file=file, mol_name_col=None, res_name_col=2, res_num_col=1, spin_name_col=None, spin_num_col=None) 129 130 # Unresolved spins. 131 self._execute_uf(uf_name='deselect.read', file=data_path+'unresolved', mol_name_col=None, res_name_col=None, res_num_col=1, spin_name_col=None, spin_num_col=None, change_all=True) 132 133 # Name the spins. 134 self._execute_uf(uf_name='spin.name', name='N') 135 136 # Flush the interpreter in preparation for the synchronous user functions of the peak list wizard. 137 interpreter.flush() 138 139 # Spectrum names. 140 names = [ 141 'T2_ncyc1_ave', 142 'T2_ncyc1b_ave', 143 'T2_ncyc2_ave', 144 'T2_ncyc4_ave', 145 'T2_ncyc4b_ave', 146 'T2_ncyc6_ave', 147 'T2_ncyc9_ave', 148 'T2_ncyc9b_ave', 149 'T2_ncyc11_ave', 150 'T2_ncyc11b_ave' 151 ] 152 153 # Replicated spectra. 154 replicated = { 155 'T2_ncyc1b_ave': 'T2_ncyc1_ave', 156 'T2_ncyc4b_ave': 'T2_ncyc4_ave', 157 'T2_ncyc9b_ave': 'T2_ncyc9_ave', 158 'T2_ncyc11b_ave': 'T2_ncyc11_ave' 159 } 160 161 # Number of cycles. 162 ncyc = [1, 163 1, 164 2, 165 4, 166 4, 167 6, 168 9, 169 9, 170 11, 171 11 172 ] 173 174 # The delay time. 175 time = 0.0176 176 177 # Add the spectra and number of cycles. 178 for i in range(len(names)): 179 # Set up the peak intensity wizard. 180 analysis.peak_wizard_launch(None) 181 wizard = analysis.peak_wizard 182 183 # The spectrum. 184 page = wizard.get_page(wizard.page_indices['read']) 185 page.uf_args['file'].SetValue(str_to_gui("%s%s.list" % (data_path, names[i]))) 186 page.uf_args['spectrum_id'].SetValue(str_to_gui(names[i])) 187 188 # Go to the next page. 189 wizard._go_next(None) 190 191 # The error type. 192 page = wizard.get_page(wizard.page_indices['err_type']) 193 page.selection = 'repl' 194 195 # Go to the next page. 196 wizard._go_next(None) 197 198 # Replicated spectra: 199 if names[i] in replicated.keys(): 200 page = wizard.get_page(wizard.page_indices['repl']) 201 page.uf_args['spectrum_ids'].SetValue(value=replicated[names[i]], index=1) 202 203 # Go to the next page. 204 wizard._go_next(None) 205 206 # Set the delay ime. 207 page = wizard.get_page(wizard.page_indices['relax_time']) 208 page.uf_args['time'].SetValue(float_to_gui(ncyc[i]*time)) 209 210 # Go to the next page (i.e. finish). 211 wizard._go_next(None) 212 213 # Set the number of MC sims. 214 analysis.mc_sim_num.SetValue(3) 215 216 # Execute relax. 217 analysis.execute(wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, analysis.button_exec_relax.GetId())) 218 219 # Wait for execution to complete. 220 analysis.thread.join() 221 222 # Flush all wx events. 223 wx.Yield() 224 225 # Exceptions in the thread. 226 self.check_exceptions() 227 228 # Check the relax controller. 229 # FIXME: skipping the checks for certain wxPython bugs. 230 if status.relax_mode != 'gui' and wx.version() != '2.9.4.1 gtk2 (classic)': 231 self.assertEqual(self.app.gui.controller.mc_gauge_rx.GetValue(), 100) 232 self.assertEqual(self.app.gui.controller.main_gauge.GetValue(), 100) 233 234 # Check the data pipe. 235 self.assertEqual(cdp_name(), ds.relax_gui.analyses[0].pipe_name) 236 237 # Check the data. 238 self.check_curve_fitting() 239 240 # Check the created files. 241 self.assert_(access(ds.tmpdir+sep+'r1.600.out', F_OK)) 242 self.assert_(access(ds.tmpdir+sep+'results.bz2', F_OK)) 243 self.assert_(access(ds.tmpdir+sep+'r1.600.save.bz2', F_OK)) 244 self.assert_(access(ds.tmpdir+sep+'grace'+sep+'r1.600.agr', F_OK)) 245 self.assert_(access(ds.tmpdir+sep+'grace'+sep+'chi2.agr', F_OK)) 246 self.assert_(access(ds.tmpdir+sep+'grace'+sep+'i0.agr', F_OK)) 247 self.assert_(access(ds.tmpdir+sep+'grace'+sep+'intensities.agr', F_OK)) 248 self.assert_(access(ds.tmpdir+sep+'grace'+sep+'intensities_norm.agr', F_OK))
249