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