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-2015 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, linspace, log, save, std, sum, zeros 
  28  from minfx.generic import generic_minimise 
  29  from random import gauss 
  30  import re, math 
  31  from sys import version_info 
  32  from tempfile import mkdtemp, NamedTemporaryFile 
  33   
  34   
  35  # relax module imports. 
  36  from auto_analyses import relax_disp 
  37  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  38  from data_store import Relax_data_store; ds = Relax_data_store() 
  39  import dep_check 
  40  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_ANALYTIC_CPMG, MODEL_LIST_FULL, MODEL_LIST_NUMERIC_CPMG, 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_NS_R1RHO_3SITE, MODEL_NS_R1RHO_3SITE_LINEAR, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  41  from lib.errors import RelaxError 
  42  from lib.io import extract_data, get_file_path, open_read_file 
  43  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  44  from pipe_control.mol_res_spin import display_spin, generate_spin_string, return_spin, spin_loop 
  45  from pipe_control.minimise import assemble_scaling_matrix 
  46  from pipe_control.pipes import display 
  47  from specific_analyses.relax_disp.checks import check_missing_r1 
  48  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  49  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, has_r1rho_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_exp_frq_offset_point_time, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  50  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 
  51  from specific_analyses.relax_disp.model import models_info, nesting_param 
  52  from specific_analyses.relax_disp.parameters import linear_constraints 
  53  from status import Status; status = Status() 
  54  from target_functions.relax_fit_wrapper import Relax_fit_opt 
  55  from test_suite.system_tests.base_classes import SystemTestCase 
  56   
  57   
58 -class Relax_disp(SystemTestCase):
59 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 60
61 - def __init__(self, methodName='runTest'):
62 """Skip certain tests if the C modules are non-functional. 63 64 @keyword methodName: The name of the test. 65 @type methodName: str 66 """ 67 68 # Execute the base class method. 69 super(Relax_disp, self).__init__(methodName) 70 71 # Tests to skip. 72 blacklist = [ 73 'test_m61b_data_to_m61b' 74 ] 75 if methodName in blacklist: 76 status.skipped_tests.append([methodName, None, self._skip_type]) 77 78 # Missing module. 79 if not dep_check.C_module_exp_fn: 80 # The list of tests to skip. 81 to_skip = [ 82 "test_bug_atul_srivastava", 83 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 84 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 85 "test_estimate_r2eff_err", 86 "test_estimate_r2eff_err_auto", 87 "test_estimate_r2eff_err_methods", 88 "test_finite_value", 89 "test_exp_fit", 90 "test_m61_exp_data_to_m61", 91 "test_r1rho_kjaergaard_auto", 92 "test_r1rho_kjaergaard_auto_check_graphs", 93 "test_r1rho_kjaergaard_man", 94 "test_r1rho_kjaergaard_missing_r1", 95 "test_value_write_calc_rotating_frame_params_auto_analysis" 96 ] 97 98 # Store in the status object. 99 if methodName in to_skip: 100 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 101 102 # If not scipy.optimize.leastsq. 103 if not dep_check.scipy_module: 104 # The list of tests to skip. 105 to_skip = [ 106 "test_estimate_r2eff_err_methods" 107 ] 108 109 # Store in the status object. 110 if methodName in to_skip: 111 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 112 113 # If not NMRPipe showApod program in PATH. 114 if not dep_check.showApod_software: 115 # The list of tests to skip. 116 to_skip = [ 117 "test_show_apod_extract", 118 "test_show_apod_rmsd", 119 "test_show_apod_rmsd_to_file", 120 "test_show_apod_rmsd_dir_to_files" 121 ] 122 123 # Store in the status object. 124 if methodName in to_skip: 125 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 126 127 # If not matplotlib module 128 if not dep_check.matplotlib_module: 129 # The list of tests to skip. 130 to_skip = [ 131 "test_repeat_cpmg" 132 ] 133 134 # Store in the status object. 135 if methodName in to_skip: 136 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
137 138
139 - def setUp(self):
140 """Set up for all the functional tests.""" 141 142 # Create the data pipe. 143 self.interpreter.pipe.create('relax_disp', 'relax_disp') 144 145 # Create a temporary directory for dumping files. 146 ds.tmpdir = mkdtemp() 147 self.tmpdir = ds.tmpdir
148 149
150 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
151 """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. 152 153 @keyword folder: The name of the folder for the test data. 154 @type folder: str 155 @keyword model_analyse: The name of the model which will be tested. 156 @type model_analyse: str 157 """ 158 159 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 160 161 # Data. 162 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 163 164 ## Experiments 165 # Exp 1 166 sfrq_1 = 500.0*1E6 167 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 168 time_T2_1 = 0.05 169 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 170 # 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. 171 #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] 172 r2eff_errs_1 = [0.0] * len(ncycs_1) 173 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 174 175 sfrq_2 = 600.0*1E6 176 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 177 time_T2_2 = 0.06 178 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 179 # 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. 180 #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] 181 r2eff_errs_2 = [0.0] * len(ncycs_2) 182 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 183 184 sfrq_3 = 700.0*1E6 185 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 186 time_T2_3 = 0.07 187 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 188 # 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. 189 #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] 190 r2eff_errs_3 = [0.0] * len(ncycs_3) 191 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 192 193 # Collect all exps 194 exps = [exp_1, exp_2, exp_3] 195 196 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] 197 dw_arr = [1.0, 2.0, 3.0, 4.0] 198 pA_arr = [0.9] 199 kex_arr = [1000.] 200 201 spins = [ 202 ['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]}], 203 ['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]}], 204 ['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]}], 205 ['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]}], 206 ] 207 208 # Create the data pipe. 209 pipe_name = 'base pipe' 210 pipe_type = 'relax_disp' 211 pipe_bundle = 'relax_disp' 212 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 213 214 # Generate the sequence. 215 for res_name, res_num, spin_name, params in spins: 216 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 217 218 # Set isotope 219 self.interpreter.spin.isotope('15N', spin_id='@N') 220 221 # Now loop over the experiments, to set the variables in relax. 222 exp_ids = [] 223 for exp_i in exps: 224 sfrq, time_T2, ncycs, r2eff_errs = exp_i 225 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 226 exp_ids.append(exp_id) 227 228 ids = [] 229 for ncyc in ncycs: 230 nu_cpmg = ncyc / time_T2 231 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 232 ids.append(cur_id) 233 234 # Set the spectrometer frequency. 235 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 236 237 # Set the experiment type. 238 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 239 240 # Set the relaxation dispersion CPMG constant time delay T (in s). 241 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 242 243 # Set the relaxation dispersion CPMG frequencies. 244 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 245 246 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 247 248 ### Now do fitting. 249 # Change pipe. 250 251 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 252 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 253 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 254 255 # Now read data in. 256 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 257 exp_id = exp_ids[mi] 258 exp_i = exps[mi] 259 sfrq, time_T2, ncycs, r2eff_errs = exp_i 260 261 # Then loop over the spins. 262 for res_name, res_num, spin_name, params in spins: 263 cur_spin_id = ":%i@%s"%(res_num, spin_name) 264 265 # Define file name 266 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 267 268 # Read in the R2eff file to put into spin structure. 269 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) 270 271 # Then select model. 272 self.interpreter.relax_disp.select_model(model=model_analyse) 273 274 # Then cluster 275 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 276 277 # Grid search 278 low_arr = R20 + dw_arr + pA_arr + kex_arr 279 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 280 281 # Then loop over the defined spins and read the parameters. 282 for i in range(len(spins)): 283 res_name, res_num, spin_name, params = spins[i] 284 cur_spin_id = ":%i@%s"%(res_num, spin_name) 285 cur_spin = return_spin(cur_spin_id) 286 287 for mo_param in cur_spin.params: 288 print(mo_param) 289 # The R2 is a dictionary, depending on spectrometer frequency. 290 if isinstance(getattr(cur_spin, mo_param), dict): 291 for key, val in list(getattr(cur_spin, mo_param).items()): 292 should_be = params[mo_param][key] 293 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 294 self.assertAlmostEqual(val, should_be) 295 else: 296 should_be = float(params[mo_param]) 297 val = getattr(cur_spin, mo_param) 298 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 299 self.assertAlmostEqual(val, should_be) 300 301 # Test chi2. 302 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 303 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
304 305
306 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
307 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 308 309 # The path to the data files. 310 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 311 312 # Set pipe name, bundle and type. 313 ds.pipe_name = 'base pipe' 314 ds.pipe_bundle = 'relax_disp' 315 ds.pipe_type = 'relax_disp' 316 317 # Create the data pipe. 318 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 319 320 # Read the spins. 321 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 322 323 # Name the isotope for field strength scaling. 324 self.interpreter.spin.isotope(isotope='15N') 325 326 # Set number of experiments to be used. 327 NR_exp = 70 328 329 # Load the experiments settings file. 330 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 331 expfileslines = expfile.readlines()[:NR_exp] 332 expfile.close() 333 334 # In MHz 335 yOBS = 81.050 336 # In ppm 337 yCAR = 118.078 338 centerPPM_N15 = yCAR 339 340 ## Read the chemical shift data. 341 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 342 343 # The lock power to field, has been found in an calibration experiment. 344 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 345 346 # Apply spectra settings. 347 # Count settings 348 j = 0 349 for i in range(len(expfileslines)): 350 line = expfileslines[i] 351 if line[0] == "#": 352 continue 353 else: 354 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 355 DIRN = line.split()[0] 356 I = int(line.split()[1]) 357 deltadof2 = line.split()[2] 358 dpwr2slock = line.split()[3] 359 ncyc = int(line.split()[4]) 360 trim = float(line.split()[5]) 361 ss = int(line.split()[6]) 362 set_sfrq = float(line.split()[7]) 363 apod_rmsd = float(line.split()[8]) 364 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 365 366 # Calculate spin_lock time 367 time_sl = 2*ncyc*trim 368 369 # Define file name for peak list. 370 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 371 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 372 373 # Load the peak intensities. 374 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 375 376 # Set the peak intensity errors, as defined as the baseplane RMSD. 377 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 378 379 # Set the relaxation dispersion experiment type. 380 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 381 382 # Set The spin-lock field strength, nu1, in Hz 383 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 384 385 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 386 frq_N15_Hz = yOBS * 1E6 387 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 388 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 389 390 # Set The spin-lock offset, omega_rf, in ppm. 391 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 392 393 # Set the relaxation times (in s). 394 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 395 396 # Set the spectrometer frequency. 397 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 398 399 # Add to counter 400 j += 1 401 402 403 print("Testing the number of settings") 404 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type))) 405 self.assertEqual(70, len(expfileslines)) 406 self.assertEqual(69, j) 407 self.assertEqual(69, len(cdp.exp_type)) 408 409 # Cluster spins 410 for curspin in cluster_ids: 411 print("Adding spin %s to cluster"%curspin) 412 self.interpreter.relax_disp.cluster('model_cluster', curspin) 413 414 # De-select for analysis those spins who have not been clustered 415 for free_spin in cdp.clustering['free spins']: 416 print("Deselecting free spin %s"%free_spin) 417 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 418 419 420 #Paper reference values 421 # 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 422 # 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 423 ds.ref = dict() 424 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] 425 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] 426 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] 427 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] 428 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] 429 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] 430 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] 431 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] 432 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] 433 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] 434 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] 435 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] 436 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] 437 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] 438 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] 439 440 ds.guess = dict() 441 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] 442 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] 443 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] 444 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] 445 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] 446 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] 447 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] 448 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] 449 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] 450 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] 451 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] 452 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] 453 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] 454 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] 455 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] 456 457 # Assign guess values. 458 for spin, spin_id in spin_loop(return_id=True): 459 if spin_id in cluster_ids: 460 print("spin_id %s in cluster ids"%(spin_id)) 461 spin.kex = ds.guess[spin_id][6] 462 spin.phi_ex = ds.guess[spin_id][10] 463 else: 464 print("spin_id %s NOT in cluster ids"%(spin_id)) 465 466 if read_R1: 467 # Read the R1 data 468 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)
469 470
471 - def setup_hansen_cpmg_data(self, model=None):
472 """Set up the data for the test_hansen_cpmg_data_*() system tests. 473 474 @keyword model: The name of the model which will be tested. 475 @type model: str 476 """ 477 478 # Create the data pipe and load the base data. 479 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 480 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 481 self.interpreter.results.read(data_path+sep+'base_pipe') 482 self.interpreter.deselect.spin(':4') 483 484 # Set the nuclear isotope data. 485 self.interpreter.spin.isotope('15N') 486 487 # Create the R2eff data pipe and load the results. 488 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 489 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 490 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 491 self.interpreter.deselect.spin(':4') 492 493 # The model data pipe. 494 pipe_name = "%s - relax_disp" % model 495 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 496 self.interpreter.pipe.switch(pipe_name=pipe_name) 497 498 # Set the model. 499 self.interpreter.relax_disp.select_model(model=model) 500 501 # Copy the data. 502 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
503 504
505 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
506 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 507 508 @keyword model: The name of the model which will be tested. 509 @type model: str 510 """ 511 512 # Create the data pipe and load the base data. 513 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 514 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 515 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 516 517 # Create the R2eff data pipe and load the results. 518 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 519 self.interpreter.pipe.switch(pipe_name='R2eff') 520 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 521 522 # The model data pipe. 523 pipe_name = "%s - relax_disp" % model 524 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 525 self.interpreter.pipe.switch(pipe_name=pipe_name) 526 527 # Set the model. 528 self.interpreter.relax_disp.select_model(model=model) 529 530 # Copy the data. 531 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
532 533
534 - def setup_korzhnev_2005_data(self, data_list=[]):
535 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 536 537 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 538 539 - 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>}). 540 541 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. 542 543 544 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 545 @type data_list: list of str 546 """ 547 548 # Create the data pipe and load the base data. 549 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 550 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 551 552 # Create the spin system. 553 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 554 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 555 self.interpreter.spin.element('H', spin_id='@H') 556 self.interpreter.spin.element('N', spin_id='@N') 557 self.interpreter.spin.isotope('1H', spin_id='@H') 558 self.interpreter.spin.isotope('15N', spin_id='@N') 559 560 # Define the magnetic dipole-dipole relaxation interaction. 561 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 562 563 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 564 data = [ 565 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 566 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 567 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 568 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 569 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 570 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 571 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 572 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 573 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 574 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 575 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 576 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 577 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 578 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 579 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 580 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 581 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 582 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 583 ] 584 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] 585 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] 586 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] 587 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] 588 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] 589 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] 590 591 # Loop over the files, reading in the data. 592 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 593 # Skip undesired data. 594 if data_type not in data_list: 595 continue 596 597 # Alias the CPMG frequencies. 598 if data_type == 'SQ': 599 cpmg_frqs = cpmg_frqs_sq 600 elif data_type == '1H SQ': 601 cpmg_frqs = cpmg_frqs_1h_sq 602 elif data_type == 'DQ': 603 cpmg_frqs = cpmg_frqs_dq 604 elif data_type == 'ZQ': 605 cpmg_frqs = cpmg_frqs_zq 606 elif data_type == '1H MQ': 607 cpmg_frqs = cpmg_frqs_1h_mq 608 elif data_type == 'MQ': 609 cpmg_frqs = cpmg_frqs_mq 610 611 # Loop over each CPMG frequency. 612 for cpmg_frq in cpmg_frqs: 613 # The id. 614 new_id = "%s_%s" % (id, cpmg_frq) 615 616 # Set the NMR field strength. 617 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 618 619 # Set the relaxation dispersion experiment type. 620 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 621 622 # Relaxation dispersion CPMG constant time delay T (in s). 623 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 624 625 # Set the CPMG frequency. 626 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 627 628 # Read the R2eff data. 629 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) 630 631 # Change the model. 632 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
633 634
635 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
636 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 637 638 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 639 'SOD1-WT' CPMG data to the CR72 dispersion model. 640 641 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. 642 Data is for experiment at 25 degree Celcius. 643 """ 644 645 # Create the data pipe and load the base data. 646 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 647 648 # Set experiment settings. sfrq, time_T2, ncyc 649 Exps = [ 650 ["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"] ], 651 ["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"] ] ] 652 653 # Create base pipe 654 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 655 656 # Loop throug experiments 657 id_lists = [] 658 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 659 # Read spins 660 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 661 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 662 663 # Make spectrum id list 664 id_list = list(key+str(i) for i in range(len(ncycs))) 665 id_lists.append(id_list) 666 667 # Read intensities 668 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))) ) 669 670 # Loop over experiments 671 for i in range(len(ncycs)): 672 ncyc = ncycs[i] 673 vcpmg = ncyc/time_T2 674 675 # Test if spectrum is a reference 676 if float(vcpmg) == 0.0: 677 vcpmg = None 678 else: 679 vcpmg = round(float(vcpmg), 3) 680 681 # Set current id 682 current_id = id_list[i] 683 684 # Set the current experiment type. 685 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 686 687 # Set the NMR field strength of the spectrum. 688 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 689 690 # Relaxation dispersion CPMG constant time delay T (in s). 691 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 692 693 # Set the relaxation dispersion CPMG frequencies. 694 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 695 696 # Define replicated 697 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 698 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 699 700 # Perform error analysis 701 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 702 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 703 704 # Define isotope 705 self.interpreter.spin.isotope(isotope='15N') 706 707 ############# 708 709 # Define the 64 residues which was used for Global fitting 710 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 711 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 712 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 713 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 714 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 715 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 716 717 # Test number of global 718 self.assertEqual(64, len(glob_assn )) 719 720 ## Turn assignments into relax spin ids. 721 # Define regular expression search 722 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 723 724 # Create list to hold regular expression search 725 relax_glob_ids = [] 726 727 # Loop over assignments 728 for assn in glob_assn: 729 # Make match for the regular search 730 m = r.match(assn) 731 # Convert to relax spin string 732 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 733 734 # Save the relax spin string and the regular search 735 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 736 737 ############# Deselect all spins, and select few spins 738 739 ## Deselect all spins, and select a few for analysis 740 self.interpreter.deselect.all() 741 742 # Select few spins 743 for i in select_spin_index: 744 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 745 746 ############## 747 748 # Prepare for R2eff calculation 749 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 750 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 751 752 # Select model for points calculation 753 MODEL = "R2eff" 754 self.interpreter.relax_disp.select_model(model=MODEL) 755 # Calculate R2eff values 756 self.interpreter.minimise.calculate(verbosity=1)
757 758
759 - def setup_missing_r1_spins(self):
760 """Function for setting up a few spins for the given pipe.""" 761 762 # Path to file. 763 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 764 765 # File with spins. 766 file = open(data_path+sep+'R1_fitted_values.txt') 767 lines = file.readlines() 768 file.close() 769 770 for i, line in enumerate(lines): 771 # Make the string test 772 line_split = line.split() 773 774 if line_split[0] == "#": 775 continue 776 777 mol_name = line_split[0] 778 mol_name = None 779 res_num = int(line_split[1]) 780 res_name = line_split[2] 781 spin_num = line_split[3] 782 spin_num = None 783 spin_name = line_split[4] 784 785 # Create the spin. 786 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
787 788
789 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
790 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 791 792 # Reset. 793 self.interpreter.reset() 794 795 # Create the data pipe and load the base data. 796 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 797 self.interpreter.state.load(data_path+sep+'r2eff_values') 798 799 # The model data pipe. 800 model = 'NS R1rho 2-site' 801 pipe_name = "%s - relax_disp" % model 802 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 803 self.interpreter.pipe.switch(pipe_name=pipe_name) 804 805 # Set the model. 806 self.interpreter.relax_disp.select_model(model=model) 807 808 # Copy the data. 809 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 810 811 # Alias the spins. 812 spin1 = cdp.mol[0].res[0].spin[0] 813 spin2 = cdp.mol[0].res[1].spin[0] 814 815 # The R20 keys. 816 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 817 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 818 819 # Set the initial parameter values. 820 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 821 spin1.pA = 0.779782428085762 822 spin1.dw = 7.57855284496424 823 spin1.kex = 1116.7911285203 824 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 825 spin2.pA = 0.826666229688602 826 spin2.dw = 9.5732624231366 827 spin2.kex = 1380.46162655657 828 829 # Test the values when clustering. 830 if clustering: 831 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 832 833 # Low precision optimisation. 834 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) 835 836 # Printout. 837 print("\n\nOptimised parameters:\n") 838 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 839 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 840 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 841 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 842 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 843 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 844 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
845 846
847 - def test_baldwin_synthetic(self):
848 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 849 850 Support requst sr #3154 U{https://web.archive.org/web/https://gna.org/support/index.php?3154}. 851 852 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. 853 """ 854 855 # The path to the data files. 856 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 857 858 # Create pipe 859 pipe_name = 'base pipe' 860 pipe_type = 'relax_disp' 861 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 862 863 # Create base pipe 864 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 865 866 # Generate the sequence. 867 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 868 869 # Define the isotope. 870 self.interpreter.spin.isotope('1H', spin_id='@H') 871 872 # Build the experiment IDs. 873 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 874 ncycs = [2, 4, 8, 10, 20, 40, 500] 875 ids = [] 876 for ncyc in ncycs: 877 ids.append('CPMG_%s' % ncyc) 878 879 print("\n\nThe experiment IDs are %s." % ids) 880 881 # Set up the metadata for the experiments. 882 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 883 sfrq = 200. * 1E6 884 885 # Total time of CPMG block. 886 Trelax = 0.04 887 888 # First set the 889 for i in range(len(ids)): 890 id = ids[i] 891 # Set the spectrometer frequency. 892 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 893 894 # Set the experiment type. 895 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 896 897 # Set the relaxation dispersion CPMG constant time delay T (in s). 898 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 899 900 # Set the relaxation dispersion CPMG frequencies. 901 ncyc = ncycs[i] 902 nu_cpmg = ncyc / Trelax 903 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 904 905 # Prepare for R2eff reading. 906 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 907 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 908 909 # Try reading the R2eff file. 910 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) 911 912 # Check the global data. 913 data = [ 914 ['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}], 915 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 916 ['dispersion_points', len(ncycs)], 917 ['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'}], 918 ['exp_type_list', ['SQ CPMG']], 919 ['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}], 920 ['spectrometer_frq_count', 1], 921 ['spectrometer_frq_list', [sfrq]], 922 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 923 ] 924 for name, value in data: 925 # Does it exist? 926 self.assert_(hasattr(cdp, name)) 927 928 # Check the object. 929 obj = getattr(cdp, name) 930 if not isinstance(data, dict): 931 self.assertEqual(obj, value) 932 933 # Check the global dictionary data. 934 else: 935 for id in ids: 936 self.assertEqual(obj[id], value[id]) 937 938 # Check the spin data. 939 n_data = [ 940 [ 50.000000, 10.367900, 0.1], 941 [ 100.000000, 10.146849, 0.1], 942 [ 200.000000, 9.765987, 0.1], 943 [ 250.000000, 9.409789, 0.1], 944 [ 500.000000, 5.829819, 0.1], 945 [ 1000.000000, 3.191928, 0.1], 946 [ 12500.000000, 2.008231, 0.1] 947 ] 948 for disp_point, value, error in n_data: 949 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 950 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 951 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 952 953 # Generate r20 key. 954 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 955 956 ## Now prepare for MODEL calculation. 957 MODEL = "B14" 958 959 # Change pipe. 960 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 961 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 962 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 963 964 # Then select model. 965 self.interpreter.relax_disp.select_model(model=MODEL) 966 967 # Store grid and minimisations results. 968 grid_results = [] 969 mini_results = [] 970 971 # The grid search size (the number of increments per dimension). 972 # If None, use the default values. 973 #GRID = None 974 GRID = 13 975 # Perform Grid Search. 976 if GRID: 977 # Set the R20 parameters in the default grid search using the minimum R2eff value. 978 # This speeds it up considerably. 979 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 980 981 # Then do grid search. 982 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 983 984 # If no Grid search, set the default values. 985 else: 986 for param in MODEL_PARAMS[MODEL]: 987 self.interpreter.value.set(param=param, index=None) 988 # Do a grid search, which will store the chi2 value. 989 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 990 991 # Store result. 992 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 993 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 994 995 ## Now do minimisation. 996 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 997 set_func_tol = 1e-10 998 set_max_iter = 1000 999 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1000 1001 # Store result. 1002 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1003 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1004 1005 # Print results. 1006 for i in range(len(grid_results)): 1007 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1008 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1009 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)) 1010 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)) 1011 1012 # Reference values from Baldwin.py. 1013 # Exchange rate = k+ + k- (s-1) 1014 kex = 1000. 1015 # Fractional population of excited state k+/kex 1016 pb = 0.01 1017 # deltaOmega in ppm 1018 dw_ppm = 2. 1019 #relaxation rate of ground (s-1) 1020 R2g = 2. 1021 #relaxation rate of excited (s-1) 1022 R2e = 2. 1023 1024 # Test the parameters which created the data. 1025 # This is for the 1H spin. 1026 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1027 1028 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1029 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1030 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1031 1032
1034 """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}. 1035 1036 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>}. 1037 """ 1038 1039 # The path to the data files. 1040 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1041 1042 # Create pipe 1043 pipe_name = 'base pipe' 1044 pipe_type = 'relax_disp' 1045 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1046 1047 # Create base pipe 1048 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1049 1050 # Generate the sequence. 1051 # Generate both a 1H spin, and 15N spin. 1052 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1053 1054 # Define the isotope. 1055 self.interpreter.spin.isotope('1H', spin_id='@H') 1056 1057 # Build the experiment IDs. 1058 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1059 ncycs = [2, 4, 8, 10, 20, 40, 500] 1060 ids = [] 1061 for ncyc in ncycs: 1062 ids.append('CPMG_%s' % ncyc) 1063 1064 print("\n\nThe experiment IDs are %s." % ids) 1065 1066 # Set up the metadata for the experiments. 1067 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1068 sfrq = 200. * 1E6 1069 1070 # Total time of CPMG block. 1071 Trelax = 0.04 1072 1073 # First set the 1074 for i in range(len(ids)): 1075 id = ids[i] 1076 # Set the spectrometer frequency. 1077 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1078 1079 # Set the experiment type. 1080 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1081 1082 # Set the relaxation dispersion CPMG constant time delay T (in s). 1083 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1084 1085 # Set the relaxation dispersion CPMG frequencies. 1086 ncyc = ncycs[i] 1087 nu_cpmg = ncyc / Trelax 1088 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1089 1090 # Prepare for R2eff reading. 1091 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1092 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1093 1094 # Try reading the R2eff file. 1095 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) 1096 1097 # Check the global data. 1098 data = [ 1099 ['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}], 1100 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1101 ['dispersion_points', len(ncycs)], 1102 ['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'}], 1103 ['exp_type_list', ['SQ CPMG']], 1104 ['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}], 1105 ['spectrometer_frq_count', 1], 1106 ['spectrometer_frq_list', [sfrq]], 1107 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1108 ] 1109 for name, value in data: 1110 # Does it exist? 1111 self.assert_(hasattr(cdp, name)) 1112 1113 # Check the object. 1114 obj = getattr(cdp, name) 1115 if not isinstance(data, dict): 1116 self.assertEqual(obj, value) 1117 1118 # Check the global dictionary data. 1119 else: 1120 for id in ids: 1121 self.assertEqual(obj[id], value[id]) 1122 1123 # Check the spin data. 1124 n_data = [ 1125 [ 50.000000, 10.286255, 0.1], 1126 [ 100.000000, 10.073083, 0.1], 1127 [ 200.000000, 9.692746, 0.1], 1128 [ 250.000000, 9.382441, 0.1], 1129 [ 500.000000, 6.312396, 0.1], 1130 [ 1000.000000, 3.957029, 0.1], 1131 [ 12500.000000, 2.880420, 0.1] 1132 ] 1133 for disp_point, value, error in n_data: 1134 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1135 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1136 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1137 1138 # Generate r20 key. 1139 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1140 1141 ## Now prepare for MODEL calculation. 1142 MODEL = "B14 full" 1143 1144 # Change pipe. 1145 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1146 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1147 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1148 1149 # Then select model. 1150 self.interpreter.relax_disp.select_model(model=MODEL) 1151 1152 # Store grid and minimisations results. 1153 grid_results = [] 1154 mini_results = [] 1155 clust_results = [] 1156 1157 # The grid search size (the number of increments per dimension). 1158 # If None, use the default values. 1159 #GRID = None 1160 GRID = 13 1161 # Perform Grid Search. 1162 if GRID: 1163 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1164 # This speeds it up considerably. 1165 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1166 1167 # Then do grid search. 1168 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1169 1170 # If no Grid search, set the default values. 1171 else: 1172 for param in MODEL_PARAMS[MODEL]: 1173 self.interpreter.value.set(param=param, index=None) 1174 # Do a grid search, which will store the chi2 value. 1175 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1176 1177 # Store result. 1178 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1179 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1180 1181 ## Now do minimisation. 1182 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1183 set_func_tol = 1e-11 1184 set_max_iter = 10000 1185 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1186 1187 # Store result. 1188 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1189 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1190 1191 print("\n# Now print before and after minimisation-\n") 1192 1193 # Print results. 1194 for i in range(len(grid_results)): 1195 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1196 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1197 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)) 1198 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)) 1199 1200 # Reference values from Baldwin.py. 1201 # Exchange rate = k+ + k- (s-1) 1202 kex = 1000. 1203 # Fractional population of excited state k+/kex 1204 pb = 0.01 1205 # deltaOmega in ppm 1206 dw_ppm = 2. 1207 #relaxation rate of ground (s-1) 1208 R2g = 2. 1209 #relaxation rate of excited (s-1) 1210 R2e = 100. 1211 1212 # Test the parameters which created the data. 1213 # This is for the 1H spin. 1214 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3) 1215 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3) 1216 1217 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1218 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1219 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1220 1221
1222 - def x_test_bmrb_sub_cpmg(self):
1223 """U{Task #7858: <https://web.archive.org/web/https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1224 This uses CPMG data from: 1225 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1226 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1227 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1228 """ 1229 1230 # Define path to data 1231 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1232 1233 # Read data. 1234 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1235 1236 # Set element 1237 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1238 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1239 # Rename molecule from None to 'HEWL' 1240 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1241 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1242 1243 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1244 print(spin_id) 1245 if resn == 'C': 1246 print(resi, resn) 1247 1248 # Select the thiol state of the system. 1249 # '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' 1250 self.interpreter.bmrb.thiol_state(state='not reported') 1251 1252 # relax_data.temp_calibration(ri_id=None, method=None) 1253 1254 # Call display of bmrb. 1255 self.interpreter.bmrb.display()
1256 1257
1259 """U{Bug #21081<https://web.archive.org/web/https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1260 1261 # Clear the data store. 1262 self.interpreter.reset() 1263 1264 # Load the state. 1265 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1266 self.interpreter.state.load(state, force=True) 1267 1268 # Model selection - to catch the failure. 1269 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1270 1271
1273 """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.""" 1274 1275 # Clear the data store. 1276 self.interpreter.reset() 1277 1278 # Load the state. 1279 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1280 self.interpreter.state.load(state, force=True) 1281 1282 # Execute the auto-analysis (fast). 1283 relax_disp.Relax_disp.opt_func_tol = 1e-5 1284 relax_disp.Relax_disp.opt_max_iterations = 1000 1285 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)
1286 1287
1289 """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.""" 1290 1291 # Clear the data store. 1292 self.interpreter.reset() 1293 1294 # Load the state. 1295 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1296 self.interpreter.state.load(state, force=True) 1297 1298 # Execute the auto-analysis (fast). 1299 relax_disp.Relax_disp.opt_func_tol = 1e-5 1300 relax_disp.Relax_disp.opt_max_iterations = 1000 1301 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)
1302 1303
1305 """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().""" 1306 1307 # Clear the data store. 1308 self.interpreter.reset() 1309 1310 # Load the state. 1311 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1312 self.interpreter.state.load(state, force=True) 1313 1314 # Run the calculation. 1315 self.interpreter.minimise.calculate(verbosity=1)
1316 1317
1319 """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.""" 1320 1321 # Clear the data store. 1322 self.interpreter.reset() 1323 1324 # Load the state. 1325 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1326 self.interpreter.state.load(state, force=True) 1327 1328 # Execute the auto-analysis (fast). 1329 relax_disp.Relax_disp.opt_func_tol = 1e-5 1330 relax_disp.Relax_disp.opt_max_iterations = 1000 1331 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)
1332 1333
1335 """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.""" 1336 1337 # Clear the data store. 1338 self.interpreter.reset() 1339 1340 # Load the state. 1341 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1342 self.interpreter.state.load(state, force=True) 1343 1344 # Execute the auto-analysis (fast). 1345 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1346 relax_disp.Relax_disp.opt_func_tol = 1e-5 1347 relax_disp.Relax_disp.opt_max_iterations = 1000 1348 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)
1349 1350
1352 """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.""" 1353 1354 # Base data setup. 1355 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1356 1357
1359 """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.""" 1360 1361 # Base data setup. 1362 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1363 1364
1366 """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.""" 1367 1368 # Base data setup. 1369 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1370 1371
1373 """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.""" 1374 1375 # Base data setup. 1376 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1377 1378
1380 """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.""" 1381 1382 # Clear the data store. 1383 self.interpreter.reset() 1384 1385 # Load the state. 1386 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' 1387 self.interpreter.state.load(state, force=True) 1388 1389 param = 'k_AB' 1390 1391 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1392 print(spin_id, spin.params) 1393 if param in spin.params: 1394 print(spin_id, spin.k_AB, spin.k_AB_err) 1395 1396 # Perform write. 1397 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1398 1399 1400 # Test the header of the value.write parameter r2. 1401 param = 'r2' 1402 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1403 1404 file = open(self.tmpdir+sep+'%s.out'%param) 1405 lines = file.readlines() 1406 file.close() 1407 1408 for i, line in enumerate(lines): 1409 # Make the string test 1410 line_split = line.split() 1411 print(line_split) 1412 1413 if len(line_split) > 1: 1414 # Break at parameter header. 1415 if line_split[0] == "#" and line_split[1] == 'mol_name': 1416 nr_split_header = len(line_split) 1417 nr_split_header_i = i 1418 break 1419 1420 # Call the line after. 1421 line_split_val = lines[nr_split_header_i + 1].split() 1422 print(line_split_val) 1423 1424 # Assert that the number of columns is equal, plus 1 for "#". 1425 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1426 1427 # Test the header of the value.write for parameter r2eff. 1428 param = 'r2eff' 1429 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1430 1431 file = open(self.tmpdir+sep+'%s.out'%param) 1432 lines = file.readlines() 1433 file.close() 1434 1435 for i, line in enumerate(lines): 1436 # Make the string test 1437 line_split = line.split() 1438 print(line_split) 1439 1440 if len(line_split) > 1: 1441 # Break at parameter header. 1442 if line_split[0] == "#" and line_split[1] == 'mol_name': 1443 nr_split_header = len(line_split) 1444 nr_split_header_i = i 1445 break 1446 1447 # Call the line after. 1448 line_split_val = lines[nr_split_header_i + 1].split() 1449 print(line_split_val) 1450 1451 # Assert that the number of columns is equal, plus 1 for "#". 1452 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1453 1454
1456 """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.""" 1457 1458 # Clear the data store. 1459 self.interpreter.reset() 1460 1461 # Load the state. 1462 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_23186.bz2' 1463 self.interpreter.state.load(state, force=True) 1464 1465 # Dic key to spectrometer frq. 1466 dickey = 'SQ CPMG - 599.89086220 MHz' 1467 1468 # First get the resi 0 array of sim r2a. 1469 resi_0_r2a = [] 1470 1471 # Assign spins 1472 res0 = cdp.mol[0].res[0].spin[0] 1473 res1 = cdp.mol[0].res[1].spin[0] 1474 1475 print("Chi2 before call to minimise: %3.3f"%res0.chi2) 1476 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000, verbosity=0) 1477 print("Chi2 after call to minimise: %3.3f"%res0.chi2) 1478 1479 # Loop over the dics in spin. 1480 for cdic in res0.r2a_sim: 1481 resi_0_r2a.append(cdic[dickey]) 1482 1483 # Get stats with numpy 1484 resi_0_r2a_std = std(asarray(resi_0_r2a), ddof=1) 1485 1486 # First get the resi 86 array of sim r2a. 1487 resi_86_r2a = [] 1488 1489 # Loop over the dics in spin. 1490 for cdic in res1.r2a_sim: 1491 resi_86_r2a.append(cdic[dickey]) 1492 1493 # Get stats with numpy 1494 resi_86_r2a_std = std(asarray(resi_86_r2a), ddof=1) 1495 1496 # Then get for dw. 1497 1498 # First get the array of sim dw. 1499 resi_0_dw = res0.dw_sim 1500 resi_86_dw = res1.dw_sim 1501 1502 # Get stats with numpy 1503 resi_0_dw_std = std(asarray(resi_0_dw), ddof=1) 1504 resi_86_dw_std = std(asarray(resi_86_dw), ddof=1) 1505 1506 # Then get for spin independent parameter. 1507 1508 # First get the array of sim dw. 1509 resi_0_kAB = res0.k_AB_sim 1510 resi_86_kAB = res1.k_AB_sim 1511 1512 # Get stats with numpy 1513 resi_0_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1514 resi_86_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1515 1516 # Assume they both std of k_AB values are equal 1517 self.assertEqual(resi_0_kAB_std, resi_86_kAB_std) 1518 1519 # Perform error analysis. 1520 self.interpreter.monte_carlo.error_analysis() 1521 1522 # Check values for k_AB. 1523 self.assertAlmostEqual(resi_0_kAB_std, res0.k_AB_err) 1524 self.assertAlmostEqual(resi_86_kAB_std, res1.k_AB_err) 1525 1526 # Check values for r2a. 1527 self.assertAlmostEqual(resi_0_r2a_std, res0.r2a_err[dickey]) 1528 self.assertAlmostEqual(resi_86_r2a_std, res1.r2a_err[dickey]) 1529 1530 # Check values for dw. 1531 self.assertAlmostEqual(resi_0_dw_std, res0.dw_err) 1532 self.assertAlmostEqual(resi_86_dw_std, res1.dw_err) 1533 1534 # 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. 1535 # 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. 1536 1537 # Check calculates the same Monte-Carlo chi2 values 1538 self.interpreter.monte_carlo.setup(number=3) 1539 self.interpreter.monte_carlo.create_data(method='back_calc') 1540 self.interpreter.monte_carlo.initial_values() 1541 1542 # Assign original data instead of back_calculated error. 1543 res0.r2eff_sim[0] = copy.copy(res0.r2eff) 1544 res0.r2eff_sim[1] = copy.copy(res0.r2eff) 1545 res0.r2eff_sim[2] = copy.copy(res0.r2eff) 1546 res1.r2eff_sim[0] = copy.copy(res1.r2eff) 1547 res1.r2eff_sim[1] = copy.copy(res1.r2eff) 1548 res1.r2eff_sim[2] = copy.copy(res1.r2eff) 1549 1550 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000) 1551 self.interpreter.monte_carlo.error_analysis() 1552 1553 # Get the simulation array and calculate the average 1554 spin_chi2_mc = res0.chi2 1555 spin_chi2_mc_sim = res0.chi2_sim 1556 spin_chi2_mc_sim_ave = average(spin_chi2_mc_sim) 1557 1558 print("The chi2 from calculation is: %3.3f"%spin_chi2_mc) 1559 print("The array with monte-carlo chi2 values is: %s"%spin_chi2_mc_sim) 1560 print("The average of this array is: %3.3f"%spin_chi2_mc_sim_ave) 1561 1562 self.assertAlmostEqual(spin_chi2_mc, spin_chi2_mc_sim_ave, 7)
1563 1564
1566 """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.""" 1567 1568 # Define path to data 1569 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" 1570 1571 # Read data. 1572 self.interpreter.results.read(prev_data_path + sep + 'results') 1573 1574 # Now count number 1575 graph_nr = 1 1576 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1577 print("\nGraph nr %i" % graph_nr) 1578 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1579 print(exp_type, frq, offset, point, time) 1580 graph_nr += 1 1581 1582 ## Possibly do an error analysis. 1583 1584 # Check if intensity errors have already been calculated by the user. 1585 precalc = True 1586 for spin in spin_loop(skip_desel=True): 1587 # No structure. 1588 if not hasattr(spin, 'peak_intensity_err'): 1589 precalc = False 1590 break 1591 1592 # Determine if a spectrum ID is missing from the list. 1593 for id in cdp.spectrum_ids: 1594 if id not in spin.peak_intensity_err: 1595 precalc = False 1596 break 1597 1598 # Skip. 1599 if precalc: 1600 print("Skipping the error analysis as it has already been performed.") 1601 1602 else: 1603 # Loop over the spectrometer frequencies. 1604 for frq in loop_frq(): 1605 # Generate a list of spectrum IDs matching the frequency. 1606 ids = [] 1607 for id in cdp.spectrum_ids: 1608 # Check that the spectrometer frequency matches. 1609 match_frq = True 1610 if frq != None and cdp.spectrometer_frq[id] != frq: 1611 match_frq = False 1612 1613 # Add the ID. 1614 if match_frq: 1615 ids.append(id) 1616 1617 # Run the error analysis on the subset. 1618 self.interpreter.spectrum.error_analysis(subset=ids) 1619 1620 print("has_exponential_exp_type:", has_exponential_exp_type()) 1621 1622 model = 'R2eff' 1623 self.interpreter.relax_disp.select_model(model) 1624 1625 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1626 #delattr(spin, 'r2eff') 1627 #delattr(spin, 'r2eff_err') 1628 #delattr(spin, 'i0') 1629 #delattr(spin, 'i0_err') 1630 setattr(spin, 'r2eff', {}) 1631 setattr(spin, 'r2eff_err', {}) 1632 setattr(spin, 'i0', {}) 1633 setattr(spin, 'i0_err', {}) 1634 1635 # Do Grid Search 1636 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1637 1638 # Start dic. 1639 my_dic = {} 1640 1641 # Define counter for maximum elements in the numpy array list 1642 NE = 0 1643 NS = 1 1644 NM = 0 1645 NO = 0 1646 ND = 0 1647 NT = 0 1648 1649 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1650 # Save to counter. 1651 if ei > NE: 1652 NE = ei 1653 if mi > NM: 1654 NM = mi 1655 if oi > NO: 1656 NO = oi 1657 if di > ND: 1658 ND = di 1659 1660 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1661 # Save to counter. 1662 if ti > NT: 1663 NT = ti 1664 1665 # Add 1 to counter, since index start from 0. 1666 NE = NE + 1 1667 NM = NM + 1 1668 NO = NO + 1 1669 ND = ND + 1 1670 NT = NT + 1 1671 1672 # Make data array. 1673 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1674 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1675 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1676 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1677 param_key_list = [] 1678 1679 1680 # Loop over each spectrometer frequency and dispersion point. 1681 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1682 # Add key to dic. 1683 my_dic[spin_id] = {} 1684 1685 # Generate spin string. 1686 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1687 1688 # Loop over the parameters. 1689 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1690 1691 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1692 # Generate the param_key. 1693 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1694 1695 # Append key. 1696 param_key_list.append(param_key) 1697 1698 # Add key to dic. 1699 my_dic[spin_id][param_key] = {} 1700 1701 # Get the value. 1702 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1703 i0_value = getattr(cur_spin, 'i0')[param_key] 1704 1705 # Save to dic. 1706 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1707 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1708 1709 ## Now try do a line of best fit by least squares. 1710 # The peak intensities, errors and times. 1711 values = [] 1712 errors = [] 1713 times = [] 1714 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1715 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1716 values.append(value) 1717 1718 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1719 errors.append(error) 1720 times.append(time) 1721 1722 # Save to numpy arrays. 1723 values_arr[ei, 0, mi, oi, di, ti] = value 1724 errors_arr[ei, 0, mi, oi, di, ti] = error 1725 times_arr[ei, 0, mi, oi, di, ti] = time 1726 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1727 1728 # y= A exp(x * k) 1729 # w[i] = ln(y[i]) 1730 # int[i] = i0 * exp( - times[i] * r2eff); 1731 w = log(array(values)) 1732 x = - array(times) 1733 n = len(times) 1734 1735 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1736 a = 1./n * sum(w) - b * 1./n * sum(x) 1737 R2eff_est = b 1738 i0_est = exp(a) 1739 1740 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1741 my_dic[spin_id][param_key]['i0_est'] = i0_est 1742 1743 # Print value. 1744 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1745 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1746 1747 1748 # Do minimisation. 1749 set_func_tol = 1e-25 1750 set_max_iter = int(1e7) 1751 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1752 1753 # Loop over each spectrometer frequency and dispersion point. 1754 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1755 # Generate spin string. 1756 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1757 1758 # Loop over the parameters. 1759 print("Optimised parameters for spin: %s" % (spin_string)) 1760 1761 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1762 # Generate the param_key. 1763 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1764 1765 # Get the value. 1766 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1767 i0_value = getattr(cur_spin, 'i0')[param_key] 1768 1769 # Extract from dic. 1770 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1771 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1772 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1773 i0_est = my_dic[spin_id][param_key]['i0_est'] 1774 1775 # Print value. 1776 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1777 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1778 1779 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1780 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1781 1782 print(NE, NS, NM, NO, ND, NT) 1783 for param_key in param_key_list: 1784 print(" '%s'," % param_key) 1785 print(values_arr.shape) 1786 1787 # Save arrays to profiling. 1788 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1789 #save(data_path + "values_arr", values_arr) 1790 #save(data_path + "errors_arr", errors_arr) 1791 #save(data_path + "times_arr", times_arr) 1792 #save(data_path + "struct_arr", struct_arr) 1793 1794
1795 - def test_bug_atul_srivastava(self):
1796 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1797 shows it is exponential fitting, but only one time point is added per file. 1798 1799 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1800 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1801 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1802 1803 """ 1804 1805 # Data path. 1806 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1807 file = data_path + sep + 'bug_script.py' 1808 1809 # Run script. 1810 self.interpreter.script(file=file, dir=None) 1811 1812 # The grid search size (the number of increments per dimension). 1813 GRID_INC = 11 1814 1815 # Check-data. 1816 ################# 1817 1818 # Loop over spins, to see current setup. 1819 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1820 print(mol_name, resi, resn, spin_id) 1821 1822 # Loop over setup. 1823 for id in cdp.exp_type: 1824 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1825 1826 1827 # Manual minimisation. 1828 ################# 1829 if True: 1830 # Set the model. 1831 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1832 1833 # Check if intensity errors have already been calculated. 1834 check_intensity_errors() 1835 1836 # Calculate the R2eff values for the fixed relaxation time period data types. 1837 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1838 self.interpreter.minimise.calculate() 1839 1840 # Optimise the model. 1841 else: 1842 constraints = False 1843 min_algor = 'Newton' 1844 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC) 1845 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints) 1846 1847 # Inspect. 1848 if False: 1849 # Loop over attributes. 1850 par_attr_list = ['r2eff', 'i0'] 1851 1852 # Collect the estimation data. 1853 my_dic = {} 1854 param_key_list = [] 1855 est_keys = [] 1856 est_key = 'grid' 1857 est_keys.append(est_key) 1858 spin_id_list = [] 1859 1860 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1861 # Add key to dic. 1862 my_dic[spin_id] = {} 1863 1864 # Add key for estimate. 1865 my_dic[spin_id][est_key] = {} 1866 1867 # Add spin key to list. 1868 spin_id_list.append(spin_id) 1869 1870 # Generate spin string. 1871 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1872 1873 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1874 # Generate the param_key. 1875 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1876 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1877 1878 # Append key. 1879 param_key_list.append(param_key) 1880 1881 # Add key to dic. 1882 my_dic[spin_id][est_key][param_key] = {} 1883 1884 # Get the value. 1885 # Loop over err attributes. 1886 for par_attr in par_attr_list: 1887 if hasattr(cur_spin, par_attr): 1888 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1889 else: 1890 get_par_attr = 0.0 1891 1892 # Save to dic. 1893 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1894 1895 # Check number of values. 1896 values = [] 1897 errors = [] 1898 times = [] 1899 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1900 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1901 values.append(value) 1902 1903 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1904 errors.append(error) 1905 times.append(time) 1906 1907 # Save to dic. 1908 my_dic[spin_id][est_key][param_key]['values'] = values 1909 my_dic[spin_id][est_key][param_key]['errors'] = errors 1910 my_dic[spin_id][est_key][param_key]['times'] = times 1911 1912 # Analysis variables. 1913 ##################### 1914 1915 # The dispersion models. 1916 MODELS = ['R2eff', 'No Rex'] 1917 1918 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1919 MC_NUM = 10 1920 1921 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1922 MC_SIM_ALL_MODELS = False 1923 1924 # The results directory. 1925 RESULTS_DIR = ds.tmpdir 1926 1927 # The directory of results of an earlier analysis without clustering. 1928 PRE_RUN_DIR = None 1929 1930 # The model selection technique to use. 1931 MODSEL = 'AIC' 1932 1933 # The flag for only using numeric models in the final model selection. 1934 NUMERIC_ONLY = False 1935 1936 # 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. 1937 INSIGNIFICANCE = 1.0 1938 1939 # Auto-analysis execution. 1940 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)
1941 1942
1944 """Test data, where peak intensities are negative in CPMG 1945 1946 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). 1947 """ 1948 1949 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' 1950 1951 # Create the spins 1952 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1953 1954 # Name the isotope for field strength scaling. 1955 self.interpreter.spin.isotope(isotope='15N') 1956 1957 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1958 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1959 1960 # Loop over the spectra settings. 1961 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1962 1963 # Make empty ncyclist 1964 ncyclist = [] 1965 1966 i = 0 1967 for line in ncycfile: 1968 ncyc = line.split()[0] 1969 time_T2 = float(line.split()[1]) 1970 vcpmg = line.split()[2] 1971 set_sfrq = float(line.split()[3]) 1972 rmsd_err = float(line.split()[4]) 1973 1974 # Test if spectrum is a reference 1975 if float(vcpmg) == 0.0: 1976 vcpmg = None 1977 else: 1978 vcpmg = round(float(vcpmg), 3) 1979 1980 # Add ncyc to list 1981 ncyclist.append(int(ncyc)) 1982 1983 # Set the current spectrum id 1984 current_id = "Z_A%s"%(i) 1985 1986 # Set the current experiment type. 1987 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 1988 1989 # Set the peak intensity errors, as defined as the baseplane RMSD. 1990 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 1991 1992 # Set the NMR field strength of the spectrum. 1993 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 1994 1995 # Relaxation dispersion CPMG constant time delay T (in s). 1996 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 1997 1998 # Set the relaxation dispersion CPMG frequencies. 1999 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 2000 2001 i += 1 2002 2003 # Specify the duplicated spectra. 2004 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 2005 2006 # Delete replicate spectrum 2007 #self.interpreter.spectrum.delete('Z_A15') 2008 2009 MODELS = [MODEL_R2EFF, MODEL_NOREX] 2010 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 2011 2012 results_dir = ds.tmpdir 2013 2014 # Execute 2015 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) 2016 2017 # Check spin less R2eff points. 2018 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 2019 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 2020 if spin_id == ':4@N': 2021 self.assertEqual(len(cur_spin.r2eff), 14) 2022 else: 2023 self.assertEqual(len(cur_spin.r2eff), 15)
2024 2025
2026 - def test_check_missing_r1(self):
2027 """Test of the check_missing_r1() function.""" 2028 2029 # Set up some spins. 2030 self.setup_missing_r1_spins() 2031 2032 # Set variables. 2033 exp_type = 'R1rho' 2034 frq = 800.1 * 1E6 2035 2036 spectrum_id='test' 2037 2038 # Set an experiment type to the pipe. 2039 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 2040 2041 # Set a frequency to loop through. 2042 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 2043 2044 # Check R1 for DPL94. 2045 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2046 self.assertEqual(check_missing_r1_return, True) 2047 2048 # Check R1 for R2eff. 2049 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 2050 self.assertEqual(check_missing_r1_return, False) 2051 2052 # The path to the data files. 2053 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 2054 2055 # Now load some R1 data. 2056 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) 2057 2058 # Check R1. 2059 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2060 self.assertEqual(check_missing_r1_return, False)
2061 2062
2064 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 2065 2066 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. 2067 2068 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2069 """ 2070 2071 # Reset. 2072 #self.interpreter.reset() 2073 2074 ## Set Experiments. 2075 model_create = 'B14' 2076 #model_create = 'NS CPMG 2-site expanded' 2077 model_analyse = 'NS CPMG 2-site 3D' 2078 2079 # Exp 1 2080 sfrq_1 = 599.8908617*1E6 2081 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2082 time_T2_1 = 0.06 2083 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2084 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2085 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2086 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2087 2088 sfrq_2 = 499.8908617*1E6 2089 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2090 time_T2_2 = 0.05 2091 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2092 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2093 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2094 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2095 2096 # Collect all exps 2097 exps = [exp_1, exp_2] 2098 2099 spins = [ 2100 ['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.} ], 2101 ['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.} ] 2102 ] 2103 2104 # Collect the data to be used. 2105 ds.data = [model_create, model_analyse, spins, exps] 2106 2107 # The tmp directory. None is the local directory. 2108 ds.tmpdir = ds.tmpdir 2109 2110 # The results directory. None is the local directory. 2111 #ds.resdir = None 2112 ds.resdir = ds.tmpdir 2113 2114 # Do r20_from_min_r2eff ?. 2115 ds.r20_from_min_r2eff = True 2116 2117 # Remove insignificant level. 2118 ds.insignificance = 0.0 2119 2120 # The grid search size (the number of increments per dimension). 2121 ds.GRID_INC = None 2122 2123 # The do clustering. 2124 ds.do_cluster = True 2125 2126 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2127 # The default value is 1e-25. 2128 ds.set_func_tol = 1e-1 2129 2130 # The maximum number of iterations. 2131 # The default value is 1e7. 2132 ds.set_max_iter = 1000 2133 2134 # The verbosity level. 2135 ds.verbosity = 1 2136 2137 # The rel_change WARNING level. 2138 ds.rel_change = 0.05 2139 2140 # The plot_curves. 2141 ds.plot_curves = False 2142 2143 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2144 ds.sherekhan_input = False 2145 2146 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2147 ds.opendx = False 2148 2149 # The set r2eff err. 2150 ds.r2eff_err = 0.1 2151 2152 # The print result info. 2153 ds.print_res = True 2154 2155 # Execute the script. 2156 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2157 2158 cur_spins = ds.data[2] 2159 # Compare results. 2160 for i in range(len(cur_spins)): 2161 res_name, res_num, spin_name, params = cur_spins[i] 2162 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2163 cur_spin = return_spin(cur_spin_id) 2164 2165 grid_params = ds.grid_results[i][3] 2166 2167 # Extract the clust results. 2168 min_params = ds.clust_results[i][3] 2169 # Now read the parameters. 2170 print("For spin: '%s'"%cur_spin_id) 2171 for mo_param in cur_spin.params: 2172 # The R2 is a dictionary, depending on spectrometer frequency. 2173 if isinstance(getattr(cur_spin, mo_param), dict): 2174 grid_r2 = grid_params[mo_param] 2175 min_r2 = min_params[mo_param] 2176 set_r2 = params[mo_param] 2177 for key, val in list(set_r2.items()): 2178 grid_r2_frq = grid_r2[key] 2179 min_r2_frq = min_r2[key] 2180 set_r2_frq = set_r2[key] 2181 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2182 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2183 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) ) 2184 if rel_change > ds.rel_change: 2185 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2186 print("###################################") 2187 2188 ## Make test on R2. 2189 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2190 else: 2191 grid_val = grid_params[mo_param] 2192 min_val = min_params[mo_param] 2193 set_val = params[mo_param] 2194 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2195 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) ) 2196 if rel_change > ds.rel_change: 2197 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2198 print("###################################") 2199 2200 ## Make test on parameters. 2201 if mo_param == 'dw': 2202 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2203 elif mo_param == 'kex': 2204 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2205 elif mo_param == 'pA': 2206 self.assertAlmostEqual(set_val, min_val, 2)
2207 2208
2210 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2211 2212 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. 2213 2214 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2215 """ 2216 2217 # Reset. 2218 #self.interpreter.reset() 2219 2220 ## Set Experiments. 2221 model_create = 'B14' 2222 #model_create = 'NS CPMG 2-site expanded' 2223 model_analyse = 'NS CPMG 2-site star' 2224 2225 # Exp 1 2226 sfrq_1 = 599.8908617*1E6 2227 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2228 time_T2_1 = 0.06 2229 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2230 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2231 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2232 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2233 2234 sfrq_2 = 499.8908617*1E6 2235 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2236 time_T2_2 = 0.05 2237 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2238 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2239 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2240 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2241 2242 # Collect all exps 2243 exps = [exp_1, exp_2] 2244 2245 spins = [ 2246 ['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.} ], 2247 ['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.} ] 2248 ] 2249 2250 # Collect the data to be used. 2251 ds.data = [model_create, model_analyse, spins, exps] 2252 2253 # The tmp directory. None is the local directory. 2254 ds.tmpdir = ds.tmpdir 2255 2256 # The results directory. None is the local directory. 2257 #ds.resdir = None 2258 ds.resdir = ds.tmpdir 2259 2260 # Do r20_from_min_r2eff ?. 2261 ds.r20_from_min_r2eff = True 2262 2263 # Remove insignificant level. 2264 ds.insignificance = 0.0 2265 2266 # The grid search size (the number of increments per dimension). 2267 ds.GRID_INC = None 2268 2269 # The do clustering. 2270 ds.do_cluster = True 2271 2272 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2273 # The default value is 1e-25. 2274 ds.set_func_tol = 1e-1 2275 2276 # The maximum number of iterations. 2277 # The default value is 1e7. 2278 ds.set_max_iter = 1000 2279 2280 # The verbosity level. 2281 ds.verbosity = 1 2282 2283 # The rel_change WARNING level. 2284 ds.rel_change = 0.05 2285 2286 # The plot_curves. 2287 ds.plot_curves = False 2288 2289 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2290 ds.sherekhan_input = False 2291 2292 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2293 ds.opendx = False 2294 2295 # The set r2eff err. 2296 ds.r2eff_err = 0.1 2297 2298 # The print result info. 2299 ds.print_res = True 2300 2301 # Execute the script. 2302 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2303 2304 cur_spins = ds.data[2] 2305 # Compare results. 2306 for i in range(len(cur_spins)): 2307 res_name, res_num, spin_name, params = cur_spins[i] 2308 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2309 cur_spin = return_spin(cur_spin_id) 2310 2311 grid_params = ds.grid_results[i][3] 2312 2313 # Extract the clust results. 2314 min_params = ds.clust_results[i][3] 2315 # Now read the parameters. 2316 print("For spin: '%s'"%cur_spin_id) 2317 for mo_param in cur_spin.params: 2318 # The R2 is a dictionary, depending on spectrometer frequency. 2319 if isinstance(getattr(cur_spin, mo_param), dict): 2320 grid_r2 = grid_params[mo_param] 2321 min_r2 = min_params[mo_param] 2322 set_r2 = params[mo_param] 2323 for key, val in list(set_r2.items()): 2324 grid_r2_frq = grid_r2[key] 2325 min_r2_frq = min_r2[key] 2326 set_r2_frq = set_r2[key] 2327 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2328 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2329 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) ) 2330 if rel_change > ds.rel_change: 2331 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2332 print("###################################") 2333 2334 ## Make test on R2. 2335 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2336 else: 2337 grid_val = grid_params[mo_param] 2338 min_val = min_params[mo_param] 2339 set_val = params[mo_param] 2340 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2341 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) ) 2342 if rel_change > ds.rel_change: 2343 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2344 print("###################################") 2345 2346 ## Make test on parameters. 2347 if mo_param == 'dw': 2348 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2349 elif mo_param == 'kex': 2350 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2351 elif mo_param == 'pA': 2352 self.assertAlmostEqual(set_val, min_val, 2)
2353 2354
2356 """Test synthetic cpmg data. 2357 2358 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2359 """ 2360 2361 # Reset. 2362 #self.interpreter.reset() 2363 2364 ## Set Experiments. 2365 model_create = 'NS CPMG 2-site 3D' 2366 #model_create = 'NS CPMG 2-site expanded' 2367 model_analyse = 'CR72' 2368 # Exp 1 2369 sfrq_1 = 599.8908617*1E6 2370 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2371 time_T2_1 = 0.06 2372 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2373 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2374 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2375 2376 sfrq_2 = 499.8908617*1E6 2377 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2378 time_T2_2 = 0.05 2379 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2380 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2381 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2382 2383 # Collect all exps 2384 exps = [exp_1, exp_2] 2385 2386 spins = [ 2387 ['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.} ] 2388 ] 2389 2390 # Collect the data to be used. 2391 ds.data = [model_create, model_analyse, spins, exps] 2392 2393 # The tmp directory. None is the local directory. 2394 ds.tmpdir = ds.tmpdir 2395 2396 # The results directory. None is the local directory. 2397 #ds.resdir = None 2398 ds.resdir = ds.tmpdir 2399 2400 # Do r20_from_min_r2eff ?. 2401 ds.r20_from_min_r2eff = True 2402 2403 # Remove insignificant level. 2404 ds.insignificance = 0.0 2405 2406 # The grid search size (the number of increments per dimension). 2407 ds.GRID_INC = 8 2408 2409 # The do clustering. 2410 ds.do_cluster = False 2411 2412 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2413 # The default value is 1e-25. 2414 ds.set_func_tol = 1e-9 2415 2416 # The maximum number of iterations. 2417 # The default value is 1e7. 2418 ds.set_max_iter = 1000 2419 2420 # The verbosity level. 2421 ds.verbosity = 1 2422 2423 # The rel_change WARNING level. 2424 ds.rel_change = 0.05 2425 2426 # The plot_curves. 2427 ds.plot_curves = False 2428 2429 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2430 ds.sherekhan_input = False 2431 2432 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2433 ds.opendx = False 2434 2435 # The set r2eff err. 2436 ds.r2eff_err = 0.1 2437 2438 # The print result info. 2439 ds.print_res = False 2440 2441 # Execute the script. 2442 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2443 2444 cur_spins = ds.data[2] 2445 # Compare results. 2446 for i in range(len(cur_spins)): 2447 res_name, res_num, spin_name, params = cur_spins[i] 2448 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2449 cur_spin = return_spin(cur_spin_id) 2450 2451 grid_params = ds.grid_results[i][3] 2452 min_params = ds.min_results[i][3] 2453 # Now read the parameters. 2454 print("For spin: '%s'"%cur_spin_id) 2455 for mo_param in cur_spin.params: 2456 # The R2 is a dictionary, depending on spectrometer frequency. 2457 if isinstance(getattr(cur_spin, mo_param), dict): 2458 grid_r2 = grid_params[mo_param] 2459 min_r2 = min_params[mo_param] 2460 set_r2 = params[mo_param] 2461 for key, val in list(set_r2.items()): 2462 grid_r2_frq = grid_r2[key] 2463 min_r2_frq = min_r2[key] 2464 set_r2_frq = set_r2[key] 2465 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2466 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2467 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) ) 2468 if rel_change > ds.rel_change: 2469 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2470 print("###################################") 2471 2472 ## Make test on R2. 2473 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2474 else: 2475 grid_val = grid_params[mo_param] 2476 min_val = min_params[mo_param] 2477 set_val = params[mo_param] 2478 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2479 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) ) 2480 if rel_change > ds.rel_change: 2481 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2482 print("###################################") 2483 2484 ## Make test on parameters. 2485 if mo_param == 'dw': 2486 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2487 elif mo_param == 'kex': 2488 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2489 elif mo_param == 'pA': 2490 self.assertAlmostEqual(set_val, min_val, 3)
2491 2492
2494 """Test synthetic cpmg data. 2495 2496 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2497 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. 2498 """ 2499 2500 # Reset. 2501 #self.interpreter.reset() 2502 2503 ## Set Experiments. 2504 model_create = 'NS CPMG 2-site 3D' 2505 #model_create = 'NS CPMG 2-site expanded' 2506 model_analyse = 'B14' 2507 # Exp 1 2508 sfrq_1 = 599.8908617*1E6 2509 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2510 time_T2_1 = 0.06 2511 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2512 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2513 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2514 2515 sfrq_2 = 499.8908617*1E6 2516 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2517 time_T2_2 = 0.05 2518 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2519 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2520 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2521 2522 # Collect all exps 2523 exps = [exp_1, exp_2] 2524 2525 spins = [ 2526 ['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.} ] 2527 ] 2528 2529 # Collect the data to be used. 2530 ds.data = [model_create, model_analyse, spins, exps] 2531 2532 # The tmp directory. None is the local directory. 2533 ds.tmpdir = ds.tmpdir 2534 2535 # The results directory. None is the local directory. 2536 #ds.resdir = None 2537 ds.resdir = ds.tmpdir 2538 2539 # Do r20_from_min_r2eff ?. 2540 ds.r20_from_min_r2eff = True 2541 2542 # Remove insignificant level. 2543 ds.insignificance = 0.0 2544 2545 # The grid search size (the number of increments per dimension). 2546 ds.GRID_INC = 8 2547 2548 # The do clustering. 2549 ds.do_cluster = False 2550 2551 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2552 # The default value is 1e-25. 2553 ds.set_func_tol = 1e-9 2554 2555 # The maximum number of iterations. 2556 # The default value is 1e7. 2557 ds.set_max_iter = 1000 2558 2559 # The verbosity level. 2560 ds.verbosity = 1 2561 2562 # The rel_change WARNING level. 2563 ds.rel_change = 0.05 2564 2565 # The plot_curves. 2566 ds.plot_curves = False 2567 2568 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2569 ds.sherekhan_input = False 2570 2571 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2572 ds.opendx = False 2573 2574 # The set r2eff err. 2575 ds.r2eff_err = 0.1 2576 2577 # The print result info. 2578 ds.print_res = False 2579 2580 # Execute the script. 2581 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2582 2583 cur_spins = ds.data[2] 2584 # Compare results. 2585 for i in range(len(cur_spins)): 2586 res_name, res_num, spin_name, params = cur_spins[i] 2587 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2588 cur_spin = return_spin(cur_spin_id) 2589 2590 grid_params = ds.grid_results[i][3] 2591 min_params = ds.min_results[i][3] 2592 # Now read the parameters. 2593 print("For spin: '%s'"%cur_spin_id) 2594 for mo_param in cur_spin.params: 2595 # The R2 is a dictionary, depending on spectrometer frequency. 2596 if isinstance(getattr(cur_spin, mo_param), dict): 2597 grid_r2 = grid_params[mo_param] 2598 min_r2 = min_params[mo_param] 2599 set_r2 = params[mo_param] 2600 for key, val in list(set_r2.items()): 2601 grid_r2_frq = grid_r2[key] 2602 min_r2_frq = min_r2[key] 2603 set_r2_frq = set_r2[key] 2604 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2605 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2606 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) ) 2607 if rel_change > ds.rel_change: 2608 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2609 print("###################################") 2610 2611 ## Make test on R2. 2612 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2613 else: 2614 grid_val = grid_params[mo_param] 2615 min_val = min_params[mo_param] 2616 set_val = params[mo_param] 2617 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2618 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) ) 2619 if rel_change > ds.rel_change: 2620 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2621 print("###################################") 2622 2623 ## Make test on parameters. 2624 if mo_param == 'dw': 2625 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2626 elif mo_param == 'kex': 2627 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2628 elif mo_param == 'pA': 2629 self.assertAlmostEqual(set_val, min_val, 6)
2630 2631
2633 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2634 2635 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2636 """ 2637 2638 # Reset. 2639 #self.interpreter.reset() 2640 2641 ## Set Experiments. 2642 model_create = 'NS CPMG 2-site 3D' 2643 #model_create = 'NS CPMG 2-site expanded' 2644 model_analyse = 'CR72' 2645 2646 # Exp 1 2647 sfrq_1 = 599.8908617*1E6 2648 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2649 time_T2_1 = 0.06 2650 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2651 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2652 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2653 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2654 2655 sfrq_2 = 499.8908617*1E6 2656 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2657 time_T2_2 = 0.05 2658 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2659 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2660 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2661 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2662 2663 # Collect all exps 2664 exps = [exp_1, exp_2] 2665 2666 spins = [ 2667 ['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.} ], 2668 ['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.} ] 2669 ] 2670 2671 # Collect the data to be used. 2672 ds.data = [model_create, model_analyse, spins, exps] 2673 2674 # The tmp directory. None is the local directory. 2675 ds.tmpdir = ds.tmpdir 2676 2677 # The results directory. None is the local directory. 2678 #ds.resdir = None 2679 ds.resdir = ds.tmpdir 2680 2681 # Do r20_from_min_r2eff ?. 2682 ds.r20_from_min_r2eff = True 2683 2684 # Remove insignificant level. 2685 ds.insignificance = 0.0 2686 2687 # The grid search size (the number of increments per dimension). 2688 ds.GRID_INC = 13 2689 2690 # The do clustering. 2691 ds.do_cluster = True 2692 2693 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2694 # The default value is 1e-25. 2695 ds.set_func_tol = 1e-8 2696 2697 # The maximum number of iterations. 2698 # The default value is 1e7. 2699 ds.set_max_iter = 10000 2700 2701 # The verbosity level. 2702 ds.verbosity = 1 2703 2704 # The rel_change WARNING level. 2705 ds.rel_change = 0.05 2706 2707 # The plot_curves. 2708 ds.plot_curves = False 2709 2710 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2711 ds.sherekhan_input = False 2712 2713 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2714 ds.opendx = False 2715 2716 # The set r2eff err. 2717 ds.r2eff_err = 0.1 2718 2719 # The print result info. 2720 ds.print_res = False 2721 2722 # Execute the script. 2723 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2724 2725 cur_spins = ds.data[2] 2726 # Compare results. 2727 for i in range(len(cur_spins)): 2728 res_name, res_num, spin_name, params = cur_spins[i] 2729 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2730 cur_spin = return_spin(cur_spin_id) 2731 2732 grid_params = ds.grid_results[i][3] 2733 2734 # Extract the clust results. 2735 min_params = ds.clust_results[i][3] 2736 # Now read the parameters. 2737 print("For spin: '%s'"%cur_spin_id) 2738 for mo_param in cur_spin.params: 2739 # The R2 is a dictionary, depending on spectrometer frequency. 2740 if isinstance(getattr(cur_spin, mo_param), dict): 2741 grid_r2 = grid_params[mo_param] 2742 min_r2 = min_params[mo_param] 2743 set_r2 = params[mo_param] 2744 for key, val in list(set_r2.items()): 2745 grid_r2_frq = grid_r2[key] 2746 min_r2_frq = min_r2[key] 2747 set_r2_frq = set_r2[key] 2748 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2749 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2750 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) ) 2751 if rel_change > ds.rel_change: 2752 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2753 print("###################################") 2754 2755 ## Make test on R2. 2756 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2757 else: 2758 grid_val = grid_params[mo_param] 2759 min_val = min_params[mo_param] 2760 set_val = params[mo_param] 2761 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2762 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) ) 2763 if rel_change > ds.rel_change: 2764 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2765 print("###################################") 2766 2767 ## Make test on parameters. 2768 if mo_param == 'dw': 2769 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2770 elif mo_param == 'kex': 2771 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2772 elif mo_param == 'pA': 2773 self.assertAlmostEqual(set_val, min_val, 2)
2774 2775
2777 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2778 2779 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2780 """ 2781 2782 # Reset. 2783 #self.interpreter.reset() 2784 2785 ## Set Experiments. 2786 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2787 model_analyse = 'CR72' 2788 # Exp 1 2789 sfrq_1 = 599.8908617*1E6 2790 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2791 time_T2_1 = 0.06 2792 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2793 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2794 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2795 2796 sfrq_2 = 499.8908617*1E6 2797 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2798 time_T2_2 = 0.05 2799 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2800 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2801 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2802 2803 # Collect all exps 2804 exps = [exp_1, exp_2] 2805 2806 spins = [ 2807 ['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} ] 2808 ] 2809 2810 # Collect the data to be used. 2811 ds.data = [model_create, model_analyse, spins, exps] 2812 2813 # The tmp directory. None is the local directory. 2814 ds.tmpdir = ds.tmpdir 2815 2816 # The results directory. None is the local directory. 2817 #ds.resdir = None 2818 ds.resdir = ds.tmpdir 2819 2820 # Do r20_from_min_r2eff ?. 2821 ds.r20_from_min_r2eff = True 2822 2823 # Remove insignificant level. 2824 ds.insignificance = 0.0 2825 2826 # The grid search size (the number of increments per dimension). 2827 ds.GRID_INC = None 2828 2829 # The do clustering. 2830 ds.do_cluster = False 2831 2832 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2833 # The default value is 1e-25. 2834 ds.set_func_tol = 1e-9 2835 2836 # The maximum number of iterations. 2837 # The default value is 1e7. 2838 ds.set_max_iter = 1000 2839 2840 # The verbosity level. 2841 ds.verbosity = 1 2842 2843 # The rel_change WARNING level. 2844 ds.rel_change = 0.05 2845 2846 # The plot_curves. 2847 ds.plot_curves = False 2848 2849 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2850 ds.sherekhan_input = False 2851 2852 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2853 ds.opendx = False 2854 2855 # The set r2eff err. 2856 ds.r2eff_err = 0.1 2857 2858 # The print result info. 2859 ds.print_res = False 2860 2861 # Execute the script. 2862 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2863 2864 # Get the spins. 2865 cur_spins = ds.data[2] 2866 2867 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2868 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2869 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2870 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2871 2872 # Copy R2eff, but not the original parameters 2873 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2874 2875 # Then select model. 2876 self.interpreter.relax_disp.select_model(model=model_analyse) 2877 2878 # Define dx.map settings. 2879 ds.dx_inc = 4 2880 ds.dx_params = ['dw', 'pA', 'kex'] 2881 2882 res_name, res_num, spin_name, params = cur_spins[0] 2883 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2884 cur_spin = return_spin(cur_spin_id) 2885 2886 print("Params for dx map is") 2887 print(ds.dx_params) 2888 print("Point param for dx map is") 2889 print(ds.dx_set_val) 2890 cur_model = model_analyse.replace(' ', '_') 2891 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2892 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2893 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) 2894 2895 ## Check for file creation 2896 # Set filepaths. 2897 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2898 map_net = ds.tmpdir+sep+file_name_map+".net" 2899 map_general = ds.tmpdir+sep+file_name_map+".general" 2900 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir) 2901 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir) 2902 2903 point_general = ds.tmpdir+sep+file_name_point+".general" 2904 point_point = ds.tmpdir+sep+file_name_point 2905 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir) 2906 2907 # Test the files exists. 2908 self.assert_(access(map_cfg, F_OK)) 2909 self.assert_(access(map_net, F_OK)) 2910 self.assert_(access(map_general, F_OK)) 2911 self.assert_(access(map_par, F_OK)) 2912 self.assert_(access(map_plot, F_OK)) 2913 self.assert_(access(point_general, F_OK)) 2914 self.assert_(access(point_point, F_OK)) 2915 self.assert_(access(point_par, F_OK)) 2916 2917 # Open the files for testing. 2918 # Check the cfg file. 2919 print("\nChecking the dx map .cfg file.") 2920 res_file = [ 2921 '//'+"\n", 2922 '//'+"\n", 2923 '// time: Thu May 8 18:55:31 2014'+"\n", 2924 '//'+"\n", 2925 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2926 '//'+"\n", 2927 '//'+"\n", 2928 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2929 '// title: value = Control Panel'+"\n", 2930 '//'+"\n", 2931 '// workspace: width = 251, height = 142'+"\n", 2932 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2933 '//'+"\n", 2934 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2935 '// selections: maximum = 2, current = 0 '+"\n", 2936 '// option[0]: name = "Colour", value = 1'+"\n", 2937 '// option[1]: name = "Grey", value = 2'+"\n", 2938 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2939 '// label: value = Colour Selector'+"\n", 2940 '//'+"\n", 2941 '// node Image[3]:'+"\n", 2942 '// title: value = Surface'+"\n", 2943 '// depth: value = 24'+"\n", 2944 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2945 ] 2946 file = open(map_cfg, 'r') 2947 lines = file.readlines() 2948 file.close() 2949 for i in range(len(res_file)): 2950 # Skip time point 2951 if i == 2: 2952 continue 2953 self.assertEqual(res_file[i], lines[i]) 2954 2955 print("\nChecking the dx map .general file.") 2956 res_file = [ 2957 'file = CR72_map_1_N'+"\n", 2958 'grid = 5 x 5 x 5'+"\n", 2959 'format = ascii'+"\n", 2960 'interleaving = field'+"\n", 2961 'majority = row'+"\n", 2962 'field = data'+"\n", 2963 'structure = scalar'+"\n", 2964 'type = float'+"\n", 2965 'dependency = positions'+"\n", 2966 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2967 ''+"\n", 2968 'end'+"\n", 2969 ] 2970 file = open(map_general, 'r') 2971 lines = file.readlines() 2972 file.close() 2973 for i in range(len(res_file)): 2974 # Skip time point 2975 #if i == 2: 2976 # continue 2977 self.assertEqual(res_file[i], lines[i]) 2978 2979 print("\nChecking the dx point .general file.") 2980 res_file = [ 2981 'file = CR72_point_1_N'+"\n", 2982 'points = 2'+"\n", 2983 'format = ascii'+"\n", 2984 'interleaving = field'+"\n", 2985 'field = locations, field0'+"\n", 2986 'structure = 3-vector, scalar'+"\n", 2987 'type = float, float'+"\n", 2988 ''+"\n", 2989 'end'+"\n", 2990 ] 2991 file = open(point_general, 'r') 2992 lines = file.readlines() 2993 file.close() 2994 for i in range(len(res_file)): 2995 # Skip time point 2996 #if i == 2: 2997 # continue 2998 self.assertEqual(res_file[i], lines[i]) 2999 3000 print("\nChecking the dx point point file.") 3001 res_file = [ 3002 '0.8 3.92 0.39964 1'+"\n", 3003 '0.76981 3.9169 0.41353 1'+"\n", 3004 ] 3005 file = open(point_point, 'r') 3006 lines = file.readlines() 3007 file.close() 3008 for i in range(len(res_file)): 3009 # Skip time point 3010 #if i == 2: 3011 # continue 3012 self.assertEqual(res_file[i], lines[i]) 3013 3014 print("\nChecking the dx point par file.") 3015 res_file = [ 3016 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3017 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3018 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n", 3019 ] 3020 res_file2 = [ 3021 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3022 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3023 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n", 3024 ] # Python 2.5 and 3.1. 3025 file = open(point_par, 'r') 3026 lines = file.readlines() 3027 file.close() 3028 for i in range(len(res_file)): 3029 if lines[i] != res_file[i] and lines[i] != res_file2[i]: 3030 self.assertEqual(res_file[i], lines[i]) 3031 3032 print("\nChecking the matplotlib surface plot file.") 3033 res_file = [ 3034 'from copy import deepcopy'+"\n", 3035 'import numpy as np'+"\n", 3036 'import scipy.interpolate'+"\n", 3037 'from numpy.ma import masked_where'+"\n", 3038 ''+"\n", 3039 'from mpl_toolkits.mplot3d import axes3d'+"\n", 3040 'import matplotlib.pyplot as plt'+"\n", 3041 'from matplotlib import cm'+"\n", 3042 ''+"\n", 3043 '# Open file and get header.'+"\n", 3044 'mapfile_name = "%s.par"'%file_name_map+"\n", 3045 'pointfile_name = "%s.par"'%file_name_point+"\n", 3046 ''+"\n", 3047 ] 3048 file = open(map_plot, 'r') 3049 lines = file.readlines() 3050 file.close() 3051 for i in range(len(res_file)): 3052 self.assertEqual(res_file[i], lines[i])
3053 3054
3056 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 3057 3058 # Reset. 3059 self.interpreter.reset() 3060 3061 # Load the base data. 3062 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 3063 self.interpreter.state.load(data_path+sep+'r2eff_values') 3064 3065 # The type. 3066 curve_type = get_curve_type(id='500_133.33.in') 3067 self.assertEqual(curve_type, 'fixed time')
3068 3069
3070 - def test_curve_type_r1rho_exponential(self, model=None):
3071 """Test the curve type detection using the 'M61' exponential test data.""" 3072 3073 # Reset. 3074 self.interpreter.reset() 3075 3076 # Load the base data. 3077 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 3078 self.interpreter.state.load(data_path+sep+'r2eff_values') 3079 3080 # The type. 3081 curve_type = get_curve_type(id='nu_2000_ncyc9') 3082 self.assertEqual(curve_type, 'exponential')
3083 3084
3085 - def test_curve_type_r1rho_fixed_time(self, model=None):
3086 """Test the curve type detection using the 'TP02' fixed time test data.""" 3087 3088 # Reset. 3089 self.interpreter.reset() 3090 3091 # Load the base data. 3092 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 3093 self.interpreter.state.load(data_path+sep+'r2eff_values') 3094 3095 # The type. 3096 curve_type = get_curve_type(id='nu_1000.0_500MHz') 3097 self.assertEqual(curve_type, 'fixed time')
3098 3099
3100 - def test_dpl94_data_to_dpl94(self):
3101 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 3102 3103 # Fixed time variable. 3104 ds.fixed = True 3105 3106 # Execute the script. 3107 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') 3108 3109 # The original parameters. 3110 i0 = [100000.0, 20000.0] 3111 r1rho_prime = [2.25, 24.0] 3112 pA = 0.7 3113 kex = 1000.0 3114 delta_omega = [1.0, 2.0] 3115 phi_ex = [] 3116 for i in range(2): 3117 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 3118 3119 # Switch to the 'DPL94' model data pipe, then check for each spin. 3120 self.interpreter.pipe.switch('DPL94 - relax_disp') 3121 spin_index = 0 3122 for spin, spin_id in spin_loop(return_id=True): 3123 # Printout. 3124 print("\nSpin %s." % spin_id) 3125 3126 # Check the fitted parameters. 3127 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 3128 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 3129 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 3130 3131 # Increment the spin index. 3132 spin_index += 1
3133 3134
3135 - def test_dx_map_clustered(self):
3136 """Test making dx_map for residues under clustered calculation. 3137 3138 This uses CPMG data from: 3139 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 3140 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 3141 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 3142 """ 3143 3144 # Define path to data 3145 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 3146 3147 # Read data. 3148 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3149 3150 # Get residue of interest. 3151 cur_spin_id = ":%i@%s"%(52, 'N') 3152 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3153 3154 # Get the spin container. 3155 cur_spin = return_spin(cur_spin_id) 3156 3157 # Get the chi2 value 3158 pre_chi2 = cur_spin.chi2 3159 3160 # Then do a local minimisation. 3161 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3162 self.interpreter.minimise.calculate() 3163 3164 # Get the chi2 value after calculation. 3165 calc_chi2 = cur_spin.chi2 3166 3167 # Assert calculation is equal. 3168 self.assertAlmostEqual(pre_chi2, calc_chi2) 3169 3170 # Define dx.map settings. 3171 dx_inc = 2 3172 dx_inc_sides = dx_inc / 2 3173 3174 dx_params = ['dw', 'pA', 'kex'] 3175 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3176 3177 print("Params for dx map is") 3178 print(dx_params) 3179 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3180 print(dx_point_clustered_min) 3181 3182 # Define file_names. 3183 cur_model = 'CR72' 3184 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3185 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3186 3187 # Step-size of parameter is 10 % 3188 param_delta = 0.1 3189 3190 # Determine bounds for lower and upper 3191 lower = [] 3192 upper = [] 3193 for i, param_val in enumerate(dx_point_clustered_min): 3194 param = dx_params[i] 3195 step_val = param_delta * param_val 3196 step_length = step_val * dx_inc_sides 3197 3198 # Calculate value 3199 low_val = param_val - step_length 3200 lower.append(low_val) 3201 3202 upp_val = param_val + step_length 3203 upper.append(upp_val) 3204 3205 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)) 3206 3207 # If the number of increments are 2, there will be 3 point calculations per parameter. 3208 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3209 dx_param_indexes = dx_inc + 1 3210 dx_point_index = dx_inc_sides + 1 3211 3212 # Find the line number. 3213 line = 1 3214 for i in range(1, dx_param_indexes + 1): 3215 for j in range(1, dx_param_indexes + 1): 3216 for k in range(1, dx_param_indexes + 1): 3217 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3218 line_chi2 = line 3219 # Add to line counter. 3220 line += 1 3221 3222 # Define temporary folder. 3223 result_dir = self.tmpdir 3224 3225 # For testing. 3226 #result_dir = None 3227 #lower = None 3228 #upper = None 3229 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3230 3231 3232 # Then do the map. 3233 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) 3234 3235 # Print where to locate values. 3236 nr_chi2_val = dx_param_indexes**3 3237 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3238 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3239 3240 ## Check for file creation 3241 # Set filepaths. 3242 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3243 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3244 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3245 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3246 3247 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3248 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3249 3250 # Test the files exists. 3251 self.assert_(access(map_cfg, F_OK)) 3252 self.assert_(access(map_net, F_OK)) 3253 self.assert_(access(map_general, F_OK)) 3254 self.assert_(access(point_general, F_OK)) 3255 self.assert_(access(point_point, F_OK)) 3256 3257 # Open the file, and assert the chi2 value is as expected. 3258 get_data = extract_data(file=map_name) 3259 3260 # Extract line 0, column 0. 3261 test = float(get_data[line_chi2-1][0]) 3262 3263 # Assert. 3264 self.assertAlmostEqual(test, pre_chi2, 6)
3265 3266
3268 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file. 3269 3270 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. 3271 3272 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). 3273 """ 3274 3275 # Define path to data 3276 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting' 3277 3278 # Read data. 3279 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2') 3280 3281 # Get residue of interest. 3282 cur_spin_id = ":%i@%s"%(65, 'N') 3283 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3284 3285 # Get the spin container. 3286 cur_spin = return_spin(cur_spin_id) 3287 3288 # Get the chi2 value 3289 pre_chi2 = cur_spin.chi2 3290 3291 # Then do a local minimisation. 3292 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3293 self.interpreter.minimise.calculate() 3294 3295 # Get the chi2 value after calculation. 3296 calc_chi2 = cur_spin.chi2 3297 3298 # Assert calculation is equal. 3299 self.assertAlmostEqual(pre_chi2, calc_chi2) 3300 3301 # Define dx.map settings. 3302 dx_inc = 2 3303 dx_params = ['dw', 'k_AB', 'r2a'] 3304 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']] 3305 3306 print("Params for dx map is") 3307 print(dx_params) 3308 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3309 print(dx_point_clustered_min) 3310 3311 # Define file_names. 3312 cur_model = 'TSMFK01' 3313 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3314 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3315 3316 # Determine bounds for lower and upper 3317 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]] 3318 upper = [19.0, 2.4, 9.5] 3319 3320 # Define temporary folder. 3321 result_dir = self.tmpdir 3322 3323 # For testing. 3324 #result_dir = None 3325 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3326 3327 # Then do the map. 3328 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) 3329 3330 # Print where to locate values. 3331 nr_chi2_val = (dx_inc + 1)**3 3332 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3333 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) ) 3334 3335 ## Check for file creation 3336 # Set filepaths. 3337 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3338 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3339 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3340 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3341 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir) 3342 3343 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3344 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3345 3346 # Test the files exists. 3347 self.assert_(access(map_cfg, F_OK)) 3348 self.assert_(access(map_net, F_OK)) 3349 self.assert_(access(map_general, F_OK)) 3350 self.assert_(access(map_par, F_OK)) 3351 self.assert_(access(point_general, F_OK)) 3352 self.assert_(access(point_point, F_OK)) 3353 3354 print("\nParams for dx map is") 3355 print(dx_params) 3356 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3357 print(dx_point_clustered_min, "\n") 3358 3359 # Open the parameter chi2 file, and assert the chi2 value in the sorted parameter file is not lower that than the global minimisation. 3360 get_data = extract_data(file=map_par) 3361 3362 # Extract line 1, column 9. 3363 test = float(get_data[1][9]) 3364 3365 # Print data if map contain a lower value than the global minimised value. 3366 if test < pre_chi2: 3367 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test)) 3368 for line in get_data: 3369 print(line)
3370 3371 # Assert that the initial global chi2 is lower than the map value. 3372 3373 # The following test was taken out, since this a particular interesting case. 3374 # There exist a double minimum, where relax has not found the global minimum. 3375 # This is due to not grid searching for R2A, but using the minimum 3376 #self.assert_(pre_chi2 < test) 3377 3378
3379 - def test_estimate_r2eff_err(self):
3380 """Test the user function for estimating R2eff errors from exponential curve fitting. 3381 3382 This follows Task 7822. 3383 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. 3384 3385 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3386 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3387 """ 3388 3389 # Cluster residues 3390 cluster_ids = [ 3391 ":13@N", 3392 ":15@N", 3393 ":16@N", 3394 ":25@N", 3395 ":26@N", 3396 ":28@N", 3397 ":39@N", 3398 ":40@N", 3399 ":41@N", 3400 ":43@N", 3401 ":44@N", 3402 ":45@N", 3403 ":49@N", 3404 ":52@N", 3405 ":53@N"] 3406 3407 # Load the data. 3408 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3409 3410 # The dispersion models. 3411 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3412 3413 # The grid search size (the number of increments per dimension). 3414 GRID_INC = None 3415 3416 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3417 MC_NUM = 3 3418 3419 # Model selection technique. 3420 MODSEL = 'AIC' 3421 3422 # Execute the auto-analysis (fast). 3423 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3424 OPT_FUNC_TOL = 1e-25 3425 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3426 OPT_MAX_ITERATIONS = 10000000 3427 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3428 3429 result_dir_name = ds.tmpdir 3430 3431 # Make all spins free 3432 for curspin in cluster_ids: 3433 self.interpreter.relax_disp.cluster('free spins', curspin) 3434 # Shut them down 3435 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3436 3437 # Select only a subset of spins for global fitting 3438 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3439 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3440 3441 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3442 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3443 3444 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3445 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3446 3447 # Set the model. 3448 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3449 3450 # Check if intensity errors have already been calculated. 3451 check_intensity_errors() 3452 3453 # Do a grid search. 3454 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3455 3456 # Minimise. 3457 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3458 3459 # Estimate R2eff errors. 3460 self.interpreter.relax_disp.r2eff_err_estimate() 3461 3462 r1_fit = True 3463 3464 # Run the analysis. 3465 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) 3466 3467 # Verify the data. 3468 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3469 3470
3472 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3473 3474 This follows Task 7822. 3475 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. 3476 3477 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3478 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3479 """ 3480 3481 # Cluster residues 3482 cluster_ids = [ 3483 ":13@N", 3484 ":15@N", 3485 ":16@N", 3486 ":25@N", 3487 ":26@N", 3488 ":28@N", 3489 ":39@N", 3490 ":40@N", 3491 ":41@N", 3492 ":43@N", 3493 ":44@N", 3494 ":45@N", 3495 ":49@N", 3496 ":52@N", 3497 ":53@N"] 3498 3499 # Load the data. 3500 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3501 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3502 3503 # Set pipe name, bundle and type. 3504 pipe_name = 'base pipe' 3505 pipe_bundle = 'relax_disp' 3506 pipe_type = 'relax_disp' 3507 3508 # Create the data pipe. 3509 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3510 3511 file = data_path + '1_setup_r1rho_GUI.py' 3512 self.interpreter.script(file=file, dir=None) 3513 3514 # The dispersion models. 3515 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3516 3517 # The grid search size (the number of increments per dimension). 3518 GRID_INC = None 3519 3520 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3521 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3522 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3523 EXP_MC_NUM = -1 3524 3525 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3526 MC_NUM = 3 3527 3528 # Model selection technique. 3529 MODSEL = 'AIC' 3530 3531 # Execute the auto-analysis (fast). 3532 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3533 OPT_FUNC_TOL = 1e-25 3534 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3535 OPT_MAX_ITERATIONS = 10000000 3536 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3537 3538 # Make all spins free 3539 #for curspin in cluster_ids: 3540 # self.interpreter.relax_disp.cluster('free spins', curspin) 3541 # # Shut them down 3542 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3543 3544 # Make all spins free 3545 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3546 3547 # Select only a subset of spins for global fitting 3548 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3549 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3550 3551 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3552 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3553 3554 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3555 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3556 3557 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3558 print(spin_id) 3559 3560 result_dir_name = self.tmpdir 3561 r1_fit = True 3562 3563 # Run the analysis. 3564 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) 3565 3566 # Verify the data. 3567 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3568 3569
3571 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3572 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3573 3574 This follows Task 7822. 3575 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. 3576 3577 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3578 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3579 3580 NOTE: The difference in the methods was due to a bug in relax! 3581 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. 3582 3583 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3584 """ 3585 3586 # Define data path. 3587 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" 3588 3589 # Create pipe. 3590 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3591 3592 # Read results for 2000 MC simulations. 3593 self.interpreter.results.read(prev_data_path + sep + 'results') 3594 3595 # Start dic. 3596 my_dic = {} 3597 param_key_list = [] 3598 3599 # Do boot strapping ? 3600 do_boot = True 3601 if do_boot: 3602 min_algor = 'Newton' 3603 min_options = () 3604 sim_boot = 200 3605 scaling_list = [1.0, 1.0] 3606 3607 # First check sim values. 3608 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3609 # Add key to dic. 3610 my_dic[spin_id] = {} 3611 3612 # Loop over sim. 3613 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3614 # Loop over all exp type. 3615 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3616 # Generate the param_key. 3617 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3618 r2eff_sim_point = r2eff_sim[param_key] 3619 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3620 3621 # Assert point are higher than 0.0. 3622 #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) 3623 #print(point_info) 3624 self.assert_(r2eff_sim_point > 0.0) 3625 self.assert_(i0_sim_point > 0.0) 3626 3627 # Get the data. 3628 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3629 # Generate spin string. 3630 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3631 3632 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3633 # Generate the param_key. 3634 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3635 3636 # Loop over all sim, and collect data. 3637 r2eff_sim_l = [] 3638 i0_sim_l = [] 3639 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3640 i0_sim = cur_spin.i0_sim[i] 3641 3642 r2eff_sim_i = r2eff_sim[param_key] 3643 r2eff_sim_l.append(r2eff_sim_i) 3644 i0_sim_i = i0_sim[param_key] 3645 i0_sim_l.append(i0_sim_i) 3646 3647 # Take the standard deviation of all values. 3648 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3649 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3650 3651 # Append key. 3652 param_key_list.append(param_key) 3653 3654 # Add key to dic. 3655 my_dic[spin_id][param_key] = {} 3656 3657 # Get the value. 3658 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3659 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3660 i0 = getattr(cur_spin, 'i0')[param_key] 3661 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3662 3663 # Save to dic. 3664 my_dic[spin_id][param_key]['r2eff'] = r2eff 3665 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3666 my_dic[spin_id][param_key]['i0'] = i0 3667 my_dic[spin_id][param_key]['i0_err'] = i0_err 3668 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3669 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3670 3671 # Assert values are equal 3672 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3673 self.assertAlmostEqual(i0_sim_err, i0_err) 3674 3675 if do_boot: 3676 values = [] 3677 errors = [] 3678 times = [] 3679 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3680 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3681 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3682 times.append(time) 3683 3684 # Convert to numpy array. 3685 values = asarray(values) 3686 errors = asarray(errors) 3687 times = asarray(times) 3688 3689 R_m_sim_l = [] 3690 I0_m_sim_l = [] 3691 for j in range(sim_boot): 3692 if j in range(0, 100000, 100): 3693 print("Simulation %i"%j) 3694 # Start minimisation. 3695 3696 # Produce errors 3697 I_err = [] 3698 for j, error in enumerate(errors): 3699 I_error = gauss(values[j], error) 3700 I_err.append(I_error) 3701 # Convert to numpy array. 3702 I_err = asarray(I_err) 3703 3704 x0 = [r2eff, i0] 3705 model = Relax_fit_opt(model='exp', num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3706 3707 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) 3708 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3709 R_m_sim_l.append(R_m_sim_j) 3710 I0_m_sim_l.append(I0_m_sim_j) 3711 3712 # Get stats on distribution. 3713 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3714 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3715 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3716 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3717 3718 3719 # A new data pipe. 3720 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3721 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3722 3723 # Delete old errors. 3724 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3725 delattr(cur_spin, 'r2eff_err') 3726 delattr(cur_spin, 'i0_err') 3727 3728 # Set the model. 3729 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3730 3731 # Estimate R2eff and errors. 3732 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3733 3734 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3735 # Generate spin string. 3736 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3737 3738 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3739 # Generate the param_key. 3740 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3741 3742 # Get the value. 3743 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3744 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3745 i0_est = getattr(cur_spin, 'i0')[param_key] 3746 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3747 3748 # Get from dic. 3749 r2eff = my_dic[spin_id][param_key]['r2eff'] 3750 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3751 i0 = my_dic[spin_id][param_key]['i0'] 3752 i0_err = my_dic[spin_id][param_key]['i0_err'] 3753 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3754 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3755 3756 if do_boot: 3757 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3758 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3759 else: 3760 r2eff_boot_err = 0.0 3761 i0_boot_err = 0.0 3762 3763 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3764 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) ), 3765 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) ) 3766 3767 3768 # Now do it manually. 3769 estimate_r2eff(method='scipy.optimize.leastsq') 3770 3771 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3772 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3773 3774 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3775 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3776 3777 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3778 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3779 3780 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3781 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3782 3783 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3784 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3785 3786 3787
3788 - def test_exp_fit(self):
3789 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3790 3791 # Execute the script. 3792 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3793 3794 # The original exponential curve parameters. 3795 res_data = [ 3796 [15., 10., 20000., 25000.], 3797 [12., 11., 50000., 51000.], 3798 [17., 9., 100000., 96000.] 3799 ] 3800 3801 # List of parameters which do not belong to the model. 3802 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3803 3804 # Checks for each residue. 3805 for i in range(len(res_data)): 3806 # Printout. 3807 print("\nResidue number %s." % (i+1)) 3808 3809 # Check the fitted parameters. 3810 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3811 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3812 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) 3813 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) 3814 3815 # Check the simulation errors. 3816 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3817 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3818 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3819 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3820 3821 # Check that certain parameters are not present. 3822 for param in blacklist: 3823 print("\tChecking for the absence of the '%s' parameter." % param) 3824 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3825 3826 # Check the clustering information. 3827 self.assert_(hasattr(cdp, 'clustering')) 3828 keys = ['free spins', 'cluster'] 3829 for key in keys: 3830 self.assert_(key in cdp.clustering) 3831 self.assert_('test' not in cdp.clustering) 3832 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3833 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3834 3835
3836 - def test_finite_value(self):
3837 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3838 3839 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3840 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3841 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3842 3843 scaling_list = [1.0, 1.0] 3844 model = Relax_fit_opt(model='exp', num_params=2, values=I, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3845 3846 R = - 500. 3847 I0 = 1000. 3848 params = [R, I0] 3849 3850 chi2 = model.func(params) 3851 3852 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3853 self.assertNotEqual(chi2, inf)
3854 3855
3856 - def test_hansen_catia_input(self):
3857 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3858 3859 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. 3860 """ 3861 3862 # Load the R2eff results file. 3863 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3864 self.interpreter.results.read(file_name) 3865 self.interpreter.deselect.spin(':4') 3866 3867 # The spin isotopes. 3868 self.interpreter.spin.isotope("15N") 3869 3870 # Generate the input files. 3871 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3872 3873 # Check the r2eff set files. 3874 print("\nChecking the R2eff input set files.") 3875 files = ['data_set_500.inp', 'data_set_500.inp'] 3876 for file in files: 3877 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3878 data_set_500 = [ 3879 "ID=500\n", 3880 "Sfrq = 500\n", 3881 "Temperature = 0.0\n", 3882 "Nucleus = N15\n", 3883 "Couplednucleus = H1\n", 3884 "Time_equil = 0.0\n", 3885 "Pwx_cp = 0.0\n", 3886 "Taub = 0.0\n", 3887 "Time_T2 = 0.03\n", 3888 "Xcar = 0.0\n", 3889 "Seqfil = CW_CPMG\n", 3890 "Minerror = (2.%;0.5/s)\n", 3891 "Basis = (Iph_7)\n", 3892 "Format = (0;1;2)\n", 3893 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3894 "Data = (\n", 3895 " [70N;spin_70_N_500.cpmg];\n", 3896 " [71N;spin_71_N_500.cpmg];\n", 3897 ")\n", 3898 ] 3899 file = open(ds.tmpdir+sep+files[0]) 3900 lines = file.readlines() 3901 file.close() 3902 for i in range(len(data_set_500)): 3903 # Skip the data directory, as this is a random file name. 3904 if i == 14: 3905 continue 3906 3907 self.assertEqual(data_set_500[i], lines[i]) 3908 3909 # Check the r2eff files. 3910 print("\nChecking the R2eff input files.") 3911 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3912 for file in files: 3913 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3914 spin_70_N_500 = [ 3915 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3916 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3917 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3918 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3919 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3920 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3921 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3922 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3923 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3924 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3925 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3926 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3927 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3928 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3929 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3930 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3931 ] 3932 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3933 lines = file.readlines() 3934 file.close() 3935 for i in range(len(lines)): 3936 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3937 for i in range(len(spin_70_N_500)): 3938 self.assertEqual(spin_70_N_500[i], lines[i]) 3939 3940 # Check the main file. 3941 print("\nChecking the main CATIA execution file.") 3942 main_file = [ 3943 "ReadDataset(data_set_500.inp)\n", 3944 "ReadDataset(data_set_800.inp)\n", 3945 "ReadParam_Global(ParamGlobal.inp)\n", 3946 "ReadParam_Local(ParamSet1.inp)\n", 3947 "\n", 3948 "FreeLocalParam(all;Omega;false)\n", 3949 "FreeLocalParam(all;R1iph_500;false)\n", 3950 "FreeLocalParam(all;R1iph_800;false)\n", 3951 "\n", 3952 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3953 "\n", 3954 "PrintParam(output/GlobalParam.fit;global)\n", 3955 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3956 "PrintData(output/)\n", 3957 "\n", 3958 "ChiSq(all;all)\n", 3959 "exit(0)\n" 3960 ] 3961 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3962 lines = file.readlines() 3963 file.close() 3964 for i in range(len(main_file)): 3965 self.assertEqual(main_file[i], lines[i])
3966 3967
3969 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3970 3971 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. 3972 """ 3973 3974 # Set the model. 3975 ds.models = [ 3976 MODEL_NOREX, 3977 MODEL_LM63, 3978 MODEL_CR72, 3979 MODEL_IT99 3980 ] 3981 3982 # Execute the script. 3983 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3984 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3985 3986 # The R20 keys. 3987 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3988 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3989 3990 # The 'No Rex' model checks. 3991 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3992 spin70 = return_spin(":70") 3993 spin71 = return_spin(":71") 3994 print("\n\nOptimised parameters:\n") 3995 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3996 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3997 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3998 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3999 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4000 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4001 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4002 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4003 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4004 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4005 4006 # The 'LM63' model checks. 4007 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4008 spin70 = return_spin(":70") 4009 spin71 = return_spin(":71") 4010 print("\n\nOptimised parameters:\n") 4011 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4012 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4013 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4014 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4015 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4016 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4017 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4018 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4019 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4020 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4021 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4022 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4023 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4024 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4025 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4026 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4027 4028 # The 'CR72' model checks. 4029 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4030 spin70 = return_spin(":70") 4031 spin71 = return_spin(":71") 4032 print("\n\nOptimised parameters:\n") 4033 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4034 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4035 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4036 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4037 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4038 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4039 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4040 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4041 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4042 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4043 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4044 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4045 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4046 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4047 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4048 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4049 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4050 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4051 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4052 4053
4055 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 4056 4057 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. 4058 """ 4059 4060 # Set the model and numeric flag. 4061 ds.models = [ 4062 MODEL_NOREX, 4063 MODEL_CR72, 4064 MODEL_NS_CPMG_2SITE_EXPANDED 4065 ] 4066 ds.numeric_only = True 4067 4068 # Execute the script. 4069 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 4070 4071 # The R20 keys. 4072 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4073 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4074 4075 # The 'No Rex' model checks. 4076 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4077 spin70 = return_spin(":70") 4078 spin71 = return_spin(":71") 4079 print("\n\nOptimised parameters:\n") 4080 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4081 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4082 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4083 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4084 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4085 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4086 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 4087 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4088 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4089 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 4090 4091 # The 'CR72' model checks. 4092 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4093 spin70 = return_spin(":70") 4094 spin71 = return_spin(":71") 4095 print("\n\nOptimised parameters:\n") 4096 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4097 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4098 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4099 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4100 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4101 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4102 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4103 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4104 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4105 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4106 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4107 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4108 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4109 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4110 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4111 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4112 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4113 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4114 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 4115 4116 # The 'NS CPMG 2-site expanded' model checks. 4117 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 4118 spin70 = return_spin(":70") 4119 spin71 = return_spin(":71") 4120 print("\n\nOptimised parameters:\n") 4121 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4122 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4123 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4124 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4125 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4126 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4127 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4128 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 4129 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 4130 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 4131 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 4132 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 4133 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 4134 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 4135 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 4136 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 4137 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 4138 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 4139 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 4140 4141 # The final data pipe checks. 4142 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 4143 spin70 = return_spin(":70") 4144 spin71 = return_spin(":71") 4145 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 4146 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4147 4148
4150 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 4151 4152 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. 4153 """ 4154 4155 # Set the model. 4156 ds.models = [ 4157 MODEL_NOREX, 4158 MODEL_LM63, 4159 MODEL_CR72, 4160 MODEL_IT99 4161 ] 4162 4163 # Execute the script. 4164 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 4165 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 4166 4167 # The R20 keys. 4168 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4169 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4170 4171 # The 'No Rex' model checks. 4172 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4173 spin70 = return_spin(":70") 4174 spin71 = return_spin(":71") 4175 print("\n\nOptimised parameters:\n") 4176 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4177 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4178 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4179 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4180 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4181 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4182 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4183 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4184 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4185 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4186 4187 # The 'LM63' model checks. 4188 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4189 spin70 = return_spin(":70") 4190 spin71 = return_spin(":71") 4191 print("\n\nOptimised parameters:\n") 4192 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4193 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4194 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4195 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4196 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4197 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4198 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4199 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4200 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4201 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4202 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4203 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4204 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4205 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4206 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4207 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4208 4209 # The 'CR72' model checks. 4210 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4211 spin70 = return_spin(":70") 4212 spin71 = return_spin(":71") 4213 print("\n\nOptimised parameters:\n") 4214 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4215 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4216 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4217 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4218 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4219 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4220 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4221 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4222 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4223 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4224 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4225 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4226 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4227 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 4228 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 4229 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 4230 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 4231 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 4232 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4233 4234
4236 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 4237 4238 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. 4239 """ 4240 4241 # Set the model. 4242 ds.models = [ 4243 MODEL_R2EFF, 4244 MODEL_NOREX, 4245 MODEL_CR72, 4246 MODEL_NS_CPMG_2SITE_EXPANDED 4247 ] 4248 4249 # Execute the script. 4250 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 4251 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4252 4253 # The R20 keys. 4254 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4255 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4256 4257 # The 'No Rex' model checks. 4258 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4259 spin4 = return_spin(":4") 4260 spin70 = return_spin(":70") 4261 spin71 = return_spin(":71") 4262 print("\n\nOptimised parameters:\n") 4263 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4264 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4265 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4266 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4267 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4268 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4269 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4270 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4271 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4272 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4273 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4274 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4275 4276 # The 'CR72' model checks. 4277 self.interpreter.pipe.switch(pipe_name='CR72 - 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" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4286 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4287 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4288 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4289 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4290 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4291 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4292 self.assertAlmostEqual(spin4.dw, 0.0, 2) 4293 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4294 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4295 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4296 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4297 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4298 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4299 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4300 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4301 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4302 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4303 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2) 4304 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4305 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4306 4307
4309 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4310 4311 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. 4312 """ 4313 4314 # Base data setup. 4315 self.setup_hansen_cpmg_data(model='CR72') 4316 4317 # Alias the spins. 4318 spin70 = return_spin(":70") 4319 spin71 = return_spin(":71") 4320 4321 # The R20 keys. 4322 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4323 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4324 4325 # Set the initial parameter values. 4326 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4327 spin70.pA = 0.9 4328 spin70.dw = 6.0 4329 spin70.kex = 1500.0 4330 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4331 spin71.pA = 0.9 4332 spin71.dw = 4.0 4333 spin71.kex = 1900.0 4334 4335 # Low precision optimisation. 4336 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) 4337 4338 # Printout. 4339 print("\n\nOptimised parameters:\n") 4340 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4341 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4342 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4343 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4344 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4345 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4346 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4347 4348 # Checks for residue :70. 4349 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4350 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4351 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4352 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4353 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4354 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4355 4356 # Checks for residue :71. 4357 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4358 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4359 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4360 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4361 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4362 4363 # Test the conversion to k_AB from kex and pA. 4364 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4365 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4366 4367 # Test the conversion to k_BA from kex and pA. 4368 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4369 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4370 4371
4373 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4374 4375 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. 4376 """ 4377 4378 # Base data setup. 4379 self.setup_hansen_cpmg_data(model='CR72 full') 4380 4381 # Alias the spins. 4382 spin70 = return_spin(":70") 4383 spin71 = return_spin(":71") 4384 4385 # The R20 keys. 4386 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4387 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4388 4389 # Set the initial parameter values. 4390 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4391 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4392 spin70.pA = 0.9 4393 spin70.dw = 6.0 4394 spin70.kex = 1500.0 4395 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4396 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4397 spin71.pA = 0.9 4398 spin71.dw = 4.0 4399 spin71.kex = 1900.0 4400 4401 # Low precision optimisation. 4402 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) 4403 4404 # Printout. 4405 print("\n\nOptimised parameters:\n") 4406 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4407 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4408 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4409 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4410 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4411 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4412 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4413 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4414 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4415 4416 # Checks for residue :70. 4417 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4418 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4419 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4420 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4421 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4422 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4423 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4424 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4425 4426 # Checks for residue :71. 4427 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4428 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4429 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4430 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4431 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4432 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4433 4434 # Test the conversion to k_AB from kex and pA. 4435 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4436 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4437 4438 # Test the conversion to k_BA from kex and pA. 4439 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4440 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4441 4442
4444 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4445 4446 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. 4447 """ 4448 4449 # Base data setup. 4450 self.setup_hansen_cpmg_data(model='IT99') 4451 4452 # Alias the spins. 4453 spin70 = return_spin(":70") 4454 spin71 = return_spin(":71") 4455 4456 # The R20 keys. 4457 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4458 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4459 4460 # Set the initial parameter values. 4461 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4462 spin70.dw = 10.0 4463 spin70.pA = 0.5 4464 spin70.tex = 1000.09 4465 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4466 spin71.dw = 10.0 4467 spin71.pA = 0.95 4468 spin71.tex = 0.1 4469 4470 # Low precision optimisation. 4471 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) 4472 4473 # Printout. 4474 print("\n\nOptimised parameters:\n") 4475 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4476 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4477 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4478 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4479 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4480 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4481 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4482 4483 # Checks for residue :70. 4484 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4485 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4486 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4487 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4488 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4489 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4490 4491 # Checks for residue :71. 4492 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4493 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4494 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4495 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4496 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4497 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4498 4499
4501 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4502 4503 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. 4504 """ 4505 4506 # Base data setup. 4507 self.setup_hansen_cpmg_data(model='LM63') 4508 4509 # Alias the spins. 4510 spin70 = return_spin(":70") 4511 spin71 = return_spin(":71") 4512 4513 # The R20 keys. 4514 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4515 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4516 4517 # Set the initial parameter values. 4518 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4519 spin70.phi_ex = 0.3 4520 spin70.kex = 5000.0 4521 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4522 spin71.phi_ex = 0.1 4523 spin71.kex = 2500.0 4524 4525 # Low precision optimisation. 4526 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) 4527 4528 # Printout. 4529 print("\n\nOptimised parameters:\n") 4530 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4531 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4532 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4533 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4534 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4535 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4536 4537 # Checks for residue :70. 4538 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4539 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4540 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4541 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4542 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4543 4544 # Checks for residue :71. 4545 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4546 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4547 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4548 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4549 4550
4552 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4553 4554 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. 4555 """ 4556 4557 # Base data setup. 4558 self.setup_hansen_cpmg_data(model='LM63 3-site') 4559 4560 # Alias the spins. 4561 spin70 = return_spin(":70") 4562 spin71 = return_spin(":71") 4563 4564 # The R20 keys. 4565 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4566 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4567 4568 ## Set the initial parameter values. 4569 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4570 spin70.phi_ex_B = 0.14872003058250227 4571 spin70.phi_ex_C = 0.1319419923472704 4572 spin70.kB = 4103.672910444741 4573 spin70.kC = 7029.001690726248 4574 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4575 spin71.phi_ex_B = 0.04013553485505605 4576 spin71.phi_ex_C = 0.020050748406928887 4577 spin71.kB = 4045.3007136121364 4578 spin71.kC = 3586.38798270774 4579 4580 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4581 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4582 4583 # Low precision optimisation. 4584 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) 4585 4586 # Printout. 4587 print("\n\nOptimised parameters:\n") 4588 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4589 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4590 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4591 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4592 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4593 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4594 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4595 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4596 4597 # Checks for residue :70. 4598 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4599 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4600 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4601 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4602 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4603 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4604 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4605 4606 # Checks for residue :71. 4607 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4608 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4609 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4610 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4611 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4612 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4613 4614
4616 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4617 4618 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. 4619 """ 4620 4621 # Base data setup. 4622 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4623 4624 # Alias the spins. 4625 spin70 = return_spin(":70") 4626 spin71 = return_spin(":71") 4627 4628 # The R20 keys. 4629 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4630 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4631 4632 # Set the initial parameter values. 4633 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4634 spin70.pA = 0.9897754407 4635 spin70.dw = 5.642418428 4636 spin70.kex = 1743.666375 4637 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4638 spin71.pA = 0.9968032899 4639 spin71.dw = 4.577891393 4640 spin71.kex = 1830.044597 4641 4642 # Low precision optimisation. 4643 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) 4644 4645 # Printout. 4646 print("\n\nOptimised parameters:\n") 4647 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4648 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4649 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4650 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4651 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4652 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4653 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4654 4655 # Checks for residue :70. 4656 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4657 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4658 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4659 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4660 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4661 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4662 4663 # Checks for residue :71. 4664 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4665 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4666 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4667 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4668 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4669 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4670 4671 # Test the conversion to k_AB from kex and pA. 4672 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4673 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4674 4675 # Test the conversion to k_BA from kex and pA. 4676 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4677 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4678 4679
4681 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4682 4683 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. 4684 """ 4685 4686 # Base data setup. 4687 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4688 4689 # Alias the spins. 4690 spin70 = return_spin(":70") 4691 spin71 = return_spin(":71") 4692 4693 # The R20 keys. 4694 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4695 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4696 4697 # Set the initial parameter values. 4698 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4699 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4700 spin70.pA = 0.9884781357 4701 spin70.dw = 5.456507396 4702 spin70.kex = 1906.521189 4703 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4704 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4705 spin71.pA = 0.986709616684097 4706 spin71.dw = 2.09245158280905 4707 spin71.kex = 2438.2766211401 4708 4709 # Low precision optimisation. 4710 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) 4711 4712 # Printout. 4713 print("\n\nOptimised parameters:\n") 4714 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4715 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4716 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4717 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4718 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4719 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4720 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4721 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4722 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4723 4724 # Checks for residue :70. 4725 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4726 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4727 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4728 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4729 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4730 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4731 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4732 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4733 4734 # Checks for residue :71. 4735 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4736 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4737 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4738 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4739 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4740 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4741 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4742 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4743 4744 # Test the conversion to k_AB from kex and pA. 4745 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4746 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4747 4748 # Test the conversion to k_BA from kex and pA. 4749 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4750 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4751 4752
4754 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4755 4756 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. 4757 """ 4758 4759 # Base data setup. 4760 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4761 4762 # Alias the spins. 4763 spin70 = return_spin(":70") 4764 spin71 = return_spin(":71") 4765 4766 # The R20 keys. 4767 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4768 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4769 4770 # Set the initial parameter values. 4771 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4772 spin70.pA = 0.9 4773 spin70.dw = 6.0 4774 spin70.kex = 1500.0 4775 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4776 spin71.pA = 0.9 4777 spin71.dw = 4.0 4778 spin71.kex = 1900.0 4779 4780 # Low precision optimisation. 4781 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) 4782 4783 # Printout. 4784 print("\n\nOptimised parameters:\n") 4785 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4786 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4787 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4788 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4789 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4790 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4791 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4792 4793 # Checks for residue :70. 4794 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4795 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4796 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4797 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4798 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4799 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4800 4801 # Checks for residue :71. 4802 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4803 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4804 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4805 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4806 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4807 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4808 4809 # Test the conversion to k_AB from kex and pA. 4810 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4811 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4812 4813 # Test the conversion to k_BA from kex and pA. 4814 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4815 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4816 4817
4819 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4820 4821 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. 4822 """ 4823 4824 # Base data setup. 4825 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4826 4827 # Alias the spins. 4828 spin70 = return_spin(":70") 4829 spin71 = return_spin(":71") 4830 4831 # The R20 keys. 4832 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4833 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4834 4835 # Set the initial parameter values. 4836 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4837 spin70.pA = 0.9897519798 4838 spin70.dw = 5.644862195 4839 spin70.kex = 1723.820567 4840 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4841 spin71.pA = 0.9968032899 4842 spin71.dw = 4.577891393 4843 spin71.kex = 1830.044597 4844 4845 # Low precision optimisation. 4846 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) 4847 4848 # Printout. 4849 print("\n\nOptimised parameters:\n") 4850 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4851 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4852 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4853 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4854 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4855 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4856 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4857 4858 # Checks for residue :70. 4859 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4860 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4861 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4862 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4863 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4864 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4865 4866 # Checks for residue :71. 4867 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4868 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4869 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4870 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4871 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4872 4873 # Test the conversion to k_AB from kex and pA. 4874 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4875 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4876 4877 # Test the conversion to k_BA from kex and pA. 4878 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4879 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4880 4881
4883 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4884 4885 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. 4886 """ 4887 4888 # Base data setup. 4889 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4890 4891 # Alias the spins. 4892 spin70 = return_spin(":70") 4893 spin71 = return_spin(":71") 4894 4895 # The R20 keys. 4896 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4897 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4898 4899 # Set the initial parameter values. 4900 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4901 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4902 spin70.pA = 0.987648082613451 4903 spin70.dw = 5.30679853807572 4904 spin70.kex = 2033.25380420666 4905 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4906 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4907 spin71.pA = 0.992258541625787 4908 spin71.dw = 2.75140650899058 4909 spin71.kex = 2106.60885247431 4910 4911 # Low precision optimisation. 4912 self.interpreter.minimise.calculate() 4913 4914 # Checks for residue :70. 4915 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4916 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4917 4918
4919 - def test_hansen_cpmgfit_input(self):
4920 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4921 4922 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. 4923 """ 4924 4925 # Load the R2eff results file. 4926 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4927 self.interpreter.results.read(file_name) 4928 self.interpreter.deselect.spin(':4') 4929 4930 # Set up the model. 4931 self.interpreter.relax_disp.select_model('LM63') 4932 4933 # Generate the input files. 4934 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4935 4936 # What the files should contain. 4937 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'] 4938 spin1 = [ 4939 "title :70@N\n", 4940 "fields 2 11.7432964915 18.7892743865\n", 4941 "function CPMG\n", 4942 "R2 1 10 20\n", 4943 "Rex 0 100.0 100\n", 4944 "Tau 0 10.0 100\n", 4945 "xmgr\n", 4946 "@ xaxis label \"1/tcp (1/ms)\"\n", 4947 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4948 "@ xaxis ticklabel format decimal\n", 4949 "@ yaxis ticklabel format decimal\n", 4950 "@ xaxis ticklabel char size 0.8\n", 4951 "@ yaxis ticklabel char size 0.8\n", 4952 "@ world xmin 0.0\n", 4953 "data\n", 4954 "0.133333 16.045541 0.310925 11.743296 \n", 4955 "0.266667 14.877925 0.303217 11.743296 \n", 4956 "0.400000 14.357820 0.299894 11.743296 \n", 4957 "0.533333 12.664495 0.289532 11.743296 \n", 4958 "0.666667 12.363205 0.287760 11.743296 \n", 4959 "0.800000 11.092532 0.280514 11.743296 \n", 4960 "0.933333 10.566090 0.277619 11.743296 \n", 4961 "1.066667 9.805807 0.273544 11.743296 \n", 4962 "1.200000 9.564301 0.272276 11.743296 \n", 4963 "1.333333 9.015634 0.269442 11.743296 \n", 4964 "1.466667 8.607765 0.267375 11.743296 \n", 4965 "1.600000 8.279997 0.265740 11.743296 \n", 4966 "1.733333 8.474536 0.266708 11.743296 \n", 4967 "1.866667 8.158973 0.265141 11.743296 \n", 4968 "2.000000 7.988631 0.264304 11.743296 \n", 4969 "0.133333 22.224914 0.166231 18.789274 \n", 4970 "0.266667 21.230874 0.162377 18.789274 \n", 4971 "0.400000 20.603704 0.160017 18.789274 \n", 4972 "0.533333 20.327797 0.158996 18.789274 \n", 4973 "0.666667 18.855377 0.153719 18.789274 \n", 4974 "0.800000 18.537531 0.152617 18.789274 \n", 4975 "0.933333 17.508069 0.149138 18.789274 \n", 4976 "1.066667 16.035604 0.144391 18.789274 \n", 4977 "1.200000 15.168192 0.141717 18.789274 \n", 4978 "1.333333 14.431802 0.139516 18.789274 \n", 4979 "1.466667 14.034137 0.138354 18.789274 \n", 4980 "1.600000 12.920148 0.135192 18.789274 \n", 4981 "1.733333 12.653673 0.134456 18.789274 \n", 4982 "1.866667 12.610864 0.134338 18.789274 \n", 4983 "2.000000 11.969303 0.132601 18.789274 \n" 4984 ] 4985 spin2 = [ 4986 "title :71@N\n", 4987 "fields 2 11.7432964915 18.7892743865\n", 4988 "function CPMG\n", 4989 "R2 1 10 20\n", 4990 "Rex 0 100.0 100\n", 4991 "Tau 0 10.0 100\n", 4992 "xmgr\n", 4993 "@ xaxis label \"1/tcp (1/ms)\"\n", 4994 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4995 "@ xaxis ticklabel format decimal\n", 4996 "@ yaxis ticklabel format decimal\n", 4997 "@ xaxis ticklabel char size 0.8\n", 4998 "@ yaxis ticklabel char size 0.8\n", 4999 "@ world xmin 0.0\n", 5000 "data\n", 5001 "0.133333 7.044342 0.170035 11.743296 \n", 5002 "0.266667 6.781033 0.169228 11.743296 \n", 5003 "0.400000 6.467623 0.168279 11.743296 \n", 5004 "0.533333 6.333340 0.167876 11.743296 \n", 5005 "0.666667 6.323238 0.167846 11.743296 \n", 5006 "0.800000 6.005245 0.166902 11.743296 \n", 5007 "0.933333 5.767052 0.166203 11.743296 \n", 5008 "1.066667 5.476968 0.165361 11.743296 \n", 5009 "1.200000 5.469949 0.165341 11.743296 \n", 5010 "1.333333 5.295113 0.164838 11.743296 \n", 5011 "1.466667 5.435648 0.165242 11.743296 \n", 5012 "1.600000 5.410400 0.165169 11.743296 \n", 5013 "1.733333 5.437554 0.165247 11.743296 \n", 5014 "1.866667 5.176844 0.164501 11.743296 \n", 5015 "2.000000 5.227232 0.164644 11.743296 \n", 5016 "0.133333 11.530903 0.081928 18.789274 \n", 5017 "0.266667 10.983094 0.081041 18.789274 \n", 5018 "0.400000 10.512403 0.080294 18.789274 \n", 5019 "0.533333 9.984805 0.079473 18.789274 \n", 5020 "0.666667 9.573163 0.078845 18.789274 \n", 5021 "0.800000 9.178810 0.078253 18.789274 \n", 5022 "0.933333 8.935719 0.077893 18.789274 \n", 5023 "1.066667 8.610147 0.077416 18.789274 \n", 5024 "1.200000 8.353778 0.077045 18.789274 \n", 5025 "1.333333 8.173729 0.076787 18.789274 \n", 5026 "1.466667 8.091607 0.076670 18.789274 \n", 5027 "1.600000 7.706420 0.076126 18.789274 \n", 5028 "1.733333 7.709125 0.076129 18.789274 \n", 5029 "1.866667 7.610856 0.075992 18.789274 \n", 5030 "2.000000 7.552584 0.075911 18.789274 \n", 5031 ] 5032 5033 # Check the batch file. 5034 print("\nChecking the batch file.") 5035 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 5036 lines = file.readlines() 5037 file.close() 5038 for i in range(len(lines)): 5039 self.assertEqual(batch_file[i], lines[i]) 5040 5041 # Check spin :70@N. 5042 print("\nChecking the spin :70@N input file.") 5043 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 5044 lines = file.readlines() 5045 file.close() 5046 for i in range(len(spin1)): 5047 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5048 for i in range(len(lines)): 5049 self.assertEqual(spin1[i], lines[i]) 5050 5051 # Check spin :71@N. 5052 print("\nChecking the spin :71@N input file.") 5053 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 5054 lines = file.readlines() 5055 file.close() 5056 for i in range(len(lines)): 5057 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5058 for i in range(len(spin2)): 5059 self.assertEqual(spin2[i], lines[i])
5060 5061
5063 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 5064 5065 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. 5066 5067 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 5068 5069 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 5070 - pA = 0.965402506690231, 5071 - dw = 0.805197170133360, 5072 - dwH = -0.595536627771890, 5073 - kex = 569.003663067619868, 5074 - chi2 = 9.297671357952812. 5075 """ 5076 5077 # Base data setup. 5078 self.setup_korzhnev_2005_data(data_list=['DQ']) 5079 5080 # Alias the spin. 5081 spin = return_spin(":9@N") 5082 5083 # The R20 keys. 5084 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5085 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5086 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5087 5088 # Set the initial parameter values. 5089 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 5090 spin.pA = 0.965638501551899 5091 spin.dw = 2.8537583461577 5092 spin.dwH = -0.387633062766635 5093 spin.kex = 573.704033851592 5094 5095 # Low precision optimisation. 5096 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5097 5098 # Monte Carlo simulations. 5099 self.interpreter.monte_carlo.setup(number=3) 5100 self.interpreter.monte_carlo.create_data(method='back_calc') 5101 self.interpreter.monte_carlo.initial_values() 5102 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5103 self.interpreter.monte_carlo.error_analysis() 5104 5105 # Plot the dispersion curves. 5106 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5107 5108 # Save the results. 5109 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5110 5111 # Printout. 5112 print("\n\nOptimised parameters:\n") 5113 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5114 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5115 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5116 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5117 print("%-20s %20.15g" % ("pA", spin.pA)) 5118 print("%-20s %20.15g" % ("dw", spin.dw)) 5119 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5120 print("%-20s %20.15g" % ("kex", spin.kex)) 5121 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5122 5123 # Checks for residue :9. 5124 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 5125 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 5126 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 5127 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 5128 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 5129 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 5130 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 5131 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5132 5133
5135 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 5136 5137 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. 5138 5139 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 5140 5141 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 5142 - pA = 0.930027999814003, 5143 - dw = 4.338620619954370, 5144 - dwH = -0.274250775560818, 5145 - kex = 344.613362916544475, 5146 - chi2 = 10.367733168217050. 5147 """ 5148 5149 # Base data setup. 5150 self.setup_korzhnev_2005_data(data_list=['MQ']) 5151 5152 # Alias the spin. 5153 spin = return_spin(":9@N") 5154 5155 # The R20 keys. 5156 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5157 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5158 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5159 5160 # Set the initial parameter values. 5161 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 5162 spin.pA = 0.930083249288083 5163 spin.dw = 4.33890689462363 5164 spin.dwH = -0.274316585638047 5165 spin.kex = 344.329651956132 5166 5167 # Low precision optimisation. 5168 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5169 5170 # Monte Carlo simulations. 5171 self.interpreter.monte_carlo.setup(number=3) 5172 self.interpreter.monte_carlo.create_data(method='back_calc') 5173 self.interpreter.monte_carlo.initial_values() 5174 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5175 self.interpreter.monte_carlo.error_analysis() 5176 5177 # Plot the dispersion curves. 5178 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5179 5180 # Save the results. 5181 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5182 5183 # Printout. 5184 print("\n\nOptimised parameters:\n") 5185 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5186 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5187 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5188 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5189 print("%-20s %20.15g" % ("pA", spin.pA)) 5190 print("%-20s %20.15g" % ("dw", spin.dw)) 5191 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5192 print("%-20s %20.15g" % ("kex", spin.kex)) 5193 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5194 5195 # Checks for residue :9. 5196 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 5197 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 5198 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 5199 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 5200 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 5201 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 5202 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 5203 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5204 5205
5207 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 5208 5209 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. 5210 5211 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 5212 5213 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 5214 - pA = 0.950003458294991, 5215 - dw = 4.358402855315123, 5216 - kex = 429.906473361926999, 5217 - chi2 = 17.393331915567252. 5218 """ 5219 5220 # Base data setup. 5221 self.setup_korzhnev_2005_data(data_list=['SQ']) 5222 5223 # Alias the spin. 5224 spin = return_spin(":9@N") 5225 5226 # The R20 keys. 5227 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5228 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5229 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5230 5231 # Set the initial parameter values. 5232 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 5233 spin.pA = 0.950310172115387 5234 spin.dw = 4.356737157889636 5235 spin.kex = 433.176323890829849 5236 5237 # Low precision optimisation. 5238 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5239 5240 # Monte Carlo simulations. 5241 self.interpreter.monte_carlo.setup(number=3) 5242 self.interpreter.monte_carlo.create_data(method='back_calc') 5243 self.interpreter.monte_carlo.initial_values() 5244 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5245 self.interpreter.monte_carlo.error_analysis() 5246 5247 # Plot the dispersion curves. 5248 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5249 5250 # Save the results. 5251 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5252 5253 # Printout. 5254 print("\n\nOptimised parameters:\n") 5255 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5256 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5257 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5258 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5259 print("%-20s %20.15g" % ("pA", spin.pA)) 5260 print("%-20s %20.15g" % ("dw", spin.dw)) 5261 print("%-20s %20.15g" % ("kex", spin.kex)) 5262 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5263 5264 # Checks for residue :9. 5265 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5266 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5267 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5268 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5269 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5270 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5271 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5272 5273
5275 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5276 5277 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. 5278 5279 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5280 5281 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5282 - pA = 0.942452612380140, 5283 - dw = 0.858972784230892, 5284 - dwH = 0.087155962730608, 5285 - kex = 373.219151384798920, 5286 - chi2 = 23.863208106025152. 5287 """ 5288 5289 # Base data setup. 5290 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5291 5292 # Alias the spin. 5293 spin = return_spin(":9@N") 5294 5295 # The R20 keys. 5296 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5297 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5298 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5299 5300 # Set the initial parameter values. 5301 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5302 spin.pA = 0.942457332074014 5303 spin.dw = 0.850592422908884 5304 spin.dwH = 0.0881272284455416 5305 spin.kex = 372.745483351305 5306 5307 # Low precision optimisation. 5308 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5309 5310 # Monte Carlo simulations. 5311 self.interpreter.monte_carlo.setup(number=3) 5312 self.interpreter.monte_carlo.create_data(method='back_calc') 5313 self.interpreter.monte_carlo.initial_values() 5314 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5315 self.interpreter.monte_carlo.error_analysis() 5316 5317 # Plot the dispersion curves. 5318 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5319 5320 # Save the results. 5321 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5322 5323 # Printout. 5324 print("\n\nOptimised parameters:\n") 5325 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5326 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5327 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5328 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5329 print("%-20s %20.15g" % ("pA", spin.pA)) 5330 print("%-20s %20.15g" % ("dw", spin.dw)) 5331 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5332 print("%-20s %20.15g" % ("kex", spin.kex)) 5333 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5334 5335 # Checks for residue :9. 5336 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5337 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5338 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5339 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5340 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5341 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5342 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5343 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5344 5345
5347 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5348 5349 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. 5350 5351 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5352 5353 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5354 - pA = 0.936911090448340, 5355 - dw = 4.325314846914845, 5356 - dwH = -0.213870168665628, 5357 - kex = 487.361914835074117, 5358 - chi2 = 14.870371897291138. 5359 """ 5360 5361 # Base data setup. 5362 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5363 5364 # Alias the spin. 5365 spin = return_spin(":9@N") 5366 5367 # The R20 keys. 5368 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5369 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5370 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5371 5372 # Set the initial parameter values. 5373 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5374 spin.pA = 0.936884348941701 5375 spin.dw = 4.326454531583964 5376 spin.dwH = -0.214026093221782 5377 spin.kex = 487.043592705469223 5378 5379 # Low precision optimisation. 5380 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5381 5382 # Monte Carlo simulations. 5383 self.interpreter.monte_carlo.setup(number=3) 5384 self.interpreter.monte_carlo.create_data(method='back_calc') 5385 self.interpreter.monte_carlo.initial_values() 5386 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5387 self.interpreter.monte_carlo.error_analysis() 5388 5389 # Plot the dispersion curves. 5390 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5391 5392 # Save the results. 5393 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5394 5395 # Printout. 5396 print("\n\nOptimised parameters:\n") 5397 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5398 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5399 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5400 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5401 print("%-20s %20.15g" % ("pA", spin.pA)) 5402 print("%-20s %20.15g" % ("dw", spin.dw)) 5403 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5404 print("%-20s %20.15g" % ("kex", spin.kex)) 5405 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5406 5407 # Checks for residue :9. 5408 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5409 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5410 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5411 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5412 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5413 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5414 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5415 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5416 5417
5419 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5420 5421 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. 5422 5423 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5424 5425 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5426 - pA = 0.946949480545876, 5427 - dwH = -0.265279672133308, 5428 - kex = 406.548178869750700, 5429 - chi2 = 50.400680290545026. 5430 """ 5431 5432 # Base data setup. 5433 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5434 5435 # Alias the spin. 5436 spin = return_spin(":9@N") 5437 5438 # The R20 keys. 5439 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5440 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5441 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5442 5443 # Set the initial parameter values. 5444 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5445 spin.pA = 0.946990967372467 5446 spin.dwH = -0.265308128403529 5447 spin.kex = 406.843250675648 5448 5449 # Low precision optimisation. 5450 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5451 5452 # Monte Carlo simulations. 5453 self.interpreter.monte_carlo.setup(number=3) 5454 self.interpreter.monte_carlo.create_data(method='back_calc') 5455 self.interpreter.monte_carlo.initial_values() 5456 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5457 self.interpreter.monte_carlo.error_analysis() 5458 5459 # Plot the dispersion curves. 5460 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5461 5462 # Save the results. 5463 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5464 5465 # Printout. 5466 print("\n\nOptimised parameters:\n") 5467 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5468 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5469 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5470 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5471 print("%-20s %20.15g" % ("pA", spin.pA)) 5472 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5473 print("%-20s %20.15g" % ("kex", spin.kex)) 5474 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5475 5476 # Checks for residue :9. 5477 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5478 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5479 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5480 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5481 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5482 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5483 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5484 5485
5487 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5488 5489 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. 5490 5491 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5492 5493 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5494 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5495 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5496 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5497 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5498 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5499 - pA = 0.943125351763911, 5500 - dw = 4.421827493809807, 5501 - dwH = -0.272637034755752, 5502 - kex = 360.609744568697238, 5503 - chi2 = 162.589570340050813. 5504 """ 5505 5506 # Base data setup. 5507 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5508 5509 # Alias the spin. 5510 spin = return_spin(":9@N") 5511 5512 # The R20 keys. 5513 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5514 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5515 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5516 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5517 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5518 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5519 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5520 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5521 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5522 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5523 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5524 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5525 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5526 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5527 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5528 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5529 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5530 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5531 5532 # Set the initial parameter values. 5533 spin.r2 = { 5534 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5535 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5536 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5537 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5538 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5539 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5540 } 5541 spin.pA = 0.943129019477673 5542 spin.dw = 4.42209952545181 5543 spin.dwH = -0.27258970590969 5544 spin.kex = 360.516132791038 5545 5546 # Low precision optimisation. 5547 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5548 5549 # Monte Carlo simulations. 5550 self.interpreter.monte_carlo.setup(number=3) 5551 self.interpreter.monte_carlo.create_data(method='back_calc') 5552 self.interpreter.monte_carlo.initial_values() 5553 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5554 self.interpreter.monte_carlo.error_analysis() 5555 5556 # Plot the dispersion curves. 5557 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5558 5559 # Save the results. 5560 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5561 5562 # Printout. 5563 print("\n\nOptimised parameters:\n") 5564 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5565 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5566 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5567 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5568 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5569 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5570 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5571 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5572 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5573 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5574 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5575 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5576 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5577 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5578 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5579 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5580 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5581 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5582 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5583 print("%-20s %20.15g" % ("pA", spin.pA)) 5584 print("%-20s %20.15g" % ("dw", spin.dw)) 5585 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5586 print("%-20s %20.15g" % ("kex", spin.kex)) 5587 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5588 5589 # Checks for residue :9. 5590 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5591 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5592 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5593 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5594 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5595 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5596 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5597 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5598 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5599 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5600 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5601 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5602 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5603 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5604 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5605 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5606 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5607 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5608 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5609 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5610 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5611 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5612 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5613 5614
5616 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5617 5618 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. 5619 5620 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5621 5622 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5623 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5624 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5625 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5626 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5627 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5628 - pA = 0.943125351763911, 5629 - dw = 4.421827493809807, 5630 - dwH = -0.272637034755752, 5631 - kex = 360.609744568697238, 5632 - chi2 = 162.589570340050813. 5633 """ 5634 5635 # Base data setup. 5636 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5637 5638 # Alias the spin. 5639 spin = return_spin(":9@N") 5640 5641 # The R20 keys. 5642 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5643 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5644 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5645 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5646 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5647 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5648 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5649 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5650 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5651 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5652 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5653 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5654 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5655 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5656 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5657 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5658 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5659 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5660 5661 # Set the initial parameter values. 5662 spin.r2 = { 5663 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5664 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5665 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5666 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5667 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5668 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5669 } 5670 spin.pA = 0.943129019477673 5671 spin.dw = 4.42209952545181 5672 spin.dwH = -0.27258970590969 5673 spin.kex = 360.516132791038 5674 5675 # Calc the chi2 values at these parameters. 5676 self.interpreter.minimise.calculate(verbosity=1) 5677 5678 # Printout. 5679 print("\n\nOptimised parameters:\n") 5680 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5681 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5682 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5683 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5684 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5685 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5686 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5687 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5688 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5689 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5690 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5691 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5692 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5693 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5694 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5695 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5696 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5697 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5698 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5699 print("%-20s %20.15g" % ("pA", spin.pA)) 5700 print("%-20s %20.15g" % ("dw", spin.dw)) 5701 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5702 print("%-20s %20.15g" % ("kex", spin.kex)) 5703 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5704 5705 # Checks for residue :9. 5706 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5707 5708
5710 """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. 5711 5712 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). 5713 5714 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5715 5716 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5717 - 0.483 0.89623903 2.4503699912708878 5718 - 0.545 1.1694838 5719 - 0.545 1.1761503 5720 - 0.622 1.294 5721 - 0.669 1.5176493 5722 - 0.722 1.6238791 5723 - 0.813 1.9395758 5724 - 1.011 2.3558415 10.547000429321157 5725 """ 5726 5727 # Base data setup. 5728 model = 'TSMFK01' 5729 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5730 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5731 5732 # Alias the spins. 5733 res61L = cdp.mol[0].res[0].spin[0] 5734 5735 # The R20 keys. 5736 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5737 5738 # Set the initial parameter values. 5739 res61L.r2a = {r20_key1: 8.0} 5740 res61L.dw = 6.5 5741 res61L.k_AB = 2.5 5742 5743 # Low precision optimisation. 5744 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) 5745 5746 # Start testing all possible combinations of graphs. 5747 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5748 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5749 interpolate_types = [INTERPOLATE_DISP] 5750 5751 # Write to temp folder. 5752 result_dir_name = ds.tmpdir 5753 result_folders = [model] 5754 spin_id = ":61@N" 5755 5756 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5757 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5758 5759 for result_folder in result_folders: 5760 for y_axis in y_axis_types: 5761 for x_axis in x_axis_types: 5762 for interpolate in interpolate_types: 5763 # Determine file name: 5764 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5765 5766 # Make the file name. 5767 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5768 5769 # Write the curves. 5770 dir = result_dir_name+sep+result_folder 5771 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5772 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5773 5774 # Get the file path. 5775 file_path = get_file_path(file_name, dir) 5776 5777 # Test the plot file exists. 5778 print("Testing file access to graph: %s"%file_path) 5779 self.assert_(access(file_path, F_OK)) 5780 5781 # Now open, and compare content, line by line. 5782 file_prod = open(file_path) 5783 lines_prod = file_prod.readlines() 5784 file_prod.close() 5785 5786 # Define file to compare against. 5787 dir_comp = data_path+sep+result_folder 5788 file_path_comp = get_file_path(file_name, dir_comp) 5789 file_comp = open(file_path_comp) 5790 lines_comp = file_comp.readlines() 5791 file_comp.close() 5792 5793 ## Assert number of lines is equal. 5794 self.assertEqual(len(lines_prod), len(lines_comp)) 5795 for j in range(len(lines_prod)): 5796 # Make the string test 5797 first_char = lines_prod[j][0] 5798 if first_char in ["@", "&"]: 5799 self.assertEqual(lines_prod[j], lines_comp[j]) 5800 else: 5801 # Split string in x, y, error. 5802 # The error would change per run. 5803 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5804 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5805 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5806 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5807 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5808 5809
5811 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5812 5813 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). 5814 """ 5815 5816 # Base data setup. 5817 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5818 5819 # Alias the spins. 5820 res61L = cdp.mol[0].res[0].spin[0] 5821 5822 # The R20 keys. 5823 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5824 5825 # Set the initial parameter values. 5826 res61L.r2 = {r20_key1: 8.0} 5827 res61L.pA = 0.9 5828 res61L.dw = 6.0 5829 res61L.kex = 600.0 5830 5831 # Low precision optimisation. 5832 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) 5833 5834 # Printout. 5835 print("\n\nOptimised parameters:\n") 5836 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5837 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5838 print("%-20s %20.15g" % ("pA", res61L.pA)) 5839 print("%-20s %20.15g" % ("dw", res61L.dw)) 5840 print("%-20s %20.15g" % ("kex", res61L.kex)) 5841 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5842 5843 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5844 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5845 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5846 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5847 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5848 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5849 5850 # Test the conversion to k_AB from kex and pA. 5851 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5852 5853 # Test the conversion to k_BA from kex and pA. 5854 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5855 5856
5858 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5859 5860 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). 5861 """ 5862 5863 # Base data setup. 5864 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5865 5866 # Alias the spins. 5867 res61L = cdp.mol[0].res[0].spin[0] 5868 5869 # The R20 keys. 5870 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5871 5872 # Set the initial parameter values. 5873 res61L.r2a = {r20_key1: 8.0} 5874 res61L.r2b = {r20_key1: 105.0} 5875 res61L.pA = 0.9 5876 res61L.dw = 6.0 5877 res61L.kex = 500.0 5878 5879 # Low precision optimisation. 5880 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) 5881 5882 # Printout. 5883 print("\n\nOptimised parameters:\n") 5884 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5885 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5886 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5887 print("%-20s %20.15g" % ("pA", res61L.pA)) 5888 print("%-20s %20.15g" % ("dw", res61L.dw)) 5889 print("%-20s %20.15g" % ("kex", res61L.kex)) 5890 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5891 5892 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5893 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5894 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5895 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5896 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5897 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5898 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5899 5900
5902 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5903 5904 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). 5905 5906 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5907 5908 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5909 - 0.483 0.89623903 2.4503699912708878 5910 - 0.545 1.1694838 5911 - 0.545 1.1761503 5912 - 0.622 1.294 5913 - 0.669 1.5176493 5914 - 0.722 1.6238791 5915 - 0.813 1.9395758 5916 - 1.011 2.3558415 10.547000429321157 5917 """ 5918 5919 # Base data setup. 5920 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5921 5922 # Alias the spins. 5923 res61L = cdp.mol[0].res[0].spin[0] 5924 5925 # The R20 keys. 5926 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5927 5928 # Set the initial parameter values. 5929 res61L.r2a = {r20_key1: 8.0} 5930 res61L.dw = 6.5 5931 res61L.k_AB = 2.5 5932 5933 # Low precision optimisation. 5934 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) 5935 5936 # Printout. 5937 print("\n\nOptimised parameters:\n") 5938 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5939 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5940 print("%-20s %20.15g" % ("dw", res61L.dw)) 5941 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5942 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5943 5944 # Checks for residue :61. Reference values from paper 5945 5946 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5947 5948
5950 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5951 5952 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). 5953 5954 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. 5955 5956 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: 5957 5958 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5959 - k_AB = 11.3 +/- 0.7 s^-1, 5960 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5961 - R2 = 8.0 +/- 0.5 s^-1. 5962 5963 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5964 - k_AB = 10.55 +/- 0.08 s^-1, 5965 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5966 - R2 = 8.4 +/- 0.3 s^-1. 5967 5968 Conversion of paper results to relax results is performed by: 5969 5970 - 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. 5971 5972 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5973 5974 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5975 - 0.483 0.89623903 2.4503699912708878 5976 - 0.545 1.1694838 5977 - 0.545 1.1761503 5978 - 0.622 1.294 5979 - 0.669 1.5176493 5980 - 0.722 1.6238791 5981 - 0.813 1.9395758 5982 - 1.011 2.3558415 10.547000429321157 5983 """ 5984 5985 # Base data setup. 5986 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 5987 5988 # Alias the spins. 5989 res61L = cdp.mol[0].res[0].spin[0] 5990 5991 # The R20 keys. 5992 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 5993 5994 # Set the initial parameter values. 5995 res61L.r2a = {r20_key1: 8.0} 5996 res61L.dw = 6.5 5997 res61L.k_AB = 11.0 5998 5999 # Low precision optimisation. 6000 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) 6001 6002 # Printout. 6003 print("\n\nOptimised parameters:\n") 6004 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 6005 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 6006 print("%-20s %20.15g" % ("dw", res61L.dw)) 6007 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 6008 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 6009 6010 # Checks for residue :61. Reference values from paper 6011 6012 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 6013 self.assertAlmostEqual(res61L.dw, 6.41, 0) 6014 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
6015 6016
6017 - def test_lm63_3site_synthetic(self):
6018 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 6019 6020 # The path to the data files. 6021 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 6022 6023 # Load the state file. 6024 self.interpreter.reset() 6025 self.interpreter.state.load(data_path+sep+'r2eff_values') 6026 6027 # A new data pipe. 6028 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 6029 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 6030 6031 # Set up the model data. 6032 self.interpreter.relax_disp.select_model(model='LM63 3-site') 6033 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 6034 self.interpreter.spin.isotope('15N') 6035 6036 # Alias the spins. 6037 spin1 = return_spin(":1") 6038 spin2 = return_spin(":2") 6039 6040 # The R20 keys. 6041 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 6042 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 6043 6044 # Manually set the parameter values. 6045 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 6046 spin1.phi_ex_B = 0.1 6047 spin1.phi_ex_C = 0.5 6048 spin1.kB = 1500.0 6049 spin1.kC = 2500.0 6050 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 6051 spin2.phi_ex_B = 0.1 6052 spin2.phi_ex_C = 0.5 6053 spin2.kB = 1500.0 6054 spin2.kC = 2500.0 6055 6056 # Low precision optimisation. 6057 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) 6058 6059 # Monte Carlo simulations. 6060 self.interpreter.monte_carlo.setup(number=3) 6061 self.interpreter.monte_carlo.create_data(method='back_calc') 6062 self.interpreter.monte_carlo.initial_values() 6063 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) 6064 self.interpreter.monte_carlo.error_analysis() 6065 6066 # Save the results. 6067 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 6068 6069 # The model checks. 6070 print("\n\nOptimised parameters:\n") 6071 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 6072 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 6073 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 6074 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 6075 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 6076 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 6077 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 6078 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 6079 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 6080 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 6081 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6082 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6083 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6084 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6085 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 6086 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 6087 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 6088 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6089 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6090 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6091 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6092 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
6093 6094
6095 - def test_m61_data_to_m61(self):
6096 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 6097 6098 # Fixed time variable. 6099 ds.fixed = True 6100 6101 # Execute the script. 6102 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') 6103 6104 # The original parameters. 6105 i0 = [100000.0, 20000.0] 6106 r1rho_prime = [2.25, 24.0] 6107 pA = 0.7 6108 kex = 1000.0 6109 delta_omega = [1.0, 2.0] 6110 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'] 6111 phi_ex = [] 6112 for i in range(2): 6113 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6114 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]] 6115 6116 # Switch to the 'R2eff' model data pipe, then check for each spin. 6117 self.interpreter.pipe.switch('R2eff - relax_disp') 6118 spin_index = 0 6119 for spin, spin_id in spin_loop(return_id=True): 6120 # Printout. 6121 print("\nSpin %s." % spin_id) 6122 6123 # Check the fitted parameters. 6124 for i in range(len(keys)): 6125 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6126 6127 # Increment the spin index. 6128 spin_index += 1 6129 6130 # The R20 keys. 6131 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6132 6133 # Switch to the 'M61' model data pipe, then check for each spin. 6134 self.interpreter.pipe.switch('M61 - relax_disp') 6135 spin_index = 0 6136 for spin, spin_id in spin_loop(return_id=True): 6137 # Printout. 6138 print("\nSpin %s." % spin_id) 6139 6140 # Check the fitted parameters. 6141 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6142 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6143 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6144 6145 # Increment the spin index. 6146 spin_index += 1
6147 6148
6149 - def test_m61_exp_data_to_m61(self):
6150 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 6151 6152 # Fixed time variable. 6153 ds.fixed = False 6154 6155 # Single spin optimisation. 6156 ds.single = True 6157 6158 # Execute the script. 6159 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') 6160 6161 # The original parameters. 6162 i0 = [100000.0, 20000.0] 6163 r1rho_prime = [2.25, 24.0] 6164 pA = 0.7 6165 kex = 1000.0 6166 delta_omega = [1.0, 2.0] 6167 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'] 6168 phi_ex = [] 6169 for i in range(2): 6170 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6171 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]] 6172 6173 # Switch to the 'R2eff' model data pipe, then check for each spin. 6174 self.interpreter.pipe.switch('R2eff - relax_disp') 6175 spin_index = 0 6176 for spin, spin_id in spin_loop(return_id=True): 6177 # Printout. 6178 print("\nSpin %s." % spin_id) 6179 6180 # Check the fitted parameters. 6181 for i in range(len(keys)): 6182 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6183 6184 # Increment the spin index. 6185 spin_index += 1 6186 6187 # The R20 keys. 6188 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6189 6190 # Switch to the 'M61' model data pipe, then check for each spin. 6191 self.interpreter.pipe.switch('M61 - relax_disp') 6192 spin_index = 0 6193 for spin, spin_id in spin_loop(return_id=True): 6194 # Printout. 6195 print("\nSpin %s." % spin_id) 6196 6197 # Check the fitted parameters. 6198 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6199 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6200 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6201 6202 # Increment the spin index. 6203 spin_index += 1
6204 6205
6206 - def test_m61b_data_to_m61b(self):
6207 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 6208 6209 # Execute the script. 6210 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') 6211 6212 # The original parameters. 6213 i0 = [100000.0, 20000.0] 6214 r1rho_prime = [10.0, 24.0] 6215 pA = 0.95 6216 kex = 2000.0 6217 delta_omega = [1.0, 2.0] 6218 6219 # The R20 keys. 6220 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6221 6222 # Switch to the 'M61 skew' model data pipe, then check for each spin. 6223 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 6224 spin_index = 0 6225 for spin, spin_id in spin_loop(return_id=True): 6226 # Printout. 6227 print("\nSpin %s." % spin_id) 6228 6229 # Check the fitted parameters. 6230 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6231 self.assertAlmostEqual(spin.pA, pA, 2) 6232 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 6233 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6234 6235 # Increment the spin index. 6236 spin_index += 1
6237 6238
6240 """Test that all models which can nest, have all their parameters converted.""" 6241 6242 # Set the experiment type. 6243 cdp.exp_type_list = EXP_TYPE_LIST 6244 6245 # Get info for all models. 6246 all_models_info = models_info(models=MODEL_LIST_FULL) 6247 6248 # Loop over all models. 6249 print("Printing the listed of nested models for each model.") 6250 print("#########################################") 6251 for model_info in all_models_info: 6252 print("%s"%model_info.model), 6253 print("<-"), 6254 nest_list = model_info.nest_list 6255 if nest_list == None: 6256 nest_list = ["None"] 6257 print(', '.join(map(str, nest_list))) 6258 6259 # Skip if there is no model to nest from. 6260 if nest_list == ["None"]: 6261 continue 6262 6263 # Assign params to variable. 6264 model_params = model_info.params 6265 6266 # Now loop over the nested models. 6267 for nested_model in nest_list: 6268 # Get the params for the nested model. 6269 nested_model_params = MODEL_PARAMS[nested_model] 6270 6271 # Get the dictionary of parameter conversion. 6272 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6273 6274 # Test the number of elements in the dictionary. 6275 self.assertEqual(len(par_dic), len(model_params)) 6276 6277 # Loop over dictionary. 6278 for param in par_dic: 6279 if param != par_dic[param]: 6280 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param)) 6281 self.assertNotEqual(par_dic[param], None)
6282 6283
6284 - def test_ns_mmq_3site(self):
6285 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6286 6287 # Execute the script. 6288 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6289 6290 # Check the chi-squared value. 6291 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6292 6293
6294 - def test_ns_mmq_3site_linear(self):
6295 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6296 6297 # Execute the script. 6298 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') 6299 6300 # Check the chi-squared value. 6301 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6302 6303
6304 - def test_ns_r1rho_3site(self):
6305 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6306 6307 # Execute the script. 6308 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6309 6310 # Check the chi-squared value. 6311 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6312 6313
6314 - def test_ns_r1rho_3site_linear(self):
6315 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6316 6317 # Execute the script. 6318 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') 6319 6320 # Check the chi-squared value. 6321 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6322 6323
6324 - def test_repeat_cpmg(self):
6325 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6326 6327 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. 6328 """ 6329 6330 # Reset. 6331 self.interpreter.reset() 6332 6333 # Define base path to files. 6334 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6335 6336 # Setup dictionary with settings. 6337 sdic = {} 6338 6339 # Spectrometer frqs in list. 6340 sfrq_1 = 499.86214 6341 sfrq_2 = 599.8908587 6342 sfrqs = [sfrq_1, sfrq_2] 6343 6344 # Store in dictionary. 6345 sdic['sfrqs'] = sfrqs 6346 6347 # Store unit for frq. 6348 sdic['sfrq_unit'] = 'MHz' 6349 6350 # Store exp_type 6351 sdic['exp_type'] = 'SQ CPMG' 6352 6353 # Store spin isotope 6354 sdic['isotope'] = '15N' 6355 6356 # How intensity was measured. 6357 sdic['int_method'] = 'height' 6358 6359 # Define the time for result directory. 6360 sdic['time'] = '2014_09' 6361 6362 # Initialize frq dics. 6363 for frq in sfrqs: 6364 key = DIC_KEY_FORMAT % (frq) 6365 sdic[key] = {} 6366 6367 # Set keys. 6368 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6369 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6370 6371 # Store time T2. 6372 sdic[e_1]['time_T2'] = 0.04 6373 sdic[e_2]['time_T2'] = 0.06 6374 6375 # Set ncyc. 6376 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6377 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6378 6379 # Calculate the cpmg_frq and store. 6380 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6381 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6382 6383 # Define peak lists. 6384 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6385 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6386 sdic[e_1]['peaks_folder'] = peaks_folder_1 6387 sdic[e_2]['peaks_folder'] = peaks_folder_2 6388 6389 # Define folder to all rmsd files. 6390 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6391 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6392 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6393 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6394 6395 # Define temporary folder. 6396 sdic['results_dir'] = self.tmpdir 6397 6398 # Setup class with data. 6399 RDR = Relax_disp_rep(sdic) 6400 6401 # Setup base information. 6402 RDR.set_base_cpmg(method='FT', glob_ini=128) 6403 6404 methods = ['FT', 'MDD'] 6405 #methods = ['FT'] 6406 6407 # Set the intensity. 6408 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6409 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6410 6411 # Try plot some intensity correlations. 6412 if True: 6413 selection = None 6414 6415 # Now make a spin selection. 6416 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6417 6418 # For mdd 6419 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6420 6421 # Plot correlation of intensity 6422 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6423 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6424 corr_data = [fig1, fig2] 6425 6426 write_stats = True 6427 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6428 6429 # Open stat file. 6430 if write_stats: 6431 for i, corr_data_i in enumerate(corr_data): 6432 data, methods, glob_inis = corr_data[i] 6433 data_x, data_y = data 6434 method_x, method_y = methods 6435 glob_ini_x, glob_ini_y = glob_inis 6436 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6437 np = len(x) 6438 6439 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6440 6441 if selection == None: 6442 file_name = file_name_ini + '_all.txt' 6443 else: 6444 file_name = file_name_ini + '_sel.txt' 6445 path = RDR.results_dir 6446 data = extract_data(file=file_name, dir=path) 6447 6448 # Loop over the lines. 6449 for i, data_i in enumerate(data): 6450 print(i, data_i) 6451 6452 6453 # Try plot some intensity statistics. 6454 if True: 6455 # Collect r2eff values. 6456 selections = [None, ':2,3'] 6457 for selection in selections: 6458 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6459 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6460 6461 # Get R2eff stats. 6462 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6463 6464 ## Plot R2eff stats 6465 write_stats = True 6466 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6467 6468 # Open stat file. 6469 if write_stats: 6470 if selection == None: 6471 file_name = 'int_stat_all.txt' 6472 else: 6473 file_name = 'int_stat_sel.txt' 6474 path = RDR.results_dir 6475 data = extract_data(file=file_name, dir=path) 6476 6477 # Loop over the lines. 6478 for i, data_i in enumerate(data): 6479 print(i, data_i) 6480 6481 6482 # Try write some R2eff correlations. 6483 if True: 6484 selection = None 6485 # Collect r2eff values. 6486 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6487 6488 # For all spins, mdd 6489 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6490 6491 # Plot correlation of intensity 6492 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6493 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6494 corr_data = [fig1, fig2] 6495 6496 write_stats = True 6497 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6498 6499 # Open stat file. 6500 if write_stats: 6501 for i, corr_data_i in enumerate(corr_data): 6502 data, methods, glob_inis = corr_data[i] 6503 data_x, data_y = data 6504 method_x, method_y = methods 6505 glob_ini_x, glob_ini_y = glob_inis 6506 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6507 np = len(x) 6508 6509 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6510 6511 if selection == None: 6512 file_name = file_name_ini + '_all.txt' 6513 else: 6514 file_name = file_name_ini + '_sel.txt' 6515 path = RDR.results_dir 6516 data = extract_data(file=file_name, dir=path) 6517 6518 # Loop over the lines. 6519 for i, data_i in enumerate(data): 6520 print(i, data_i) 6521 6522 6523 # Try plot some R2eff statistics. 6524 if True: 6525 # Collect r2eff values. 6526 selections = [None, ':2,3'] 6527 for selection in selections: 6528 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6529 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6530 6531 # Get R2eff stats. 6532 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6533 6534 ## Plot R2eff stats 6535 write_stats = True 6536 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) 6537 6538 # Open stat file. 6539 if write_stats: 6540 if selection == None: 6541 file_name = 'r2eff_stat_all.txt' 6542 else: 6543 file_name = 'r2eff_stat_sel.txt' 6544 path = RDR.results_dir 6545 data = extract_data(file=file_name, dir=path) 6546 6547 # Loop over the lines. 6548 for i, data_i in enumerate(data): 6549 print(i, data_i) 6550 6551 6552 # Do minimisation individual. 6553 if True: 6554 methods = ['FT', 'MDD'] 6555 # Now calculate R2eff. 6556 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6557 6558 min_methods = [['FT'], ['MDD']] 6559 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6560 6561 #min_methods = [['FT']] 6562 #min_list_glob_ini = [[128]] 6563 #selection = ':2,3' 6564 selection = None 6565 6566 for i, methods in enumerate(min_methods): 6567 list_glob_ini = min_list_glob_ini[i] 6568 6569 if True: 6570 # First get data. 6571 if True: 6572 # First load all data. 6573 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6574 6575 # Then set R20 6576 if True: 6577 # Set R20 from min R2eff in preparation for Grid search. 6578 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) 6579 6580 # Check and print parameters. 6581 if True: 6582 # Print for pipe name 6583 method = methods[0] 6584 glob_ini = list_glob_ini[0] 6585 6586 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6587 RDR.spin_display_params(pipe_name=test_pipe_name) 6588 6589 # Then Grid search. 6590 if True: 6591 # Do Grid search. 6592 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) 6593 6594 # Then Minimise. 6595 if True: 6596 # Minimise 6597 RDR.opt_max_iterations = int(1e2) 6598 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6599 6600 #print asd 6601 6602 # Plot statistics. 6603 # Try plot some minimisation correlations. 6604 if True: 6605 selections = [None, ':2,3'] 6606 for selection in selections: 6607 # Collect param values. 6608 analysis = 'min_ind' 6609 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6610 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6611 6612 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6613 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6614 corr_data = [fig1, fig2] 6615 6616 write_stats = True 6617 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6618 6619 # Open stat file. 6620 if write_stats: 6621 for i, corr_data_i in enumerate(corr_data): 6622 data, methods, glob_inis = corr_data[i] 6623 data_x, data_y = data 6624 method_x, method_y = methods 6625 glob_ini_x, glob_ini_y = glob_inis 6626 6627 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6628 6629 if selection == None: 6630 file_name = file_name_ini + '_all.txt' 6631 else: 6632 file_name = file_name_ini + '_sel.txt' 6633 path = RDR.results_dir 6634 data = extract_data(file=file_name, dir=path) 6635 6636 # Loop over the lines. 6637 for i, data_i in enumerate(data): 6638 print(i, data_i) 6639 6640 # Try plot some minimisation statistics. 6641 if True: 6642 # Collect param values. 6643 #selections = [None, ':2,3'] 6644 selections = [None, ':2,3'] 6645 for selection in selections: 6646 analysis = 'min_ind' 6647 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6648 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6649 6650 # Get param stats. 6651 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6652 6653 ## Plot R2eff stats 6654 write_stats = True 6655 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) 6656 6657 # Open stat file. 6658 if write_stats: 6659 if selection == None: 6660 file_name = '%s_stat_all.txt' % (analysis) 6661 else: 6662 file_name = '%s_stat_sel.txt' % (analysis) 6663 path = RDR.results_dir 6664 data = extract_data(file=file_name, dir=path) 6665 6666 # Loop over the lines. 6667 for i, data_i in enumerate(data): 6668 print(i, data_i) 6669 6670 6671 # Do minimisation clustered. 6672 if True: 6673 methods = ['FT', 'MDD'] 6674 # Now calculate R2eff. 6675 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6676 6677 min_methods = [['FT'], ['MDD']] 6678 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6679 6680 #min_methods = [['FT']] 6681 #min_list_glob_ini = [[128]] 6682 selection = ':2,3' 6683 6684 for i, methods in enumerate(min_methods): 6685 list_glob_ini = min_list_glob_ini[i] 6686 6687 if True: 6688 # First get data. 6689 if True: 6690 # First load all data. 6691 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6692 6693 # Then select spins. 6694 if True: 6695 # Deselect all spins. 6696 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) 6697 6698 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6699 6700 # Then preset values. 6701 if True: 6702 # Set k_AB for Grid search. 6703 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) 6704 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) 6705 6706 # Then set R20 6707 if True: 6708 # Set R20 from min R2eff in preparation for Grid search. 6709 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6710 6711 # Check and print parameters. 6712 if True: 6713 # Print for pipe name 6714 method = methods[0] 6715 glob_ini = list_glob_ini[0] 6716 6717 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6718 RDR.spin_display_params(pipe_name=test_pipe_name) 6719 6720 # Then Grid search. 6721 if True: 6722 # Do Grid search. 6723 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) 6724 6725 # Then cluster spins. 6726 if True: 6727 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6728 6729 # Then Minimise. 6730 if True: 6731 # Minimise 6732 RDR.opt_max_iterations = int(1e2) 6733 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6734 6735 # Plot statistics. 6736 # Try plot some minimisation correlations. 6737 if True: 6738 selection = ':2,3' 6739 # Collect param values. 6740 analysis = 'min' 6741 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6742 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6743 6744 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6745 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6746 corr_data = [fig1, fig2] 6747 6748 write_stats = True 6749 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6750 6751 # Open stat file. 6752 if write_stats: 6753 for i, corr_data_i in enumerate(corr_data): 6754 data, methods, glob_inis = corr_data[i] 6755 data_x, data_y = data 6756 method_x, method_y = methods 6757 glob_ini_x, glob_ini_y = glob_inis 6758 6759 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6760 6761 if selection == None: 6762 file_name = file_name_ini + '_all.txt' 6763 else: 6764 file_name = file_name_ini + '_sel.txt' 6765 path = RDR.results_dir 6766 data = extract_data(file=file_name, dir=path) 6767 6768 # Loop over the lines. 6769 for i, data_i in enumerate(data): 6770 print(i, data_i) 6771 6772 # Try plot some minimisation statistics. 6773 if True: 6774 # Collect param values. 6775 selections = [':2,3'] 6776 for selection in selections: 6777 analysis = 'min' 6778 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6779 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6780 6781 # Get param stats. 6782 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6783 6784 ## Plot R2eff stats 6785 write_stats = True 6786 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) 6787 6788 # Open stat file. 6789 if write_stats: 6790 if selection == None: 6791 file_name = '%s_stat_all.txt' % (analysis) 6792 else: 6793 file_name = '%s_stat_sel.txt' % (analysis) 6794 path = RDR.results_dir 6795 data = extract_data(file=file_name, dir=path) 6796 6797 # Loop over the lines. 6798 for i, data_i in enumerate(data): 6799 print(i, data_i)
6800 6801 6802
6803 - def test_r1rho_kjaergaard_auto(self):
6804 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6805 6806 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6807 6808 This uses the automatic analysis. 6809 6810 """ 6811 6812 # Cluster residues 6813 cluster_ids = [ 6814 ":13@N", 6815 ":15@N", 6816 ":16@N", 6817 ":25@N", 6818 ":26@N", 6819 ":28@N", 6820 ":39@N", 6821 ":40@N", 6822 ":41@N", 6823 ":43@N", 6824 ":44@N", 6825 ":45@N", 6826 ":49@N", 6827 ":52@N", 6828 ":53@N"] 6829 6830 # Load the data. 6831 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6832 6833 # Test some of the sequence. 6834 self.assertEqual(len(cdp.mol), 1) 6835 self.assertEqual(cdp.mol[0].name, None) 6836 self.assertEqual(len(cdp.mol[0].res), 48) 6837 6838 # Test the chemical shift data. 6839 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 6840 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 6841 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 6842 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] 6843 6844 i = 0 6845 for spin, spin_id in spin_loop(return_id=True): 6846 # Check the chemical shift. 6847 self.assertEqual(spin.chemical_shift, cs[i]) 6848 6849 # Increment the index. 6850 i += 1 6851 6852 # Initialize counter 6853 i = 0 6854 j = 0 6855 # Count instances of select/deselect 6856 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6857 if curspin.select == True: 6858 i += 1 6859 if curspin.select == False: 6860 j += 1 6861 6862 # Test number of selected/deselected spins. 6863 self.assertEqual(i, len(cluster_ids)) 6864 self.assertEqual(j, 48-len(cluster_ids)) 6865 6866 # Check the initial setup. 6867 self.assertEqual(cdp.mol[0].res[7].num, 13) 6868 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 6869 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 6870 6871 self.assertEqual(cdp.mol[0].res[9].num, 15) 6872 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 6873 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 6874 6875 self.assertEqual(cdp.mol[0].res[10].num, 16) 6876 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 6877 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 6878 6879 self.assertEqual(cdp.mol[0].res[16].num, 25) 6880 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 6881 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 6882 6883 self.assertEqual(cdp.mol[0].res[17].num, 26) 6884 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 6885 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 6886 6887 self.assertEqual(cdp.mol[0].res[19].num, 28) 6888 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 6889 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 6890 6891 self.assertEqual(cdp.mol[0].res[29].num, 39) 6892 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 6893 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 6894 6895 self.assertEqual(cdp.mol[0].res[30].num, 40) 6896 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 6897 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 6898 6899 self.assertEqual(cdp.mol[0].res[31].num, 41) 6900 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 6901 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 6902 6903 self.assertEqual(cdp.mol[0].res[33].num, 43) 6904 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 6905 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 6906 6907 self.assertEqual(cdp.mol[0].res[34].num, 44) 6908 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 6909 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 6910 6911 self.assertEqual(cdp.mol[0].res[35].num, 45) 6912 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 6913 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 6914 6915 self.assertEqual(cdp.mol[0].res[38].num, 49) 6916 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 6917 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 6918 6919 self.assertEqual(cdp.mol[0].res[41].num, 52) 6920 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 6921 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 6922 6923 self.assertEqual(cdp.mol[0].res[42].num, 53) 6924 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 6925 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 6926 6927 # The dispersion models. 6928 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 6929 6930 # The grid search size (the number of increments per dimension). 6931 GRID_INC = 4 6932 6933 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6934 MC_NUM = 3 6935 6936 # Model selection technique. 6937 MODSEL = 'AIC' 6938 6939 # Execute the auto-analysis (fast). 6940 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6941 OPT_FUNC_TOL = 1e-1 6942 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6943 OPT_MAX_ITERATIONS = 1000 6944 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6945 6946 result_dir_name = ds.tmpdir 6947 6948 # Make all spins free 6949 for curspin in cluster_ids: 6950 self.interpreter.relax_disp.cluster('free spins', curspin) 6951 # Shut them down 6952 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6953 6954 # Select only a subset of spins for global fitting 6955 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6956 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6957 6958 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6959 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6960 6961 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6962 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6963 6964 # Run the analysis. 6965 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) 6966 6967 # Check the kex value of residue 52 6968 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 6969 6970 # Print results for each model. 6971 print("\n\n################") 6972 print("Printing results") 6973 print("################\n") 6974 for model in MODELS: 6975 # Skip R2eff model. 6976 if model == MODEL_R2EFF: 6977 continue 6978 6979 # Switch to pipe. 6980 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 6981 print("\nModel: %s" % (model)) 6982 6983 # Loop over the spins. 6984 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6985 # Generate spin string. 6986 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 6987 6988 # Loop over the parameters. 6989 print("Optimised parameters for spin: %s" % (spin_string)) 6990 for param in cur_spin.params + ['chi2']: 6991 # Get the value. 6992 if param in ['r1', 'r2']: 6993 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 6994 # Generate the R20 key. 6995 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 6996 6997 # Get the value. 6998 value = getattr(cur_spin, param)[r20_key] 6999 7000 # Print value. 7001 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7002 7003 # For all other parameters. 7004 else: 7005 # Get the value. 7006 value = getattr(cur_spin, param) 7007 7008 # Print value. 7009 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7010 7011 # Print the final pipe. 7012 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 7013 print("\nFinal pipe")
7014 7015
7017 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 7018 7019 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7020 7021 This uses the automatic analysis. 7022 7023 """ 7024 7025 # Cluster residues 7026 cluster_ids = [ 7027 ":52@N"] 7028 7029 # Load the data. 7030 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 7031 7032 # The dispersion models. 7033 MODELS = [MODEL_R2EFF] 7034 7035 # The grid search size (the number of increments per dimension). 7036 GRID_INC = 4 7037 7038 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7039 MC_NUM = 3 7040 7041 # Model selection technique. 7042 MODSEL = 'AIC' 7043 7044 # Execute the auto-analysis (fast). 7045 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7046 OPT_FUNC_TOL = 1e-1 7047 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7048 OPT_MAX_ITERATIONS = 1000 7049 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7050 7051 result_dir_name = ds.tmpdir 7052 7053 # Make all spins free 7054 for curspin in cluster_ids: 7055 self.interpreter.relax_disp.cluster('free spins', curspin) 7056 # Shut them down 7057 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7058 7059 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7060 7061 # Run the analysis. 7062 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) 7063 7064 # Check the graphs produced. 7065 graph_comb = [ 7066 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 7067 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 7068 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 7069 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 7070 ] 7071 7072 # Define expected folder names. 7073 result_folders = MODELS 7074 7075 # Assign spin_id. 7076 spin_id = ':52@N' 7077 7078 # Loop over result folders. 7079 for result_folder in result_folders: 7080 # Skip the model R2eff, which does not produce graphs. 7081 if result_folder == MODEL_R2EFF: 7082 continue 7083 7084 # Loop over graphs. 7085 for y_axis, x_axis, interpolate in graph_comb: 7086 # Determine file name: 7087 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7088 7089 # Make the file name. 7090 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7091 7092 # Get the file path. 7093 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 7094 7095 print("Testing file access to graph: %s"%file_path) 7096 self.assert_(access(file_path, F_OK)) 7097 7098 # Start testing all possible combinations of graphs. 7099 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 7100 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 7101 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 7102 7103 result_dir_name = ds.tmpdir 7104 7105 # Loop through all possible combinations of y_axis, x_axis and interpolation. 7106 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 7107 7108 for result_folder in result_folders: 7109 # Skip the model R2eff, which does not produce graphs. 7110 if result_folder == MODEL_R2EFF: 7111 continue 7112 7113 for y_axis in y_axis_types: 7114 for x_axis in x_axis_types: 7115 for interpolate in interpolate_types: 7116 # Determine file name: 7117 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7118 7119 # Make the file name. 7120 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7121 7122 # Write the curves. 7123 dir = result_dir_name+sep+result_folder 7124 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 7125 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 7126 7127 # Get the file path. 7128 file_path = get_file_path(file_name, dir) 7129 7130 # Test the plot file exists. 7131 print("Testing file access to graph: %s"%file_path) 7132 self.assert_(access(file_path, F_OK)) 7133 7134 # Now open, and compare content, line by line. 7135 file_prod = open(file_path) 7136 lines_prod = file_prod.readlines() 7137 file_prod.close() 7138 7139 # Define file to compare against. 7140 dir_comp = data_path+sep+result_folder 7141 file_path_comp = get_file_path(file_name, dir_comp) 7142 file_comp = open(file_path_comp) 7143 lines_comp = file_comp.readlines() 7144 file_comp.close() 7145 7146 # Assert number of lines is equal. 7147 self.assertEqual(len(lines_prod), len(lines_comp)) 7148 for j in range(len(lines_prod)): 7149 # Make the string test 7150 first_char = lines_prod[j][0] 7151 if first_char in ["@", "&"]: 7152 self.assertEqual(lines_prod[j], lines_comp[j]) 7153 else: 7154 # Split string in x, y, error. 7155 # The error would change per run. 7156 x_prod, y_prod, y_prod_err = lines_prod[j].split() 7157 x_comp, y_comp, y_comp_err = lines_comp[j].split() 7158 self.assertAlmostEqual(float(x_prod), float(x_comp)) 7159 self.assertAlmostEqual(float(y_prod), float(y_comp))
7160 7161
7163 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7164 7165 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7166 7167 This uses the automatic analysis, with missing loading R1. 7168 7169 """ 7170 7171 # Cluster residues 7172 cluster_ids = [ 7173 ":13@N", 7174 ":15@N", 7175 ":16@N", 7176 ":25@N", 7177 ":26@N", 7178 ":28@N", 7179 ":39@N", 7180 ":40@N", 7181 ":41@N", 7182 ":43@N", 7183 ":44@N", 7184 ":45@N", 7185 ":49@N", 7186 ":52@N", 7187 ":53@N"] 7188 7189 # Load the data. 7190 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 7191 7192 # The dispersion models. 7193 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7194 7195 # The grid search size (the number of increments per dimension). 7196 GRID_INC = None 7197 7198 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7199 MC_NUM = 3 7200 7201 # Model selection technique. 7202 MODSEL = 'AIC' 7203 7204 # Execute the auto-analysis (fast). 7205 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7206 OPT_FUNC_TOL = 1e-25 7207 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7208 OPT_MAX_ITERATIONS = 10000000 7209 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7210 7211 result_dir_name = ds.tmpdir 7212 7213 # Make all spins free 7214 for curspin in cluster_ids: 7215 self.interpreter.relax_disp.cluster('free spins', curspin) 7216 # Shut them down 7217 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7218 7219 # Select only a subset of spins for global fitting 7220 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7221 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7222 7223 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7224 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7225 7226 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7227 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7228 7229 # Point to directory with R2eff values, with 2000 MC simulations. 7230 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" 7231 7232 r1_fit = True 7233 7234 # Run the analysis. 7235 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) 7236 7237 # Verify the data. 7238 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7239 7240
7241 - def test_r2eff_read(self):
7242 """Test the operation of the relax_disp.r2eff_read user function.""" 7243 7244 # The path to the data files. 7245 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 7246 7247 # Read the sequence data. 7248 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 7249 7250 # The ID. 7251 id = 'test' 7252 7253 # Set up the metadata. 7254 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 7255 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7256 7257 # Try reading the file. 7258 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) 7259 7260 # Check the global data. 7261 data = [ 7262 ['cpmg_frqs', {'test': 66.667}], 7263 ['cpmg_frqs_list', [66.667]], 7264 ['dispersion_points', 1], 7265 ['exp_type', {'test': 'SQ CPMG'}], 7266 ['exp_type_list', ['SQ CPMG']], 7267 ['spectrometer_frq', {'test': 800000000.0}], 7268 ['spectrometer_frq_count', 1], 7269 ['spectrometer_frq_list', [800000000.0]], 7270 ['spectrum_ids', ['test']] 7271 ] 7272 for name, value in data: 7273 # Does it exist? 7274 self.assert_(hasattr(cdp, name)) 7275 7276 # Check the object. 7277 obj = getattr(cdp, name) 7278 self.assertEqual(obj, value) 7279 7280 # Check the spin data. 7281 data = [ 7282 [1, 2.3035747e+04, 8.5467725e+01], 7283 [2, 9.9629762e+04, 2.8322033e+02], 7284 [3, 9.5663137e+04, 2.8632929e+02], 7285 [4, 1.7089893e+05, 3.1089428e+02], 7286 [5, 4.7323876e+04, 1.0084269e+02], 7287 [6, 2.0199122e+04, 1.0135220e+02], 7288 [7, 1.6655488e+05, 3.1609061e+02], 7289 [8, 9.0061074e+04, 1.9176585e+02], 7290 [10, 8.4726204e+04, 2.8898155e+02], 7291 [11, 1.5050233e+05, 4.3138029e+02], 7292 [12, 9.2998531e+04, 3.0440191e+02], 7293 [13, 1.6343507e+05, 3.3144097e+02], 7294 [14, 1.0137301e+05, 3.7314642e+02], 7295 [15, 8.3407837e+04, 1.6546473e+02], 7296 [16, 1.3819126e+05, 3.3388517e+02], 7297 [17, 1.1010490e+05, 3.5639222e+02], 7298 [18, 9.4324035e+04, 3.2343585e+02], 7299 [19, 1.1135179e+05, 3.0706671e+02], 7300 [20, 7.6339410e+04, 1.7377460e+02], 7301 [21, 6.2008453e+04, 1.7327150e+02], 7302 [22, 1.0590404e+05, 2.4814635e+02], 7303 [23, 1.0630198e+05, 2.3601100e+02], 7304 [24, 7.2996320e+04, 1.4952465e+02], 7305 [25, 9.5486742e+04, 2.7080766e+02], 7306 [26, 5.8067989e+04, 1.6820462e+02], 7307 [27, -1.7168510e+04, 2.2519560e+02], 7308 [28, 1.6891473e+05, 2.3497525e+02], 7309 [29, 9.4038555e+04, 2.0357593e+02], 7310 [30, 2.1386951e+04, 2.2153532e+02], 7311 [31, 9.3982899e+04, 2.0937056e+02], 7312 [32, 8.6097484e+04, 2.3868467e+02], 7313 [33, 1.0194337e+05, 2.7370704e+02], 7314 [34, 8.5683111e+04, 2.0838076e+02], 7315 [35, 8.6985768e+04, 2.0889310e+02], 7316 [36, 8.6011237e+04, 1.7498390e+02], 7317 [37, 1.0984097e+05, 2.7622998e+02], 7318 [38, 8.7017879e+04, 2.6547994e+02], 7319 [39, 9.1682649e+04, 5.2777676e+02], 7320 [40, 7.6370440e+04, 1.9873214e+02], 7321 [41, 9.1393531e+04, 2.4483824e+02], 7322 [42, 1.1017111e+05, 2.8020699e+02], 7323 [43, 9.4552366e+04, 3.4394150e+02], 7324 [44, 1.2858281e+05, 6.8449252e+02], 7325 [45, 7.4583525e+04, 1.9544210e+02], 7326 [46, 9.2087490e+04, 2.0491066e+02], 7327 [47, 9.7507255e+04, 2.5162839e+02], 7328 [48, 1.0033842e+05, 2.7566430e+02], 7329 [49, 1.3048305e+05, 2.6797466e+02], 7330 [50, 1.0546796e+05, 1.9304384e+02], 7331 [51, 9.3099697e+04, 2.0773311e+02], 7332 [52, 4.6863758e+04, 1.3169068e+02], 7333 [53, 6.1055806e+04, 1.5448477e+02], 7334 [55, 6.8629994e+04, 1.6868673e+02], 7335 [56, 1.1005552e+05, 2.1940465e+02], 7336 [57, 1.0572760e+05, 1.9768486e+02], 7337 [58, 1.1176950e+05, 3.0009610e+02], 7338 [59, 9.8758603e+04, 3.3803895e+02], 7339 [60, 9.9517201e+04, 3.5137994e+02], 7340 [61, 5.4357946e+04, 2.5896579e+02], 7341 [62, 1.0899978e+05, 2.8720371e+02], 7342 [63, 8.4549759e+04, 4.1401837e+02], 7343 [64, 5.5014550e+04, 2.1135781e+02], 7344 [65, 8.0569666e+04, 2.3249709e+02], 7345 [66, 1.2936610e+05, 3.5218725e+02], 7346 [67, 3.6438010e+04, 8.7924003e+01], 7347 [70, 3.8763157e+04, 1.3325040e+02], 7348 [71, 8.5711411e+04, 2.9316183e+02], 7349 [72, 3.3211541e+04, 1.2182123e+02], 7350 [73, 3.2070576e+04, 1.2305430e+02] 7351 ] 7352 for res_num, value, error in data: 7353 # Get the spin. 7354 spin = return_spin(spin_id=":%s"%res_num) 7355 7356 # Check the values. 7357 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7358 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7359 7360
7361 - def test_r2eff_read_spin(self):
7362 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7363 7364 # The path to the data files. 7365 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7366 7367 # Generate the sequence. 7368 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7369 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7370 self.interpreter.spin.isotope('1H', spin_id='@H') 7371 self.interpreter.spin.isotope('15N', spin_id='@N') 7372 7373 # Build the experiment IDs. 7374 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] 7375 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] 7376 ids = [] 7377 for value in H_disp_points: 7378 ids.append('1H_CPMG_%s' % value) 7379 for value in N_disp_points: 7380 ids.append('15N_CPMG_%s' % value) 7381 print("\n\nThe experiment IDs are %s." % ids) 7382 7383 # Set up the metadata for the experiments. 7384 for id in ids: 7385 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7386 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7387 for value in H_disp_points: 7388 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7389 for value in N_disp_points: 7390 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7391 7392 # Loop over the experiments. 7393 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7394 # Try reading the file. 7395 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) 7396 7397 # Check the global data. 7398 data = [ 7399 ['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}], 7400 ['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]], 7401 ['dispersion_points', 24], 7402 ['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'}], 7403 ['exp_type_list', ['SQ CPMG']], 7404 ['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}], 7405 ['spectrometer_frq_count', 1], 7406 ['spectrometer_frq_list', [500000000.0]], 7407 ['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']] 7408 ] 7409 for name, value in data: 7410 # Does it exist? 7411 self.assert_(hasattr(cdp, name)) 7412 7413 # Check the object. 7414 obj = getattr(cdp, name) 7415 if not isinstance(data, dict): 7416 self.assertEqual(obj, value) 7417 7418 # Check the global dictionary data. 7419 else: 7420 for id in ids: 7421 self.assertEqual(obj[id], value[id]) 7422 7423 # Check the spin data. 7424 h_data = [ 7425 [ 67.0, 21.47924, 0.42958], 7426 [ 133.0, 16.73898, 0.33478], 7427 [ 267.0, 9.97357, 0.19947], 7428 [ 400.0, 8.23877, 0.24737], 7429 [ 533.0, 7.59290, 0.24263], 7430 [ 667.0, 7.45843, 0.24165], 7431 [ 800.0, 7.11222, 0.23915], 7432 [ 933.0, 7.40880, 0.24129], 7433 [1067.0, 6.55191, 0.16629], 7434 [1600.0, 6.72177, 0.23637], 7435 [2133.0, 7.09629, 0.23904], 7436 [2667.0, 7.14675, 0.23940] 7437 ] 7438 for disp_point, value, error in h_data: 7439 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7440 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7441 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7442 n_data = [ 7443 [ 50.0, 27.15767, 0.54315], 7444 [ 100.0, 26.55781, 0.53116], 7445 [ 150.0, 24.73462, 0.49469], 7446 [ 200.0, 20.98617, 0.41972], 7447 [ 250.0, 17.82442, 0.35649], 7448 [ 300.0, 15.55352, 0.31107], 7449 [ 350.0, 13.78958, 0.27579], 7450 [ 400.0, 12.48334, 0.24967], 7451 [ 500.0, 11.55724, 0.23114], 7452 [ 600.0, 10.53874, 0.21077], 7453 [ 700.0, 10.07395, 0.20148], 7454 [ 800.0, 9.62952, 0.19259], 7455 [ 900.0, 9.49994, 0.19000], 7456 [1000.0, 8.71350, 0.17427] 7457 ] 7458 for disp_point, value, error in n_data: 7459 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7460 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7461 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7462 7463
7464 - def test_r2eff_fit_fixed_time(self):
7465 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7466 7467 # Execute the script. 7468 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7469 7470
7471 - def test_read_r2eff(self):
7472 """Test the reading of a file containing r2eff values.""" 7473 7474 # Create the sequence data, and name the spins. 7475 self.interpreter.residue.create(1, 'Gly') 7476 self.interpreter.residue.create(2, 'Gly') 7477 self.interpreter.residue.create(3, 'Gly') 7478 7479 # Read the file. 7480 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) 7481 7482 # Test the data. 7483 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7484 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7485 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7486 7487
7489 """Test speeding up grid search. Support requst sr #3151 U{https://web.archive.org/web/https://gna.org/support/index.php?3151}. 7490 7491 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7492 7493 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7494 'SOD1-WT' CPMG data to the CR72 dispersion model. 7495 7496 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. 7497 Data is for experiment at 25 degree Celcius. 7498 """ 7499 7500 # Base data setup. 7501 pipe_name = 'base pipe' 7502 pipe_type = 'relax_disp' 7503 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7504 select_spin_index = list(range(0, 1)) 7505 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7506 7507 # Generate r20 key. 7508 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7509 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7510 7511 ## Now prepare for MODEL calculation. 7512 MODEL = "CR72" 7513 7514 # Change pipe. 7515 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7516 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7517 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7518 7519 # Then select model. 7520 self.interpreter.relax_disp.select_model(model=MODEL) 7521 7522 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7523 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7524 7525 # Test result, for normal run. 7526 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7527 # Get the spin_params. 7528 spin_params = spin.params 7529 7530 # Defined fixed values for testing. 7531 if spin_id == ":10@N": 7532 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7533 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7534 7535 # Print out. 7536 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)) 7537 7538 # Testing the r2 values for the different fields are not the same. 7539 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7540 7541 # Test values are larger than 0. 7542 self.assert_(spin.r2[r20_key_600] > 0.0) 7543 self.assert_(spin.r2[r20_key_500] > 0.0) 7544 7545 # Loop over the experiment settings. 7546 r2eff_600 = [] 7547 r2eff_500 = [] 7548 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7549 # Create the data key. 7550 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7551 7552 # Extract the r2 eff data. 7553 r2eff = spin.r2eff[data_key] 7554 if frq == 599.8908617*1E6: 7555 r2eff_600.append(r2eff) 7556 elif frq == 499.862139*1E6: 7557 r2eff_500.append(r2eff) 7558 7559 # Sort values. 7560 r2eff_600.sort() 7561 r2eff_500.sort() 7562 7563 # Test values again. 7564 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7565 print(r2eff_600) 7566 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7567 print("") 7568 7569 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7570 print(r2eff_500) 7571 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7572 print("") 7573 7574 print("###########################################") 7575 print("Trying GRID SEARCH for minimum R2eff values") 7576 7577 ### Test just the Grid search. 7578 GRID_INC = 5 7579 7580 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7581 7582 ### Then test the value.set function. 7583 # Change pipe. 7584 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7585 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7586 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7587 7588 # Then select model. 7589 self.interpreter.relax_disp.select_model(model=MODEL) 7590 7591 # Then set the standard parameter values. 7592 for param in spin_params: 7593 print("Setting standard parameter for param: %s"%param) 7594 self.interpreter.value.set(param=param, index=None) 7595 7596 # Test result, for normal run. 7597 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7598 # Print out. 7599 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)) 7600 7601 # Testing the r2 values. 7602 self.assertEqual(spin.r2[r20_key_600], 10.00) 7603 self.assertEqual(spin.r2[r20_key_500], 10.00) 7604 self.assertEqual(spin.pA, 0.9) 7605 self.assertEqual(spin.dw, 1.0) 7606 self.assertEqual(spin.kex, 1000.0) 7607 7608 print("###########################################") 7609 print("Trying GRID SEARCH for standard R2eff values") 7610 7611 ### Test just the Grid search. 7612 GRID_INC = 5 7613 7614 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7615 7616 ### Run auto_analysis. 7617 # The grid search size (the number of increments per dimension). 7618 GRID_INC = 5 7619 7620 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7621 MC_NUM = 3 7622 7623 # Model selection technique. 7624 MODSEL = 'AIC' 7625 7626 # Execute the auto-analysis (fast). 7627 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7628 OPT_FUNC_TOL = 1e-1 7629 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7630 OPT_MAX_ITERATIONS = 1000 7631 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7632 7633 # Run the analysis. 7634 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)
7635 7636
7637 - def test_show_apod_extract(self):
7638 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7639 7640 # The path to the data files. 7641 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' 7642 7643 # Define file name. 7644 file_name = '128_0_FT.ft2' 7645 7646 # Call function. 7647 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7648 7649 # Define how output should look like. 7650 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7651 # Dont test lines which can differ. 7652 show_apod_ver = [ 7653 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7654 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7655 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7656 '', 7657 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7658 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7659 #'', 7660 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7661 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7662 7663 for i, line in enumerate(show_apod_ver): 7664 line_ver = get_output[i] 7665 7666 print(line) 7667 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7668 continue 7669 # Make the string test 7670 self.assertEqual(line, line_ver)
7671 7672
7673 - def test_show_apod_rmsd(self):
7674 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7675 7676 # The path to the data files. 7677 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' 7678 7679 # Define file name. 7680 file_name = '128_0_FT.ft2' 7681 7682 # Call function. 7683 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7684 7685 # Assert. 7686 self.assertEqual(rmsd, 8583.41)
7687 7688
7690 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7691 7692 # The path to the data files. 7693 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' 7694 7695 # Call function, and get all file names. 7696 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7697 7698 # Loop over file_paths. 7699 for wfile_path in wfile_paths: 7700 # Open the file. 7701 get_data = extract_data(file=wfile_path) 7702 7703 # Extract line 0, column 0. 7704 test = float(get_data[0][0]) 7705 7706 # Assert. 7707 self.assertEqual(test, 8583.41)
7708 7709
7711 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7712 7713 # The path to the data files. 7714 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' 7715 7716 # Define file name. 7717 file_name = '128_0_FT.ft2' 7718 7719 # Call function, and get file name. 7720 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7721 7722 # Open the file. 7723 get_data = extract_data(file=wfile_path) 7724 7725 # Extract line 0, column 0. 7726 test = float(get_data[0][0]) 7727 7728 # Assert. 7729 self.assertEqual(test, 8583.41)
7730 7731
7733 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7734 7735 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7736 'SOD1-WT' CPMG data to the CR72 dispersion model. 7737 7738 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. 7739 Data is for experiment at 25 degree Celcius. 7740 7741 bug #21954 U{https://web.archive.org/web/https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7742 """ 7743 7744 # Base data setup. 7745 pipe_name = 'base pipe' 7746 pipe_type = 'relax_disp' 7747 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7748 select_spin_index = list(range(0, 1)) 7749 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7750 7751 # Define replicated 7752 repl_A = ['Z_A1', 'Z_A15'] 7753 repl_B = ['Z_B1', 'Z_B18'] 7754 7755 # Loop over spectrum ID, and sort them 7756 spectrum_ids_A = [] 7757 spectrum_ids_B = [] 7758 for spectrum_id in cdp.spectrum_ids: 7759 if "A" in spectrum_id: 7760 spectrum_ids_A.append(spectrum_id) 7761 elif "B" in spectrum_id: 7762 spectrum_ids_B.append(spectrum_id) 7763 7764 # To clean up old error analysis, delete attributes 7765 delattr(cdp, "var_I") 7766 delattr(cdp, "sigma_I") 7767 7768 # Perform error analysis 7769 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7770 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7771 7772 # Loop over spins, save errors to list 7773 Errors_A_B = [] 7774 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7775 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7776 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7777 Errors_A_B.append([A_err, B_err]) 7778 7779 # To clean up old error analysis, delete attributes 7780 delattr(cdp, "var_I") 7781 delattr(cdp, "sigma_I") 7782 7783 # Perform error analysis. Order is important 7784 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7785 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7786 7787 # Loop over spins, save errors to list 7788 Errors_B_A = [] 7789 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7790 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7791 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7792 Errors_B_A.append([A_err, B_err]) 7793 7794 # Make test for order of error 7795 for i in range(len(Errors_A_B)): 7796 Error_A_B = Errors_A_B[i] 7797 Error_B_A = Errors_B_A[i] 7798 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7799 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7800 7801 # Make further tests for fixed values 7802 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7803 std_A_fix = 2785.7263335738567 7804 7805 for id_A in spectrum_ids_A: 7806 self.assertEqual(cdp.sigma_I[id_A], std_A) 7807 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7808 7809 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7810 std_B_fix = 4967.3772030667988 7811 7812 for id_B in spectrum_ids_B: 7813 self.assertEqual(cdp.sigma_I[id_B], std_B) 7814 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7815 7816
7817 - def test_sod1wt_t25_to_cr72(self):
7818 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7819 7820 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7821 'SOD1-WT' CPMG data to the CR72 dispersion model. 7822 7823 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. 7824 Data is for experiment at 25 degree Celcius. 7825 """ 7826 7827 # Base data setup. 7828 pipe_name = 'base pipe' 7829 pipe_type = 'relax_disp' 7830 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7831 select_spin_index = list(range(0, 2)) 7832 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7833 7834 # Generate r20 key. 7835 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7836 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7837 7838 ## Now prepare for MODEL calculation. 7839 MODEL = "CR72" 7840 7841 # Change pipe. 7842 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7843 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7844 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7845 7846 # Then select model. 7847 self.interpreter.relax_disp.select_model(model=MODEL) 7848 7849 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 7850 GRID_INC = 7 7851 7852 # Store grid and minimisations results. 7853 grid_results = [] 7854 mini_results = [] 7855 clust_results = [] 7856 7857 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7858 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7859 7860 # Deselect insignificant spins. 7861 self.interpreter.relax_disp.insignificance(level=1.0) 7862 7863 # Perform Grid Search. 7864 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7865 7866 # Store result. 7867 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7868 # Store grid results. 7869 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]) 7870 7871 ## Now do minimisation. 7872 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7873 set_func_tol = 1e-9 7874 set_max_iter = 100000 7875 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7876 7877 # Store result. 7878 pA_values = [] 7879 kex_values = [] 7880 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7881 # Store minimisation results. 7882 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]) 7883 7884 # Store pA values. 7885 pA_values.append(spin.pA) 7886 7887 # Store kex values. 7888 kex_values.append(spin.kex) 7889 7890 print("\n# Now print before and after minimisation.\n") 7891 7892 # Print results. 7893 for i in range(len(grid_results)): 7894 # Get values. 7895 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7896 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7897 7898 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)) 7899 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)) 7900 7901 ## Prepare for clustering 7902 # Change pipe. 7903 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 7904 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 7905 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 7906 7907 # Then select model. 7908 self.interpreter.relax_disp.select_model(model=MODEL) 7909 7910 # Define cluster id. 7911 cluster_id = 'clust' 7912 7913 # Loop over spins to cluster them. 7914 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7915 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 7916 7917 # Copy over values. 7918 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 7919 7920 # Test the median values is correct 7921 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7922 print(pA_values) 7923 # The the median pA value returned. 7924 self.assertEqual(median(pA_values), spin.pA) 7925 7926 # The the median kex value returned. 7927 self.assertEqual(median(kex_values), spin.kex) 7928 7929 ## Now do minimisation. 7930 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7931 7932 # Store result. 7933 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7934 # Store clust results. 7935 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]) 7936 7937 # Store the outcome of the clustering minimisation. 7938 clust_pA = spin.pA 7939 clust_kex = spin.kex 7940 7941 print("\n# Now testing.\n") 7942 7943 # Define results 7944 test_res = {} 7945 test_res[':10@N'] = {} 7946 test_res[':10@N']['r2600'] = 18.429755324773360 7947 test_res[':10@N']['r2500'] = 16.981349161968630 7948 test_res[':10@N']['dw'] = 2.700755859433969 7949 test_res[':10@N']['pA'] = 0.971531659288657 7950 test_res[':10@N']['kex'] = 3831.766337047963134 7951 test_res[':11@N'] = {} 7952 test_res[':11@N']['r2600'] = 18.193409421115213 7953 test_res[':11@N']['r2500'] = 17.308838135567765 7954 test_res[':11@N']['dw'] = 2.706650302761793 7955 test_res[':11@N']['pA'] = 0.971531659288657 7956 test_res[':11@N']['kex'] = 3831.766337047963134 7957 7958 # Then make tests. 7959 for i in range(len(grid_results)): 7960 # Get values. 7961 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7962 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7963 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 7964 7965 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)) 7966 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)) 7967 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)) 7968 7969 # Make tests. 7970 self.assertEqual(clust_pA, c_pA) 7971 self.assertEqual(clust_kex, c_kex) 7972 7973 # Test values. 7974 if c_spin_id in test_res: 7975 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 7976 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 7977 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 7978 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 7979 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
7980 7981 # Save disp graph to temp. 7982 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 7983 7984
7986 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 7987 7988 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7989 'SOD1-WT' CPMG data to the CR72 dispersion model. 7990 7991 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. 7992 Data is for experiment at 25 degree Celcius. 7993 """ 7994 7995 # Base data setup. 7996 pipe_name = 'base pipe' 7997 pipe_type = 'relax_disp' 7998 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7999 select_spin_index = list(range(0, 2)) 8000 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 8001 8002 # Generate r20 key. 8003 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 8004 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 8005 8006 # Cluster everything, to analyse together. 8007 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 8008 8009 # Write input 8010 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 8011 8012 # Check the r2eff set files. 8013 print("\nChecking the R2eff input set files.") 8014 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 8015 8016 # First check file exists 8017 for dir, file in files: 8018 print(dir+sep+file) 8019 self.assert_(access(dir+sep+file, F_OK)) 8020 8021 # Define how files should look like 8022 data_set_600 = [ 8023 "60.8272464287\n", 8024 "0.06\n", 8025 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8026 "# G10\n", 8027 " 33.333 26.53556078711 0.5236104771163\n", 8028 " 66.667 25.29735243318 0.48766574122\n", 8029 " 100 25.09470361403 0.4820438864671\n", 8030 " 133.333 25.15603274331 0.4837377286085\n", 8031 " 166.667 24.27213341753 0.4599457904395\n", 8032 " 200 24.00364120328 0.4529773198905\n", 8033 " 266.667 24.03511395168 0.4537880662536\n", 8034 " 300 23.04761040024 0.4291039120557\n", 8035 " 333.333 22.95530300787 0.4268745963972\n", 8036 " 400 23.06158810662 0.4294426293624\n", 8037 " 466.667 22.26799054092 0.4106809618644\n", 8038 " 533.333 21.99851418823 0.4045232104735\n", 8039 " 666.667 21.19651570955 0.3868136173831\n", 8040 " 833.333 20.30938498379 0.3682604887899\n", 8041 " 1000 20.28273252609 0.367719392568\n", 8042 "# D11\n", 8043 " 33.333 24.76520269878 0.5026475808706\n", 8044 " 66.667 24.8773107448 0.5058752916906\n", 8045 " 100 24.90357815239 0.5066348551479\n", 8046 " 133.333 23.7782506151 0.4751950583865\n", 8047 " 166.667 23.68548762076 0.4727017128631\n", 8048 " 200 23.58629651618 0.4700517377679\n", 8049 " 266.667 23.47734671187 0.4671601744044\n", 8050 " 300 24.08647493772 0.4835855560598\n", 8051 " 333.333 22.98314371029 0.4542918950801\n", 8052 " 400 22.80339361568 0.4497107885587\n", 8053 " 466.667 22.91634335366 0.4525833037874\n", 8054 " 533.333 22.59774140046 0.4445334311324\n", 8055 " 666.667 20.9177750759 0.4046955726046\n", 8056 " 833.333 20.71792550566 0.4002363835007\n", 8057 " 1000 19.54080006349 0.3751112751853\n", 8058 ] 8059 8060 # Check data_set_600 8061 file = open(files[0][0]+sep+files[0][1]) 8062 lines = file.readlines() 8063 file.close() 8064 self.assertEqual(len(data_set_600), len(lines)) 8065 for i in range(len(data_set_600)): 8066 # Make the string test 8067 self.assertEqual(data_set_600[i], lines[i]) 8068 8069 # Define how files should look like 8070 data_set_500 = [ 8071 "50.6846152368\n", 8072 "0.04\n", 8073 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8074 "# G10\n", 8075 " 50 22.28084307393 0.2944966344183\n", 8076 " 100 21.93494977761 0.2910362768307\n", 8077 " 150 21.09850032232 0.282892238351\n", 8078 " 200 20.86493960397 0.2806737853646\n", 8079 " 250 20.75287269752 0.2796178205016\n", 8080 " 300 20.25597152406 0.2750013546989\n", 8081 " 350 19.92172163467 0.2719555756504\n", 8082 " 400 19.97712052922 0.272457105051\n", 8083 " 450 19.46807010415 0.2678972122793\n", 8084 " 500 19.76875460947 0.2705774849203\n", 8085 " 550 19.39161367402 0.2672216964327\n", 8086 " 600 19.03949517697 0.2641417899694\n", 8087 " 650 19.12218812132 0.2648605059901\n", 8088 " 700 19.01037461457 0.2638893584683\n", 8089 " 800 18.83395162904 0.2623674321143\n", 8090 " 900 18.47529972436 0.2593123604687\n", 8091 " 1000 18.5252023121 0.2597343394038\n", 8092 "# D11\n", 8093 " 50 22.15403890237 0.3285588379827\n", 8094 " 100 21.80946781746 0.3247185598713\n", 8095 " 150 21.77715415505 0.324361526682\n", 8096 " 200 21.41647464235 0.3204122024881\n", 8097 " 250 21.17099940822 0.3177616325958\n", 8098 " 300 21.03740030577 0.3163316496664\n", 8099 " 350 20.95393648281 0.3154427665172\n", 8100 " 400 20.93311399332 0.315221543436\n", 8101 " 450 20.18219905222 0.3073848655291\n", 8102 " 500 19.93599065085 0.3048744697057\n", 8103 " 550 19.68475725452 0.3023424499113\n", 8104 " 600 19.33575433934 0.2988741928798\n", 8105 " 650 19.53915692194 0.3008886196853\n", 8106 " 700 19.2018754351 0.2975587767134\n", 8107 " 800 18.82360965368 0.2938866923878\n", 8108 " 900 18.71861761238 0.2928790380131\n", 8109 " 1000 17.95878049287 0.2857341721151\n", 8110 ] 8111 8112 # Check data_set_500 8113 file = open(files[1][0]+sep+files[1][1]) 8114 lines = file.readlines() 8115 file.close() 8116 self.assertEqual(len(data_set_500), len(lines)) 8117 for i in range(len(data_set_500)): 8118 # Make the string test 8119 self.assertEqual(data_set_500[i], lines[i]) 8120 8121 # Test local dir tests. This will be turned off in system test. 8122 turn_on_local_dir_test = False 8123 8124 if turn_on_local_dir_test: 8125 ## Now check to local folder with None argument. 8126 # Write input 8127 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 8128 8129 # Check the r2eff set files. 8130 print("\nChecking the R2eff input set files.") 8131 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 8132 8133 # First check file exists 8134 for dir, file in files: 8135 print(dir+sep+file) 8136 self.assert_(access(dir+sep+file, F_OK)) 8137 8138 ## Now check to local folder with dir argument. 8139 # Write input 8140 set_dir = "Test_ShereKhan" 8141 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 8142 8143 # Check the r2eff set files. 8144 print("\nChecking the R2eff input set files.") 8145 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 8146 8147 # First check file exists 8148 for dir, file in files: 8149 print(dir+sep+file) 8150 self.assert_(access(dir+sep+file, F_OK))
8151 8152
8153 - def test_sprangers_data_to_mmq_cr72(self, model=None):
8154 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 8155 8156 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. 8157 """ 8158 8159 # Reset. 8160 self.interpreter.reset() 8161 8162 # Create the data pipe and load the base data. 8163 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8164 self.interpreter.state.load(data_path+sep+'r2eff_values') 8165 8166 # The model data pipe. 8167 model = 'MMQ CR72' 8168 pipe_name = "%s - relax_disp" % model 8169 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8170 self.interpreter.pipe.switch(pipe_name=pipe_name) 8171 8172 # Set the model. 8173 self.interpreter.relax_disp.select_model(model=model) 8174 8175 # Cluster everything. 8176 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8177 8178 # Copy the data. 8179 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8180 8181 # Alias the spins. 8182 spin135S = cdp.mol[0].res[0].spin[0] 8183 spin135F = cdp.mol[0].res[0].spin[1] 8184 spin137S = cdp.mol[0].res[1].spin[0] 8185 spin137F = cdp.mol[0].res[1].spin[1] 8186 8187 # The R20 keys. 8188 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 8189 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8190 8191 # Set the cluster specific parameters (only for the first spin). 8192 spin135S.pA = 0.836591763632 8193 spin135S.kex = 241.806525261 8194 8195 # Set the initial parameter values. 8196 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 8197 spin135S.dw = 0.583003118785 8198 spin135S.dwH = 0.0361441944301 8199 8200 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 8201 spin135F.dw = 0.805849745104 8202 spin135F.dwH = 0.0215791945715 8203 8204 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 8205 spin137S.dw = 0.688107568372 8206 spin137S.dwH = 0.0344463604043 8207 8208 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 8209 spin137F.dw = 0.94978299907 8210 spin137F.dwH = 1.4818877939e-07 8211 8212 # Low precision optimisation. 8213 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 8214 8215 # Printout. 8216 print("\n\nOptimised parameters:\n") 8217 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8218 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])) 8219 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])) 8220 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8221 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8222 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8223 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8224 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8225 print("\n # Set the cluster specific parameters (only for the first spin).") 8226 print(" spin135S.pA = %s" % spin135S.pA) 8227 print(" spin135S.kex = %s" % spin135S.kex) 8228 print("\n # Set the initial parameter values.") 8229 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 8230 print(" spin135S.dw = %s" % spin135S.dw) 8231 print(" spin135S.dwH = %s" % spin135S.dwH) 8232 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 8233 print(" spin135F.dw = %s" % spin135F.dw) 8234 print(" spin135F.dwH = %s" % spin135F.dwH) 8235 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 8236 print(" spin137S.dw = %s" % spin137S.dw) 8237 print(" spin137S.dwH = %s" % spin137S.dwH) 8238 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 8239 print(" spin137F.dw = %s" % spin137F.dw) 8240 print(" spin137F.dwH = %s" % spin137F.dwH) 8241 8242 # Checks for residue :135S. 8243 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 8244 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 8245 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 8246 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 8247 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 8248 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 8249 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 8250 8251 # Checks for residue :135F. 8252 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 8253 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 8254 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 8255 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 8256 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 8257 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 8258 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8259 8260 # Checks for residue :137S. 8261 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8262 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8263 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8264 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8265 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8266 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8267 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8268 8269 # Checks for residue :137F. 8270 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8271 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8272 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8273 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8274 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8275 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8276 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8277 8278
8279 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8280 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8281 8282 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. 8283 """ 8284 8285 # Reset. 8286 self.interpreter.reset() 8287 8288 # Create the data pipe and load the base data. 8289 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8290 self.interpreter.state.load(data_path+sep+'r2eff_values') 8291 8292 # The model data pipe. 8293 model = 'NS MMQ 2-site' 8294 pipe_name = "%s - relax_disp" % model 8295 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8296 self.interpreter.pipe.switch(pipe_name=pipe_name) 8297 8298 # Set the model. 8299 self.interpreter.relax_disp.select_model(model=model) 8300 8301 # Cluster everything. 8302 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8303 8304 # Copy the data. 8305 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8306 8307 # Alias the spins. 8308 spin135S = cdp.mol[0].res[0].spin[0] 8309 spin135F = cdp.mol[0].res[0].spin[1] 8310 spin137S = cdp.mol[0].res[1].spin[0] 8311 spin137F = cdp.mol[0].res[1].spin[1] 8312 8313 # The R20 keys. 8314 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8315 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8316 8317 # Set the cluster specific parameters (only for the first spin). 8318 spin135S.pA = 0.847378444499757 8319 spin135S.kex = 264.055604934724329 8320 8321 # Set the initial parameter values. 8322 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8323 spin135S.dw = 0.585574008745351 8324 spin135S.dwH = 0.000000000000002 8325 8326 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8327 spin135F.dw = 0.856699277665748 8328 spin135F.dwH = 0.000000000582587 8329 8330 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8331 spin137S.dw = 0.772904450844973 8332 spin137S.dwH = 0.183351478512970 8333 8334 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8335 spin137F.dw = 0.984568590342831 8336 spin137F.dwH = 0.000000001993458 8337 8338 # Low precision optimisation. 8339 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) 8340 8341 # Printout. 8342 print("\n\nOptimised parameters:\n") 8343 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8344 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])) 8345 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])) 8346 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8347 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8348 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8349 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8350 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8351 8352 # FIXME: Remove this temporary return and properly check the results. 8353 return 8354 8355 # Checks for residue :135S. 8356 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8357 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8358 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8359 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8360 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8361 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8362 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8363 8364 # Checks for residue :135F. 8365 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8366 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8367 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8368 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8369 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8370 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8371 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8372 8373 # Checks for residue :137S. 8374 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8375 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8376 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8377 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8378 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8379 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8380 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8381 8382 # Checks for residue :137F. 8383 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8384 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8385 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8386 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8387 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8388 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8389 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8390 8391
8392 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8393 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8394 8395 # Setup the data. 8396 self.setup_tp02_data_to_ns_r1rho_2site() 8397 8398 # Alias the spins. 8399 spin1 = cdp.mol[0].res[0].spin[0] 8400 spin2 = cdp.mol[0].res[1].spin[0] 8401 8402 # The R20 keys. 8403 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8404 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8405 8406 # Checks for residue :1. 8407 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8408 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8409 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8410 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8411 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8412 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8413 8414 # Checks for residue :2. 8415 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8416 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8417 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8418 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8419 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8420 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8421 8422
8423 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8424 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8425 8426 # Setup the data. 8427 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8428 8429 # Alias the spins. 8430 spin1 = cdp.mol[0].res[0].spin[0] 8431 spin2 = cdp.mol[0].res[1].spin[0] 8432 8433 # The R20 keys. 8434 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8435 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8436 8437 # Checks for residue :1. 8438 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8439 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8440 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8441 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8442 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8443 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8444 8445 # Checks for residue :2. 8446 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8447 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8448 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8449 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8450 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8451 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8452 8453
8454 - def test_tp02_data_to_mp05(self):
8455 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8456 8457 # Fixed time variable and the models. 8458 ds.fixed = True 8459 ds.models = ['R2eff', 'MP05'] 8460 8461 # Execute the script. 8462 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') 8463 8464 # Switch back to the data pipe for the optimisation. 8465 self.interpreter.pipe.switch('MP05 - relax_disp') 8466 8467 # The equivalent MP05 parameters. 8468 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8469 pA = [0.775055484521586, 0.500000000036595] 8470 kex = [1235.20361276079, 2378.31403454691] 8471 delta_omega = [7.08194146569694, 5.4083562844306] 8472 chi2 = [0.0370400968727768, 0.182141732163934] 8473 8474 # Alias the spins. 8475 spin1 = cdp.mol[0].res[0].spin[0] 8476 spin2 = cdp.mol[0].res[1].spin[0] 8477 8478 # The R20 keys. 8479 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8480 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8481 8482 # Printout. 8483 print("\n\nOptimised parameters:\n") 8484 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8485 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8486 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8487 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8488 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8489 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8490 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8491 8492 # Check each spin. 8493 spin_index = 0 8494 for spin, spin_id in spin_loop(return_id=True): 8495 # Printout. 8496 print("\nSpin %s." % spin_id) 8497 8498 # Check the fitted parameters. 8499 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8500 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8501 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8502 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8503 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8504 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8505 8506 # Increment the spin index. 8507 spin_index += 1
8508 8509
8510 - def test_tp02_data_to_tap03(self):
8511 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8512 8513 # Fixed time variable and the models. 8514 ds.fixed = True 8515 ds.models = ['R2eff', 'TAP03'] 8516 8517 # Execute the script. 8518 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') 8519 8520 # Switch back to the data pipe for the optimisation. 8521 self.interpreter.pipe.switch('TAP03 - relax_disp') 8522 8523 # The equivalent TAP03 parameters. 8524 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8525 pA = [0.775042569092891, 0.500000000229685] 8526 kex = [1235.20852748765, 2379.47085580169] 8527 delta_omega = [7.08176806468445, 5.40708372863538] 8528 chi2 = [0.0371366837083293, 0.182212857256044] 8529 8530 # Alias the spins. 8531 spin1 = cdp.mol[0].res[0].spin[0] 8532 spin2 = cdp.mol[0].res[1].spin[0] 8533 8534 # The R20 keys. 8535 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8536 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8537 8538 # Printout. 8539 print("\n\nOptimised parameters:\n") 8540 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8541 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8542 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8543 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8544 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8545 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8546 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8547 8548 # Switch to the 'MP05' model data pipe, then check for each spin. 8549 self.interpreter.pipe.switch('TAP03 - relax_disp') 8550 spin_index = 0 8551 for spin, spin_id in spin_loop(return_id=True): 8552 # Printout. 8553 print("\nSpin %s." % spin_id) 8554 8555 # Check the fitted parameters. 8556 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8557 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8558 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8559 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8560 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8561 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8562 8563 # Increment the spin index. 8564 spin_index += 1
8565 8566
8568 """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""" 8569 8570 # 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. 8571 8572 # Load the results file from a clustered minimisation. 8573 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8574 self.interpreter.results.read(file_name) 8575 8576 # Get the spins, which was used for clustering. 8577 spins_cluster = cdp.clustering['sel'] 8578 spins_free = cdp.clustering['free spins'] 8579 8580 # For sanity check, calculate degree of freedom. 8581 cur_spin_id = spins_cluster[0] 8582 cur_spin = return_spin(cur_spin_id) 8583 8584 # Calculate total number of datapoins. 8585 N = len(spins_cluster) 8586 N_dp = N * len(cur_spin.r2eff) 8587 8588 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8589 N_par = cdp.spectrometer_frq_count * N + N + 1 + 1 8590 dof = N_dp - N_par 8591 8592 # Sanity check of parameters. 8593 print(N_par, N_dp) 8594 8595 # Number of MC 8596 mc_nr = 3 8597 8598 # Setup MC for errors generated from the distribution described by chi2 and degrees of freedom from best fit. 8599 self.interpreter.monte_carlo.setup(number=mc_nr) 8600 8601 # Create data. 8602 self.interpreter.monte_carlo.create_data(distribution="red_chi2") 8603 8604 # Setup MC again. 8605 self.interpreter.monte_carlo.setup(number=mc_nr) 8606 8607 # Create data, and set the fixed error value, without setting the correct distribution. 8608 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, fixed_error=1.) 8609 8610 # Setup MC again. 8611 self.interpreter.monte_carlo.setup(number=mc_nr) 8612 8613 # Create data, with fixed error distribution, but not setting the error value. 8614 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="fixed") 8615 8616 # Setup MC again. 8617 self.interpreter.monte_carlo.create_data(distribution="fixed", fixed_error=1.) 8618 8619 # Now select the R2eff model, and try again. Expect raising an error. 8620 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8621 8622 # Setup MC again. 8623 self.interpreter.monte_carlo.setup(number=mc_nr) 8624 8625 # Create data, and assert failure. 8626 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="red_chi2") 8627 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, method="direct", distribution="red_chi2")
8628 8629
8630 - def x_test_task_7882_kex_conf(self):
8631 """Test related to Task #7882 U{https://web.archive.org/web/https://gna.org/task/?7882}: Try making a confidence interval of kex. 8632 According to the regression book of Graphpad: U{http://www.graphpad.com/faq/file/Prism4RegressionBook.pdf}. 8633 Page 109-111. 8634 """ 8635 8636 # Load the results file from a clustered minimisation. 8637 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8638 self.interpreter.results.read(file_name) 8639 8640 # Get the spins, which was used for clustering. 8641 spins_cluster = cdp.clustering['sel'] 8642 spins_free = cdp.clustering['free spins'] 8643 8644 # For sanity check, calculate degree of freedom. 8645 cur_spin_id = spins_cluster[0] 8646 cur_spin = return_spin(cur_spin_id) 8647 8648 # Calculate total number of datapoins. 8649 Ns = len(spins_cluster) 8650 N_dp = Ns * len(cur_spin.r2eff) 8651 8652 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8653 N_par = cdp.spectrometer_frq_count * Ns + Ns + 1 + 1 8654 dof_fit = N_dp - N_par 8655 8656 # Assert values. 8657 self.assertEqual(Ns, 61) 8658 self.assertEqual(N_dp, 1952) 8659 self.assertEqual(N_par, 185) 8660 8661 # Confidence interval of kex. 8662 # The number of parameters to check is kex = 1. 8663 P = 1 8664 # Number of datapoints 8665 N = N_dp 8666 # The degrees of freedom for this confidence interval 8667 dof_conf = N - P 8668 8669 # The critical value of the F distribution with p-value of 0.05 for 95% confidence. 8670 # Can be calculated with microsoft excel: 8671 # F=FINV(0,05; P; dof_conf), F=FINV(0,05; P; dof_conf), F=FINV(0,05; 1; 1951)=3,846229551 8672 # Can also be calculated with: import scipy.stats; scipy.stats.f.isf(0.05, 1, 1951)=3.8462295505435562 8673 F = 3.8462295505435562 8674 # Then calculate the scaling of chi2, which is the weighted sum of squares of best fit. 8675 scale = F*P/dof_conf +1 8676 8677 # Get the sum of best fit. 8678 SSbest_fit = cur_spin.chi2 8679 SSbest_kex = cur_spin.kex 8680 8681 # Get the scaled sum of best fit 8682 SSall_fixed = SSbest_fit * scale 8683 8684 print(SSbest_fit, scale, SSall_fixed) 8685 8686 # Now generate a list of kex values to try. 8687 kex_cur = cur_spin.kex 8688 kex_list = linspace(kex_cur - 1500, kex_cur + 3000, 200) 8689 8690 chi2_list = [] 8691 8692 for kex in kex_list: 8693 self.interpreter.value.set(val=kex, param='kex') 8694 8695 # Calculate the chi2 values. 8696 self.interpreter.minimise.calculate(verbosity=0) 8697 8698 # Get the chi2 value 8699 chi2_cur = cur_spin.chi2 8700 print("kex=%3.2f, chi2=%3.2f"%(kex, chi2_cur), chi2_cur<SSall_fixed) 8701 8702 # Add to list 8703 chi2_list.append(chi2_cur) 8704 8705 # Now make to numpy array. 8706 chi2_list = asarray(chi2_list) 8707 8708 # Now make a selection mask based on the criteria. 8709 sel_mask = chi2_list < SSall_fixed 8710 8711 # Select values of kex, and chi2_list 8712 kex_sel = kex_list[sel_mask] 8713 chi2_sel = chi2_list[sel_mask] 8714 8715 # Now make plot 8716 print(SSbest_kex, SSbest_fit, SSall_fixed) 8717 print(kex_sel) 8718 print(chi2_sel) 8719 8720 if True: 8721 import matplotlib.pyplot as plt 8722 8723 plt.plot(kex_sel, chi2_sel, "bo") 8724 plt.plot(SSbest_kex, SSbest_fit, "g*") 8725 plt.show()
8726 8727
8728 - def test_tp02_data_to_tp02(self):
8729 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8730 8731 # Fixed time variable. 8732 ds.fixed = True 8733 8734 # Execute the script. 8735 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') 8736 8737 # The original parameters. 8738 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8739 pA = 0.7654321 8740 kex = 1234.56789 8741 delta_omega = [7.0, 9.0] 8742 8743 # The R20 keys. 8744 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8745 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8746 8747 # Switch to the 'TP02' model data pipe, then check for each spin. 8748 self.interpreter.pipe.switch('TP02 - relax_disp') 8749 spin_index = 0 8750 for spin, spin_id in spin_loop(return_id=True): 8751 # Printout. 8752 print("\nSpin %s." % spin_id) 8753 8754 # Check the fitted parameters. 8755 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8756 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8757 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8758 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8759 8760 # Increment the spin index. 8761 spin_index += 1
8762 8763
8765 """System test of the value.write function to write intensities for an R1rho setup. 8766 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. 8767 8768 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 8769 """ 8770 8771 # Load the state. 8772 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8773 self.interpreter.state.load(statefile, force=True) 8774 8775 # Set filepaths. 8776 int_filepath = ds.tmpdir+sep+'int.out' 8777 8778 # Write out the intensity parameter file. 8779 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8780 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8781 8782 # Test the file exists. 8783 self.assert_(access(int_filepath, F_OK)) 8784 8785 # Open the files for testing. 8786 int_file = open(int_filepath, 'r') 8787 8788 # Loop over the intensity file to test values. 8789 for line in int_file: 8790 # Skip lines starting with #. 8791 if line[0] == "#": 8792 continue 8793 8794 # Split the line 8795 linesplit = line.split() 8796 8797 # Assume values 8798 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8799 self.assertEqual(linesplit[5], "115571.4") 8800 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8801 self.assertEqual(linesplit[5], "68377.52") 8802 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8803 self.assertEqual(linesplit[5], "9141.689") 8804 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8805 self.assertEqual(linesplit[5], "29123.77") 8806 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8807 self.assertEqual(linesplit[5], "58914.94") 8808 8809 # Close files 8810 int_file.close()
8811 8812
8814 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8815 8816 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 8817 """ 8818 8819 # Load the state. 8820 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8821 self.interpreter.state.load(statefile, force=True) 8822 8823 # Set filepaths. 8824 theta_filepath = ds.tmpdir+sep+'theta.out' 8825 8826 # Write out the theta parameter file. 8827 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 8828 8829 # Test the file exists. 8830 self.assert_(access(theta_filepath, F_OK)) 8831 8832 # Open the files for testing. 8833 theta_file = open(theta_filepath, 'r') 8834 8835 # Loop over the theta file to test values. 8836 for line in theta_file: 8837 # Skip lines starting with #. 8838 if line[0] == "#": 8839 continue 8840 # Print lines, not including newline character. 8841 print(line[:-1]) 8842 8843 # Split the line 8844 linesplit = line.split() 8845 8846 # Assume values 8847 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8848 self.assertNotEqual(linesplit[5], "None") 8849 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8850 self.assertNotEqual(linesplit[5], "None") 8851 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8852 self.assertNotEqual(linesplit[5], "None") 8853 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8854 self.assertNotEqual(linesplit[5], "None") 8855 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8856 self.assertNotEqual(linesplit[5], "None") 8857 8858 # Close files 8859 theta_file.close()
8860 8861
8863 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 8864 8865 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 8866 """ 8867 8868 # Load the state. 8869 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8870 self.interpreter.state.load(statefile, force=True) 8871 8872 # Set filepaths. 8873 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 8874 8875 # Write out the w_eff parameter file. 8876 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 8877 8878 # Test the file exists. 8879 self.assert_(access(w_eff_filepath, F_OK)) 8880 8881 # Open the files for testing. 8882 w_eff_file = open(w_eff_filepath, 'r') 8883 8884 # Loop over the w_eff file to test values. 8885 for line in w_eff_file: 8886 # Skip lines starting with #. 8887 if line[0] == "#": 8888 continue 8889 # Print lines, not including newline character. 8890 print(line[:-1]) 8891 8892 # Split the line 8893 linesplit = line.split() 8894 8895 # Assume values 8896 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8897 self.assertNotEqual(linesplit[5], "None") 8898 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8899 self.assertNotEqual(linesplit[5], "None") 8900 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8901 self.assertNotEqual(linesplit[5], "None") 8902 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8903 self.assertNotEqual(linesplit[5], "None") 8904 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8905 self.assertNotEqual(linesplit[5], "None") 8906 8907 # Close files 8908 w_eff_file.close()
8909 8910
8912 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 8913 8914 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}. 8915 """ 8916 8917 # Load the state. 8918 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 8919 self.interpreter.state.load(statefile, force=True) 8920 8921 # Set pipe name, bundle and type. 8922 pipe_name = 'base pipe' 8923 pipe_bundle = 'relax_disp' 8924 pipe_type = 'relax_disp' 8925 8926 # The path to the data files. 8927 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 8928 8929 # Deselect all spins 8930 self.interpreter.deselect.all() 8931 8932 # Specify spins to be selected. 8933 select_spin_ids = [ 8934 ":13@N", 8935 ":15@N", 8936 ":16@N", 8937 ":25@N", 8938 ":26@N", 8939 ":28@N", 8940 ":39@N", 8941 ":40@N", 8942 ":41@N", 8943 ":43@N", 8944 ":44@N", 8945 ":45@N", 8946 ":49@N", 8947 ":52@N", 8948 ":53@N"] 8949 8950 # Reverse the selection for the spins. 8951 for curspin in select_spin_ids: 8952 print("Selecting spin %s"%curspin) 8953 self.interpreter.deselect.reverse(spin_id=curspin) 8954 8955 # Read the R1 data 8956 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) 8957 8958 # The dispersion models. 8959 MODELS = ['R2eff'] 8960 8961 # The grid search size (the number of increments per dimension). 8962 GRID_INC = 4 8963 8964 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 8965 MC_NUM = 3 8966 8967 # Model selection technique. 8968 MODSEL = 'AIC' 8969 8970 # Execute the auto-analysis (fast). 8971 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8972 OPT_FUNC_TOL = 1e-1 8973 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 8974 OPT_MAX_ITERATIONS = 1000 8975 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 8976 8977 # Run the analysis. 8978 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) 8979 8980 ## Check for file creation 8981 # Set filepaths. 8982 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 8983 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 8984 8985 # Test the files exists. 8986 self.assert_(access(theta_filepath, F_OK)) 8987 self.assert_(access(w_eff_filepath, F_OK)) 8988 8989 # Open the files for testing. 8990 theta_file = open(theta_filepath, 'r') 8991 theta_result = [ 8992 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 8993 "#\n", 8994 "# 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", 8995 "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", 8996 "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", 8997 "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", 8998 "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", 8999 "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", 9000 "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", 9001 "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", 9002 "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", 9003 "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", 9004 "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", 9005 "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", 9006 "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", 9007 "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", 9008 "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", 9009 "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", 9010 "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", 9011 "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", 9012 "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", 9013 "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", 9014 "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", 9015 "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", 9016 "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", 9017 "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", 9018 "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", 9019 "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", 9020 "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", 9021 "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", 9022 "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", 9023 "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", 9024 "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", 9025 "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", 9026 "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", 9027 "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", 9028 "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", 9029 "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", 9030 "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", 9031 "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", 9032 "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", 9033 "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", 9034 "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", 9035 "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", 9036 "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", 9037 "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", 9038 "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", 9039 "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", 9040 "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", 9041 "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", 9042 "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" 9043 ] 9044 # Check the created theta file. 9045 lines = theta_file.readlines() 9046 for i in range(len(lines)): 9047 # Test lines starting with # 9048 if theta_result[i][0] == "#": 9049 self.assertEqual(theta_result[i], lines[i]) 9050 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9051 if theta_result[i] == lines[i]: 9052 self.assertEqual(theta_result[i], lines[i]) 9053 # If the line is not equal each other, make a slower comparison of values. 9054 else: 9055 # Print lines if they don't match. To help find differences. 9056 print(theta_result[i]) 9057 print(lines[i]) 9058 9059 # First test first 62 characters containing spin information 9060 self.assertEqual(theta_result[i][:62], lines[i][:62]) 9061 9062 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9063 theta_result_s = theta_result[i][62:].split()[::2] 9064 print(theta_result_s ) 9065 lines_s = lines[i][62:].split()[::2] 9066 print(lines_s) 9067 # Loop over the value elements 9068 for j in range(len(lines_s)): 9069 print(theta_result_s[j], lines_s[j]) 9070 # Assume a precision to digits. 9071 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 9072 9073 # Close file 9074 theta_file.close() 9075 9076 w_eff_file = open(w_eff_filepath, 'r') 9077 w_eff_result = [ 9078 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 9079 "#\n", 9080 "# 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", 9081 "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", 9082 "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", 9083 "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", 9084 "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", 9085 "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", 9086 "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", 9087 "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", 9088 "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", 9089 "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", 9090 "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", 9091 "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", 9092 "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", 9093 "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", 9094 "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", 9095 "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", 9096 "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", 9097 "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", 9098 "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", 9099 "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", 9100 "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", 9101 "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", 9102 "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", 9103 "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", 9104 "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", 9105 "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", 9106 "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", 9107 "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", 9108 "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", 9109 "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", 9110 "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", 9111 "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", 9112 "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", 9113 "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", 9114 "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", 9115 "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", 9116 "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", 9117 "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", 9118 "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", 9119 "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", 9120 "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", 9121 "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", 9122 "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", 9123 "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", 9124 "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", 9125 "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", 9126 "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", 9127 "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", 9128 "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" 9129 ] 9130 # Check the created w_eff file. 9131 lines = w_eff_file.readlines() 9132 for i in range(len(lines)): 9133 # Test lines starting with # 9134 if w_eff_result[i][0] == "#": 9135 self.assertEqual(w_eff_result[i], lines[i]) 9136 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9137 if w_eff_result[i] == lines[i]: 9138 self.assertEqual(w_eff_result[i], lines[i]) 9139 # If the line is not equal each other, make a slower comparison of values. 9140 else: 9141 # Print lines if they don't match. To help find differences. 9142 print(w_eff_result[i]) 9143 print(lines[i]) 9144 9145 # First test first 62 characters containing spin information 9146 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 9147 9148 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9149 w_eff_result_s = w_eff_result[i][62:].split()[::2] 9150 print(w_eff_result_s ) 9151 lines_s = lines[i][62:].split()[::2] 9152 print(lines_s) 9153 # Loop over the value elements 9154 for j in range(len(lines_s)): 9155 print(w_eff_result_s[j], lines_s[j]) 9156 # Assume a precision to digits. 9157 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 9158 9159 # Close file 9160 w_eff_file.close()
9161 9162
9164 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 9165 9166 This follows Task 7822. 9167 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. 9168 9169 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 9170 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 9171 """ 9172 9173 # Load the data. 9174 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 9175 9176 # Set pipe name, bundle and type. 9177 pipe_name = 'base pipe' 9178 pipe_bundle = 'relax_disp' 9179 pipe_type = 'relax_disp' 9180 9181 # Create the data pipe. 9182 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 9183 9184 file = data_path + '1_setup_r1rho_GUI.py' 9185 self.interpreter.script(file=file, dir=None) 9186 9187 # Deselect all spins. 9188 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 9189 9190 # Select one spin. 9191 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 9192 9193 # Set the model. 9194 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 9195 9196 # Check if intensity errors have already been calculated. 9197 check_intensity_errors() 9198 9199 # Do a grid search. 9200 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 9201 9202 # Set algorithm. 9203 min_algor = 'Newton' 9204 constraints = True 9205 if constraints: 9206 min_options = ('%s'%(min_algor),) 9207 #min_algor = 'Log barrier' 9208 min_algor = 'Method of Multipliers' 9209 scaling_matrix = assemble_scaling_matrix(scaling=True) 9210 9211 # Collect spins 9212 all_spin_ids = [] 9213 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9214 all_spin_ids.append(spin_id) 9215 9216 spins = spin_ids_to_containers(all_spin_ids[:1]) 9217 9218 # Get constraints 9219 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 9220 else: 9221 min_options = () 9222 A, b = None, None 9223 min_options = () 9224 sim_boot = 200 9225 scaling_list = [1.0, 1.0] 9226 9227 # Minimise. 9228 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 9229 9230 # Loop over old err attributes. 9231 err_attr_list = ['r2eff_err', 'i0_err'] 9232 9233 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9234 # Loop over old err attributes. 9235 for err_attr in err_attr_list: 9236 if hasattr(cur_spin, err_attr): 9237 delattr(cur_spin, err_attr) 9238 9239 # Collect the estimation data from boot. 9240 my_dic = {} 9241 param_key_list = [] 9242 est_keys = [] 9243 est_key = '-2' 9244 est_keys.append(est_key) 9245 spin_id_list = [] 9246 9247 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9248 # Add key to dic. 9249 my_dic[spin_id] = {} 9250 9251 # Add key for estimate. 9252 my_dic[spin_id][est_key] = {} 9253 9254 # Add spin key to list. 9255 spin_id_list.append(spin_id) 9256 9257 # Generate spin string. 9258 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9259 9260 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9261 # Generate the param_key. 9262 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9263 9264 # Append key. 9265 param_key_list.append(param_key) 9266 9267 # Add key to dic. 9268 my_dic[spin_id][est_key][param_key] = {} 9269 9270 values = [] 9271 errors = [] 9272 times = [] 9273 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 9274 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 9275 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 9276 times.append(time) 9277 9278 # Convert to numpy array. 9279 values = asarray(values) 9280 errors = asarray(errors) 9281 times = asarray(times) 9282 9283 r2eff = getattr(cur_spin, 'r2eff')[param_key] 9284 i0 = getattr(cur_spin, 'i0')[param_key] 9285 9286 R_m_sim_l = [] 9287 I0_m_sim_l = [] 9288 for j in range(sim_boot): 9289 if j in range(0, 100000, 100): 9290 print("Simulation %i"%j) 9291 # Start minimisation. 9292 9293 # Produce errors 9294 I_err = [] 9295 for j, error in enumerate(errors): 9296 I_error = gauss(values[j], error) 9297 I_err.append(I_error) 9298 # Convert to numpy array. 9299 I_err = asarray(I_err) 9300 9301 x0 = [r2eff, i0] 9302 model = Relax_fit_opt(num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 9303 9304 # Ref input. 9305 #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): 9306 # l=l, u=u, c=c, dc=dc, d2c=d2c 9307 # l: Lower bound constraint vector (l <= x <= u). 9308 # u: Upper bound constraint vector (l <= x <= u). 9309 # c: User supplied constraint function. 9310 # dc: User supplied constraint gradient function. 9311 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) 9312 9313 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 9314 R_m_sim_l.append(R_m_sim_j) 9315 I0_m_sim_l.append(I0_m_sim_j) 9316 9317 # Get stats on distribution. 9318 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 9319 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 9320 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 9321 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 9322 9323 # Estimate R2eff errors. 9324 self.interpreter.relax_disp.r2eff_err_estimate() 9325 9326 est_key = '-1' 9327 est_keys.append(est_key) 9328 9329 # Collect data. 9330 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9331 # Add key for estimate. 9332 my_dic[spin_id][est_key] = {} 9333 9334 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9335 # Generate the param_key. 9336 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9337 9338 # Add key to dic. 9339 my_dic[spin_id][est_key][param_key] = {} 9340 9341 # Get the value. 9342 # Loop over err attributes. 9343 for err_attr in err_attr_list: 9344 if hasattr(cur_spin, err_attr): 9345 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9346 else: 9347 get_err_attr = 0.0 9348 9349 # Save to dic. 9350 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9351 9352 9353 # Make Carlo Simulations number 9354 mc_number_list = list(range(0, 1000, 250)) 9355 9356 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'] 9357 9358 # Loop over the Monte Carlo simulations: 9359 for number in mc_number_list: 9360 # First delete old simulations. 9361 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9362 # Loop over old err attributes. 9363 for err_attr in err_attr_list: 9364 if hasattr(cur_spin, err_attr): 9365 delattr(cur_spin, err_attr) 9366 9367 # Loop over the simulated attributes. 9368 for sim_attr in sim_attr_list: 9369 if hasattr(cur_spin, sim_attr): 9370 delattr(cur_spin, sim_attr) 9371 9372 self.interpreter.monte_carlo.setup(number=number) 9373 self.interpreter.monte_carlo.create_data() 9374 self.interpreter.monte_carlo.initial_values() 9375 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 9376 self.interpreter.eliminate() 9377 self.interpreter.monte_carlo.error_analysis() 9378 9379 est_key = '%i'%number 9380 est_keys.append(est_key) 9381 9382 # Collect data. 9383 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9384 # Add key for estimate. 9385 my_dic[spin_id][est_key] = {} 9386 9387 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9388 # Generate the param_key. 9389 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9390 9391 # Add key to dic. 9392 my_dic[spin_id][est_key][param_key] = {} 9393 9394 # Get the value. 9395 # Loop over err attributes. 9396 for err_attr in err_attr_list: 9397 if hasattr(cur_spin, err_attr): 9398 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9399 else: 9400 get_err_attr = 0.0 9401 9402 # Save to dic. 9403 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9404 9405 # Set what to extract. 9406 err_attr = err_attr_list[0] 9407 9408 # Define list with text. 9409 text_list = [] 9410 9411 # Now loop through the data. 9412 for spin_id in spin_id_list: 9413 for est_key in est_keys: 9414 # Define list to pickup data. 9415 r2eff_err_list = [] 9416 9417 for param_key in param_key_list: 9418 # Get the value. 9419 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9420 9421 # Add to list. 9422 r2eff_err_list.append(r2eff_err) 9423 9424 # Sum the list 9425 sum_array = sum(array(r2eff_err_list)) 9426 9427 # Join floats to string. 9428 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9429 9430 # Define print string. 9431 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9432 text_list.append(text) 9433 9434 9435 # Now print. 9436 filepath = NamedTemporaryFile(delete=False).name 9437 # Open the files for testing. 9438 w_file = open(filepath, 'w') 9439 9440 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9441 9442 for text in text_list: 9443 # Print. 9444 print(text) 9445 9446 # Write to file. 9447 w_file.write(text+"\n") 9448 9449 # Close files 9450 w_file.close() 9451 9452 print("Filepath is: %s"%filepath) 9453 print("Start 'gnuplot' and write:") 9454 print("set term dumb") 9455 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9456 9457
9458 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9459 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9460 9461 # Check the kex value of residue 52 9462 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9463 9464 # Print results for each model. 9465 print("\n\n################") 9466 print("Printing results") 9467 print("################\n") 9468 for model in models: 9469 # Skip R2eff model. 9470 if model == MODEL_R2EFF: 9471 continue 9472 9473 # Switch to pipe. 9474 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9475 print("\nModel: %s" % (model)) 9476 9477 # Loop over the spins. 9478 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9479 # Generate spin string. 9480 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9481 9482 # Loop over the parameters. 9483 print("Optimised parameters for spin: %s" % (spin_string)) 9484 for param in cur_spin.params + ['chi2']: 9485 # Get the value. 9486 if param in ['r1', 'r2']: 9487 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9488 # Generate the R20 key. 9489 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9490 9491 # Get the value. 9492 value = getattr(cur_spin, param)[r20_key] 9493 9494 # Print value. 9495 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9496 9497 # Compare values. 9498 if spin_id == ':52@N': 9499 if param == 'r1': 9500 if model == MODEL_NOREX: 9501 if r2eff_estimate == 'direct': 9502 self.assertAlmostEqual(value, 1.46138805) 9503 elif r2eff_estimate == 'MC2000': 9504 self.assertAlmostEqual(value, 1.46328102) 9505 elif r2eff_estimate == 'chi2_pyt': 9506 self.assertAlmostEqual(value, 1.43820629) 9507 elif model == MODEL_DPL94: 9508 if r2eff_estimate == 'direct': 9509 self.assertAlmostEqual(value, 1.44845742) 9510 elif r2eff_estimate == 'MC2000': 9511 self.assertAlmostEqual(value, 1.45019848) 9512 elif r2eff_estimate == 'chi2_pyt': 9513 self.assertAlmostEqual(value, 1.44666512) 9514 elif model == MODEL_TP02: 9515 if r2eff_estimate == 'direct': 9516 self.assertAlmostEqual(value, 1.54354392) 9517 elif r2eff_estimate == 'MC2000': 9518 self.assertAlmostEqual(value, 1.54352369) 9519 elif r2eff_estimate == 'chi2_pyt': 9520 self.assertAlmostEqual(value, 1.55964020) 9521 elif model == MODEL_TAP03: 9522 if r2eff_estimate == 'direct': 9523 self.assertAlmostEqual(value, 1.54356410) 9524 elif r2eff_estimate == 'MC2000': 9525 self.assertAlmostEqual(value, 1.54354367) 9526 elif r2eff_estimate == 'chi2_pyt': 9527 self.assertAlmostEqual(value, 1.55967157) 9528 elif model == MODEL_MP05: 9529 if r2eff_estimate == 'direct': 9530 self.assertAlmostEqual(value, 1.54356416) 9531 elif r2eff_estimate == 'MC2000': 9532 self.assertAlmostEqual(value, 1.54354372) 9533 elif r2eff_estimate == 'chi2_pyt': 9534 self.assertAlmostEqual(value, 1.55967163) 9535 elif model == MODEL_NS_R1RHO_2SITE: 9536 if r2eff_estimate == 'direct': 9537 self.assertAlmostEqual(value, 1.41359221, 5) 9538 elif r2eff_estimate == 'MC2000': 9539 self.assertAlmostEqual(value, 1.41321968, 5) 9540 elif r2eff_estimate == 'chi2_pyt': 9541 self.assertAlmostEqual(value, 1.36303129, 5) 9542 9543 elif param == 'r2': 9544 if model == MODEL_NOREX: 9545 if r2eff_estimate == 'direct': 9546 self.assertAlmostEqual(value, 11.48392439) 9547 elif r2eff_estimate == 'MC2000': 9548 self.assertAlmostEqual(value, 11.48040934) 9549 elif r2eff_estimate == 'chi2_pyt': 9550 self.assertAlmostEqual(value, 11.47224488) 9551 elif model == MODEL_DPL94: 9552 if r2eff_estimate == 'direct': 9553 self.assertAlmostEqual(value, 10.15688372, 6) 9554 elif r2eff_estimate == 'MC2000': 9555 self.assertAlmostEqual(value, 10.16304887, 6) 9556 elif r2eff_estimate == 'chi2_pyt': 9557 self.assertAlmostEqual(value, 9.20037797, 6) 9558 elif model == MODEL_TP02: 9559 if r2eff_estimate == 'direct': 9560 self.assertAlmostEqual(value, 9.72654896, 6) 9561 elif r2eff_estimate == 'MC2000': 9562 self.assertAlmostEqual(value, 9.72772726, 6) 9563 elif r2eff_estimate == 'chi2_pyt': 9564 self.assertAlmostEqual(value, 9.53948340, 6) 9565 elif model == MODEL_TAP03: 9566 if r2eff_estimate == 'direct': 9567 self.assertAlmostEqual(value, 9.72641887, 6) 9568 elif r2eff_estimate == 'MC2000': 9569 self.assertAlmostEqual(value, 9.72759374, 6) 9570 elif r2eff_estimate == 'chi2_pyt': 9571 self.assertAlmostEqual(value, 9.53926913, 6) 9572 elif model == MODEL_MP05: 9573 if r2eff_estimate == 'direct': 9574 self.assertAlmostEqual(value, 9.72641723, 6) 9575 elif r2eff_estimate == 'MC2000': 9576 self.assertAlmostEqual(value, 9.72759220, 6) 9577 elif r2eff_estimate == 'chi2_pyt': 9578 self.assertAlmostEqual(value, 9.53926778, 6) 9579 elif model == MODEL_NS_R1RHO_2SITE: 9580 if r2eff_estimate == 'direct': 9581 self.assertAlmostEqual(value, 9.34531535, 5) 9582 elif r2eff_estimate == 'MC2000': 9583 self.assertAlmostEqual(value, 9.34602793, 5) 9584 elif r2eff_estimate == 'chi2_pyt': 9585 self.assertAlmostEqual(value, 9.17631409, 5) 9586 9587 # For all other parameters. 9588 else: 9589 # Get the value. 9590 value = getattr(cur_spin, param) 9591 9592 # Print value. 9593 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9594 9595 # Compare values. 9596 if spin_id == ':52@N': 9597 if param == 'phi_ex': 9598 if model == MODEL_DPL94: 9599 if r2eff_estimate == 'direct': 9600 self.assertAlmostEqual(value, 0.07599563) 9601 elif r2eff_estimate == 'MC2000': 9602 self.assertAlmostEqual(value, 0.07561937) 9603 elif r2eff_estimate == 'chi2_pyt': 9604 self.assertAlmostEqual(value, 0.12946061) 9605 9606 elif param == 'pA': 9607 if model == MODEL_TP02: 9608 if r2eff_estimate == 'direct': 9609 self.assertAlmostEqual(value, 0.88827040) 9610 elif r2eff_estimate == 'MC2000': 9611 self.assertAlmostEqual(value, 0.88807487) 9612 elif r2eff_estimate == 'chi2_pyt': 9613 self.assertAlmostEqual(value, 0.87746233) 9614 elif model == MODEL_TAP03: 9615 if r2eff_estimate == 'direct': 9616 self.assertAlmostEqual(value, 0.88828922) 9617 elif r2eff_estimate == 'MC2000': 9618 self.assertAlmostEqual(value, 0.88809318) 9619 elif r2eff_estimate == 'chi2_pyt': 9620 self.assertAlmostEqual(value, 0.87747558) 9621 elif model == MODEL_MP05: 9622 if r2eff_estimate == 'direct': 9623 self.assertAlmostEqual(value, 0.88828924, 6) 9624 elif r2eff_estimate == 'MC2000': 9625 self.assertAlmostEqual(value, 0.88809321) 9626 elif r2eff_estimate == 'chi2_pyt': 9627 self.assertAlmostEqual(value, 0.87747562) 9628 elif model == MODEL_NS_R1RHO_2SITE: 9629 if r2eff_estimate == 'direct': 9630 self.assertAlmostEqual(value, 0.94504369, 6) 9631 elif r2eff_estimate == 'MC2000': 9632 self.assertAlmostEqual(value, 0.94496541, 6) 9633 elif r2eff_estimate == 'chi2_pyt': 9634 self.assertAlmostEqual(value, 0.92084707, 6) 9635 9636 elif param == 'dw': 9637 if model == MODEL_TP02: 9638 if r2eff_estimate == 'direct': 9639 self.assertAlmostEqual(value, 1.08875840, 6) 9640 elif r2eff_estimate == 'MC2000': 9641 self.assertAlmostEqual(value, 1.08765638, 6) 9642 elif r2eff_estimate == 'chi2_pyt': 9643 self.assertAlmostEqual(value, 1.09753230, 6) 9644 elif model == MODEL_TAP03: 9645 if r2eff_estimate == 'direct': 9646 self.assertAlmostEqual(value, 1.08837238, 6) 9647 elif r2eff_estimate == 'MC2000': 9648 self.assertAlmostEqual(value, 1.08726698, 6) 9649 elif r2eff_estimate == 'chi2_pyt': 9650 self.assertAlmostEqual(value, 1.09708821, 6) 9651 elif model == MODEL_MP05: 9652 if r2eff_estimate == 'direct': 9653 self.assertAlmostEqual(value, 1.08837241, 6) 9654 elif r2eff_estimate == 'MC2000': 9655 self.assertAlmostEqual(value, 1.08726706, 6) 9656 elif r2eff_estimate == 'chi2_pyt': 9657 self.assertAlmostEqual(value, 1.09708832, 6) 9658 elif model == MODEL_NS_R1RHO_2SITE: 9659 if r2eff_estimate == 'direct': 9660 self.assertAlmostEqual(value, 1.56001812, 5) 9661 elif r2eff_estimate == 'MC2000': 9662 self.assertAlmostEqual(value, 1.55833321, 5) 9663 elif r2eff_estimate == 'chi2_pyt': 9664 self.assertAlmostEqual(value, 1.36406712, 5) 9665 9666 elif param == 'kex': 9667 if model == MODEL_DPL94: 9668 if r2eff_estimate == 'direct': 9669 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9670 elif r2eff_estimate == 'MC2000': 9671 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9672 elif r2eff_estimate == 'chi2_pyt': 9673 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9674 elif model == MODEL_TP02: 9675 if r2eff_estimate == 'direct': 9676 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9677 elif r2eff_estimate == 'MC2000': 9678 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9679 elif r2eff_estimate == 'chi2_pyt': 9680 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9681 elif model == MODEL_TAP03: 9682 if r2eff_estimate == 'direct': 9683 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9684 elif r2eff_estimate == 'MC2000': 9685 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9686 elif r2eff_estimate == 'chi2_pyt': 9687 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9688 elif model == MODEL_MP05: 9689 if r2eff_estimate == 'direct': 9690 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9691 elif r2eff_estimate == 'MC2000': 9692 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9693 elif r2eff_estimate == 'chi2_pyt': 9694 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9695 elif model == MODEL_NS_R1RHO_2SITE: 9696 if r2eff_estimate == 'direct': 9697 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9698 elif r2eff_estimate == 'MC2000': 9699 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9700 elif r2eff_estimate == 'chi2_pyt': 9701 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9702 9703 elif param == 'chi2': 9704 if model == MODEL_NOREX: 9705 if r2eff_estimate == 'direct': 9706 self.assertAlmostEqual(value, 848.42016907, 5) 9707 elif r2eff_estimate == 'MC2000': 9708 self.assertAlmostEqual(value, 3363.95829122, 5) 9709 elif r2eff_estimate == 'chi2_pyt': 9710 self.assertAlmostEqual(value, 5976.49946726, 5) 9711 elif model == MODEL_DPL94: 9712 if r2eff_estimate == 'direct': 9713 self.assertAlmostEqual(value, 179.47041241) 9714 elif r2eff_estimate == 'MC2000': 9715 self.assertAlmostEqual(value, 710.24767560) 9716 elif r2eff_estimate == 'chi2_pyt': 9717 self.assertAlmostEqual(value, 612.72616697, 5) 9718 elif model == MODEL_TP02: 9719 if r2eff_estimate == 'direct': 9720 self.assertAlmostEqual(value, 29.33882530, 6) 9721 elif r2eff_estimate == 'MC2000': 9722 self.assertAlmostEqual(value, 114.47142772, 6) 9723 elif r2eff_estimate == 'chi2_pyt': 9724 self.assertAlmostEqual(value, 250.50838162, 5) 9725 elif model == MODEL_TAP03: 9726 if r2eff_estimate == 'direct': 9727 self.assertAlmostEqual(value, 29.29050673, 6) 9728 elif r2eff_estimate == 'MC2000': 9729 self.assertAlmostEqual(value, 114.27987534) 9730 elif r2eff_estimate == 'chi2_pyt': 9731 self.assertAlmostEqual(value, 250.04050719, 5) 9732 elif model == MODEL_MP05: 9733 if r2eff_estimate == 'direct': 9734 self.assertAlmostEqual(value, 29.29054301, 6) 9735 elif r2eff_estimate == 'MC2000': 9736 self.assertAlmostEqual(value, 114.28002272) 9737 elif r2eff_estimate == 'chi2_pyt': 9738 self.assertAlmostEqual(value, 250.04077478, 5) 9739 elif model == MODEL_NS_R1RHO_2SITE: 9740 if r2eff_estimate == 'direct': 9741 self.assertAlmostEqual(value, 34.44010543, 6) 9742 elif r2eff_estimate == 'MC2000': 9743 self.assertAlmostEqual(value, 134.14368365) 9744 elif r2eff_estimate == 'chi2_pyt': 9745 self.assertAlmostEqual(value, 278.55121388, 5) 9746 9747 9748 # Print the final pipe. 9749 model = 'final' 9750 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9751 print("\nFinal pipe") 9752 9753 # Loop over the spins. 9754 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9755 # Generate spin string. 9756 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9757 9758 # Loop over the parameters. 9759 print("Optimised model for spin: %s" % (spin_string)) 9760 param = 'model' 9761 9762 # Get the value. 9763 value = getattr(cur_spin, param) 9764 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9765 9766 9767 ### Now check some of the written out files. 9768 file_names = ['r1rho_prime', 'r1'] 9769 9770 for file_name_i in file_names: 9771 9772 # Make the file name. 9773 file_name = "%s.out" % file_name_i 9774 9775 # Get the file path. 9776 file_path = get_file_path(file_name, result_dir_name + sep + model) 9777 9778 # Test the file exists. 9779 print("Testing file access to: %s"%file_path) 9780 self.assert_(access(file_path, F_OK)) 9781 9782 # Now open, and compare content, line by line. 9783 file_prod = open(file_path) 9784 lines_prod = file_prod.readlines() 9785 file_prod.close() 9786 9787 # Loop over the lines. 9788 for i, line in enumerate(lines_prod): 9789 # Make the string test 9790 line_split = line.split() 9791 9792 # Continue for comment lines. 9793 if line_split[0] == "#": 9794 print(line), 9795 continue 9796 9797 # Assign the split of the line. 9798 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9799 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9800 9801 if res_num == '52': 9802 # Assert that the value is not None. 9803 self.assertNotEqual(val, 'None')
9804