Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2016 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  import copy 
  27  from numpy import array, asarray, average, exp, median, inf, isnan, linspace, log, std, sum, zeros 
  28  from minfx.generic import generic_minimise 
  29  from random import gauss 
  30  import re, math 
  31  from tempfile import mkdtemp, NamedTemporaryFile 
  32   
  33   
  34  # relax module imports. 
  35  from auto_analyses import relax_disp 
  36  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  37  from data_store import Relax_data_store; ds = Relax_data_store() 
  38  import dep_check 
  39  from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_FULL, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  40  from lib.errors import RelaxError 
  41  from lib.io import extract_data, get_file_path 
  42  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  43  from pipe_control.mol_res_spin import generate_spin_string, return_spin, spin_loop 
  44  from pipe_control.minimise import assemble_scaling_matrix 
  45  from specific_analyses.relax_disp.checks import check_missing_r1 
  46  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  47  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  48  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  49  from specific_analyses.relax_disp.model import models_info, nesting_param 
  50  from specific_analyses.relax_disp.parameters import linear_constraints 
  51  from status import Status; status = Status() 
  52  from target_functions.relax_fit_wrapper import Relax_fit_opt 
  53  from test_suite.system_tests.base_classes import SystemTestCase 
  54   
  55   
56 -class Relax_disp(SystemTestCase):
57 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 58
59 - def __init__(self, methodName='runTest'):
60 """Skip certain tests if the C modules are non-functional. 61 62 @keyword methodName: The name of the test. 63 @type methodName: str 64 """ 65 66 # Execute the base class method. 67 super(Relax_disp, self).__init__(methodName) 68 69 # Tests to skip. 70 blacklist = [ 71 'test_m61b_data_to_m61b' 72 ] 73 if methodName in blacklist: 74 status.skipped_tests.append([methodName, None, self._skip_type]) 75 76 # Missing module. 77 if not dep_check.C_module_exp_fn: 78 # The list of tests to skip. 79 to_skip = [ 80 "test_bug_atul_srivastava", 81 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 82 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 83 "test_estimate_r2eff_err", 84 "test_estimate_r2eff_err_auto", 85 "test_estimate_r2eff_err_methods", 86 "test_finite_value", 87 "test_exp_fit", 88 "test_m61_exp_data_to_m61", 89 "test_r1rho_kjaergaard_auto", 90 "test_r1rho_kjaergaard_auto_check_graphs", 91 "test_r1rho_kjaergaard_man", 92 "test_r1rho_kjaergaard_missing_r1", 93 "test_value_write_calc_rotating_frame_params_auto_analysis" 94 ] 95 96 # Store in the status object. 97 if methodName in to_skip: 98 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 99 100 # If not scipy.optimize.leastsq. 101 if not dep_check.scipy_module: 102 # The list of tests to skip. 103 to_skip = [ 104 "test_estimate_r2eff_err_methods" 105 ] 106 107 # Store in the status object. 108 if methodName in to_skip: 109 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 110 111 # If not NMRPipe showApod program in PATH. 112 if not dep_check.showApod_software: 113 # The list of tests to skip. 114 to_skip = [ 115 "test_show_apod_extract", 116 "test_show_apod_rmsd", 117 "test_show_apod_rmsd_to_file", 118 "test_show_apod_rmsd_dir_to_files" 119 ] 120 121 # Store in the status object. 122 if methodName in to_skip: 123 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 124 125 # If not matplotlib module 126 if not dep_check.matplotlib_module: 127 # The list of tests to skip. 128 to_skip = [ 129 "test_repeat_cpmg" 130 ] 131 132 # Store in the status object. 133 if methodName in to_skip: 134 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
135 136
137 - def setUp(self):
138 """Set up for all the functional tests.""" 139 140 # Create the data pipe. 141 self.interpreter.pipe.create('relax_disp', 'relax_disp') 142 143 # Create a temporary directory for dumping files. 144 ds.tmpdir = mkdtemp() 145 self.tmpdir = ds.tmpdir
146 147
148 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
149 """Setup data for the catch of U{bug #22146<https://web.archive.org/web/https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 150 151 @keyword folder: The name of the folder for the test data. 152 @type folder: str 153 @keyword model_analyse: The name of the model which will be tested. 154 @type model_analyse: str 155 """ 156 157 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 158 159 # Data. 160 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 161 162 ## Experiments 163 # Exp 1 164 sfrq_1 = 500.0*1E6 165 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 166 time_T2_1 = 0.05 167 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 168 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 169 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 170 r2eff_errs_1 = [0.0] * len(ncycs_1) 171 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 172 173 sfrq_2 = 600.0*1E6 174 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 175 time_T2_2 = 0.06 176 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 177 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 178 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 179 r2eff_errs_2 = [0.0] * len(ncycs_2) 180 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 181 182 sfrq_3 = 700.0*1E6 183 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 184 time_T2_3 = 0.07 185 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 186 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 187 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 188 r2eff_errs_3 = [0.0] * len(ncycs_3) 189 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 190 191 # Collect all exps 192 exps = [exp_1, exp_2, exp_3] 193 194 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 195 dw_arr = [1.0, 2.0, 3.0, 4.0] 196 pA_arr = [0.9] 197 kex_arr = [1000.] 198 199 spins = [ 200 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 201 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 202 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 203 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 204 ] 205 206 # Create the data pipe. 207 pipe_name = 'base pipe' 208 pipe_type = 'relax_disp' 209 pipe_bundle = 'relax_disp' 210 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 211 212 # Generate the sequence. 213 for res_name, res_num, spin_name, params in spins: 214 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 215 216 # Set isotope 217 self.interpreter.spin.isotope('15N', spin_id='@N') 218 219 # Now loop over the experiments, to set the variables in relax. 220 exp_ids = [] 221 for exp_i in exps: 222 sfrq, time_T2, ncycs, r2eff_errs = exp_i 223 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 224 exp_ids.append(exp_id) 225 226 ids = [] 227 for ncyc in ncycs: 228 nu_cpmg = ncyc / time_T2 229 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 230 ids.append(cur_id) 231 232 # Set the spectrometer frequency. 233 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 234 235 # Set the experiment type. 236 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 237 238 # Set the relaxation dispersion CPMG constant time delay T (in s). 239 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 240 241 # Set the relaxation dispersion CPMG frequencies. 242 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 243 244 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 245 246 ### Now do fitting. 247 # Change pipe. 248 249 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 250 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 251 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 252 253 # Now read data in. 254 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 255 exp_id = exp_ids[mi] 256 exp_i = exps[mi] 257 sfrq, time_T2, ncycs, r2eff_errs = exp_i 258 259 # Then loop over the spins. 260 for res_name, res_num, spin_name, params in spins: 261 cur_spin_id = ":%i@%s"%(res_num, spin_name) 262 263 # Define file name 264 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 265 266 # Read in the R2eff file to put into spin structure. 267 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 268 269 # Then select model. 270 self.interpreter.relax_disp.select_model(model=model_analyse) 271 272 # Then cluster 273 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 274 275 # Grid search 276 low_arr = R20 + dw_arr + pA_arr + kex_arr 277 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 278 279 # Then loop over the defined spins and read the parameters. 280 for i in range(len(spins)): 281 res_name, res_num, spin_name, params = spins[i] 282 cur_spin_id = ":%i@%s"%(res_num, spin_name) 283 cur_spin = return_spin(cur_spin_id) 284 285 for mo_param in cur_spin.params: 286 print(mo_param) 287 # The R2 is a dictionary, depending on spectrometer frequency. 288 if isinstance(getattr(cur_spin, mo_param), dict): 289 for key, val in list(getattr(cur_spin, mo_param).items()): 290 should_be = params[mo_param][key] 291 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 292 self.assertAlmostEqual(val, should_be) 293 else: 294 should_be = float(params[mo_param]) 295 val = getattr(cur_spin, mo_param) 296 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 297 self.assertAlmostEqual(val, should_be) 298 299 # Test chi2. 300 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 301 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
302 303
304 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
305 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 306 307 # The path to the data files. 308 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 309 310 # Set pipe name, bundle and type. 311 ds.pipe_name = 'base pipe' 312 ds.pipe_bundle = 'relax_disp' 313 ds.pipe_type = 'relax_disp' 314 315 # Create the data pipe. 316 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 317 318 # Read the spins. 319 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 320 321 # Name the isotope for field strength scaling. 322 self.interpreter.spin.isotope(isotope='15N') 323 324 # Set number of experiments to be used. 325 NR_exp = 70 326 327 # Load the experiments settings file. 328 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 329 expfileslines = expfile.readlines()[:NR_exp] 330 expfile.close() 331 332 # In MHz 333 yOBS = 81.050 334 # In ppm 335 yCAR = 118.078 336 centerPPM_N15 = yCAR 337 338 ## Read the chemical shift data. 339 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 340 341 # The lock power to field, has been found in an calibration experiment. 342 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 343 344 # Apply spectra settings. 345 # Count settings 346 j = 0 347 for i in range(len(expfileslines)): 348 line = expfileslines[i] 349 if line[0] == "#": 350 continue 351 else: 352 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 353 DIRN = line.split()[0] 354 I = int(line.split()[1]) 355 deltadof2 = line.split()[2] 356 dpwr2slock = line.split()[3] 357 ncyc = int(line.split()[4]) 358 trim = float(line.split()[5]) 359 ss = int(line.split()[6]) 360 set_sfrq = float(line.split()[7]) 361 apod_rmsd = float(line.split()[8]) 362 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 363 364 # Calculate spin_lock time 365 time_sl = 2*ncyc*trim 366 367 # Define file name for peak list. 368 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 369 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 370 371 # Load the peak intensities. 372 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 373 374 # Set the peak intensity errors, as defined as the baseplane RMSD. 375 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 376 377 # Set the relaxation dispersion experiment type. 378 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 379 380 # Set The spin-lock field strength, nu1, in Hz 381 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 382 383 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 384 frq_N15_Hz = yOBS * 1E6 385 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 386 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 387 388 # Set The spin-lock offset, omega_rf, in ppm. 389 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 390 391 # Set the relaxation times (in s). 392 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 393 394 # Set the spectrometer frequency. 395 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 396 397 # Add to counter 398 j += 1 399 400 401 print("Testing the number of settings") 402 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type))) 403 self.assertEqual(70, len(expfileslines)) 404 self.assertEqual(69, j) 405 self.assertEqual(69, len(cdp.exp_type)) 406 407 # Cluster spins 408 for curspin in cluster_ids: 409 print("Adding spin %s to cluster"%curspin) 410 self.interpreter.relax_disp.cluster('model_cluster', curspin) 411 412 # De-select for analysis those spins who have not been clustered 413 for free_spin in cdp.clustering['free spins']: 414 print("Deselecting free spin %s"%free_spin) 415 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 416 417 418 #Paper reference values 419 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 420 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 421 ds.ref = dict() 422 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 423 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 424 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 425 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 426 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 427 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 428 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 429 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 430 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 431 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 432 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 433 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 434 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 435 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 436 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 437 438 ds.guess = dict() 439 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 440 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 441 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 442 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 443 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 444 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 445 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 446 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 447 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 448 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 449 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 450 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 451 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 452 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 453 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 454 455 # Assign guess values. 456 for spin, spin_id in spin_loop(return_id=True): 457 if spin_id in cluster_ids: 458 print("spin_id %s in cluster ids"%(spin_id)) 459 spin.kex = ds.guess[spin_id][6] 460 spin.phi_ex = ds.guess[spin_id][10] 461 else: 462 print("spin_id %s NOT in cluster ids"%(spin_id)) 463 464 if read_R1: 465 # Read the R1 data 466 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
467 468
469 - def setup_hansen_cpmg_data(self, model=None):
470 """Set up the data for the test_hansen_cpmg_data_*() system tests. 471 472 @keyword model: The name of the model which will be tested. 473 @type model: str 474 """ 475 476 # Create the data pipe and load the base data. 477 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 478 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 479 self.interpreter.results.read(data_path+sep+'base_pipe') 480 self.interpreter.deselect.spin(':4') 481 482 # Set the nuclear isotope data. 483 self.interpreter.spin.isotope('15N') 484 485 # Create the R2eff data pipe and load the results. 486 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 487 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 488 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 489 self.interpreter.deselect.spin(':4') 490 491 # The model data pipe. 492 pipe_name = "%s - relax_disp" % model 493 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 494 self.interpreter.pipe.switch(pipe_name=pipe_name) 495 496 # Set the model. 497 self.interpreter.relax_disp.select_model(model=model) 498 499 # Copy the data. 500 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
501 502
503 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
504 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 505 506 @keyword model: The name of the model which will be tested. 507 @type model: str 508 """ 509 510 # Create the data pipe and load the base data. 511 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 512 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 513 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 514 515 # Create the R2eff data pipe and load the results. 516 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 517 self.interpreter.pipe.switch(pipe_name='R2eff') 518 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 519 520 # The model data pipe. 521 pipe_name = "%s - relax_disp" % model 522 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 523 self.interpreter.pipe.switch(pipe_name=pipe_name) 524 525 # Set the model. 526 self.interpreter.relax_disp.select_model(model=model) 527 528 # Copy the data. 529 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
530 531
532 - def setup_korzhnev_2005_data(self, data_list=[]):
533 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 534 535 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 536 537 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 538 539 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 540 541 542 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 543 @type data_list: list of str 544 """ 545 546 # Create the data pipe and load the base data. 547 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 548 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 549 550 # Create the spin system. 551 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 552 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 553 self.interpreter.spin.element('H', spin_id='@H') 554 self.interpreter.spin.element('N', spin_id='@N') 555 self.interpreter.spin.isotope('1H', spin_id='@H') 556 self.interpreter.spin.isotope('15N', spin_id='@N') 557 558 # Define the magnetic dipole-dipole relaxation interaction. 559 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 560 561 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 562 data = [ 563 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 564 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 565 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 566 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 567 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 568 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 569 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 570 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 571 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 572 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 573 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 574 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 575 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 576 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 577 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 578 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 579 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 580 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 581 ] 582 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 583 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 584 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 585 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 586 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 587 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 588 589 # Loop over the files, reading in the data. 590 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 591 # Skip undesired data. 592 if data_type not in data_list: 593 continue 594 595 # Alias the CPMG frequencies. 596 if data_type == 'SQ': 597 cpmg_frqs = cpmg_frqs_sq 598 elif data_type == '1H SQ': 599 cpmg_frqs = cpmg_frqs_1h_sq 600 elif data_type == 'DQ': 601 cpmg_frqs = cpmg_frqs_dq 602 elif data_type == 'ZQ': 603 cpmg_frqs = cpmg_frqs_zq 604 elif data_type == '1H MQ': 605 cpmg_frqs = cpmg_frqs_1h_mq 606 elif data_type == 'MQ': 607 cpmg_frqs = cpmg_frqs_mq 608 609 # Loop over each CPMG frequency. 610 for cpmg_frq in cpmg_frqs: 611 # The id. 612 new_id = "%s_%s" % (id, cpmg_frq) 613 614 # Set the NMR field strength. 615 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 616 617 # Set the relaxation dispersion experiment type. 618 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 619 620 # Relaxation dispersion CPMG constant time delay T (in s). 621 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 622 623 # Set the CPMG frequency. 624 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 625 626 # Read the R2eff data. 627 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 628 629 # Change the model. 630 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
631 632
633 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
634 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 635 636 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 637 'SOD1-WT' CPMG data to the CR72 dispersion model. 638 639 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 640 Data is for experiment at 25 degree Celcius. 641 """ 642 643 # Create the data pipe and load the base data. 644 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 645 646 # Set experiment settings. sfrq, time_T2, ncyc 647 Exps = [ 648 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 649 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 650 651 # Create base pipe 652 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 653 654 # Loop throug experiments 655 id_lists = [] 656 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 657 # Read spins 658 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 659 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 660 661 # Make spectrum id list 662 id_list = list(key+str(i) for i in range(len(ncycs))) 663 id_lists.append(id_list) 664 665 # Read intensities 666 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 667 668 # Loop over experiments 669 for i in range(len(ncycs)): 670 ncyc = ncycs[i] 671 vcpmg = ncyc/time_T2 672 673 # Test if spectrum is a reference 674 if float(vcpmg) == 0.0: 675 vcpmg = None 676 else: 677 vcpmg = round(float(vcpmg), 3) 678 679 # Set current id 680 current_id = id_list[i] 681 682 # Set the current experiment type. 683 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 684 685 # Set the NMR field strength of the spectrum. 686 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 687 688 # Relaxation dispersion CPMG constant time delay T (in s). 689 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 690 691 # Set the relaxation dispersion CPMG frequencies. 692 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 693 694 # Define replicated 695 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 696 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 697 698 # Perform error analysis 699 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 700 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 701 702 # Define isotope 703 self.interpreter.spin.isotope(isotope='15N') 704 705 ############# 706 707 # Define the 64 residues which was used for Global fitting 708 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 709 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 710 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 711 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 712 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 713 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 714 715 # Test number of global 716 self.assertEqual(64, len(glob_assn )) 717 718 ## Turn assignments into relax spin ids. 719 # Define regular expression search 720 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 721 722 # Create list to hold regular expression search 723 relax_glob_ids = [] 724 725 # Loop over assignments 726 for assn in glob_assn: 727 # Make match for the regular search 728 m = r.match(assn) 729 # Convert to relax spin string 730 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 731 732 # Save the relax spin string and the regular search 733 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 734 735 ############# Deselect all spins, and select few spins 736 737 ## Deselect all spins, and select a few for analysis 738 self.interpreter.deselect.all() 739 740 # Select few spins 741 for i in select_spin_index: 742 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 743 744 ############## 745 746 # Prepare for R2eff calculation 747 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 748 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 749 750 # Select model for points calculation 751 MODEL = "R2eff" 752 self.interpreter.relax_disp.select_model(model=MODEL) 753 # Calculate R2eff values 754 self.interpreter.minimise.calculate(verbosity=1)
755 756
757 - def setup_missing_r1_spins(self):
758 """Function for setting up a few spins for the given pipe.""" 759 760 # Path to file. 761 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 762 763 # File with spins. 764 file = open(data_path+sep+'R1_fitted_values.txt') 765 lines = file.readlines() 766 file.close() 767 768 for i, line in enumerate(lines): 769 # Make the string test 770 line_split = line.split() 771 772 if line_split[0] == "#": 773 continue 774 775 mol_name = line_split[0] 776 mol_name = None 777 res_num = int(line_split[1]) 778 res_name = line_split[2] 779 spin_num = line_split[3] 780 spin_num = None 781 spin_name = line_split[4] 782 783 # Create the spin. 784 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
785 786
787 - def setup_paul_schanda_nov_2015(self, outdir=None):
788 """This setup the truncated private data which was provided by Paul Schanda.""" 789 790 # Data path. 791 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Paul_Schanda_2015_Nov' 792 file = data_path + sep + '1_prepare_data.py' 793 794 # Store the out 795 status.outdir = outdir 796 797 # Run script. 798 self.interpreter.script(file=file, dir=None)
799 800
801 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
802 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 803 804 # Reset. 805 self.interpreter.reset() 806 807 # Create the data pipe and load the base data. 808 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 809 self.interpreter.state.load(data_path+sep+'r2eff_values') 810 811 # The model data pipe. 812 model = 'NS R1rho 2-site' 813 pipe_name = "%s - relax_disp" % model 814 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 815 self.interpreter.pipe.switch(pipe_name=pipe_name) 816 817 # Set the model. 818 self.interpreter.relax_disp.select_model(model=model) 819 820 # Copy the data. 821 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 822 823 # Alias the spins. 824 spin1 = cdp.mol[0].res[0].spin[0] 825 spin2 = cdp.mol[0].res[1].spin[0] 826 827 # The R20 keys. 828 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 829 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 830 831 # Set the initial parameter values. 832 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 833 spin1.pA = 0.779782428085762 834 spin1.dw = 7.57855284496424 835 spin1.kex = 1116.7911285203 836 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 837 spin2.pA = 0.826666229688602 838 spin2.dw = 9.5732624231366 839 spin2.kex = 1380.46162655657 840 841 # Test the values when clustering. 842 if clustering: 843 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 844 845 # Low precision optimisation. 846 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 847 848 # Printout. 849 print("\n\nOptimised parameters:\n") 850 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 851 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 852 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 853 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 854 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 855 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 856 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
857 858
859 - def test_baldwin_synthetic(self):
860 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 861 862 Support requst sr #3154 U{https://web.archive.org/web/https://gna.org/support/index.php?3154}. 863 864 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 865 """ 866 867 # The path to the data files. 868 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 869 870 # Create pipe 871 pipe_name = 'base pipe' 872 pipe_type = 'relax_disp' 873 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 874 875 # Create base pipe 876 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 877 878 # Generate the sequence. 879 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 880 881 # Define the isotope. 882 self.interpreter.spin.isotope('1H', spin_id='@H') 883 884 # Build the experiment IDs. 885 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 886 ncycs = [2, 4, 8, 10, 20, 40, 500] 887 ids = [] 888 for ncyc in ncycs: 889 ids.append('CPMG_%s' % ncyc) 890 891 print("\n\nThe experiment IDs are %s." % ids) 892 893 # Set up the metadata for the experiments. 894 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 895 sfrq = 200. * 1E6 896 897 # Total time of CPMG block. 898 Trelax = 0.04 899 900 # First set the 901 for i in range(len(ids)): 902 id = ids[i] 903 # Set the spectrometer frequency. 904 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 905 906 # Set the experiment type. 907 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 908 909 # Set the relaxation dispersion CPMG constant time delay T (in s). 910 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 911 912 # Set the relaxation dispersion CPMG frequencies. 913 ncyc = ncycs[i] 914 nu_cpmg = ncyc / Trelax 915 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 916 917 # Prepare for R2eff reading. 918 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 919 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 920 921 # Try reading the R2eff file. 922 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 923 924 # Check the global data. 925 data = [ 926 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 927 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 928 ['dispersion_points', len(ncycs)], 929 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 930 ['exp_type_list', ['SQ CPMG']], 931 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 932 ['spectrometer_frq_count', 1], 933 ['spectrometer_frq_list', [sfrq]], 934 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 935 ] 936 for name, value in data: 937 # Does it exist? 938 self.assert_(hasattr(cdp, name)) 939 940 # Check the object. 941 obj = getattr(cdp, name) 942 if not isinstance(data, dict): 943 self.assertEqual(obj, value) 944 945 # Check the global dictionary data. 946 else: 947 for id in ids: 948 self.assertEqual(obj[id], value[id]) 949 950 # Check the spin data. 951 n_data = [ 952 [ 50.000000, 10.367900, 0.1], 953 [ 100.000000, 10.146849, 0.1], 954 [ 200.000000, 9.765987, 0.1], 955 [ 250.000000, 9.409789, 0.1], 956 [ 500.000000, 5.829819, 0.1], 957 [ 1000.000000, 3.191928, 0.1], 958 [ 12500.000000, 2.008231, 0.1] 959 ] 960 for disp_point, value, error in n_data: 961 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 962 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 963 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 964 965 # Generate r20 key. 966 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 967 968 ## Now prepare for MODEL calculation. 969 MODEL = "B14" 970 971 # Change pipe. 972 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 973 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 974 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 975 976 # Then select model. 977 self.interpreter.relax_disp.select_model(model=MODEL) 978 979 # Store grid and minimisations results. 980 grid_results = [] 981 mini_results = [] 982 983 # The grid search size (the number of increments per dimension). 984 # If None, use the default values. 985 #GRID = None 986 GRID = 13 987 # Perform Grid Search. 988 if GRID: 989 # Set the R20 parameters in the default grid search using the minimum R2eff value. 990 # This speeds it up considerably. 991 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 992 993 # Then do grid search. 994 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 995 996 # If no Grid search, set the default values. 997 else: 998 for param in MODEL_PARAMS[MODEL]: 999 self.interpreter.value.set(param=param, index=None) 1000 # Do a grid search, which will store the chi2 value. 1001 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1002 1003 # Store result. 1004 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1005 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1006 1007 ## Now do minimisation. 1008 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1009 set_func_tol = 1e-10 1010 set_max_iter = 1000 1011 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1012 1013 # Store result. 1014 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1015 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1016 1017 # Print results. 1018 for i in range(len(grid_results)): 1019 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1020 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1021 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1022 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1023 1024 # Reference values from Baldwin.py. 1025 # Exchange rate = k+ + k- (s-1) 1026 kex = 1000. 1027 # Fractional population of excited state k+/kex 1028 pb = 0.01 1029 # deltaOmega in ppm 1030 dw_ppm = 2. 1031 #relaxation rate of ground (s-1) 1032 R2g = 2. 1033 #relaxation rate of excited (s-1) 1034 R2e = 2. 1035 1036 # Test the parameters which created the data. 1037 # This is for the 1H spin. 1038 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1039 1040 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1041 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1042 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1043 1044
1046 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://web.archive.org/web/https://gna.org/support/index.php?3154}. 1047 1048 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1049 """ 1050 1051 # The path to the data files. 1052 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1053 1054 # Create pipe 1055 pipe_name = 'base pipe' 1056 pipe_type = 'relax_disp' 1057 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1058 1059 # Create base pipe 1060 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1061 1062 # Generate the sequence. 1063 # Generate both a 1H spin, and 15N spin. 1064 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1065 1066 # Define the isotope. 1067 self.interpreter.spin.isotope('1H', spin_id='@H') 1068 1069 # Build the experiment IDs. 1070 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1071 ncycs = [2, 4, 8, 10, 20, 40, 500] 1072 ids = [] 1073 for ncyc in ncycs: 1074 ids.append('CPMG_%s' % ncyc) 1075 1076 print("\n\nThe experiment IDs are %s." % ids) 1077 1078 # Set up the metadata for the experiments. 1079 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1080 sfrq = 200. * 1E6 1081 1082 # Total time of CPMG block. 1083 Trelax = 0.04 1084 1085 # First set the 1086 for i in range(len(ids)): 1087 id = ids[i] 1088 # Set the spectrometer frequency. 1089 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1090 1091 # Set the experiment type. 1092 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1093 1094 # Set the relaxation dispersion CPMG constant time delay T (in s). 1095 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1096 1097 # Set the relaxation dispersion CPMG frequencies. 1098 ncyc = ncycs[i] 1099 nu_cpmg = ncyc / Trelax 1100 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1101 1102 # Prepare for R2eff reading. 1103 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1104 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1105 1106 # Try reading the R2eff file. 1107 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1108 1109 # Check the global data. 1110 data = [ 1111 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1112 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1113 ['dispersion_points', len(ncycs)], 1114 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1115 ['exp_type_list', ['SQ CPMG']], 1116 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1117 ['spectrometer_frq_count', 1], 1118 ['spectrometer_frq_list', [sfrq]], 1119 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1120 ] 1121 for name, value in data: 1122 # Does it exist? 1123 self.assert_(hasattr(cdp, name)) 1124 1125 # Check the object. 1126 obj = getattr(cdp, name) 1127 if not isinstance(data, dict): 1128 self.assertEqual(obj, value) 1129 1130 # Check the global dictionary data. 1131 else: 1132 for id in ids: 1133 self.assertEqual(obj[id], value[id]) 1134 1135 # Check the spin data. 1136 n_data = [ 1137 [ 50.000000, 10.286255, 0.1], 1138 [ 100.000000, 10.073083, 0.1], 1139 [ 200.000000, 9.692746, 0.1], 1140 [ 250.000000, 9.382441, 0.1], 1141 [ 500.000000, 6.312396, 0.1], 1142 [ 1000.000000, 3.957029, 0.1], 1143 [ 12500.000000, 2.880420, 0.1] 1144 ] 1145 for disp_point, value, error in n_data: 1146 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1147 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1148 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1149 1150 # Generate r20 key. 1151 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1152 1153 ## Now prepare for MODEL calculation. 1154 MODEL = "B14 full" 1155 1156 # Change pipe. 1157 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1158 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1159 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1160 1161 # Then select model. 1162 self.interpreter.relax_disp.select_model(model=MODEL) 1163 1164 # Store grid and minimisations results. 1165 grid_results = [] 1166 mini_results = [] 1167 clust_results = [] 1168 1169 # The grid search size (the number of increments per dimension). 1170 # If None, use the default values. 1171 #GRID = None 1172 GRID = 13 1173 # Perform Grid Search. 1174 if GRID: 1175 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1176 # This speeds it up considerably. 1177 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1178 1179 # Then do grid search. 1180 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1181 1182 # If no Grid search, set the default values. 1183 else: 1184 for param in MODEL_PARAMS[MODEL]: 1185 self.interpreter.value.set(param=param, index=None) 1186 # Do a grid search, which will store the chi2 value. 1187 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1188 1189 # Store result. 1190 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1191 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1192 1193 ## Now do minimisation. 1194 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1195 set_func_tol = 1e-11 1196 set_max_iter = 10000 1197 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1198 1199 # Store result. 1200 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1201 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1202 1203 print("\n# Now print before and after minimisation-\n") 1204 1205 # Print results. 1206 for i in range(len(grid_results)): 1207 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1208 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1209 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1210 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1211 1212 # Reference values from Baldwin.py. 1213 # Exchange rate = k+ + k- (s-1) 1214 kex = 1000. 1215 # Fractional population of excited state k+/kex 1216 pb = 0.01 1217 # deltaOmega in ppm 1218 dw_ppm = 2. 1219 #relaxation rate of ground (s-1) 1220 R2g = 2. 1221 #relaxation rate of excited (s-1) 1222 R2e = 100. 1223 1224 # Test the parameters which created the data. 1225 # This is for the 1H spin. 1226 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3) 1227 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3) 1228 1229 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1230 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1231 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1232 1233
1234 - def x_test_bmrb_sub_cpmg(self):
1235 """U{Task #7858: <https://web.archive.org/web/https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1236 This uses CPMG data from: 1237 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1238 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1239 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1240 """ 1241 1242 # Define path to data 1243 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1244 1245 # Read data. 1246 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1247 1248 # Set element 1249 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1250 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1251 # Rename molecule from None to 'HEWL' 1252 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1253 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1254 1255 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1256 print(spin_id) 1257 if resn == 'C': 1258 print(resi, resn) 1259 1260 # Select the thiol state of the system. 1261 # 'all disulfide bound', 'all free', 'all other bound', 'disulfide and other bound', 'free and disulfide bound', 'free and other bound', 'free disulfide and other bound', 'not available', 'not present', 'not reported', 'unknown' 1262 self.interpreter.bmrb.thiol_state(state='not reported') 1263 1264 # relax_data.temp_calibration(ri_id=None, method=None) 1265 1266 # Call display of bmrb. 1267 self.interpreter.bmrb.display()
1268 1269
1271 """U{Bug #21081<https://web.archive.org/web/https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1272 1273 # Clear the data store. 1274 self.interpreter.reset() 1275 1276 # Load the state. 1277 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1278 self.interpreter.state.load(state, force=True) 1279 1280 # Model selection - to catch the failure. 1281 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1282 1283
1285 """U{Bug #21460<https://web.archive.org/web/https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1286 1287 # Clear the data store. 1288 self.interpreter.reset() 1289 1290 # Load the state. 1291 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1292 self.interpreter.state.load(state, force=True) 1293 1294 # Execute the auto-analysis (fast). 1295 relax_disp.Relax_disp.opt_func_tol = 1e-5 1296 relax_disp.Relax_disp.opt_max_iterations = 1000 1297 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1298 1299
1301 """U{Bug #21665<https://web.archive.org/web/https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1302 1303 # Clear the data store. 1304 self.interpreter.reset() 1305 1306 # Load the state. 1307 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1308 self.interpreter.state.load(state, force=True) 1309 1310 # Execute the auto-analysis (fast). 1311 relax_disp.Relax_disp.opt_func_tol = 1e-5 1312 relax_disp.Relax_disp.opt_max_iterations = 1000 1313 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1314 1315
1317 """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 minimise.calculate().""" 1318 1319 # Clear the data store. 1320 self.interpreter.reset() 1321 1322 # Load the state. 1323 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1324 self.interpreter.state.load(state, force=True) 1325 1326 # Run the calculation. 1327 self.interpreter.minimise.calculate(verbosity=1)
1328 1329
1331 """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 auto_analysis.""" 1332 1333 # Clear the data store. 1334 self.interpreter.reset() 1335 1336 # Load the state. 1337 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1338 self.interpreter.state.load(state, force=True) 1339 1340 # Execute the auto-analysis (fast). 1341 relax_disp.Relax_disp.opt_func_tol = 1e-5 1342 relax_disp.Relax_disp.opt_max_iterations = 1000 1343 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1344 1345
1347 """Catch U{bug #21715<https://web.archive.org/web/https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1348 1349 # Clear the data store. 1350 self.interpreter.reset() 1351 1352 # Load the state. 1353 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1354 self.interpreter.state.load(state, force=True) 1355 1356 # Execute the auto-analysis (fast). 1357 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1358 relax_disp.Relax_disp.opt_func_tol = 1e-5 1359 relax_disp.Relax_disp.opt_max_iterations = 1000 1360 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=3, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1361 1362
1364 """Catch U{bug #22146<https://web.archive.org/web/https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1365 1366 # Base data setup. 1367 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1368 1369
1371 """Catch U{bug #22146<https://web.archive.org/web/https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1372 1373 # Base data setup. 1374 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1375 1376
1378 """Catch U{bug #22146<https://web.archive.org/web/https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1379 1380 # Base data setup. 1381 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1382 1383
1385 """Catch U{bug #22146<https://web.archive.org/web/https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1386 1387 # Base data setup. 1388 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1389 1390
1392 """Catch U{bug #22146<https://web.archive.org/web/https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1393 1394 # Clear the data store. 1395 self.interpreter.reset() 1396 1397 # Load the state. 1398 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1399 self.interpreter.state.load(state, force=True) 1400 1401 param = 'k_AB' 1402 1403 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1404 print(spin_id, spin.params) 1405 if param in spin.params: 1406 print(spin_id, spin.k_AB, spin.k_AB_err) 1407 1408 # Perform write. 1409 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1410 1411 1412 # Test the header of the value.write parameter r2. 1413 param = 'r2' 1414 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1415 1416 file = open(self.tmpdir+sep+'%s.out'%param) 1417 lines = file.readlines() 1418 file.close() 1419 1420 for i, line in enumerate(lines): 1421 # Make the string test 1422 line_split = line.split() 1423 print(line_split) 1424 1425 if len(line_split) > 1: 1426 # Break at parameter header. 1427 if line_split[0] == "#" and line_split[1] == 'mol_name': 1428 nr_split_header = len(line_split) 1429 nr_split_header_i = i 1430 break 1431 1432 # Call the line after. 1433 line_split_val = lines[nr_split_header_i + 1].split() 1434 print(line_split_val) 1435 1436 # Assert that the number of columns is equal, plus 1 for "#". 1437 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1438 1439 # Test the header of the value.write for parameter r2eff. 1440 param = 'r2eff' 1441 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1442 1443 file = open(self.tmpdir+sep+'%s.out'%param) 1444 lines = file.readlines() 1445 file.close() 1446 1447 for i, line in enumerate(lines): 1448 # Make the string test 1449 line_split = line.split() 1450 print(line_split) 1451 1452 if len(line_split) > 1: 1453 # Break at parameter header. 1454 if line_split[0] == "#" and line_split[1] == 'mol_name': 1455 nr_split_header = len(line_split) 1456 nr_split_header_i = i 1457 break 1458 1459 # Call the line after. 1460 line_split_val = lines[nr_split_header_i + 1].split() 1461 print(line_split_val) 1462 1463 # Assert that the number of columns is equal, plus 1 for "#". 1464 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1465 1466
1468 """Catch U{bug #23186<https://web.archive.org/web/https://gna.org/bugs/?23186>}: Error calculation of individual parameter "dw" from Monte-Carlo, is based on first spin.""" 1469 1470 # Clear the data store. 1471 self.interpreter.reset() 1472 1473 # Load the state. 1474 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_23186.bz2' 1475 self.interpreter.state.load(state, force=True) 1476 1477 # Dic key to spectrometer frq. 1478 dickey = 'SQ CPMG - 599.89086220 MHz' 1479 1480 # First get the resi 0 array of sim r2a. 1481 resi_0_r2a = [] 1482 1483 # Assign spins 1484 res0 = cdp.mol[0].res[0].spin[0] 1485 res1 = cdp.mol[0].res[1].spin[0] 1486 1487 print("Chi2 before call to minimise: %3.3f"%res0.chi2) 1488 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000, verbosity=0) 1489 print("Chi2 after call to minimise: %3.3f"%res0.chi2) 1490 1491 # Loop over the dics in spin. 1492 for cdic in res0.r2a_sim: 1493 resi_0_r2a.append(cdic[dickey]) 1494 1495 # Get stats with numpy 1496 resi_0_r2a_std = std(asarray(resi_0_r2a), ddof=1) 1497 1498 # First get the resi 86 array of sim r2a. 1499 resi_86_r2a = [] 1500 1501 # Loop over the dics in spin. 1502 for cdic in res1.r2a_sim: 1503 resi_86_r2a.append(cdic[dickey]) 1504 1505 # Get stats with numpy 1506 resi_86_r2a_std = std(asarray(resi_86_r2a), ddof=1) 1507 1508 # Then get for dw. 1509 1510 # First get the array of sim dw. 1511 resi_0_dw = res0.dw_sim 1512 resi_86_dw = res1.dw_sim 1513 1514 # Get stats with numpy 1515 resi_0_dw_std = std(asarray(resi_0_dw), ddof=1) 1516 resi_86_dw_std = std(asarray(resi_86_dw), ddof=1) 1517 1518 # Then get for spin independent parameter. 1519 1520 # First get the array of sim dw. 1521 resi_0_kAB = res0.k_AB_sim 1522 resi_86_kAB = res1.k_AB_sim 1523 1524 # Get stats with numpy 1525 resi_0_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1526 resi_86_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1527 1528 # Assume they both std of k_AB values are equal 1529 self.assertEqual(resi_0_kAB_std, resi_86_kAB_std) 1530 1531 # Perform error analysis. 1532 self.interpreter.monte_carlo.error_analysis() 1533 1534 # Check values for k_AB. 1535 self.assertAlmostEqual(resi_0_kAB_std, res0.k_AB_err) 1536 self.assertAlmostEqual(resi_86_kAB_std, res1.k_AB_err) 1537 1538 # Check values for r2a. 1539 self.assertAlmostEqual(resi_0_r2a_std, res0.r2a_err[dickey]) 1540 self.assertAlmostEqual(resi_86_r2a_std, res1.r2a_err[dickey]) 1541 1542 # Check values for dw. 1543 self.assertAlmostEqual(resi_0_dw_std, res0.dw_err) 1544 self.assertAlmostEqual(resi_86_dw_std, res1.dw_err) 1545 1546 # The following is for Bug #23619: (https://web.archive.org/web/https://gna.org/bugs/index.php?23619): Stored chi2 sim values from Monte-Carlo simulations does not equal normal chi2 values. 1547 # This is to show that this bug is invalid. The "very" different chi2 values stems from r2eff points being back-calculated values rather than original measured values. 1548 1549 # Check calculates the same Monte-Carlo chi2 values 1550 self.interpreter.monte_carlo.setup(number=3) 1551 self.interpreter.monte_carlo.create_data(method='back_calc') 1552 self.interpreter.monte_carlo.initial_values() 1553 1554 # Assign original data instead of back_calculated error. 1555 res0.r2eff_sim[0] = copy.copy(res0.r2eff) 1556 res0.r2eff_sim[1] = copy.copy(res0.r2eff) 1557 res0.r2eff_sim[2] = copy.copy(res0.r2eff) 1558 res1.r2eff_sim[0] = copy.copy(res1.r2eff) 1559 res1.r2eff_sim[1] = copy.copy(res1.r2eff) 1560 res1.r2eff_sim[2] = copy.copy(res1.r2eff) 1561 1562 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000) 1563 self.interpreter.monte_carlo.error_analysis() 1564 1565 # Get the simulation array and calculate the average 1566 spin_chi2_mc = res0.chi2 1567 spin_chi2_mc_sim = res0.chi2_sim 1568 spin_chi2_mc_sim_ave = average(spin_chi2_mc_sim) 1569 1570 print("The chi2 from calculation is: %3.3f"%spin_chi2_mc) 1571 print("The array with monte-carlo chi2 values is: %s"%spin_chi2_mc_sim) 1572 print("The average of this array is: %3.3f"%spin_chi2_mc_sim_ave) 1573 1574 self.assertAlmostEqual(spin_chi2_mc, spin_chi2_mc_sim_ave, 7)
1575 1576
1578 """Catch U{bug #24601<https://web.archive.org/web/https://gna.org/bugs/?24601>}, the failure of optimisation of the 'R2eff' model with missing data.""" 1579 1580 # Execute the script. 1581 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_missing_data.py')
1582 1583
1585 """Catch U{bug #9999<https://web.archive.org/web/https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1586 1587 # Define path to data 1588 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1589 1590 # Read data. 1591 self.interpreter.results.read(prev_data_path + sep + 'results') 1592 1593 # Now count number 1594 graph_nr = 1 1595 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1596 print("\nGraph nr %i" % graph_nr) 1597 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1598 print(exp_type, frq, offset, point, time) 1599 graph_nr += 1 1600 1601 ## Possibly do an error analysis. 1602 1603 # Check if intensity errors have already been calculated by the user. 1604 precalc = True 1605 for spin in spin_loop(skip_desel=True): 1606 # No structure. 1607 if not hasattr(spin, 'peak_intensity_err'): 1608 precalc = False 1609 break 1610 1611 # Determine if a spectrum ID is missing from the list. 1612 for id in cdp.spectrum_ids: 1613 if id not in spin.peak_intensity_err: 1614 precalc = False 1615 break 1616 1617 # Skip. 1618 if precalc: 1619 print("Skipping the error analysis as it has already been performed.") 1620 1621 else: 1622 # Loop over the spectrometer frequencies. 1623 for frq in loop_frq(): 1624 # Generate a list of spectrum IDs matching the frequency. 1625 ids = [] 1626 for id in cdp.spectrum_ids: 1627 # Check that the spectrometer frequency matches. 1628 match_frq = True 1629 if frq != None and cdp.spectrometer_frq[id] != frq: 1630 match_frq = False 1631 1632 # Add the ID. 1633 if match_frq: 1634 ids.append(id) 1635 1636 # Run the error analysis on the subset. 1637 self.interpreter.spectrum.error_analysis(subset=ids) 1638 1639 print("has_exponential_exp_type:", has_exponential_exp_type()) 1640 1641 model = 'R2eff' 1642 self.interpreter.relax_disp.select_model(model) 1643 1644 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1645 #delattr(spin, 'r2eff') 1646 #delattr(spin, 'r2eff_err') 1647 #delattr(spin, 'i0') 1648 #delattr(spin, 'i0_err') 1649 setattr(spin, 'r2eff', {}) 1650 setattr(spin, 'r2eff_err', {}) 1651 setattr(spin, 'i0', {}) 1652 setattr(spin, 'i0_err', {}) 1653 1654 # Do Grid Search 1655 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1656 1657 # Start dic. 1658 my_dic = {} 1659 1660 # Define counter for maximum elements in the numpy array list 1661 NE = 0 1662 NS = 1 1663 NM = 0 1664 NO = 0 1665 ND = 0 1666 NT = 0 1667 1668 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1669 # Save to counter. 1670 if ei > NE: 1671 NE = ei 1672 if mi > NM: 1673 NM = mi 1674 if oi > NO: 1675 NO = oi 1676 if di > ND: 1677 ND = di 1678 1679 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1680 # Save to counter. 1681 if ti > NT: 1682 NT = ti 1683 1684 # Add 1 to counter, since index start from 0. 1685 NE = NE + 1 1686 NM = NM + 1 1687 NO = NO + 1 1688 ND = ND + 1 1689 NT = NT + 1 1690 1691 # Make data array. 1692 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1693 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1694 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1695 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1696 param_key_list = [] 1697 1698 1699 # Loop over each spectrometer frequency and dispersion point. 1700 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1701 # Add key to dic. 1702 my_dic[spin_id] = {} 1703 1704 # Generate spin string. 1705 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1706 1707 # Loop over the parameters. 1708 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1709 1710 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1711 # Generate the param_key. 1712 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1713 1714 # Append key. 1715 param_key_list.append(param_key) 1716 1717 # Add key to dic. 1718 my_dic[spin_id][param_key] = {} 1719 1720 # Get the value. 1721 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1722 i0_value = getattr(cur_spin, 'i0')[param_key] 1723 1724 # Save to dic. 1725 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1726 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1727 1728 ## Now try do a line of best fit by least squares. 1729 # The peak intensities, errors and times. 1730 values = [] 1731 errors = [] 1732 times = [] 1733 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1734 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1735 values.append(value) 1736 1737 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1738 errors.append(error) 1739 times.append(time) 1740 1741 # Save to numpy arrays. 1742 values_arr[ei, 0, mi, oi, di, ti] = value 1743 errors_arr[ei, 0, mi, oi, di, ti] = error 1744 times_arr[ei, 0, mi, oi, di, ti] = time 1745 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1746 1747 # y= A exp(x * k) 1748 # w[i] = ln(y[i]) 1749 # int[i] = i0 * exp( - times[i] * r2eff); 1750 w = log(array(values)) 1751 x = - array(times) 1752 n = len(times) 1753 1754 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1755 a = 1./n * sum(w) - b * 1./n * sum(x) 1756 R2eff_est = b 1757 i0_est = exp(a) 1758 1759 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1760 my_dic[spin_id][param_key]['i0_est'] = i0_est 1761 1762 # Print value. 1763 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1764 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1765 1766 1767 # Do minimisation. 1768 set_func_tol = 1e-25 1769 set_max_iter = int(1e7) 1770 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1771 1772 # Loop over each spectrometer frequency and dispersion point. 1773 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1774 # Generate spin string. 1775 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1776 1777 # Loop over the parameters. 1778 print("Optimised parameters for spin: %s" % (spin_string)) 1779 1780 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1781 # Generate the param_key. 1782 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1783 1784 # Get the value. 1785 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1786 i0_value = getattr(cur_spin, 'i0')[param_key] 1787 1788 # Extract from dic. 1789 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1790 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1791 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1792 i0_est = my_dic[spin_id][param_key]['i0_est'] 1793 1794 # Print value. 1795 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1796 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1797 1798 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1799 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1800 1801 print(NE, NS, NM, NO, ND, NT) 1802 for param_key in param_key_list: 1803 print(" '%s'," % param_key) 1804 print(values_arr.shape) 1805 1806 # Save arrays to profiling. 1807 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1808 #save(data_path + "values_arr", values_arr) 1809 #save(data_path + "errors_arr", errors_arr) 1810 #save(data_path + "times_arr", times_arr) 1811 #save(data_path + "struct_arr", struct_arr) 1812 1813
1814 - def test_bug_atul_srivastava(self):
1815 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1816 shows it is exponential fitting, but only one time point is added per file. 1817 1818 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1819 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1820 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1821 1822 """ 1823 1824 # Data path. 1825 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1826 file = data_path + sep + 'bug_script.py' 1827 1828 # Run script. 1829 self.interpreter.script(file=file, dir=None) 1830 1831 # The grid search size (the number of increments per dimension). 1832 GRID_INC = 11 1833 1834 # Check-data. 1835 ################# 1836 1837 # Loop over spins, to see current setup. 1838 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1839 print(mol_name, resi, resn, spin_id) 1840 1841 # Loop over setup. 1842 for id in cdp.exp_type: 1843 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1844 1845 1846 # Manual minimisation. 1847 ################# 1848 if True: 1849 # Set the model. 1850 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1851 1852 # Check if intensity errors have already been calculated. 1853 check_intensity_errors() 1854 1855 # Calculate the R2eff values for the fixed relaxation time period data types. 1856 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1857 self.interpreter.minimise.calculate() 1858 1859 # Optimise the model. 1860 else: 1861 constraints = False 1862 min_algor = 'Newton' 1863 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC) 1864 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints) 1865 1866 # Inspect. 1867 if False: 1868 # Loop over attributes. 1869 par_attr_list = ['r2eff', 'i0'] 1870 1871 # Collect the estimation data. 1872 my_dic = {} 1873 param_key_list = [] 1874 est_keys = [] 1875 est_key = 'grid' 1876 est_keys.append(est_key) 1877 spin_id_list = [] 1878 1879 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1880 # Add key to dic. 1881 my_dic[spin_id] = {} 1882 1883 # Add key for estimate. 1884 my_dic[spin_id][est_key] = {} 1885 1886 # Add spin key to list. 1887 spin_id_list.append(spin_id) 1888 1889 # Generate spin string. 1890 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1891 1892 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1893 # Generate the param_key. 1894 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1895 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1896 1897 # Append key. 1898 param_key_list.append(param_key) 1899 1900 # Add key to dic. 1901 my_dic[spin_id][est_key][param_key] = {} 1902 1903 # Get the value. 1904 # Loop over err attributes. 1905 for par_attr in par_attr_list: 1906 if hasattr(cur_spin, par_attr): 1907 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1908 else: 1909 get_par_attr = 0.0 1910 1911 # Save to dic. 1912 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1913 1914 # Check number of values. 1915 values = [] 1916 errors = [] 1917 times = [] 1918 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1919 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1920 values.append(value) 1921 1922 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1923 errors.append(error) 1924 times.append(time) 1925 1926 # Save to dic. 1927 my_dic[spin_id][est_key][param_key]['values'] = values 1928 my_dic[spin_id][est_key][param_key]['errors'] = errors 1929 my_dic[spin_id][est_key][param_key]['times'] = times 1930 1931 # Analysis variables. 1932 ##################### 1933 1934 # The dispersion models. 1935 MODELS = ['R2eff', 'No Rex'] 1936 1937 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1938 MC_NUM = 10 1939 1940 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1941 MC_SIM_ALL_MODELS = False 1942 1943 # The results directory. 1944 RESULTS_DIR = ds.tmpdir 1945 1946 # The directory of results of an earlier analysis without clustering. 1947 PRE_RUN_DIR = None 1948 1949 # The model selection technique to use. 1950 MODSEL = 'AIC' 1951 1952 # The flag for only using numeric models in the final model selection. 1953 NUMERIC_ONLY = False 1954 1955 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1956 INSIGNIFICANCE = 1.0 1957 1958 # Auto-analysis execution. 1959 self.assertRaises(RelaxError, relax_disp.Relax_disp, pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1960 1961
1963 """Test data, where peak intensities are negative in CPMG 1964 1965 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1966 """ 1967 1968 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1969 1970 # Create the spins 1971 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1972 1973 # Name the isotope for field strength scaling. 1974 self.interpreter.spin.isotope(isotope='15N') 1975 1976 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1977 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1978 1979 # Loop over the spectra settings. 1980 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1981 1982 # Make empty ncyclist 1983 ncyclist = [] 1984 1985 i = 0 1986 for line in ncycfile: 1987 ncyc = line.split()[0] 1988 time_T2 = float(line.split()[1]) 1989 vcpmg = line.split()[2] 1990 set_sfrq = float(line.split()[3]) 1991 rmsd_err = float(line.split()[4]) 1992 1993 # Test if spectrum is a reference 1994 if float(vcpmg) == 0.0: 1995 vcpmg = None 1996 else: 1997 vcpmg = round(float(vcpmg), 3) 1998 1999 # Add ncyc to list 2000 ncyclist.append(int(ncyc)) 2001 2002 # Set the current spectrum id 2003 current_id = "Z_A%s"%(i) 2004 2005 # Set the current experiment type. 2006 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 2007 2008 # Set the peak intensity errors, as defined as the baseplane RMSD. 2009 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 2010 2011 # Set the NMR field strength of the spectrum. 2012 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 2013 2014 # Relaxation dispersion CPMG constant time delay T (in s). 2015 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 2016 2017 # Set the relaxation dispersion CPMG frequencies. 2018 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 2019 2020 i += 1 2021 2022 # Specify the duplicated spectra. 2023 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 2024 2025 # Delete replicate spectrum 2026 #self.interpreter.spectrum.delete('Z_A15') 2027 2028 MODELS = [MODEL_R2EFF, MODEL_NOREX] 2029 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 2030 2031 results_dir = ds.tmpdir 2032 2033 # Execute 2034 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 2035 2036 # Check spin less R2eff points. 2037 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 2038 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 2039 if spin_id == ':4@N': 2040 self.assertEqual(len(cur_spin.r2eff), 14) 2041 else: 2042 self.assertEqual(len(cur_spin.r2eff), 15)
2043 2044
2045 - def test_check_missing_r1(self):
2046 """Test of the check_missing_r1() function.""" 2047 2048 # Set up some spins. 2049 self.setup_missing_r1_spins() 2050 2051 # Set variables. 2052 exp_type = 'R1rho' 2053 frq = 800.1 * 1E6 2054 2055 spectrum_id='test' 2056 2057 # Set an experiment type to the pipe. 2058 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 2059 2060 # Set a frequency to loop through. 2061 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 2062 2063 # Check R1 for DPL94. 2064 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2065 self.assertEqual(check_missing_r1_return, True) 2066 2067 # Check R1 for R2eff. 2068 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 2069 self.assertEqual(check_missing_r1_return, False) 2070 2071 # The path to the data files. 2072 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 2073 2074 # Now load some R1 data. 2075 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 2076 2077 # Check R1. 2078 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2079 self.assertEqual(check_missing_r1_return, False)
2080 2081
2083 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 2084 2085 This is part of: U{Task #7807 <https://web.archive.org/web/https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2086 2087 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2088 """ 2089 2090 # Reset. 2091 #self.interpreter.reset() 2092 2093 ## Set Experiments. 2094 model_create = 'B14' 2095 #model_create = 'NS CPMG 2-site expanded' 2096 model_analyse = 'NS CPMG 2-site 3D' 2097 2098 # Exp 1 2099 sfrq_1 = 599.8908617*1E6 2100 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2101 time_T2_1 = 0.06 2102 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2103 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2104 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2105 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2106 2107 sfrq_2 = 499.8908617*1E6 2108 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2109 time_T2_2 = 0.05 2110 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2111 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2112 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2113 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2114 2115 # Collect all exps 2116 exps = [exp_1, exp_2] 2117 2118 spins = [ 2119 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2120 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2121 ] 2122 2123 # Collect the data to be used. 2124 ds.data = [model_create, model_analyse, spins, exps] 2125 2126 # The tmp directory. None is the local directory. 2127 ds.tmpdir = ds.tmpdir 2128 2129 # The results directory. None is the local directory. 2130 #ds.resdir = None 2131 ds.resdir = ds.tmpdir 2132 2133 # Do r20_from_min_r2eff ?. 2134 ds.r20_from_min_r2eff = True 2135 2136 # Remove insignificant level. 2137 ds.insignificance = 0.0 2138 2139 # The grid search size (the number of increments per dimension). 2140 ds.GRID_INC = None 2141 2142 # The do clustering. 2143 ds.do_cluster = True 2144 2145 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2146 # The default value is 1e-25. 2147 ds.set_func_tol = 1e-1 2148 2149 # The maximum number of iterations. 2150 # The default value is 1e7. 2151 ds.set_max_iter = 1000 2152 2153 # The verbosity level. 2154 ds.verbosity = 1 2155 2156 # The rel_change WARNING level. 2157 ds.rel_change = 0.05 2158 2159 # The plot_curves. 2160 ds.plot_curves = False 2161 2162 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2163 ds.sherekhan_input = False 2164 2165 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2166 ds.opendx = False 2167 2168 # The set r2eff err. 2169 ds.r2eff_err = 0.1 2170 2171 # The print result info. 2172 ds.print_res = True 2173 2174 # Execute the script. 2175 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2176 2177 cur_spins = ds.data[2] 2178 # Compare results. 2179 for i in range(len(cur_spins)): 2180 res_name, res_num, spin_name, params = cur_spins[i] 2181 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2182 cur_spin = return_spin(cur_spin_id) 2183 2184 grid_params = ds.grid_results[i][3] 2185 2186 # Extract the clust results. 2187 min_params = ds.clust_results[i][3] 2188 # Now read the parameters. 2189 print("For spin: '%s'"%cur_spin_id) 2190 for mo_param in cur_spin.params: 2191 # The R2 is a dictionary, depending on spectrometer frequency. 2192 if isinstance(getattr(cur_spin, mo_param), dict): 2193 grid_r2 = grid_params[mo_param] 2194 min_r2 = min_params[mo_param] 2195 set_r2 = params[mo_param] 2196 for key, val in list(set_r2.items()): 2197 grid_r2_frq = grid_r2[key] 2198 min_r2_frq = min_r2[key] 2199 set_r2_frq = set_r2[key] 2200 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2201 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2202 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2203 if rel_change > ds.rel_change: 2204 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2205 print("###################################") 2206 2207 ## Make test on R2. 2208 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2209 else: 2210 grid_val = grid_params[mo_param] 2211 min_val = min_params[mo_param] 2212 set_val = params[mo_param] 2213 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2214 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2215 if rel_change > ds.rel_change: 2216 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2217 print("###################################") 2218 2219 ## Make test on parameters. 2220 if mo_param == 'dw': 2221 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2222 elif mo_param == 'kex': 2223 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2224 elif mo_param == 'pA': 2225 self.assertAlmostEqual(set_val, min_val, 2)
2226 2227
2229 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2230 2231 This is part of: U{Task #7807 <https://web.archive.org/web/https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2232 2233 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2234 """ 2235 2236 # Reset. 2237 #self.interpreter.reset() 2238 2239 ## Set Experiments. 2240 model_create = 'B14' 2241 #model_create = 'NS CPMG 2-site expanded' 2242 model_analyse = 'NS CPMG 2-site star' 2243 2244 # Exp 1 2245 sfrq_1 = 599.8908617*1E6 2246 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2247 time_T2_1 = 0.06 2248 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2249 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2250 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2251 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2252 2253 sfrq_2 = 499.8908617*1E6 2254 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2255 time_T2_2 = 0.05 2256 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2257 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2258 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2259 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2260 2261 # Collect all exps 2262 exps = [exp_1, exp_2] 2263 2264 spins = [ 2265 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2266 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2267 ] 2268 2269 # Collect the data to be used. 2270 ds.data = [model_create, model_analyse, spins, exps] 2271 2272 # The tmp directory. None is the local directory. 2273 ds.tmpdir = ds.tmpdir 2274 2275 # The results directory. None is the local directory. 2276 #ds.resdir = None 2277 ds.resdir = ds.tmpdir 2278 2279 # Do r20_from_min_r2eff ?. 2280 ds.r20_from_min_r2eff = True 2281 2282 # Remove insignificant level. 2283 ds.insignificance = 0.0 2284 2285 # The grid search size (the number of increments per dimension). 2286 ds.GRID_INC = None 2287 2288 # The do clustering. 2289 ds.do_cluster = True 2290 2291 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2292 # The default value is 1e-25. 2293 ds.set_func_tol = 1e-1 2294 2295 # The maximum number of iterations. 2296 # The default value is 1e7. 2297 ds.set_max_iter = 1000 2298 2299 # The verbosity level. 2300 ds.verbosity = 1 2301 2302 # The rel_change WARNING level. 2303 ds.rel_change = 0.05 2304 2305 # The plot_curves. 2306 ds.plot_curves = False 2307 2308 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2309 ds.sherekhan_input = False 2310 2311 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2312 ds.opendx = False 2313 2314 # The set r2eff err. 2315 ds.r2eff_err = 0.1 2316 2317 # The print result info. 2318 ds.print_res = True 2319 2320 # Execute the script. 2321 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2322 2323 cur_spins = ds.data[2] 2324 # Compare results. 2325 for i in range(len(cur_spins)): 2326 res_name, res_num, spin_name, params = cur_spins[i] 2327 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2328 cur_spin = return_spin(cur_spin_id) 2329 2330 grid_params = ds.grid_results[i][3] 2331 2332 # Extract the clust results. 2333 min_params = ds.clust_results[i][3] 2334 # Now read the parameters. 2335 print("For spin: '%s'"%cur_spin_id) 2336 for mo_param in cur_spin.params: 2337 # The R2 is a dictionary, depending on spectrometer frequency. 2338 if isinstance(getattr(cur_spin, mo_param), dict): 2339 grid_r2 = grid_params[mo_param] 2340 min_r2 = min_params[mo_param] 2341 set_r2 = params[mo_param] 2342 for key, val in list(set_r2.items()): 2343 grid_r2_frq = grid_r2[key] 2344 min_r2_frq = min_r2[key] 2345 set_r2_frq = set_r2[key] 2346 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2347 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2348 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2349 if rel_change > ds.rel_change: 2350 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2351 print("###################################") 2352 2353 ## Make test on R2. 2354 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2355 else: 2356 grid_val = grid_params[mo_param] 2357 min_val = min_params[mo_param] 2358 set_val = params[mo_param] 2359 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2360 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2361 if rel_change > ds.rel_change: 2362 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2363 print("###################################") 2364 2365 ## Make test on parameters. 2366 if mo_param == 'dw': 2367 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2368 elif mo_param == 'kex': 2369 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2370 elif mo_param == 'pA': 2371 self.assertAlmostEqual(set_val, min_val, 2)
2372 2373
2375 """Test synthetic cpmg data. 2376 2377 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2378 """ 2379 2380 # Reset. 2381 #self.interpreter.reset() 2382 2383 ## Set Experiments. 2384 model_create = 'NS CPMG 2-site 3D' 2385 #model_create = 'NS CPMG 2-site expanded' 2386 model_analyse = 'CR72' 2387 # Exp 1 2388 sfrq_1 = 599.8908617*1E6 2389 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2390 time_T2_1 = 0.06 2391 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2392 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2393 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2394 2395 sfrq_2 = 499.8908617*1E6 2396 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2397 time_T2_2 = 0.05 2398 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2399 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2400 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2401 2402 # Collect all exps 2403 exps = [exp_1, exp_2] 2404 2405 spins = [ 2406 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2407 ] 2408 2409 # Collect the data to be used. 2410 ds.data = [model_create, model_analyse, spins, exps] 2411 2412 # The tmp directory. None is the local directory. 2413 ds.tmpdir = ds.tmpdir 2414 2415 # The results directory. None is the local directory. 2416 #ds.resdir = None 2417 ds.resdir = ds.tmpdir 2418 2419 # Do r20_from_min_r2eff ?. 2420 ds.r20_from_min_r2eff = True 2421 2422 # Remove insignificant level. 2423 ds.insignificance = 0.0 2424 2425 # The grid search size (the number of increments per dimension). 2426 ds.GRID_INC = 8 2427 2428 # The do clustering. 2429 ds.do_cluster = False 2430 2431 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2432 # The default value is 1e-25. 2433 ds.set_func_tol = 1e-9 2434 2435 # The maximum number of iterations. 2436 # The default value is 1e7. 2437 ds.set_max_iter = 1000 2438 2439 # The verbosity level. 2440 ds.verbosity = 1 2441 2442 # The rel_change WARNING level. 2443 ds.rel_change = 0.05 2444 2445 # The plot_curves. 2446 ds.plot_curves = False 2447 2448 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2449 ds.sherekhan_input = False 2450 2451 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2452 ds.opendx = False 2453 2454 # The set r2eff err. 2455 ds.r2eff_err = 0.1 2456 2457 # The print result info. 2458 ds.print_res = False 2459 2460 # Execute the script. 2461 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2462 2463 cur_spins = ds.data[2] 2464 # Compare results. 2465 for i in range(len(cur_spins)): 2466 res_name, res_num, spin_name, params = cur_spins[i] 2467 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2468 cur_spin = return_spin(cur_spin_id) 2469 2470 grid_params = ds.grid_results[i][3] 2471 min_params = ds.min_results[i][3] 2472 # Now read the parameters. 2473 print("For spin: '%s'"%cur_spin_id) 2474 for mo_param in cur_spin.params: 2475 # The R2 is a dictionary, depending on spectrometer frequency. 2476 if isinstance(getattr(cur_spin, mo_param), dict): 2477 grid_r2 = grid_params[mo_param] 2478 min_r2 = min_params[mo_param] 2479 set_r2 = params[mo_param] 2480 for key, val in list(set_r2.items()): 2481 grid_r2_frq = grid_r2[key] 2482 min_r2_frq = min_r2[key] 2483 set_r2_frq = set_r2[key] 2484 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2485 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2486 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2487 if rel_change > ds.rel_change: 2488 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2489 print("###################################") 2490 2491 ## Make test on R2. 2492 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2493 else: 2494 grid_val = grid_params[mo_param] 2495 min_val = min_params[mo_param] 2496 set_val = params[mo_param] 2497 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2498 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2499 if rel_change > ds.rel_change: 2500 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2501 print("###################################") 2502 2503 ## Make test on parameters. 2504 if mo_param == 'dw': 2505 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2506 elif mo_param == 'kex': 2507 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2508 elif mo_param == 'pA': 2509 self.assertAlmostEqual(set_val, min_val, 3)
2510 2511
2513 """Test synthetic cpmg data. 2514 2515 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2516 Try to catch bug #22021 U{https://web.archive.org/web/https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2517 """ 2518 2519 # Reset. 2520 #self.interpreter.reset() 2521 2522 ## Set Experiments. 2523 model_create = 'NS CPMG 2-site 3D' 2524 #model_create = 'NS CPMG 2-site expanded' 2525 model_analyse = 'B14' 2526 # Exp 1 2527 sfrq_1 = 599.8908617*1E6 2528 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2529 time_T2_1 = 0.06 2530 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2531 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2532 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2533 2534 sfrq_2 = 499.8908617*1E6 2535 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2536 time_T2_2 = 0.05 2537 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2538 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2539 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2540 2541 # Collect all exps 2542 exps = [exp_1, exp_2] 2543 2544 spins = [ 2545 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2546 ] 2547 2548 # Collect the data to be used. 2549 ds.data = [model_create, model_analyse, spins, exps] 2550 2551 # The tmp directory. None is the local directory. 2552 ds.tmpdir = ds.tmpdir 2553 2554 # The results directory. None is the local directory. 2555 #ds.resdir = None 2556 ds.resdir = ds.tmpdir 2557 2558 # Do r20_from_min_r2eff ?. 2559 ds.r20_from_min_r2eff = True 2560 2561 # Remove insignificant level. 2562 ds.insignificance = 0.0 2563 2564 # The grid search size (the number of increments per dimension). 2565 ds.GRID_INC = 8 2566 2567 # The do clustering. 2568 ds.do_cluster = False 2569 2570 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2571 # The default value is 1e-25. 2572 ds.set_func_tol = 1e-9 2573 2574 # The maximum number of iterations. 2575 # The default value is 1e7. 2576 ds.set_max_iter = 1000 2577 2578 # The verbosity level. 2579 ds.verbosity = 1 2580 2581 # The rel_change WARNING level. 2582 ds.rel_change = 0.05 2583 2584 # The plot_curves. 2585 ds.plot_curves = False 2586 2587 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2588 ds.sherekhan_input = False 2589 2590 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2591 ds.opendx = False 2592 2593 # The set r2eff err. 2594 ds.r2eff_err = 0.1 2595 2596 # The print result info. 2597 ds.print_res = False 2598 2599 # Execute the script. 2600 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2601 2602 cur_spins = ds.data[2] 2603 # Compare results. 2604 for i in range(len(cur_spins)): 2605 res_name, res_num, spin_name, params = cur_spins[i] 2606 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2607 cur_spin = return_spin(cur_spin_id) 2608 2609 grid_params = ds.grid_results[i][3] 2610 min_params = ds.min_results[i][3] 2611 # Now read the parameters. 2612 print("For spin: '%s'"%cur_spin_id) 2613 for mo_param in cur_spin.params: 2614 # The R2 is a dictionary, depending on spectrometer frequency. 2615 if isinstance(getattr(cur_spin, mo_param), dict): 2616 grid_r2 = grid_params[mo_param] 2617 min_r2 = min_params[mo_param] 2618 set_r2 = params[mo_param] 2619 for key, val in list(set_r2.items()): 2620 grid_r2_frq = grid_r2[key] 2621 min_r2_frq = min_r2[key] 2622 set_r2_frq = set_r2[key] 2623 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2624 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2625 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2626 if rel_change > ds.rel_change: 2627 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2628 print("###################################") 2629 2630 ## Make test on R2. 2631 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2632 else: 2633 grid_val = grid_params[mo_param] 2634 min_val = min_params[mo_param] 2635 set_val = params[mo_param] 2636 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2637 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2638 if rel_change > ds.rel_change: 2639 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2640 print("###################################") 2641 2642 ## Make test on parameters. 2643 if mo_param == 'dw': 2644 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2645 elif mo_param == 'kex': 2646 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2647 elif mo_param == 'pA': 2648 self.assertAlmostEqual(set_val, min_val, 6)
2649 2650
2652 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2653 2654 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2655 """ 2656 2657 # Reset. 2658 #self.interpreter.reset() 2659 2660 ## Set Experiments. 2661 model_create = 'NS CPMG 2-site 3D' 2662 #model_create = 'NS CPMG 2-site expanded' 2663 model_analyse = 'CR72' 2664 2665 # Exp 1 2666 sfrq_1 = 599.8908617*1E6 2667 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2668 time_T2_1 = 0.06 2669 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2670 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2671 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2672 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2673 2674 sfrq_2 = 499.8908617*1E6 2675 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2676 time_T2_2 = 0.05 2677 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2678 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2679 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2680 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2681 2682 # Collect all exps 2683 exps = [exp_1, exp_2] 2684 2685 spins = [ 2686 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2687 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2688 ] 2689 2690 # Collect the data to be used. 2691 ds.data = [model_create, model_analyse, spins, exps] 2692 2693 # The tmp directory. None is the local directory. 2694 ds.tmpdir = ds.tmpdir 2695 2696 # The results directory. None is the local directory. 2697 #ds.resdir = None 2698 ds.resdir = ds.tmpdir 2699 2700 # Do r20_from_min_r2eff ?. 2701 ds.r20_from_min_r2eff = True 2702 2703 # Remove insignificant level. 2704 ds.insignificance = 0.0 2705 2706 # The grid search size (the number of increments per dimension). 2707 ds.GRID_INC = 13 2708 2709 # The do clustering. 2710 ds.do_cluster = True 2711 2712 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2713 # The default value is 1e-25. 2714 ds.set_func_tol = 1e-8 2715 2716 # The maximum number of iterations. 2717 # The default value is 1e7. 2718 ds.set_max_iter = 10000 2719 2720 # The verbosity level. 2721 ds.verbosity = 1 2722 2723 # The rel_change WARNING level. 2724 ds.rel_change = 0.05 2725 2726 # The plot_curves. 2727 ds.plot_curves = False 2728 2729 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2730 ds.sherekhan_input = False 2731 2732 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2733 ds.opendx = False 2734 2735 # The set r2eff err. 2736 ds.r2eff_err = 0.1 2737 2738 # The print result info. 2739 ds.print_res = False 2740 2741 # Execute the script. 2742 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2743 2744 cur_spins = ds.data[2] 2745 # Compare results. 2746 for i in range(len(cur_spins)): 2747 res_name, res_num, spin_name, params = cur_spins[i] 2748 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2749 cur_spin = return_spin(cur_spin_id) 2750 2751 grid_params = ds.grid_results[i][3] 2752 2753 # Extract the clust results. 2754 min_params = ds.clust_results[i][3] 2755 # Now read the parameters. 2756 print("For spin: '%s'"%cur_spin_id) 2757 for mo_param in cur_spin.params: 2758 # The R2 is a dictionary, depending on spectrometer frequency. 2759 if isinstance(getattr(cur_spin, mo_param), dict): 2760 grid_r2 = grid_params[mo_param] 2761 min_r2 = min_params[mo_param] 2762 set_r2 = params[mo_param] 2763 for key, val in list(set_r2.items()): 2764 grid_r2_frq = grid_r2[key] 2765 min_r2_frq = min_r2[key] 2766 set_r2_frq = set_r2[key] 2767 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2768 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2769 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2770 if rel_change > ds.rel_change: 2771 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2772 print("###################################") 2773 2774 ## Make test on R2. 2775 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2776 else: 2777 grid_val = grid_params[mo_param] 2778 min_val = min_params[mo_param] 2779 set_val = params[mo_param] 2780 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2781 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2782 if rel_change > ds.rel_change: 2783 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2784 print("###################################") 2785 2786 ## Make test on parameters. 2787 if mo_param == 'dw': 2788 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2789 elif mo_param == 'kex': 2790 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2791 elif mo_param == 'pA': 2792 self.assertAlmostEqual(set_val, min_val, 2)
2793 2794
2796 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2797 2798 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2799 """ 2800 2801 # Reset. 2802 #self.interpreter.reset() 2803 2804 ## Set Experiments. 2805 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2806 model_analyse = 'CR72' 2807 # Exp 1 2808 sfrq_1 = 599.8908617*1E6 2809 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2810 time_T2_1 = 0.06 2811 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2812 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2813 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2814 2815 sfrq_2 = 499.8908617*1E6 2816 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2817 time_T2_2 = 0.05 2818 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2819 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2820 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2821 2822 # Collect all exps 2823 exps = [exp_1, exp_2] 2824 2825 spins = [ 2826 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2827 ] 2828 2829 # Collect the data to be used. 2830 ds.data = [model_create, model_analyse, spins, exps] 2831 2832 # The tmp directory. None is the local directory. 2833 ds.tmpdir = ds.tmpdir 2834 2835 # The results directory. None is the local directory. 2836 #ds.resdir = None 2837 ds.resdir = ds.tmpdir 2838 2839 # Do r20_from_min_r2eff ?. 2840 ds.r20_from_min_r2eff = True 2841 2842 # Remove insignificant level. 2843 ds.insignificance = 0.0 2844 2845 # The grid search size (the number of increments per dimension). 2846 ds.GRID_INC = None 2847 2848 # The do clustering. 2849 ds.do_cluster = False 2850 2851 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2852 # The default value is 1e-25. 2853 ds.set_func_tol = 1e-9 2854 2855 # The maximum number of iterations. 2856 # The default value is 1e7. 2857 ds.set_max_iter = 1000 2858 2859 # The verbosity level. 2860 ds.verbosity = 1 2861 2862 # The rel_change WARNING level. 2863 ds.rel_change = 0.05 2864 2865 # The plot_curves. 2866 ds.plot_curves = False 2867 2868 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2869 ds.sherekhan_input = False 2870 2871 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2872 ds.opendx = False 2873 2874 # The set r2eff err. 2875 ds.r2eff_err = 0.1 2876 2877 # The print result info. 2878 ds.print_res = False 2879 2880 # Execute the script. 2881 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2882 2883 # Get the spins. 2884 cur_spins = ds.data[2] 2885 2886 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2887 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2888 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2889 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2890 2891 # Copy R2eff, but not the original parameters 2892 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2893 2894 # Then select model. 2895 self.interpreter.relax_disp.select_model(model=model_analyse) 2896 2897 # Define dx.map settings. 2898 ds.dx_inc = 4 2899 ds.dx_params = ['dw', 'pA', 'kex'] 2900 2901 res_name, res_num, spin_name, params = cur_spins[0] 2902 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2903 cur_spin = return_spin(cur_spin_id) 2904 2905 print("Params for dx map is") 2906 print(ds.dx_params) 2907 print("Point param for dx map is") 2908 print(ds.dx_set_val) 2909 cur_model = model_analyse.replace(' ', '_') 2910 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2911 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2912 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point, create_par_file=True) 2913 2914 ## Check for file creation 2915 # Set filepaths. 2916 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2917 map_net = ds.tmpdir+sep+file_name_map+".net" 2918 map_general = ds.tmpdir+sep+file_name_map+".general" 2919 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir) 2920 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir) 2921 2922 point_general = ds.tmpdir+sep+file_name_point+".general" 2923 point_point = ds.tmpdir+sep+file_name_point 2924 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir) 2925 2926 # Test the files exists. 2927 self.assert_(access(map_cfg, F_OK)) 2928 self.assert_(access(map_net, F_OK)) 2929 self.assert_(access(map_general, F_OK)) 2930 self.assert_(access(map_par, F_OK)) 2931 self.assert_(access(map_plot, F_OK)) 2932 self.assert_(access(point_general, F_OK)) 2933 self.assert_(access(point_point, F_OK)) 2934 self.assert_(access(point_par, F_OK)) 2935 2936 # Open the files for testing. 2937 # Check the cfg file. 2938 print("\nChecking the dx map .cfg file.") 2939 res_file = [ 2940 '//'+"\n", 2941 '//'+"\n", 2942 '// time: Thu May 8 18:55:31 2014'+"\n", 2943 '//'+"\n", 2944 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2945 '//'+"\n", 2946 '//'+"\n", 2947 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2948 '// title: value = Control Panel'+"\n", 2949 '//'+"\n", 2950 '// workspace: width = 251, height = 142'+"\n", 2951 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2952 '//'+"\n", 2953 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2954 '// selections: maximum = 2, current = 0 '+"\n", 2955 '// option[0]: name = "Colour", value = 1'+"\n", 2956 '// option[1]: name = "Grey", value = 2'+"\n", 2957 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2958 '// label: value = Colour Selector'+"\n", 2959 '//'+"\n", 2960 '// node Image[3]:'+"\n", 2961 '// title: value = Surface'+"\n", 2962 '// depth: value = 24'+"\n", 2963 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2964 ] 2965 file = open(map_cfg, 'r') 2966 lines = file.readlines() 2967 file.close() 2968 for i in range(len(res_file)): 2969 # Skip time point 2970 if i == 2: 2971 continue 2972 self.assertEqual(res_file[i], lines[i]) 2973 2974 print("\nChecking the dx map .general file.") 2975 res_file = [ 2976 'file = CR72_map_1_N'+"\n", 2977 'grid = 5 x 5 x 5'+"\n", 2978 'format = ascii'+"\n", 2979 'interleaving = field'+"\n", 2980 'majority = row'+"\n", 2981 'field = data'+"\n", 2982 'structure = scalar'+"\n", 2983 'type = float'+"\n", 2984 'dependency = positions'+"\n", 2985 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2986 ''+"\n", 2987 'end'+"\n", 2988 ] 2989 file = open(map_general, 'r') 2990 lines = file.readlines() 2991 file.close() 2992 for i in range(len(res_file)): 2993 # Skip time point 2994 #if i == 2: 2995 # continue 2996 self.assertEqual(res_file[i], lines[i]) 2997 2998 print("\nChecking the dx point .general file.") 2999 res_file = [ 3000 'file = CR72_point_1_N'+"\n", 3001 'points = 2'+"\n", 3002 'format = ascii'+"\n", 3003 'interleaving = field'+"\n", 3004 'field = locations, field0'+"\n", 3005 'structure = 3-vector, scalar'+"\n", 3006 'type = float, float'+"\n", 3007 ''+"\n", 3008 'end'+"\n", 3009 ] 3010 file = open(point_general, 'r') 3011 lines = file.readlines() 3012 file.close() 3013 for i in range(len(res_file)): 3014 # Skip time point 3015 #if i == 2: 3016 # continue 3017 self.assertEqual(res_file[i], lines[i]) 3018 3019 print("\nChecking the dx point point file.") 3020 res_file = [ 3021 '0.8 3.92 0.39964 1'+"\n", 3022 '0.76981 3.9169 0.41353 1'+"\n", 3023 ] 3024 file = open(point_point, 'r') 3025 lines = file.readlines() 3026 file.close() 3027 for i in range(len(res_file)): 3028 # Skip time point 3029 #if i == 2: 3030 # continue 3031 self.assertEqual(res_file[i], lines[i]) 3032 3033 print("\nChecking the dx point par file.") 3034 res_file = [ 3035 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3036 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3037 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n", 3038 ] 3039 res_file2 = [ 3040 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3041 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3042 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n", 3043 ] # Python 2.5 and 3.1. 3044 file = open(point_par, 'r') 3045 lines = file.readlines() 3046 file.close() 3047 for i in range(len(res_file)): 3048 if lines[i] != res_file[i] and lines[i] != res_file2[i]: 3049 self.assertEqual(res_file[i], lines[i]) 3050 3051 print("\nChecking the matplotlib surface plot file.") 3052 res_file = [ 3053 'from copy import deepcopy'+"\n", 3054 'import numpy as np'+"\n", 3055 'import scipy.interpolate'+"\n", 3056 'from numpy.ma import masked_where'+"\n", 3057 ''+"\n", 3058 'from mpl_toolkits.mplot3d import axes3d'+"\n", 3059 'import matplotlib.pyplot as plt'+"\n", 3060 'from matplotlib import cm'+"\n", 3061 ''+"\n", 3062 '# Open file and get header.'+"\n", 3063 'mapfile_name = "%s.par"'%file_name_map+"\n", 3064 'pointfile_name = "%s.par"'%file_name_point+"\n", 3065 ''+"\n", 3066 ] 3067 file = open(map_plot, 'r') 3068 lines = file.readlines() 3069 file.close() 3070 for i in range(len(res_file)): 3071 self.assertEqual(res_file[i], lines[i])
3072 3073
3075 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 3076 3077 # Reset. 3078 self.interpreter.reset() 3079 3080 # Load the base data. 3081 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 3082 self.interpreter.state.load(data_path+sep+'r2eff_values') 3083 3084 # The type. 3085 curve_type = get_curve_type(id='500_133.33.in') 3086 self.assertEqual(curve_type, 'fixed time')
3087 3088
3089 - def test_curve_type_r1rho_exponential(self, model=None):
3090 """Test the curve type detection using the 'M61' exponential test data.""" 3091 3092 # Reset. 3093 self.interpreter.reset() 3094 3095 # Load the base data. 3096 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 3097 self.interpreter.state.load(data_path+sep+'r2eff_values') 3098 3099 # The type. 3100 curve_type = get_curve_type(id='nu_2000_ncyc9') 3101 self.assertEqual(curve_type, 'exponential')
3102 3103
3104 - def test_curve_type_r1rho_fixed_time(self, model=None):
3105 """Test the curve type detection using the 'TP02' fixed time test data.""" 3106 3107 # Reset. 3108 self.interpreter.reset() 3109 3110 # Load the base data. 3111 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 3112 self.interpreter.state.load(data_path+sep+'r2eff_values') 3113 3114 # The type. 3115 curve_type = get_curve_type(id='nu_1000.0_500MHz') 3116 self.assertEqual(curve_type, 'fixed time')
3117 3118
3119 - def test_dpl94_data_to_dpl94(self):
3120 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 3121 3122 # Fixed time variable. 3123 ds.fixed = True 3124 3125 # Execute the script. 3126 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 3127 3128 # The original parameters. 3129 i0 = [100000.0, 20000.0] 3130 r1rho_prime = [2.25, 24.0] 3131 pA = 0.7 3132 kex = 1000.0 3133 delta_omega = [1.0, 2.0] 3134 phi_ex = [] 3135 for i in range(2): 3136 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 3137 3138 # Switch to the 'DPL94' model data pipe, then check for each spin. 3139 self.interpreter.pipe.switch('DPL94 - relax_disp') 3140 spin_index = 0 3141 for spin, spin_id in spin_loop(return_id=True): 3142 # Printout. 3143 print("\nSpin %s." % spin_id) 3144 3145 # Check the fitted parameters. 3146 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 3147 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 3148 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 3149 3150 # Increment the spin index. 3151 spin_index += 1
3152 3153
3154 - def test_dx_map_clustered(self):
3155 """Test making dx_map for residues under clustered calculation. 3156 3157 This uses CPMG data from: 3158 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 3159 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 3160 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 3161 """ 3162 3163 # Define path to data 3164 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 3165 3166 # Read data. 3167 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3168 3169 # Get residue of interest. 3170 cur_spin_id = ":%i@%s"%(52, 'N') 3171 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3172 3173 # Get the spin container. 3174 cur_spin = return_spin(cur_spin_id) 3175 3176 # Get the chi2 value 3177 pre_chi2 = cur_spin.chi2 3178 3179 # Then do a local minimisation. 3180 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3181 self.interpreter.minimise.calculate() 3182 3183 # Get the chi2 value after calculation. 3184 calc_chi2 = cur_spin.chi2 3185 3186 # Assert calculation is equal. 3187 self.assertAlmostEqual(pre_chi2, calc_chi2) 3188 3189 # Define dx.map settings. 3190 dx_inc = 2 3191 dx_inc_sides = dx_inc / 2 3192 3193 dx_params = ['dw', 'pA', 'kex'] 3194 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3195 3196 print("Params for dx map is") 3197 print(dx_params) 3198 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3199 print(dx_point_clustered_min) 3200 3201 # Define file_names. 3202 cur_model = 'CR72' 3203 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3204 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3205 3206 # Step-size of parameter is 10 % 3207 param_delta = 0.1 3208 3209 # Determine bounds for lower and upper 3210 lower = [] 3211 upper = [] 3212 for i, param_val in enumerate(dx_point_clustered_min): 3213 param = dx_params[i] 3214 step_val = param_delta * param_val 3215 step_length = step_val * dx_inc_sides 3216 3217 # Calculate value 3218 low_val = param_val - step_length 3219 lower.append(low_val) 3220 3221 upp_val = param_val + step_length 3222 upper.append(upp_val) 3223 3224 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val)) 3225 3226 # If the number of increments are 2, there will be 3 point calculations per parameter. 3227 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3228 dx_param_indexes = dx_inc + 1 3229 dx_point_index = dx_inc_sides + 1 3230 3231 # Find the line number. 3232 line = 1 3233 for i in range(1, dx_param_indexes + 1): 3234 for j in range(1, dx_param_indexes + 1): 3235 for k in range(1, dx_param_indexes + 1): 3236 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3237 line_chi2 = line 3238 # Add to line counter. 3239 line += 1 3240 3241 # Define temporary folder. 3242 result_dir = self.tmpdir 3243 3244 # For testing. 3245 #result_dir = None 3246 #lower = None 3247 #upper = None 3248 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3249 3250 3251 # Then do the map. 3252 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point) 3253 3254 # Print where to locate values. 3255 nr_chi2_val = dx_param_indexes**3 3256 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3257 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3258 3259 ## Check for file creation 3260 # Set filepaths. 3261 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3262 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3263 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3264 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3265 3266 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3267 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3268 3269 # Test the files exists. 3270 self.assert_(access(map_cfg, F_OK)) 3271 self.assert_(access(map_net, F_OK)) 3272 self.assert_(access(map_general, F_OK)) 3273 self.assert_(access(point_general, F_OK)) 3274 self.assert_(access(point_point, F_OK)) 3275 3276 # Open the file, and assert the chi2 value is as expected. 3277 get_data = extract_data(file=map_name) 3278 3279 # Extract line 0, column 0. 3280 test = float(get_data[line_chi2-1][0]) 3281 3282 # Assert. 3283 self.assertAlmostEqual(test, pre_chi2, 6)
3284 3285
3287 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file. 3288 3289 U{Task #7860<https://web.archive.org/web/https://gna.org/task/index.php?7860>} : When dx_map is issued, create a parameter file which maps parameters to chi2 value. 3290 3291 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 3292 """ 3293 3294 # Define path to data 3295 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting' 3296 3297 # Read data. 3298 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2') 3299 3300 # Get residue of interest. 3301 cur_spin_id = ":%i@%s"%(65, 'N') 3302 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3303 3304 # Get the spin container. 3305 cur_spin = return_spin(cur_spin_id) 3306 3307 # Get the chi2 value 3308 pre_chi2 = cur_spin.chi2 3309 3310 # Then do a local minimisation. 3311 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3312 self.interpreter.minimise.calculate() 3313 3314 # Get the chi2 value after calculation. 3315 calc_chi2 = cur_spin.chi2 3316 3317 # Assert calculation is equal. 3318 self.assertAlmostEqual(pre_chi2, calc_chi2) 3319 3320 # Define dx.map settings. 3321 dx_inc = 2 3322 dx_params = ['dw', 'k_AB', 'r2a'] 3323 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']] 3324 3325 print("Params for dx map is") 3326 print(dx_params) 3327 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3328 print(dx_point_clustered_min) 3329 3330 # Define file_names. 3331 cur_model = 'TSMFK01' 3332 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3333 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3334 3335 # Determine bounds for lower and upper 3336 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]] 3337 upper = [19.0, 2.4, 9.5] 3338 3339 # Define temporary folder. 3340 result_dir = self.tmpdir 3341 3342 # For testing. 3343 #result_dir = None 3344 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3345 3346 # Then do the map. 3347 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point, create_par_file=True) 3348 3349 # Print where to locate values. 3350 nr_chi2_val = (dx_inc + 1)**3 3351 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3352 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) ) 3353 3354 ## Check for file creation 3355 # Set filepaths. 3356 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3357 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3358 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3359 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3360 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir) 3361 3362 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3363 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3364 3365 # Test the files exists. 3366 self.assert_(access(map_cfg, F_OK)) 3367 self.assert_(access(map_net, F_OK)) 3368 self.assert_(access(map_general, F_OK)) 3369 self.assert_(access(map_par, F_OK)) 3370 self.assert_(access(point_general, F_OK)) 3371 self.assert_(access(point_point, F_OK)) 3372 3373 print("\nParams for dx map is") 3374 print(dx_params) 3375 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3376 print(dx_point_clustered_min, "\n") 3377 3378 # Open the parameter chi2 file, and assert the chi2 value in the sorted parameter file is not lower that than the global minimisation. 3379 get_data = extract_data(file=map_par) 3380 3381 # Extract line 1, column 9. 3382 test = float(get_data[1][9]) 3383 3384 # Print data if map contain a lower value than the global minimised value. 3385 if test < pre_chi2: 3386 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test)) 3387 for line in get_data: 3388 print(line)
3389 3390 # Assert that the initial global chi2 is lower than the map value. 3391 3392 # The following test was taken out, since this a particular interesting case. 3393 # There exist a double minimum, where relax has not found the global minimum. 3394 # This is due to not grid searching for R2A, but using the minimum 3395 #self.assert_(pre_chi2 < test) 3396 3397
3398 - def test_estimate_r2eff_err(self):
3399 """Test the user function for estimating R2eff errors from exponential curve fitting. 3400 3401 This follows Task 7822. 3402 U{task #7822<https://web.archive.org/web/https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3403 3404 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3405 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3406 """ 3407 3408 # Cluster residues 3409 cluster_ids = [ 3410 ":13@N", 3411 ":15@N", 3412 ":16@N", 3413 ":25@N", 3414 ":26@N", 3415 ":28@N", 3416 ":39@N", 3417 ":40@N", 3418 ":41@N", 3419 ":43@N", 3420 ":44@N", 3421 ":45@N", 3422 ":49@N", 3423 ":52@N", 3424 ":53@N"] 3425 3426 # Load the data. 3427 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3428 3429 # The dispersion models. 3430 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3431 3432 # The grid search size (the number of increments per dimension). 3433 GRID_INC = None 3434 3435 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3436 MC_NUM = 3 3437 3438 # Model selection technique. 3439 MODSEL = 'AIC' 3440 3441 # Execute the auto-analysis (fast). 3442 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3443 OPT_FUNC_TOL = 1e-25 3444 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3445 OPT_MAX_ITERATIONS = 10000000 3446 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3447 3448 result_dir_name = ds.tmpdir 3449 3450 # Make all spins free 3451 for curspin in cluster_ids: 3452 self.interpreter.relax_disp.cluster('free spins', curspin) 3453 # Shut them down 3454 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3455 3456 # Select only a subset of spins for global fitting 3457 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3458 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3459 3460 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3461 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3462 3463 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3464 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3465 3466 # Set the model. 3467 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3468 3469 # Check if intensity errors have already been calculated. 3470 check_intensity_errors() 3471 3472 # Do a grid search. 3473 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3474 3475 # Minimise. 3476 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3477 3478 # Estimate R2eff errors. 3479 self.interpreter.relax_disp.r2eff_err_estimate() 3480 3481 r1_fit = True 3482 3483 # Run the analysis. 3484 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3485 3486 # Verify the data. 3487 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3488 3489
3491 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3492 3493 This follows Task 7822. 3494 U{task #7822<https://web.archive.org/web/https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3495 3496 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3497 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3498 """ 3499 3500 # Cluster residues 3501 cluster_ids = [ 3502 ":13@N", 3503 ":15@N", 3504 ":16@N", 3505 ":25@N", 3506 ":26@N", 3507 ":28@N", 3508 ":39@N", 3509 ":40@N", 3510 ":41@N", 3511 ":43@N", 3512 ":44@N", 3513 ":45@N", 3514 ":49@N", 3515 ":52@N", 3516 ":53@N"] 3517 3518 # Load the data. 3519 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3520 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3521 3522 # Set pipe name, bundle and type. 3523 pipe_name = 'base pipe' 3524 pipe_bundle = 'relax_disp' 3525 pipe_type = 'relax_disp' 3526 3527 # Create the data pipe. 3528 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3529 3530 file = data_path + '1_setup_r1rho_GUI.py' 3531 self.interpreter.script(file=file, dir=None) 3532 3533 # The dispersion models. 3534 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3535 3536 # The grid search size (the number of increments per dimension). 3537 GRID_INC = None 3538 3539 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3540 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3541 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3542 EXP_MC_NUM = -1 3543 3544 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3545 MC_NUM = 3 3546 3547 # Model selection technique. 3548 MODSEL = 'AIC' 3549 3550 # Execute the auto-analysis (fast). 3551 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3552 OPT_FUNC_TOL = 1e-25 3553 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3554 OPT_MAX_ITERATIONS = 10000000 3555 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3556 3557 # Make all spins free 3558 #for curspin in cluster_ids: 3559 # self.interpreter.relax_disp.cluster('free spins', curspin) 3560 # # Shut them down 3561 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3562 3563 # Make all spins free 3564 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3565 3566 # Select only a subset of spins for global fitting 3567 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3568 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3569 3570 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3571 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3572 3573 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3574 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3575 3576 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3577 print(spin_id) 3578 3579 result_dir_name = self.tmpdir 3580 r1_fit = True 3581 3582 # Run the analysis. 3583 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3584 3585 # Verify the data. 3586 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3587 3588
3590 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3591 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3592 3593 This follows Task 7822. 3594 U{task #7822<https://web.archive.org/web/https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3595 3596 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3597 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3598 3599 NOTE: The difference in the methods was due to a bug in relax! 3600 U{bug #22554<https://web.archive.org/web/https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3601 3602 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3603 """ 3604 3605 # Define data path. 3606 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3607 3608 # Create pipe. 3609 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3610 3611 # Read results for 2000 MC simulations. 3612 self.interpreter.results.read(prev_data_path + sep + 'results') 3613 3614 # Start dic. 3615 my_dic = {} 3616 param_key_list = [] 3617 3618 # Do boot strapping ? 3619 do_boot = True 3620 if do_boot: 3621 min_algor = 'Newton' 3622 min_options = () 3623 sim_boot = 200 3624 scaling_list = [1.0, 1.0] 3625 3626 # First check sim values. 3627 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3628 # Add key to dic. 3629 my_dic[spin_id] = {} 3630 3631 # Loop over sim. 3632 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3633 # Loop over all exp type. 3634 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3635 # Generate the param_key. 3636 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3637 r2eff_sim_point = r2eff_sim[param_key] 3638 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3639 3640 # Assert point are higher than 0.0. 3641 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3642 #print(point_info) 3643 self.assert_(r2eff_sim_point > 0.0) 3644 self.assert_(i0_sim_point > 0.0) 3645 3646 # Get the data. 3647 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3648 # Generate spin string. 3649 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3650 3651 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3652 # Generate the param_key. 3653 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3654 3655 # Loop over all sim, and collect data. 3656 r2eff_sim_l = [] 3657 i0_sim_l = [] 3658 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3659 i0_sim = cur_spin.i0_sim[i] 3660 3661 r2eff_sim_i = r2eff_sim[param_key] 3662 r2eff_sim_l.append(r2eff_sim_i) 3663 i0_sim_i = i0_sim[param_key] 3664 i0_sim_l.append(i0_sim_i) 3665 3666 # Take the standard deviation of all values. 3667 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3668 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3669 3670 # Append key. 3671 param_key_list.append(param_key) 3672 3673 # Add key to dic. 3674 my_dic[spin_id][param_key] = {} 3675 3676 # Get the value. 3677 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3678 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3679 i0 = getattr(cur_spin, 'i0')[param_key] 3680 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3681 3682 # Save to dic. 3683 my_dic[spin_id][param_key]['r2eff'] = r2eff 3684 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3685 my_dic[spin_id][param_key]['i0'] = i0 3686 my_dic[spin_id][param_key]['i0_err'] = i0_err 3687 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3688 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3689 3690 # Assert values are equal 3691 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3692 self.assertAlmostEqual(i0_sim_err, i0_err) 3693 3694 if do_boot: 3695 values = [] 3696 errors = [] 3697 times = [] 3698 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3699 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3700 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3701 times.append(time) 3702 3703 # Convert to numpy array. 3704 values = asarray(values) 3705 errors = asarray(errors) 3706 times = asarray(times) 3707 3708 R_m_sim_l = [] 3709 I0_m_sim_l = [] 3710 for j in range(sim_boot): 3711 if j in range(0, 100000, 100): 3712 print("Simulation %i"%j) 3713 # Start minimisation. 3714 3715 # Produce errors 3716 I_err = [] 3717 for j, error in enumerate(errors): 3718 I_error = gauss(values[j], error) 3719 I_err.append(I_error) 3720 # Convert to numpy array. 3721 I_err = asarray(I_err) 3722 3723 x0 = [r2eff, i0] 3724 model = Relax_fit_opt(model='exp', num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3725 3726 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3727 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3728 R_m_sim_l.append(R_m_sim_j) 3729 I0_m_sim_l.append(I0_m_sim_j) 3730 3731 # Get stats on distribution. 3732 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3733 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3734 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3735 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3736 3737 3738 # A new data pipe. 3739 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3740 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3741 3742 # Delete old errors. 3743 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3744 delattr(cur_spin, 'r2eff_err') 3745 delattr(cur_spin, 'i0_err') 3746 3747 # Set the model. 3748 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3749 3750 # Estimate R2eff and errors. 3751 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3752 3753 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3754 # Generate spin string. 3755 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3756 3757 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3758 # Generate the param_key. 3759 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3760 3761 # Get the value. 3762 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3763 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3764 i0_est = getattr(cur_spin, 'i0')[param_key] 3765 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3766 3767 # Get from dic. 3768 r2eff = my_dic[spin_id][param_key]['r2eff'] 3769 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3770 i0 = my_dic[spin_id][param_key]['i0'] 3771 i0_err = my_dic[spin_id][param_key]['i0_err'] 3772 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3773 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3774 3775 if do_boot: 3776 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3777 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3778 else: 3779 r2eff_boot_err = 0.0 3780 i0_boot_err = 0.0 3781 3782 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3783 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3784 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3785 3786 3787 # Now do it manually. 3788 estimate_r2eff(method='scipy.optimize.leastsq') 3789 3790 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3791 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3792 3793 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3794 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3795 3796 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3797 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3798 3799 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3800 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3801 3802 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3803 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3804 3805 3806
3807 - def test_exp_fit(self):
3808 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3809 3810 # Execute the script. 3811 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3812 3813 # The original exponential curve parameters. 3814 res_data = [ 3815 [15., 10., 20000., 25000.], 3816 [12., 11., 50000., 51000.], 3817 [17., 9., 100000., 96000.] 3818 ] 3819 3820 # List of parameters which do not belong to the model. 3821 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3822 3823 # Checks for each residue. 3824 for i in range(len(res_data)): 3825 # Printout. 3826 print("\nResidue number %s." % (i+1)) 3827 3828 # Check the fitted parameters. 3829 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3830 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3831 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3832 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3833 3834 # Check the simulation errors. 3835 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3836 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3837 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3838 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3839 3840 # Check that certain parameters are not present. 3841 for param in blacklist: 3842 print("\tChecking for the absence of the '%s' parameter." % param) 3843 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3844 3845 # Check the clustering information. 3846 self.assert_(hasattr(cdp, 'clustering')) 3847 keys = ['free spins', 'cluster'] 3848 for key in keys: 3849 self.assert_(key in cdp.clustering) 3850 self.assert_('test' not in cdp.clustering) 3851 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3852 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3853 3854
3855 - def test_finite_value(self):
3856 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3857 3858 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3859 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3860 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3861 3862 scaling_list = [1.0, 1.0] 3863 model = Relax_fit_opt(model='exp', num_params=2, values=I, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3864 3865 R = - 500. 3866 I0 = 1000. 3867 params = [R, I0] 3868 3869 chi2 = model.func(params) 3870 3871 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3872 self.assertNotEqual(chi2, inf)
3873 3874
3875 - def test_hansen_catia_input(self):
3876 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3877 3878 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3879 """ 3880 3881 # Load the R2eff results file. 3882 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3883 self.interpreter.results.read(file_name) 3884 self.interpreter.deselect.spin(':4') 3885 3886 # The spin isotopes. 3887 self.interpreter.spin.isotope("15N") 3888 3889 # Generate the input files. 3890 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3891 3892 # Check the r2eff set files. 3893 print("\nChecking the R2eff input set files.") 3894 files = ['data_set_500.inp', 'data_set_500.inp'] 3895 for file in files: 3896 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3897 data_set_500 = [ 3898 "ID=500\n", 3899 "Sfrq = 500\n", 3900 "Temperature = 0.0\n", 3901 "Nucleus = N15\n", 3902 "Couplednucleus = H1\n", 3903 "Time_equil = 0.0\n", 3904 "Pwx_cp = 0.0\n", 3905 "Taub = 0.0\n", 3906 "Time_T2 = 0.03\n", 3907 "Xcar = 0.0\n", 3908 "Seqfil = CW_CPMG\n", 3909 "Minerror = (2.%;0.5/s)\n", 3910 "Basis = (Iph_7)\n", 3911 "Format = (0;1;2)\n", 3912 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3913 "Data = (\n", 3914 " [70N;spin_70_N_500.cpmg];\n", 3915 " [71N;spin_71_N_500.cpmg];\n", 3916 ")\n", 3917 ] 3918 file = open(ds.tmpdir+sep+files[0]) 3919 lines = file.readlines() 3920 file.close() 3921 for i in range(len(data_set_500)): 3922 # Skip the data directory, as this is a random file name. 3923 if i == 14: 3924 continue 3925 3926 self.assertEqual(data_set_500[i], lines[i]) 3927 3928 # Check the r2eff files. 3929 print("\nChecking the R2eff input files.") 3930 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3931 for file in files: 3932 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3933 spin_70_N_500 = [ 3934 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3935 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3936 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3937 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3938 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3939 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3940 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3941 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3942 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3943 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3944 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3945 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3946 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3947 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3948 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3949 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3950 ] 3951 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3952 lines = file.readlines() 3953 file.close() 3954 for i in range(len(lines)): 3955 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3956 for i in range(len(spin_70_N_500)): 3957 self.assertEqual(spin_70_N_500[i], lines[i]) 3958 3959 # Check the main file. 3960 print("\nChecking the main CATIA execution file.") 3961 main_file = [ 3962 "ReadDataset(data_set_500.inp)\n", 3963 "ReadDataset(data_set_800.inp)\n", 3964 "ReadParam_Global(ParamGlobal.inp)\n", 3965 "ReadParam_Local(ParamSet1.inp)\n", 3966 "\n", 3967 "FreeLocalParam(all;Omega;false)\n", 3968 "FreeLocalParam(all;R1iph_500;false)\n", 3969 "FreeLocalParam(all;R1iph_800;false)\n", 3970 "\n", 3971 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3972 "\n", 3973 "PrintParam(output/GlobalParam.fit;global)\n", 3974 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3975 "PrintData(output/)\n", 3976 "\n", 3977 "ChiSq(all;all)\n", 3978 "exit(0)\n" 3979 ] 3980 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3981 lines = file.readlines() 3982 file.close() 3983 for i in range(len(main_file)): 3984 self.assertEqual(main_file[i], lines[i])
3985 3986
3988 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3989 3990 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3991 """ 3992 3993 # Set the model. 3994 ds.models = [ 3995 MODEL_NOREX, 3996 MODEL_LM63, 3997 MODEL_CR72, 3998 MODEL_IT99 3999 ] 4000 4001 # Execute the script. 4002 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 4003 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4004 4005 # The R20 keys. 4006 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4007 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4008 4009 # The 'No Rex' model checks. 4010 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4011 spin70 = return_spin(":70") 4012 spin71 = return_spin(":71") 4013 print("\n\nOptimised parameters:\n") 4014 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4015 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4016 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4017 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4018 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4019 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4020 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4021 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4022 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4023 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4024 4025 # The 'LM63' model checks. 4026 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4027 spin70 = return_spin(":70") 4028 spin71 = return_spin(":71") 4029 print("\n\nOptimised parameters:\n") 4030 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4031 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4032 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4033 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4034 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4035 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4036 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4037 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4038 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4039 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4040 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4041 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4042 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4043 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4044 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4045 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4046 4047 # The 'CR72' model checks. 4048 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4049 spin70 = return_spin(":70") 4050 spin71 = return_spin(":71") 4051 print("\n\nOptimised parameters:\n") 4052 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4053 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4054 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4055 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4056 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4057 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4058 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4059 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4060 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4061 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4062 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4063 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4064 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4065 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4066 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4067 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4068 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4069 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4070 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4071 4072
4074 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 4075 4076 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4077 """ 4078 4079 # Set the model and numeric flag. 4080 ds.models = [ 4081 MODEL_NOREX, 4082 MODEL_CR72, 4083 MODEL_NS_CPMG_2SITE_EXPANDED 4084 ] 4085 ds.numeric_only = True 4086 4087 # Execute the script. 4088 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 4089 4090 # The R20 keys. 4091 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4092 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4093 4094 # The 'No Rex' model checks. 4095 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4096 spin70 = return_spin(":70") 4097 spin71 = return_spin(":71") 4098 print("\n\nOptimised parameters:\n") 4099 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4100 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4101 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4102 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4103 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4104 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4105 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 4106 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4107 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4108 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 4109 4110 # The 'CR72' model checks. 4111 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4112 spin70 = return_spin(":70") 4113 spin71 = return_spin(":71") 4114 print("\n\nOptimised parameters:\n") 4115 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4116 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4117 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4118 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4119 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4120 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4121 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4122 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4123 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4124 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4125 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4126 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4127 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4128 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4129 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4130 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4131 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4132 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4133 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 4134 4135 # The 'NS CPMG 2-site expanded' model checks. 4136 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 4137 spin70 = return_spin(":70") 4138 spin71 = return_spin(":71") 4139 print("\n\nOptimised parameters:\n") 4140 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4141 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4142 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4143 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4144 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4145 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4146 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4147 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 4148 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 4149 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 4150 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 4151 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 4152 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 4153 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 4154 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 4155 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 4156 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 4157 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 4158 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 4159 4160 # The final data pipe checks. 4161 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 4162 spin70 = return_spin(":70") 4163 spin71 = return_spin(":71") 4164 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 4165 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4166 4167
4169 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 4170 4171 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4172 """ 4173 4174 # Set the model. 4175 ds.models = [ 4176 MODEL_NOREX, 4177 MODEL_LM63, 4178 MODEL_CR72, 4179 MODEL_IT99 4180 ] 4181 4182 # Execute the script. 4183 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 4184 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 4185 4186 # The R20 keys. 4187 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4188 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4189 4190 # The 'No Rex' model checks. 4191 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4192 spin70 = return_spin(":70") 4193 spin71 = return_spin(":71") 4194 print("\n\nOptimised parameters:\n") 4195 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4196 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4197 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4198 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4199 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4200 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4201 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4202 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4203 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4204 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4205 4206 # The 'LM63' model checks. 4207 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4208 spin70 = return_spin(":70") 4209 spin71 = return_spin(":71") 4210 print("\n\nOptimised parameters:\n") 4211 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4212 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4213 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4214 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4215 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4216 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4217 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4218 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4219 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4220 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4221 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4222 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4223 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4224 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4225 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4226 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4227 4228 # The 'CR72' model checks. 4229 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4230 spin70 = return_spin(":70") 4231 spin71 = return_spin(":71") 4232 print("\n\nOptimised parameters:\n") 4233 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4234 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4235 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4236 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4237 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4238 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4239 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4240 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4241 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4242 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4243 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4244 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4245 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4246 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 4247 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 4248 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 4249 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 4250 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 4251 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4252 4253
4255 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 4256 4257 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4258 """ 4259 4260 # Set the model. 4261 ds.models = [ 4262 MODEL_R2EFF, 4263 MODEL_NOREX, 4264 MODEL_CR72, 4265 MODEL_NS_CPMG_2SITE_EXPANDED 4266 ] 4267 4268 # Execute the script. 4269 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 4270 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4271 4272 # The R20 keys. 4273 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4274 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4275 4276 # The 'No Rex' model checks. 4277 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4278 spin4 = return_spin(":4") 4279 spin70 = return_spin(":70") 4280 spin71 = return_spin(":71") 4281 print("\n\nOptimised parameters:\n") 4282 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4283 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4284 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4285 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4286 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4287 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4288 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4289 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4290 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4291 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4292 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4293 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4294 4295 # The 'CR72' model checks. 4296 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4297 spin4 = return_spin(":4") 4298 spin70 = return_spin(":70") 4299 spin71 = return_spin(":71") 4300 print("\n\nOptimised parameters:\n") 4301 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4302 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4303 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4304 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4305 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4306 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4307 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4308 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4309 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4310 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4311 self.assertAlmostEqual(spin4.dw, 0.0, 2) 4312 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4313 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4314 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4315 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4316 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4317 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4318 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4319 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4320 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4321 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4322 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2) 4323 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4324 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4325 4326
4328 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4329 4330 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4331 """ 4332 4333 # Base data setup. 4334 self.setup_hansen_cpmg_data(model='CR72') 4335 4336 # Alias the spins. 4337 spin70 = return_spin(":70") 4338 spin71 = return_spin(":71") 4339 4340 # The R20 keys. 4341 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4342 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4343 4344 # Set the initial parameter values. 4345 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4346 spin70.pA = 0.9 4347 spin70.dw = 6.0 4348 spin70.kex = 1500.0 4349 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4350 spin71.pA = 0.9 4351 spin71.dw = 4.0 4352 spin71.kex = 1900.0 4353 4354 # Low precision optimisation. 4355 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4356 4357 # Printout. 4358 print("\n\nOptimised parameters:\n") 4359 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4360 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4361 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4362 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4363 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4364 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4365 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4366 4367 # Checks for residue :70. 4368 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4369 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4370 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4371 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4372 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4373 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4374 4375 # Checks for residue :71. 4376 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4377 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4378 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4379 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4380 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4381 4382 # Test the conversion to k_AB from kex and pA. 4383 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4384 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4385 4386 # Test the conversion to k_BA from kex and pA. 4387 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4388 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4389 4390
4392 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4393 4394 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4395 """ 4396 4397 # Base data setup. 4398 self.setup_hansen_cpmg_data(model='CR72 full') 4399 4400 # Alias the spins. 4401 spin70 = return_spin(":70") 4402 spin71 = return_spin(":71") 4403 4404 # The R20 keys. 4405 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4406 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4407 4408 # Set the initial parameter values. 4409 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4410 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4411 spin70.pA = 0.9 4412 spin70.dw = 6.0 4413 spin70.kex = 1500.0 4414 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4415 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4416 spin71.pA = 0.9 4417 spin71.dw = 4.0 4418 spin71.kex = 1900.0 4419 4420 # Low precision optimisation. 4421 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4422 4423 # Printout. 4424 print("\n\nOptimised parameters:\n") 4425 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4426 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4427 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4428 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4429 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4430 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4431 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4432 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4433 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4434 4435 # Checks for residue :70. 4436 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4437 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4438 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4439 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4440 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4441 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4442 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4443 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4444 4445 # Checks for residue :71. 4446 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4447 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4448 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4449 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4450 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4451 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4452 4453 # Test the conversion to k_AB from kex and pA. 4454 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4455 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4456 4457 # Test the conversion to k_BA from kex and pA. 4458 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4459 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4460 4461
4463 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4464 4465 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4466 """ 4467 4468 # Base data setup. 4469 self.setup_hansen_cpmg_data(model='IT99') 4470 4471 # Alias the spins. 4472 spin70 = return_spin(":70") 4473 spin71 = return_spin(":71") 4474 4475 # The R20 keys. 4476 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4477 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4478 4479 # Set the initial parameter values. 4480 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4481 spin70.dw = 10.0 4482 spin70.pA = 0.5 4483 spin70.tex = 1000.09 4484 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4485 spin71.dw = 10.0 4486 spin71.pA = 0.95 4487 spin71.tex = 0.1 4488 4489 # Low precision optimisation. 4490 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4491 4492 # Printout. 4493 print("\n\nOptimised parameters:\n") 4494 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4495 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4496 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4497 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4498 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4499 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4500 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4501 4502 # Checks for residue :70. 4503 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4504 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4505 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4506 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4507 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4508 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4509 4510 # Checks for residue :71. 4511 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4512 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4513 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4514 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4515 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4516 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4517 4518
4520 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4521 4522 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4523 """ 4524 4525 # Base data setup. 4526 self.setup_hansen_cpmg_data(model='LM63') 4527 4528 # Alias the spins. 4529 spin70 = return_spin(":70") 4530 spin71 = return_spin(":71") 4531 4532 # The R20 keys. 4533 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4534 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4535 4536 # Set the initial parameter values. 4537 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4538 spin70.phi_ex = 0.3 4539 spin70.kex = 5000.0 4540 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4541 spin71.phi_ex = 0.1 4542 spin71.kex = 2500.0 4543 4544 # Low precision optimisation. 4545 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4546 4547 # Printout. 4548 print("\n\nOptimised parameters:\n") 4549 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4550 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4551 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4552 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4553 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4554 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4555 4556 # Checks for residue :70. 4557 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4558 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4559 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4560 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4561 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4562 4563 # Checks for residue :71. 4564 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4565 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4566 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4567 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4568 4569
4571 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4572 4573 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4574 """ 4575 4576 # Base data setup. 4577 self.setup_hansen_cpmg_data(model='LM63 3-site') 4578 4579 # Alias the spins. 4580 spin70 = return_spin(":70") 4581 spin71 = return_spin(":71") 4582 4583 # The R20 keys. 4584 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4585 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4586 4587 ## Set the initial parameter values. 4588 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4589 spin70.phi_ex_B = 0.14872003058250227 4590 spin70.phi_ex_C = 0.1319419923472704 4591 spin70.kB = 4103.672910444741 4592 spin70.kC = 7029.001690726248 4593 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4594 spin71.phi_ex_B = 0.04013553485505605 4595 spin71.phi_ex_C = 0.020050748406928887 4596 spin71.kB = 4045.3007136121364 4597 spin71.kC = 3586.38798270774 4598 4599 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4600 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4601 4602 # Low precision optimisation. 4603 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4604 4605 # Printout. 4606 print("\n\nOptimised parameters:\n") 4607 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4608 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4609 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4610 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4611 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4612 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4613 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4614 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4615 4616 # Checks for residue :70. 4617 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4618 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4619 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4620 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4621 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4622 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4623 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4624 4625 # Checks for residue :71. 4626 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4627 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4628 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4629 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4630 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4631 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4632 4633
4635 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4636 4637 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4638 """ 4639 4640 # Base data setup. 4641 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4642 4643 # Alias the spins. 4644 spin70 = return_spin(":70") 4645 spin71 = return_spin(":71") 4646 4647 # The R20 keys. 4648 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4649 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4650 4651 # Set the initial parameter values. 4652 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4653 spin70.pA = 0.9897754407 4654 spin70.dw = 5.642418428 4655 spin70.kex = 1743.666375 4656 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4657 spin71.pA = 0.9968032899 4658 spin71.dw = 4.577891393 4659 spin71.kex = 1830.044597 4660 4661 # Low precision optimisation. 4662 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4663 4664 # Printout. 4665 print("\n\nOptimised parameters:\n") 4666 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4667 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4668 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4669 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4670 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4671 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4672 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4673 4674 # Checks for residue :70. 4675 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4676 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4677 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4678 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4679 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4680 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4681 4682 # Checks for residue :71. 4683 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4684 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4685 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4686 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4687 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4688 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4689 4690 # Test the conversion to k_AB from kex and pA. 4691 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4692 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4693 4694 # Test the conversion to k_BA from kex and pA. 4695 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4696 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4697 4698
4700 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4701 4702 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4703 """ 4704 4705 # Base data setup. 4706 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4707 4708 # Alias the spins. 4709 spin70 = return_spin(":70") 4710 spin71 = return_spin(":71") 4711 4712 # The R20 keys. 4713 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4714 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4715 4716 # Set the initial parameter values. 4717 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4718 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4719 spin70.pA = 0.9884781357 4720 spin70.dw = 5.456507396 4721 spin70.kex = 1906.521189 4722 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4723 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4724 spin71.pA = 0.986709616684097 4725 spin71.dw = 2.09245158280905 4726 spin71.kex = 2438.2766211401 4727 4728 # Low precision optimisation. 4729 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4730 4731 # Printout. 4732 print("\n\nOptimised parameters:\n") 4733 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4734 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4735 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4736 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4737 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4738 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4739 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4740 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4741 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4742 4743 # Checks for residue :70. 4744 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4745 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4746 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4747 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4748 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4749 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4750 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4751 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4752 4753 # Checks for residue :71. 4754 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4755 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4756 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4757 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4758 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4759 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4760 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4761 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4762 4763 # Test the conversion to k_AB from kex and pA. 4764 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4765 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4766 4767 # Test the conversion to k_BA from kex and pA. 4768 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4769 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4770 4771
4773 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4774 4775 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4776 """ 4777 4778 # Base data setup. 4779 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4780 4781 # Alias the spins. 4782 spin70 = return_spin(":70") 4783 spin71 = return_spin(":71") 4784 4785 # The R20 keys. 4786 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4787 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4788 4789 # Set the initial parameter values. 4790 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4791 spin70.pA = 0.9 4792 spin70.dw = 6.0 4793 spin70.kex = 1500.0 4794 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4795 spin71.pA = 0.9 4796 spin71.dw = 4.0 4797 spin71.kex = 1900.0 4798 4799 # Low precision optimisation. 4800 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4801 4802 # Printout. 4803 print("\n\nOptimised parameters:\n") 4804 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4805 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4806 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4807 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4808 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4809 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4810 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4811 4812 # Checks for residue :70. 4813 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4814 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4815 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4816 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4817 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4818 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4819 4820 # Checks for residue :71. 4821 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4822 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4823 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4824 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4825 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4826 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4827 4828 # Test the conversion to k_AB from kex and pA. 4829 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4830 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4831 4832 # Test the conversion to k_BA from kex and pA. 4833 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4834 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4835 4836
4838 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4839 4840 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4841 """ 4842 4843 # Base data setup. 4844 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4845 4846 # Alias the spins. 4847 spin70 = return_spin(":70") 4848 spin71 = return_spin(":71") 4849 4850 # The R20 keys. 4851 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4852 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4853 4854 # Set the initial parameter values. 4855 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4856 spin70.pA = 0.9897519798 4857 spin70.dw = 5.644862195 4858 spin70.kex = 1723.820567 4859 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4860 spin71.pA = 0.9968032899 4861 spin71.dw = 4.577891393 4862 spin71.kex = 1830.044597 4863 4864 # Low precision optimisation. 4865 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4866 4867 # Printout. 4868 print("\n\nOptimised parameters:\n") 4869 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4870 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4871 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4872 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4873 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4874 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4875 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4876 4877 # Checks for residue :70. 4878 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4879 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4880 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4881 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4882 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4883 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4884 4885 # Checks for residue :71. 4886 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4887 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4888 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4889 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4890 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4891 4892 # Test the conversion to k_AB from kex and pA. 4893 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4894 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4895 4896 # Test the conversion to k_BA from kex and pA. 4897 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4898 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4899 4900
4902 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4903 4904 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4905 """ 4906 4907 # Base data setup. 4908 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4909 4910 # Alias the spins. 4911 spin70 = return_spin(":70") 4912 spin71 = return_spin(":71") 4913 4914 # The R20 keys. 4915 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4916 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4917 4918 # Set the initial parameter values. 4919 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4920 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4921 spin70.pA = 0.987648082613451 4922 spin70.dw = 5.30679853807572 4923 spin70.kex = 2033.25380420666 4924 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4925 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4926 spin71.pA = 0.992258541625787 4927 spin71.dw = 2.75140650899058 4928 spin71.kex = 2106.60885247431 4929 4930 # Low precision optimisation. 4931 self.interpreter.minimise.calculate() 4932 4933 # Checks for residue :70. 4934 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4935 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4936 4937
4938 - def test_hansen_cpmgfit_input(self):
4939 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4940 4941 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4942 """ 4943 4944 # Load the R2eff results file. 4945 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4946 self.interpreter.results.read(file_name) 4947 self.interpreter.deselect.spin(':4') 4948 4949 # Set up the model. 4950 self.interpreter.relax_disp.select_model('LM63') 4951 4952 # Generate the input files. 4953 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4954 4955 # What the files should contain. 4956 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4957 spin1 = [ 4958 "title :70@N\n", 4959 "fields 2 11.7432964915 18.7892743865\n", 4960 "function CPMG\n", 4961 "R2 1 10 20\n", 4962 "Rex 0 100.0 100\n", 4963 "Tau 0 10.0 100\n", 4964 "xmgr\n", 4965 "@ xaxis label \"1/tcp (1/ms)\"\n", 4966 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4967 "@ xaxis ticklabel format decimal\n", 4968 "@ yaxis ticklabel format decimal\n", 4969 "@ xaxis ticklabel char size 0.8\n", 4970 "@ yaxis ticklabel char size 0.8\n", 4971 "@ world xmin 0.0\n", 4972 "data\n", 4973 "0.133333 16.045541 0.310925 11.743296 \n", 4974 "0.266667 14.877925 0.303217 11.743296 \n", 4975 "0.400000 14.357820 0.299894 11.743296 \n", 4976 "0.533333 12.664495 0.289532 11.743296 \n", 4977 "0.666667 12.363205 0.287760 11.743296 \n", 4978 "0.800000 11.092532 0.280514 11.743296 \n", 4979 "0.933333 10.566090 0.277619 11.743296 \n", 4980 "1.066667 9.805807 0.273544 11.743296 \n", 4981 "1.200000 9.564301 0.272276 11.743296 \n", 4982 "1.333333 9.015634 0.269442 11.743296 \n", 4983 "1.466667 8.607765 0.267375 11.743296 \n", 4984 "1.600000 8.279997 0.265740 11.743296 \n", 4985 "1.733333 8.474536 0.266708 11.743296 \n", 4986 "1.866667 8.158973 0.265141 11.743296 \n", 4987 "2.000000 7.988631 0.264304 11.743296 \n", 4988 "0.133333 22.224914 0.166231 18.789274 \n", 4989 "0.266667 21.230874 0.162377 18.789274 \n", 4990 "0.400000 20.603704 0.160017 18.789274 \n", 4991 "0.533333 20.327797 0.158996 18.789274 \n", 4992 "0.666667 18.855377 0.153719 18.789274 \n", 4993 "0.800000 18.537531 0.152617 18.789274 \n", 4994 "0.933333 17.508069 0.149138 18.789274 \n", 4995 "1.066667 16.035604 0.144391 18.789274 \n", 4996 "1.200000 15.168192 0.141717 18.789274 \n", 4997 "1.333333 14.431802 0.139516 18.789274 \n", 4998 "1.466667 14.034137 0.138354 18.789274 \n", 4999 "1.600000 12.920148 0.135192 18.789274 \n", 5000 "1.733333 12.653673 0.134456 18.789274 \n", 5001 "1.866667 12.610864 0.134338 18.789274 \n", 5002 "2.000000 11.969303 0.132601 18.789274 \n" 5003 ] 5004 spin2 = [ 5005 "title :71@N\n", 5006 "fields 2 11.7432964915 18.7892743865\n", 5007 "function CPMG\n", 5008 "R2 1 10 20\n", 5009 "Rex 0 100.0 100\n", 5010 "Tau 0 10.0 100\n", 5011 "xmgr\n", 5012 "@ xaxis label \"1/tcp (1/ms)\"\n", 5013 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 5014 "@ xaxis ticklabel format decimal\n", 5015 "@ yaxis ticklabel format decimal\n", 5016 "@ xaxis ticklabel char size 0.8\n", 5017 "@ yaxis ticklabel char size 0.8\n", 5018 "@ world xmin 0.0\n", 5019 "data\n", 5020 "0.133333 7.044342 0.170035 11.743296 \n", 5021 "0.266667 6.781033 0.169228 11.743296 \n", 5022 "0.400000 6.467623 0.168279 11.743296 \n", 5023 "0.533333 6.333340 0.167876 11.743296 \n", 5024 "0.666667 6.323238 0.167846 11.743296 \n", 5025 "0.800000 6.005245 0.166902 11.743296 \n", 5026 "0.933333 5.767052 0.166203 11.743296 \n", 5027 "1.066667 5.476968 0.165361 11.743296 \n", 5028 "1.200000 5.469949 0.165341 11.743296 \n", 5029 "1.333333 5.295113 0.164838 11.743296 \n", 5030 "1.466667 5.435648 0.165242 11.743296 \n", 5031 "1.600000 5.410400 0.165169 11.743296 \n", 5032 "1.733333 5.437554 0.165247 11.743296 \n", 5033 "1.866667 5.176844 0.164501 11.743296 \n", 5034 "2.000000 5.227232 0.164644 11.743296 \n", 5035 "0.133333 11.530903 0.081928 18.789274 \n", 5036 "0.266667 10.983094 0.081041 18.789274 \n", 5037 "0.400000 10.512403 0.080294 18.789274 \n", 5038 "0.533333 9.984805 0.079473 18.789274 \n", 5039 "0.666667 9.573163 0.078845 18.789274 \n", 5040 "0.800000 9.178810 0.078253 18.789274 \n", 5041 "0.933333 8.935719 0.077893 18.789274 \n", 5042 "1.066667 8.610147 0.077416 18.789274 \n", 5043 "1.200000 8.353778 0.077045 18.789274 \n", 5044 "1.333333 8.173729 0.076787 18.789274 \n", 5045 "1.466667 8.091607 0.076670 18.789274 \n", 5046 "1.600000 7.706420 0.076126 18.789274 \n", 5047 "1.733333 7.709125 0.076129 18.789274 \n", 5048 "1.866667 7.610856 0.075992 18.789274 \n", 5049 "2.000000 7.552584 0.075911 18.789274 \n", 5050 ] 5051 5052 # Check the batch file. 5053 print("\nChecking the batch file.") 5054 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 5055 lines = file.readlines() 5056 file.close() 5057 for i in range(len(lines)): 5058 self.assertEqual(batch_file[i], lines[i]) 5059 5060 # Check spin :70@N. 5061 print("\nChecking the spin :70@N input file.") 5062 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 5063 lines = file.readlines() 5064 file.close() 5065 for i in range(len(spin1)): 5066 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5067 for i in range(len(lines)): 5068 self.assertEqual(spin1[i], lines[i]) 5069 5070 # Check spin :71@N. 5071 print("\nChecking the spin :71@N input file.") 5072 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 5073 lines = file.readlines() 5074 file.close() 5075 for i in range(len(lines)): 5076 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5077 for i in range(len(spin2)): 5078 self.assertEqual(spin2[i], lines[i])
5079 5080
5082 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 5083 5084 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5085 5086 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 5087 5088 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 5089 - pA = 0.965402506690231, 5090 - dw = 0.805197170133360, 5091 - dwH = -0.595536627771890, 5092 - kex = 569.003663067619868, 5093 - chi2 = 9.297671357952812. 5094 """ 5095 5096 # Base data setup. 5097 self.setup_korzhnev_2005_data(data_list=['DQ']) 5098 5099 # Alias the spin. 5100 spin = return_spin(":9@N") 5101 5102 # The R20 keys. 5103 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5104 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5105 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5106 5107 # Set the initial parameter values. 5108 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 5109 spin.pA = 0.965638501551899 5110 spin.dw = 2.8537583461577 5111 spin.dwH = -0.387633062766635 5112 spin.kex = 573.704033851592 5113 5114 # Low precision optimisation. 5115 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5116 5117 # Monte Carlo simulations. 5118 self.interpreter.monte_carlo.setup(number=3) 5119 self.interpreter.monte_carlo.create_data(method='back_calc') 5120 self.interpreter.monte_carlo.initial_values() 5121 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5122 self.interpreter.monte_carlo.error_analysis() 5123 5124 # Plot the dispersion curves. 5125 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5126 5127 # Save the results. 5128 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5129 5130 # Printout. 5131 print("\n\nOptimised parameters:\n") 5132 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5133 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5134 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5135 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5136 print("%-20s %20.15g" % ("pA", spin.pA)) 5137 print("%-20s %20.15g" % ("dw", spin.dw)) 5138 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5139 print("%-20s %20.15g" % ("kex", spin.kex)) 5140 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5141 5142 # Checks for residue :9. 5143 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 5144 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 5145 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 5146 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 5147 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 5148 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 5149 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 5150 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5151 5152
5154 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 5155 5156 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5157 5158 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 5159 5160 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 5161 - pA = 0.930027999814003, 5162 - dw = 4.338620619954370, 5163 - dwH = -0.274250775560818, 5164 - kex = 344.613362916544475, 5165 - chi2 = 10.367733168217050. 5166 """ 5167 5168 # Base data setup. 5169 self.setup_korzhnev_2005_data(data_list=['MQ']) 5170 5171 # Alias the spin. 5172 spin = return_spin(":9@N") 5173 5174 # The R20 keys. 5175 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5176 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5177 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5178 5179 # Set the initial parameter values. 5180 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 5181 spin.pA = 0.930083249288083 5182 spin.dw = 4.33890689462363 5183 spin.dwH = -0.274316585638047 5184 spin.kex = 344.329651956132 5185 5186 # Low precision optimisation. 5187 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5188 5189 # Monte Carlo simulations. 5190 self.interpreter.monte_carlo.setup(number=3) 5191 self.interpreter.monte_carlo.create_data(method='back_calc') 5192 self.interpreter.monte_carlo.initial_values() 5193 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5194 self.interpreter.monte_carlo.error_analysis() 5195 5196 # Plot the dispersion curves. 5197 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5198 5199 # Save the results. 5200 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5201 5202 # Printout. 5203 print("\n\nOptimised parameters:\n") 5204 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5205 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5206 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5207 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5208 print("%-20s %20.15g" % ("pA", spin.pA)) 5209 print("%-20s %20.15g" % ("dw", spin.dw)) 5210 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5211 print("%-20s %20.15g" % ("kex", spin.kex)) 5212 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5213 5214 # Checks for residue :9. 5215 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 5216 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 5217 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 5218 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 5219 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 5220 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 5221 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 5222 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5223 5224
5226 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 5227 5228 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5229 5230 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 5231 5232 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 5233 - pA = 0.950003458294991, 5234 - dw = 4.358402855315123, 5235 - kex = 429.906473361926999, 5236 - chi2 = 17.393331915567252. 5237 """ 5238 5239 # Base data setup. 5240 self.setup_korzhnev_2005_data(data_list=['SQ']) 5241 5242 # Alias the spin. 5243 spin = return_spin(":9@N") 5244 5245 # The R20 keys. 5246 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5247 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5248 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5249 5250 # Set the initial parameter values. 5251 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 5252 spin.pA = 0.950310172115387 5253 spin.dw = 4.356737157889636 5254 spin.kex = 433.176323890829849 5255 5256 # Low precision optimisation. 5257 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5258 5259 # Monte Carlo simulations. 5260 self.interpreter.monte_carlo.setup(number=3) 5261 self.interpreter.monte_carlo.create_data(method='back_calc') 5262 self.interpreter.monte_carlo.initial_values() 5263 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5264 self.interpreter.monte_carlo.error_analysis() 5265 5266 # Plot the dispersion curves. 5267 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5268 5269 # Save the results. 5270 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5271 5272 # Printout. 5273 print("\n\nOptimised parameters:\n") 5274 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5275 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5276 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5277 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5278 print("%-20s %20.15g" % ("pA", spin.pA)) 5279 print("%-20s %20.15g" % ("dw", spin.dw)) 5280 print("%-20s %20.15g" % ("kex", spin.kex)) 5281 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5282 5283 # Checks for residue :9. 5284 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5285 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5286 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5287 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5288 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5289 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5290 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5291 5292
5294 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5295 5296 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5297 5298 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5299 5300 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5301 - pA = 0.942452612380140, 5302 - dw = 0.858972784230892, 5303 - dwH = 0.087155962730608, 5304 - kex = 373.219151384798920, 5305 - chi2 = 23.863208106025152. 5306 """ 5307 5308 # Base data setup. 5309 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5310 5311 # Alias the spin. 5312 spin = return_spin(":9@N") 5313 5314 # The R20 keys. 5315 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5316 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5317 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5318 5319 # Set the initial parameter values. 5320 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5321 spin.pA = 0.942457332074014 5322 spin.dw = 0.850592422908884 5323 spin.dwH = 0.0881272284455416 5324 spin.kex = 372.745483351305 5325 5326 # Low precision optimisation. 5327 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5328 5329 # Monte Carlo simulations. 5330 self.interpreter.monte_carlo.setup(number=3) 5331 self.interpreter.monte_carlo.create_data(method='back_calc') 5332 self.interpreter.monte_carlo.initial_values() 5333 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5334 self.interpreter.monte_carlo.error_analysis() 5335 5336 # Plot the dispersion curves. 5337 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5338 5339 # Save the results. 5340 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5341 5342 # Printout. 5343 print("\n\nOptimised parameters:\n") 5344 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5345 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5346 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5347 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5348 print("%-20s %20.15g" % ("pA", spin.pA)) 5349 print("%-20s %20.15g" % ("dw", spin.dw)) 5350 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5351 print("%-20s %20.15g" % ("kex", spin.kex)) 5352 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5353 5354 # Checks for residue :9. 5355 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5356 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5357 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5358 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5359 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5360 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5361 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5362 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5363 5364
5366 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5367 5368 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5369 5370 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5371 5372 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5373 - pA = 0.936911090448340, 5374 - dw = 4.325314846914845, 5375 - dwH = -0.213870168665628, 5376 - kex = 487.361914835074117, 5377 - chi2 = 14.870371897291138. 5378 """ 5379 5380 # Base data setup. 5381 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5382 5383 # Alias the spin. 5384 spin = return_spin(":9@N") 5385 5386 # The R20 keys. 5387 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5388 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5389 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5390 5391 # Set the initial parameter values. 5392 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5393 spin.pA = 0.936884348941701 5394 spin.dw = 4.326454531583964 5395 spin.dwH = -0.214026093221782 5396 spin.kex = 487.043592705469223 5397 5398 # Low precision optimisation. 5399 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5400 5401 # Monte Carlo simulations. 5402 self.interpreter.monte_carlo.setup(number=3) 5403 self.interpreter.monte_carlo.create_data(method='back_calc') 5404 self.interpreter.monte_carlo.initial_values() 5405 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5406 self.interpreter.monte_carlo.error_analysis() 5407 5408 # Plot the dispersion curves. 5409 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5410 5411 # Save the results. 5412 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5413 5414 # Printout. 5415 print("\n\nOptimised parameters:\n") 5416 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5417 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5418 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5419 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5420 print("%-20s %20.15g" % ("pA", spin.pA)) 5421 print("%-20s %20.15g" % ("dw", spin.dw)) 5422 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5423 print("%-20s %20.15g" % ("kex", spin.kex)) 5424 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5425 5426 # Checks for residue :9. 5427 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5428 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5429 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5430 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5431 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5432 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5433 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5434 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5435 5436
5438 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5439 5440 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5441 5442 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5443 5444 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5445 - pA = 0.946949480545876, 5446 - dwH = -0.265279672133308, 5447 - kex = 406.548178869750700, 5448 - chi2 = 50.400680290545026. 5449 """ 5450 5451 # Base data setup. 5452 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5453 5454 # Alias the spin. 5455 spin = return_spin(":9@N") 5456 5457 # The R20 keys. 5458 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5459 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5460 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5461 5462 # Set the initial parameter values. 5463 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5464 spin.pA = 0.946990967372467 5465 spin.dwH = -0.265308128403529 5466 spin.kex = 406.843250675648 5467 5468 # Low precision optimisation. 5469 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5470 5471 # Monte Carlo simulations. 5472 self.interpreter.monte_carlo.setup(number=3) 5473 self.interpreter.monte_carlo.create_data(method='back_calc') 5474 self.interpreter.monte_carlo.initial_values() 5475 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5476 self.interpreter.monte_carlo.error_analysis() 5477 5478 # Plot the dispersion curves. 5479 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5480 5481 # Save the results. 5482 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5483 5484 # Printout. 5485 print("\n\nOptimised parameters:\n") 5486 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5487 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5488 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5489 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5490 print("%-20s %20.15g" % ("pA", spin.pA)) 5491 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5492 print("%-20s %20.15g" % ("kex", spin.kex)) 5493 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5494 5495 # Checks for residue :9. 5496 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5497 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5498 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5499 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5500 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5501 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5502 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5503 5504
5506 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5507 5508 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5509 5510 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5511 5512 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5513 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5514 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5515 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5516 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5517 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5518 - pA = 0.943125351763911, 5519 - dw = 4.421827493809807, 5520 - dwH = -0.272637034755752, 5521 - kex = 360.609744568697238, 5522 - chi2 = 162.589570340050813. 5523 """ 5524 5525 # Base data setup. 5526 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5527 5528 # Alias the spin. 5529 spin = return_spin(":9@N") 5530 5531 # The R20 keys. 5532 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5533 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5534 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5535 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5536 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5537 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5538 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5539 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5540 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5541 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5542 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5543 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5544 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5545 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5546 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5547 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5548 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5549 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5550 5551 # Set the initial parameter values. 5552 spin.r2 = { 5553 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5554 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5555 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5556 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5557 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5558 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5559 } 5560 spin.pA = 0.943129019477673 5561 spin.dw = 4.42209952545181 5562 spin.dwH = -0.27258970590969 5563 spin.kex = 360.516132791038 5564 5565 # Low precision optimisation. 5566 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5567 5568 # Monte Carlo simulations. 5569 self.interpreter.monte_carlo.setup(number=3) 5570 self.interpreter.monte_carlo.create_data(method='back_calc') 5571 self.interpreter.monte_carlo.initial_values() 5572 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5573 self.interpreter.monte_carlo.error_analysis() 5574 5575 # Plot the dispersion curves. 5576 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5577 5578 # Save the results. 5579 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5580 5581 # Printout. 5582 print("\n\nOptimised parameters:\n") 5583 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5584 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5585 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5586 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5587 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5588 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5589 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5590 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5591 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5592 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5593 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5594 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5595 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5596 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5597 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5598 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5599 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5600 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5601 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5602 print("%-20s %20.15g" % ("pA", spin.pA)) 5603 print("%-20s %20.15g" % ("dw", spin.dw)) 5604 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5605 print("%-20s %20.15g" % ("kex", spin.kex)) 5606 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5607 5608 # Checks for residue :9. 5609 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5610 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5611 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5612 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5613 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5614 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5615 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5616 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5617 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5618 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5619 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5620 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5621 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5622 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5623 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5624 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5625 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5626 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5627 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5628 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5629 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5630 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5631 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5632 5633
5635 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5636 5637 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5638 5639 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5640 5641 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5642 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5643 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5644 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5645 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5646 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5647 - pA = 0.943125351763911, 5648 - dw = 4.421827493809807, 5649 - dwH = -0.272637034755752, 5650 - kex = 360.609744568697238, 5651 - chi2 = 162.589570340050813. 5652 """ 5653 5654 # Base data setup. 5655 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5656 5657 # Alias the spin. 5658 spin = return_spin(":9@N") 5659 5660 # The R20 keys. 5661 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5662 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5663 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5664 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5665 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5666 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5667 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5668 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5669 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5670 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5671 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5672 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5673 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5674 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5675 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5676 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5677 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5678 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5679 5680 # Set the initial parameter values. 5681 spin.r2 = { 5682 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5683 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5684 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5685 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5686 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5687 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5688 } 5689 spin.pA = 0.943129019477673 5690 spin.dw = 4.42209952545181 5691 spin.dwH = -0.27258970590969 5692 spin.kex = 360.516132791038 5693 5694 # Calc the chi2 values at these parameters. 5695 self.interpreter.minimise.calculate(verbosity=1) 5696 5697 # Printout. 5698 print("\n\nOptimised parameters:\n") 5699 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5700 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5701 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5702 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5703 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5704 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5705 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5706 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5707 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5708 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5709 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5710 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5711 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5712 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5713 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5714 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5715 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5716 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5717 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5718 print("%-20s %20.15g" % ("pA", spin.pA)) 5719 print("%-20s %20.15g" % ("dw", spin.dw)) 5720 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5721 print("%-20s %20.15g" % ("kex", spin.kex)) 5722 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5723 5724 # Checks for residue :9. 5725 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5726 5727
5729 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5730 5731 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5732 5733 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5734 5735 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5736 - 0.483 0.89623903 2.4503699912708878 5737 - 0.545 1.1694838 5738 - 0.545 1.1761503 5739 - 0.622 1.294 5740 - 0.669 1.5176493 5741 - 0.722 1.6238791 5742 - 0.813 1.9395758 5743 - 1.011 2.3558415 10.547000429321157 5744 """ 5745 5746 # Base data setup. 5747 model = 'TSMFK01' 5748 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5749 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5750 5751 # Alias the spins. 5752 res61L = cdp.mol[0].res[0].spin[0] 5753 5754 # The R20 keys. 5755 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5756 5757 # Set the initial parameter values. 5758 res61L.r2a = {r20_key1: 8.0} 5759 res61L.dw = 6.5 5760 res61L.k_AB = 2.5 5761 5762 # Low precision optimisation. 5763 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5764 5765 # Start testing all possible combinations of graphs. 5766 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5767 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5768 interpolate_types = [INTERPOLATE_DISP] 5769 5770 # Write to temp folder. 5771 result_dir_name = ds.tmpdir 5772 result_folders = [model] 5773 spin_id = ":61@N" 5774 5775 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5776 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5777 5778 for result_folder in result_folders: 5779 for y_axis in y_axis_types: 5780 for x_axis in x_axis_types: 5781 for interpolate in interpolate_types: 5782 # Determine file name: 5783 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5784 5785 # Make the file name. 5786 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5787 5788 # Write the curves. 5789 dir = result_dir_name+sep+result_folder 5790 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5791 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5792 5793 # Get the file path. 5794 file_path = get_file_path(file_name, dir) 5795 5796 # Test the plot file exists. 5797 print("Testing file access to graph: %s"%file_path) 5798 self.assert_(access(file_path, F_OK)) 5799 5800 # Now open, and compare content, line by line. 5801 file_prod = open(file_path) 5802 lines_prod = file_prod.readlines() 5803 file_prod.close() 5804 5805 # Define file to compare against. 5806 dir_comp = data_path+sep+result_folder 5807 file_path_comp = get_file_path(file_name, dir_comp) 5808 file_comp = open(file_path_comp) 5809 lines_comp = file_comp.readlines() 5810 file_comp.close() 5811 5812 ## Assert number of lines is equal. 5813 self.assertEqual(len(lines_prod), len(lines_comp)) 5814 for j in range(len(lines_prod)): 5815 # Make the string test 5816 first_char = lines_prod[j][0] 5817 if first_char in ["@", "&"]: 5818 self.assertEqual(lines_prod[j], lines_comp[j]) 5819 else: 5820 # Split string in x, y, error. 5821 # The error would change per run. 5822 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5823 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5824 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5825 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5826 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5827 5828
5830 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5831 5832 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5833 """ 5834 5835 # Base data setup. 5836 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5837 5838 # Alias the spins. 5839 res61L = cdp.mol[0].res[0].spin[0] 5840 5841 # The R20 keys. 5842 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5843 5844 # Set the initial parameter values. 5845 res61L.r2 = {r20_key1: 8.0} 5846 res61L.pA = 0.9 5847 res61L.dw = 6.0 5848 res61L.kex = 600.0 5849 5850 # Low precision optimisation. 5851 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5852 5853 # Printout. 5854 print("\n\nOptimised parameters:\n") 5855 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5856 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5857 print("%-20s %20.15g" % ("pA", res61L.pA)) 5858 print("%-20s %20.15g" % ("dw", res61L.dw)) 5859 print("%-20s %20.15g" % ("kex", res61L.kex)) 5860 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5861 5862 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5863 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5864 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5865 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5866 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5867 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5868 5869 # Test the conversion to k_AB from kex and pA. 5870 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5871 5872 # Test the conversion to k_BA from kex and pA. 5873 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5874 5875
5877 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5878 5879 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5880 """ 5881 5882 # Base data setup. 5883 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5884 5885 # Alias the spins. 5886 res61L = cdp.mol[0].res[0].spin[0] 5887 5888 # The R20 keys. 5889 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5890 5891 # Set the initial parameter values. 5892 res61L.r2a = {r20_key1: 8.0} 5893 res61L.r2b = {r20_key1: 105.0} 5894 res61L.pA = 0.9 5895 res61L.dw = 6.0 5896 res61L.kex = 500.0 5897 5898 # Low precision optimisation. 5899 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5900 5901 # Printout. 5902 print("\n\nOptimised parameters:\n") 5903 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5904 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5905 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5906 print("%-20s %20.15g" % ("pA", res61L.pA)) 5907 print("%-20s %20.15g" % ("dw", res61L.dw)) 5908 print("%-20s %20.15g" % ("kex", res61L.kex)) 5909 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5910 5911 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5912 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5913 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5914 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5915 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5916 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5917 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5918 5919
5921 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5922 5923 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5924 5925 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5926 5927 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5928 - 0.483 0.89623903 2.4503699912708878 5929 - 0.545 1.1694838 5930 - 0.545 1.1761503 5931 - 0.622 1.294 5932 - 0.669 1.5176493 5933 - 0.722 1.6238791 5934 - 0.813 1.9395758 5935 - 1.011 2.3558415 10.547000429321157 5936 """ 5937 5938 # Base data setup. 5939 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5940 5941 # Alias the spins. 5942 res61L = cdp.mol[0].res[0].spin[0] 5943 5944 # The R20 keys. 5945 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5946 5947 # Set the initial parameter values. 5948 res61L.r2a = {r20_key1: 8.0} 5949 res61L.dw = 6.5 5950 res61L.k_AB = 2.5 5951 5952 # Low precision optimisation. 5953 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5954 5955 # Printout. 5956 print("\n\nOptimised parameters:\n") 5957 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5958 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5959 print("%-20s %20.15g" % ("dw", res61L.dw)) 5960 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5961 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5962 5963 # Checks for residue :61. Reference values from paper 5964 5965 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5966 5967
5969 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5970 5971 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5972 5973 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5974 5975 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5976 5977 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5978 - k_AB = 11.3 +/- 0.7 s^-1, 5979 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5980 - R2 = 8.0 +/- 0.5 s^-1. 5981 5982 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5983 - k_AB = 10.55 +/- 0.08 s^-1, 5984 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5985 - R2 = 8.4 +/- 0.3 s^-1. 5986 5987 Conversion of paper results to relax results is performed by: 5988 5989 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5990 5991 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5992 5993 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5994 - 0.483 0.89623903 2.4503699912708878 5995 - 0.545 1.1694838 5996 - 0.545 1.1761503 5997 - 0.622 1.294 5998 - 0.669 1.5176493 5999 - 0.722 1.6238791 6000 - 0.813 1.9395758 6001 - 1.011 2.3558415 10.547000429321157 6002 """ 6003 6004 # Base data setup. 6005 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 6006 6007 # Alias the spins. 6008 res61L = cdp.mol[0].res[0].spin[0] 6009 6010 # The R20 keys. 6011 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 6012 6013 # Set the initial parameter values. 6014 res61L.r2a = {r20_key1: 8.0} 6015 res61L.dw = 6.5 6016 res61L.k_AB = 11.0 6017 6018 # Low precision optimisation. 6019 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 6020 6021 # Printout. 6022 print("\n\nOptimised parameters:\n") 6023 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 6024 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 6025 print("%-20s %20.15g" % ("dw", res61L.dw)) 6026 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 6027 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 6028 6029 # Checks for residue :61. Reference values from paper 6030 6031 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 6032 self.assertAlmostEqual(res61L.dw, 6.41, 0) 6033 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
6034 6035
6036 - def test_lm63_3site_synthetic(self):
6037 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 6038 6039 # The path to the data files. 6040 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 6041 6042 # Load the state file. 6043 self.interpreter.reset() 6044 self.interpreter.state.load(data_path+sep+'r2eff_values') 6045 6046 # A new data pipe. 6047 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 6048 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 6049 6050 # Set up the model data. 6051 self.interpreter.relax_disp.select_model(model='LM63 3-site') 6052 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 6053 self.interpreter.spin.isotope('15N') 6054 6055 # Alias the spins. 6056 spin1 = return_spin(":1") 6057 spin2 = return_spin(":2") 6058 6059 # The R20 keys. 6060 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 6061 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 6062 6063 # Manually set the parameter values. 6064 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 6065 spin1.phi_ex_B = 0.1 6066 spin1.phi_ex_C = 0.5 6067 spin1.kB = 1500.0 6068 spin1.kC = 2500.0 6069 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 6070 spin2.phi_ex_B = 0.1 6071 spin2.phi_ex_C = 0.5 6072 spin2.kB = 1500.0 6073 spin2.kC = 2500.0 6074 6075 # Low precision optimisation. 6076 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 6077 6078 # Monte Carlo simulations. 6079 self.interpreter.monte_carlo.setup(number=3) 6080 self.interpreter.monte_carlo.create_data(method='back_calc') 6081 self.interpreter.monte_carlo.initial_values() 6082 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 6083 self.interpreter.monte_carlo.error_analysis() 6084 6085 # Save the results. 6086 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 6087 6088 # The model checks. 6089 print("\n\nOptimised parameters:\n") 6090 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 6091 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 6092 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 6093 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 6094 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 6095 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 6096 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 6097 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 6098 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 6099 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 6100 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6101 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6102 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6103 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6104 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 6105 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 6106 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 6107 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6108 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6109 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6110 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6111 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
6112 6113
6114 - def test_m61_data_to_m61(self):
6115 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 6116 6117 # Fixed time variable. 6118 ds.fixed = True 6119 6120 # Execute the script. 6121 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6122 6123 # The original parameters. 6124 i0 = [100000.0, 20000.0] 6125 r1rho_prime = [2.25, 24.0] 6126 pA = 0.7 6127 kex = 1000.0 6128 delta_omega = [1.0, 2.0] 6129 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6130 phi_ex = [] 6131 for i in range(2): 6132 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6133 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6134 6135 # Switch to the 'R2eff' model data pipe, then check for each spin. 6136 self.interpreter.pipe.switch('R2eff - relax_disp') 6137 spin_index = 0 6138 for spin, spin_id in spin_loop(return_id=True): 6139 # Printout. 6140 print("\nSpin %s." % spin_id) 6141 6142 # Check the fitted parameters. 6143 for i in range(len(keys)): 6144 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6145 6146 # Increment the spin index. 6147 spin_index += 1 6148 6149 # The R20 keys. 6150 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6151 6152 # Switch to the 'M61' model data pipe, then check for each spin. 6153 self.interpreter.pipe.switch('M61 - relax_disp') 6154 spin_index = 0 6155 for spin, spin_id in spin_loop(return_id=True): 6156 # Printout. 6157 print("\nSpin %s." % spin_id) 6158 6159 # Check the fitted parameters. 6160 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6161 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6162 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6163 6164 # Increment the spin index. 6165 spin_index += 1
6166 6167
6168 - def test_m61_exp_data_to_m61(self):
6169 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 6170 6171 # Fixed time variable. 6172 ds.fixed = False 6173 6174 # Single spin optimisation. 6175 ds.single = True 6176 6177 # Execute the script. 6178 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6179 6180 # The original parameters. 6181 i0 = [100000.0, 20000.0] 6182 r1rho_prime = [2.25, 24.0] 6183 pA = 0.7 6184 kex = 1000.0 6185 delta_omega = [1.0, 2.0] 6186 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6187 phi_ex = [] 6188 for i in range(2): 6189 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6190 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6191 6192 # Switch to the 'R2eff' model data pipe, then check for each spin. 6193 self.interpreter.pipe.switch('R2eff - relax_disp') 6194 spin_index = 0 6195 for spin, spin_id in spin_loop(return_id=True): 6196 # Printout. 6197 print("\nSpin %s." % spin_id) 6198 6199 # Check the fitted parameters. 6200 for i in range(len(keys)): 6201 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6202 6203 # Increment the spin index. 6204 spin_index += 1 6205 6206 # The R20 keys. 6207 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6208 6209 # Switch to the 'M61' model data pipe, then check for each spin. 6210 self.interpreter.pipe.switch('M61 - relax_disp') 6211 spin_index = 0 6212 for spin, spin_id in spin_loop(return_id=True): 6213 # Printout. 6214 print("\nSpin %s." % spin_id) 6215 6216 # Check the fitted parameters. 6217 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6218 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6219 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6220 6221 # Increment the spin index. 6222 spin_index += 1
6223 6224
6225 - def test_m61b_data_to_m61b(self):
6226 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 6227 6228 # Execute the script. 6229 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 6230 6231 # The original parameters. 6232 i0 = [100000.0, 20000.0] 6233 r1rho_prime = [10.0, 24.0] 6234 pA = 0.95 6235 kex = 2000.0 6236 delta_omega = [1.0, 2.0] 6237 6238 # The R20 keys. 6239 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6240 6241 # Switch to the 'M61 skew' model data pipe, then check for each spin. 6242 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 6243 spin_index = 0 6244 for spin, spin_id in spin_loop(return_id=True): 6245 # Printout. 6246 print("\nSpin %s." % spin_id) 6247 6248 # Check the fitted parameters. 6249 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6250 self.assertAlmostEqual(spin.pA, pA, 2) 6251 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 6252 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6253 6254 # Increment the spin index. 6255 spin_index += 1
6256 6257
6259 """Test that all models which can nest, have all their parameters converted.""" 6260 6261 # Set the experiment type. 6262 cdp.exp_type_list = EXP_TYPE_LIST 6263 6264 # Get info for all models. 6265 all_models_info = models_info(models=MODEL_LIST_FULL) 6266 6267 # Loop over all models. 6268 print("Printing the listed of nested models for each model.") 6269 print("#########################################") 6270 for model_info in all_models_info: 6271 print("%s"%model_info.model), 6272 print("<-"), 6273 nest_list = model_info.nest_list 6274 if nest_list == None: 6275 nest_list = ["None"] 6276 print(', '.join(map(str, nest_list))) 6277 6278 # Skip if there is no model to nest from. 6279 if nest_list == ["None"]: 6280 continue 6281 6282 # Assign params to variable. 6283 model_params = model_info.params 6284 6285 # Now loop over the nested models. 6286 for nested_model in nest_list: 6287 # Get the params for the nested model. 6288 nested_model_params = MODEL_PARAMS[nested_model] 6289 6290 # Get the dictionary of parameter conversion. 6291 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6292 6293 # Test the number of elements in the dictionary. 6294 self.assertEqual(len(par_dic), len(model_params)) 6295 6296 # Loop over dictionary. 6297 for param in par_dic: 6298 if param != par_dic[param]: 6299 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param)) 6300 self.assertNotEqual(par_dic[param], None)
6301 6302
6303 - def test_ns_mmq_3site(self):
6304 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6305 6306 # Execute the script. 6307 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6308 6309 # Check the chi-squared value. 6310 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6311 6312
6313 - def test_ns_mmq_3site_linear(self):
6314 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6315 6316 # Execute the script. 6317 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 6318 6319 # Check the chi-squared value. 6320 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6321 6322
6323 - def test_ns_r1rho_3site(self):
6324 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6325 6326 # Execute the script. 6327 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6328 6329 # Check the chi-squared value. 6330 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6331 6332
6333 - def test_ns_r1rho_3site_linear(self):
6334 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6335 6336 # Execute the script. 6337 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 6338 6339 # Check the chi-squared value. 6340 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6341 6342
6343 - def test_paul_schanda_nov_2015(self):
6344 """This test truncated private data which was provided by Paul Schanda. This systemtest uncovers some unfortunate problems when 6345 running an analysis and reading points by the R2eff method. 6346 """ 6347 6348 # Assign 6349 outdir = ds.tmpdir 6350 6351 # Execute the setup and creation of files. 6352 self.setup_paul_schanda_nov_2015(outdir=outdir) 6353 6354 # Minimum: Just read the sequence data, but this misses a lot of information. 6355 self.interpreter.sequence.read(file='residues.txt', res_num_col=1, dir=outdir) 6356 6357 # Open the settings file. 6358 set_file = open(outdir+sep+"exp_settings.txt") 6359 set_file_lines = set_file.readlines() 6360 6361 # Now load the data. 6362 for line in set_file_lines: 6363 if "#" in line[0]: 6364 continue 6365 6366 # Get data 6367 field, RF_field_strength_kHz, f_name = line.split() 6368 6369 # Assign data 6370 spec_id = f_name 6371 self.interpreter.relax_disp.exp_type(spectrum_id=spec_id, exp_type='R1rho') 6372 6373 # Set the spectrometer frequency 6374 self.interpreter.spectrometer.frequency(id=spec_id, frq=float(field), units='MHz') 6375 6376 # Is in kHz, som convert to Hz 6377 disp_frq = float(RF_field_strength_kHz)*1000 6378 6379 # Set The spin-lock field strength, nu1, in Hz 6380 self.interpreter.relax_disp.spin_lock_field(spectrum_id=spec_id, field=disp_frq) 6381 6382 # Read the R2eff data 6383 self.interpreter.relax_disp.r2eff_read(id=spec_id, file=f_name, dir=None, disp_frq=disp_frq, res_num_col=1, data_col=2, error_col=3) 6384 6385 # Is this necessary? The time, in seconds, of the relaxation period. 6386 #self.interpreter.relax_disp.relax_time(spectrum_id=spec_id, time=time_sl) 6387 6388 6389 # Check that the number of R2eff points is correct after dropping 1 datapoint for spin 51. 6390 r2eff_points = [] 6391 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6392 # Loop over the R2eff points 6393 for key in cur_spin.r2eff: 6394 value = cur_spin.r2eff[key] 6395 err = cur_spin.r2eff_err[key] 6396 r2eff_points.append(value) 6397 6398 # Test that values and errors are not nan. 6399 self.assert_(not isnan(value)) 6400 self.assert_(not isnan(err)) 6401 6402 6403 # Test the number of r2eff points. One is subtracted, due to one of the error values are "nan" in spin 51. 6404 self.assertEqual(len(r2eff_points), 2*(10+19)-1) 6405 6406 # Test stored value in the pipe. 6407 self.assertEqual(len(cdp.mol), 1) 6408 self.assertEqual(cdp.mol[0].name, None) 6409 self.assertEqual(len(cdp.mol[0].res), 2) 6410 6411 self.assertEqual(cdp.spectrometer_frq_count, 2) 6412 self.assertEqual(cdp.spectrometer_frq_list, [600000000.0, 950000000.0]) 6413 self.assertEqual(cdp.exp_type_list, ['R1rho']) 6414 6415 # Test the number of frequencies. 6416 count_600 = 0 6417 count_950 = 0 6418 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 6419 if frq == cdp.spectrometer_frq_list[0]: 6420 count_600 += 1 6421 elif frq == cdp.spectrometer_frq_list[1]: 6422 count_950 += 1 6423 6424 # Assert the number of points 6425 self.assertEqual(count_600, 10) 6426 self.assertEqual(count_950, 19) 6427 6428 # Name the isotope for field strength scaling. 6429 self.interpreter.spin.isotope(isotope='15N') 6430 6431 # Now test that the plotting can be performed of just the raw data. 6432 self.assertRaises(RelaxError, self.interpreter.relax_disp.plot_disp_curves, dir=outdir, y_axis='r2_eff', x_axis='disp', num_points=1000, extend_hz=500.0, extend_ppm=500.0, interpolate='disp', force=True) 6433 self.interpreter.relax_disp.select_model(model=MODEL_R2EFF) 6434 self.interpreter.relax_disp.plot_disp_curves(dir=outdir, y_axis='r2_eff', x_axis='disp', num_points=1000, extend_hz=500.0, extend_ppm=500.0, interpolate='disp', force=True) 6435 6436 6437 # Number of grid search increments. If set to None, then the grid search will be turned off and the default parameter values will be used instead. 6438 #GRID_INC = None 6439 GRID_INC = 21 6440 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6441 MC_NUM = 3 6442 # Model selection technique. 6443 MODSEL = 'AIC' 6444 # Which models to analyse ? 6445 MODELS = [MODEL_NOREX, MODEL_M61] 6446 # Fit, instead of read. Off for On-resonance. 6447 r1_fit = False 6448 # Set the initial guess from the minimum R2eff point 6449 set_grid_r20=True 6450 6451 # Execute the auto-analysis (fast). 6452 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6453 OPT_FUNC_TOL = 1e-1 6454 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6455 OPT_MAX_ITERATIONS = 1000 6456 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6457 6458 # Go 6459 relax_disp.Relax_disp(pipe_name="relax_disp", pipe_bundle="relax_disp", results_dir=outdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit) 6460 6461 # Now simulate that all spins are first deselected, and then selected. 6462 self.interpreter.deselect.all() 6463 sel_ids = [ 6464 ":12", 6465 ":51", 6466 ] 6467 for sel_spin in sel_ids: 6468 print("Selecting spin %s"%sel_spin) 6469 self.interpreter.select.spin(spin_id=sel_spin, change_all=False) 6470 6471 # Inspect which residues should be analysed together for a clustered/global fit. 6472 cluster_ids = sel_ids 6473 6474 # Cluster spins 6475 for curspin in cluster_ids: 6476 print("Adding spin %s to cluster"%curspin) 6477 self.interpreter.relax_disp.cluster('model_cluster', curspin) 6478 6479 # Show the pipe 6480 print("\nPrinting all the available pipes.") 6481 self.interpreter.pipe.display() 6482 6483 # Get the selected models 6484 print("\nChecking which model is stored per spin.") 6485 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6486 print("For spin_id '%s the model is '%s''"%(spin_id, curspin.model)) 6487 6488 # Copy pipe and switch to it. 6489 self.interpreter.pipe.copy(pipe_from="final - relax_disp", pipe_to="relax_disp_cluster", bundle_to="relax_disp_cluster") 6490 self.interpreter.pipe.switch(pipe_name="relax_disp_cluster") 6491 self.interpreter.pipe.display() 6492 6493 # Go again with clustered spins. 6494 relax_disp.Relax_disp(pipe_name="relax_disp_cluster", pipe_bundle="relax_disp_cluster", results_dir=outdir+sep+"cluster", models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit) 6495 6496 # Get the clustered fitted values 6497 print("\nChecking which value is stored per spin.") 6498 kex = None 6499 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6500 if kex == None: 6501 kex = curspin.kex 6502 self.assertEqual(curspin.kex, kex) 6503 print("For spin_id %s the kex is %.3f"%(spin_id, kex))
6504 6505
6506 - def test_repeat_cpmg(self):
6507 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6508 6509 U{task #7826<https://web.archive.org/web/https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data. 6510 """ 6511 6512 # Reset. 6513 self.interpreter.reset() 6514 6515 # Define base path to files. 6516 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6517 6518 # Setup dictionary with settings. 6519 sdic = {} 6520 6521 # Spectrometer frqs in list. 6522 sfrq_1 = 499.86214 6523 sfrq_2 = 599.8908587 6524 sfrqs = [sfrq_1, sfrq_2] 6525 6526 # Store in dictionary. 6527 sdic['sfrqs'] = sfrqs 6528 6529 # Store unit for frq. 6530 sdic['sfrq_unit'] = 'MHz' 6531 6532 # Store exp_type 6533 sdic['exp_type'] = 'SQ CPMG' 6534 6535 # Store spin isotope 6536 sdic['isotope'] = '15N' 6537 6538 # How intensity was measured. 6539 sdic['int_method'] = 'height' 6540 6541 # Define the time for result directory. 6542 sdic['time'] = '2014_09' 6543 6544 # Initialize frq dics. 6545 for frq in sfrqs: 6546 key = DIC_KEY_FORMAT % (frq) 6547 sdic[key] = {} 6548 6549 # Set keys. 6550 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6551 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6552 6553 # Store time T2. 6554 sdic[e_1]['time_T2'] = 0.04 6555 sdic[e_2]['time_T2'] = 0.06 6556 6557 # Set ncyc. 6558 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6559 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6560 6561 # Calculate the cpmg_frq and store. 6562 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6563 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6564 6565 # Define peak lists. 6566 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6567 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6568 sdic[e_1]['peaks_folder'] = peaks_folder_1 6569 sdic[e_2]['peaks_folder'] = peaks_folder_2 6570 6571 # Define folder to all rmsd files. 6572 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6573 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6574 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6575 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6576 6577 # Define temporary folder. 6578 sdic['results_dir'] = self.tmpdir 6579 6580 # Setup class with data. 6581 RDR = Relax_disp_rep(sdic) 6582 6583 # Setup base information. 6584 RDR.set_base_cpmg(method='FT', glob_ini=128) 6585 6586 methods = ['FT', 'MDD'] 6587 #methods = ['FT'] 6588 6589 # Set the intensity. 6590 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6591 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6592 6593 # Try plot some intensity correlations. 6594 if True: 6595 selection = None 6596 6597 # Now make a spin selection. 6598 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6599 6600 # For mdd 6601 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6602 6603 # Plot correlation of intensity 6604 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6605 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6606 corr_data = [fig1, fig2] 6607 6608 write_stats = True 6609 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6610 6611 # Open stat file. 6612 if write_stats: 6613 for i, corr_data_i in enumerate(corr_data): 6614 data, methods, glob_inis = corr_data[i] 6615 data_x, data_y = data 6616 method_x, method_y = methods 6617 glob_ini_x, glob_ini_y = glob_inis 6618 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6619 np = len(x) 6620 6621 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6622 6623 if selection == None: 6624 file_name = file_name_ini + '_all.txt' 6625 else: 6626 file_name = file_name_ini + '_sel.txt' 6627 path = RDR.results_dir 6628 data = extract_data(file=file_name, dir=path) 6629 6630 # Loop over the lines. 6631 for i, data_i in enumerate(data): 6632 print(i, data_i) 6633 6634 6635 # Try plot some intensity statistics. 6636 if True: 6637 # Collect r2eff values. 6638 selections = [None, ':2,3'] 6639 for selection in selections: 6640 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6641 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6642 6643 # Get R2eff stats. 6644 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6645 6646 ## Plot R2eff stats 6647 write_stats = True 6648 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6649 6650 # Open stat file. 6651 if write_stats: 6652 if selection == None: 6653 file_name = 'int_stat_all.txt' 6654 else: 6655 file_name = 'int_stat_sel.txt' 6656 path = RDR.results_dir 6657 data = extract_data(file=file_name, dir=path) 6658 6659 # Loop over the lines. 6660 for i, data_i in enumerate(data): 6661 print(i, data_i) 6662 6663 6664 # Try write some R2eff correlations. 6665 if True: 6666 selection = None 6667 # Collect r2eff values. 6668 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6669 6670 # For all spins, mdd 6671 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6672 6673 # Plot correlation of intensity 6674 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6675 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6676 corr_data = [fig1, fig2] 6677 6678 write_stats = True 6679 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6680 6681 # Open stat file. 6682 if write_stats: 6683 for i, corr_data_i in enumerate(corr_data): 6684 data, methods, glob_inis = corr_data[i] 6685 data_x, data_y = data 6686 method_x, method_y = methods 6687 glob_ini_x, glob_ini_y = glob_inis 6688 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6689 np = len(x) 6690 6691 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6692 6693 if selection == None: 6694 file_name = file_name_ini + '_all.txt' 6695 else: 6696 file_name = file_name_ini + '_sel.txt' 6697 path = RDR.results_dir 6698 data = extract_data(file=file_name, dir=path) 6699 6700 # Loop over the lines. 6701 for i, data_i in enumerate(data): 6702 print(i, data_i) 6703 6704 6705 # Try plot some R2eff statistics. 6706 if True: 6707 # Collect r2eff values. 6708 selections = [None, ':2,3'] 6709 for selection in selections: 6710 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6711 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6712 6713 # Get R2eff stats. 6714 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6715 6716 ## Plot R2eff stats 6717 write_stats = True 6718 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6719 6720 # Open stat file. 6721 if write_stats: 6722 if selection == None: 6723 file_name = 'r2eff_stat_all.txt' 6724 else: 6725 file_name = 'r2eff_stat_sel.txt' 6726 path = RDR.results_dir 6727 data = extract_data(file=file_name, dir=path) 6728 6729 # Loop over the lines. 6730 for i, data_i in enumerate(data): 6731 print(i, data_i) 6732 6733 6734 # Do minimisation individual. 6735 if True: 6736 methods = ['FT', 'MDD'] 6737 # Now calculate R2eff. 6738 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6739 6740 min_methods = [['FT'], ['MDD']] 6741 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6742 6743 #min_methods = [['FT']] 6744 #min_list_glob_ini = [[128]] 6745 #selection = ':2,3' 6746 selection = None 6747 6748 for i, methods in enumerate(min_methods): 6749 list_glob_ini = min_list_glob_ini[i] 6750 6751 if True: 6752 # First get data. 6753 if True: 6754 # First load all data. 6755 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6756 6757 # Then set R20 6758 if True: 6759 # Set R20 from min R2eff in preparation for Grid search. 6760 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6761 6762 # Check and print parameters. 6763 if True: 6764 # Print for pipe name 6765 method = methods[0] 6766 glob_ini = list_glob_ini[0] 6767 6768 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6769 RDR.spin_display_params(pipe_name=test_pipe_name) 6770 6771 # Then Grid search. 6772 if True: 6773 # Do Grid search. 6774 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6775 6776 # Then Minimise. 6777 if True: 6778 # Minimise 6779 RDR.opt_max_iterations = int(1e2) 6780 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6781 6782 #print asd 6783 6784 # Plot statistics. 6785 # Try plot some minimisation correlations. 6786 if True: 6787 selections = [None, ':2,3'] 6788 for selection in selections: 6789 # Collect param values. 6790 analysis = 'min_ind' 6791 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6792 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6793 6794 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6795 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6796 corr_data = [fig1, fig2] 6797 6798 write_stats = True 6799 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6800 6801 # Open stat file. 6802 if write_stats: 6803 for i, corr_data_i in enumerate(corr_data): 6804 data, methods, glob_inis = corr_data[i] 6805 data_x, data_y = data 6806 method_x, method_y = methods 6807 glob_ini_x, glob_ini_y = glob_inis 6808 6809 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6810 6811 if selection == None: 6812 file_name = file_name_ini + '_all.txt' 6813 else: 6814 file_name = file_name_ini + '_sel.txt' 6815 path = RDR.results_dir 6816 data = extract_data(file=file_name, dir=path) 6817 6818 # Loop over the lines. 6819 for i, data_i in enumerate(data): 6820 print(i, data_i) 6821 6822 # Try plot some minimisation statistics. 6823 if True: 6824 # Collect param values. 6825 #selections = [None, ':2,3'] 6826 selections = [None, ':2,3'] 6827 for selection in selections: 6828 analysis = 'min_ind' 6829 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6830 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6831 6832 # Get param stats. 6833 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6834 6835 ## Plot R2eff stats 6836 write_stats = True 6837 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6838 6839 # Open stat file. 6840 if write_stats: 6841 if selection == None: 6842 file_name = '%s_stat_all.txt' % (analysis) 6843 else: 6844 file_name = '%s_stat_sel.txt' % (analysis) 6845 path = RDR.results_dir 6846 data = extract_data(file=file_name, dir=path) 6847 6848 # Loop over the lines. 6849 for i, data_i in enumerate(data): 6850 print(i, data_i) 6851 6852 6853 # Do minimisation clustered. 6854 if True: 6855 methods = ['FT', 'MDD'] 6856 # Now calculate R2eff. 6857 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6858 6859 min_methods = [['FT'], ['MDD']] 6860 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6861 6862 #min_methods = [['FT']] 6863 #min_list_glob_ini = [[128]] 6864 selection = ':2,3' 6865 6866 for i, methods in enumerate(min_methods): 6867 list_glob_ini = min_list_glob_ini[i] 6868 6869 if True: 6870 # First get data. 6871 if True: 6872 # First load all data. 6873 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6874 6875 # Then select spins. 6876 if True: 6877 # Deselect all spins. 6878 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6879 6880 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6881 6882 # Then preset values. 6883 if True: 6884 # Set k_AB for Grid search. 6885 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6886 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6887 6888 # Then set R20 6889 if True: 6890 # Set R20 from min R2eff in preparation for Grid search. 6891 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6892 6893 # Check and print parameters. 6894 if True: 6895 # Print for pipe name 6896 method = methods[0] 6897 glob_ini = list_glob_ini[0] 6898 6899 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6900 RDR.spin_display_params(pipe_name=test_pipe_name) 6901 6902 # Then Grid search. 6903 if True: 6904 # Do Grid search. 6905 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True) 6906 6907 # Then cluster spins. 6908 if True: 6909 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6910 6911 # Then Minimise. 6912 if True: 6913 # Minimise 6914 RDR.opt_max_iterations = int(1e2) 6915 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6916 6917 # Plot statistics. 6918 # Try plot some minimisation correlations. 6919 if True: 6920 selection = ':2,3' 6921 # Collect param values. 6922 analysis = 'min' 6923 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6924 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6925 6926 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6927 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6928 corr_data = [fig1, fig2] 6929 6930 write_stats = True 6931 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6932 6933 # Open stat file. 6934 if write_stats: 6935 for i, corr_data_i in enumerate(corr_data): 6936 data, methods, glob_inis = corr_data[i] 6937 data_x, data_y = data 6938 method_x, method_y = methods 6939 glob_ini_x, glob_ini_y = glob_inis 6940 6941 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6942 6943 if selection == None: 6944 file_name = file_name_ini + '_all.txt' 6945 else: 6946 file_name = file_name_ini + '_sel.txt' 6947 path = RDR.results_dir 6948 data = extract_data(file=file_name, dir=path) 6949 6950 # Loop over the lines. 6951 for i, data_i in enumerate(data): 6952 print(i, data_i) 6953 6954 # Try plot some minimisation statistics. 6955 if True: 6956 # Collect param values. 6957 selections = [':2,3'] 6958 for selection in selections: 6959 analysis = 'min' 6960 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6961 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6962 6963 # Get param stats. 6964 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6965 6966 ## Plot R2eff stats 6967 write_stats = True 6968 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6969 6970 # Open stat file. 6971 if write_stats: 6972 if selection == None: 6973 file_name = '%s_stat_all.txt' % (analysis) 6974 else: 6975 file_name = '%s_stat_sel.txt' % (analysis) 6976 path = RDR.results_dir 6977 data = extract_data(file=file_name, dir=path) 6978 6979 # Loop over the lines. 6980 for i, data_i in enumerate(data): 6981 print(i, data_i)
6982 6983
6984 - def test_r1rho_kjaergaard_auto(self):
6985 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6986 6987 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6988 6989 This uses the automatic analysis. 6990 6991 """ 6992 6993 # Cluster residues 6994 cluster_ids = [ 6995 ":13@N", 6996 ":15@N", 6997 ":16@N", 6998 ":25@N", 6999 ":26@N", 7000 ":28@N", 7001 ":39@N", 7002 ":40@N", 7003 ":41@N", 7004 ":43@N", 7005 ":44@N", 7006 ":45@N", 7007 ":49@N", 7008 ":52@N", 7009 ":53@N"] 7010 7011 # Load the data. 7012 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 7013 7014 # Test some of the sequence. 7015 self.assertEqual(len(cdp.mol), 1) 7016 self.assertEqual(cdp.mol[0].name, None) 7017 self.assertEqual(len(cdp.mol[0].res), 48) 7018 7019 # Test the chemical shift data. 7020 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 7021 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 7022 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 7023 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 7024 7025 i = 0 7026 for spin, spin_id in spin_loop(return_id=True): 7027 # Check the chemical shift. 7028 self.assertEqual(spin.chemical_shift, cs[i]) 7029 7030 # Increment the index. 7031 i += 1 7032 7033 # Initialize counter 7034 i = 0 7035 j = 0 7036 # Count instances of select/deselect 7037 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 7038 if curspin.select == True: 7039 i += 1 7040 if curspin.select == False: 7041 j += 1 7042 7043 # Test number of selected/deselected spins. 7044 self.assertEqual(i, len(cluster_ids)) 7045 self.assertEqual(j, 48-len(cluster_ids)) 7046 7047 # Check the initial setup. 7048 self.assertEqual(cdp.mol[0].res[7].num, 13) 7049 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 7050 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 7051 7052 self.assertEqual(cdp.mol[0].res[9].num, 15) 7053 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 7054 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 7055 7056 self.assertEqual(cdp.mol[0].res[10].num, 16) 7057 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 7058 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 7059 7060 self.assertEqual(cdp.mol[0].res[16].num, 25) 7061 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 7062 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 7063 7064 self.assertEqual(cdp.mol[0].res[17].num, 26) 7065 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 7066 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 7067 7068 self.assertEqual(cdp.mol[0].res[19].num, 28) 7069 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 7070 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 7071 7072 self.assertEqual(cdp.mol[0].res[29].num, 39) 7073 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 7074 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 7075 7076 self.assertEqual(cdp.mol[0].res[30].num, 40) 7077 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 7078 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 7079 7080 self.assertEqual(cdp.mol[0].res[31].num, 41) 7081 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 7082 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 7083 7084 self.assertEqual(cdp.mol[0].res[33].num, 43) 7085 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 7086 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 7087 7088 self.assertEqual(cdp.mol[0].res[34].num, 44) 7089 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 7090 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 7091 7092 self.assertEqual(cdp.mol[0].res[35].num, 45) 7093 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 7094 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 7095 7096 self.assertEqual(cdp.mol[0].res[38].num, 49) 7097 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 7098 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 7099 7100 self.assertEqual(cdp.mol[0].res[41].num, 52) 7101 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 7102 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 7103 7104 self.assertEqual(cdp.mol[0].res[42].num, 53) 7105 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 7106 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 7107 7108 # The dispersion models. 7109 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7110 7111 # The grid search size (the number of increments per dimension). 7112 GRID_INC = 4 7113 7114 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7115 MC_NUM = 3 7116 7117 # Model selection technique. 7118 MODSEL = 'AIC' 7119 7120 # Execute the auto-analysis (fast). 7121 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7122 OPT_FUNC_TOL = 1e-1 7123 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7124 OPT_MAX_ITERATIONS = 1000 7125 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7126 7127 result_dir_name = ds.tmpdir 7128 7129 # Make all spins free 7130 for curspin in cluster_ids: 7131 self.interpreter.relax_disp.cluster('free spins', curspin) 7132 # Shut them down 7133 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7134 7135 # Select only a subset of spins for global fitting 7136 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7137 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7138 7139 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7140 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7141 7142 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7143 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7144 7145 # Run the analysis. 7146 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7147 7148 # Check the kex value of residue 52 7149 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 7150 7151 # Print results for each model. 7152 print("\n\n################") 7153 print("Printing results") 7154 print("################\n") 7155 for model in MODELS: 7156 # Skip R2eff model. 7157 if model == MODEL_R2EFF: 7158 continue 7159 7160 # Switch to pipe. 7161 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 7162 print("\nModel: %s" % (model)) 7163 7164 # Loop over the spins. 7165 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7166 # Generate spin string. 7167 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 7168 7169 # Loop over the parameters. 7170 print("Optimised parameters for spin: %s" % (spin_string)) 7171 for param in cur_spin.params + ['chi2']: 7172 # Get the value. 7173 if param in ['r1', 'r2']: 7174 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 7175 # Generate the R20 key. 7176 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 7177 7178 # Get the value. 7179 value = getattr(cur_spin, param)[r20_key] 7180 7181 # Print value. 7182 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7183 7184 # For all other parameters. 7185 else: 7186 # Get the value. 7187 value = getattr(cur_spin, param) 7188 7189 # Print value. 7190 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7191 7192 # Print the final pipe. 7193 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 7194 print("\nFinal pipe")
7195 7196
7198 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 7199 7200 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7201 7202 This uses the automatic analysis. 7203 7204 """ 7205 7206 # Cluster residues 7207 cluster_ids = [ 7208 ":52@N"] 7209 7210 # Load the data. 7211 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 7212 7213 # The dispersion models. 7214 MODELS = [MODEL_R2EFF] 7215 7216 # The grid search size (the number of increments per dimension). 7217 GRID_INC = 4 7218 7219 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7220 MC_NUM = 3 7221 7222 # Model selection technique. 7223 MODSEL = 'AIC' 7224 7225 # Execute the auto-analysis (fast). 7226 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7227 OPT_FUNC_TOL = 1e-1 7228 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7229 OPT_MAX_ITERATIONS = 1000 7230 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7231 7232 result_dir_name = ds.tmpdir 7233 7234 # Make all spins free 7235 for curspin in cluster_ids: 7236 self.interpreter.relax_disp.cluster('free spins', curspin) 7237 # Shut them down 7238 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7239 7240 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7241 7242 # Run the analysis. 7243 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7244 7245 # Check the graphs produced. 7246 graph_comb = [ 7247 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 7248 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 7249 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 7250 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 7251 ] 7252 7253 # Define expected folder names. 7254 result_folders = MODELS 7255 7256 # Assign spin_id. 7257 spin_id = ':52@N' 7258 7259 # Loop over result folders. 7260 for result_folder in result_folders: 7261 # Skip the model R2eff, which does not produce graphs. 7262 if result_folder == MODEL_R2EFF: 7263 continue 7264 7265 # Loop over graphs. 7266 for y_axis, x_axis, interpolate in graph_comb: 7267 # Determine file name: 7268 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7269 7270 # Make the file name. 7271 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7272 7273 # Get the file path. 7274 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 7275 7276 print("Testing file access to graph: %s"%file_path) 7277 self.assert_(access(file_path, F_OK)) 7278 7279 # Start testing all possible combinations of graphs. 7280 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 7281 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 7282 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 7283 7284 result_dir_name = ds.tmpdir 7285 7286 # Loop through all possible combinations of y_axis, x_axis and interpolation. 7287 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 7288 7289 for result_folder in result_folders: 7290 # Skip the model R2eff, which does not produce graphs. 7291 if result_folder == MODEL_R2EFF: 7292 continue 7293 7294 for y_axis in y_axis_types: 7295 for x_axis in x_axis_types: 7296 for interpolate in interpolate_types: 7297 # Determine file name: 7298 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7299 7300 # Make the file name. 7301 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7302 7303 # Write the curves. 7304 dir = result_dir_name+sep+result_folder 7305 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 7306 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 7307 7308 # Get the file path. 7309 file_path = get_file_path(file_name, dir) 7310 7311 # Test the plot file exists. 7312 print("Testing file access to graph: %s"%file_path) 7313 self.assert_(access(file_path, F_OK)) 7314 7315 # Now open, and compare content, line by line. 7316 file_prod = open(file_path) 7317 lines_prod = file_prod.readlines() 7318 file_prod.close() 7319 7320 # Define file to compare against. 7321 dir_comp = data_path+sep+result_folder 7322 file_path_comp = get_file_path(file_name, dir_comp) 7323 file_comp = open(file_path_comp) 7324 lines_comp = file_comp.readlines() 7325 file_comp.close() 7326 7327 # Assert number of lines is equal. 7328 self.assertEqual(len(lines_prod), len(lines_comp)) 7329 for j in range(len(lines_prod)): 7330 # Make the string test 7331 first_char = lines_prod[j][0] 7332 if first_char in ["@", "&"]: 7333 self.assertEqual(lines_prod[j], lines_comp[j]) 7334 else: 7335 # Split string in x, y, error. 7336 # The error would change per run. 7337 x_prod, y_prod, y_prod_err = lines_prod[j].split() 7338 x_comp, y_comp, y_comp_err = lines_comp[j].split() 7339 self.assertAlmostEqual(float(x_prod), float(x_comp)) 7340 self.assertAlmostEqual(float(y_prod), float(y_comp))
7341 7342
7344 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7345 7346 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7347 7348 This uses the automatic analysis, with missing loading R1. 7349 7350 """ 7351 7352 # Cluster residues 7353 cluster_ids = [ 7354 ":13@N", 7355 ":15@N", 7356 ":16@N", 7357 ":25@N", 7358 ":26@N", 7359 ":28@N", 7360 ":39@N", 7361 ":40@N", 7362 ":41@N", 7363 ":43@N", 7364 ":44@N", 7365 ":45@N", 7366 ":49@N", 7367 ":52@N", 7368 ":53@N"] 7369 7370 # Load the data. 7371 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 7372 7373 # The dispersion models. 7374 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7375 7376 # The grid search size (the number of increments per dimension). 7377 GRID_INC = None 7378 7379 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7380 MC_NUM = 3 7381 7382 # Model selection technique. 7383 MODSEL = 'AIC' 7384 7385 # Execute the auto-analysis (fast). 7386 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7387 OPT_FUNC_TOL = 1e-25 7388 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7389 OPT_MAX_ITERATIONS = 10000000 7390 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7391 7392 result_dir_name = ds.tmpdir 7393 7394 # Make all spins free 7395 for curspin in cluster_ids: 7396 self.interpreter.relax_disp.cluster('free spins', curspin) 7397 # Shut them down 7398 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7399 7400 # Select only a subset of spins for global fitting 7401 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7402 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7403 7404 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7405 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7406 7407 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7408 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7409 7410 # Point to directory with R2eff values, with 2000 MC simulations. 7411 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 7412 7413 r1_fit = True 7414 7415 # Run the analysis. 7416 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 7417 7418 # Verify the data. 7419 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7420 7421
7422 - def test_r2eff_read(self):
7423 """Test the operation of the relax_disp.r2eff_read user function.""" 7424 7425 # The path to the data files. 7426 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 7427 7428 # Read the sequence data. 7429 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 7430 7431 # The ID. 7432 id = 'test' 7433 7434 # Set up the metadata. 7435 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 7436 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7437 7438 # Try reading the file. 7439 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 7440 7441 # Check the global data. 7442 data = [ 7443 ['cpmg_frqs', {'test': 66.667}], 7444 ['cpmg_frqs_list', [66.667]], 7445 ['dispersion_points', 1], 7446 ['exp_type', {'test': 'SQ CPMG'}], 7447 ['exp_type_list', ['SQ CPMG']], 7448 ['spectrometer_frq', {'test': 800000000.0}], 7449 ['spectrometer_frq_count', 1], 7450 ['spectrometer_frq_list', [800000000.0]], 7451 ['spectrum_ids', ['test']] 7452 ] 7453 for name, value in data: 7454 # Does it exist? 7455 self.assert_(hasattr(cdp, name)) 7456 7457 # Check the object. 7458 obj = getattr(cdp, name) 7459 self.assertEqual(obj, value) 7460 7461 # Check the spin data. 7462 data = [ 7463 [1, 2.3035747e+04, 8.5467725e+01], 7464 [2, 9.9629762e+04, 2.8322033e+02], 7465 [3, 9.5663137e+04, 2.8632929e+02], 7466 [4, 1.7089893e+05, 3.1089428e+02], 7467 [5, 4.7323876e+04, 1.0084269e+02], 7468 [6, 2.0199122e+04, 1.0135220e+02], 7469 [7, 1.6655488e+05, 3.1609061e+02], 7470 [8, 9.0061074e+04, 1.9176585e+02], 7471 [10, 8.4726204e+04, 2.8898155e+02], 7472 [11, 1.5050233e+05, 4.3138029e+02], 7473 [12, 9.2998531e+04, 3.0440191e+02], 7474 [13, 1.6343507e+05, 3.3144097e+02], 7475 [14, 1.0137301e+05, 3.7314642e+02], 7476 [15, 8.3407837e+04, 1.6546473e+02], 7477 [16, 1.3819126e+05, 3.3388517e+02], 7478 [17, 1.1010490e+05, 3.5639222e+02], 7479 [18, 9.4324035e+04, 3.2343585e+02], 7480 [19, 1.1135179e+05, 3.0706671e+02], 7481 [20, 7.6339410e+04, 1.7377460e+02], 7482 [21, 6.2008453e+04, 1.7327150e+02], 7483 [22, 1.0590404e+05, 2.4814635e+02], 7484 [23, 1.0630198e+05, 2.3601100e+02], 7485 [24, 7.2996320e+04, 1.4952465e+02], 7486 [25, 9.5486742e+04, 2.7080766e+02], 7487 [26, 5.8067989e+04, 1.6820462e+02], 7488 [27, -1.7168510e+04, 2.2519560e+02], 7489 [28, 1.6891473e+05, 2.3497525e+02], 7490 [29, 9.4038555e+04, 2.0357593e+02], 7491 [30, 2.1386951e+04, 2.2153532e+02], 7492 [31, 9.3982899e+04, 2.0937056e+02], 7493 [32, 8.6097484e+04, 2.3868467e+02], 7494 [33, 1.0194337e+05, 2.7370704e+02], 7495 [34, 8.5683111e+04, 2.0838076e+02], 7496 [35, 8.6985768e+04, 2.0889310e+02], 7497 [36, 8.6011237e+04, 1.7498390e+02], 7498 [37, 1.0984097e+05, 2.7622998e+02], 7499 [38, 8.7017879e+04, 2.6547994e+02], 7500 [39, 9.1682649e+04, 5.2777676e+02], 7501 [40, 7.6370440e+04, 1.9873214e+02], 7502 [41, 9.1393531e+04, 2.4483824e+02], 7503 [42, 1.1017111e+05, 2.8020699e+02], 7504 [43, 9.4552366e+04, 3.4394150e+02], 7505 [44, 1.2858281e+05, 6.8449252e+02], 7506 [45, 7.4583525e+04, 1.9544210e+02], 7507 [46, 9.2087490e+04, 2.0491066e+02], 7508 [47, 9.7507255e+04, 2.5162839e+02], 7509 [48, 1.0033842e+05, 2.7566430e+02], 7510 [49, 1.3048305e+05, 2.6797466e+02], 7511 [50, 1.0546796e+05, 1.9304384e+02], 7512 [51, 9.3099697e+04, 2.0773311e+02], 7513 [52, 4.6863758e+04, 1.3169068e+02], 7514 [53, 6.1055806e+04, 1.5448477e+02], 7515 [55, 6.8629994e+04, 1.6868673e+02], 7516 [56, 1.1005552e+05, 2.1940465e+02], 7517 [57, 1.0572760e+05, 1.9768486e+02], 7518 [58, 1.1176950e+05, 3.0009610e+02], 7519 [59, 9.8758603e+04, 3.3803895e+02], 7520 [60, 9.9517201e+04, 3.5137994e+02], 7521 [61, 5.4357946e+04, 2.5896579e+02], 7522 [62, 1.0899978e+05, 2.8720371e+02], 7523 [63, 8.4549759e+04, 4.1401837e+02], 7524 [64, 5.5014550e+04, 2.1135781e+02], 7525 [65, 8.0569666e+04, 2.3249709e+02], 7526 [66, 1.2936610e+05, 3.5218725e+02], 7527 [67, 3.6438010e+04, 8.7924003e+01], 7528 [70, 3.8763157e+04, 1.3325040e+02], 7529 [71, 8.5711411e+04, 2.9316183e+02], 7530 [72, 3.3211541e+04, 1.2182123e+02], 7531 [73, 3.2070576e+04, 1.2305430e+02] 7532 ] 7533 for res_num, value, error in data: 7534 # Get the spin. 7535 spin = return_spin(spin_id=":%s"%res_num) 7536 7537 # Check the values. 7538 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7539 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7540 7541
7542 - def test_r2eff_read_spin(self):
7543 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7544 7545 # The path to the data files. 7546 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7547 7548 # Generate the sequence. 7549 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7550 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7551 self.interpreter.spin.isotope('1H', spin_id='@H') 7552 self.interpreter.spin.isotope('15N', spin_id='@N') 7553 7554 # Build the experiment IDs. 7555 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 7556 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 7557 ids = [] 7558 for value in H_disp_points: 7559 ids.append('1H_CPMG_%s' % value) 7560 for value in N_disp_points: 7561 ids.append('15N_CPMG_%s' % value) 7562 print("\n\nThe experiment IDs are %s." % ids) 7563 7564 # Set up the metadata for the experiments. 7565 for id in ids: 7566 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7567 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7568 for value in H_disp_points: 7569 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7570 for value in N_disp_points: 7571 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7572 7573 # Loop over the experiments. 7574 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7575 # Try reading the file. 7576 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 7577 7578 # Check the global data. 7579 data = [ 7580 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 7581 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 7582 ['dispersion_points', 24], 7583 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 7584 ['exp_type_list', ['SQ CPMG']], 7585 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 7586 ['spectrometer_frq_count', 1], 7587 ['spectrometer_frq_list', [500000000.0]], 7588 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 7589 ] 7590 for name, value in data: 7591 # Does it exist? 7592 self.assert_(hasattr(cdp, name)) 7593 7594 # Check the object. 7595 obj = getattr(cdp, name) 7596 if not isinstance(data, dict): 7597 self.assertEqual(obj, value) 7598 7599 # Check the global dictionary data. 7600 else: 7601 for id in ids: 7602 self.assertEqual(obj[id], value[id]) 7603 7604 # Check the spin data. 7605 h_data = [ 7606 [ 67.0, 21.47924, 0.42958], 7607 [ 133.0, 16.73898, 0.33478], 7608 [ 267.0, 9.97357, 0.19947], 7609 [ 400.0, 8.23877, 0.24737], 7610 [ 533.0, 7.59290, 0.24263], 7611 [ 667.0, 7.45843, 0.24165], 7612 [ 800.0, 7.11222, 0.23915], 7613 [ 933.0, 7.40880, 0.24129], 7614 [1067.0, 6.55191, 0.16629], 7615 [1600.0, 6.72177, 0.23637], 7616 [2133.0, 7.09629, 0.23904], 7617 [2667.0, 7.14675, 0.23940] 7618 ] 7619 for disp_point, value, error in h_data: 7620 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7621 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7622 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7623 n_data = [ 7624 [ 50.0, 27.15767, 0.54315], 7625 [ 100.0, 26.55781, 0.53116], 7626 [ 150.0, 24.73462, 0.49469], 7627 [ 200.0, 20.98617, 0.41972], 7628 [ 250.0, 17.82442, 0.35649], 7629 [ 300.0, 15.55352, 0.31107], 7630 [ 350.0, 13.78958, 0.27579], 7631 [ 400.0, 12.48334, 0.24967], 7632 [ 500.0, 11.55724, 0.23114], 7633 [ 600.0, 10.53874, 0.21077], 7634 [ 700.0, 10.07395, 0.20148], 7635 [ 800.0, 9.62952, 0.19259], 7636 [ 900.0, 9.49994, 0.19000], 7637 [1000.0, 8.71350, 0.17427] 7638 ] 7639 for disp_point, value, error in n_data: 7640 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7641 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7642 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7643 7644
7645 - def test_r2eff_fit_fixed_time(self):
7646 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7647 7648 # Execute the script. 7649 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7650 7651
7652 - def test_read_r2eff(self):
7653 """Test the reading of a file containing r2eff values.""" 7654 7655 # Create the sequence data, and name the spins. 7656 self.interpreter.residue.create(1, 'Gly') 7657 self.interpreter.residue.create(2, 'Gly') 7658 self.interpreter.residue.create(3, 'Gly') 7659 7660 # Read the file. 7661 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 7662 7663 # Test the data. 7664 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7665 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7666 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7667 7668
7670 """Test speeding up grid search. Support requst sr #3151 U{https://web.archive.org/web/https://gna.org/support/index.php?3151}. 7671 7672 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7673 7674 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7675 'SOD1-WT' CPMG data to the CR72 dispersion model. 7676 7677 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7678 Data is for experiment at 25 degree Celcius. 7679 """ 7680 7681 # Base data setup. 7682 pipe_name = 'base pipe' 7683 pipe_type = 'relax_disp' 7684 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7685 select_spin_index = list(range(0, 1)) 7686 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7687 7688 # Generate r20 key. 7689 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7690 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7691 7692 ## Now prepare for MODEL calculation. 7693 MODEL = "CR72" 7694 7695 # Change pipe. 7696 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7697 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7698 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7699 7700 # Then select model. 7701 self.interpreter.relax_disp.select_model(model=MODEL) 7702 7703 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7704 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7705 7706 # Test result, for normal run. 7707 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7708 # Get the spin_params. 7709 spin_params = spin.params 7710 7711 # Defined fixed values for testing. 7712 if spin_id == ":10@N": 7713 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7714 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7715 7716 # Print out. 7717 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 7718 7719 # Testing the r2 values for the different fields are not the same. 7720 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7721 7722 # Test values are larger than 0. 7723 self.assert_(spin.r2[r20_key_600] > 0.0) 7724 self.assert_(spin.r2[r20_key_500] > 0.0) 7725 7726 # Loop over the experiment settings. 7727 r2eff_600 = [] 7728 r2eff_500 = [] 7729 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7730 # Create the data key. 7731 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7732 7733 # Extract the r2 eff data. 7734 r2eff = spin.r2eff[data_key] 7735 if frq == 599.8908617*1E6: 7736 r2eff_600.append(r2eff) 7737 elif frq == 499.862139*1E6: 7738 r2eff_500.append(r2eff) 7739 7740 # Sort values. 7741 r2eff_600.sort() 7742 r2eff_500.sort() 7743 7744 # Test values again. 7745 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7746 print(r2eff_600) 7747 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7748 print("") 7749 7750 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7751 print(r2eff_500) 7752 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7753 print("") 7754 7755 print("###########################################") 7756 print("Trying GRID SEARCH for minimum R2eff values") 7757 7758 ### Test just the Grid search. 7759 GRID_INC = 5 7760 7761 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7762 7763 ### Then test the value.set function. 7764 # Change pipe. 7765 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7766 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7767 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7768 7769 # Then select model. 7770 self.interpreter.relax_disp.select_model(model=MODEL) 7771 7772 # Then set the standard parameter values. 7773 for param in spin_params: 7774 print("Setting standard parameter for param: %s"%param) 7775 self.interpreter.value.set(param=param, index=None) 7776 7777 # Test result, for normal run. 7778 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7779 # Print out. 7780 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 7781 7782 # Testing the r2 values. 7783 self.assertEqual(spin.r2[r20_key_600], 10.00) 7784 self.assertEqual(spin.r2[r20_key_500], 10.00) 7785 self.assertEqual(spin.pA, 0.9) 7786 self.assertEqual(spin.dw, 1.0) 7787 self.assertEqual(spin.kex, 1000.0) 7788 7789 print("###########################################") 7790 print("Trying GRID SEARCH for standard R2eff values") 7791 7792 ### Test just the Grid search. 7793 GRID_INC = 5 7794 7795 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7796 7797 ### Run auto_analysis. 7798 # The grid search size (the number of increments per dimension). 7799 GRID_INC = 5 7800 7801 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7802 MC_NUM = 3 7803 7804 # Model selection technique. 7805 MODSEL = 'AIC' 7806 7807 # Execute the auto-analysis (fast). 7808 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7809 OPT_FUNC_TOL = 1e-1 7810 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7811 OPT_MAX_ITERATIONS = 1000 7812 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7813 7814 # Run the analysis. 7815 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7816 7817
7818 - def test_show_apod_extract(self):
7819 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7820 7821 # The path to the data files. 7822 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7823 7824 # Define file name. 7825 file_name = '128_0_FT.ft2' 7826 7827 # Call function. 7828 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7829 7830 # Define how output should look like. 7831 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7832 # Dont test lines which can differ. 7833 show_apod_ver = [ 7834 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7835 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7836 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7837 '', 7838 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7839 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7840 #'', 7841 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7842 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7843 7844 for i, line in enumerate(show_apod_ver): 7845 line_ver = get_output[i] 7846 7847 print(line) 7848 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7849 continue 7850 # Make the string test 7851 self.assertEqual(line, line_ver)
7852 7853
7854 - def test_show_apod_rmsd(self):
7855 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7856 7857 # The path to the data files. 7858 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7859 7860 # Define file name. 7861 file_name = '128_0_FT.ft2' 7862 7863 # Call function. 7864 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7865 7866 # Assert. 7867 self.assertEqual(rmsd, 8583.41)
7868 7869
7871 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7872 7873 # The path to the data files. 7874 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7875 7876 # Call function, and get all file names. 7877 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7878 7879 # Loop over file_paths. 7880 for wfile_path in wfile_paths: 7881 # Open the file. 7882 get_data = extract_data(file=wfile_path) 7883 7884 # Extract line 0, column 0. 7885 test = float(get_data[0][0]) 7886 7887 # Assert. 7888 self.assertEqual(test, 8583.41)
7889 7890
7892 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7893 7894 # The path to the data files. 7895 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7896 7897 # Define file name. 7898 file_name = '128_0_FT.ft2' 7899 7900 # Call function, and get file name. 7901 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7902 7903 # Open the file. 7904 get_data = extract_data(file=wfile_path) 7905 7906 # Extract line 0, column 0. 7907 test = float(get_data[0][0]) 7908 7909 # Assert. 7910 self.assertEqual(test, 8583.41)
7911 7912
7914 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7915 7916 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7917 'SOD1-WT' CPMG data to the CR72 dispersion model. 7918 7919 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7920 Data is for experiment at 25 degree Celcius. 7921 7922 bug #21954 U{https://web.archive.org/web/https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7923 """ 7924 7925 # Base data setup. 7926 pipe_name = 'base pipe' 7927 pipe_type = 'relax_disp' 7928 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7929 select_spin_index = list(range(0, 1)) 7930 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7931 7932 # Define replicated 7933 repl_A = ['Z_A1', 'Z_A15'] 7934 repl_B = ['Z_B1', 'Z_B18'] 7935 7936 # Loop over spectrum ID, and sort them 7937 spectrum_ids_A = [] 7938 spectrum_ids_B = [] 7939 for spectrum_id in cdp.spectrum_ids: 7940 if "A" in spectrum_id: 7941 spectrum_ids_A.append(spectrum_id) 7942 elif "B" in spectrum_id: 7943 spectrum_ids_B.append(spectrum_id) 7944 7945 # To clean up old error analysis, delete attributes 7946 delattr(cdp, "var_I") 7947 delattr(cdp, "sigma_I") 7948 7949 # Perform error analysis 7950 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7951 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7952 7953 # Loop over spins, save errors to list 7954 Errors_A_B = [] 7955 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7956 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7957 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7958 Errors_A_B.append([A_err, B_err]) 7959 7960 # To clean up old error analysis, delete attributes 7961 delattr(cdp, "var_I") 7962 delattr(cdp, "sigma_I") 7963 7964 # Perform error analysis. Order is important 7965 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7966 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7967 7968 # Loop over spins, save errors to list 7969 Errors_B_A = [] 7970 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7971 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7972 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7973 Errors_B_A.append([A_err, B_err]) 7974 7975 # Make test for order of error 7976 for i in range(len(Errors_A_B)): 7977 Error_A_B = Errors_A_B[i] 7978 Error_B_A = Errors_B_A[i] 7979 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7980 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7981 7982 # Make further tests for fixed values 7983 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7984 std_A_fix = 2785.7263335738567 7985 7986 for id_A in spectrum_ids_A: 7987 self.assertEqual(cdp.sigma_I[id_A], std_A) 7988 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7989 7990 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7991 std_B_fix = 4967.3772030667988 7992 7993 for id_B in spectrum_ids_B: 7994 self.assertEqual(cdp.sigma_I[id_B], std_B) 7995 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7996 7997
7998 - def test_sod1wt_t25_to_cr72(self):
7999 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 8000 8001 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 8002 'SOD1-WT' CPMG data to the CR72 dispersion model. 8003 8004 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 8005 Data is for experiment at 25 degree Celcius. 8006 """ 8007 8008 # Base data setup. 8009 pipe_name = 'base pipe' 8010 pipe_type = 'relax_disp' 8011 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 8012 select_spin_index = list(range(0, 2)) 8013 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 8014 8015 # Generate r20 key. 8016 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 8017 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 8018 8019 ## Now prepare for MODEL calculation. 8020 MODEL = "CR72" 8021 8022 # Change pipe. 8023 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 8024 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 8025 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 8026 8027 # Then select model. 8028 self.interpreter.relax_disp.select_model(model=MODEL) 8029 8030 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 8031 GRID_INC = 7 8032 8033 # Store grid and minimisations results. 8034 grid_results = [] 8035 mini_results = [] 8036 clust_results = [] 8037 8038 # Set the R20 parameters in the default grid search using the minimum R2eff value. 8039 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 8040 8041 # Deselect insignificant spins. 8042 self.interpreter.relax_disp.insignificance(level=1.0) 8043 8044 # Perform Grid Search. 8045 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 8046 8047 # Store result. 8048 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8049 # Store grid results. 8050 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8051 8052 ## Now do minimisation. 8053 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8054 set_func_tol = 1e-9 8055 set_max_iter = 100000 8056 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 8057 8058 # Store result. 8059 pA_values = [] 8060 kex_values = [] 8061 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8062 # Store minimisation results. 8063 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8064 8065 # Store pA values. 8066 pA_values.append(spin.pA) 8067 8068 # Store kex values. 8069 kex_values.append(spin.kex) 8070 8071 print("\n# Now print before and after minimisation.\n") 8072 8073 # Print results. 8074 for i in range(len(grid_results)): 8075 # Get values. 8076 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 8077 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 8078 8079 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 8080 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 8081 8082 ## Prepare for clustering 8083 # Change pipe. 8084 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 8085 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 8086 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 8087 8088 # Then select model. 8089 self.interpreter.relax_disp.select_model(model=MODEL) 8090 8091 # Define cluster id. 8092 cluster_id = 'clust' 8093 8094 # Loop over spins to cluster them. 8095 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8096 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 8097 8098 # Copy over values. 8099 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 8100 8101 # Test the median values is correct 8102 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8103 print(pA_values) 8104 # The the median pA value returned. 8105 self.assertEqual(median(pA_values), spin.pA) 8106 8107 # The the median kex value returned. 8108 self.assertEqual(median(kex_values), spin.kex) 8109 8110 ## Now do minimisation. 8111 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 8112 8113 # Store result. 8114 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 8115 # Store clust results. 8116 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 8117 8118 # Store the outcome of the clustering minimisation. 8119 clust_pA = spin.pA 8120 clust_kex = spin.kex 8121 8122 print("\n# Now testing.\n") 8123 8124 # Define results 8125 test_res = {} 8126 test_res[':10@N'] = {} 8127 test_res[':10@N']['r2600'] = 18.429755324773360 8128 test_res[':10@N']['r2500'] = 16.981349161968630 8129 test_res[':10@N']['dw'] = 2.700755859433969 8130 test_res[':10@N']['pA'] = 0.971531659288657 8131 test_res[':10@N']['kex'] = 3831.766337047963134 8132 test_res[':11@N'] = {} 8133 test_res[':11@N']['r2600'] = 18.193409421115213 8134 test_res[':11@N']['r2500'] = 17.308838135567765 8135 test_res[':11@N']['dw'] = 2.706650302761793 8136 test_res[':11@N']['pA'] = 0.971531659288657 8137 test_res[':11@N']['kex'] = 3831.766337047963134 8138 8139 # Then make tests. 8140 for i in range(len(grid_results)): 8141 # Get values. 8142 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 8143 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 8144 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 8145 8146 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 8147 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 8148 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 8149 8150 # Make tests. 8151 self.assertEqual(clust_pA, c_pA) 8152 self.assertEqual(clust_kex, c_kex) 8153 8154 # Test values. 8155 if c_spin_id in test_res: 8156 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 8157 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 8158 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 8159 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 8160 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
8161 8162 # Save disp graph to temp. 8163 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 8164 8165
8167 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 8168 8169 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 8170 'SOD1-WT' CPMG data to the CR72 dispersion model. 8171 8172 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 8173 Data is for experiment at 25 degree Celcius. 8174 """ 8175 8176 # Base data setup. 8177 pipe_name = 'base pipe' 8178 pipe_type = 'relax_disp' 8179 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 8180 select_spin_index = list(range(0, 2)) 8181 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 8182 8183 # Generate r20 key. 8184 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 8185 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 8186 8187 # Cluster everything, to analyse together. 8188 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 8189 8190 # Write input 8191 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 8192 8193 # Check the r2eff set files. 8194 print("\nChecking the R2eff input set files.") 8195 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 8196 8197 # First check file exists 8198 for dir, file in files: 8199 print(dir+sep+file) 8200 self.assert_(access(dir+sep+file, F_OK)) 8201 8202 # Define how files should look like 8203 data_set_600 = [ 8204 "60.8272464287\n", 8205 "0.06\n", 8206 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8207 "# G10\n", 8208 " 33.333 26.53556078711 0.5236104771163\n", 8209 " 66.667 25.29735243318 0.48766574122\n", 8210 " 100 25.09470361403 0.4820438864671\n", 8211 " 133.333 25.15603274331 0.4837377286085\n", 8212 " 166.667 24.27213341753 0.4599457904395\n", 8213 " 200 24.00364120328 0.4529773198905\n", 8214 " 266.667 24.03511395168 0.4537880662536\n", 8215 " 300 23.04761040024 0.4291039120557\n", 8216 " 333.333 22.95530300787 0.4268745963972\n", 8217 " 400 23.06158810662 0.4294426293624\n", 8218 " 466.667 22.26799054092 0.4106809618644\n", 8219 " 533.333 21.99851418823 0.4045232104735\n", 8220 " 666.667 21.19651570955 0.3868136173831\n", 8221 " 833.333 20.30938498379 0.3682604887899\n", 8222 " 1000 20.28273252609 0.367719392568\n", 8223 "# D11\n", 8224 " 33.333 24.76520269878 0.5026475808706\n", 8225 " 66.667 24.8773107448 0.5058752916906\n", 8226 " 100 24.90357815239 0.5066348551479\n", 8227 " 133.333 23.7782506151 0.4751950583865\n", 8228 " 166.667 23.68548762076 0.4727017128631\n", 8229 " 200 23.58629651618 0.4700517377679\n", 8230 " 266.667 23.47734671187 0.4671601744044\n", 8231 " 300 24.08647493772 0.4835855560598\n", 8232 " 333.333 22.98314371029 0.4542918950801\n", 8233 " 400 22.80339361568 0.4497107885587\n", 8234 " 466.667 22.91634335366 0.4525833037874\n", 8235 " 533.333 22.59774140046 0.4445334311324\n", 8236 " 666.667 20.9177750759 0.4046955726046\n", 8237 " 833.333 20.71792550566 0.4002363835007\n", 8238 " 1000 19.54080006349 0.3751112751853\n", 8239 ] 8240 8241 # Check data_set_600 8242 file = open(files[0][0]+sep+files[0][1]) 8243 lines = file.readlines() 8244 file.close() 8245 self.assertEqual(len(data_set_600), len(lines)) 8246 for i in range(len(data_set_600)): 8247 # Make the string test 8248 self.assertEqual(data_set_600[i], lines[i]) 8249 8250 # Define how files should look like 8251 data_set_500 = [ 8252 "50.6846152368\n", 8253 "0.04\n", 8254 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8255 "# G10\n", 8256 " 50 22.28084307393 0.2944966344183\n", 8257 " 100 21.93494977761 0.2910362768307\n", 8258 " 150 21.09850032232 0.282892238351\n", 8259 " 200 20.86493960397 0.2806737853646\n", 8260 " 250 20.75287269752 0.2796178205016\n", 8261 " 300 20.25597152406 0.2750013546989\n", 8262 " 350 19.92172163467 0.2719555756504\n", 8263 " 400 19.97712052922 0.272457105051\n", 8264 " 450 19.46807010415 0.2678972122793\n", 8265 " 500 19.76875460947 0.2705774849203\n", 8266 " 550 19.39161367402 0.2672216964327\n", 8267 " 600 19.03949517697 0.2641417899694\n", 8268 " 650 19.12218812132 0.2648605059901\n", 8269 " 700 19.01037461457 0.2638893584683\n", 8270 " 800 18.83395162904 0.2623674321143\n", 8271 " 900 18.47529972436 0.2593123604687\n", 8272 " 1000 18.5252023121 0.2597343394038\n", 8273 "# D11\n", 8274 " 50 22.15403890237 0.3285588379827\n", 8275 " 100 21.80946781746 0.3247185598713\n", 8276 " 150 21.77715415505 0.324361526682\n", 8277 " 200 21.41647464235 0.3204122024881\n", 8278 " 250 21.17099940822 0.3177616325958\n", 8279 " 300 21.03740030577 0.3163316496664\n", 8280 " 350 20.95393648281 0.3154427665172\n", 8281 " 400 20.93311399332 0.315221543436\n", 8282 " 450 20.18219905222 0.3073848655291\n", 8283 " 500 19.93599065085 0.3048744697057\n", 8284 " 550 19.68475725452 0.3023424499113\n", 8285 " 600 19.33575433934 0.2988741928798\n", 8286 " 650 19.53915692194 0.3008886196853\n", 8287 " 700 19.2018754351 0.2975587767134\n", 8288 " 800 18.82360965368 0.2938866923878\n", 8289 " 900 18.71861761238 0.2928790380131\n", 8290 " 1000 17.95878049287 0.2857341721151\n", 8291 ] 8292 8293 # Check data_set_500 8294 file = open(files[1][0]+sep+files[1][1]) 8295 lines = file.readlines() 8296 file.close() 8297 self.assertEqual(len(data_set_500), len(lines)) 8298 for i in range(len(data_set_500)): 8299 # Make the string test 8300 self.assertEqual(data_set_500[i], lines[i]) 8301 8302 # Test local dir tests. This will be turned off in system test. 8303 turn_on_local_dir_test = False 8304 8305 if turn_on_local_dir_test: 8306 ## Now check to local folder with None argument. 8307 # Write input 8308 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 8309 8310 # Check the r2eff set files. 8311 print("\nChecking the R2eff input set files.") 8312 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 8313 8314 # First check file exists 8315 for dir, file in files: 8316 print(dir+sep+file) 8317 self.assert_(access(dir+sep+file, F_OK)) 8318 8319 ## Now check to local folder with dir argument. 8320 # Write input 8321 set_dir = "Test_ShereKhan" 8322 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 8323 8324 # Check the r2eff set files. 8325 print("\nChecking the R2eff input set files.") 8326 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 8327 8328 # First check file exists 8329 for dir, file in files: 8330 print(dir+sep+file) 8331 self.assert_(access(dir+sep+file, F_OK))
8332 8333
8334 - def test_sprangers_data_to_mmq_cr72(self, model=None):
8335 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 8336 8337 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 8338 """ 8339 8340 # Reset. 8341 self.interpreter.reset() 8342 8343 # Create the data pipe and load the base data. 8344 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8345 self.interpreter.state.load(data_path+sep+'r2eff_values') 8346 8347 # The model data pipe. 8348 model = 'MMQ CR72' 8349 pipe_name = "%s - relax_disp" % model 8350 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8351 self.interpreter.pipe.switch(pipe_name=pipe_name) 8352 8353 # Set the model. 8354 self.interpreter.relax_disp.select_model(model=model) 8355 8356 # Cluster everything. 8357 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8358 8359 # Copy the data. 8360 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8361 8362 # Alias the spins. 8363 spin135S = cdp.mol[0].res[0].spin[0] 8364 spin135F = cdp.mol[0].res[0].spin[1] 8365 spin137S = cdp.mol[0].res[1].spin[0] 8366 spin137F = cdp.mol[0].res[1].spin[1] 8367 8368 # The R20 keys. 8369 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 8370 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8371 8372 # Set the cluster specific parameters (only for the first spin). 8373 spin135S.pA = 0.836591763632 8374 spin135S.kex = 241.806525261 8375 8376 # Set the initial parameter values. 8377 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 8378 spin135S.dw = 0.583003118785 8379 spin135S.dwH = 0.0361441944301 8380 8381 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 8382 spin135F.dw = 0.805849745104 8383 spin135F.dwH = 0.0215791945715 8384 8385 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 8386 spin137S.dw = 0.688107568372 8387 spin137S.dwH = 0.0344463604043 8388 8389 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 8390 spin137F.dw = 0.94978299907 8391 spin137F.dwH = 1.4818877939e-07 8392 8393 # Low precision optimisation. 8394 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 8395 8396 # Printout. 8397 print("\n\nOptimised parameters:\n") 8398 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8399 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8400 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8401 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8402 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8403 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8404 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8405 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8406 print("\n # Set the cluster specific parameters (only for the first spin).") 8407 print(" spin135S.pA = %s" % spin135S.pA) 8408 print(" spin135S.kex = %s" % spin135S.kex) 8409 print("\n # Set the initial parameter values.") 8410 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 8411 print(" spin135S.dw = %s" % spin135S.dw) 8412 print(" spin135S.dwH = %s" % spin135S.dwH) 8413 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 8414 print(" spin135F.dw = %s" % spin135F.dw) 8415 print(" spin135F.dwH = %s" % spin135F.dwH) 8416 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 8417 print(" spin137S.dw = %s" % spin137S.dw) 8418 print(" spin137S.dwH = %s" % spin137S.dwH) 8419 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 8420 print(" spin137F.dw = %s" % spin137F.dw) 8421 print(" spin137F.dwH = %s" % spin137F.dwH) 8422 8423 # Checks for residue :135S. 8424 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 8425 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 8426 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 8427 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 8428 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 8429 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 8430 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 8431 8432 # Checks for residue :135F. 8433 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 8434 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 8435 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 8436 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 8437 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 8438 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 8439 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8440 8441 # Checks for residue :137S. 8442 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8443 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8444 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8445 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8446 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8447 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8448 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8449 8450 # Checks for residue :137F. 8451 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8452 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8453 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8454 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8455 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8456 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8457 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8458 8459
8460 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8461 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8462 8463 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 8464 """ 8465 8466 # Reset. 8467 self.interpreter.reset() 8468 8469 # Create the data pipe and load the base data. 8470 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8471 self.interpreter.state.load(data_path+sep+'r2eff_values') 8472 8473 # The model data pipe. 8474 model = 'NS MMQ 2-site' 8475 pipe_name = "%s - relax_disp" % model 8476 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8477 self.interpreter.pipe.switch(pipe_name=pipe_name) 8478 8479 # Set the model. 8480 self.interpreter.relax_disp.select_model(model=model) 8481 8482 # Cluster everything. 8483 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8484 8485 # Copy the data. 8486 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8487 8488 # Alias the spins. 8489 spin135S = cdp.mol[0].res[0].spin[0] 8490 spin135F = cdp.mol[0].res[0].spin[1] 8491 spin137S = cdp.mol[0].res[1].spin[0] 8492 spin137F = cdp.mol[0].res[1].spin[1] 8493 8494 # The R20 keys. 8495 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8496 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8497 8498 # Set the cluster specific parameters (only for the first spin). 8499 spin135S.pA = 0.847378444499757 8500 spin135S.kex = 264.055604934724329 8501 8502 # Set the initial parameter values. 8503 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8504 spin135S.dw = 0.585574008745351 8505 spin135S.dwH = 0.000000000000002 8506 8507 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8508 spin135F.dw = 0.856699277665748 8509 spin135F.dwH = 0.000000000582587 8510 8511 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8512 spin137S.dw = 0.772904450844973 8513 spin137S.dwH = 0.183351478512970 8514 8515 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8516 spin137F.dw = 0.984568590342831 8517 spin137F.dwH = 0.000000001993458 8518 8519 # Low precision optimisation. 8520 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 8521 8522 # Printout. 8523 print("\n\nOptimised parameters:\n") 8524 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8525 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8526 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8527 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8528 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8529 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8530 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8531 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8532 8533 # FIXME: Remove this temporary return and properly check the results. 8534 return 8535 8536 # Checks for residue :135S. 8537 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8538 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8539 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8540 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8541 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8542 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8543 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8544 8545 # Checks for residue :135F. 8546 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8547 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8548 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8549 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8550 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8551 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8552 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8553 8554 # Checks for residue :137S. 8555 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8556 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8557 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8558 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8559 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8560 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8561 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8562 8563 # Checks for residue :137F. 8564 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8565 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8566 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8567 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8568 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8569 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8570 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8571 8572
8573 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8574 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8575 8576 # Setup the data. 8577 self.setup_tp02_data_to_ns_r1rho_2site() 8578 8579 # Alias the spins. 8580 spin1 = cdp.mol[0].res[0].spin[0] 8581 spin2 = cdp.mol[0].res[1].spin[0] 8582 8583 # The R20 keys. 8584 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8585 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8586 8587 # Checks for residue :1. 8588 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8589 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8590 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8591 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8592 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8593 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8594 8595 # Checks for residue :2. 8596 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8597 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8598 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8599 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8600 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8601 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8602 8603
8604 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8605 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8606 8607 # Setup the data. 8608 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8609 8610 # Alias the spins. 8611 spin1 = cdp.mol[0].res[0].spin[0] 8612 spin2 = cdp.mol[0].res[1].spin[0] 8613 8614 # The R20 keys. 8615 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8616 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8617 8618 # Checks for residue :1. 8619 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8620 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8621 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8622 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8623 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8624 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8625 8626 # Checks for residue :2. 8627 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8628 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8629 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8630 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8631 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8632 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8633 8634
8635 - def test_tp02_data_to_mp05(self):
8636 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8637 8638 # Fixed time variable and the models. 8639 ds.fixed = True 8640 ds.models = ['R2eff', 'MP05'] 8641 8642 # Execute the script. 8643 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8644 8645 # Switch back to the data pipe for the optimisation. 8646 self.interpreter.pipe.switch('MP05 - relax_disp') 8647 8648 # The equivalent MP05 parameters. 8649 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8650 pA = [0.775055484521586, 0.500000000036595] 8651 kex = [1235.20361276079, 2378.31403454691] 8652 delta_omega = [7.08194146569694, 5.4083562844306] 8653 chi2 = [0.0370400968727768, 0.182141732163934] 8654 8655 # Alias the spins. 8656 spin1 = cdp.mol[0].res[0].spin[0] 8657 spin2 = cdp.mol[0].res[1].spin[0] 8658 8659 # The R20 keys. 8660 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8661 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8662 8663 # Printout. 8664 print("\n\nOptimised parameters:\n") 8665 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8666 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8667 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8668 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8669 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8670 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8671 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8672 8673 # Check each spin. 8674 spin_index = 0 8675 for spin, spin_id in spin_loop(return_id=True): 8676 # Printout. 8677 print("\nSpin %s." % spin_id) 8678 8679 # Check the fitted parameters. 8680 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8681 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8682 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8683 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8684 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8685 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8686 8687 # Increment the spin index. 8688 spin_index += 1
8689 8690
8691 - def test_tp02_data_to_tap03(self):
8692 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8693 8694 # Fixed time variable and the models. 8695 ds.fixed = True 8696 ds.models = ['R2eff', 'TAP03'] 8697 8698 # Execute the script. 8699 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8700 8701 # Switch back to the data pipe for the optimisation. 8702 self.interpreter.pipe.switch('TAP03 - relax_disp') 8703 8704 # The equivalent TAP03 parameters. 8705 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8706 pA = [0.775042569092891, 0.500000000229685] 8707 kex = [1235.20852748765, 2379.47085580169] 8708 delta_omega = [7.08176806468445, 5.40708372863538] 8709 chi2 = [0.0371366837083293, 0.182212857256044] 8710 8711 # Alias the spins. 8712 spin1 = cdp.mol[0].res[0].spin[0] 8713 spin2 = cdp.mol[0].res[1].spin[0] 8714 8715 # The R20 keys. 8716 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8717 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8718 8719 # Printout. 8720 print("\n\nOptimised parameters:\n") 8721 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8722 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8723 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8724 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8725 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8726 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8727 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8728 8729 # Switch to the 'MP05' model data pipe, then check for each spin. 8730 self.interpreter.pipe.switch('TAP03 - relax_disp') 8731 spin_index = 0 8732 for spin, spin_id in spin_loop(return_id=True): 8733 # Printout. 8734 print("\nSpin %s." % spin_id) 8735 8736 # Check the fitted parameters. 8737 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8738 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8739 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8740 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8741 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8742 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8743 8744 # Increment the spin index. 8745 spin_index += 1
8746 8747
8749 """Implementation of Task #7882 U{https://web.archive.org/web/https://gna.org/task/?7882}: Implement Monte-Carlo simulation, where errors are generated with width of standard deviation or residuals""" 8750 8751 # First check that results are stored with minimisation, to make sure that Sum of Squares are stored (Chi2 without weighting) and degrees of freedom (dof) is stored. 8752 8753 # Load the results file from a clustered minimisation. 8754 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8755 self.interpreter.results.read(file_name) 8756 8757 # Get the spins, which was used for clustering. 8758 spins_cluster = cdp.clustering['sel'] 8759 spins_free = cdp.clustering['free spins'] 8760 8761 # For sanity check, calculate degree of freedom. 8762 cur_spin_id = spins_cluster[0] 8763 cur_spin = return_spin(cur_spin_id) 8764 8765 # Calculate total number of datapoins. 8766 N = len(spins_cluster) 8767 N_dp = N * len(cur_spin.r2eff) 8768 8769 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8770 N_par = cdp.spectrometer_frq_count * N + N + 1 + 1 8771 dof = N_dp - N_par 8772 8773 # Sanity check of parameters. 8774 print(N_par, N_dp) 8775 8776 # Number of MC 8777 mc_nr = 3 8778 8779 # Setup MC for errors generated from the distribution described by chi2 and degrees of freedom from best fit. 8780 self.interpreter.monte_carlo.setup(number=mc_nr) 8781 8782 # Create data. 8783 self.interpreter.monte_carlo.create_data(distribution="red_chi2") 8784 8785 # Setup MC again. 8786 self.interpreter.monte_carlo.setup(number=mc_nr) 8787 8788 # Create data, and set the fixed error value, without setting the correct distribution. 8789 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, fixed_error=1.) 8790 8791 # Setup MC again. 8792 self.interpreter.monte_carlo.setup(number=mc_nr) 8793 8794 # Create data, with fixed error distribution, but not setting the error value. 8795 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="fixed") 8796 8797 # Setup MC again. 8798 self.interpreter.monte_carlo.create_data(distribution="fixed", fixed_error=1.) 8799 8800 # Now select the R2eff model, and try again. Expect raising an error. 8801 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8802 8803 # Setup MC again. 8804 self.interpreter.monte_carlo.setup(number=mc_nr) 8805 8806 # Create data, and assert failure. 8807 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="red_chi2") 8808 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, method="direct", distribution="red_chi2")
8809 8810
8811 - def x_test_task_7882_kex_conf(self):
8812 """Test related to Task #7882 U{https://web.archive.org/web/https://gna.org/task/?7882}: Try making a confidence interval of kex. 8813 According to the regression book of Graphpad: U{http://www.graphpad.com/faq/file/Prism4RegressionBook.pdf}. 8814 Page 109-111. 8815 """ 8816 8817 # Load the results file from a clustered minimisation. 8818 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8819 self.interpreter.results.read(file_name) 8820 8821 # Get the spins, which was used for clustering. 8822 spins_cluster = cdp.clustering['sel'] 8823 spins_free = cdp.clustering['free spins'] 8824 8825 # For sanity check, calculate degree of freedom. 8826 cur_spin_id = spins_cluster[0] 8827 cur_spin = return_spin(cur_spin_id) 8828 8829 # Calculate total number of datapoins. 8830 Ns = len(spins_cluster) 8831 N_dp = Ns * len(cur_spin.r2eff) 8832 8833 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8834 N_par = cdp.spectrometer_frq_count * Ns + Ns + 1 + 1 8835 dof_fit = N_dp - N_par 8836 8837 # Assert values. 8838 self.assertEqual(Ns, 61) 8839 self.assertEqual(N_dp, 1952) 8840 self.assertEqual(N_par, 185) 8841 8842 # Confidence interval of kex. 8843 # The number of parameters to check is kex = 1. 8844 P = 1 8845 # Number of datapoints 8846 N = N_dp 8847 # The degrees of freedom for this confidence interval 8848 dof_conf = N - P 8849 8850 # The critical value of the F distribution with p-value of 0.05 for 95% confidence. 8851 # Can be calculated with microsoft excel: 8852 # F=FINV(0,05; P; dof_conf), F=FINV(0,05; P; dof_conf), F=FINV(0,05; 1; 1951)=3,846229551 8853 # Can also be calculated with: import scipy.stats; scipy.stats.f.isf(0.05, 1, 1951)=3.8462295505435562 8854 F = 3.8462295505435562 8855 # Then calculate the scaling of chi2, which is the weighted sum of squares of best fit. 8856 scale = F*P/dof_conf +1 8857 8858 # Get the sum of best fit. 8859 SSbest_fit = cur_spin.chi2 8860 SSbest_kex = cur_spin.kex 8861 8862 # Get the scaled sum of best fit 8863 SSall_fixed = SSbest_fit * scale 8864 8865 print(SSbest_fit, scale, SSall_fixed) 8866 8867 # Now generate a list of kex values to try. 8868 kex_cur = cur_spin.kex 8869 kex_list = linspace(kex_cur - 1500, kex_cur + 3000, 200) 8870 8871 chi2_list = [] 8872 8873 for kex in kex_list: 8874 self.interpreter.value.set(val=kex, param='kex') 8875 8876 # Calculate the chi2 values. 8877 self.interpreter.minimise.calculate(verbosity=0) 8878 8879 # Get the chi2 value 8880 chi2_cur = cur_spin.chi2 8881 print("kex=%3.2f, chi2=%3.2f"%(kex, chi2_cur), chi2_cur<SSall_fixed) 8882 8883 # Add to list 8884 chi2_list.append(chi2_cur) 8885 8886 # Now make to numpy array. 8887 chi2_list = asarray(chi2_list) 8888 8889 # Now make a selection mask based on the criteria. 8890 sel_mask = chi2_list < SSall_fixed 8891 8892 # Select values of kex, and chi2_list 8893 kex_sel = kex_list[sel_mask] 8894 chi2_sel = chi2_list[sel_mask] 8895 8896 # Now make plot 8897 print(SSbest_kex, SSbest_fit, SSall_fixed) 8898 print(kex_sel) 8899 print(chi2_sel) 8900 8901 if True: 8902 import matplotlib.pyplot as plt 8903 8904 plt.plot(kex_sel, chi2_sel, "bo") 8905 plt.plot(SSbest_kex, SSbest_fit, "g*") 8906 plt.show()
8907 8908
8909 - def test_tp02_data_to_tp02(self):
8910 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8911 8912 # Fixed time variable. 8913 ds.fixed = True 8914 8915 # Execute the script. 8916 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8917 8918 # The original parameters. 8919 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8920 pA = 0.7654321 8921 kex = 1234.56789 8922 delta_omega = [7.0, 9.0] 8923 8924 # The R20 keys. 8925 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8926 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8927 8928 # Switch to the 'TP02' model data pipe, then check for each spin. 8929 self.interpreter.pipe.switch('TP02 - relax_disp') 8930 spin_index = 0 8931 for spin, spin_id in spin_loop(return_id=True): 8932 # Printout. 8933 print("\nSpin %s." % spin_id) 8934 8935 # Check the fitted parameters. 8936 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8937 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8938 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8939 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8940 8941 # Increment the spin index. 8942 spin_index += 1
8943 8944
8946 """System test of the value.write function to write intensities for an R1rho setup. 8947 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 8948 8949 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 8950 """ 8951 8952 # Load the state. 8953 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8954 self.interpreter.state.load(statefile, force=True) 8955 8956 # Set filepaths. 8957 int_filepath = ds.tmpdir+sep+'int.out' 8958 8959 # Write out the intensity parameter file. 8960 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8961 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8962 8963 # Test the file exists. 8964 self.assert_(access(int_filepath, F_OK)) 8965 8966 # Open the files for testing. 8967 int_file = open(int_filepath, 'r') 8968 8969 # Loop over the intensity file to test values. 8970 for line in int_file: 8971 # Skip lines starting with #. 8972 if line[0] == "#": 8973 continue 8974 8975 # Split the line 8976 linesplit = line.split() 8977 8978 # Assume values 8979 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8980 self.assertEqual(linesplit[5], "115571.4") 8981 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8982 self.assertEqual(linesplit[5], "68377.52") 8983 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8984 self.assertEqual(linesplit[5], "9141.689") 8985 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8986 self.assertEqual(linesplit[5], "29123.77") 8987 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8988 self.assertEqual(linesplit[5], "58914.94") 8989 8990 # Close files 8991 int_file.close()
8992 8993
8995 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8996 8997 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 8998 """ 8999 9000 # Load the state. 9001 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 9002 self.interpreter.state.load(statefile, force=True) 9003 9004 # Set filepaths. 9005 theta_filepath = ds.tmpdir+sep+'theta.out' 9006 9007 # Write out the theta parameter file. 9008 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 9009 9010 # Test the file exists. 9011 self.assert_(access(theta_filepath, F_OK)) 9012 9013 # Open the files for testing. 9014 theta_file = open(theta_filepath, 'r') 9015 9016 # Loop over the theta file to test values. 9017 for line in theta_file: 9018 # Skip lines starting with #. 9019 if line[0] == "#": 9020 continue 9021 # Print lines, not including newline character. 9022 print(line[:-1]) 9023 9024 # Split the line 9025 linesplit = line.split() 9026 9027 # Assume values 9028 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 9029 self.assertNotEqual(linesplit[5], "None") 9030 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 9031 self.assertNotEqual(linesplit[5], "None") 9032 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 9033 self.assertNotEqual(linesplit[5], "None") 9034 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 9035 self.assertNotEqual(linesplit[5], "None") 9036 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 9037 self.assertNotEqual(linesplit[5], "None") 9038 9039 # Close files 9040 theta_file.close()
9041 9042
9044 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 9045 9046 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 9047 """ 9048 9049 # Load the state. 9050 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 9051 self.interpreter.state.load(statefile, force=True) 9052 9053 # Set filepaths. 9054 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 9055 9056 # Write out the w_eff parameter file. 9057 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 9058 9059 # Test the file exists. 9060 self.assert_(access(w_eff_filepath, F_OK)) 9061 9062 # Open the files for testing. 9063 w_eff_file = open(w_eff_filepath, 'r') 9064 9065 # Loop over the w_eff file to test values. 9066 for line in w_eff_file: 9067 # Skip lines starting with #. 9068 if line[0] == "#": 9069 continue 9070 # Print lines, not including newline character. 9071 print(line[:-1]) 9072 9073 # Split the line 9074 linesplit = line.split() 9075 9076 # Assume values 9077 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 9078 self.assertNotEqual(linesplit[5], "None") 9079 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 9080 self.assertNotEqual(linesplit[5], "None") 9081 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 9082 self.assertNotEqual(linesplit[5], "None") 9083 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 9084 self.assertNotEqual(linesplit[5], "None") 9085 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 9086 self.assertNotEqual(linesplit[5], "None") 9087 9088 # Close files 9089 w_eff_file.close()
9090 9091
9093 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 9094 9095 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 9096 """ 9097 9098 # Load the state. 9099 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 9100 self.interpreter.state.load(statefile, force=True) 9101 9102 # Set pipe name, bundle and type. 9103 pipe_name = 'base pipe' 9104 pipe_bundle = 'relax_disp' 9105 pipe_type = 'relax_disp' 9106 9107 # The path to the data files. 9108 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 9109 9110 # Deselect all spins 9111 self.interpreter.deselect.all() 9112 9113 # Specify spins to be selected. 9114 select_spin_ids = [ 9115 ":13@N", 9116 ":15@N", 9117 ":16@N", 9118 ":25@N", 9119 ":26@N", 9120 ":28@N", 9121 ":39@N", 9122 ":40@N", 9123 ":41@N", 9124 ":43@N", 9125 ":44@N", 9126 ":45@N", 9127 ":49@N", 9128 ":52@N", 9129 ":53@N"] 9130 9131 # Reverse the selection for the spins. 9132 for curspin in select_spin_ids: 9133 print("Selecting spin %s"%curspin) 9134 self.interpreter.deselect.reverse(spin_id=curspin) 9135 9136 # Read the R1 data 9137 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 9138 9139 # The dispersion models. 9140 MODELS = ['R2eff'] 9141 9142 # The grid search size (the number of increments per dimension). 9143 GRID_INC = 4 9144 9145 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 9146 MC_NUM = 3 9147 9148 # Model selection technique. 9149 MODSEL = 'AIC' 9150 9151 # Execute the auto-analysis (fast). 9152 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 9153 OPT_FUNC_TOL = 1e-1 9154 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 9155 OPT_MAX_ITERATIONS = 1000 9156 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 9157 9158 # Run the analysis. 9159 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 9160 9161 ## Check for file creation 9162 # Set filepaths. 9163 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 9164 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 9165 9166 # Test the files exists. 9167 self.assert_(access(theta_filepath, F_OK)) 9168 self.assert_(access(w_eff_filepath, F_OK)) 9169 9170 # Open the files for testing. 9171 theta_file = open(theta_filepath, 'r') 9172 theta_result = [ 9173 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 9174 "#\n", 9175 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 9176 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9177 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9178 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9179 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9180 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9181 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9182 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9183 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 9184 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9185 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 9186 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 9187 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9188 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9189 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9190 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9191 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9192 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 9193 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 9194 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9195 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 9196 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9197 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9198 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9199 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9200 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9201 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9202 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9203 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9204 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9205 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 9206 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 9207 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 9208 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9209 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 9210 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 9211 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 9212 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9213 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9214 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 9215 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9216 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9217 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 9218 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 9219 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9220 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9221 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9222 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9223 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9224 ] 9225 # Check the created theta file. 9226 lines = theta_file.readlines() 9227 for i in range(len(lines)): 9228 # Test lines starting with # 9229 if theta_result[i][0] == "#": 9230 self.assertEqual(theta_result[i], lines[i]) 9231 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9232 if theta_result[i] == lines[i]: 9233 self.assertEqual(theta_result[i], lines[i]) 9234 # If the line is not equal each other, make a slower comparison of values. 9235 else: 9236 # Print lines if they don't match. To help find differences. 9237 print(theta_result[i]) 9238 print(lines[i]) 9239 9240 # First test first 62 characters containing spin information 9241 self.assertEqual(theta_result[i][:62], lines[i][:62]) 9242 9243 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9244 theta_result_s = theta_result[i][62:].split()[::2] 9245 print(theta_result_s ) 9246 lines_s = lines[i][62:].split()[::2] 9247 print(lines_s) 9248 # Loop over the value elements 9249 for j in range(len(lines_s)): 9250 print(theta_result_s[j], lines_s[j]) 9251 # Assume a precision to digits. 9252 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 9253 9254 # Close file 9255 theta_file.close() 9256 9257 w_eff_file = open(w_eff_filepath, 'r') 9258 w_eff_result = [ 9259 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 9260 "#\n", 9261 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 9262 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9263 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9264 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9265 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9266 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9267 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9268 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9269 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 9270 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9271 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 9272 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 9273 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9274 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9275 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9276 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9277 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9278 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 9279 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 9280 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9281 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 9282 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9283 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9284 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9285 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9286 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9287 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9288 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9289 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9290 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9291 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 9292 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 9293 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 9294 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9295 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 9296 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 9297 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 9298 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9299 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9300 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 9301 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9302 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9303 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 9304 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 9305 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9306 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9307 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9308 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9309 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9310 ] 9311 # Check the created w_eff file. 9312 lines = w_eff_file.readlines() 9313 for i in range(len(lines)): 9314 # Test lines starting with # 9315 if w_eff_result[i][0] == "#": 9316 self.assertEqual(w_eff_result[i], lines[i]) 9317 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9318 if w_eff_result[i] == lines[i]: 9319 self.assertEqual(w_eff_result[i], lines[i]) 9320 # If the line is not equal each other, make a slower comparison of values. 9321 else: 9322 # Print lines if they don't match. To help find differences. 9323 print(w_eff_result[i]) 9324 print(lines[i]) 9325 9326 # First test first 62 characters containing spin information 9327 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 9328 9329 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9330 w_eff_result_s = w_eff_result[i][62:].split()[::2] 9331 print(w_eff_result_s ) 9332 lines_s = lines[i][62:].split()[::2] 9333 print(lines_s) 9334 # Loop over the value elements 9335 for j in range(len(lines_s)): 9336 print(w_eff_result_s[j], lines_s[j]) 9337 # Assume a precision to digits. 9338 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 9339 9340 # Close file 9341 w_eff_file.close()
9342 9343
9345 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 9346 9347 This follows Task 7822. 9348 U{task #7822<https://web.archive.org/web/https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 9349 9350 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 9351 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 9352 """ 9353 9354 # Load the data. 9355 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 9356 9357 # Set pipe name, bundle and type. 9358 pipe_name = 'base pipe' 9359 pipe_bundle = 'relax_disp' 9360 pipe_type = 'relax_disp' 9361 9362 # Create the data pipe. 9363 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 9364 9365 file = data_path + '1_setup_r1rho_GUI.py' 9366 self.interpreter.script(file=file, dir=None) 9367 9368 # Deselect all spins. 9369 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 9370 9371 # Select one spin. 9372 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 9373 9374 # Set the model. 9375 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 9376 9377 # Check if intensity errors have already been calculated. 9378 check_intensity_errors() 9379 9380 # Do a grid search. 9381 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 9382 9383 # Set algorithm. 9384 min_algor = 'Newton' 9385 constraints = True 9386 if constraints: 9387 min_options = ('%s'%(min_algor),) 9388 #min_algor = 'Log barrier' 9389 min_algor = 'Method of Multipliers' 9390 scaling_matrix = assemble_scaling_matrix(scaling=True) 9391 9392 # Collect spins 9393 all_spin_ids = [] 9394 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9395 all_spin_ids.append(spin_id) 9396 9397 spins = spin_ids_to_containers(all_spin_ids[:1]) 9398 9399 # Get constraints 9400 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 9401 else: 9402 min_options = () 9403 A, b = None, None 9404 min_options = () 9405 sim_boot = 200 9406 scaling_list = [1.0, 1.0] 9407 9408 # Minimise. 9409 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 9410 9411 # Loop over old err attributes. 9412 err_attr_list = ['r2eff_err', 'i0_err'] 9413 9414 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9415 # Loop over old err attributes. 9416 for err_attr in err_attr_list: 9417 if hasattr(cur_spin, err_attr): 9418 delattr(cur_spin, err_attr) 9419 9420 # Collect the estimation data from boot. 9421 my_dic = {} 9422 param_key_list = [] 9423 est_keys = [] 9424 est_key = '-2' 9425 est_keys.append(est_key) 9426 spin_id_list = [] 9427 9428 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9429 # Add key to dic. 9430 my_dic[spin_id] = {} 9431 9432 # Add key for estimate. 9433 my_dic[spin_id][est_key] = {} 9434 9435 # Add spin key to list. 9436 spin_id_list.append(spin_id) 9437 9438 # Generate spin string. 9439 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9440 9441 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9442 # Generate the param_key. 9443 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9444 9445 # Append key. 9446 param_key_list.append(param_key) 9447 9448 # Add key to dic. 9449 my_dic[spin_id][est_key][param_key] = {} 9450 9451 values = [] 9452 errors = [] 9453 times = [] 9454 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 9455 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 9456 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 9457 times.append(time) 9458 9459 # Convert to numpy array. 9460 values = asarray(values) 9461 errors = asarray(errors) 9462 times = asarray(times) 9463 9464 r2eff = getattr(cur_spin, 'r2eff')[param_key] 9465 i0 = getattr(cur_spin, 'i0')[param_key] 9466 9467 R_m_sim_l = [] 9468 I0_m_sim_l = [] 9469 for j in range(sim_boot): 9470 if j in range(0, 100000, 100): 9471 print("Simulation %i"%j) 9472 # Start minimisation. 9473 9474 # Produce errors 9475 I_err = [] 9476 for j, error in enumerate(errors): 9477 I_error = gauss(values[j], error) 9478 I_err.append(I_error) 9479 # Convert to numpy array. 9480 I_err = asarray(I_err) 9481 9482 x0 = [r2eff, i0] 9483 model = Relax_fit_opt(num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 9484 9485 # Ref input. 9486 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 9487 # l=l, u=u, c=c, dc=dc, d2c=d2c 9488 # l: Lower bound constraint vector (l <= x <= u). 9489 # u: Upper bound constraint vector (l <= x <= u). 9490 # c: User supplied constraint function. 9491 # dc: User supplied constraint gradient function. 9492 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 9493 9494 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 9495 R_m_sim_l.append(R_m_sim_j) 9496 I0_m_sim_l.append(I0_m_sim_j) 9497 9498 # Get stats on distribution. 9499 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 9500 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 9501 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 9502 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 9503 9504 # Estimate R2eff errors. 9505 self.interpreter.relax_disp.r2eff_err_estimate() 9506 9507 est_key = '-1' 9508 est_keys.append(est_key) 9509 9510 # Collect data. 9511 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9512 # Add key for estimate. 9513 my_dic[spin_id][est_key] = {} 9514 9515 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9516 # Generate the param_key. 9517 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9518 9519 # Add key to dic. 9520 my_dic[spin_id][est_key][param_key] = {} 9521 9522 # Get the value. 9523 # Loop over err attributes. 9524 for err_attr in err_attr_list: 9525 if hasattr(cur_spin, err_attr): 9526 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9527 else: 9528 get_err_attr = 0.0 9529 9530 # Save to dic. 9531 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9532 9533 9534 # Make Carlo Simulations number 9535 mc_number_list = list(range(0, 1000, 250)) 9536 9537 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 9538 9539 # Loop over the Monte Carlo simulations: 9540 for number in mc_number_list: 9541 # First delete old simulations. 9542 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9543 # Loop over old err attributes. 9544 for err_attr in err_attr_list: 9545 if hasattr(cur_spin, err_attr): 9546 delattr(cur_spin, err_attr) 9547 9548 # Loop over the simulated attributes. 9549 for sim_attr in sim_attr_list: 9550 if hasattr(cur_spin, sim_attr): 9551 delattr(cur_spin, sim_attr) 9552 9553 self.interpreter.monte_carlo.setup(number=number) 9554 self.interpreter.monte_carlo.create_data() 9555 self.interpreter.monte_carlo.initial_values() 9556 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 9557 self.interpreter.eliminate() 9558 self.interpreter.monte_carlo.error_analysis() 9559 9560 est_key = '%i'%number 9561 est_keys.append(est_key) 9562 9563 # Collect data. 9564 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9565 # Add key for estimate. 9566 my_dic[spin_id][est_key] = {} 9567 9568 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9569 # Generate the param_key. 9570 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9571 9572 # Add key to dic. 9573 my_dic[spin_id][est_key][param_key] = {} 9574 9575 # Get the value. 9576 # Loop over err attributes. 9577 for err_attr in err_attr_list: 9578 if hasattr(cur_spin, err_attr): 9579 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9580 else: 9581 get_err_attr = 0.0 9582 9583 # Save to dic. 9584 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9585 9586 # Set what to extract. 9587 err_attr = err_attr_list[0] 9588 9589 # Define list with text. 9590 text_list = [] 9591 9592 # Now loop through the data. 9593 for spin_id in spin_id_list: 9594 for est_key in est_keys: 9595 # Define list to pickup data. 9596 r2eff_err_list = [] 9597 9598 for param_key in param_key_list: 9599 # Get the value. 9600 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9601 9602 # Add to list. 9603 r2eff_err_list.append(r2eff_err) 9604 9605 # Sum the list 9606 sum_array = sum(array(r2eff_err_list)) 9607 9608 # Join floats to string. 9609 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9610 9611 # Define print string. 9612 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9613 text_list.append(text) 9614 9615 9616 # Now print. 9617 filepath = NamedTemporaryFile(delete=False).name 9618 # Open the files for testing. 9619 w_file = open(filepath, 'w') 9620 9621 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9622 9623 for text in text_list: 9624 # Print. 9625 print(text) 9626 9627 # Write to file. 9628 w_file.write(text+"\n") 9629 9630 # Close files 9631 w_file.close() 9632 9633 print("Filepath is: %s"%filepath) 9634 print("Start 'gnuplot' and write:") 9635 print("set term dumb") 9636 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9637 9638
9639 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9640 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9641 9642 # Check the kex value of residue 52 9643 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9644 9645 # Print results for each model. 9646 print("\n\n################") 9647 print("Printing results") 9648 print("################\n") 9649 for model in models: 9650 # Skip R2eff model. 9651 if model == MODEL_R2EFF: 9652 continue 9653 9654 # Switch to pipe. 9655 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9656 print("\nModel: %s" % (model)) 9657 9658 # Loop over the spins. 9659 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9660 # Generate spin string. 9661 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9662 9663 # Loop over the parameters. 9664 print("Optimised parameters for spin: %s" % (spin_string)) 9665 for param in cur_spin.params + ['chi2']: 9666 # Get the value. 9667 if param in ['r1', 'r2']: 9668 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9669 # Generate the R20 key. 9670 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9671 9672 # Get the value. 9673 value = getattr(cur_spin, param)[r20_key] 9674 9675 # Print value. 9676 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9677 9678 # Compare values. 9679 if spin_id == ':52@N': 9680 if param == 'r1': 9681 if model == MODEL_NOREX: 9682 if r2eff_estimate == 'direct': 9683 self.assertAlmostEqual(value, 1.46138805) 9684 elif r2eff_estimate == 'MC2000': 9685 self.assertAlmostEqual(value, 1.46328102) 9686 elif r2eff_estimate == 'chi2_pyt': 9687 self.assertAlmostEqual(value, 1.43820629) 9688 elif model == MODEL_DPL94: 9689 if r2eff_estimate == 'direct': 9690 self.assertAlmostEqual(value, 1.44845742) 9691 elif r2eff_estimate == 'MC2000': 9692 self.assertAlmostEqual(value, 1.45019848) 9693 elif r2eff_estimate == 'chi2_pyt': 9694 self.assertAlmostEqual(value, 1.44666512) 9695 elif model == MODEL_TP02: 9696 if r2eff_estimate == 'direct': 9697 self.assertAlmostEqual(value, 1.54354392) 9698 elif r2eff_estimate == 'MC2000': 9699 self.assertAlmostEqual(value, 1.54352369) 9700 elif r2eff_estimate == 'chi2_pyt': 9701 self.assertAlmostEqual(value, 1.55964020) 9702 elif model == MODEL_TAP03: 9703 if r2eff_estimate == 'direct': 9704 self.assertAlmostEqual(value, 1.54356410) 9705 elif r2eff_estimate == 'MC2000': 9706 self.assertAlmostEqual(value, 1.54354367) 9707 elif r2eff_estimate == 'chi2_pyt': 9708 self.assertAlmostEqual(value, 1.55967157) 9709 elif model == MODEL_MP05: 9710 if r2eff_estimate == 'direct': 9711 self.assertAlmostEqual(value, 1.54356416) 9712 elif r2eff_estimate == 'MC2000': 9713 self.assertAlmostEqual(value, 1.54354372) 9714 elif r2eff_estimate == 'chi2_pyt': 9715 self.assertAlmostEqual(value, 1.55967163) 9716 elif model == MODEL_NS_R1RHO_2SITE: 9717 if r2eff_estimate == 'direct': 9718 self.assertAlmostEqual(value, 1.41359221, 5) 9719 elif r2eff_estimate == 'MC2000': 9720 self.assertAlmostEqual(value, 1.41321968, 5) 9721 elif r2eff_estimate == 'chi2_pyt': 9722 self.assertAlmostEqual(value, 1.36303129, 5) 9723 9724 elif param == 'r2': 9725 if model == MODEL_NOREX: 9726 if r2eff_estimate == 'direct': 9727 self.assertAlmostEqual(value, 11.48392439) 9728 elif r2eff_estimate == 'MC2000': 9729 self.assertAlmostEqual(value, 11.48040934) 9730 elif r2eff_estimate == 'chi2_pyt': 9731 self.assertAlmostEqual(value, 11.47224488) 9732 elif model == MODEL_DPL94: 9733 if r2eff_estimate == 'direct': 9734 self.assertAlmostEqual(value, 10.15688372, 6) 9735 elif r2eff_estimate == 'MC2000': 9736 self.assertAlmostEqual(value, 10.16304887, 6) 9737 elif r2eff_estimate == 'chi2_pyt': 9738 self.assertAlmostEqual(value, 9.20037797, 6) 9739 elif model == MODEL_TP02: 9740 if r2eff_estimate == 'direct': 9741 self.assertAlmostEqual(value, 9.72654896, 6) 9742 elif r2eff_estimate == 'MC2000': 9743 self.assertAlmostEqual(value, 9.72772726, 6) 9744 elif r2eff_estimate == 'chi2_pyt': 9745 self.assertAlmostEqual(value, 9.53948340, 6) 9746 elif model == MODEL_TAP03: 9747 if r2eff_estimate == 'direct': 9748 self.assertAlmostEqual(value, 9.72641887, 6) 9749 elif r2eff_estimate == 'MC2000': 9750 self.assertAlmostEqual(value, 9.72759374, 6) 9751 elif r2eff_estimate == 'chi2_pyt': 9752 self.assertAlmostEqual(value, 9.53926913, 6) 9753 elif model == MODEL_MP05: 9754 if r2eff_estimate == 'direct': 9755 self.assertAlmostEqual(value, 9.72641723, 6) 9756 elif r2eff_estimate == 'MC2000': 9757 self.assertAlmostEqual(value, 9.72759220, 6) 9758 elif r2eff_estimate == 'chi2_pyt': 9759 self.assertAlmostEqual(value, 9.53926778, 6) 9760 elif model == MODEL_NS_R1RHO_2SITE: 9761 if r2eff_estimate == 'direct': 9762 self.assertAlmostEqual(value, 9.34531535, 5) 9763 elif r2eff_estimate == 'MC2000': 9764 self.assertAlmostEqual(value, 9.34602793, 5) 9765 elif r2eff_estimate == 'chi2_pyt': 9766 self.assertAlmostEqual(value, 9.17631409, 5) 9767 9768 # For all other parameters. 9769 else: 9770 # Get the value. 9771 value = getattr(cur_spin, param) 9772 9773 # Print value. 9774 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9775 9776 # Compare values. 9777 if spin_id == ':52@N': 9778 if param == 'phi_ex': 9779 if model == MODEL_DPL94: 9780 if r2eff_estimate == 'direct': 9781 self.assertAlmostEqual(value, 0.07599563) 9782 elif r2eff_estimate == 'MC2000': 9783 self.assertAlmostEqual(value, 0.07561937) 9784 elif r2eff_estimate == 'chi2_pyt': 9785 self.assertAlmostEqual(value, 0.12946061) 9786 9787 elif param == 'pA': 9788 if model == MODEL_TP02: 9789 if r2eff_estimate == 'direct': 9790 self.assertAlmostEqual(value, 0.88827040) 9791 elif r2eff_estimate == 'MC2000': 9792 self.assertAlmostEqual(value, 0.88807487) 9793 elif r2eff_estimate == 'chi2_pyt': 9794 self.assertAlmostEqual(value, 0.87746233) 9795 elif model == MODEL_TAP03: 9796 if r2eff_estimate == 'direct': 9797 self.assertAlmostEqual(value, 0.88828922) 9798 elif r2eff_estimate == 'MC2000': 9799 self.assertAlmostEqual(value, 0.88809318) 9800 elif r2eff_estimate == 'chi2_pyt': 9801 self.assertAlmostEqual(value, 0.87747558) 9802 elif model == MODEL_MP05: 9803 if r2eff_estimate == 'direct': 9804 self.assertAlmostEqual(value, 0.88828924, 6) 9805 elif r2eff_estimate == 'MC2000': 9806 self.assertAlmostEqual(value, 0.88809321) 9807 elif r2eff_estimate == 'chi2_pyt': 9808 self.assertAlmostEqual(value, 0.87747562) 9809 elif model == MODEL_NS_R1RHO_2SITE: 9810 if r2eff_estimate == 'direct': 9811 self.assertAlmostEqual(value, 0.94504369, 6) 9812 elif r2eff_estimate == 'MC2000': 9813 self.assertAlmostEqual(value, 0.94496541, 6) 9814 elif r2eff_estimate == 'chi2_pyt': 9815 self.assertAlmostEqual(value, 0.92084707, 6) 9816 9817 elif param == 'dw': 9818 if model == MODEL_TP02: 9819 if r2eff_estimate == 'direct': 9820 self.assertAlmostEqual(value, 1.08875840, 6) 9821 elif r2eff_estimate == 'MC2000': 9822 self.assertAlmostEqual(value, 1.08765638, 6) 9823 elif r2eff_estimate == 'chi2_pyt': 9824 self.assertAlmostEqual(value, 1.09753230, 6) 9825 elif model == MODEL_TAP03: 9826 if r2eff_estimate == 'direct': 9827 self.assertAlmostEqual(value, 1.08837238, 6) 9828 elif r2eff_estimate == 'MC2000': 9829 self.assertAlmostEqual(value, 1.08726698, 6) 9830 elif r2eff_estimate == 'chi2_pyt': 9831 self.assertAlmostEqual(value, 1.09708821, 6) 9832 elif model == MODEL_MP05: 9833 if r2eff_estimate == 'direct': 9834 self.assertAlmostEqual(value, 1.08837241, 6) 9835 elif r2eff_estimate == 'MC2000': 9836 self.assertAlmostEqual(value, 1.08726706, 6) 9837 elif r2eff_estimate == 'chi2_pyt': 9838 self.assertAlmostEqual(value, 1.09708832, 6) 9839 elif model == MODEL_NS_R1RHO_2SITE: 9840 if r2eff_estimate == 'direct': 9841 self.assertAlmostEqual(value, 1.56001812, 5) 9842 elif r2eff_estimate == 'MC2000': 9843 self.assertAlmostEqual(value, 1.55833321, 5) 9844 elif r2eff_estimate == 'chi2_pyt': 9845 self.assertAlmostEqual(value, 1.36406712, 5) 9846 9847 elif param == 'kex': 9848 if model == MODEL_DPL94: 9849 if r2eff_estimate == 'direct': 9850 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9851 elif r2eff_estimate == 'MC2000': 9852 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9853 elif r2eff_estimate == 'chi2_pyt': 9854 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9855 elif model == MODEL_TP02: 9856 if r2eff_estimate == 'direct': 9857 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9858 elif r2eff_estimate == 'MC2000': 9859 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9860 elif r2eff_estimate == 'chi2_pyt': 9861 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9862 elif model == MODEL_TAP03: 9863 if r2eff_estimate == 'direct': 9864 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9865 elif r2eff_estimate == 'MC2000': 9866 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9867 elif r2eff_estimate == 'chi2_pyt': 9868 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9869 elif model == MODEL_MP05: 9870 if r2eff_estimate == 'direct': 9871 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9872 elif r2eff_estimate == 'MC2000': 9873 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9874 elif r2eff_estimate == 'chi2_pyt': 9875 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9876 elif model == MODEL_NS_R1RHO_2SITE: 9877 if r2eff_estimate == 'direct': 9878 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9879 elif r2eff_estimate == 'MC2000': 9880 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9881 elif r2eff_estimate == 'chi2_pyt': 9882 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9883 9884 elif param == 'chi2': 9885 if model == MODEL_NOREX: 9886 if r2eff_estimate == 'direct': 9887 self.assertAlmostEqual(value, 848.42016907, 5) 9888 elif r2eff_estimate == 'MC2000': 9889 self.assertAlmostEqual(value, 3363.95829122, 5) 9890 elif r2eff_estimate == 'chi2_pyt': 9891 self.assertAlmostEqual(value, 5976.49946726, 5) 9892 elif model == MODEL_DPL94: 9893 if r2eff_estimate == 'direct': 9894 self.assertAlmostEqual(value, 179.47041241) 9895 elif r2eff_estimate == 'MC2000': 9896 self.assertAlmostEqual(value, 710.24767560) 9897 elif r2eff_estimate == 'chi2_pyt': 9898 self.assertAlmostEqual(value, 612.72616697, 5) 9899 elif model == MODEL_TP02: 9900 if r2eff_estimate == 'direct': 9901 self.assertAlmostEqual(value, 29.33882530, 6) 9902 elif r2eff_estimate == 'MC2000': 9903 self.assertAlmostEqual(value, 114.47142772, 6) 9904 elif r2eff_estimate == 'chi2_pyt': 9905 self.assertAlmostEqual(value, 250.50838162, 5) 9906 elif model == MODEL_TAP03: 9907 if r2eff_estimate == 'direct': 9908 self.assertAlmostEqual(value, 29.29050673, 6) 9909 elif r2eff_estimate == 'MC2000': 9910 self.assertAlmostEqual(value, 114.27987534) 9911 elif r2eff_estimate == 'chi2_pyt': 9912 self.assertAlmostEqual(value, 250.04050719, 5) 9913 elif model == MODEL_MP05: 9914 if r2eff_estimate == 'direct': 9915 self.assertAlmostEqual(value, 29.29054301, 6) 9916 elif r2eff_estimate == 'MC2000': 9917 self.assertAlmostEqual(value, 114.28002272) 9918 elif r2eff_estimate == 'chi2_pyt': 9919 self.assertAlmostEqual(value, 250.04077478, 5) 9920 elif model == MODEL_NS_R1RHO_2SITE: 9921 if r2eff_estimate == 'direct': 9922 self.assertAlmostEqual(value, 34.44010543, 6) 9923 elif r2eff_estimate == 'MC2000': 9924 self.assertAlmostEqual(value, 134.14368365) 9925 elif r2eff_estimate == 'chi2_pyt': 9926 self.assertAlmostEqual(value, 278.55121388, 5) 9927 9928 9929 # Print the final pipe. 9930 model = 'final' 9931 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9932 print("\nFinal pipe") 9933 9934 # Loop over the spins. 9935 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9936 # Generate spin string. 9937 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9938 9939 # Loop over the parameters. 9940 print("Optimised model for spin: %s" % (spin_string)) 9941 param = 'model' 9942 9943 # Get the value. 9944 value = getattr(cur_spin, param) 9945 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9946 9947 9948 ### Now check some of the written out files. 9949 file_names = ['r1rho_prime', 'r1'] 9950 9951 for file_name_i in file_names: 9952 9953 # Make the file name. 9954 file_name = "%s.out" % file_name_i 9955 9956 # Get the file path. 9957 file_path = get_file_path(file_name, result_dir_name + sep + model) 9958 9959 # Test the file exists. 9960 print("Testing file access to: %s"%file_path) 9961 self.assert_(access(file_path, F_OK)) 9962 9963 # Now open, and compare content, line by line. 9964 file_prod = open(file_path) 9965 lines_prod = file_prod.readlines() 9966 file_prod.close() 9967 9968 # Loop over the lines. 9969 for i, line in enumerate(lines_prod): 9970 # Make the string test 9971 line_split = line.split() 9972 9973 # Continue for comment lines. 9974 if line_split[0] == "#": 9975 print(line), 9976 continue 9977 9978 # Assign the split of the line. 9979 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9980 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9981 9982 if res_num == '52': 9983 # Assert that the value is not None. 9984 self.assertNotEqual(val, 'None')
9985