Package test_suite :: Package unit_tests :: Package _specific_analyses :: Package _relax_disp :: Module test_disp_data
[hide private]
[frames] | no frames]

Source Code for Module test_suite.unit_tests._specific_analyses._relax_disp.test_disp_data

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2014 Edward d'Auvergne                                   # 
  4  # Copyright (C) 2014 Troels E. Linnet                                         # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  from os import sep 
 25   
 26  # relax module imports. 
 27  from data_store import Relax_data_store; ds = Relax_data_store() 
 28  from math import atan, pi 
 29  from pipe_control import state 
 30  from pipe_control.mol_res_spin import get_spin_ids, return_spin 
 31  from specific_analyses.relax_disp.checks import get_times 
 32  from specific_analyses.relax_disp.disp_data import calc_rotating_frame_params, count_relax_times, find_intensity_keys, get_curve_type, has_exponential_exp_type, loop_exp_frq, loop_exp_frq_offset, loop_exp_frq_offset_point, loop_exp_frq_offset_point_time, loop_time, return_offset_data, return_spin_lock_nu1 
 33  from status import Status; status = Status() 
 34  from test_suite.unit_tests.base_classes import UnitTestCase 
 35   
 36   
37 -class Test_disp_data(UnitTestCase):
38 """Unit tests for the functions of the specific_analyses.relax_disp.disp_data module.""" 39
40 - def setUp(self):
41 """Setup some structures for the unit tests.""" 42 43 # Create a dispersion data pipe. 44 ds.add(pipe_name='orig', pipe_type='relax_disp')
45 46
48 """Unit test of the calc_rotating_frame_params() function for R1rho setup. 49 50 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 51 """ 52 53 # Load the state. 54 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 55 state.load_state(statefile, force=True) 56 57 curspin_id = ':5@N' 58 curspin = return_spin(curspin_id) 59 60 # Use calc_tilt_angle function 61 theta_spin_dic, Domega_spin_dic, w_eff_spin_dic, dic_key_list = calc_rotating_frame_params(spin = curspin, spin_id = curspin_id) 62 63 for dic_key in dic_key_list: 64 print(dic_key, theta_spin_dic[dic_key], Domega_spin_dic[dic_key], w_eff_spin_dic[dic_key])
65 66
68 """Unit test of the count_relax_times() function. 69 70 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 71 """ 72 73 # Load the state. 74 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 75 state.load_state(statefile, force=True) 76 77 # Original data (exp_type, frq). 78 data = [ 79 ['SQ CPMG', 499862140.0], 80 ['SQ CPMG', 599890858.69999993] 81 ] 82 83 # Original indices (ei, mi). 84 indices = [ 85 [0, 0], 86 [0, 1] 87 ] 88 89 # Check the number of time counts. 90 print("Checking the number of time counts.") 91 for id in cdp.exp_type.keys(): 92 exp_type = cdp.exp_type[id] 93 frq = cdp.spectrometer_frq[id] 94 point = cdp.cpmg_frqs[id] 95 count = count_relax_times(exp_type = exp_type, frq = frq, point = point, ei = cdp.exp_type_list.index(cdp.exp_type[id])) 96 print(id, exp_type, frq, point, count) 97 98 # Test the data 99 if id.split('A')[0] == 'Z_': 100 self.assertEqual(exp_type, data[0][0]) 101 self.assertEqual(frq, data[0][1]) 102 elif id.split('B')[0] == 'Z_': 103 self.assertEqual(exp_type, data[1][0]) 104 self.assertEqual(frq, data[1][1]) 105 # Test the time count 106 self.assertEqual(count, 1)
107 108
110 """Unit test of the count_relax_times() function. 111 112 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 113 """ 114 115 # Load the state. 116 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 117 state.load_state(statefile, force=True) 118 119 # Original data (spectrum id: exp_type, frq, omega_rf_ppm, spin_lock_field_strength, time_spin_lock). 120 data = dict() 121 data['46_0_35_0'] = ['R1rho', 799777399.1, 118.078, 431.0, 0.0] 122 data['48_0_35_4'] = ['R1rho', 799777399.1, 118.078, 431.0, 0.04] 123 data['47_0_35_10'] = ['R1rho', 799777399.1, 118.078, 431.0, 0.1] 124 data['49_0_35_20'] = ['R1rho', 799777399.1, 118.078, 431.0, 0.2] 125 data['36_0_39_0'] = ['R1rho', 799777399.1, 118.078, 651.2, 0.0] 126 data['39_0_39_4'] = ['R1rho', 799777399.1, 118.078, 651.2, 0.04] 127 data['37_0_39_10'] = ['R1rho', 799777399.1, 118.078, 651.2, 0.1] 128 data['40_0_39_20'] = ['R1rho', 799777399.1, 118.078, 651.2, 0.2] 129 data['38_0_39_40'] = ['R1rho', 799777399.1, 118.078, 651.2, 0.4] 130 data['41_0_41_0'] = ['R1rho', 799777399.1, 118.078, 800.5, 0.0] 131 data['44_0_41_4'] = ['R1rho', 799777399.1, 118.078, 800.5, 0.04] 132 data['42_0_41_10'] = ['R1rho', 799777399.1, 118.078, 800.5, 0.1] 133 data['45_0_41_20'] = ['R1rho', 799777399.1, 118.078, 800.5, 0.2] 134 data['43_0_41_40'] = ['R1rho', 799777399.1, 118.078, 800.5, 0.4] 135 data['31_0_43_0'] = ['R1rho', 799777399.1, 118.078, 984.0, 0.0] 136 data['34_0_43_4'] = ['R1rho', 799777399.1, 118.078, 984.0, 0.04] 137 data['32_0_43_10'] = ['R1rho', 799777399.1, 118.078, 984.0, 0.1] 138 data['35_0_43_20'] = ['R1rho', 799777399.1, 118.078, 984.0, 0.2] 139 data['33_0_43_40'] = ['R1rho', 799777399.1, 118.078, 984.0, 0.4] 140 data['1_0_46_0'] = ['R1rho', 799777399.1, 118.078, 1341.11, 0.0] 141 data['4_0_46_4'] = ['R1rho', 799777399.1, 118.078, 1341.11, 0.04] 142 data['2_0_46_10'] = ['R1rho', 799777399.1, 118.078, 1341.11, 0.1] 143 data['5_0_46_20'] = ['R1rho', 799777399.1, 118.078, 1341.11, 0.2] 144 data['3_0_46_40'] = ['R1rho', 799777399.1, 118.078, 1341.11, 0.4] 145 data['60_0_48_0'] = ['R1rho', 799777399.1, 118.078, 1648.5, 0.0] 146 data['63_0_48_4'] = ['R1rho', 799777399.1, 118.078, 1648.5, 0.04] 147 data['61_0_48_10'] = ['R1rho', 799777399.1, 118.078, 1648.5, 0.1] 148 data['62_0_48_14'] = ['R1rho', 799777399.1, 118.078, 1648.5, 0.14] 149 data['64_0_48_20'] = ['R1rho', 799777399.1, 118.078, 1648.5, 0.2] 150 data['11_500_46_0'] = ['R1rho', 799777399.1, 124.24703146206046, 1341.11, 0.0] 151 data['14_500_46_4'] = ['R1rho', 799777399.1, 124.24703146206046, 1341.11, 0.04] 152 data['12_500_46_10'] = ['R1rho', 799777399.1, 124.24703146206046, 1341.11, 0.1] 153 data['15_500_46_20'] = ['R1rho', 799777399.1, 124.24703146206046, 1341.11, 0.2] 154 data['13_500_46_40'] = ['R1rho', 799777399.1, 124.24703146206046, 1341.11, 0.4] 155 data['50_1000_41_0'] = ['R1rho', 799777399.1, 130.41606292412092, 800.5, 0.0] 156 data['53_1000_41_4'] = ['R1rho', 799777399.1, 130.41606292412092, 800.5, 0.04] 157 data['51_1000_41_10'] = ['R1rho', 799777399.1, 130.41606292412092, 800.5, 0.1] 158 data['54_1000_41_20'] = ['R1rho', 799777399.1, 130.41606292412092, 800.5, 0.2] 159 data['52_1000_41_40'] = ['R1rho', 799777399.1, 130.41606292412092, 800.5, 0.4] 160 data['21_1000_46_0'] = ['R1rho', 799777399.1, 130.41606292412092, 1341.11, 0.0] 161 data['24_1000_46_4'] = ['R1rho', 799777399.1, 130.41606292412092, 1341.11, 0.04] 162 data['22_1000_46_10'] = ['R1rho', 799777399.1, 130.41606292412092, 1341.11, 0.1] 163 data['25_1000_46_20'] = ['R1rho', 799777399.1, 130.41606292412092, 1341.11, 0.2] 164 data['23_1000_46_40'] = ['R1rho', 799777399.1, 130.41606292412092, 1341.11, 0.4] 165 data['65_1000_48_0'] = ['R1rho', 799777399.1, 130.41606292412092, 1648.5, 0.0] 166 data['68_1000_48_4'] = ['R1rho', 799777399.1, 130.41606292412092, 1648.5, 0.04] 167 data['66_1000_48_10'] = ['R1rho', 799777399.1, 130.41606292412092, 1648.5, 0.1] 168 data['67_1000_48_14'] = ['R1rho', 799777399.1, 130.41606292412092, 1648.5, 0.14] 169 data['69_1000_48_20'] = ['R1rho', 799777399.1, 130.41606292412092, 1648.5, 0.2] 170 data['55_2000_41_0'] = ['R1rho', 799777399.1, 142.75412584824184, 800.5, 0.0] 171 data['58_2000_41_4'] = ['R1rho', 799777399.1, 142.75412584824184, 800.5, 0.04] 172 data['56_2000_41_10'] = ['R1rho', 799777399.1, 142.75412584824184, 800.5, 0.1] 173 data['59_2000_41_20'] = ['R1rho', 799777399.1, 142.75412584824184, 800.5, 0.2] 174 data['57_2000_41_40'] = ['R1rho', 799777399.1, 142.75412584824184, 800.5, 0.4] 175 data['6_2000_46_0'] = ['R1rho', 799777399.1, 142.75412584824184, 1341.11, 0.0] 176 data['9_2000_46_4'] = ['R1rho', 799777399.1, 142.75412584824184, 1341.11, 0.04] 177 data['7_2000_46_10'] = ['R1rho', 799777399.1, 142.75412584824184, 1341.11, 0.1] 178 data['10_2000_46_20'] = ['R1rho', 799777399.1, 142.75412584824184, 1341.11, 0.2] 179 data['8_2000_46_40'] = ['R1rho', 799777399.1, 142.75412584824184, 1341.11, 0.4] 180 data['16_5000_46_0'] = ['R1rho', 799777399.1, 179.76831462060457, 1341.11, 0.0] 181 data['19_5000_46_4'] = ['R1rho', 799777399.1, 179.76831462060457, 1341.11, 0.04] 182 data['17_5000_46_10'] = ['R1rho', 799777399.1, 179.76831462060457, 1341.11, 0.1] 183 data['20_5000_46_20'] = ['R1rho', 799777399.1, 179.76831462060457, 1341.11, 0.2] 184 data['18_5000_46_40'] = ['R1rho', 799777399.1, 179.76831462060457, 1341.11, 0.4] 185 data['26_10000_46_0'] = ['R1rho', 799777399.1, 241.45862924120914, 1341.11, 0.0] 186 data['29_10000_46_4'] = ['R1rho', 799777399.1, 241.45862924120914, 1341.11, 0.04] 187 data['27_10000_46_10'] = ['R1rho', 799777399.1, 241.45862924120914, 1341.11, 0.1] 188 data['30_10000_46_20'] = ['R1rho', 799777399.1, 241.45862924120914, 1341.11, 0.2] 189 data['28_10000_46_40'] = ['R1rho', 799777399.1, 241.45862924120914, 1341.11, 0.4] 190 191 time_comp = { 192 '118.078_431.0':4, 193 '118.078_651.2':5, 194 '118.078_800.5':5, 195 '118.078_984.0':5, 196 '118.078_1341.11':5, 197 '118.078_1648.5':5, 198 '124.247031462_1341.11':5, 199 '130.416062924_800.5':5, 200 '130.416062924_1341.11':5, 201 '130.416062924_1648.5':5, 202 '142.754125848_800.5':5, 203 '142.754125848_1341.11':5, 204 '179.768314621_1341.11':5, 205 '241.458629241_1341.11':5} 206 207 # Check the number of time counts. 208 print("Checking the number of time counts.") 209 for id in cdp.exp_type.keys(): 210 exp_type = cdp.exp_type[id] 211 frq = cdp.spectrometer_frq[id] 212 offset = cdp.spin_lock_offset[id] 213 point = cdp.spin_lock_nu1[id] 214 count = count_relax_times(exp_type = exp_type, frq = frq, offset=offset, point = point, ei = cdp.exp_type_list.index(cdp.exp_type[id])) 215 print(id, exp_type, frq, offset, point, count) 216 217 # Test the time count 218 self.assertEqual(count, time_comp['%s_%s'%(offset, point)])
219 220
222 """Unit test of the find_intensity_keys() function. 223 224 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 225 """ 226 227 # Load the state. 228 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 229 state.load_state(statefile, force=True) 230 231 # Original data (spectrum id: exp_type, frq, omega_rf_ppm, spin_lock_field_strength, time_spin_lock). 232 data = dict() 233 data['118_431.00_0.00'] = ['46_0_35_0', 'R1rho', 799777399.1, 118.078, 431.0, 0.0] 234 data['118_431.00_0.04'] = ['48_0_35_4', 'R1rho', 799777399.1, 118.078, 431.0, 0.04] 235 data['118_431.00_0.10'] = ['47_0_35_10', 'R1rho', 799777399.1, 118.078, 431.0, 0.1] 236 data['118_431.00_0.20'] = ['49_0_35_20', 'R1rho', 799777399.1, 118.078, 431.0, 0.2] 237 data['118_651.20_0.00'] = ['36_0_39_0', 'R1rho', 799777399.1, 118.078, 651.2, 0.0] 238 data['118_651.20_0.04'] = ['39_0_39_4', 'R1rho', 799777399.1, 118.078, 651.2, 0.04] 239 data['118_651.20_0.10'] = ['37_0_39_10', 'R1rho', 799777399.1, 118.078, 651.2, 0.1] 240 data['118_651.20_0.20'] = ['40_0_39_20', 'R1rho', 799777399.1, 118.078, 651.2, 0.2] 241 data['118_651.20_0.40'] = ['38_0_39_40', 'R1rho', 799777399.1, 118.078, 651.2, 0.4] 242 data['118_800.50_0.00'] = ['41_0_41_0', 'R1rho', 799777399.1, 118.078, 800.5, 0.0] 243 data['118_800.50_0.04'] = ['44_0_41_4', 'R1rho', 799777399.1, 118.078, 800.5, 0.04] 244 data['118_800.50_0.10'] = ['42_0_41_10', 'R1rho', 799777399.1, 118.078, 800.5, 0.1] 245 data['118_800.50_0.20'] = ['45_0_41_20', 'R1rho', 799777399.1, 118.078, 800.5, 0.2] 246 data['118_800.50_0.40'] = ['43_0_41_40', 'R1rho', 799777399.1, 118.078, 800.5, 0.4] 247 data['118_984.00_0.00'] = ['31_0_43_0', 'R1rho', 799777399.1, 118.078, 984.0, 0.0] 248 data['118_984.00_0.04'] = ['34_0_43_4', 'R1rho', 799777399.1, 118.078, 984.0, 0.04] 249 data['118_984.00_0.10'] = ['32_0_43_10', 'R1rho', 799777399.1, 118.078, 984.0, 0.1] 250 data['118_984.00_0.20'] = ['35_0_43_20', 'R1rho', 799777399.1, 118.078, 984.0, 0.2] 251 data['118_984.00_0.40'] = ['33_0_43_40', 'R1rho', 799777399.1, 118.078, 984.0, 0.4] 252 data['118_1341.11_0.00'] = ['1_0_46_0', 'R1rho', 799777399.1, 118.078, 1341.11, 0.0] 253 data['118_1341.11_0.04'] = ['4_0_46_4', 'R1rho', 799777399.1, 118.078, 1341.11, 0.04] 254 data['118_1341.11_0.10'] = ['2_0_46_10', 'R1rho', 799777399.1, 118.078, 1341.11, 0.1] 255 data['118_1341.11_0.20'] = ['5_0_46_20', 'R1rho', 799777399.1, 118.078, 1341.11, 0.2] 256 data['118_1341.11_0.40'] = ['3_0_46_40', 'R1rho', 799777399.1, 118.078, 1341.11, 0.4] 257 data['118_1648.50_0.00'] = ['60_0_48_0', 'R1rho', 799777399.1, 118.078, 1648.5, 0.0] 258 data['118_1648.50_0.04'] = ['63_0_48_4', 'R1rho', 799777399.1, 118.078, 1648.5, 0.04] 259 data['118_1648.50_0.10'] = ['61_0_48_10', 'R1rho', 799777399.1, 118.078, 1648.5, 0.1] 260 data['118_1648.50_0.14'] = ['62_0_48_14', 'R1rho', 799777399.1, 118.078, 1648.5, 0.14] 261 data['118_1648.50_0.20'] = ['64_0_48_20', 'R1rho', 799777399.1, 118.078, 1648.5, 0.2] 262 data['124_1341.11_0.00'] = ['11_500_46_0', 'R1rho', 799777399.1, 124.247031462, 1341.11, 0.0] 263 data['124_1341.11_0.04'] = ['14_500_46_4', 'R1rho', 799777399.1, 124.247031462, 1341.11, 0.04] 264 data['124_1341.11_0.10'] = ['12_500_46_10', 'R1rho', 799777399.1, 124.247031462, 1341.11, 0.1] 265 data['124_1341.11_0.20'] = ['15_500_46_20', 'R1rho', 799777399.1, 124.247031462, 1341.11, 0.2] 266 data['124_1341.11_0.40'] = ['13_500_46_40', 'R1rho', 799777399.1, 124.247031462, 1341.11, 0.4] 267 data['130_800.50_0.00'] = ['50_1000_41_0', 'R1rho', 799777399.1, 130.416062924, 800.5, 0.0] 268 data['130_800.50_0.04'] = ['53_1000_41_4', 'R1rho', 799777399.1, 130.416062924, 800.5, 0.04] 269 data['130_800.50_0.10'] = ['51_1000_41_10', 'R1rho', 799777399.1, 130.416062924, 800.5, 0.1] 270 data['130_800.50_0.20'] = ['54_1000_41_20', 'R1rho', 799777399.1, 130.416062924, 800.5, 0.2] 271 data['130_800.50_0.40'] = ['52_1000_41_40', 'R1rho', 799777399.1, 130.416062924, 800.5, 0.4] 272 data['130_1341.11_0.00'] = ['21_1000_46_0', 'R1rho', 799777399.1, 130.416062924, 1341.11, 0.0] 273 data['130_1341.11_0.04'] = ['24_1000_46_4', 'R1rho', 799777399.1, 130.416062924, 1341.11, 0.04] 274 data['130_1341.11_0.10'] = ['22_1000_46_10', 'R1rho', 799777399.1, 130.416062924, 1341.11, 0.1] 275 data['130_1341.11_0.20'] = ['25_1000_46_20', 'R1rho', 799777399.1, 130.416062924, 1341.11, 0.2] 276 data['130_1341.11_0.40'] = ['23_1000_46_40', 'R1rho', 799777399.1, 130.416062924, 1341.11, 0.4] 277 data['130_1648.50_0.00'] = ['65_1000_48_0', 'R1rho', 799777399.1, 130.416062924, 1648.5, 0.0] 278 data['130_1648.50_0.04'] = ['68_1000_48_4', 'R1rho', 799777399.1, 130.416062924, 1648.5, 0.04] 279 data['130_1648.50_0.10'] = ['66_1000_48_10', 'R1rho', 799777399.1, 130.416062924, 1648.5, 0.1] 280 data['130_1648.50_0.14'] = ['67_1000_48_14', 'R1rho', 799777399.1, 130.416062924, 1648.5, 0.14] 281 data['130_1648.50_0.20'] = ['69_1000_48_20', 'R1rho', 799777399.1, 130.416062924, 1648.5, 0.2] 282 data['143_800.50_0.00'] = ['55_2000_41_0', 'R1rho', 799777399.1, 142.754125848, 800.5, 0.0] 283 data['143_800.50_0.04'] = ['58_2000_41_4', 'R1rho', 799777399.1, 142.754125848, 800.5, 0.04] 284 data['143_800.50_0.10'] = ['56_2000_41_10', 'R1rho', 799777399.1, 142.754125848, 800.5, 0.1] 285 data['143_800.50_0.20'] = ['59_2000_41_20', 'R1rho', 799777399.1, 142.754125848, 800.5, 0.2] 286 data['143_800.50_0.40'] = ['57_2000_41_40', 'R1rho', 799777399.1, 142.754125848, 800.5, 0.4] 287 data['143_1341.11_0.00'] = ['6_2000_46_0', 'R1rho', 799777399.1, 142.754125848, 1341.11, 0.0] 288 data['143_1341.11_0.04'] = ['9_2000_46_4', 'R1rho', 799777399.1, 142.754125848, 1341.11, 0.04] 289 data['143_1341.11_0.10'] = ['7_2000_46_10', 'R1rho', 799777399.1, 142.754125848, 1341.11, 0.1] 290 data['143_1341.11_0.20'] = ['10_2000_46_20', 'R1rho', 799777399.1, 142.754125848, 1341.11, 0.2] 291 data['143_1341.11_0.40'] = ['8_2000_46_40', 'R1rho', 799777399.1, 142.754125848, 1341.11, 0.4] 292 data['180_1341.11_0.00'] = ['16_5000_46_0', 'R1rho', 799777399.1, 179.768314621, 1341.11, 0.0] 293 data['180_1341.11_0.04'] = ['19_5000_46_4', 'R1rho', 799777399.1, 179.768314621, 1341.11, 0.04] 294 data['180_1341.11_0.10'] = ['17_5000_46_10', 'R1rho', 799777399.1, 179.768314621, 1341.11, 0.1] 295 data['180_1341.11_0.20'] = ['20_5000_46_20', 'R1rho', 799777399.1, 179.768314621, 1341.11, 0.2] 296 data['180_1341.11_0.40'] = ['18_5000_46_40', 'R1rho', 799777399.1, 179.768314621, 1341.11, 0.4] 297 data['241_1341.11_0.00'] = ['26_10000_46_0', 'R1rho', 799777399.1, 241.458629241, 1341.11, 0.0] 298 data['241_1341.11_0.04'] = ['29_10000_46_4', 'R1rho', 799777399.1, 241.458629241, 1341.11, 0.04] 299 data['241_1341.11_0.10'] = ['27_10000_46_10', 'R1rho', 799777399.1, 241.458629241, 1341.11, 0.1] 300 data['241_1341.11_0.20'] = ['30_10000_46_20', 'R1rho', 799777399.1, 241.458629241, 1341.11, 0.2] 301 data['241_1341.11_0.40'] = ['28_10000_46_40', 'R1rho', 799777399.1, 241.458629241, 1341.11, 0.4] 302 303 # Check the number of time counts. 304 print("Checking the id return experiment.") 305 for id in cdp.exp_type.keys(): 306 exp_type = cdp.exp_type[id] 307 frq = cdp.spectrometer_frq[id] 308 offset = cdp.spin_lock_offset[id] 309 point = cdp.spin_lock_nu1[id] 310 311 # Loop over time 312 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 313 ids = find_intensity_keys(exp_type=exp_type, frq=frq, offset=offset, point=point, time=time) 314 315 print(exp_type, frq, offset, point, time, data["%3.0f_%3.2f_%1.2f"%(offset, point, time)][5], id, ids) 316 317 # Test the id return 318 self.assertEqual(len(ids), 1) 319 # Test the time point 320 self.assertEqual(time, data["%3.0f_%3.2f_%1.2f"%(offset, point, time)][5]) 321 self.assertEqual(ids[0], data["%3.0f_%3.2f_%1.2f"%(offset, point, time)][0])
322 323
324 - def test_get_curve_type_cpmg(self):
325 """Unit test of the get_curve_type() function. 326 327 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 328 """ 329 330 # Load the state. 331 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 332 state.load_state(statefile, force=True) 333 334 # Check the return of get_curve_type function. 335 curve_type = get_curve_type() 336 print(curve_type) 337 self.assertEqual(curve_type, 'fixed time')
338 339
340 - def test_get_times_cpmg(self):
341 """Unit test of the get_times() function. 342 343 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 344 """ 345 346 # Load the state. 347 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 348 state.load_state(statefile, force=True) 349 350 # Check the return of get_times(). 351 times = get_times() 352 for exp_type in times: 353 print(times[exp_type]) 354 self.assertEqual(len(times[exp_type]), 2)
355 356
358 """Unit test of the has_exponential_exp_type() function. 359 360 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 361 """ 362 363 # Load the state. 364 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 365 state.load_state(statefile, force=True) 366 367 # Check the return of has_exponential_exp_type. 368 exponential_exp_type = has_exponential_exp_type() 369 print(exponential_exp_type) 370 self.assertEqual(exponential_exp_type, False)
371 372
373 - def test_loop_exp_frq_cpmg(self):
374 """Unit test of the loop_exp_frq() function. 375 376 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 377 """ 378 379 # Load the state. 380 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 381 state.load_state(statefile, force=True) 382 383 # Original data (exp_type, frq). 384 data = [ 385 ['SQ CPMG', 499862140.0], 386 ['SQ CPMG', 599890858.69999993] 387 ] 388 389 # Original indices (ei, mi). 390 indices = [ 391 [0, 0], 392 [0, 1] 393 ] 394 395 # Check the number of iterations. 396 print("Checking the number of iterations of the loop.") 397 count = 0 398 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 399 print(exp_type, frq, ei, mi) 400 count += 1 401 self.assertEqual(count, 2) 402 403 # Check the values. 404 print("Checking the values returned by the loop.") 405 index = 0 406 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 407 # Check the experiment info. 408 self.assertEqual(exp_type, data[index][0]) 409 self.assertEqual(ei, indices[index][0]) 410 411 # Check the frequency info. 412 self.assertEqual(frq, data[index][1]) 413 self.assertEqual(mi, indices[index][1]) 414 415 # Increment the data index. 416 index += 1
417 418
420 """Unit test of the loop_exp_frq_offset() function. 421 422 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 423 """ 424 425 # Load the state. 426 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 427 state.load_state(statefile, force=True) 428 429 # Original data (exp_type, frq, offset). 430 data = [ 431 ['SQ CPMG', 499862140.0, 0], 432 ['SQ CPMG', 599890858.69999993, 0] 433 ] 434 435 # Original indices (ei, mi, oi). 436 indices = [ 437 [0, 0, 0], 438 [0, 1, 0] 439 ] 440 441 # Check the number of iterations. 442 print("Checking the number of iterations of the loop.") 443 count = 0 444 for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True): 445 print(exp_type, frq, offset, ei, mi, oi) 446 count += 1 447 self.assertEqual(count, 2) 448 449 # Check the values. 450 print("Checking the values returned by the loop.") 451 index = 0 452 for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True): 453 # Check the experiment info. 454 self.assertEqual(exp_type, data[index][0]) 455 self.assertEqual(ei, indices[index][0]) 456 457 # Check the frequency info. 458 self.assertEqual(frq, data[index][1]) 459 self.assertEqual(mi, indices[index][1]) 460 461 # Check the offset info. 462 self.assertEqual(offset, data[index][2]) 463 self.assertEqual(oi, indices[index][2]) 464 465 # Increment the data index. 466 index += 1
467 468
470 """Unit test of the loop_exp_frq_offset_point() function. 471 472 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 473 """ 474 475 # Load the state. 476 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 477 state.load_state(statefile, force=True) 478 479 # Original data (exp_type, frq, offset, point). 480 data = [ 481 ['SQ CPMG', 499862140.0, 0, [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 550.0, 600.0, 650.0, 700.0, 800.0, 900.0, 1000.0]], 482 ['SQ CPMG', 599890858.69999993, 0, [33.3333, 66.666, 100.0, 133.333, 166.666, 200.0, 233.333, 266.666, 300.0, 333.333, 366.666, 400.0, 466.666, 533.333, 666.666, 866.666, 1000.0]] 483 ] 484 485 # Original indices (ei, mi, oi). 486 indices = [ 487 [0, 0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]], 488 [0, 1, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]] 489 ] 490 491 # Check the number of iterations. 492 print("Checking the number of iterations of the loop.") 493 count = 0 494 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 495 print(exp_type, frq, offset, point, ei, mi, oi, di) 496 count += 1 497 self.assertEqual(count, 34) 498 499 # Check the values. 500 print("Checking the values returned by the loop.") 501 frq_index = 0 502 disp_index = 0 503 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 504 # Check the experiment info. 505 self.assertEqual(exp_type, data[frq_index][0]) 506 self.assertEqual(ei, indices[frq_index][0]) 507 508 # Check the frequency info. 509 self.assertEqual(frq, data[frq_index][1]) 510 self.assertEqual(mi, indices[frq_index][1]) 511 512 # Check the offset info. 513 self.assertEqual(offset, data[frq_index][2]) 514 self.assertEqual(oi, indices[frq_index][2]) 515 516 # Check the dispersion point info. 517 self.assertAlmostEqual(point, data[frq_index][3][disp_index],2) 518 self.assertEqual(di, indices[frq_index][3][disp_index]) 519 520 # Increment the data index. 521 if disp_index == 16: 522 frq_index += 1 523 disp_index = 0 524 else: 525 disp_index += 1
526 527
529 """Unit test of the loop_exp_frq_offset_point_time() function. 530 531 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 532 """ 533 534 # Load the state. 535 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 536 state.load_state(statefile, force=True) 537 538 # Original data (exp_type, frq, offset, point). 539 data = [ 540 ['SQ CPMG', 499862140.0, 0, [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 550.0, 600.0, 650.0, 700.0, 800.0, 900.0, 1000.0],0.04], 541 ['SQ CPMG', 599890858.69999993, 0, [33.3333, 66.666, 100.0, 133.333, 166.666, 200.0, 233.333, 266.666, 300.0, 333.333, 366.666, 400.0, 466.666, 533.333, 666.666, 866.666, 1000.0],0.06] 542 ] 543 544 # Original indices (ei, mi, oi). 545 indices = [ 546 [0, 0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 0], 547 [0, 1, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 0] 548 ] 549 550 # Check the number of iterations. 551 print("Checking the number of iterations of the loop.") 552 count = 0 553 for exp_type, frq, offset, point, time, ei, mi, oi, di, ti in loop_exp_frq_offset_point_time(return_indices=True): 554 print(exp_type, frq, offset, point, time, ei, mi, oi, di, ti) 555 count += 1 556 self.assertEqual(count, 34) 557 558 # Check the values. 559 print("Checking the values returned by the loop.") 560 frq_index = 0 561 disp_index = 0 562 for exp_type, frq, offset, point, time, ei, mi, oi, di, ti in loop_exp_frq_offset_point_time(return_indices=True): 563 # Check the experiment info. 564 self.assertEqual(exp_type, data[frq_index][0]) 565 self.assertEqual(ei, indices[frq_index][0]) 566 567 # Check the frequency info. 568 self.assertEqual(frq, data[frq_index][1]) 569 self.assertEqual(mi, indices[frq_index][1]) 570 571 # Check the offset info. 572 self.assertEqual(offset, data[frq_index][2]) 573 self.assertEqual(oi, indices[frq_index][2]) 574 575 # Check the dispersion point info. 576 self.assertAlmostEqual(point, data[frq_index][3][disp_index],2) 577 self.assertEqual(di, indices[frq_index][3][disp_index]) 578 579 # Check the time point info. 580 self.assertEqual(time, data[frq_index][4]) 581 self.assertEqual(ti, indices[frq_index][4]) 582 583 # Increment the data index. 584 if disp_index == 16: 585 frq_index += 1 586 disp_index = 0 587 else: 588 disp_index += 1
589 590
592 """U{Bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using calc().""" 593 594 # Load the state. 595 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 596 state.load_state(statefile, force=True) 597 598 # Original data 599 ncyc_1 = [20, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28] 600 sfrq_1 = 499.86214*1E6 601 time_T2_1 = 0.04 602 cpmg_1 = [ncyc/time_T2_1 for ncyc in ncyc_1] 603 cpmg_1.sort() 604 605 ncyc_2 = [28, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 24, 14, 22] 606 sfrq_2 = 599.8908587*1E6 607 time_T2_2 = 0.06 608 cpmg_2 = [ncyc/time_T2_2 for ncyc in ncyc_2] 609 cpmg_2.sort() 610 611 # Test the loop function. 612 # First initialize index for the two lists. 613 i = -1 614 j = -1 615 for exp_type, frq, offset, point, time, ei, mi, oi, di, ti in loop_exp_frq_offset_point_time(return_indices=True): 616 if frq == sfrq_1: 617 i += 1 618 self.assertEqual(time, time_T2_1) 619 self.assertAlmostEqual(point, cpmg_1[i],3) 620 if frq == sfrq_2: 621 j += 1 622 self.assertEqual(time, time_T2_2) 623 self.assertAlmostEqual(point, cpmg_2[j],3)
624 625
626 - def test_loop_time_cpmg(self):
627 """Unit test of the loop_time() function. 628 629 This uses the data of the saved state attached to U{bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21665>}. 630 """ 631 632 # Load the state. 633 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 634 state.load_state(statefile, force=True) 635 636 # Original data (exp_type, frq, offset, point). 637 data = [ 638 ['SQ CPMG', 499862140.0, 0, [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 550.0, 600.0, 650.0, 700.0, 800.0, 900.0, 1000.0],0.04], 639 ['SQ CPMG', 599890858.69999993, 0, [33.3333, 66.666, 100.0, 133.333, 166.666, 200.0, 233.333, 266.666, 300.0, 333.333, 366.666, 400.0, 466.666, 533.333, 666.666, 866.666, 1000.0],0.06] 640 ] 641 642 # Original indices (ei, mi, oi, ti). 643 indices = [ 644 [0, 0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 0], 645 [0, 1, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], 0] 646 ] 647 648 # Check the number of iterations. 649 print("Checking the number of iterations of the loop.") 650 count_frq = 0 651 for dat in data: 652 frq = dat[1] 653 for time, ti in loop_time(frq=frq, return_indices=True): 654 print(time, ti) 655 count_frq += 1 656 self.assertEqual(count_frq, 2)
657 658
659 - def test_loop_time_r1rho(self):
660 """Unit test of the loop_time() function for R1rho setup. 661 662 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 663 """ 664 665 # Load the state. 666 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 667 state.load_state(statefile, force=True) 668 669 # Offset and point combinations, with their associated time. 670 offset_point_time_list = [ 671 [118.078, 431.0, [0.0, 0.04, 0.1, 0.2]], 672 [118.078, 651.2, [0.0, 0.04, 0.1, 0.2, 0.4]], 673 [118.078, 800.5, [0.0, 0.04, 0.1, 0.2, 0.4]], 674 [118.078, 984.0, [0.0, 0.04, 0.1, 0.2, 0.4]], 675 [118.078, 1341.11, [0.0, 0.04, 0.1, 0.2, 0.4]], 676 [118.078, 1648.5, [0.0, 0.04, 0.1, 0.14, 0.2]], 677 [124.247031462, 1341.11, [0.0, 0.04, 0.1, 0.2, 0.4]], 678 [130.416062924, 800.5, [0.0, 0.04, 0.1, 0.2, 0.4]], 679 [130.416062924, 1341.11, [0.0, 0.04, 0.1, 0.2, 0.4]], 680 [130.416062924, 1648.5, [0.0, 0.04, 0.1, 0.14, 0.2]], 681 [142.754125848, 800.5, [0.0, 0.04, 0.1, 0.2, 0.4]], 682 [142.754125848, 1341.11, [0.0, 0.04, 0.1, 0.2, 0.4]], 683 [179.768314621, 1341.11, [0.0, 0.04, 0.1, 0.2, 0.4]], 684 [241.458629241, 1341.11, [0.0, 0.04, 0.1, 0.2, 0.4]]] 685 686 687 # Check the number of iterations. 688 print("Checking the number of iterations of the loop.") 689 frq = 799777399.1 690 691 for offset, point, time_list in offset_point_time_list: 692 # Define count 693 count = 0 694 for time, ti in loop_time(frq=frq, offset=offset, point=point, return_indices=True): 695 print(frq, offset, point, time, ti, count) 696 self.assertEqual(time, time_list[count]) 697 self.assertEqual(ti, count) 698 count += 1
699 700
701 - def test_return_offset_data(self):
702 """Unit test of the return_offset_data() function for R1rho setup. 703 704 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 705 """ 706 707 # Load the state. 708 statefile = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 709 state.load_state(statefile, force=True) 710 711 # Get the field count 712 field_count = cdp.spectrometer_frq_count 713 714 # Get the spin_lock_field points 715 spin_lock_nu1 = return_spin_lock_nu1(ref_flag=False) 716 717 # Initialize data containers 718 all_spin_ids = get_spin_ids() 719 720 # Containers for only selected spins 721 cur_spin_ids = [] 722 cur_spins = [] 723 for curspin_id in all_spin_ids: 724 # Get the spin 725 curspin = return_spin(curspin_id) 726 727 # Check if is selected 728 if curspin.select == True: 729 cur_spin_ids.append(curspin_id) 730 cur_spins.append(curspin) 731 732 # Get the spectometer frequency 733 sfrq = cdp.spectrometer_frq_list[0] 734 735 # Gyromagnetic ratios 736 g1H = 26.7522212 * 1e7 737 g15N = -2.7126 * 1e7 738 739 # The offset and R1 data. 740 chemical_shifts, offsets, tilt_angles, Delta_omega, w_eff = return_offset_data(spins=cur_spins, spin_ids=cur_spin_ids, field_count=field_count, fields=spin_lock_nu1) 741 742 # Loop over the index of spins, then exp_type, frq, offset 743 print("Printing the following") 744 print("exp_type curspin_id frq offset{ppm} offsets[ei][si][mi][oi]{rad/s} ei mi oi si di cur_spin.chemical_shift{ppm} chemical_shifts[ei][si][mi]{rad/s} spin_lock_nu1{Hz} tilt_angles[ei][si][mi][oi]{rad}") 745 for si in range(len(cur_spin_ids)): 746 curspin_id = cur_spin_ids[si] 747 cur_spin = cur_spins[si] 748 for exp_type, frq, offset, ei, mi, oi in loop_exp_frq_offset(return_indices=True): 749 # Loop over the dispersion points. 750 spin_lock_fields = spin_lock_nu1[ei][mi][oi] 751 for di in range(len(spin_lock_fields)): 752 print("%-8s %-10s %11.1f %8.4f %12.5f %i %i %i %i %i %7.3f %12.5f %12.5f %12.5f"%(exp_type, curspin_id, frq, offset, offsets[ei][si][mi][oi], ei, mi, oi, si, di, cur_spin.chemical_shift, chemical_shifts[ei][si][mi], spin_lock_fields[di], tilt_angles[ei][si][mi][oi][di])) 753 # Test chemical shift conversion 754 self.assertEqual(chemical_shifts[ei][si][mi], cur_spin.chemical_shift * 2.0 * pi * sfrq / g1H * g15N * 1e-6) 755 # Test the offset conversion 756 self.assertEqual(offsets[ei][si][mi][oi], offset * 2.0 * pi * sfrq / g1H * g15N * 1e-6) 757 # Test the tiltangle 758 c_omega1 = spin_lock_fields[di] * 2.0 * pi 759 c_Delta_omega = chemical_shifts[ei][si][mi] - offsets[ei][si][mi][oi] 760 if c_omega1 / c_Delta_omega > 0: 761 c_theta = atan(c_omega1 / c_Delta_omega) 762 else: 763 c_theta = pi + atan(c_omega1 / c_Delta_omega) 764 self.assertEqual(tilt_angles[ei][si][mi][oi][di], c_theta)
765