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