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