1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 from os import F_OK, access, getcwd, path, sep
26 import copy
27 from numpy import array, asarray, average, exp, median, inf, isnan, linspace, log, std, sum, zeros
28 from minfx.generic import generic_minimise
29 from random import gauss
30 import re, math
31 from tempfile import mkdtemp, NamedTemporaryFile
32
33
34
35 from auto_analyses import relax_disp
36 from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep
37 from data_store import Relax_data_store; ds = Relax_data_store()
38 import dep_check
39 from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_FULL, MODEL_LM63, MODEL_M61, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03
40 from lib.errors import RelaxError
41 from lib.io import extract_data, get_file_path
42 from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file
43 from pipe_control.mol_res_spin import generate_spin_string, return_spin, spin_loop
44 from pipe_control.minimise import assemble_scaling_matrix
45 from specific_analyses.relax_disp.checks import check_missing_r1
46 from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff
47 from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_spectrum_ids, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers
48 from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF
49 from specific_analyses.relax_disp.model import models_info, nesting_param
50 from specific_analyses.relax_disp.parameters import linear_constraints
51 from status import Status; status = Status()
52 from target_functions.relax_fit_wrapper import Relax_fit_opt
53 from test_suite.system_tests.base_classes import SystemTestCase
54
55
57 """Class for testing various aspects specific to relaxation dispersion curve-fitting."""
58
59 - def __init__(self, methodName='runTest'):
60 """Skip certain tests if the C modules are non-functional.
61
62 @keyword methodName: The name of the test.
63 @type methodName: str
64 """
65
66
67 super(Relax_disp, self).__init__(methodName)
68
69
70 blacklist = [
71 'test_m61b_data_to_m61b'
72 ]
73 if methodName in blacklist:
74 status.skipped_tests.append([methodName, None, self._skip_type])
75
76
77 if not dep_check.C_module_exp_fn:
78
79 to_skip = [
80 "test_bug_atul_srivastava",
81 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp",
82 "test_bug_24601_r2eff_missing_data",
83 "test_bug_9999_slow_r1rho_r2eff_error_with_mc",
84 "test_estimate_r2eff_err",
85 "test_estimate_r2eff_err_auto",
86 "test_estimate_r2eff_err_methods",
87 "test_finite_value",
88 "test_exp_fit",
89 "test_m61_exp_data_to_m61",
90 "test_r1rho_kjaergaard_auto",
91 "test_r1rho_kjaergaard_auto_check_graphs",
92 "test_r1rho_kjaergaard_man",
93 "test_r1rho_kjaergaard_missing_r1",
94 "test_value_write_calc_rotating_frame_params_auto_analysis"
95 ]
96
97
98 if methodName in to_skip:
99 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type])
100
101
102 if not dep_check.scipy_module:
103
104 to_skip = [
105 "test_estimate_r2eff_err_methods",
106 "test_paul_schanda_nov_2015",
107 ]
108
109
110 if methodName in to_skip:
111 status.skipped_tests.append([methodName, 'Scipy', self._skip_type])
112
113
114 if not dep_check.showApod_software:
115
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
124 if methodName in to_skip:
125 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type])
126
127
128 if not dep_check.matplotlib_module:
129
130 to_skip = [
131 "test_repeat_cpmg"
132 ]
133
134
135 if methodName in to_skip:
136 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
137
138
140 """Set up for all the functional tests."""
141
142
143 self.interpreter.pipe.create('relax_disp', 'relax_disp')
144
145
146 ds.tmpdir = mkdtemp()
147 self.tmpdir = ds.tmpdir
148
149
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
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
165
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
171
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
180
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
189
190 r2eff_errs_3 = [0.0] * len(ncycs_3)
191 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3]
192
193
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
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
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
219 self.interpreter.spin.isotope('15N', spin_id='@N')
220
221
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
235 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq)
236
237
238 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ)
239
240
241 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2)
242
243
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
249
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
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
262 for res_name, res_num, spin_name, params in spins:
263 cur_spin_id = ":%i@%s"%(res_num, spin_name)
264
265
266 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_'))
267
268
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
272 self.interpreter.relax_disp.select_model(model=model_analyse)
273
274
275 self.interpreter.relax_disp.cluster('model_cluster', ":1-100")
276
277
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
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(spin_id=cur_spin_id)
286
287 for mo_param in cur_spin.params:
288 print(mo_param)
289
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
302
303 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
304
305
307 """Set up the data for the test_r1rho_kjaergaard_*() system tests."""
308
309
310 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'
311
312
313 ds.pipe_name = 'base pipe'
314 ds.pipe_bundle = 'relax_disp'
315 ds.pipe_type = 'relax_disp'
316
317
318 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type)
319
320
321 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists')
322
323
324 self.interpreter.spin.isotope(isotope='15N')
325
326
327 NR_exp = 70
328
329
330 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r')
331 expfileslines = expfile.readlines()[:NR_exp]
332 expfile.close()
333
334
335 yOBS = 81.050
336
337 yCAR = 118.078
338 centerPPM_N15 = yCAR
339
340
341 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists')
342
343
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
347
348 j = 0
349 for i in range(len(expfileslines)):
350 line = expfileslines[i]
351 if line[0] == "#":
352 continue
353 else:
354
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
367 time_sl = 2*ncyc*trim
368
369
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
374 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height')
375
376
377 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id)
378
379
380 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho')
381
382
383 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength)
384
385
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
391 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm)
392
393
394 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl)
395
396
397 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz')
398
399
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
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
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
421
422
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
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
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
503
504
532
533
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
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
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
561 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True)
562
563
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
592 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data:
593
594 if data_type not in data_list:
595 continue
596
597
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
612 for cpmg_frq in cpmg_frqs:
613
614 new_id = "%s_%s" % (id, cpmg_frq)
615
616
617 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq)
618
619
620 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type)
621
622
623 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time)
624
625
626 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq)
627
628
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
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
646 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25'
647
648
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
654 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type)
655
656
657 id_lists = []
658 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps:
659
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
664 id_list = list(key+str(i) for i in range(len(ncycs)))
665 id_lists.append(id_list)
666
667
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
671 for i in range(len(ncycs)):
672 ncyc = ncycs[i]
673 vcpmg = ncyc/time_T2
674
675
676 if float(vcpmg) == 0.0:
677 vcpmg = None
678 else:
679 vcpmg = round(float(vcpmg), 3)
680
681
682 current_id = id_list[i]
683
684
685 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG')
686
687
688 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz')
689
690
691 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2)
692
693
694 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg)
695
696
697 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5])
698 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5])
699
700
701 self.interpreter.spectrum.error_analysis(subset=id_lists[0])
702 self.interpreter.spectrum.error_analysis(subset=id_lists[1])
703
704
705 self.interpreter.spin.isotope(isotope='15N')
706
707
708
709
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
718 self.assertEqual(64, len(glob_assn ))
719
720
721
722 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)")
723
724
725 relax_glob_ids = []
726
727
728 for assn in glob_assn:
729
730 m = r.match(assn)
731
732 relax_string = ":%s@%s"%(m.group(2), m.group(3))
733
734
735 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string])
736
737
738
739
740 self.interpreter.deselect.all()
741
742
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
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
753 MODEL = "R2eff"
754 self.interpreter.relax_disp.select_model(model=MODEL)
755
756 self.interpreter.minimise.calculate(verbosity=1)
757
758
760 """Function for setting up a few spins for the given pipe."""
761
762
763 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'
764
765
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
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
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
790 """This setup the truncated private data which was provided by Paul Schanda."""
791
792
793 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Paul_Schanda_2015_Nov'
794 file = data_path + sep + '1_prepare_data.py'
795
796
797 status.outdir = outdir
798
799
800 self.interpreter.script(file=file, dir=None)
801
802
804 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data."""
805
806
807 self.interpreter.reset()
808
809
810 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02'
811 self.interpreter.state.load(data_path+sep+'r2eff_values')
812
813
814 model = 'NS R1rho 2-site'
815 pipe_name = "%s - relax_disp" % model
816 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp')
817 self.interpreter.pipe.switch(pipe_name=pipe_name)
818
819
820 self.interpreter.relax_disp.select_model(model=model)
821
822
823 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
824
825
826 spin1 = cdp.mol[0].res[0].spin[0]
827 spin2 = cdp.mol[0].res[1].spin[0]
828
829
830 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
831 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
832
833
834 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684}
835 spin1.pA = 0.779782428085762
836 spin1.dw = 7.57855284496424
837 spin1.kex = 1116.7911285203
838 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337}
839 spin2.pA = 0.826666229688602
840 spin2.dw = 9.5732624231366
841 spin2.kex = 1380.46162655657
842
843
844 if clustering:
845 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100")
846
847
848 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)
849
850
851 print("\n\nOptimised parameters:\n")
852 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)"))
853 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1]))
854 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2]))
855 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA))
856 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw))
857 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex))
858 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
859
860
862 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed.
863
864 Support requst sr #3154 U{https://web.archive.org/web/https://gna.org/support/index.php?3154}.
865
866 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.
867 """
868
869
870 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014'
871
872
873 pipe_name = 'base pipe'
874 pipe_type = 'relax_disp'
875 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
876
877
878 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type)
879
880
881 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H')
882
883
884 self.interpreter.spin.isotope('1H', spin_id='@H')
885
886
887
888 ncycs = [2, 4, 8, 10, 20, 40, 500]
889 ids = []
890 for ncyc in ncycs:
891 ids.append('CPMG_%s' % ncyc)
892
893 print("\n\nThe experiment IDs are %s." % ids)
894
895
896
897 sfrq = 200. * 1E6
898
899
900 Trelax = 0.04
901
902
903 for i in range(len(ids)):
904 id = ids[i]
905
906 self.interpreter.spectrometer.frequency(id=id, frq=sfrq)
907
908
909 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG')
910
911
912 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax)
913
914
915 ncyc = ncycs[i]
916 nu_cpmg = ncyc / Trelax
917 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg)
918
919
920 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff)
921 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff)
922
923
924 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)
925
926
927 data = [
928 ['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}],
929 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ],
930 ['dispersion_points', len(ncycs)],
931 ['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'}],
932 ['exp_type_list', ['SQ CPMG']],
933 ['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}],
934 ['spectrometer_frq_count', 1],
935 ['spectrometer_frq_list', [sfrq]],
936 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']]
937 ]
938 for name, value in data:
939
940 self.assertTrue(hasattr(cdp, name))
941
942
943 obj = getattr(cdp, name)
944 if not isinstance(data, dict):
945 self.assertEqual(obj, value)
946
947
948 else:
949 for id in ids:
950 self.assertEqual(obj[id], value[id])
951
952
953 n_data = [
954 [ 50.000000, 10.367900, 0.1],
955 [ 100.000000, 10.146849, 0.1],
956 [ 200.000000, 9.765987, 0.1],
957 [ 250.000000, 9.409789, 0.1],
958 [ 500.000000, 5.829819, 0.1],
959 [ 1000.000000, 3.191928, 0.1],
960 [ 12500.000000, 2.008231, 0.1]
961 ]
962 for disp_point, value, error in n_data:
963 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point
964 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value)
965 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error)
966
967
968 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq)
969
970
971 MODEL = "B14"
972
973
974 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL)
975 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
976 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
977
978
979 self.interpreter.relax_disp.select_model(model=MODEL)
980
981
982 grid_results = []
983 mini_results = []
984
985
986
987
988 GRID = 13
989
990 if GRID:
991
992
993 self.interpreter.relax_disp.r20_from_min_r2eff(force=False)
994
995
996 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1)
997
998
999 else:
1000 for param in MODEL_PARAMS[MODEL]:
1001 self.interpreter.value.set(param=param, index=None)
1002
1003 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1)
1004
1005
1006 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1007 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
1008
1009
1010
1011 set_func_tol = 1e-10
1012 set_max_iter = 1000
1013 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
1014
1015
1016 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1017 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
1018
1019
1020 for i in range(len(grid_results)):
1021 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i]
1022 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i]
1023 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))
1024 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))
1025
1026
1027
1028 kex = 1000.
1029
1030 pb = 0.01
1031
1032 dw_ppm = 2.
1033
1034 R2g = 2.
1035
1036 R2e = 2.
1037
1038
1039
1040 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6)
1041
1042 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6)
1043 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8)
1044 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1045
1046
1048 """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}.
1049
1050 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>}.
1051 """
1052
1053
1054 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014'
1055
1056
1057 pipe_name = 'base pipe'
1058 pipe_type = 'relax_disp'
1059 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
1060
1061
1062 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type)
1063
1064
1065
1066 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H')
1067
1068
1069 self.interpreter.spin.isotope('1H', spin_id='@H')
1070
1071
1072
1073 ncycs = [2, 4, 8, 10, 20, 40, 500]
1074 ids = []
1075 for ncyc in ncycs:
1076 ids.append('CPMG_%s' % ncyc)
1077
1078 print("\n\nThe experiment IDs are %s." % ids)
1079
1080
1081
1082 sfrq = 200. * 1E6
1083
1084
1085 Trelax = 0.04
1086
1087
1088 for i in range(len(ids)):
1089 id = ids[i]
1090
1091 self.interpreter.spectrometer.frequency(id=id, frq=sfrq)
1092
1093
1094 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG')
1095
1096
1097 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax)
1098
1099
1100 ncyc = ncycs[i]
1101 nu_cpmg = ncyc / Trelax
1102 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg)
1103
1104
1105 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff)
1106 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff)
1107
1108
1109 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)
1110
1111
1112 data = [
1113 ['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}],
1114 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ],
1115 ['dispersion_points', len(ncycs)],
1116 ['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'}],
1117 ['exp_type_list', ['SQ CPMG']],
1118 ['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}],
1119 ['spectrometer_frq_count', 1],
1120 ['spectrometer_frq_list', [sfrq]],
1121 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']]
1122 ]
1123 for name, value in data:
1124
1125 self.assertTrue(hasattr(cdp, name))
1126
1127
1128 obj = getattr(cdp, name)
1129 if not isinstance(data, dict):
1130 self.assertEqual(obj, value)
1131
1132
1133 else:
1134 for id in ids:
1135 self.assertEqual(obj[id], value[id])
1136
1137
1138 n_data = [
1139 [ 50.000000, 10.286255, 0.1],
1140 [ 100.000000, 10.073083, 0.1],
1141 [ 200.000000, 9.692746, 0.1],
1142 [ 250.000000, 9.382441, 0.1],
1143 [ 500.000000, 6.312396, 0.1],
1144 [ 1000.000000, 3.957029, 0.1],
1145 [ 12500.000000, 2.880420, 0.1]
1146 ]
1147 for disp_point, value, error in n_data:
1148 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point
1149 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value)
1150 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error)
1151
1152
1153 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq)
1154
1155
1156 MODEL = "B14 full"
1157
1158
1159 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL)
1160 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
1161 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
1162
1163
1164 self.interpreter.relax_disp.select_model(model=MODEL)
1165
1166
1167 grid_results = []
1168 mini_results = []
1169 clust_results = []
1170
1171
1172
1173
1174 GRID = 13
1175
1176 if GRID:
1177
1178
1179 self.interpreter.relax_disp.r20_from_min_r2eff(force=False)
1180
1181
1182 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1)
1183
1184
1185 else:
1186 for param in MODEL_PARAMS[MODEL]:
1187 self.interpreter.value.set(param=param, index=None)
1188
1189 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1)
1190
1191
1192 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1193 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
1194
1195
1196
1197 set_func_tol = 1e-11
1198 set_max_iter = 10000
1199 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
1200
1201
1202 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1203 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn])
1204
1205 print("\n# Now print before and after minimisation-\n")
1206
1207
1208 for i in range(len(grid_results)):
1209 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i]
1210 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i]
1211 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))
1212 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))
1213
1214
1215
1216 kex = 1000.
1217
1218 pb = 0.01
1219
1220 dw_ppm = 2.
1221
1222 R2g = 2.
1223
1224 R2e = 100.
1225
1226
1227
1228 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3)
1229 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3)
1230
1231 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6)
1232 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6)
1233 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1234
1235
1237 """U{Task #7858: <https://web.archive.org/web/https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB.
1238 This uses CPMG data from:
1239 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE.
1240 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations.
1241 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886
1242 """
1243
1244
1245 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011'
1246
1247
1248 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins')
1249
1250
1251 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False)
1252
1253
1254 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True)
1255 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False)
1256
1257 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1258 print(spin_id)
1259 if resn == 'C':
1260 print(resi, resn)
1261
1262
1263
1264 self.interpreter.bmrb.thiol_state(state='not reported')
1265
1266
1267
1268
1269 self.interpreter.bmrb.display()
1270
1271
1273 """U{Bug #21081<https://web.archive.org/web/https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected."""
1274
1275
1276 self.interpreter.reset()
1277
1278
1279 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2'
1280 self.interpreter.state.load(state, force=True)
1281
1282
1283 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1284
1285
1287 """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."""
1288
1289
1290 self.interpreter.reset()
1291
1292
1293 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2'
1294 self.interpreter.state.load(state, force=True)
1295
1296
1297 relax_disp.Relax_disp.opt_func_tol = 1e-5
1298 relax_disp.Relax_disp.opt_max_iterations = 1000
1299 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)
1300
1301
1303 """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."""
1304
1305
1306 self.interpreter.reset()
1307
1308
1309 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
1310 self.interpreter.state.load(state, force=True)
1311
1312
1313 relax_disp.Relax_disp.opt_func_tol = 1e-5
1314 relax_disp.Relax_disp.opt_max_iterations = 1000
1315 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)
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 minimise.calculate()."""
1320
1321
1322 self.interpreter.reset()
1323
1324
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
1329 self.interpreter.minimise.calculate(verbosity=1)
1330
1331
1333 """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."""
1334
1335
1336 self.interpreter.reset()
1337
1338
1339 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2'
1340 self.interpreter.state.load(state, force=True)
1341
1342
1343 relax_disp.Relax_disp.opt_func_tol = 1e-5
1344 relax_disp.Relax_disp.opt_max_iterations = 1000
1345 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)
1346
1347
1349 """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."""
1350
1351
1352 self.interpreter.reset()
1353
1354
1355 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2'
1356 self.interpreter.state.load(state, force=True)
1357
1358
1359 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered'
1360 relax_disp.Relax_disp.opt_func_tol = 1e-5
1361 relax_disp.Relax_disp.opt_max_iterations = 1000
1362 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)
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 B14 full analysis."""
1367
1368
1369 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_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 CR72 full analysis."""
1374
1375
1376 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1377
1378
1384
1385
1391
1392
1394 """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."""
1395
1396
1397 self.interpreter.reset()
1398
1399
1400 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'
1401 self.interpreter.state.load(state, force=True)
1402
1403 param = 'k_AB'
1404
1405 for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
1406 print(spin_id, spin.params)
1407 if param in spin.params:
1408 print(spin_id, spin.k_AB, spin.k_AB_err)
1409
1410
1411 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True)
1412
1413
1414
1415 param = 'r2'
1416 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True)
1417
1418 file = open(self.tmpdir+sep+'%s.out'%param)
1419 lines = file.readlines()
1420 file.close()
1421
1422 for i, line in enumerate(lines):
1423
1424 line_split = line.split()
1425 print(line_split)
1426
1427 if len(line_split) > 1:
1428
1429 if line_split[0] == "#" and line_split[1] == 'mol_name':
1430 nr_split_header = len(line_split)
1431 nr_split_header_i = i
1432 break
1433
1434
1435 line_split_val = lines[nr_split_header_i + 1].split()
1436 print(line_split_val)
1437
1438
1439 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1440
1441
1442 param = 'r2eff'
1443 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True)
1444
1445 file = open(self.tmpdir+sep+'%s.out'%param)
1446 lines = file.readlines()
1447 file.close()
1448
1449 for i, line in enumerate(lines):
1450
1451 line_split = line.split()
1452 print(line_split)
1453
1454 if len(line_split) > 1:
1455
1456 if line_split[0] == "#" and line_split[1] == 'mol_name':
1457 nr_split_header = len(line_split)
1458 nr_split_header_i = i
1459 break
1460
1461
1462 line_split_val = lines[nr_split_header_i + 1].split()
1463 print(line_split_val)
1464
1465
1466 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1467
1468
1470 """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."""
1471
1472
1473 self.interpreter.reset()
1474
1475
1476 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_23186.bz2'
1477 self.interpreter.state.load(state, force=True)
1478
1479
1480 dickey = 'SQ CPMG - 599.89086220 MHz'
1481
1482
1483 resi_0_r2a = []
1484
1485
1486 res0 = cdp.mol[0].res[0].spin[0]
1487 res1 = cdp.mol[0].res[1].spin[0]
1488
1489 print("Chi2 before call to minimise: %3.3f"%res0.chi2)
1490 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000, verbosity=0)
1491 print("Chi2 after call to minimise: %3.3f"%res0.chi2)
1492
1493
1494 for cdic in res0.r2a_sim:
1495 resi_0_r2a.append(cdic[dickey])
1496
1497
1498 resi_0_r2a_std = std(asarray(resi_0_r2a), ddof=1)
1499
1500
1501 resi_86_r2a = []
1502
1503
1504 for cdic in res1.r2a_sim:
1505 resi_86_r2a.append(cdic[dickey])
1506
1507
1508 resi_86_r2a_std = std(asarray(resi_86_r2a), ddof=1)
1509
1510
1511
1512
1513 resi_0_dw = res0.dw_sim
1514 resi_86_dw = res1.dw_sim
1515
1516
1517 resi_0_dw_std = std(asarray(resi_0_dw), ddof=1)
1518 resi_86_dw_std = std(asarray(resi_86_dw), ddof=1)
1519
1520
1521
1522
1523 resi_0_kAB = res0.k_AB_sim
1524 resi_86_kAB = res1.k_AB_sim
1525
1526
1527 resi_0_kAB_std = std(asarray(resi_0_kAB), ddof=1)
1528 resi_86_kAB_std = std(asarray(resi_0_kAB), ddof=1)
1529
1530
1531 self.assertEqual(resi_0_kAB_std, resi_86_kAB_std)
1532
1533
1534 self.interpreter.monte_carlo.error_analysis()
1535
1536
1537 self.assertAlmostEqual(resi_0_kAB_std, res0.k_AB_err)
1538 self.assertAlmostEqual(resi_86_kAB_std, res1.k_AB_err)
1539
1540
1541 self.assertAlmostEqual(resi_0_r2a_std, res0.r2a_err[dickey])
1542 self.assertAlmostEqual(resi_86_r2a_std, res1.r2a_err[dickey])
1543
1544
1545 self.assertAlmostEqual(resi_0_dw_std, res0.dw_err)
1546 self.assertAlmostEqual(resi_86_dw_std, res1.dw_err)
1547
1548
1549
1550
1551
1552 self.interpreter.monte_carlo.setup(number=3)
1553 self.interpreter.monte_carlo.create_data(method='back_calc')
1554 self.interpreter.monte_carlo.initial_values()
1555
1556
1557 res0.r2eff_sim[0] = copy.copy(res0.r2eff)
1558 res0.r2eff_sim[1] = copy.copy(res0.r2eff)
1559 res0.r2eff_sim[2] = copy.copy(res0.r2eff)
1560 res1.r2eff_sim[0] = copy.copy(res1.r2eff)
1561 res1.r2eff_sim[1] = copy.copy(res1.r2eff)
1562 res1.r2eff_sim[2] = copy.copy(res1.r2eff)
1563
1564 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000)
1565 self.interpreter.monte_carlo.error_analysis()
1566
1567
1568 spin_chi2_mc = res0.chi2
1569 spin_chi2_mc_sim = res0.chi2_sim
1570 spin_chi2_mc_sim_ave = average(spin_chi2_mc_sim)
1571
1572 print("The chi2 from calculation is: %3.3f"%spin_chi2_mc)
1573 print("The array with monte-carlo chi2 values is: %s"%spin_chi2_mc_sim)
1574 print("The average of this array is: %3.3f"%spin_chi2_mc_sim_ave)
1575
1576 self.assertAlmostEqual(spin_chi2_mc, spin_chi2_mc_sim_ave, 7)
1577
1578
1580 """Catch U{bug #24601<https://web.archive.org/web/https://gna.org/bugs/?24601>}, the failure of optimisation of the 'R2eff' model with missing data."""
1581
1582
1583 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_missing_data.py')
1584
1585
1587 """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."""
1588
1589
1590 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"
1591
1592
1593 self.interpreter.results.read(prev_data_path + sep + 'results')
1594
1595
1596 graph_nr = 1
1597 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False):
1598 print("\nGraph nr %i" % graph_nr)
1599 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point):
1600 print(exp_type, frq, offset, point, time)
1601 graph_nr += 1
1602
1603
1604
1605
1606 precalc = True
1607 for spin in spin_loop(skip_desel=True):
1608
1609 if not hasattr(spin, 'peak_intensity_err'):
1610 precalc = False
1611 break
1612
1613
1614 for id in cdp.spectrum_ids:
1615 if id not in spin.peak_intensity_err:
1616 precalc = False
1617 break
1618
1619
1620 if precalc:
1621 print("Skipping the error analysis as it has already been performed.")
1622
1623 else:
1624
1625 for frq in loop_frq():
1626
1627 ids = []
1628 for id in cdp.spectrum_ids:
1629
1630 match_frq = True
1631 if frq != None and cdp.spectrometer_frq[id] != frq:
1632 match_frq = False
1633
1634
1635 if match_frq:
1636 ids.append(id)
1637
1638
1639 self.interpreter.spectrum.error_analysis(subset=ids)
1640
1641 print("has_exponential_exp_type:", has_exponential_exp_type())
1642
1643 model = 'R2eff'
1644 self.interpreter.relax_disp.select_model(model)
1645
1646 for spin, spin_id in spin_loop(return_id=True, skip_desel=True):
1647
1648
1649
1650
1651 setattr(spin, 'r2eff', {})
1652 setattr(spin, 'r2eff_err', {})
1653 setattr(spin, 'i0', {})
1654 setattr(spin, 'i0_err', {})
1655
1656
1657 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1)
1658
1659
1660 my_dic = {}
1661
1662
1663 NE = 0
1664 NS = 1
1665 NM = 0
1666 NO = 0
1667 ND = 0
1668 NT = 0
1669
1670 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
1671
1672 if ei > NE:
1673 NE = ei
1674 if mi > NM:
1675 NM = mi
1676 if oi > NO:
1677 NO = oi
1678 if di > ND:
1679 ND = di
1680
1681 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True):
1682
1683 if ti > NT:
1684 NT = ti
1685
1686
1687 NE = NE + 1
1688 NM = NM + 1
1689 NO = NO + 1
1690 ND = ND + 1
1691 NT = NT + 1
1692
1693
1694 values_arr = zeros([NE, NS, NM, NO, ND, NT])
1695 errors_arr = zeros([NE, NS, NM, NO, ND, NT])
1696 times_arr = zeros([NE, NS, NM, NO, ND, NT])
1697 struct_arr = zeros([NE, NS, NM, NO, ND, NT])
1698 param_key_list = []
1699
1700
1701
1702 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1703
1704 my_dic[spin_id] = {}
1705
1706
1707 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
1708
1709
1710
1711
1712 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
1713
1714 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
1715
1716
1717 param_key_list.append(param_key)
1718
1719
1720 my_dic[spin_id][param_key] = {}
1721
1722
1723 R2eff_value = getattr(cur_spin, 'r2eff')[param_key]
1724 i0_value = getattr(cur_spin, 'i0')[param_key]
1725
1726
1727 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value
1728 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value
1729
1730
1731
1732 values = []
1733 errors = []
1734 times = []
1735 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True):
1736 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None)
1737 values.append(value)
1738
1739 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)
1740 errors.append(error)
1741 times.append(time)
1742
1743
1744 values_arr[ei, 0, mi, oi, di, ti] = value
1745 errors_arr[ei, 0, mi, oi, di, ti] = error
1746 times_arr[ei, 0, mi, oi, di, ti] = time
1747 struct_arr[ei, 0, mi, oi, di, ti] = 1.0
1748
1749
1750
1751
1752 w = log(array(values))
1753 x = - array(times)
1754 n = len(times)
1755
1756 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 )
1757 a = 1./n * sum(w) - b * 1./n * sum(x)
1758 R2eff_est = b
1759 i0_est = exp(a)
1760
1761 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est
1762 my_dic[spin_id][param_key]['i0_est'] = i0_est
1763
1764
1765
1766
1767
1768
1769
1770 set_func_tol = 1e-25
1771 set_max_iter = int(1e7)
1772 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
1773
1774
1775 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1776
1777 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
1778
1779
1780 print("Optimised parameters for spin: %s" % (spin_string))
1781
1782 for exp_type, frq, offset, point in loop_exp_frq_offset_point():
1783
1784 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
1785
1786
1787 R2eff_value = getattr(cur_spin, 'r2eff')[param_key]
1788 i0_value = getattr(cur_spin, 'i0')[param_key]
1789
1790
1791 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid']
1792 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid']
1793 R2eff_est = my_dic[spin_id][param_key]['R2eff_est']
1794 i0_est = my_dic[spin_id][param_key]['i0_est']
1795
1796
1797
1798
1799
1800 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est))
1801 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est))
1802
1803 print(NE, NS, NM, NO, ND, NT)
1804 for param_key in param_key_list:
1805 print(" '%s'," % param_key)
1806 print(values_arr.shape)
1807
1808
1809 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1810
1811
1812
1813
1814
1815
1817 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data
1818 shows it is exponential fitting, but only one time point is added per file.
1819
1820 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}:
1821 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}:
1822 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}:
1823
1824 """
1825
1826
1827 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava'
1828 file = data_path + sep + 'bug_script.py'
1829
1830
1831 self.interpreter.script(file=file, dir=None)
1832
1833
1834 GRID_INC = 11
1835
1836
1837
1838
1839
1840 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1841 print(mol_name, resi, resn, spin_id)
1842
1843
1844 for id in cdp.exp_type:
1845 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id])
1846
1847
1848
1849
1850 if True:
1851
1852 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
1853
1854
1855 check_intensity_errors()
1856
1857
1858 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type():
1859 self.interpreter.minimise.calculate()
1860
1861
1862 else:
1863 constraints = False
1864 min_algor = 'Newton'
1865 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC)
1866 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints)
1867
1868
1869 if False:
1870
1871 par_attr_list = ['r2eff', 'i0']
1872
1873
1874 my_dic = {}
1875 param_key_list = []
1876 est_keys = []
1877 est_key = 'grid'
1878 est_keys.append(est_key)
1879 spin_id_list = []
1880
1881 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
1882
1883 my_dic[spin_id] = {}
1884
1885
1886 my_dic[spin_id][est_key] = {}
1887
1888
1889 spin_id_list.append(spin_id)
1890
1891
1892 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
1893
1894 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
1895
1896 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
1897
1898
1899
1900 param_key_list.append(param_key)
1901
1902
1903 my_dic[spin_id][est_key][param_key] = {}
1904
1905
1906
1907 for par_attr in par_attr_list:
1908 if hasattr(cur_spin, par_attr):
1909 get_par_attr = getattr(cur_spin, par_attr)[param_key]
1910 else:
1911 get_par_attr = 0.0
1912
1913
1914 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr
1915
1916
1917 values = []
1918 errors = []
1919 times = []
1920 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True):
1921 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None)
1922 values.append(value)
1923
1924 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)
1925 errors.append(error)
1926 times.append(time)
1927
1928
1929 my_dic[spin_id][est_key][param_key]['values'] = values
1930 my_dic[spin_id][est_key][param_key]['errors'] = errors
1931 my_dic[spin_id][est_key][param_key]['times'] = times
1932
1933
1934
1935
1936
1937 MODELS = ['R2eff', 'No Rex']
1938
1939
1940 MC_NUM = 10
1941
1942
1943 MC_SIM_ALL_MODELS = False
1944
1945
1946 RESULTS_DIR = ds.tmpdir
1947
1948
1949 PRE_RUN_DIR = None
1950
1951
1952 MODSEL = 'AIC'
1953
1954
1955 NUMERIC_ONLY = False
1956
1957
1958 INSIGNIFICANCE = 1.0
1959
1960
1961 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)
1962
1963
1965 """Test data, where peak intensities are negative in CPMG
1966
1967 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).
1968 """
1969
1970 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'
1971
1972
1973 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path)
1974
1975
1976 self.interpreter.spin.isotope(isotope='15N')
1977
1978
1979 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height')
1980
1981
1982 ncycfile=open(data_path + sep + 'ncyc.txt', 'r')
1983
1984
1985 ncyclist = []
1986
1987 i = 0
1988 for line in ncycfile:
1989 ncyc = line.split()[0]
1990 time_T2 = float(line.split()[1])
1991 vcpmg = line.split()[2]
1992 set_sfrq = float(line.split()[3])
1993 rmsd_err = float(line.split()[4])
1994
1995
1996 if float(vcpmg) == 0.0:
1997 vcpmg = None
1998 else:
1999 vcpmg = round(float(vcpmg), 3)
2000
2001
2002 ncyclist.append(int(ncyc))
2003
2004
2005 current_id = "Z_A%s"%(i)
2006
2007
2008 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG')
2009
2010
2011 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id)
2012
2013
2014 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz')
2015
2016
2017 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2)
2018
2019
2020 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg)
2021
2022 i += 1
2023
2024
2025 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15'])
2026
2027
2028
2029
2030 MODELS = [MODEL_R2EFF, MODEL_NOREX]
2031 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC'
2032
2033 results_dir = ds.tmpdir
2034
2035
2036 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)
2037
2038
2039 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False):
2040
2041 if spin_id == ':4@N':
2042 self.assertEqual(len(cur_spin.r2eff), 14)
2043 else:
2044 self.assertEqual(len(cur_spin.r2eff), 15)
2045
2046
2113
2114
2116 """Test of the check_missing_r1() function."""
2117
2118
2119 self.setup_missing_r1_spins()
2120
2121
2122 exp_type = 'R1rho'
2123 frq = 800.1 * 1E6
2124
2125 spectrum_id='test'
2126
2127
2128 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type)
2129
2130
2131 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz')
2132
2133
2134 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94)
2135 self.assertEqual(check_missing_r1_return, True)
2136
2137
2138 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF)
2139 self.assertEqual(check_missing_r1_return, False)
2140
2141
2142 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'
2143
2144
2145 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)
2146
2147
2148 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94)
2149 self.assertEqual(check_missing_r1_return, False)
2150
2151
2153 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis.
2154
2155 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.
2156
2157 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model.
2158 """
2159
2160
2161
2162
2163
2164 model_create = 'B14'
2165
2166 model_analyse = 'NS CPMG 2-site 3D'
2167
2168
2169 sfrq_1 = 599.8908617*1E6
2170 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2171 time_T2_1 = 0.06
2172 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2173
2174 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
2175 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1]
2176
2177 sfrq_2 = 499.8908617*1E6
2178 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2179 time_T2_2 = 0.05
2180 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2181
2182 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
2183 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2]
2184
2185
2186 exps = [exp_1, exp_2]
2187
2188 spins = [
2189 ['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.} ],
2190 ['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.} ]
2191 ]
2192
2193
2194 ds.data = [model_create, model_analyse, spins, exps]
2195
2196
2197 ds.tmpdir = ds.tmpdir
2198
2199
2200
2201 ds.resdir = ds.tmpdir
2202
2203
2204 ds.r20_from_min_r2eff = True
2205
2206
2207 ds.insignificance = 0.0
2208
2209
2210 ds.GRID_INC = None
2211
2212
2213 ds.do_cluster = True
2214
2215
2216
2217 ds.set_func_tol = 1e-1
2218
2219
2220
2221 ds.set_max_iter = 1000
2222
2223
2224 ds.verbosity = 1
2225
2226
2227 ds.rel_change = 0.05
2228
2229
2230 ds.plot_curves = False
2231
2232
2233 ds.sherekhan_input = False
2234
2235
2236 ds.opendx = False
2237
2238
2239 ds.r2eff_err = 0.1
2240
2241
2242 ds.print_res = True
2243
2244
2245 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2246
2247 cur_spins = ds.data[2]
2248
2249 for i in range(len(cur_spins)):
2250 res_name, res_num, spin_name, params = cur_spins[i]
2251 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2252 cur_spin = return_spin(spin_id=cur_spin_id)
2253
2254 grid_params = ds.grid_results[i][3]
2255
2256
2257 min_params = ds.clust_results[i][3]
2258
2259 print("For spin: '%s'"%cur_spin_id)
2260 for mo_param in cur_spin.params:
2261
2262 if isinstance(getattr(cur_spin, mo_param), dict):
2263 grid_r2 = grid_params[mo_param]
2264 min_r2 = min_params[mo_param]
2265 set_r2 = params[mo_param]
2266 for key, val in list(set_r2.items()):
2267 grid_r2_frq = grid_r2[key]
2268 min_r2_frq = min_r2[key]
2269 set_r2_frq = set_r2[key]
2270 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2271 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2272 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) )
2273 if rel_change > ds.rel_change:
2274 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2275 print("###################################")
2276
2277
2278 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1)
2279 else:
2280 grid_val = grid_params[mo_param]
2281 min_val = min_params[mo_param]
2282 set_val = params[mo_param]
2283 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2284 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) )
2285 if rel_change > ds.rel_change:
2286 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2287 print("###################################")
2288
2289
2290 if mo_param == 'dw':
2291 self.assertAlmostEqual(set_val/10, min_val/10, 1)
2292 elif mo_param == 'kex':
2293 self.assertAlmostEqual(set_val/1000, min_val/1000, 1)
2294 elif mo_param == 'pA':
2295 self.assertAlmostEqual(set_val, min_val, 2)
2296
2297
2299 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis.
2300
2301 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.
2302
2303 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model.
2304 """
2305
2306
2307
2308
2309
2310 model_create = 'B14'
2311
2312 model_analyse = 'NS CPMG 2-site star'
2313
2314
2315 sfrq_1 = 599.8908617*1E6
2316 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2317 time_T2_1 = 0.06
2318 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2319
2320 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
2321 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1]
2322
2323 sfrq_2 = 499.8908617*1E6
2324 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2325 time_T2_2 = 0.05
2326 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2327
2328 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
2329 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2]
2330
2331
2332 exps = [exp_1, exp_2]
2333
2334 spins = [
2335 ['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.} ],
2336 ['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.} ]
2337 ]
2338
2339
2340 ds.data = [model_create, model_analyse, spins, exps]
2341
2342
2343 ds.tmpdir = ds.tmpdir
2344
2345
2346
2347 ds.resdir = ds.tmpdir
2348
2349
2350 ds.r20_from_min_r2eff = True
2351
2352
2353 ds.insignificance = 0.0
2354
2355
2356 ds.GRID_INC = None
2357
2358
2359 ds.do_cluster = True
2360
2361
2362
2363 ds.set_func_tol = 1e-1
2364
2365
2366
2367 ds.set_max_iter = 1000
2368
2369
2370 ds.verbosity = 1
2371
2372
2373 ds.rel_change = 0.05
2374
2375
2376 ds.plot_curves = False
2377
2378
2379 ds.sherekhan_input = False
2380
2381
2382 ds.opendx = False
2383
2384
2385 ds.r2eff_err = 0.1
2386
2387
2388 ds.print_res = True
2389
2390
2391 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2392
2393 cur_spins = ds.data[2]
2394
2395 for i in range(len(cur_spins)):
2396 res_name, res_num, spin_name, params = cur_spins[i]
2397 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2398 cur_spin = return_spin(spin_id=cur_spin_id)
2399
2400 grid_params = ds.grid_results[i][3]
2401
2402
2403 min_params = ds.clust_results[i][3]
2404
2405 print("For spin: '%s'"%cur_spin_id)
2406 for mo_param in cur_spin.params:
2407
2408 if isinstance(getattr(cur_spin, mo_param), dict):
2409 grid_r2 = grid_params[mo_param]
2410 min_r2 = min_params[mo_param]
2411 set_r2 = params[mo_param]
2412 for key, val in list(set_r2.items()):
2413 grid_r2_frq = grid_r2[key]
2414 min_r2_frq = min_r2[key]
2415 set_r2_frq = set_r2[key]
2416 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2417 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2418 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) )
2419 if rel_change > ds.rel_change:
2420 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2421 print("###################################")
2422
2423
2424 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1)
2425 else:
2426 grid_val = grid_params[mo_param]
2427 min_val = min_params[mo_param]
2428 set_val = params[mo_param]
2429 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2430 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) )
2431 if rel_change > ds.rel_change:
2432 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2433 print("###################################")
2434
2435
2436 if mo_param == 'dw':
2437 self.assertAlmostEqual(set_val/10, min_val/10, 1)
2438 elif mo_param == 'kex':
2439 self.assertAlmostEqual(set_val/1000, min_val/1000, 1)
2440 elif mo_param == 'pA':
2441 self.assertAlmostEqual(set_val, min_val, 2)
2442
2443
2445 """Test synthetic cpmg data.
2446
2447 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72.
2448 """
2449
2450
2451
2452
2453
2454 model_create = 'NS CPMG 2-site 3D'
2455
2456 model_analyse = 'CR72'
2457
2458 sfrq_1 = 599.8908617*1E6
2459 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2460 time_T2_1 = 0.06
2461 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2462 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0]
2463 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1]
2464
2465 sfrq_2 = 499.8908617*1E6
2466 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2467 time_T2_2 = 0.05
2468 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2469 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0]
2470 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2]
2471
2472
2473 exps = [exp_1, exp_2]
2474
2475 spins = [
2476 ['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.} ]
2477 ]
2478
2479
2480 ds.data = [model_create, model_analyse, spins, exps]
2481
2482
2483 ds.tmpdir = ds.tmpdir
2484
2485
2486
2487 ds.resdir = ds.tmpdir
2488
2489
2490 ds.r20_from_min_r2eff = True
2491
2492
2493 ds.insignificance = 0.0
2494
2495
2496 ds.GRID_INC = 8
2497
2498
2499 ds.do_cluster = False
2500
2501
2502
2503 ds.set_func_tol = 1e-9
2504
2505
2506
2507 ds.set_max_iter = 1000
2508
2509
2510 ds.verbosity = 1
2511
2512
2513 ds.rel_change = 0.05
2514
2515
2516 ds.plot_curves = False
2517
2518
2519 ds.sherekhan_input = False
2520
2521
2522 ds.opendx = False
2523
2524
2525 ds.r2eff_err = 0.1
2526
2527
2528 ds.print_res = False
2529
2530
2531 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2532
2533 cur_spins = ds.data[2]
2534
2535 for i in range(len(cur_spins)):
2536 res_name, res_num, spin_name, params = cur_spins[i]
2537 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2538 cur_spin = return_spin(spin_id=cur_spin_id)
2539
2540 grid_params = ds.grid_results[i][3]
2541 min_params = ds.min_results[i][3]
2542
2543 print("For spin: '%s'"%cur_spin_id)
2544 for mo_param in cur_spin.params:
2545
2546 if isinstance(getattr(cur_spin, mo_param), dict):
2547 grid_r2 = grid_params[mo_param]
2548 min_r2 = min_params[mo_param]
2549 set_r2 = params[mo_param]
2550 for key, val in list(set_r2.items()):
2551 grid_r2_frq = grid_r2[key]
2552 min_r2_frq = min_r2[key]
2553 set_r2_frq = set_r2[key]
2554 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2555 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2556 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) )
2557 if rel_change > ds.rel_change:
2558 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2559 print("###################################")
2560
2561
2562 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2)
2563 else:
2564 grid_val = grid_params[mo_param]
2565 min_val = min_params[mo_param]
2566 set_val = params[mo_param]
2567 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2568 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) )
2569 if rel_change > ds.rel_change:
2570 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2571 print("###################################")
2572
2573
2574 if mo_param == 'dw':
2575 self.assertAlmostEqual(set_val/10, min_val/10, 1)
2576 elif mo_param == 'kex':
2577 self.assertAlmostEqual(set_val/1000, min_val/1000, 1)
2578 elif mo_param == 'pA':
2579 self.assertAlmostEqual(set_val, min_val, 3)
2580
2581
2583 """Test synthetic cpmg data.
2584
2585 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14.
2586 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.
2587 """
2588
2589
2590
2591
2592
2593 model_create = 'NS CPMG 2-site 3D'
2594
2595 model_analyse = 'B14'
2596
2597 sfrq_1 = 599.8908617*1E6
2598 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2599 time_T2_1 = 0.06
2600 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2601 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0]
2602 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1]
2603
2604 sfrq_2 = 499.8908617*1E6
2605 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2606 time_T2_2 = 0.05
2607 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2608 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0]
2609 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2]
2610
2611
2612 exps = [exp_1, exp_2]
2613
2614 spins = [
2615 ['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.} ]
2616 ]
2617
2618
2619 ds.data = [model_create, model_analyse, spins, exps]
2620
2621
2622 ds.tmpdir = ds.tmpdir
2623
2624
2625
2626 ds.resdir = ds.tmpdir
2627
2628
2629 ds.r20_from_min_r2eff = True
2630
2631
2632 ds.insignificance = 0.0
2633
2634
2635 ds.GRID_INC = 8
2636
2637
2638 ds.do_cluster = False
2639
2640
2641
2642 ds.set_func_tol = 1e-9
2643
2644
2645
2646 ds.set_max_iter = 1000
2647
2648
2649 ds.verbosity = 1
2650
2651
2652 ds.rel_change = 0.05
2653
2654
2655 ds.plot_curves = False
2656
2657
2658 ds.sherekhan_input = False
2659
2660
2661 ds.opendx = False
2662
2663
2664 ds.r2eff_err = 0.1
2665
2666
2667 ds.print_res = False
2668
2669
2670 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2671
2672 cur_spins = ds.data[2]
2673
2674 for i in range(len(cur_spins)):
2675 res_name, res_num, spin_name, params = cur_spins[i]
2676 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2677 cur_spin = return_spin(spin_id=cur_spin_id)
2678
2679 grid_params = ds.grid_results[i][3]
2680 min_params = ds.min_results[i][3]
2681
2682 print("For spin: '%s'"%cur_spin_id)
2683 for mo_param in cur_spin.params:
2684
2685 if isinstance(getattr(cur_spin, mo_param), dict):
2686 grid_r2 = grid_params[mo_param]
2687 min_r2 = min_params[mo_param]
2688 set_r2 = params[mo_param]
2689 for key, val in list(set_r2.items()):
2690 grid_r2_frq = grid_r2[key]
2691 min_r2_frq = min_r2[key]
2692 set_r2_frq = set_r2[key]
2693 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2694 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2695 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) )
2696 if rel_change > ds.rel_change:
2697 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2698 print("###################################")
2699
2700
2701 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2)
2702 else:
2703 grid_val = grid_params[mo_param]
2704 min_val = min_params[mo_param]
2705 set_val = params[mo_param]
2706 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2707 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) )
2708 if rel_change > ds.rel_change:
2709 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2710 print("###################################")
2711
2712
2713 if mo_param == 'dw':
2714 self.assertAlmostEqual(set_val/10, min_val/10, 5)
2715 elif mo_param == 'kex':
2716 self.assertAlmostEqual(set_val/1000, min_val/1000, 5)
2717 elif mo_param == 'pA':
2718 self.assertAlmostEqual(set_val, min_val, 6)
2719
2720
2722 """Test synthetic cpmg data. For CR72 with small noise and cluster.
2723
2724 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model.
2725 """
2726
2727
2728
2729
2730
2731 model_create = 'NS CPMG 2-site 3D'
2732
2733 model_analyse = 'CR72'
2734
2735
2736 sfrq_1 = 599.8908617*1E6
2737 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2738 time_T2_1 = 0.06
2739 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2740 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05]
2741
2742 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1]
2743
2744 sfrq_2 = 499.8908617*1E6
2745 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2746 time_T2_2 = 0.05
2747 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2748 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05]
2749
2750 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2]
2751
2752
2753 exps = [exp_1, exp_2]
2754
2755 spins = [
2756 ['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.} ],
2757 ['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.} ]
2758 ]
2759
2760
2761 ds.data = [model_create, model_analyse, spins, exps]
2762
2763
2764 ds.tmpdir = ds.tmpdir
2765
2766
2767
2768 ds.resdir = ds.tmpdir
2769
2770
2771 ds.r20_from_min_r2eff = True
2772
2773
2774 ds.insignificance = 0.0
2775
2776
2777 ds.GRID_INC = 13
2778
2779
2780 ds.do_cluster = True
2781
2782
2783
2784 ds.set_func_tol = 1e-8
2785
2786
2787
2788 ds.set_max_iter = 10000
2789
2790
2791 ds.verbosity = 1
2792
2793
2794 ds.rel_change = 0.05
2795
2796
2797 ds.plot_curves = False
2798
2799
2800 ds.sherekhan_input = False
2801
2802
2803 ds.opendx = False
2804
2805
2806 ds.r2eff_err = 0.1
2807
2808
2809 ds.print_res = False
2810
2811
2812 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2813
2814 cur_spins = ds.data[2]
2815
2816 for i in range(len(cur_spins)):
2817 res_name, res_num, spin_name, params = cur_spins[i]
2818 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2819 cur_spin = return_spin(spin_id=cur_spin_id)
2820
2821 grid_params = ds.grid_results[i][3]
2822
2823
2824 min_params = ds.clust_results[i][3]
2825
2826 print("For spin: '%s'"%cur_spin_id)
2827 for mo_param in cur_spin.params:
2828
2829 if isinstance(getattr(cur_spin, mo_param), dict):
2830 grid_r2 = grid_params[mo_param]
2831 min_r2 = min_params[mo_param]
2832 set_r2 = params[mo_param]
2833 for key, val in list(set_r2.items()):
2834 grid_r2_frq = grid_r2[key]
2835 min_r2_frq = min_r2[key]
2836 set_r2_frq = set_r2[key]
2837 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0])
2838 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 )
2839 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) )
2840 if rel_change > ds.rel_change:
2841 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2842 print("###################################")
2843
2844
2845 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1)
2846 else:
2847 grid_val = grid_params[mo_param]
2848 min_val = min_params[mo_param]
2849 set_val = params[mo_param]
2850 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 )
2851 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) )
2852 if rel_change > ds.rel_change:
2853 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change))
2854 print("###################################")
2855
2856
2857 if mo_param == 'dw':
2858 self.assertAlmostEqual(set_val/10, min_val/10, 1)
2859 elif mo_param == 'kex':
2860 self.assertAlmostEqual(set_val/1000, min_val/1000, 1)
2861 elif mo_param == 'pA':
2862 self.assertAlmostEqual(set_val, min_val, 2)
2863
2864
2866 """Test synthetic cpmg data, calling the dx.map function with one or two points.
2867
2868 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model.
2869 """
2870
2871
2872
2873
2874
2875 model_create = MODEL_NS_CPMG_2SITE_EXPANDED
2876 model_analyse = 'CR72'
2877
2878 sfrq_1 = 599.8908617*1E6
2879 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1)
2880 time_T2_1 = 0.06
2881 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60]
2882 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0]
2883 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1]
2884
2885 sfrq_2 = 499.8908617*1E6
2886 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2)
2887 time_T2_2 = 0.05
2888 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50]
2889 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0]
2890 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2]
2891
2892
2893 exps = [exp_1, exp_2]
2894
2895 spins = [
2896 ['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} ]
2897 ]
2898
2899
2900 ds.data = [model_create, model_analyse, spins, exps]
2901
2902
2903 ds.tmpdir = ds.tmpdir
2904
2905
2906
2907 ds.resdir = ds.tmpdir
2908
2909
2910 ds.r20_from_min_r2eff = True
2911
2912
2913 ds.insignificance = 0.0
2914
2915
2916 ds.GRID_INC = None
2917
2918
2919 ds.do_cluster = False
2920
2921
2922
2923 ds.set_func_tol = 1e-9
2924
2925
2926
2927 ds.set_max_iter = 1000
2928
2929
2930 ds.verbosity = 1
2931
2932
2933 ds.rel_change = 0.05
2934
2935
2936 ds.plot_curves = False
2937
2938
2939 ds.sherekhan_input = False
2940
2941
2942 ds.opendx = False
2943
2944
2945 ds.r2eff_err = 0.1
2946
2947
2948 ds.print_res = False
2949
2950
2951 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py')
2952
2953
2954 cur_spins = ds.data[2]
2955
2956
2957 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse)
2958 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle)
2959 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP)
2960
2961
2962 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff')
2963
2964
2965 self.interpreter.relax_disp.select_model(model=model_analyse)
2966
2967
2968 ds.dx_inc = 4
2969 ds.dx_params = ['dw', 'pA', 'kex']
2970
2971 res_name, res_num, spin_name, params = cur_spins[0]
2972 cur_spin_id = ":%i@%s"%(res_num, spin_name)
2973 cur_spin = return_spin(spin_id=cur_spin_id)
2974
2975 print("Params for dx map is")
2976 print(ds.dx_params)
2977 print("Point param for dx map is")
2978 print(ds.dx_set_val)
2979 cur_model = model_analyse.replace(' ', '_')
2980 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_'))
2981 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_'))
2982 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)
2983
2984
2985
2986 map_cfg = ds.tmpdir+sep+file_name_map+".cfg"
2987 map_net = ds.tmpdir+sep+file_name_map+".net"
2988 map_general = ds.tmpdir+sep+file_name_map+".general"
2989 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir)
2990 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir)
2991
2992 point_general = ds.tmpdir+sep+file_name_point+".general"
2993 point_point = ds.tmpdir+sep+file_name_point
2994 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir)
2995
2996
2997 self.assertTrue(access(map_cfg, F_OK))
2998 self.assertTrue(access(map_net, F_OK))
2999 self.assertTrue(access(map_general, F_OK))
3000 self.assertTrue(access(map_par, F_OK))
3001 self.assertTrue(access(map_plot, F_OK))
3002 self.assertTrue(access(point_general, F_OK))
3003 self.assertTrue(access(point_point, F_OK))
3004 self.assertTrue(access(point_par, F_OK))
3005
3006
3007
3008 print("\nChecking the dx map .cfg file.")
3009 res_file = [
3010 '//'+"\n",
3011 '//'+"\n",
3012 '// time: Thu May 8 18:55:31 2014'+"\n",
3013 '//'+"\n",
3014 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n",
3015 '//'+"\n",
3016 '//'+"\n",
3017 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n",
3018 '// title: value = Control Panel'+"\n",
3019 '//'+"\n",
3020 '// workspace: width = 251, height = 142'+"\n",
3021 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n",
3022 '//'+"\n",
3023 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n",
3024 '// selections: maximum = 2, current = 0 '+"\n",
3025 '// option[0]: name = "Colour", value = 1'+"\n",
3026 '// option[1]: name = "Grey", value = 2'+"\n",
3027 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n",
3028 '// label: value = Colour Selector'+"\n",
3029 '//'+"\n",
3030 '// node Image[3]:'+"\n",
3031 '// title: value = Surface'+"\n",
3032 '// depth: value = 24'+"\n",
3033 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n",
3034 ]
3035 file = open(map_cfg, 'r')
3036 lines = file.readlines()
3037 file.close()
3038 for i in range(len(res_file)):
3039
3040 if i == 2:
3041 continue
3042 self.assertEqual(res_file[i], lines[i])
3043
3044 print("\nChecking the dx map .general file.")
3045 res_file = [
3046 'file = CR72_map_1_N'+"\n",
3047 'grid = 5 x 5 x 5'+"\n",
3048 'format = ascii'+"\n",
3049 'interleaving = field'+"\n",
3050 'majority = row'+"\n",
3051 'field = data'+"\n",
3052 'structure = scalar'+"\n",
3053 'type = float'+"\n",
3054 'dependency = positions'+"\n",
3055 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n",
3056 ''+"\n",
3057 'end'+"\n",
3058 ]
3059 file = open(map_general, 'r')
3060 lines = file.readlines()
3061 file.close()
3062 for i in range(len(res_file)):
3063
3064
3065
3066 self.assertEqual(res_file[i], lines[i])
3067
3068 print("\nChecking the dx point .general file.")
3069 res_file = [
3070 'file = CR72_point_1_N'+"\n",
3071 'points = 2'+"\n",
3072 'format = ascii'+"\n",
3073 'interleaving = field'+"\n",
3074 'field = locations, field0'+"\n",
3075 'structure = 3-vector, scalar'+"\n",
3076 'type = float, float'+"\n",
3077 ''+"\n",
3078 'end'+"\n",
3079 ]
3080 file = open(point_general, 'r')
3081 lines = file.readlines()
3082 file.close()
3083 for i in range(len(res_file)):
3084
3085
3086
3087 self.assertEqual(res_file[i], lines[i])
3088
3089 print("\nChecking the dx point point file.")
3090 res_file = [
3091 '0.8 3.92 0.39964 1'+"\n",
3092 '0.76981 3.9169 0.41353 1'+"\n",
3093 ]
3094 file = open(point_point, 'r')
3095 lines = file.readlines()
3096 file.close()
3097 for i in range(len(res_file)):
3098
3099
3100
3101 self.assertEqual(res_file[i], lines[i])
3102
3103 print("\nChecking the dx point par file.")
3104 res_file = [
3105 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n",
3106 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n",
3107 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n",
3108 ]
3109 res_file2 = [
3110 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n",
3111 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n",
3112 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n",
3113 ]
3114 file = open(point_par, 'r')
3115 lines = file.readlines()
3116 file.close()
3117 for i in range(len(res_file)):
3118 if lines[i] != res_file[i] and lines[i] != res_file2[i]:
3119 self.assertEqual(res_file[i], lines[i])
3120
3121 print("\nChecking the matplotlib surface plot file.")
3122 res_file = [
3123 'from copy import deepcopy'+"\n",
3124 'import numpy as np'+"\n",
3125 'import scipy.interpolate'+"\n",
3126 'from numpy.ma import masked_where'+"\n",
3127 ''+"\n",
3128 'from mpl_toolkits.mplot3d import axes3d'+"\n",
3129 'import matplotlib.pyplot as plt'+"\n",
3130 'from matplotlib import cm'+"\n",
3131 ''+"\n",
3132 '# Open file and get header.'+"\n",
3133 'mapfile_name = "%s.par"'%file_name_map+"\n",
3134 'pointfile_name = "%s.par"'%file_name_point+"\n",
3135 ''+"\n",
3136 ]
3137 file = open(map_plot, 'r')
3138 lines = file.readlines()
3139 file.close()
3140 for i in range(len(res_file)):
3141 self.assertEqual(res_file[i], lines[i])
3142
3143
3145 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data."""
3146
3147
3148 self.interpreter.reset()
3149
3150
3151 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'
3152 self.interpreter.state.load(data_path+sep+'r2eff_values')
3153
3154
3155 curve_type = get_curve_type(id='500_133.33.in')
3156 self.assertEqual(curve_type, 'fixed time')
3157
3158
3160 """Test the curve type detection using the 'M61' exponential test data."""
3161
3162
3163 self.interpreter.reset()
3164
3165
3166 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61'
3167 self.interpreter.state.load(data_path+sep+'r2eff_values')
3168
3169
3170 curve_type = get_curve_type(id='nu_2000_ncyc9')
3171 self.assertEqual(curve_type, 'exponential')
3172
3173
3175 """Test the curve type detection using the 'TP02' fixed time test data."""
3176
3177
3178 self.interpreter.reset()
3179
3180
3181 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02'
3182 self.interpreter.state.load(data_path+sep+'r2eff_values')
3183
3184
3185 curve_type = get_curve_type(id='nu_1000.0_500MHz')
3186 self.assertEqual(curve_type, 'fixed time')
3187
3188
3190 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data."""
3191
3192
3193 ds.fixed = True
3194
3195
3196 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')
3197
3198
3199 i0 = [100000.0, 20000.0]
3200 r1rho_prime = [2.25, 24.0]
3201 pA = 0.7
3202 kex = 1000.0
3203 delta_omega = [1.0, 2.0]
3204 phi_ex = []
3205 for i in range(2):
3206 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2)
3207
3208
3209 self.interpreter.pipe.switch('DPL94 - relax_disp')
3210 spin_index = 0
3211 for spin, spin_id in spin_loop(return_id=True):
3212
3213 print("\nSpin %s." % spin_id)
3214
3215
3216 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2)
3217 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2)
3218 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2)
3219
3220
3221 spin_index += 1
3222
3223
3225 """Test making dx_map for residues under clustered calculation.
3226
3227 This uses CPMG data from:
3228 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE
3229 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations.
3230 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>}
3231 """
3232
3233
3234 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011'
3235
3236
3237 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins')
3238
3239
3240 cur_spin_id = ":%i@%s"%(52, 'N')
3241 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')
3242
3243
3244 cur_spin = return_spin(spin_id=cur_spin_id)
3245
3246
3247 pre_chi2 = cur_spin.chi2
3248
3249
3250
3251 self.interpreter.minimise.calculate()
3252
3253
3254 calc_chi2 = cur_spin.chi2
3255
3256
3257 self.assertAlmostEqual(pre_chi2, calc_chi2)
3258
3259
3260 dx_inc = 2
3261 dx_inc_sides = dx_inc / 2
3262
3263 dx_params = ['dw', 'pA', 'kex']
3264 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex]
3265
3266 print("Params for dx map is")
3267 print(dx_params)
3268 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2)
3269 print(dx_point_clustered_min)
3270
3271
3272 cur_model = 'CR72'
3273 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str)
3274 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str)
3275
3276
3277 param_delta = 0.1
3278
3279
3280 lower = []
3281 upper = []
3282 for i, param_val in enumerate(dx_point_clustered_min):
3283 param = dx_params[i]
3284 step_val = param_delta * param_val
3285 step_length = step_val * dx_inc_sides
3286
3287
3288 low_val = param_val - step_length
3289 lower.append(low_val)
3290
3291 upp_val = param_val + step_length
3292 upper.append(upp_val)
3293
3294 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))
3295
3296
3297
3298 dx_param_indexes = dx_inc + 1
3299 dx_point_index = dx_inc_sides + 1
3300
3301
3302 line = 1
3303 for i in range(1, dx_param_indexes + 1):
3304 for j in range(1, dx_param_indexes + 1):
3305 for k in range(1, dx_param_indexes + 1):
3306 if i == dx_point_index and j == dx_point_index and k == dx_point_index:
3307 line_chi2 = line
3308
3309 line += 1
3310
3311
3312 result_dir = self.tmpdir
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322 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)
3323
3324
3325 nr_chi2_val = dx_param_indexes**3
3326 print("Nr of chi2 calculations are=%i"%nr_chi2_val)
3327 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) )
3328
3329
3330
3331 map_name = get_file_path(file_name=file_name_map, dir=result_dir)
3332 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir)
3333 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir)
3334 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir)
3335
3336 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir)
3337 point_point = get_file_path(file_name=file_name_point, dir=result_dir)
3338
3339
3340 self.assertTrue(access(map_cfg, F_OK))
3341 self.assertTrue(access(map_net, F_OK))
3342 self.assertTrue(access(map_general, F_OK))
3343 self.assertTrue(access(point_general, F_OK))
3344 self.assertTrue(access(point_point, F_OK))
3345
3346
3347 get_data = extract_data(file=map_name)
3348
3349
3350 test = float(get_data[line_chi2-1][0])
3351
3352
3353 self.assertAlmostEqual(test, pre_chi2, 6)
3354
3355
3357 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file.
3358
3359 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.
3360
3361 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).
3362 """
3363
3364
3365 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting'
3366
3367
3368 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2')
3369
3370
3371 cur_spin_id = ":%i@%s"%(65, 'N')
3372 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')
3373
3374
3375 cur_spin = return_spin(spin_id=cur_spin_id)
3376
3377
3378 pre_chi2 = cur_spin.chi2
3379
3380
3381
3382 self.interpreter.minimise.calculate()
3383
3384
3385 calc_chi2 = cur_spin.chi2
3386
3387
3388 self.assertAlmostEqual(pre_chi2, calc_chi2)
3389
3390
3391 dx_inc = 2
3392 dx_params = ['dw', 'k_AB', 'r2a']
3393 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']]
3394
3395 print("Params for dx map is")
3396 print(dx_params)
3397 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2)
3398 print(dx_point_clustered_min)
3399
3400
3401 cur_model = 'TSMFK01'
3402 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str)
3403 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str)
3404
3405
3406 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]]
3407 upper = [19.0, 2.4, 9.5]
3408
3409
3410 result_dir = self.tmpdir
3411
3412
3413
3414
3415
3416
3417 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)
3418
3419
3420 nr_chi2_val = (dx_inc + 1)**3
3421 print("Nr of chi2 calculations are=%i"%nr_chi2_val)
3422 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) )
3423
3424
3425
3426 map_name = get_file_path(file_name=file_name_map, dir=result_dir)
3427 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir)
3428 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir)
3429 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir)
3430 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir)
3431
3432 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir)
3433 point_point = get_file_path(file_name=file_name_point, dir=result_dir)
3434
3435
3436 self.assertTrue(access(map_cfg, F_OK))
3437 self.assertTrue(access(map_net, F_OK))
3438 self.assertTrue(access(map_general, F_OK))
3439 self.assertTrue(access(map_par, F_OK))
3440 self.assertTrue(access(point_general, F_OK))
3441 self.assertTrue(access(point_point, F_OK))
3442
3443 print("\nParams for dx map is")
3444 print(dx_params)
3445 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2)
3446 print(dx_point_clustered_min, "\n")
3447
3448
3449 get_data = extract_data(file=map_par)
3450
3451
3452 test = float(get_data[1][9])
3453
3454
3455 if test < pre_chi2:
3456 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test))
3457 for line in get_data:
3458 print(line)
3459
3460
3461
3462
3463
3464
3465
3466
3467
3469 """Test the user function for estimating R2eff errors from exponential curve fitting.
3470
3471 This follows Task 7822.
3472 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.
3473
3474 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
3475 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
3476 """
3477
3478
3479 cluster_ids = [
3480 ":13@N",
3481 ":15@N",
3482 ":16@N",
3483 ":25@N",
3484 ":26@N",
3485 ":28@N",
3486 ":39@N",
3487 ":40@N",
3488 ":41@N",
3489 ":43@N",
3490 ":44@N",
3491 ":45@N",
3492 ":49@N",
3493 ":52@N",
3494 ":53@N"]
3495
3496
3497 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False)
3498
3499
3500 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
3501
3502
3503 GRID_INC = None
3504
3505
3506 MC_NUM = 3
3507
3508
3509 MODSEL = 'AIC'
3510
3511
3512
3513 OPT_FUNC_TOL = 1e-25
3514 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
3515 OPT_MAX_ITERATIONS = 10000000
3516 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
3517
3518 result_dir_name = ds.tmpdir
3519
3520
3521 for curspin in cluster_ids:
3522 self.interpreter.relax_disp.cluster('free spins', curspin)
3523
3524 self.interpreter.deselect.spin(spin_id=curspin, change_all=False)
3525
3526
3527
3528
3529
3530
3531
3532
3533 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
3534
3535
3536
3537 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
3538
3539
3540 check_intensity_errors()
3541
3542
3543 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1)
3544
3545
3546 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1)
3547
3548
3549 self.interpreter.relax_disp.r2eff_err_estimate()
3550
3551 r1_fit = True
3552
3553
3554 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)
3555
3556
3557 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3558
3559
3561 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu.
3562
3563 This follows Task 7822.
3564 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.
3565
3566 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
3567 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
3568 """
3569
3570
3571 cluster_ids = [
3572 ":13@N",
3573 ":15@N",
3574 ":16@N",
3575 ":25@N",
3576 ":26@N",
3577 ":28@N",
3578 ":39@N",
3579 ":40@N",
3580 ":41@N",
3581 ":43@N",
3582 ":44@N",
3583 ":45@N",
3584 ":49@N",
3585 ":52@N",
3586 ":53@N"]
3587
3588
3589
3590 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep
3591
3592
3593 pipe_name = 'base pipe'
3594 pipe_bundle = 'relax_disp'
3595 pipe_type = 'relax_disp'
3596
3597
3598 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type)
3599
3600 file = data_path + '1_setup_r1rho_GUI.py'
3601 self.interpreter.script(file=file, dir=None)
3602
3603
3604 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
3605
3606
3607 GRID_INC = None
3608
3609
3610
3611
3612 EXP_MC_NUM = -1
3613
3614
3615 MC_NUM = 3
3616
3617
3618 MODSEL = 'AIC'
3619
3620
3621
3622 OPT_FUNC_TOL = 1e-25
3623 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
3624 OPT_MAX_ITERATIONS = 10000000
3625 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
3626
3627
3628
3629
3630
3631
3632
3633
3634 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False)
3635
3636
3637
3638
3639
3640
3641
3642
3643 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
3644
3645
3646 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3647 print(spin_id)
3648
3649 result_dir_name = self.tmpdir
3650 r1_fit = True
3651
3652
3653 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)
3654
3655
3656 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3657
3658
3660 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods.
3661 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations.
3662
3663 This follows Task 7822.
3664 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.
3665
3666 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
3667 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
3668
3669 NOTE: The difference in the methods was due to a bug in relax!
3670 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.
3671
3672 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong.
3673 """
3674
3675
3676 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"
3677
3678
3679 self.interpreter.pipe.create('MC_2000', 'relax_disp')
3680
3681
3682 self.interpreter.results.read(prev_data_path + sep + 'results')
3683
3684
3685 my_dic = {}
3686 param_key_list = []
3687
3688
3689 do_boot = True
3690 if do_boot:
3691 min_algor = 'Newton'
3692 min_options = ()
3693 sim_boot = 200
3694 scaling_list = [1.0, 1.0]
3695
3696
3697 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3698
3699 my_dic[spin_id] = {}
3700
3701
3702 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim):
3703
3704 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
3705
3706 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
3707 r2eff_sim_point = r2eff_sim[param_key]
3708 i0_sim_point = cur_spin.r2eff_sim[i][param_key]
3709
3710
3711
3712
3713 self.assertTrue(r2eff_sim_point > 0.0)
3714 self.assertTrue(i0_sim_point > 0.0)
3715
3716
3717 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3718
3719 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
3720
3721 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
3722
3723 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
3724
3725
3726 r2eff_sim_l = []
3727 i0_sim_l = []
3728 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim):
3729 i0_sim = cur_spin.i0_sim[i]
3730
3731 r2eff_sim_i = r2eff_sim[param_key]
3732 r2eff_sim_l.append(r2eff_sim_i)
3733 i0_sim_i = i0_sim[param_key]
3734 i0_sim_l.append(i0_sim_i)
3735
3736
3737 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1)
3738 i0_sim_err = std(asarray(i0_sim_l), ddof=1)
3739
3740
3741 param_key_list.append(param_key)
3742
3743
3744 my_dic[spin_id][param_key] = {}
3745
3746
3747 r2eff = getattr(cur_spin, 'r2eff')[param_key]
3748 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key]
3749 i0 = getattr(cur_spin, 'i0')[param_key]
3750 i0_err = getattr(cur_spin, 'i0_err')[param_key]
3751
3752
3753 my_dic[spin_id][param_key]['r2eff'] = r2eff
3754 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err
3755 my_dic[spin_id][param_key]['i0'] = i0
3756 my_dic[spin_id][param_key]['i0_err'] = i0_err
3757 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err
3758 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err
3759
3760
3761 self.assertAlmostEqual(r2eff_sim_err, r2eff_err)
3762 self.assertAlmostEqual(i0_sim_err, i0_err)
3763
3764 if do_boot:
3765 values = []
3766 errors = []
3767 times = []
3768 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point):
3769 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time))
3770 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True))
3771 times.append(time)
3772
3773
3774 values = asarray(values)
3775 errors = asarray(errors)
3776 times = asarray(times)
3777
3778 R_m_sim_l = []
3779 I0_m_sim_l = []
3780 for j in range(sim_boot):
3781 if j in range(0, 100000, 100):
3782 print("Simulation %i"%j)
3783
3784
3785
3786 I_err = []
3787 for j, error in enumerate(errors):
3788 I_error = gauss(values[j], error)
3789 I_err.append(I_error)
3790
3791 I_err = asarray(I_err)
3792
3793 x0 = [r2eff, i0]
3794 model = Relax_fit_opt(model='exp', num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list)
3795
3796 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)
3797 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j
3798 R_m_sim_l.append(R_m_sim_j)
3799 I0_m_sim_l.append(I0_m_sim_j)
3800
3801
3802 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1)
3803 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1)
3804 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim
3805 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim
3806
3807
3808
3809 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est')
3810 self.interpreter.pipe.switch(pipe_name='r2eff_est')
3811
3812
3813 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3814 delattr(cur_spin, 'r2eff_err')
3815 delattr(cur_spin, 'i0_err')
3816
3817
3818 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
3819
3820
3821 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0)
3822
3823 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
3824
3825 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
3826
3827 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
3828
3829 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
3830
3831
3832 r2eff_est = getattr(cur_spin, 'r2eff')[param_key]
3833 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key]
3834 i0_est = getattr(cur_spin, 'i0')[param_key]
3835 i0_err_est = getattr(cur_spin, 'i0_err')[param_key]
3836
3837
3838 r2eff = my_dic[spin_id][param_key]['r2eff']
3839 r2eff_err = my_dic[spin_id][param_key]['r2eff_err']
3840 i0 = my_dic[spin_id][param_key]['i0']
3841 i0_err = my_dic[spin_id][param_key]['i0_err']
3842 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim']
3843 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim']
3844
3845 if do_boot:
3846 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot']
3847 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot']
3848 else:
3849 r2eff_boot_err = 0.0
3850 i0_boot_err = 0.0
3851
3852 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) )
3853 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) ),
3854 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) )
3855
3856
3857
3858 estimate_r2eff(method='scipy.optimize.leastsq')
3859
3860 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False)
3861 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True)
3862
3863 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False)
3864 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True)
3865
3866 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False)
3867 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True)
3868
3869 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False)
3870 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True)
3871
3872 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False)
3873 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3874
3875
3876
3878 """Test the relaxation dispersion 'exp_fit' model curve fitting."""
3879
3880
3881 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py')
3882
3883
3884 res_data = [
3885 [15., 10., 20000., 25000.],
3886 [12., 11., 50000., 51000.],
3887 [17., 9., 100000., 96000.]
3888 ]
3889
3890
3891 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw']
3892
3893
3894 for i in range(len(res_data)):
3895
3896 print("\nResidue number %s." % (i+1))
3897
3898
3899 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2)
3900 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2)
3901 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)
3902 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)
3903
3904
3905 self.assertTrue(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0)
3906 self.assertTrue(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0)
3907 self.assertTrue(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0)
3908 self.assertTrue(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0)
3909
3910
3911 for param in blacklist:
3912 print("\tChecking for the absence of the '%s' parameter." % param)
3913 self.assertTrue(not hasattr(cdp.mol[0].res[i].spin[0], param))
3914
3915
3916 self.assertTrue(hasattr(cdp, 'clustering'))
3917 keys = ['free spins', 'cluster']
3918 for key in keys:
3919 self.assertTrue(key in cdp.clustering)
3920 self.assertTrue('test' not in cdp.clustering)
3921 self.assertEqual(cdp.clustering['free spins'], [':2@N'])
3922 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3923
3924
3926 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step."""
3927
3928 times = array([ 0.7, 1., 0.8, 0.4, 0.9])
3929 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341])
3930 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736])
3931
3932 scaling_list = [1.0, 1.0]
3933 model = Relax_fit_opt(model='exp', num_params=2, values=I, errors=errors, relax_times=times, scaling_matrix=scaling_list)
3934
3935 R = - 500.
3936 I0 = 1000.
3937 params = [R, I0]
3938
3939 chi2 = model.func(params)
3940
3941 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2))
3942 self.assertNotEqual(chi2, inf)
3943
3944
4055
4056
4058 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data.
4059
4060 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.
4061 """
4062
4063
4064 ds.models = [
4065 MODEL_NOREX,
4066 MODEL_LM63,
4067 MODEL_CR72,
4068 MODEL_IT99
4069 ]
4070
4071
4072 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py')
4073 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True)
4074
4075
4076 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4077 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4078
4079
4080 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp')
4081 spin70 = return_spin(spin_id=":70")
4082 spin71 = return_spin(spin_id=":71")
4083 print("\n\nOptimised parameters:\n")
4084 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4085 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4086 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4087 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4088 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3)
4089 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3)
4090 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3)
4091 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3)
4092 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3)
4093 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3)
4094
4095
4096 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp')
4097 spin70 = return_spin(spin_id=":70")
4098 spin71 = return_spin(spin_id=":71")
4099 print("\n\nOptimised parameters:\n")
4100 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4101 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4102 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4103 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex))
4104 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4105 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4106 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2)
4107 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2)
4108 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3)
4109 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3)
4110 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3)
4111 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3)
4112 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3)
4113 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3)
4114 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3)
4115 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3)
4116
4117
4118 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp')
4119 spin70 = return_spin(spin_id=":70")
4120 spin71 = return_spin(spin_id=":71")
4121 print("\n\nOptimised parameters:\n")
4122 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4123 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4124 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4125 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4126 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4127 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4128 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4129 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3)
4130 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2)
4131 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3)
4132 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3)
4133 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3)
4134 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3)
4135 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3)
4136 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3)
4137 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3)
4138 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2)
4139 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3)
4140 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4141
4142
4144 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data.
4145
4146 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.
4147 """
4148
4149
4150 ds.models = [
4151 MODEL_NOREX,
4152 MODEL_CR72,
4153 MODEL_NS_CPMG_2SITE_EXPANDED
4154 ]
4155 ds.numeric_only = True
4156
4157
4158 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py')
4159
4160
4161 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4162 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4163
4164
4165 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp')
4166 spin70 = return_spin(spin_id=":70")
4167 spin71 = return_spin(spin_id=":71")
4168 print("\n\nOptimised parameters:\n")
4169 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4170 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4171 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4172 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4173 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3)
4174 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3)
4175 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3)
4176 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3)
4177 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3)
4178 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3)
4179
4180
4181 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp')
4182 spin70 = return_spin(spin_id=":70")
4183 spin71 = return_spin(spin_id=":71")
4184 print("\n\nOptimised parameters:\n")
4185 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4186 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4187 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4188 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4189 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4190 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4191 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4192 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3)
4193 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2)
4194 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3)
4195 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3)
4196 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3)
4197 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3)
4198 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3)
4199 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3)
4200 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3)
4201 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2)
4202 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3)
4203 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4204
4205
4206 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp')
4207 spin70 = return_spin(spin_id=":70")
4208 spin71 = return_spin(spin_id=":71")
4209 print("\n\nOptimised parameters:\n")
4210 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4211 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4212 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4213 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4214 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4215 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4216 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4217 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3)
4218 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3)
4219 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3)
4220 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3)
4221 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3)
4222 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3)
4223 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3)
4224 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3)
4225 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3)
4226 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2)
4227 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3)
4228 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3)
4229
4230
4231 self.interpreter.pipe.switch(pipe_name='final - relax_disp')
4232 spin70 = return_spin(spin_id=":70")
4233 spin71 = return_spin(spin_id=":71")
4234 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded')
4235 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4236
4237
4239 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities).
4240
4241 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.
4242 """
4243
4244
4245 ds.models = [
4246 MODEL_NOREX,
4247 MODEL_LM63,
4248 MODEL_CR72,
4249 MODEL_IT99
4250 ]
4251
4252
4253 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py')
4254 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True)
4255
4256
4257 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4258 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4259
4260
4261 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp')
4262 spin70 = return_spin(spin_id=":70")
4263 spin71 = return_spin(spin_id=":71")
4264 print("\n\nOptimised parameters:\n")
4265 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4266 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4267 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4268 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4269 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3)
4270 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3)
4271 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3)
4272 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3)
4273 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3)
4274 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3)
4275
4276
4277 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp')
4278 spin70 = return_spin(spin_id=":70")
4279 spin71 = return_spin(spin_id=":71")
4280 print("\n\nOptimised parameters:\n")
4281 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4282 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4283 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4284 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex))
4285 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4286 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4287 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2)
4288 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2)
4289 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3)
4290 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3)
4291 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3)
4292 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3)
4293 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3)
4294 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3)
4295 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3)
4296 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3)
4297
4298
4299 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp')
4300 spin70 = return_spin(spin_id=":70")
4301 spin71 = return_spin(spin_id=":71")
4302 print("\n\nOptimised parameters:\n")
4303 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4304 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4305 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4306 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4307 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4308 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4309 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4310 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3)
4311 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2)
4312 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3)
4313 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3)
4314 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3)
4315 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3)
4316 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3)
4317 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3)
4318 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3)
4319 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2)
4320 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3)
4321 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4322
4323
4325 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing.
4326
4327 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.
4328 """
4329
4330
4331 ds.models = [
4332 MODEL_R2EFF,
4333 MODEL_NOREX,
4334 MODEL_CR72,
4335 MODEL_NS_CPMG_2SITE_EXPANDED
4336 ]
4337
4338
4339 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py')
4340 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True)
4341
4342
4343 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4344 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4345
4346
4347 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp')
4348 spin4 = return_spin(spin_id=":4")
4349 spin70 = return_spin(spin_id=":70")
4350 spin71 = return_spin(spin_id=":71")
4351 print("\n\nOptimised parameters:\n")
4352 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)"))
4353 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1]))
4354 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2]))
4355 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2))
4356 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3)
4357 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3)
4358 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3)
4359 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3)
4360 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3)
4361 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3)
4362 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3)
4363 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3)
4364
4365
4366 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp')
4367 spin4 = return_spin(spin_id=":4")
4368 spin70 = return_spin(spin_id=":70")
4369 spin71 = return_spin(spin_id=":71")
4370 print("\n\nOptimised parameters:\n")
4371 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)"))
4372 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1]))
4373 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2]))
4374 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA))
4375 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw))
4376 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex))
4377 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2))
4378 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2)
4379 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3)
4380
4381 self.assertAlmostEqual(spin4.dw, 0.0, 2)
4382 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3)
4383 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3)
4384 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3)
4385 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3)
4386 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3)
4387 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3)
4388 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3)
4389 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3)
4390 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3)
4391 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3)
4392 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2)
4393 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3)
4394 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4395
4396
4398 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model.
4399
4400 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.
4401 """
4402
4403
4404 self.setup_hansen_cpmg_data(model='CR72')
4405
4406
4407 spin70 = return_spin(spin_id=":70")
4408 spin71 = return_spin(spin_id=":71")
4409
4410
4411 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4412 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4413
4414
4415 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0}
4416 spin70.pA = 0.9
4417 spin70.dw = 6.0
4418 spin70.kex = 1500.0
4419 spin71.r2 = {r20_key1: 5, r20_key2: 9.0}
4420 spin71.pA = 0.9
4421 spin71.dw = 4.0
4422 spin71.kex = 1900.0
4423
4424
4425 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)
4426
4427
4428 print("\n\nOptimised parameters:\n")
4429 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4430 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4431 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4432 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4433 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4434 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4435 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4436
4437
4438 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4)
4439 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2)
4440 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4)
4441 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3)
4442 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3)
4443 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4)
4444
4445
4446 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4)
4447 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4)
4448 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4)
4449 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4)
4450 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4)
4451
4452
4453 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4454 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4455
4456
4457 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4458 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4459
4460
4462 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model.
4463
4464 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.
4465 """
4466
4467
4468 self.setup_hansen_cpmg_data(model='CR72 full')
4469
4470
4471 spin70 = return_spin(spin_id=":70")
4472 spin71 = return_spin(spin_id=":71")
4473
4474
4475 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4476 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4477
4478
4479 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0}
4480 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0}
4481 spin70.pA = 0.9
4482 spin70.dw = 6.0
4483 spin70.kex = 1500.0
4484 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0}
4485 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0}
4486 spin71.pA = 0.9
4487 spin71.dw = 4.0
4488 spin71.kex = 1900.0
4489
4490
4491 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)
4492
4493
4494 print("\n\nOptimised parameters:\n")
4495 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4496 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1]))
4497 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1]))
4498 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2]))
4499 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2]))
4500 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4501 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4502 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4503 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4504
4505
4506 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4)
4507 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4)
4508 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4)
4509 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4)
4510 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4)
4511 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4)
4512 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4)
4513 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4)
4514
4515
4516 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4)
4517 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4)
4518 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4)
4519 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4)
4520 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4)
4521 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4)
4522
4523
4524 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4525 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4526
4527
4528 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4529 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4530
4531
4533 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model.
4534
4535 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.
4536 """
4537
4538
4539 self.setup_hansen_cpmg_data(model='IT99')
4540
4541
4542 spin70 = return_spin(spin_id=":70")
4543 spin71 = return_spin(spin_id=":71")
4544
4545
4546 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4547 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4548
4549
4550 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6}
4551 spin70.dw = 10.0
4552 spin70.pA = 0.5
4553 spin70.tex = 1000.09
4554 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0}
4555 spin71.dw = 10.0
4556 spin71.pA = 0.95
4557 spin71.tex = 0.1
4558
4559
4560 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)
4561
4562
4563 print("\n\nOptimised parameters:\n")
4564 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4565 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4566 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4567 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4568 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4569 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex))
4570 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4571
4572
4573 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4)
4574 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4)
4575 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4)
4576 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4)
4577 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4)
4578 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4)
4579
4580
4581 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4)
4582 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4)
4583 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4)
4584 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3)
4585 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4)
4586 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4587
4588
4590 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model.
4591
4592 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.
4593 """
4594
4595
4596 self.setup_hansen_cpmg_data(model='LM63')
4597
4598
4599 spin70 = return_spin(spin_id=":70")
4600 spin71 = return_spin(spin_id=":71")
4601
4602
4603 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4604 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4605
4606
4607 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0}
4608 spin70.phi_ex = 0.3
4609 spin70.kex = 5000.0
4610 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0}
4611 spin71.phi_ex = 0.1
4612 spin71.kex = 2500.0
4613
4614
4615 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)
4616
4617
4618 print("\n\nOptimised parameters:\n")
4619 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4620 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4621 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4622 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex))
4623 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4624 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4625
4626
4627 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099)
4628 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6)
4629 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449)
4630 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6)
4631 self.assertAlmostEqual(spin70.chi2, 363.534044873483)
4632
4633
4634 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5)
4635 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5)
4636 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5)
4637 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4638
4639
4641 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model.
4642
4643 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.
4644 """
4645
4646
4647 self.setup_hansen_cpmg_data(model='LM63 3-site')
4648
4649
4650 spin70 = return_spin(spin_id=":70")
4651 spin71 = return_spin(spin_id=":71")
4652
4653
4654 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4655 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4656
4657
4658 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107}
4659 spin70.phi_ex_B = 0.14872003058250227
4660 spin70.phi_ex_C = 0.1319419923472704
4661 spin70.kB = 4103.672910444741
4662 spin70.kC = 7029.001690726248
4663 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575}
4664 spin71.phi_ex_B = 0.04013553485505605
4665 spin71.phi_ex_C = 0.020050748406928887
4666 spin71.kB = 4045.3007136121364
4667 spin71.kC = 3586.38798270774
4668
4669
4670
4671
4672
4673 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)
4674
4675
4676 print("\n\nOptimised parameters:\n")
4677 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4678 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4679 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4680 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B))
4681 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C))
4682 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB))
4683 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC))
4684 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4685
4686
4687 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5)
4688 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6)
4689 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5)
4690 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5)
4691 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6)
4692 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6)
4693 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5)
4694
4695
4696 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5)
4697 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5)
4698 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5)
4699 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5)
4700 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5)
4701 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4702
4703
4705 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model.
4706
4707 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.
4708 """
4709
4710
4711 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D')
4712
4713
4714 spin70 = return_spin(spin_id=":70")
4715 spin71 = return_spin(spin_id=":71")
4716
4717
4718 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4719 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4720
4721
4722 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427}
4723 spin70.pA = 0.9897754407
4724 spin70.dw = 5.642418428
4725 spin70.kex = 1743.666375
4726 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959}
4727 spin71.pA = 0.9968032899
4728 spin71.dw = 4.577891393
4729 spin71.kex = 1830.044597
4730
4731
4732 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)
4733
4734
4735 print("\n\nOptimised parameters:\n")
4736 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4737 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4738 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4739 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4740 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4741 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4742 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4743
4744
4745 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4)
4746 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4)
4747 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4)
4748 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4)
4749 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4)
4750 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4)
4751
4752
4753 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4)
4754 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4)
4755 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4)
4756 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4)
4757 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4)
4758 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4)
4759
4760
4761 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4762 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4763
4764
4765 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4766 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4767
4768
4770 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model.
4771
4772 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.
4773 """
4774
4775
4776 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full')
4777
4778
4779 spin70 = return_spin(spin_id=":70")
4780 spin71 = return_spin(spin_id=":71")
4781
4782
4783 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4784 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4785
4786
4787 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687}
4788 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395}
4789 spin70.pA = 0.9884781357
4790 spin70.dw = 5.456507396
4791 spin70.kex = 1906.521189
4792 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0}
4793 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0}
4794 spin71.pA = 0.986709616684097
4795 spin71.dw = 2.09245158280905
4796 spin71.kex = 2438.2766211401
4797
4798
4799 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)
4800
4801
4802 print("\n\nOptimised parameters:\n")
4803 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4804 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1]))
4805 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1]))
4806 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2]))
4807 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2]))
4808 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4809 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4810 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4811 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4812
4813
4814 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4)
4815 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4)
4816 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4)
4817 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4)
4818 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4)
4819 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4)
4820 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4)
4821 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4)
4822
4823
4824 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4)
4825 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4)
4826 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4)
4827 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4)
4828 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4)
4829 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4)
4830 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4)
4831 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4)
4832
4833
4834 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4835 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4836
4837
4838 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4839 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4840
4841
4843 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model.
4844
4845 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.
4846 """
4847
4848
4849 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded')
4850
4851
4852 spin70 = return_spin(spin_id=":70")
4853 spin71 = return_spin(spin_id=":71")
4854
4855
4856 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4857 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4858
4859
4860 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0}
4861 spin70.pA = 0.9
4862 spin70.dw = 6.0
4863 spin70.kex = 1500.0
4864 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0}
4865 spin71.pA = 0.9
4866 spin71.dw = 4.0
4867 spin71.kex = 1900.0
4868
4869
4870 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)
4871
4872
4873 print("\n\nOptimised parameters:\n")
4874 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4875 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4876 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4877 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4878 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4879 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4880 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4881
4882
4883 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4)
4884 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4)
4885 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4)
4886 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4)
4887 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4)
4888 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4)
4889
4890
4891 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4)
4892 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4)
4893 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4)
4894 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4)
4895 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4)
4896 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4)
4897
4898
4899 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4900 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4901
4902
4903 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4904 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4905
4906
4908 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model.
4909
4910 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.
4911 """
4912
4913
4914 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star')
4915
4916
4917 spin70 = return_spin(spin_id=":70")
4918 spin71 = return_spin(spin_id=":71")
4919
4920
4921 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4922 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4923
4924
4925 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268}
4926 spin70.pA = 0.9897519798
4927 spin70.dw = 5.644862195
4928 spin70.kex = 1723.820567
4929 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959}
4930 spin71.pA = 0.9968032899
4931 spin71.dw = 4.577891393
4932 spin71.kex = 1830.044597
4933
4934
4935 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)
4936
4937
4938 print("\n\nOptimised parameters:\n")
4939 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)"))
4940 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1]))
4941 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2]))
4942 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA))
4943 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw))
4944 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex))
4945 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2))
4946
4947
4948 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1)
4949 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1)
4950 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3)
4951 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1)
4952 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1)
4953 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1)
4954
4955
4956 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1)
4957 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2)
4958 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2)
4959 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2)
4960 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1)
4961
4962
4963 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA))
4964 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA))
4965
4966
4967 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA)
4968 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4969
4970
4972 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model.
4973
4974 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.
4975 """
4976
4977
4978 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full')
4979
4980
4981 spin70 = return_spin(spin_id=":70")
4982 spin71 = return_spin(spin_id=":71")
4983
4984
4985 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
4986 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
4987
4988
4989 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494}
4990 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402}
4991 spin70.pA = 0.987648082613451
4992 spin70.dw = 5.30679853807572
4993 spin70.kex = 2033.25380420666
4994 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435}
4995 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435}
4996 spin71.pA = 0.992258541625787
4997 spin71.dw = 2.75140650899058
4998 spin71.kex = 2106.60885247431
4999
5000
5001 self.interpreter.minimise.calculate()
5002
5003
5004 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2)
5005 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
5006
5007
5149
5150
5152 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model.
5153
5154 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.
5155
5156 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are:
5157
5158 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887},
5159 - pA = 0.965402506690231,
5160 - dw = 0.805197170133360,
5161 - dwH = -0.595536627771890,
5162 - kex = 569.003663067619868,
5163 - chi2 = 9.297671357952812.
5164 """
5165
5166
5167 self.setup_korzhnev_2005_data(data_list=['DQ'])
5168
5169
5170 spin = return_spin(spin_id=":9@N")
5171
5172
5173 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6)
5174 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6)
5175 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6)
5176
5177
5178 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344}
5179 spin.pA = 0.965638501551899
5180 spin.dw = 2.8537583461577
5181 spin.dwH = -0.387633062766635
5182 spin.kex = 573.704033851592
5183
5184
5185 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5186
5187
5188 self.interpreter.monte_carlo.setup(number=3)
5189 self.interpreter.monte_carlo.create_data(method='back_calc')
5190 self.interpreter.monte_carlo.initial_values()
5191 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5192 self.interpreter.monte_carlo.error_analysis()
5193
5194
5195 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5196
5197
5198 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5199
5200
5201 print("\n\nOptimised parameters:\n")
5202 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5203 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5204 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5205 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5206 print("%-20s %20.15g" % ("pA", spin.pA))
5207 print("%-20s %20.15g" % ("dw", spin.dw))
5208 print("%-20s %20.15g" % ("dwH", spin.dwH))
5209 print("%-20s %20.15g" % ("kex", spin.kex))
5210 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5211
5212
5213 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2)
5214 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2)
5215 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2)
5216 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4)
5217 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1)
5218 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2)
5219 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3)
5220 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5221
5222
5224 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model.
5225
5226 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.
5227
5228 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are:
5229
5230 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019},
5231 - pA = 0.930027999814003,
5232 - dw = 4.338620619954370,
5233 - dwH = -0.274250775560818,
5234 - kex = 344.613362916544475,
5235 - chi2 = 10.367733168217050.
5236 """
5237
5238
5239 self.setup_korzhnev_2005_data(data_list=['MQ'])
5240
5241
5242 spin = return_spin(spin_id=":9@N")
5243
5244
5245 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6)
5246 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6)
5247 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
5248
5249
5250 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622}
5251 spin.pA = 0.930083249288083
5252 spin.dw = 4.33890689462363
5253 spin.dwH = -0.274316585638047
5254 spin.kex = 344.329651956132
5255
5256
5257 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5258
5259
5260 self.interpreter.monte_carlo.setup(number=3)
5261 self.interpreter.monte_carlo.create_data(method='back_calc')
5262 self.interpreter.monte_carlo.initial_values()
5263 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5264 self.interpreter.monte_carlo.error_analysis()
5265
5266
5267 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5268
5269
5270 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5271
5272
5273 print("\n\nOptimised parameters:\n")
5274 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5275 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5276 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5277 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5278 print("%-20s %20.15g" % ("pA", spin.pA))
5279 print("%-20s %20.15g" % ("dw", spin.dw))
5280 print("%-20s %20.15g" % ("dwH", spin.dwH))
5281 print("%-20s %20.15g" % ("kex", spin.kex))
5282 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5283
5284
5285 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1)
5286 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1)
5287 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1)
5288 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3)
5289 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2)
5290 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3)
5291 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3)
5292 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5293
5294
5296 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model.
5297
5298 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.
5299
5300 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are:
5301
5302 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822},
5303 - pA = 0.950003458294991,
5304 - dw = 4.358402855315123,
5305 - kex = 429.906473361926999,
5306 - chi2 = 17.393331915567252.
5307 """
5308
5309
5310 self.setup_korzhnev_2005_data(data_list=['SQ'])
5311
5312
5313 spin = return_spin(spin_id=":9@N")
5314
5315
5316 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
5317 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6)
5318 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
5319
5320
5321 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058}
5322 spin.pA = 0.950310172115387
5323 spin.dw = 4.356737157889636
5324 spin.kex = 433.176323890829849
5325
5326
5327 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5328
5329
5330 self.interpreter.monte_carlo.setup(number=3)
5331 self.interpreter.monte_carlo.create_data(method='back_calc')
5332 self.interpreter.monte_carlo.initial_values()
5333 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5334 self.interpreter.monte_carlo.error_analysis()
5335
5336
5337 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5338
5339
5340 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5341
5342
5343 print("\n\nOptimised parameters:\n")
5344 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5345 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5346 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5347 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5348 print("%-20s %20.15g" % ("pA", spin.pA))
5349 print("%-20s %20.15g" % ("dw", spin.dw))
5350 print("%-20s %20.15g" % ("kex", spin.kex))
5351 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5352
5353
5354 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2)
5355 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2)
5356 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1)
5357 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3)
5358 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2)
5359 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2)
5360 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5361
5362
5364 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model.
5365
5366 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.
5367
5368 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are:
5369
5370 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906},
5371 - pA = 0.942452612380140,
5372 - dw = 0.858972784230892,
5373 - dwH = 0.087155962730608,
5374 - kex = 373.219151384798920,
5375 - chi2 = 23.863208106025152.
5376 """
5377
5378
5379 self.setup_korzhnev_2005_data(data_list=['ZQ'])
5380
5381
5382 spin = return_spin(spin_id=":9@N")
5383
5384
5385 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6)
5386 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6)
5387 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6)
5388
5389
5390 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537}
5391 spin.pA = 0.942457332074014
5392 spin.dw = 0.850592422908884
5393 spin.dwH = 0.0881272284455416
5394 spin.kex = 372.745483351305
5395
5396
5397 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5398
5399
5400 self.interpreter.monte_carlo.setup(number=3)
5401 self.interpreter.monte_carlo.create_data(method='back_calc')
5402 self.interpreter.monte_carlo.initial_values()
5403 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5404 self.interpreter.monte_carlo.error_analysis()
5405
5406
5407 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5408
5409
5410 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5411
5412
5413 print("\n\nOptimised parameters:\n")
5414 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5415 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5416 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5417 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5418 print("%-20s %20.15g" % ("pA", spin.pA))
5419 print("%-20s %20.15g" % ("dw", spin.dw))
5420 print("%-20s %20.15g" % ("dwH", spin.dwH))
5421 print("%-20s %20.15g" % ("kex", spin.kex))
5422 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5423
5424
5425 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2)
5426 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2)
5427 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2)
5428 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4)
5429 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1)
5430 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2)
5431 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3)
5432 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5433
5434
5436 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model.
5437
5438 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.
5439
5440 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are:
5441
5442 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728},
5443 - pA = 0.936911090448340,
5444 - dw = 4.325314846914845,
5445 - dwH = -0.213870168665628,
5446 - kex = 487.361914835074117,
5447 - chi2 = 14.870371897291138.
5448 """
5449
5450
5451 self.setup_korzhnev_2005_data(data_list=['1H MQ'])
5452
5453
5454 spin = return_spin(spin_id=":9@N")
5455
5456
5457 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6)
5458 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6)
5459 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6)
5460
5461
5462 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357}
5463 spin.pA = 0.936884348941701
5464 spin.dw = 4.326454531583964
5465 spin.dwH = -0.214026093221782
5466 spin.kex = 487.043592705469223
5467
5468
5469 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100)
5470
5471
5472 self.interpreter.monte_carlo.setup(number=3)
5473 self.interpreter.monte_carlo.create_data(method='back_calc')
5474 self.interpreter.monte_carlo.initial_values()
5475 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5476 self.interpreter.monte_carlo.error_analysis()
5477
5478
5479 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5480
5481
5482 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5483
5484
5485 print("\n\nOptimised parameters:\n")
5486 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5487 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5488 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5489 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5490 print("%-20s %20.15g" % ("pA", spin.pA))
5491 print("%-20s %20.15g" % ("dw", spin.dw))
5492 print("%-20s %20.15g" % ("dwH", spin.dwH))
5493 print("%-20s %20.15g" % ("kex", spin.kex))
5494 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5495
5496
5497 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4)
5498 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2)
5499 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2)
5500 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4)
5501 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2)
5502 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2)
5503 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4)
5504 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5505
5506
5508 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model.
5509
5510 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.
5511
5512 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are:
5513
5514 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072},
5515 - pA = 0.946949480545876,
5516 - dwH = -0.265279672133308,
5517 - kex = 406.548178869750700,
5518 - chi2 = 50.400680290545026.
5519 """
5520
5521
5522 self.setup_korzhnev_2005_data(data_list=['1H SQ'])
5523
5524
5525 spin = return_spin(spin_id=":9@N")
5526
5527
5528 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6)
5529 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6)
5530 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6)
5531
5532
5533 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077}
5534 spin.pA = 0.946990967372467
5535 spin.dwH = -0.265308128403529
5536 spin.kex = 406.843250675648
5537
5538
5539 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000)
5540
5541
5542 self.interpreter.monte_carlo.setup(number=3)
5543 self.interpreter.monte_carlo.create_data(method='back_calc')
5544 self.interpreter.monte_carlo.initial_values()
5545 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5546 self.interpreter.monte_carlo.error_analysis()
5547
5548
5549 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5550
5551
5552 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5553
5554
5555 print("\n\nOptimised parameters:\n")
5556 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5557 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1]))
5558 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2]))
5559 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3]))
5560 print("%-20s %20.15g" % ("pA", spin.pA))
5561 print("%-20s %20.15g" % ("dwH", spin.dwH))
5562 print("%-20s %20.15g" % ("kex", spin.kex))
5563 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5564
5565
5566 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2)
5567 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2)
5568 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2)
5569 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4)
5570 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3)
5571 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2)
5572 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5573
5574
5576 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model.
5577
5578 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.
5579
5580 Here all data will be optimised. The values found by cpmg_fit using just this data are:
5581
5582 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596,
5583 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709,
5584 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030,
5585 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627,
5586 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979,
5587 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118},
5588 - pA = 0.943125351763911,
5589 - dw = 4.421827493809807,
5590 - dwH = -0.272637034755752,
5591 - kex = 360.609744568697238,
5592 - chi2 = 162.589570340050813.
5593 """
5594
5595
5596 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ'])
5597
5598
5599 spin = return_spin(spin_id=":9@N")
5600
5601
5602 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6)
5603 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6)
5604 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6)
5605 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
5606 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6)
5607 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
5608 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6)
5609 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6)
5610 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6)
5611 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6)
5612 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6)
5613 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6)
5614 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6)
5615 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6)
5616 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6)
5617 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6)
5618 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6)
5619 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
5620
5621
5622 spin.r2 = {
5623 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704,
5624 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930,
5625 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265,
5626 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090,
5627 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380,
5628 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750
5629 }
5630 spin.pA = 0.943129019477673
5631 spin.dw = 4.42209952545181
5632 spin.dwH = -0.27258970590969
5633 spin.kex = 360.516132791038
5634
5635
5636 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10)
5637
5638
5639 self.interpreter.monte_carlo.setup(number=3)
5640 self.interpreter.monte_carlo.create_data(method='back_calc')
5641 self.interpreter.monte_carlo.initial_values()
5642 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10)
5643 self.interpreter.monte_carlo.error_analysis()
5644
5645
5646 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True)
5647
5648
5649 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True)
5650
5651
5652 print("\n\nOptimised parameters:\n")
5653 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5654 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1]))
5655 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2]))
5656 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3]))
5657 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4]))
5658 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5]))
5659 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6]))
5660 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7]))
5661 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8]))
5662 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9]))
5663 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10]))
5664 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11]))
5665 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12]))
5666 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13]))
5667 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14]))
5668 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15]))
5669 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16]))
5670 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17]))
5671 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18]))
5672 print("%-20s %20.15g" % ("pA", spin.pA))
5673 print("%-20s %20.15g" % ("dw", spin.dw))
5674 print("%-20s %20.15g" % ("dwH", spin.dwH))
5675 print("%-20s %20.15g" % ("kex", spin.kex))
5676 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5677
5678
5679 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4)
5680 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4)
5681 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4)
5682 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4)
5683 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4)
5684 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4)
5685 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4)
5686 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4)
5687 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4)
5688 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4)
5689 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4)
5690 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4)
5691 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4)
5692 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4)
5693 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4)
5694 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4)
5695 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4)
5696 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4)
5697 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4)
5698 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4)
5699 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4)
5700 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4)
5701 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5702
5703
5705 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model.
5706
5707 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.
5708
5709 Here all data will be optimised. The values found by cpmg_fit using just this data are:
5710
5711 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596,
5712 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709,
5713 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030,
5714 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627,
5715 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979,
5716 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118},
5717 - pA = 0.943125351763911,
5718 - dw = 4.421827493809807,
5719 - dwH = -0.272637034755752,
5720 - kex = 360.609744568697238,
5721 - chi2 = 162.589570340050813.
5722 """
5723
5724
5725 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ'])
5726
5727
5728 spin = return_spin(spin_id=":9@N")
5729
5730
5731 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6)
5732 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6)
5733 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6)
5734 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
5735 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6)
5736 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
5737 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6)
5738 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6)
5739 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6)
5740 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6)
5741 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6)
5742 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6)
5743 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6)
5744 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6)
5745 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6)
5746 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6)
5747 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6)
5748 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
5749
5750
5751 spin.r2 = {
5752 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704,
5753 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930,
5754 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265,
5755 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090,
5756 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380,
5757 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750
5758 }
5759 spin.pA = 0.943129019477673
5760 spin.dw = 4.42209952545181
5761 spin.dwH = -0.27258970590969
5762 spin.kex = 360.516132791038
5763
5764
5765 self.interpreter.minimise.calculate(verbosity=1)
5766
5767
5768 print("\n\nOptimised parameters:\n")
5769 print("%-20s %-20s" % ("Parameter", "Value (:9)"))
5770 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1]))
5771 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2]))
5772 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3]))
5773 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4]))
5774 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5]))
5775 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6]))
5776 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7]))
5777 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8]))
5778 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9]))
5779 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10]))
5780 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11]))
5781 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12]))
5782 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13]))
5783 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14]))
5784 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15]))
5785 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16]))
5786 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17]))
5787 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18]))
5788 print("%-20s %20.15g" % ("pA", spin.pA))
5789 print("%-20s %20.15g" % ("dw", spin.dw))
5790 print("%-20s %20.15g" % ("dwH", spin.dwH))
5791 print("%-20s %20.15g" % ("kex", spin.kex))
5792 print("%-20s %20.15g\n" % ("chi2", spin.chi2))
5793
5794
5795 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5796
5797
5799 """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.
5800
5801 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).
5802
5803 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are:
5804
5805 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1]
5806 - 0.483 0.89623903 2.4503699912708878
5807 - 0.545 1.1694838
5808 - 0.545 1.1761503
5809 - 0.622 1.294
5810 - 0.669 1.5176493
5811 - 0.722 1.6238791
5812 - 0.813 1.9395758
5813 - 1.011 2.3558415 10.547000429321157
5814 """
5815
5816
5817 model = 'TSMFK01'
5818 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223"
5819 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder)
5820
5821
5822 res61L = cdp.mol[0].res[0].spin[0]
5823
5824
5825 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6)
5826
5827
5828 res61L.r2a = {r20_key1: 8.0}
5829 res61L.dw = 6.5
5830 res61L.k_AB = 2.5
5831
5832
5833 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)
5834
5835
5836 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO]
5837 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF]
5838 interpolate_types = [INTERPOLATE_DISP]
5839
5840
5841 result_dir_name = ds.tmpdir
5842 result_folders = [model]
5843 spin_id = ":61@N"
5844
5845
5846 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs'
5847
5848 for result_folder in result_folders:
5849 for y_axis in y_axis_types:
5850 for x_axis in x_axis_types:
5851 for interpolate in interpolate_types:
5852
5853 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate)
5854
5855
5856 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_'))
5857
5858
5859 dir = result_dir_name+sep+result_folder
5860 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate))
5861 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True)
5862
5863
5864 file_path = get_file_path(file_name, dir)
5865
5866
5867 print("Testing file access to graph: %s"%file_path)
5868 self.assertTrue(access(file_path, F_OK))
5869
5870
5871 file_prod = open(file_path)
5872 lines_prod = file_prod.readlines()
5873 file_prod.close()
5874
5875
5876 dir_comp = data_path+sep+result_folder
5877 file_path_comp = get_file_path(file_name, dir_comp)
5878 file_comp = open(file_path_comp)
5879 lines_comp = file_comp.readlines()
5880 file_comp.close()
5881
5882
5883 self.assertEqual(len(lines_prod), len(lines_comp))
5884 for j in range(len(lines_prod)):
5885
5886 first_char = lines_prod[j][0]
5887 if first_char in ["@", "&"]:
5888 self.assertEqual(lines_prod[j], lines_comp[j])
5889 else:
5890
5891
5892 x_prod, y_prod, y_prod_err = lines_prod[j].split()
5893 x_comp, y_comp, y_comp_err = lines_comp[j].split()
5894 self.assertAlmostEqual(float(x_prod), float(x_comp))
5895 self.assertAlmostEqual(float(y_prod), float(y_comp))
5896 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5897
5898
5900 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
5901
5902 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).
5903 """
5904
5905
5906 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223")
5907
5908
5909 res61L = cdp.mol[0].res[0].spin[0]
5910
5911
5912 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6)
5913
5914
5915 res61L.r2 = {r20_key1: 8.0}
5916 res61L.pA = 0.9
5917 res61L.dw = 6.0
5918 res61L.kex = 600.0
5919
5920
5921 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)
5922
5923
5924 print("\n\nOptimised parameters:\n")
5925 print("%-20s %-20s" % ("Parameter", "Value (:61)"))
5926 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1]))
5927 print("%-20s %20.15g" % ("pA", res61L.pA))
5928 print("%-20s %20.15g" % ("dw", res61L.dw))
5929 print("%-20s %20.15g" % ("kex", res61L.kex))
5930 print("%-20s %20.15g\n" % ("chi2", res61L.chi2))
5931
5932
5933 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4)
5934 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5)
5935 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3)
5936 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0)
5937 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5)
5938
5939
5940 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA))
5941
5942
5943 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5944
5945
5947 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
5948
5949 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).
5950 """
5951
5952
5953 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223")
5954
5955
5956 res61L = cdp.mol[0].res[0].spin[0]
5957
5958
5959 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6)
5960
5961
5962 res61L.r2a = {r20_key1: 8.0}
5963 res61L.r2b = {r20_key1: 105.0}
5964 res61L.pA = 0.9
5965 res61L.dw = 6.0
5966 res61L.kex = 500.0
5967
5968
5969 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)
5970
5971
5972 print("\n\nOptimised parameters:\n")
5973 print("%-20s %-20s" % ("Parameter", "Value (:61)"))
5974 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1]))
5975 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1]))
5976 print("%-20s %20.15g" % ("pA", res61L.pA))
5977 print("%-20s %20.15g" % ("dw", res61L.dw))
5978 print("%-20s %20.15g" % ("kex", res61L.kex))
5979 print("%-20s %20.15g\n" % ("chi2", res61L.chi2))
5980
5981
5982 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0)
5983 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2)
5984 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2)
5985 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3)
5986 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2)
5987 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5988
5989
5991 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
5992
5993 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).
5994
5995 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are:
5996
5997 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1]
5998 - 0.483 0.89623903 2.4503699912708878
5999 - 0.545 1.1694838
6000 - 0.545 1.1761503
6001 - 0.622 1.294
6002 - 0.669 1.5176493
6003 - 0.722 1.6238791
6004 - 0.813 1.9395758
6005 - 1.011 2.3558415 10.547000429321157
6006 """
6007
6008
6009 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223")
6010
6011
6012 res61L = cdp.mol[0].res[0].spin[0]
6013
6014
6015 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6)
6016
6017
6018 res61L.r2a = {r20_key1: 8.0}
6019 res61L.dw = 6.5
6020 res61L.k_AB = 2.5
6021
6022
6023 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)
6024
6025
6026 print("\n\nOptimised parameters:\n")
6027 print("%-20s %-20s" % ("Parameter", "Value (:61)"))
6028 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1]))
6029 print("%-20s %20.15g" % ("dw", res61L.dw))
6030 print("%-20s %20.15g" % ("k_AB", res61L.k_AB))
6031 print("%-20s %20.15g\n" % ("chi2", res61L.chi2))
6032
6033
6034
6035 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
6036
6037
6039 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model.
6040
6041 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).
6042
6043 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.
6044
6045 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:
6046
6047 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1:
6048 - k_AB = 11.3 +/- 0.7 s^-1,
6049 - dw = (2.45 +/- 0.09) * 10^3 s^-1,
6050 - R2 = 8.0 +/- 0.5 s^-1.
6051
6052 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.:
6053 - k_AB = 10.55 +/- 0.08 s^-1,
6054 - dw = (2.44 +/- 0.08) * 10^3 s^-1,
6055 - R2 = 8.4 +/- 0.3 s^-1.
6056
6057 Conversion of paper results to relax results is performed by:
6058
6059 - 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.
6060
6061 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are:
6062
6063 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1]
6064 - 0.483 0.89623903 2.4503699912708878
6065 - 0.545 1.1694838
6066 - 0.545 1.1761503
6067 - 0.622 1.294
6068 - 0.669 1.5176493
6069 - 0.722 1.6238791
6070 - 0.813 1.9395758
6071 - 1.011 2.3558415 10.547000429321157
6072 """
6073
6074
6075 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223")
6076
6077
6078 res61L = cdp.mol[0].res[0].spin[0]
6079
6080
6081 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6)
6082
6083
6084 res61L.r2a = {r20_key1: 8.0}
6085 res61L.dw = 6.5
6086 res61L.k_AB = 11.0
6087
6088
6089 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)
6090
6091
6092 print("\n\nOptimised parameters:\n")
6093 print("%-20s %-20s" % ("Parameter", "Value (:61)"))
6094 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1]))
6095 print("%-20s %20.15g" % ("dw", res61L.dw))
6096 print("%-20s %20.15g" % ("k_AB", res61L.k_AB))
6097 print("%-20s %20.15g\n" % ("chi2", res61L.chi2))
6098
6099
6100
6101 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0)
6102 self.assertAlmostEqual(res61L.dw, 6.41, 0)
6103 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
6104
6105
6107 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data."""
6108
6109
6110 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site'
6111
6112
6113 self.interpreter.reset()
6114 self.interpreter.state.load(data_path+sep+'r2eff_values')
6115
6116
6117 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp')
6118 self.interpreter.pipe.switch(pipe_name='LM63 3-site')
6119
6120
6121 self.interpreter.relax_disp.select_model(model='LM63 3-site')
6122 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff')
6123 self.interpreter.spin.isotope('15N')
6124
6125
6126 spin1 = return_spin(spin_id=":1")
6127 spin2 = return_spin(spin_id=":2")
6128
6129
6130 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6)
6131 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6)
6132
6133
6134 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0}
6135 spin1.phi_ex_B = 0.1
6136 spin1.phi_ex_C = 0.5
6137 spin1.kB = 1500.0
6138 spin1.kC = 2500.0
6139 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0}
6140 spin2.phi_ex_B = 0.1
6141 spin2.phi_ex_C = 0.5
6142 spin2.kB = 1500.0
6143 spin2.kC = 2500.0
6144
6145
6146 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)
6147
6148
6149 self.interpreter.monte_carlo.setup(number=3)
6150 self.interpreter.monte_carlo.create_data(method='back_calc')
6151 self.interpreter.monte_carlo.initial_values()
6152 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)
6153 self.interpreter.monte_carlo.error_analysis()
6154
6155
6156 self.interpreter.results.write(file='devnull', compress_type=1, force=True)
6157
6158
6159 print("\n\nOptimised parameters:\n")
6160 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)"))
6161 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1]))
6162 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2]))
6163 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B))
6164 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C))
6165 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB))
6166 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC))
6167 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
6168 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2)
6169 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2)
6170 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3)
6171 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3)
6172 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3)
6173 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3)
6174 self.assertAlmostEqual(spin1.chi2, 0.0, 3)
6175 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3)
6176 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3)
6177 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3)
6178 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3)
6179 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3)
6180 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3)
6181 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
6182
6183
6185 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data."""
6186
6187
6188 ds.fixed = True
6189
6190
6191 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')
6192
6193
6194 i0 = [100000.0, 20000.0]
6195 r1rho_prime = [2.25, 24.0]
6196 pA = 0.7
6197 kex = 1000.0
6198 delta_omega = [1.0, 2.0]
6199 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']
6200 phi_ex = []
6201 for i in range(2):
6202 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2)
6203 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]]
6204
6205
6206 self.interpreter.pipe.switch('R2eff - relax_disp')
6207 spin_index = 0
6208 for spin, spin_id in spin_loop(return_id=True):
6209
6210 print("\nSpin %s." % spin_id)
6211
6212
6213 for i in range(len(keys)):
6214 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2)
6215
6216
6217 spin_index += 1
6218
6219
6220 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
6221
6222
6223 self.interpreter.pipe.switch('M61 - relax_disp')
6224 spin_index = 0
6225 for spin, spin_id in spin_loop(return_id=True):
6226
6227 print("\nSpin %s." % spin_id)
6228
6229
6230 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2)
6231 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2)
6232 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2)
6233
6234
6235 spin_index += 1
6236
6237
6239 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data."""
6240
6241
6242 ds.fixed = False
6243
6244
6245 ds.single = True
6246
6247
6248 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')
6249
6250
6251 i0 = [100000.0, 20000.0]
6252 r1rho_prime = [2.25, 24.0]
6253 pA = 0.7
6254 kex = 1000.0
6255 delta_omega = [1.0, 2.0]
6256 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']
6257 phi_ex = []
6258 for i in range(2):
6259 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2)
6260 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]]
6261
6262
6263 self.interpreter.pipe.switch('R2eff - relax_disp')
6264 spin_index = 0
6265 for spin, spin_id in spin_loop(return_id=True):
6266
6267 print("\nSpin %s." % spin_id)
6268
6269
6270 for i in range(len(keys)):
6271 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2)
6272
6273
6274 spin_index += 1
6275
6276
6277 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
6278
6279
6280 self.interpreter.pipe.switch('M61 - relax_disp')
6281 spin_index = 0
6282 for spin, spin_id in spin_loop(return_id=True):
6283
6284 print("\nSpin %s." % spin_id)
6285
6286
6287 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2)
6288 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2)
6289 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2)
6290
6291
6292 spin_index += 1
6293
6294
6296 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data."""
6297
6298
6299 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')
6300
6301
6302 i0 = [100000.0, 20000.0]
6303 r1rho_prime = [10.0, 24.0]
6304 pA = 0.95
6305 kex = 2000.0
6306 delta_omega = [1.0, 2.0]
6307
6308
6309 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
6310
6311
6312 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B)
6313 spin_index = 0
6314 for spin, spin_id in spin_loop(return_id=True):
6315
6316 print("\nSpin %s." % spin_id)
6317
6318
6319 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2)
6320 self.assertAlmostEqual(spin.pA, pA, 2)
6321 self.assertAlmostEqual(spin.dw, dw[spin_index], 2)
6322 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2)
6323
6324
6325 spin_index += 1
6326
6327
6329 """Test that all models which can nest, have all their parameters converted."""
6330
6331
6332 cdp.exp_type_list = copy.deepcopy(EXP_TYPE_LIST)
6333
6334
6335 all_models_info = models_info(models=MODEL_LIST_FULL)
6336
6337
6338 print("Printing the listed of nested models for each model.")
6339 print("####################################################")
6340 for model_info in all_models_info:
6341 print("%s"%model_info.model),
6342 print("<-"),
6343 nest_list = model_info.nest_list
6344 if nest_list == None:
6345 nest_list = ["None"]
6346 print(', '.join(map(str, nest_list)))
6347
6348
6349 if nest_list == ["None"]:
6350 continue
6351
6352
6353 model_params = model_info.params
6354
6355
6356 for nested_model in nest_list:
6357
6358 nested_model_params = copy.deepcopy(MODEL_PARAMS[nested_model])
6359
6360
6361 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params)
6362
6363
6364 self.assertEqual(len(par_dic), len(model_params))
6365
6366
6367 for param in par_dic:
6368 if param != par_dic[param]:
6369 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param))
6370 self.assertNotEqual(par_dic[param], None)
6371
6372
6374 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit."""
6375
6376
6377 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py')
6378
6379
6380 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6381
6382
6384 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit."""
6385
6386
6387 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')
6388
6389
6390 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6391
6392
6394 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit."""
6395
6396
6397 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py')
6398
6399
6400 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6401
6402
6404 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit."""
6405
6406
6407 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')
6408
6409
6410 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6411
6412
6414 """This test truncated private data which was provided by Paul Schanda. This systemtest uncovers some unfortunate problems when
6415 running an analysis and reading points by the R2eff method.
6416 """
6417
6418
6419 outdir = ds.tmpdir
6420
6421
6422 self.setup_paul_schanda_nov_2015(outdir=outdir)
6423
6424
6425 self.interpreter.sequence.read(file='residues.txt', res_num_col=1, dir=outdir)
6426
6427
6428 set_file = open(outdir+sep+"exp_settings.txt")
6429 set_file_lines = set_file.readlines()
6430
6431
6432 for line in set_file_lines:
6433 if "#" in line[0]:
6434 continue
6435
6436
6437 field, RF_field_strength_kHz, f_name = line.split()
6438
6439
6440 spec_id = f_name
6441 self.interpreter.relax_disp.exp_type(spectrum_id=spec_id, exp_type='R1rho')
6442
6443
6444 self.interpreter.spectrometer.frequency(id=spec_id, frq=float(field), units='MHz')
6445
6446
6447 disp_frq = float(RF_field_strength_kHz)*1000
6448
6449
6450 self.interpreter.relax_disp.spin_lock_field(spectrum_id=spec_id, field=disp_frq)
6451
6452
6453 self.interpreter.relax_disp.r2eff_read(id=spec_id, file=f_name, dir=None, disp_frq=disp_frq, res_num_col=1, data_col=2, error_col=3)
6454
6455
6456
6457
6458
6459
6460 r2eff_points = []
6461 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
6462
6463 for key in cur_spin.r2eff:
6464 value = cur_spin.r2eff[key]
6465 err = cur_spin.r2eff_err[key]
6466 r2eff_points.append(value)
6467
6468
6469 self.assertTrue(not isnan(value))
6470 self.assertTrue(not isnan(err))
6471
6472
6473
6474 self.assertEqual(len(r2eff_points), 2*(10+19)-1)
6475
6476
6477 self.assertEqual(len(cdp.mol), 1)
6478 self.assertEqual(cdp.mol[0].name, None)
6479 self.assertEqual(len(cdp.mol[0].res), 2)
6480
6481 self.assertEqual(cdp.spectrometer_frq_count, 2)
6482 self.assertEqual(cdp.spectrometer_frq_list, [600000000.0, 950000000.0])
6483 self.assertEqual(cdp.exp_type_list, ['R1rho'])
6484
6485
6486 count_600 = 0
6487 count_950 = 0
6488 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
6489 if frq == cdp.spectrometer_frq_list[0]:
6490 count_600 += 1
6491 elif frq == cdp.spectrometer_frq_list[1]:
6492 count_950 += 1
6493
6494
6495 self.assertEqual(count_600, 10)
6496 self.assertEqual(count_950, 19)
6497
6498
6499 self.interpreter.spin.isotope(isotope='15N')
6500
6501
6502 self.assertRaises(RelaxError, self.interpreter.relax_disp.plot_disp_curves, dir=outdir, y_axis='r2_eff', x_axis='disp', num_points=1000, extend_hz=500.0, extend_ppm=500.0, interpolate='disp', force=True)
6503 self.interpreter.relax_disp.select_model(model=MODEL_R2EFF)
6504 self.interpreter.relax_disp.plot_disp_curves(dir=outdir, y_axis='r2_eff', x_axis='disp', num_points=1000, extend_hz=500.0, extend_ppm=500.0, interpolate='disp', force=True)
6505
6506
6507
6508
6509 GRID_INC = 21
6510
6511 MC_NUM = 3
6512
6513 MODSEL = 'AIC'
6514
6515 MODELS = [MODEL_NOREX, MODEL_M61]
6516
6517 r1_fit = False
6518
6519 set_grid_r20=True
6520
6521
6522
6523 OPT_FUNC_TOL = 1e-1
6524 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
6525 OPT_MAX_ITERATIONS = 1000
6526 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
6527
6528
6529 relax_disp.Relax_disp(pipe_name="relax_disp", pipe_bundle="relax_disp", results_dir=outdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit)
6530
6531
6532 self.interpreter.deselect.all()
6533 sel_ids = [
6534 ":12",
6535 ":51",
6536 ]
6537 for sel_spin in sel_ids:
6538 print("Selecting spin %s"%sel_spin)
6539 self.interpreter.select.spin(spin_id=sel_spin, change_all=False)
6540
6541
6542 cluster_ids = sel_ids
6543
6544
6545 for curspin in cluster_ids:
6546 print("Adding spin %s to cluster"%curspin)
6547 self.interpreter.relax_disp.cluster('model_cluster', curspin)
6548
6549
6550 print("\nPrinting all the available pipes.")
6551 self.interpreter.pipe.display()
6552
6553
6554 print("\nChecking which model is stored per spin.")
6555 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False):
6556 print("For spin_id '%s the model is '%s''"%(spin_id, curspin.model))
6557
6558
6559 self.interpreter.pipe.copy(pipe_from="final - relax_disp", pipe_to="relax_disp_cluster", bundle_to="relax_disp_cluster")
6560 self.interpreter.pipe.switch(pipe_name="relax_disp_cluster")
6561 self.interpreter.pipe.display()
6562
6563
6564 relax_disp.Relax_disp(pipe_name="relax_disp_cluster", pipe_bundle="relax_disp_cluster", results_dir=outdir+sep+"cluster", models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=None, modsel=MODSEL, pre_run_dir=None, optimise_r2eff=False, insignificance=0.0, numeric_only=False, mc_sim_all_models=False, eliminate=True, set_grid_r20=set_grid_r20, r1_fit=r1_fit)
6565
6566
6567 print("\nChecking which value is stored per spin.")
6568 kex = None
6569 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False):
6570 if kex == None:
6571 kex = curspin.kex
6572 self.assertEqual(curspin.kex, kex)
6573 print("For spin_id %s the kex is %.3f"%(spin_id, kex))
6574
6575
6577 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg.
6578
6579 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.
6580 """
6581
6582
6583 self.interpreter.reset()
6584
6585
6586 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'
6587
6588
6589 sdic = {}
6590
6591
6592 sfrq_1 = 499.86214
6593 sfrq_2 = 599.8908587
6594 sfrqs = [sfrq_1, sfrq_2]
6595
6596
6597 sdic['sfrqs'] = sfrqs
6598
6599
6600 sdic['sfrq_unit'] = 'MHz'
6601
6602
6603 sdic['exp_type'] = 'SQ CPMG'
6604
6605
6606 sdic['isotope'] = '15N'
6607
6608
6609 sdic['int_method'] = 'height'
6610
6611
6612 sdic['time'] = '2014_09'
6613
6614
6615 for frq in sfrqs:
6616 key = DIC_KEY_FORMAT % (frq)
6617 sdic[key] = {}
6618
6619
6620 e_1 = DIC_KEY_FORMAT % (sfrq_1)
6621 e_2 = DIC_KEY_FORMAT % (sfrq_2)
6622
6623
6624 sdic[e_1]['time_T2'] = 0.04
6625 sdic[e_2]['time_T2'] = 0.06
6626
6627
6628 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0])
6629 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22])
6630
6631
6632 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2']
6633 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2']
6634
6635
6636 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files'
6637 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files'
6638 sdic[e_1]['peaks_folder'] = peaks_folder_1
6639 sdic[e_2]['peaks_folder'] = peaks_folder_2
6640
6641
6642 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data'
6643 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data'
6644 sdic[e_1]['rmsd_folder'] = rmsd_folder_1
6645 sdic[e_2]['rmsd_folder'] = rmsd_folder_2
6646
6647
6648 sdic['results_dir'] = self.tmpdir
6649
6650
6651 RDR = Relax_disp_rep(sdic)
6652
6653
6654 RDR.set_base_cpmg(method='FT', glob_ini=128)
6655
6656 methods = ['FT', 'MDD']
6657
6658
6659
6660
6661
6662
6663
6664 if True:
6665 selection = None
6666
6667
6668 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection)
6669
6670
6671 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection)
6672
6673
6674 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]]
6675 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]]
6676 corr_data = [fig1, fig2]
6677
6678 write_stats = True
6679 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats)
6680
6681
6682 if write_stats:
6683 for i, corr_data_i in enumerate(corr_data):
6684 data, methods, glob_inis = corr_data[i]
6685 data_x, data_y = data
6686 method_x, method_y = methods
6687 glob_ini_x, glob_ini_y = glob_inis
6688 x = data_x[str(glob_ini_x)]['peak_intensity_arr']
6689 np = len(x)
6690
6691 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np)
6692
6693 if selection == None:
6694 file_name = file_name_ini + '_all.txt'
6695 else:
6696 file_name = file_name_ini + '_sel.txt'
6697 path = RDR.results_dir
6698 data = extract_data(file=file_name, dir=path)
6699
6700
6701 for i, data_i in enumerate(data):
6702 print(i, data_i)
6703
6704
6705
6706 if True:
6707
6708 selections = [None, ':2,3']
6709 for selection in selections:
6710 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection)
6711 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection)
6712
6713
6714 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126])
6715
6716
6717 write_stats = True
6718 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats)
6719
6720
6721 if write_stats:
6722 if selection == None:
6723 file_name = 'int_stat_all.txt'
6724 else:
6725 file_name = 'int_stat_sel.txt'
6726 path = RDR.results_dir
6727 data = extract_data(file=file_name, dir=path)
6728
6729
6730 for i, data_i in enumerate(data):
6731 print(i, data_i)
6732
6733
6734
6735 if True:
6736 selection = None
6737
6738 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection)
6739
6740
6741 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection)
6742
6743
6744 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]]
6745 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]]
6746 corr_data = [fig1, fig2]
6747
6748 write_stats = True
6749 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats)
6750
6751
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 x = data_x[str(glob_ini_x)]['r2eff_arr']
6759 np = len(x)
6760
6761 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np)
6762
6763 if selection == None:
6764 file_name = file_name_ini + '_all.txt'
6765 else:
6766 file_name = file_name_ini + '_sel.txt'
6767 path = RDR.results_dir
6768 data = extract_data(file=file_name, dir=path)
6769
6770
6771 for i, data_i in enumerate(data):
6772 print(i, data_i)
6773
6774
6775
6776 if True:
6777
6778 selections = [None, ':2,3']
6779 for selection in selections:
6780 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection)
6781 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection)
6782
6783
6784 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126])
6785
6786
6787 write_stats = True
6788 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)
6789
6790
6791 if write_stats:
6792 if selection == None:
6793 file_name = 'r2eff_stat_all.txt'
6794 else:
6795 file_name = 'r2eff_stat_sel.txt'
6796 path = RDR.results_dir
6797 data = extract_data(file=file_name, dir=path)
6798
6799
6800 for i, data_i in enumerate(data):
6801 print(i, data_i)
6802
6803
6804
6805 if True:
6806 methods = ['FT', 'MDD']
6807
6808 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126])
6809
6810 min_methods = [['FT'], ['MDD']]
6811 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]]
6812
6813
6814
6815
6816 selection = None
6817
6818 for i, methods in enumerate(min_methods):
6819 list_glob_ini = min_list_glob_ini[i]
6820
6821 if True:
6822
6823 if True:
6824
6825 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini)
6826
6827
6828 if True:
6829
6830 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)
6831
6832
6833 if True:
6834
6835 method = methods[0]
6836 glob_ini = list_glob_ini[0]
6837
6838 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini)
6839 RDR.spin_display_params(pipe_name=test_pipe_name)
6840
6841
6842 if True:
6843
6844 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)
6845
6846
6847 if True:
6848
6849 RDR.opt_max_iterations = int(1e2)
6850 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True)
6851
6852
6853
6854
6855
6856 if True:
6857 selections = [None, ':2,3']
6858 for selection in selections:
6859
6860 analysis = 'min_ind'
6861 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection)
6862 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection)
6863
6864 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]]
6865 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]]
6866 corr_data = [fig1, fig2]
6867
6868 write_stats = True
6869 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats)
6870
6871
6872 if write_stats:
6873 for i, corr_data_i in enumerate(corr_data):
6874 data, methods, glob_inis = corr_data[i]
6875 data_x, data_y = data
6876 method_x, method_y = methods
6877 glob_ini_x, glob_ini_y = glob_inis
6878
6879 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y)
6880
6881 if selection == None:
6882 file_name = file_name_ini + '_all.txt'
6883 else:
6884 file_name = file_name_ini + '_sel.txt'
6885 path = RDR.results_dir
6886 data = extract_data(file=file_name, dir=path)
6887
6888
6889 for i, data_i in enumerate(data):
6890 print(i, data_i)
6891
6892
6893 if True:
6894
6895
6896 selections = [None, ':2,3']
6897 for selection in selections:
6898 analysis = 'min_ind'
6899 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection)
6900 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection)
6901
6902
6903 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126])
6904
6905
6906 write_stats = True
6907 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)
6908
6909
6910 if write_stats:
6911 if selection == None:
6912 file_name = '%s_stat_all.txt' % (analysis)
6913 else:
6914 file_name = '%s_stat_sel.txt' % (analysis)
6915 path = RDR.results_dir
6916 data = extract_data(file=file_name, dir=path)
6917
6918
6919 for i, data_i in enumerate(data):
6920 print(i, data_i)
6921
6922
6923
6924 if True:
6925 methods = ['FT', 'MDD']
6926
6927 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126])
6928
6929 min_methods = [['FT'], ['MDD']]
6930 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]]
6931
6932
6933
6934 selection = ':2,3'
6935
6936 for i, methods in enumerate(min_methods):
6937 list_glob_ini = min_list_glob_ini[i]
6938
6939 if True:
6940
6941 if True:
6942
6943 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini)
6944
6945
6946 if True:
6947
6948 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)
6949
6950 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True)
6951
6952
6953 if True:
6954
6955 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)
6956 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)
6957
6958
6959 if True:
6960
6961 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True)
6962
6963
6964 if True:
6965
6966 method = methods[0]
6967 glob_ini = list_glob_ini[0]
6968
6969 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini)
6970 RDR.spin_display_params(pipe_name=test_pipe_name)
6971
6972
6973 if True:
6974
6975 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)
6976
6977
6978 if True:
6979 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True)
6980
6981
6982 if True:
6983
6984 RDR.opt_max_iterations = int(1e2)
6985 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False)
6986
6987
6988
6989 if True:
6990 selection = ':2,3'
6991
6992 analysis = 'min'
6993 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection)
6994 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection)
6995
6996 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]]
6997 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]]
6998 corr_data = [fig1, fig2]
6999
7000 write_stats = True
7001 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats)
7002
7003
7004 if write_stats:
7005 for i, corr_data_i in enumerate(corr_data):
7006 data, methods, glob_inis = corr_data[i]
7007 data_x, data_y = data
7008 method_x, method_y = methods
7009 glob_ini_x, glob_ini_y = glob_inis
7010
7011 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y)
7012
7013 if selection == None:
7014 file_name = file_name_ini + '_all.txt'
7015 else:
7016 file_name = file_name_ini + '_sel.txt'
7017 path = RDR.results_dir
7018 data = extract_data(file=file_name, dir=path)
7019
7020
7021 for i, data_i in enumerate(data):
7022 print(i, data_i)
7023
7024
7025 if True:
7026
7027 selections = [':2,3']
7028 for selection in selections:
7029 analysis = 'min'
7030 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection)
7031 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection)
7032
7033
7034 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126])
7035
7036
7037 write_stats = True
7038 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)
7039
7040
7041 if write_stats:
7042 if selection == None:
7043 file_name = '%s_stat_all.txt' % (analysis)
7044 else:
7045 file_name = '%s_stat_sel.txt' % (analysis)
7046 path = RDR.results_dir
7047 data = extract_data(file=file_name, dir=path)
7048
7049
7050 for i, data_i in enumerate(data):
7051 print(i, data_i)
7052
7053
7055 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
7056
7057 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
7058
7059 This uses the automatic analysis.
7060
7061 """
7062
7063
7064 cluster_ids = [
7065 ":13@N",
7066 ":15@N",
7067 ":16@N",
7068 ":25@N",
7069 ":26@N",
7070 ":28@N",
7071 ":39@N",
7072 ":40@N",
7073 ":41@N",
7074 ":43@N",
7075 ":44@N",
7076 ":45@N",
7077 ":49@N",
7078 ":52@N",
7079 ":53@N"]
7080
7081
7082 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids)
7083
7084
7085 self.assertEqual(len(cdp.mol), 1)
7086 self.assertEqual(cdp.mol[0].name, None)
7087 self.assertEqual(len(cdp.mol[0].res), 48)
7088
7089
7090 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393,
7091 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279,
7092 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160,
7093 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]
7094
7095 i = 0
7096 for spin, spin_id in spin_loop(return_id=True):
7097
7098 self.assertEqual(spin.chemical_shift, cs[i])
7099
7100
7101 i += 1
7102
7103
7104 i = 0
7105 j = 0
7106
7107 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False):
7108 if curspin.select == True:
7109 i += 1
7110 if curspin.select == False:
7111 j += 1
7112
7113
7114 self.assertEqual(i, len(cluster_ids))
7115 self.assertEqual(j, 48-len(cluster_ids))
7116
7117
7118 self.assertEqual(cdp.mol[0].res[7].num, 13)
7119 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6])
7120 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2])
7121
7122 self.assertEqual(cdp.mol[0].res[9].num, 15)
7123 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6])
7124 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2])
7125
7126 self.assertEqual(cdp.mol[0].res[10].num, 16)
7127 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6])
7128 self.assertTrue(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data'))
7129
7130 self.assertEqual(cdp.mol[0].res[16].num, 25)
7131 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6])
7132 self.assertTrue(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data'))
7133
7134 self.assertEqual(cdp.mol[0].res[17].num, 26)
7135 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6])
7136 self.assertTrue(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data'))
7137
7138 self.assertEqual(cdp.mol[0].res[19].num, 28)
7139 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6])
7140 self.assertTrue(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data'))
7141
7142 self.assertEqual(cdp.mol[0].res[29].num, 39)
7143 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6])
7144 self.assertTrue(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data'))
7145
7146 self.assertEqual(cdp.mol[0].res[30].num, 40)
7147 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6])
7148 self.assertTrue(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data'))
7149
7150 self.assertEqual(cdp.mol[0].res[31].num, 41)
7151 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6])
7152 self.assertTrue(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data'))
7153
7154 self.assertEqual(cdp.mol[0].res[33].num, 43)
7155 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6])
7156 self.assertTrue(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data'))
7157
7158 self.assertEqual(cdp.mol[0].res[34].num, 44)
7159 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6])
7160 self.assertTrue(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data'))
7161
7162 self.assertEqual(cdp.mol[0].res[35].num, 45)
7163 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6])
7164 self.assertTrue(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data'))
7165
7166 self.assertEqual(cdp.mol[0].res[38].num, 49)
7167 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6])
7168 self.assertTrue(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data'))
7169
7170 self.assertEqual(cdp.mol[0].res[41].num, 52)
7171 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6])
7172 self.assertTrue(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data'))
7173
7174 self.assertEqual(cdp.mol[0].res[42].num, 53)
7175 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6])
7176 self.assertTrue(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data'))
7177
7178
7179 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
7180
7181
7182 GRID_INC = 4
7183
7184
7185 MC_NUM = 3
7186
7187
7188 MODSEL = 'AIC'
7189
7190
7191
7192 OPT_FUNC_TOL = 1e-1
7193 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
7194 OPT_MAX_ITERATIONS = 1000
7195 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
7196
7197 result_dir_name = ds.tmpdir
7198
7199
7200 for curspin in cluster_ids:
7201 self.interpreter.relax_disp.cluster('free spins', curspin)
7202
7203 self.interpreter.deselect.spin(spin_id=curspin, change_all=False)
7204
7205
7206
7207
7208
7209
7210
7211
7212 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
7213
7214
7215
7216 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)
7217
7218
7219
7220
7221
7222 print("\n\n################")
7223 print("Printing results")
7224 print("################\n")
7225 for model in MODELS:
7226
7227 if model == MODEL_R2EFF:
7228 continue
7229
7230
7231 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model))
7232 print("\nModel: %s" % (model))
7233
7234
7235 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7236
7237 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
7238
7239
7240 print("Optimised parameters for spin: %s" % (spin_string))
7241 for param in cur_spin.params + ['chi2']:
7242
7243 if param in ['r1', 'r2']:
7244 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True):
7245
7246 r20_key = generate_r20_key(exp_type=exp_type, frq=frq)
7247
7248
7249 value = getattr(cur_spin, param)[r20_key]
7250
7251
7252 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value))
7253
7254
7255 else:
7256
7257 value = getattr(cur_spin, param)
7258
7259
7260 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value))
7261
7262
7263 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final'))
7264 print("\nFinal pipe")
7265
7266
7268 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model.
7269
7270 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
7271
7272 This uses the automatic analysis.
7273
7274 """
7275
7276
7277 cluster_ids = [
7278 ":52@N"]
7279
7280
7281 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids)
7282
7283
7284 MODELS = [MODEL_R2EFF]
7285
7286
7287 GRID_INC = 4
7288
7289
7290 MC_NUM = 3
7291
7292
7293 MODSEL = 'AIC'
7294
7295
7296
7297 OPT_FUNC_TOL = 1e-1
7298 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
7299 OPT_MAX_ITERATIONS = 1000
7300 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
7301
7302 result_dir_name = ds.tmpdir
7303
7304
7305 for curspin in cluster_ids:
7306 self.interpreter.relax_disp.cluster('free spins', curspin)
7307
7308 self.interpreter.deselect.spin(spin_id=curspin, change_all=False)
7309
7310 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
7311
7312
7313 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)
7314
7315
7316 graph_comb = [
7317 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP],
7318 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP],
7319 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP],
7320 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET]
7321 ]
7322
7323
7324 result_folders = MODELS
7325
7326
7327 spin_id = ':52@N'
7328
7329
7330 for result_folder in result_folders:
7331
7332 if result_folder == MODEL_R2EFF:
7333 continue
7334
7335
7336 for y_axis, x_axis, interpolate in graph_comb:
7337
7338 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate)
7339
7340
7341 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_'))
7342
7343
7344 file_path = get_file_path(file_name, result_dir_name+sep+result_folder)
7345
7346 print("Testing file access to graph: %s"%file_path)
7347 self.assertTrue(access(file_path, F_OK))
7348
7349
7350 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO]
7351 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF]
7352 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET]
7353
7354 result_dir_name = ds.tmpdir
7355
7356
7357 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs'
7358
7359 for result_folder in result_folders:
7360
7361 if result_folder == MODEL_R2EFF:
7362 continue
7363
7364 for y_axis in y_axis_types:
7365 for x_axis in x_axis_types:
7366 for interpolate in interpolate_types:
7367
7368 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate)
7369
7370
7371 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_'))
7372
7373
7374 dir = result_dir_name+sep+result_folder
7375 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate))
7376 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True)
7377
7378
7379 file_path = get_file_path(file_name, dir)
7380
7381
7382 print("Testing file access to graph: %s"%file_path)
7383 self.assertTrue(access(file_path, F_OK))
7384
7385
7386 file_prod = open(file_path)
7387 lines_prod = file_prod.readlines()
7388 file_prod.close()
7389
7390
7391 dir_comp = data_path+sep+result_folder
7392 file_path_comp = get_file_path(file_name, dir_comp)
7393 file_comp = open(file_path_comp)
7394 lines_comp = file_comp.readlines()
7395 file_comp.close()
7396
7397
7398 self.assertEqual(len(lines_prod), len(lines_comp))
7399 for j in range(len(lines_prod)):
7400
7401 first_char = lines_prod[j][0]
7402 if first_char in ["@", "&"]:
7403 self.assertEqual(lines_prod[j], lines_comp[j])
7404 else:
7405
7406
7407 x_prod, y_prod, y_prod_err = lines_prod[j].split()
7408 x_comp, y_comp, y_comp_err = lines_comp[j].split()
7409 self.assertAlmostEqual(float(x_prod), float(x_comp))
7410 self.assertAlmostEqual(float(y_prod), float(y_comp))
7411
7412
7414 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
7415
7416 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
7417
7418 This uses the automatic analysis, with missing loading R1.
7419
7420 """
7421
7422
7423 cluster_ids = [
7424 ":13@N",
7425 ":15@N",
7426 ":16@N",
7427 ":25@N",
7428 ":26@N",
7429 ":28@N",
7430 ":39@N",
7431 ":40@N",
7432 ":41@N",
7433 ":43@N",
7434 ":44@N",
7435 ":45@N",
7436 ":49@N",
7437 ":52@N",
7438 ":53@N"]
7439
7440
7441 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False)
7442
7443
7444 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE]
7445
7446
7447 GRID_INC = None
7448
7449
7450 MC_NUM = 3
7451
7452
7453 MODSEL = 'AIC'
7454
7455
7456
7457 OPT_FUNC_TOL = 1e-25
7458 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
7459 OPT_MAX_ITERATIONS = 10000000
7460 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
7461
7462 result_dir_name = ds.tmpdir
7463
7464
7465 for curspin in cluster_ids:
7466 self.interpreter.relax_disp.cluster('free spins', curspin)
7467
7468 self.interpreter.deselect.spin(spin_id=curspin, change_all=False)
7469
7470
7471
7472
7473
7474
7475
7476
7477 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
7478
7479
7480
7481 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"
7482
7483 r1_fit = True
7484
7485
7486 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)
7487
7488
7489 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7490
7491
7493 """Test the operation of the relax_disp.r2eff_read user function."""
7494
7495
7496 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz'
7497
7498
7499 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1)
7500
7501
7502 id = 'test'
7503
7504
7505 self.interpreter.spectrometer.frequency(id=id, frq=800e6)
7506 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG')
7507
7508
7509 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)
7510
7511
7512 data = [
7513 ['cpmg_frqs', {'test': 66.667}],
7514 ['cpmg_frqs_list', [66.667]],
7515 ['dispersion_points', 1],
7516 ['exp_type', {'test': 'SQ CPMG'}],
7517 ['exp_type_list', ['SQ CPMG']],
7518 ['spectrometer_frq', {'test': 800000000.0}],
7519 ['spectrometer_frq_count', 1],
7520 ['spectrometer_frq_list', [800000000.0]],
7521 ['spectrum_ids', ['test']]
7522 ]
7523 for name, value in data:
7524
7525 self.assertTrue(hasattr(cdp, name))
7526
7527
7528 obj = getattr(cdp, name)
7529 self.assertEqual(obj, value)
7530
7531
7532 data = [
7533 [1, 2.3035747e+04, 8.5467725e+01],
7534 [2, 9.9629762e+04, 2.8322033e+02],
7535 [3, 9.5663137e+04, 2.8632929e+02],
7536 [4, 1.7089893e+05, 3.1089428e+02],
7537 [5, 4.7323876e+04, 1.0084269e+02],
7538 [6, 2.0199122e+04, 1.0135220e+02],
7539 [7, 1.6655488e+05, 3.1609061e+02],
7540 [8, 9.0061074e+04, 1.9176585e+02],
7541 [10, 8.4726204e+04, 2.8898155e+02],
7542 [11, 1.5050233e+05, 4.3138029e+02],
7543 [12, 9.2998531e+04, 3.0440191e+02],
7544 [13, 1.6343507e+05, 3.3144097e+02],
7545 [14, 1.0137301e+05, 3.7314642e+02],
7546 [15, 8.3407837e+04, 1.6546473e+02],
7547 [16, 1.3819126e+05, 3.3388517e+02],
7548 [17, 1.1010490e+05, 3.5639222e+02],
7549 [18, 9.4324035e+04, 3.2343585e+02],
7550 [19, 1.1135179e+05, 3.0706671e+02],
7551 [20, 7.6339410e+04, 1.7377460e+02],
7552 [21, 6.2008453e+04, 1.7327150e+02],
7553 [22, 1.0590404e+05, 2.4814635e+02],
7554 [23, 1.0630198e+05, 2.3601100e+02],
7555 [24, 7.2996320e+04, 1.4952465e+02],
7556 [25, 9.5486742e+04, 2.7080766e+02],
7557 [26, 5.8067989e+04, 1.6820462e+02],
7558 [27, -1.7168510e+04, 2.2519560e+02],
7559 [28, 1.6891473e+05, 2.3497525e+02],
7560 [29, 9.4038555e+04, 2.0357593e+02],
7561 [30, 2.1386951e+04, 2.2153532e+02],
7562 [31, 9.3982899e+04, 2.0937056e+02],
7563 [32, 8.6097484e+04, 2.3868467e+02],
7564 [33, 1.0194337e+05, 2.7370704e+02],
7565 [34, 8.5683111e+04, 2.0838076e+02],
7566 [35, 8.6985768e+04, 2.0889310e+02],
7567 [36, 8.6011237e+04, 1.7498390e+02],
7568 [37, 1.0984097e+05, 2.7622998e+02],
7569 [38, 8.7017879e+04, 2.6547994e+02],
7570 [39, 9.1682649e+04, 5.2777676e+02],
7571 [40, 7.6370440e+04, 1.9873214e+02],
7572 [41, 9.1393531e+04, 2.4483824e+02],
7573 [42, 1.1017111e+05, 2.8020699e+02],
7574 [43, 9.4552366e+04, 3.4394150e+02],
7575 [44, 1.2858281e+05, 6.8449252e+02],
7576 [45, 7.4583525e+04, 1.9544210e+02],
7577 [46, 9.2087490e+04, 2.0491066e+02],
7578 [47, 9.7507255e+04, 2.5162839e+02],
7579 [48, 1.0033842e+05, 2.7566430e+02],
7580 [49, 1.3048305e+05, 2.6797466e+02],
7581 [50, 1.0546796e+05, 1.9304384e+02],
7582 [51, 9.3099697e+04, 2.0773311e+02],
7583 [52, 4.6863758e+04, 1.3169068e+02],
7584 [53, 6.1055806e+04, 1.5448477e+02],
7585 [55, 6.8629994e+04, 1.6868673e+02],
7586 [56, 1.1005552e+05, 2.1940465e+02],
7587 [57, 1.0572760e+05, 1.9768486e+02],
7588 [58, 1.1176950e+05, 3.0009610e+02],
7589 [59, 9.8758603e+04, 3.3803895e+02],
7590 [60, 9.9517201e+04, 3.5137994e+02],
7591 [61, 5.4357946e+04, 2.5896579e+02],
7592 [62, 1.0899978e+05, 2.8720371e+02],
7593 [63, 8.4549759e+04, 4.1401837e+02],
7594 [64, 5.5014550e+04, 2.1135781e+02],
7595 [65, 8.0569666e+04, 2.3249709e+02],
7596 [66, 1.2936610e+05, 3.5218725e+02],
7597 [67, 3.6438010e+04, 8.7924003e+01],
7598 [70, 3.8763157e+04, 1.3325040e+02],
7599 [71, 8.5711411e+04, 2.9316183e+02],
7600 [72, 3.3211541e+04, 1.2182123e+02],
7601 [73, 3.2070576e+04, 1.2305430e+02]
7602 ]
7603 for res_num, value, error in data:
7604
7605 spin = return_spin(spin_id=":%s"%res_num)
7606
7607
7608 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value)
7609 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7610
7611
7613 """Test the operation of the relax_disp.r2eff_read_spin user function."""
7614
7615
7616 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005'
7617
7618
7619 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H')
7620 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N')
7621 self.interpreter.spin.isotope('1H', spin_id='@H')
7622 self.interpreter.spin.isotope('15N', spin_id='@N')
7623
7624
7625 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]
7626 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]
7627 ids = []
7628 for value in H_disp_points:
7629 ids.append('1H_CPMG_%s' % value)
7630 for value in N_disp_points:
7631 ids.append('15N_CPMG_%s' % value)
7632 print("\n\nThe experiment IDs are %s." % ids)
7633
7634
7635 for id in ids:
7636 self.interpreter.spectrometer.frequency(id=id, frq=500e6)
7637 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG')
7638 for value in H_disp_points:
7639 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value)
7640 for value in N_disp_points:
7641 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value)
7642
7643
7644 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]:
7645
7646 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)
7647
7648
7649 data = [
7650 ['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}],
7651 ['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]],
7652 ['dispersion_points', 24],
7653 ['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'}],
7654 ['exp_type_list', ['SQ CPMG']],
7655 ['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}],
7656 ['spectrometer_frq_count', 1],
7657 ['spectrometer_frq_list', [500000000.0]],
7658 ['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']]
7659 ]
7660 for name, value in data:
7661
7662 self.assertTrue(hasattr(cdp, name))
7663
7664
7665 obj = getattr(cdp, name)
7666 if not isinstance(data, dict):
7667 self.assertEqual(obj, value)
7668
7669
7670 else:
7671 for id in ids:
7672 self.assertEqual(obj[id], value[id])
7673
7674
7675 h_data = [
7676 [ 67.0, 21.47924, 0.42958],
7677 [ 133.0, 16.73898, 0.33478],
7678 [ 267.0, 9.97357, 0.19947],
7679 [ 400.0, 8.23877, 0.24737],
7680 [ 533.0, 7.59290, 0.24263],
7681 [ 667.0, 7.45843, 0.24165],
7682 [ 800.0, 7.11222, 0.23915],
7683 [ 933.0, 7.40880, 0.24129],
7684 [1067.0, 6.55191, 0.16629],
7685 [1600.0, 6.72177, 0.23637],
7686 [2133.0, 7.09629, 0.23904],
7687 [2667.0, 7.14675, 0.23940]
7688 ]
7689 for disp_point, value, error in h_data:
7690 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point
7691 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value)
7692 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error)
7693 n_data = [
7694 [ 50.0, 27.15767, 0.54315],
7695 [ 100.0, 26.55781, 0.53116],
7696 [ 150.0, 24.73462, 0.49469],
7697 [ 200.0, 20.98617, 0.41972],
7698 [ 250.0, 17.82442, 0.35649],
7699 [ 300.0, 15.55352, 0.31107],
7700 [ 350.0, 13.78958, 0.27579],
7701 [ 400.0, 12.48334, 0.24967],
7702 [ 500.0, 11.55724, 0.23114],
7703 [ 600.0, 10.53874, 0.21077],
7704 [ 700.0, 10.07395, 0.20148],
7705 [ 800.0, 9.62952, 0.19259],
7706 [ 900.0, 9.49994, 0.19000],
7707 [1000.0, 8.71350, 0.17427]
7708 ]
7709 for disp_point, value, error in n_data:
7710 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point
7711 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value)
7712 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7713
7714
7716 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis."""
7717
7718
7719 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7720
7721
7723 """Test the reading of a file containing r2eff values."""
7724
7725
7726 self.interpreter.residue.create(1, 'Gly')
7727 self.interpreter.residue.create(2, 'Gly')
7728 self.interpreter.residue.create(3, 'Gly')
7729
7730
7731 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)
7732
7733
7734 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000)
7735 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003)
7736 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7737
7738
7740 """Test speeding up grid search. Support requst sr #3151 U{https://web.archive.org/web/https://gna.org/support/index.php?3151}.
7741
7742 User function to set the R20 parameters in the default grid search using the minimum R2eff value.
7743
7744 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009
7745 'SOD1-WT' CPMG data to the CR72 dispersion model.
7746
7747 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.
7748 Data is for experiment at 25 degree Celcius.
7749 """
7750
7751
7752 pipe_name = 'base pipe'
7753 pipe_type = 'relax_disp'
7754 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
7755 select_spin_index = list(range(0, 1))
7756 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index)
7757
7758
7759 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6)
7760 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6)
7761
7762
7763 MODEL = "CR72"
7764
7765
7766 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL)
7767 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
7768 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
7769
7770
7771 self.interpreter.relax_disp.select_model(model=MODEL)
7772
7773
7774 self.interpreter.relax_disp.r20_from_min_r2eff(force=False)
7775
7776
7777 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7778
7779 spin_params = spin.params
7780
7781
7782 if spin_id == ":10@N":
7783 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106)
7784 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649)
7785
7786
7787 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))
7788
7789
7790 self.assertTrue(spin.r2[r20_key_600] != spin.r2[r20_key_500])
7791
7792
7793 self.assertTrue(spin.r2[r20_key_600] > 0.0)
7794 self.assertTrue(spin.r2[r20_key_500] > 0.0)
7795
7796
7797 r2eff_600 = []
7798 r2eff_500 = []
7799 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
7800
7801 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
7802
7803
7804 r2eff = spin.r2eff[data_key]
7805 if frq == 599.8908617*1E6:
7806 r2eff_600.append(r2eff)
7807 elif frq == 499.862139*1E6:
7808 r2eff_500.append(r2eff)
7809
7810
7811 r2eff_600.sort()
7812 r2eff_500.sort()
7813
7814
7815 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600)))
7816 print(r2eff_600)
7817 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600))
7818 print("")
7819
7820 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500)))
7821 print(r2eff_500)
7822 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500))
7823 print("")
7824
7825 print("###########################################")
7826 print("Trying GRID SEARCH for minimum R2eff values")
7827
7828
7829 GRID_INC = 5
7830
7831 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1)
7832
7833
7834
7835 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL)
7836 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
7837 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
7838
7839
7840 self.interpreter.relax_disp.select_model(model=MODEL)
7841
7842
7843 for param in spin_params:
7844 print("Setting standard parameter for param: %s"%param)
7845 self.interpreter.value.set(param=param, index=None)
7846
7847
7848 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
7849
7850 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))
7851
7852
7853 self.assertEqual(spin.r2[r20_key_600], 10.00)
7854 self.assertEqual(spin.r2[r20_key_500], 10.00)
7855 self.assertEqual(spin.pA, 0.9)
7856 self.assertEqual(spin.dw, 1.0)
7857 self.assertEqual(spin.kex, 1000.0)
7858
7859 print("###########################################")
7860 print("Trying GRID SEARCH for standard R2eff values")
7861
7862
7863 GRID_INC = 5
7864
7865 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1)
7866
7867
7868
7869 GRID_INC = 5
7870
7871
7872 MC_NUM = 3
7873
7874
7875 MODSEL = 'AIC'
7876
7877
7878
7879 OPT_FUNC_TOL = 1e-1
7880 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
7881 OPT_MAX_ITERATIONS = 1000
7882 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
7883
7884
7885 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)
7886
7887
7889 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod."""
7890
7891
7892 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'
7893
7894
7895 file_name = '128_0_FT.ft2'
7896
7897
7898 get_output = show_apod_extract(file_name=file_name, dir=data_path)
7899
7900
7901
7902
7903 show_apod_ver = [
7904 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name),
7905 'REMARK Automated Noise Std Dev in Processed Data: 8583.41',
7906 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558',
7907 '',
7908 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR',
7909 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e']
7910
7911
7912
7913
7914 for i, line in enumerate(show_apod_ver):
7915 line_ver = get_output[i]
7916
7917 print(line)
7918 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:':
7919 continue
7920
7921 self.assertEqual(line, line_ver)
7922
7923
7925 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod."""
7926
7927
7928 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'
7929
7930
7931 file_name = '128_0_FT.ft2'
7932
7933
7934 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path)
7935
7936
7937 self.assertEqual(rmsd, 8583.41)
7938
7939
7941 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files."""
7942
7943
7944 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'
7945
7946
7947 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir)
7948
7949
7950 for wfile_path in wfile_paths:
7951
7952 get_data = extract_data(file=wfile_path)
7953
7954
7955 test = float(get_data[0][0])
7956
7957
7958 self.assertEqual(test, 8583.41)
7959
7960
7962 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file."""
7963
7964
7965 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'
7966
7967
7968 file_name = '128_0_FT.ft2'
7969
7970
7971 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir)
7972
7973
7974 get_data = extract_data(file=wfile_path)
7975
7976
7977 test = float(get_data[0][0])
7978
7979
7980 self.assertEqual(test, 8583.41)
7981
7982
7984 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}.
7985
7986 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009
7987 'SOD1-WT' CPMG data to the CR72 dispersion model.
7988
7989 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.
7990 Data is for experiment at 25 degree Celcius.
7991
7992 bug #21954 U{https://web.archive.org/web/https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important.
7993 """
7994
7995
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, 1))
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
8003 repl_A = ['Z_A1', 'Z_A15']
8004 repl_B = ['Z_B1', 'Z_B18']
8005
8006
8007 spectrum_ids_A = []
8008 spectrum_ids_B = []
8009 for spectrum_id in cdp.spectrum_ids:
8010 if "A" in spectrum_id:
8011 spectrum_ids_A.append(spectrum_id)
8012 elif "B" in spectrum_id:
8013 spectrum_ids_B.append(spectrum_id)
8014
8015
8016 delattr(cdp, "var_I")
8017 delattr(cdp, "sigma_I")
8018
8019
8020 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A)
8021 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B)
8022
8023
8024 Errors_A_B = []
8025 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8026 A_err = spin.peak_intensity_err[spectrum_ids_A[0]]
8027 B_err = spin.peak_intensity_err[spectrum_ids_B[0]]
8028 Errors_A_B.append([A_err, B_err])
8029
8030
8031 delattr(cdp, "var_I")
8032 delattr(cdp, "sigma_I")
8033
8034
8035 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B)
8036 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A)
8037
8038
8039 Errors_B_A = []
8040 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8041 A_err = spin.peak_intensity_err[spectrum_ids_A[0]]
8042 B_err = spin.peak_intensity_err[spectrum_ids_B[0]]
8043 Errors_B_A.append([A_err, B_err])
8044
8045
8046 for i in range(len(Errors_A_B)):
8047 Error_A_B = Errors_A_B[i]
8048 Error_B_A = Errors_B_A[i]
8049 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4)
8050 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4)
8051
8052
8053 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2)
8054 std_A_fix = 2785.7263335738567
8055
8056 for id_A in spectrum_ids_A:
8057 self.assertEqual(cdp.sigma_I[id_A], std_A)
8058 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7)
8059
8060 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2)
8061 std_B_fix = 4967.3772030667988
8062
8063 for id_B in spectrum_ids_B:
8064 self.assertEqual(cdp.sigma_I[id_B], std_B)
8065 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
8066
8067
8069 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}.
8070
8071 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009
8072 'SOD1-WT' CPMG data to the CR72 dispersion model.
8073
8074 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.
8075 Data is for experiment at 25 degree Celcius.
8076 """
8077
8078
8079 pipe_name = 'base pipe'
8080 pipe_type = 'relax_disp'
8081 pipe_name_r2eff = "%s_R2eff"%(pipe_name)
8082 select_spin_index = list(range(0, 2))
8083 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index)
8084
8085
8086 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6)
8087 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6)
8088
8089
8090 MODEL = "CR72"
8091
8092
8093 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL)
8094 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL)
8095 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL)
8096
8097
8098 self.interpreter.relax_disp.select_model(model=MODEL)
8099
8100
8101 GRID_INC = 7
8102
8103
8104 grid_results = []
8105 mini_results = []
8106 clust_results = []
8107
8108
8109 self.interpreter.relax_disp.r20_from_min_r2eff(force=False)
8110
8111
8112 self.interpreter.relax_disp.insignificance(level=1.0)
8113
8114
8115 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1)
8116
8117
8118 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8119
8120 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])
8121
8122
8123
8124 set_func_tol = 1e-9
8125 set_max_iter = 100000
8126 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
8127
8128
8129 pA_values = []
8130 kex_values = []
8131 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8132
8133 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])
8134
8135
8136 pA_values.append(spin.pA)
8137
8138
8139 kex_values.append(spin.kex)
8140
8141 print("\n# Now print before and after minimisation.\n")
8142
8143
8144 for i in range(len(grid_results)):
8145
8146 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i]
8147 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i]
8148
8149 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))
8150 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))
8151
8152
8153
8154 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL)
8155 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER)
8156 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER)
8157
8158
8159 self.interpreter.relax_disp.select_model(model=MODEL)
8160
8161
8162 cluster_id = 'clust'
8163
8164
8165 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8166 self.interpreter.relax_disp.cluster(cluster_id, spin_id)
8167
8168
8169 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER)
8170
8171
8172 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8173 print(pA_values)
8174
8175 self.assertEqual(median(pA_values), spin.pA)
8176
8177
8178 self.assertEqual(median(kex_values), spin.kex)
8179
8180
8181 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1)
8182
8183
8184 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
8185
8186 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])
8187
8188
8189 clust_pA = spin.pA
8190 clust_kex = spin.kex
8191
8192 print("\n# Now testing.\n")
8193
8194
8195 test_res = {}
8196 test_res[':10@N'] = {}
8197 test_res[':10@N']['r2600'] = 18.429755324773360
8198 test_res[':10@N']['r2500'] = 16.981349161968630
8199 test_res[':10@N']['dw'] = 2.700755859433969
8200 test_res[':10@N']['pA'] = 0.971531659288657
8201 test_res[':10@N']['kex'] = 3831.766337047963134
8202 test_res[':11@N'] = {}
8203 test_res[':11@N']['r2600'] = 18.193409421115213
8204 test_res[':11@N']['r2500'] = 17.308838135567765
8205 test_res[':11@N']['dw'] = 2.706650302761793
8206 test_res[':11@N']['pA'] = 0.971531659288657
8207 test_res[':11@N']['kex'] = 3831.766337047963134
8208
8209
8210 for i in range(len(grid_results)):
8211
8212 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i]
8213 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i]
8214 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i]
8215
8216 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))
8217 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))
8218 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))
8219
8220
8221 self.assertEqual(clust_pA, c_pA)
8222 self.assertEqual(clust_kex, c_kex)
8223
8224
8225 if c_spin_id in test_res:
8226 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4)
8227 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4)
8228 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3)
8229 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5)
8230 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
8231
8232
8233
8234
8235
8402
8403
8405 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data.
8406
8407 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.
8408 """
8409
8410
8411 self.interpreter.reset()
8412
8413
8414 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP'
8415 self.interpreter.state.load(data_path+sep+'r2eff_values')
8416
8417
8418 model = 'MMQ CR72'
8419 pipe_name = "%s - relax_disp" % model
8420 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp')
8421 self.interpreter.pipe.switch(pipe_name=pipe_name)
8422
8423
8424 self.interpreter.relax_disp.select_model(model=model)
8425
8426
8427 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137")
8428
8429
8430 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
8431
8432
8433 spin135S = cdp.mol[0].res[0].spin[0]
8434 spin135F = cdp.mol[0].res[0].spin[1]
8435 spin137S = cdp.mol[0].res[1].spin[0]
8436 spin137F = cdp.mol[0].res[1].spin[1]
8437
8438
8439 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6)
8440 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
8441
8442
8443 spin135S.pA = 0.836591763632
8444 spin135S.kex = 241.806525261
8445
8446
8447 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715}
8448 spin135S.dw = 0.583003118785
8449 spin135S.dwH = 0.0361441944301
8450
8451 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389}
8452 spin135F.dw = 0.805849745104
8453 spin135F.dwH = 0.0215791945715
8454
8455 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934}
8456 spin137S.dw = 0.688107568372
8457 spin137S.dwH = 0.0344463604043
8458
8459 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101}
8460 spin137F.dw = 0.94978299907
8461 spin137F.dwH = 1.4818877939e-07
8462
8463
8464 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000)
8465
8466
8467 print("\n\nOptimised parameters:\n")
8468 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)"))
8469 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]))
8470 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]))
8471 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA))
8472 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw))
8473 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH))
8474 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex))
8475 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2))
8476 print("\n # Set the cluster specific parameters (only for the first spin).")
8477 print(" spin135S.pA = %s" % spin135S.pA)
8478 print(" spin135S.kex = %s" % spin135S.kex)
8479 print("\n # Set the initial parameter values.")
8480 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2]))
8481 print(" spin135S.dw = %s" % spin135S.dw)
8482 print(" spin135S.dwH = %s" % spin135S.dwH)
8483 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2]))
8484 print(" spin135F.dw = %s" % spin135F.dw)
8485 print(" spin135F.dwH = %s" % spin135F.dwH)
8486 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2]))
8487 print(" spin137S.dw = %s" % spin137S.dw)
8488 print(" spin137S.dwH = %s" % spin137S.dwH)
8489 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2]))
8490 print(" spin137F.dw = %s" % spin137F.dw)
8491 print(" spin137F.dwH = %s" % spin137F.dwH)
8492
8493
8494 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4)
8495 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4)
8496 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4)
8497 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4)
8498 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4)
8499 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4)
8500 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4)
8501
8502
8503 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4)
8504 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4)
8505 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4)
8506 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4)
8507 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4)
8508 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4)
8509 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4)
8510
8511
8512 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4)
8513 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4)
8514 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4)
8515 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4)
8516 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4)
8517 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4)
8518 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4)
8519
8520
8521 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4)
8522 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4)
8523 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4)
8524 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4)
8525 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4)
8526 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4)
8527 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8528
8529
8531 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data.
8532
8533 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.
8534 """
8535
8536
8537 self.interpreter.reset()
8538
8539
8540 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP'
8541 self.interpreter.state.load(data_path+sep+'r2eff_values')
8542
8543
8544 model = 'NS MMQ 2-site'
8545 pipe_name = "%s - relax_disp" % model
8546 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp')
8547 self.interpreter.pipe.switch(pipe_name=pipe_name)
8548
8549
8550 self.interpreter.relax_disp.select_model(model=model)
8551
8552
8553 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137")
8554
8555
8556 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
8557
8558
8559 spin135S = cdp.mol[0].res[0].spin[0]
8560 spin135F = cdp.mol[0].res[0].spin[1]
8561 spin137S = cdp.mol[0].res[1].spin[0]
8562 spin137F = cdp.mol[0].res[1].spin[1]
8563
8564
8565 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
8566 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6)
8567
8568
8569 spin135S.pA = 0.847378444499757
8570 spin135S.kex = 264.055604934724329
8571
8572
8573 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299}
8574 spin135S.dw = 0.585574008745351
8575 spin135S.dwH = 0.000000000000002
8576
8577 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893}
8578 spin135F.dw = 0.856699277665748
8579 spin135F.dwH = 0.000000000582587
8580
8581 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824}
8582 spin137S.dw = 0.772904450844973
8583 spin137S.dwH = 0.183351478512970
8584
8585 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319}
8586 spin137F.dw = 0.984568590342831
8587 spin137F.dwH = 0.000000001993458
8588
8589
8590 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)
8591
8592
8593 print("\n\nOptimised parameters:\n")
8594 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)"))
8595 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]))
8596 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]))
8597 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA))
8598 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw))
8599 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH))
8600 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex))
8601 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2))
8602
8603
8604 return
8605
8606
8607 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4)
8608 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4)
8609 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4)
8610 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4)
8611 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4)
8612 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4)
8613 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1)
8614
8615
8616 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4)
8617 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4)
8618 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4)
8619 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4)
8620 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4)
8621 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4)
8622 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1)
8623
8624
8625 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4)
8626 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4)
8627 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4)
8628 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4)
8629 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4)
8630 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4)
8631 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1)
8632
8633
8634 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4)
8635 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4)
8636 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4)
8637 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4)
8638 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4)
8639 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4)
8640 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8641
8642
8644 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data."""
8645
8646
8647 self.setup_tp02_data_to_ns_r1rho_2site()
8648
8649
8650 spin1 = cdp.mol[0].res[0].spin[0]
8651 spin2 = cdp.mol[0].res[1].spin[0]
8652
8653
8654 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8655 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8656
8657
8658 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4)
8659 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4)
8660 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4)
8661 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4)
8662 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4)
8663 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4)
8664
8665
8666 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4)
8667 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4)
8668 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4)
8669 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4)
8670 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4)
8671 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8672
8673
8675 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering."""
8676
8677
8678 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True)
8679
8680
8681 spin1 = cdp.mol[0].res[0].spin[0]
8682 spin2 = cdp.mol[0].res[1].spin[0]
8683
8684
8685 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8686 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8687
8688
8689 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4)
8690 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4)
8691 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4)
8692 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4)
8693 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4)
8694 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4)
8695
8696
8697 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4)
8698 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4)
8699 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4)
8700 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4)
8701 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4)
8702 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8703
8704
8706 """Test the dispersion 'MP05' model fitting against the 'TP02' test data."""
8707
8708
8709 ds.fixed = True
8710 ds.models = ['R2eff', 'MP05']
8711
8712
8713 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')
8714
8715
8716 self.interpreter.pipe.switch('MP05 - relax_disp')
8717
8718
8719 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]]
8720 pA = [0.775055484521586, 0.500000000036595]
8721 kex = [1235.20361276079, 2378.31403454691]
8722 delta_omega = [7.08194146569694, 5.4083562844306]
8723 chi2 = [0.0370400968727768, 0.182141732163934]
8724
8725
8726 spin1 = cdp.mol[0].res[0].spin[0]
8727 spin2 = cdp.mol[0].res[1].spin[0]
8728
8729
8730 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8731 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8732
8733
8734 print("\n\nOptimised parameters:\n")
8735 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)"))
8736 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1]))
8737 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2]))
8738 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA))
8739 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw))
8740 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex))
8741 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
8742
8743
8744 spin_index = 0
8745 for spin, spin_id in spin_loop(return_id=True):
8746
8747 print("\nSpin %s." % spin_id)
8748
8749
8750 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4)
8751 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4)
8752 self.assertAlmostEqual(spin.pA, pA[spin_index], 3)
8753 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3)
8754 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3)
8755 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3)
8756
8757
8758 spin_index += 1
8759
8760
8762 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data."""
8763
8764
8765 ds.fixed = True
8766 ds.models = ['R2eff', 'TAP03']
8767
8768
8769 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')
8770
8771
8772 self.interpreter.pipe.switch('TAP03 - relax_disp')
8773
8774
8775 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]]
8776 pA = [0.775042569092891, 0.500000000229685]
8777 kex = [1235.20852748765, 2379.47085580169]
8778 delta_omega = [7.08176806468445, 5.40708372863538]
8779 chi2 = [0.0371366837083293, 0.182212857256044]
8780
8781
8782 spin1 = cdp.mol[0].res[0].spin[0]
8783 spin2 = cdp.mol[0].res[1].spin[0]
8784
8785
8786 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8787 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8788
8789
8790 print("\n\nOptimised parameters:\n")
8791 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)"))
8792 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1]))
8793 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2]))
8794 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA))
8795 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw))
8796 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex))
8797 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
8798
8799
8800 self.interpreter.pipe.switch('TAP03 - relax_disp')
8801 spin_index = 0
8802 for spin, spin_id in spin_loop(return_id=True):
8803
8804 print("\nSpin %s." % spin_id)
8805
8806
8807 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4)
8808 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4)
8809 self.assertAlmostEqual(spin.pA, pA[spin_index], 3)
8810 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3)
8811 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3)
8812 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3)
8813
8814
8815 spin_index += 1
8816
8817
8819 """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"""
8820
8821
8822
8823
8824 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882'
8825 self.interpreter.results.read(file_name)
8826
8827
8828 spins_cluster = cdp.clustering['sel']
8829 spins_free = cdp.clustering['free spins']
8830
8831
8832 cur_spin_id = spins_cluster[0]
8833 cur_spin = return_spin(spin_id=cur_spin_id)
8834
8835
8836 N = len(spins_cluster)
8837 N_dp = N * len(cur_spin.r2eff)
8838
8839
8840 N_par = cdp.spectrometer_frq_count * N + N + 1 + 1
8841 dof = N_dp - N_par
8842
8843
8844 print(N_par, N_dp)
8845
8846
8847 mc_nr = 3
8848
8849
8850 self.interpreter.monte_carlo.setup(number=mc_nr)
8851
8852
8853 self.interpreter.monte_carlo.create_data(distribution="red_chi2")
8854
8855
8856 self.interpreter.monte_carlo.setup(number=mc_nr)
8857
8858
8859 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, fixed_error=1.)
8860
8861
8862 self.interpreter.monte_carlo.setup(number=mc_nr)
8863
8864
8865 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="fixed")
8866
8867
8868 self.interpreter.monte_carlo.create_data(distribution="fixed", fixed_error=1.)
8869
8870
8871 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
8872
8873
8874 self.interpreter.monte_carlo.setup(number=mc_nr)
8875
8876
8877 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="red_chi2")
8878 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, method="direct", distribution="red_chi2")
8879
8880
8882 """Test related to Task #7882 U{https://web.archive.org/web/https://gna.org/task/?7882}: Try making a confidence interval of kex.
8883 According to the regression book of Graphpad: U{http://www.graphpad.com/faq/file/Prism4RegressionBook.pdf}.
8884 Page 109-111.
8885 """
8886
8887
8888 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882'
8889 self.interpreter.results.read(file_name)
8890
8891
8892 spins_cluster = cdp.clustering['sel']
8893 spins_free = cdp.clustering['free spins']
8894
8895
8896 cur_spin_id = spins_cluster[0]
8897 cur_spin = return_spin(spin_id=cur_spin_id)
8898
8899
8900 Ns = len(spins_cluster)
8901 N_dp = Ns * len(cur_spin.r2eff)
8902
8903
8904 N_par = cdp.spectrometer_frq_count * Ns + Ns + 1 + 1
8905 dof_fit = N_dp - N_par
8906
8907
8908 self.assertEqual(Ns, 61)
8909 self.assertEqual(N_dp, 1952)
8910 self.assertEqual(N_par, 185)
8911
8912
8913
8914 P = 1
8915
8916 N = N_dp
8917
8918 dof_conf = N - P
8919
8920
8921
8922
8923
8924 F = 3.8462295505435562
8925
8926 scale = F*P/dof_conf +1
8927
8928
8929 SSbest_fit = cur_spin.chi2
8930 SSbest_kex = cur_spin.kex
8931
8932
8933 SSall_fixed = SSbest_fit * scale
8934
8935 print(SSbest_fit, scale, SSall_fixed)
8936
8937
8938 kex_cur = cur_spin.kex
8939 kex_list = linspace(kex_cur - 1500, kex_cur + 3000, 200)
8940
8941 chi2_list = []
8942
8943 for kex in kex_list:
8944 self.interpreter.value.set(val=kex, param='kex')
8945
8946
8947 self.interpreter.minimise.calculate(verbosity=0)
8948
8949
8950 chi2_cur = cur_spin.chi2
8951 print("kex=%3.2f, chi2=%3.2f"%(kex, chi2_cur), chi2_cur<SSall_fixed)
8952
8953
8954 chi2_list.append(chi2_cur)
8955
8956
8957 chi2_list = asarray(chi2_list)
8958
8959
8960 sel_mask = chi2_list < SSall_fixed
8961
8962
8963 kex_sel = kex_list[sel_mask]
8964 chi2_sel = chi2_list[sel_mask]
8965
8966
8967 print(SSbest_kex, SSbest_fit, SSall_fixed)
8968 print(kex_sel)
8969 print(chi2_sel)
8970
8971 if True:
8972 import matplotlib.pyplot as plt
8973
8974 plt.plot(kex_sel, chi2_sel, "bo")
8975 plt.plot(SSbest_kex, SSbest_fit, "g*")
8976 plt.show()
8977
8978
8980 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data."""
8981
8982
8983 ds.fixed = True
8984
8985
8986 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')
8987
8988
8989 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]]
8990 pA = 0.7654321
8991 kex = 1234.56789
8992 delta_omega = [7.0, 9.0]
8993
8994
8995 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6)
8996 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6)
8997
8998
8999 self.interpreter.pipe.switch('TP02 - relax_disp')
9000 spin_index = 0
9001 for spin, spin_id in spin_loop(return_id=True):
9002
9003 print("\nSpin %s." % spin_id)
9004
9005
9006 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4)
9007 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4)
9008 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3)
9009 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3)
9010
9011
9012 spin_index += 1
9013
9014
9016 """System test of the value.write function to write intensities for an R1rho setup.
9017 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.
9018
9019 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}.
9020 """
9021
9022
9023 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
9024 self.interpreter.state.load(statefile, force=True)
9025
9026
9027 int_filepath = ds.tmpdir+sep+'int.out'
9028
9029
9030
9031 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True)
9032
9033
9034 self.assertTrue(access(int_filepath, F_OK))
9035
9036
9037 int_file = open(int_filepath, 'r')
9038
9039
9040 for line in int_file:
9041
9042 if line[0] == "#":
9043 continue
9044
9045
9046 linesplit = line.split()
9047
9048
9049 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I":
9050 self.assertEqual(linesplit[5], "115571.4")
9051 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S":
9052 self.assertEqual(linesplit[5], "68377.52")
9053 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S":
9054 self.assertEqual(linesplit[5], "9141.689")
9055 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A":
9056 self.assertEqual(linesplit[5], "29123.77")
9057 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L":
9058 self.assertEqual(linesplit[5], "58914.94")
9059
9060
9061 int_file.close()
9062
9063
9065 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup.
9066
9067 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}.
9068 """
9069
9070
9071 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
9072 self.interpreter.state.load(statefile, force=True)
9073
9074
9075 theta_filepath = ds.tmpdir+sep+'theta.out'
9076
9077
9078 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True)
9079
9080
9081 self.assertTrue(access(theta_filepath, F_OK))
9082
9083
9084 theta_file = open(theta_filepath, 'r')
9085
9086
9087 for line in theta_file:
9088
9089 if line[0] == "#":
9090 continue
9091
9092 print(line[:-1])
9093
9094
9095 linesplit = line.split()
9096
9097
9098 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I":
9099 self.assertNotEqual(linesplit[5], "None")
9100 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S":
9101 self.assertNotEqual(linesplit[5], "None")
9102 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S":
9103 self.assertNotEqual(linesplit[5], "None")
9104 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A":
9105 self.assertNotEqual(linesplit[5], "None")
9106 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L":
9107 self.assertNotEqual(linesplit[5], "None")
9108
9109
9110 theta_file.close()
9111
9112
9114 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup.
9115
9116 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}.
9117 """
9118
9119
9120 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2'
9121 self.interpreter.state.load(statefile, force=True)
9122
9123
9124 w_eff_filepath = ds.tmpdir+sep+'w_eff.out'
9125
9126
9127 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True)
9128
9129
9130 self.assertTrue(access(w_eff_filepath, F_OK))
9131
9132
9133 w_eff_file = open(w_eff_filepath, 'r')
9134
9135
9136 for line in w_eff_file:
9137
9138 if line[0] == "#":
9139 continue
9140
9141 print(line[:-1])
9142
9143
9144 linesplit = line.split()
9145
9146
9147 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I":
9148 self.assertNotEqual(linesplit[5], "None")
9149 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S":
9150 self.assertNotEqual(linesplit[5], "None")
9151 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S":
9152 self.assertNotEqual(linesplit[5], "None")
9153 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A":
9154 self.assertNotEqual(linesplit[5], "None")
9155 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L":
9156 self.assertNotEqual(linesplit[5], "None")
9157
9158
9159 w_eff_file.close()
9160
9161
9163 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup.
9164
9165 This uses the data of the saved state attached to U{bug #21344<https://web.archive.org/web/https://gna.org/bugs/?21344>}.
9166 """
9167
9168
9169 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2'
9170 self.interpreter.state.load(statefile, force=True)
9171
9172
9173 pipe_name = 'base pipe'
9174 pipe_bundle = 'relax_disp'
9175 pipe_type = 'relax_disp'
9176
9177
9178 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'
9179
9180
9181 self.interpreter.deselect.all()
9182
9183
9184 select_spin_ids = [
9185 ":13@N",
9186 ":15@N",
9187 ":16@N",
9188 ":25@N",
9189 ":26@N",
9190 ":28@N",
9191 ":39@N",
9192 ":40@N",
9193 ":41@N",
9194 ":43@N",
9195 ":44@N",
9196 ":45@N",
9197 ":49@N",
9198 ":52@N",
9199 ":53@N"]
9200
9201
9202 for curspin in select_spin_ids:
9203 print("Selecting spin %s"%curspin)
9204 self.interpreter.deselect.reverse(spin_id=curspin)
9205
9206
9207 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)
9208
9209
9210 MODELS = ['R2eff']
9211
9212
9213 GRID_INC = 4
9214
9215
9216 MC_NUM = 3
9217
9218
9219 MODSEL = 'AIC'
9220
9221
9222
9223 OPT_FUNC_TOL = 1e-1
9224 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL
9225 OPT_MAX_ITERATIONS = 1000
9226 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS
9227
9228
9229 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)
9230
9231
9232
9233 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out'
9234 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out'
9235
9236
9237 self.assertTrue(access(theta_filepath, F_OK))
9238 self.assertTrue(access(w_eff_filepath, F_OK))
9239
9240
9241 theta_file = open(theta_filepath, 'r')
9242 theta_result = [
9243 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n",
9244 "#\n",
9245 "# 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",
9246 "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",
9247 "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",
9248 "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",
9249 "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",
9250 "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",
9251 "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",
9252 "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",
9253 "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",
9254 "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",
9255 "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",
9256 "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",
9257 "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",
9258 "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",
9259 "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",
9260 "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",
9261 "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",
9262 "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",
9263 "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",
9264 "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",
9265 "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",
9266 "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",
9267 "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",
9268 "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",
9269 "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",
9270 "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",
9271 "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",
9272 "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",
9273 "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",
9274 "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",
9275 "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",
9276 "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",
9277 "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",
9278 "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",
9279 "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",
9280 "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",
9281 "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",
9282 "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",
9283 "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",
9284 "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",
9285 "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",
9286 "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",
9287 "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",
9288 "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",
9289 "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",
9290 "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",
9291 "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",
9292 "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",
9293 "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"
9294 ]
9295
9296 lines = theta_file.readlines()
9297 for i in range(len(lines)):
9298
9299 if theta_result[i][0] == "#":
9300 self.assertEqual(theta_result[i], lines[i])
9301
9302 if theta_result[i] == lines[i]:
9303 self.assertEqual(theta_result[i], lines[i])
9304
9305 else:
9306
9307 print(theta_result[i])
9308 print(lines[i])
9309
9310
9311 self.assertEqual(theta_result[i][:62], lines[i][:62])
9312
9313
9314 theta_result_s = theta_result[i][62:].split()[::2]
9315 print(theta_result_s )
9316 lines_s = lines[i][62:].split()[::2]
9317 print(lines_s)
9318
9319 for j in range(len(lines_s)):
9320 print(theta_result_s[j], lines_s[j])
9321
9322 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14)
9323
9324
9325 theta_file.close()
9326
9327 w_eff_file = open(w_eff_filepath, 'r')
9328 w_eff_result = [
9329 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n",
9330 "#\n",
9331 "# 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",
9332 "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",
9333 "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",
9334 "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",
9335 "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",
9336 "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",
9337 "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",
9338 "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",
9339 "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",
9340 "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",
9341 "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",
9342 "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",
9343 "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",
9344 "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",
9345 "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",
9346 "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",
9347 "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",
9348 "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",
9349 "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",
9350 "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",
9351 "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",
9352 "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",
9353 "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",
9354 "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",
9355 "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",
9356 "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",
9357 "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",
9358 "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",
9359 "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",
9360 "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",
9361 "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",
9362 "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",
9363 "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",
9364 "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",
9365 "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",
9366 "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",
9367 "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",
9368 "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",
9369 "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",
9370 "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",
9371 "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",
9372 "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",
9373 "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",
9374 "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",
9375 "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",
9376 "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",
9377 "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",
9378 "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",
9379 "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"
9380 ]
9381
9382 lines = w_eff_file.readlines()
9383 for i in range(len(lines)):
9384
9385 if w_eff_result[i][0] == "#":
9386 self.assertEqual(w_eff_result[i], lines[i])
9387
9388 if w_eff_result[i] == lines[i]:
9389 self.assertEqual(w_eff_result[i], lines[i])
9390
9391 else:
9392
9393 print(w_eff_result[i])
9394 print(lines[i])
9395
9396
9397 self.assertEqual(w_eff_result[i][:62], lines[i][:62])
9398
9399
9400 w_eff_result_s = w_eff_result[i][62:].split()[::2]
9401 print(w_eff_result_s )
9402 lines_s = lines[i][62:].split()[::2]
9403 print(lines_s)
9404
9405 for j in range(len(lines_s)):
9406 print(w_eff_result_s[j], lines_s[j])
9407
9408 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14)
9409
9410
9411 w_eff_file.close()
9412
9413
9415 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations.
9416
9417 This follows Task 7822.
9418 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.
9419
9420 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}.
9421 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model.
9422 """
9423
9424
9425 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep
9426
9427
9428 pipe_name = 'base pipe'
9429 pipe_bundle = 'relax_disp'
9430 pipe_type = 'relax_disp'
9431
9432
9433 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type)
9434
9435 file = data_path + '1_setup_r1rho_GUI.py'
9436 self.interpreter.script(file=file, dir=None)
9437
9438
9439 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False)
9440
9441
9442 self.interpreter.select.spin(spin_id=':52@N', change_all=False)
9443
9444
9445 self.interpreter.relax_disp.select_model(MODEL_R2EFF)
9446
9447
9448 check_intensity_errors()
9449
9450
9451 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1)
9452
9453
9454 min_algor = 'Newton'
9455 constraints = True
9456 if constraints:
9457 min_options = ('%s'%(min_algor),)
9458
9459 min_algor = 'Method of Multipliers'
9460 scaling_matrix = assemble_scaling_matrix(scaling=True)
9461
9462
9463 all_spin_ids = []
9464 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9465 all_spin_ids.append(spin_id)
9466
9467 spins = spin_ids_to_containers(all_spin_ids[:1])
9468
9469
9470 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0])
9471 else:
9472 min_options = ()
9473 A, b = None, None
9474 min_options = ()
9475 sim_boot = 200
9476 scaling_list = [1.0, 1.0]
9477
9478
9479 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1)
9480
9481
9482 err_attr_list = ['r2eff_err', 'i0_err']
9483
9484 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9485
9486 for err_attr in err_attr_list:
9487 if hasattr(cur_spin, err_attr):
9488 delattr(cur_spin, err_attr)
9489
9490
9491 my_dic = {}
9492 param_key_list = []
9493 est_keys = []
9494 est_key = '-2'
9495 est_keys.append(est_key)
9496 spin_id_list = []
9497
9498 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9499
9500 my_dic[spin_id] = {}
9501
9502
9503 my_dic[spin_id][est_key] = {}
9504
9505
9506 spin_id_list.append(spin_id)
9507
9508
9509 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
9510
9511 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
9512
9513 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
9514
9515
9516 param_key_list.append(param_key)
9517
9518
9519 my_dic[spin_id][est_key][param_key] = {}
9520
9521 values = []
9522 errors = []
9523 times = []
9524 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point):
9525 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time))
9526 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True))
9527 times.append(time)
9528
9529
9530 values = asarray(values)
9531 errors = asarray(errors)
9532 times = asarray(times)
9533
9534 r2eff = getattr(cur_spin, 'r2eff')[param_key]
9535 i0 = getattr(cur_spin, 'i0')[param_key]
9536
9537 R_m_sim_l = []
9538 I0_m_sim_l = []
9539 for j in range(sim_boot):
9540 if j in range(0, 100000, 100):
9541 print("Simulation %i"%j)
9542
9543
9544
9545 I_err = []
9546 for j, error in enumerate(errors):
9547 I_error = gauss(values[j], error)
9548 I_err.append(I_error)
9549
9550 I_err = asarray(I_err)
9551
9552 x0 = [r2eff, i0]
9553 model = Relax_fit_opt(num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list)
9554
9555
9556
9557
9558
9559
9560
9561
9562 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)
9563
9564 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j
9565 R_m_sim_l.append(R_m_sim_j)
9566 I0_m_sim_l.append(I0_m_sim_j)
9567
9568
9569 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1)
9570 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1)
9571 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim
9572 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim
9573
9574
9575 self.interpreter.relax_disp.r2eff_err_estimate()
9576
9577 est_key = '-1'
9578 est_keys.append(est_key)
9579
9580
9581 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9582
9583 my_dic[spin_id][est_key] = {}
9584
9585 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
9586
9587 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
9588
9589
9590 my_dic[spin_id][est_key][param_key] = {}
9591
9592
9593
9594 for err_attr in err_attr_list:
9595 if hasattr(cur_spin, err_attr):
9596 get_err_attr = getattr(cur_spin, err_attr)[param_key]
9597 else:
9598 get_err_attr = 0.0
9599
9600
9601 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr
9602
9603
9604
9605 mc_number_list = list(range(0, 1000, 250))
9606
9607 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']
9608
9609
9610 for number in mc_number_list:
9611
9612 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9613
9614 for err_attr in err_attr_list:
9615 if hasattr(cur_spin, err_attr):
9616 delattr(cur_spin, err_attr)
9617
9618
9619 for sim_attr in sim_attr_list:
9620 if hasattr(cur_spin, sim_attr):
9621 delattr(cur_spin, sim_attr)
9622
9623 self.interpreter.monte_carlo.setup(number=number)
9624 self.interpreter.monte_carlo.create_data()
9625 self.interpreter.monte_carlo.initial_values()
9626 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints)
9627 self.interpreter.eliminate()
9628 self.interpreter.monte_carlo.error_analysis()
9629
9630 est_key = '%i'%number
9631 est_keys.append(est_key)
9632
9633
9634 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9635
9636 my_dic[spin_id][est_key] = {}
9637
9638 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True):
9639
9640 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point)
9641
9642
9643 my_dic[spin_id][est_key][param_key] = {}
9644
9645
9646
9647 for err_attr in err_attr_list:
9648 if hasattr(cur_spin, err_attr):
9649 get_err_attr = getattr(cur_spin, err_attr)[param_key]
9650 else:
9651 get_err_attr = 0.0
9652
9653
9654 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr
9655
9656
9657 err_attr = err_attr_list[0]
9658
9659
9660 text_list = []
9661
9662
9663 for spin_id in spin_id_list:
9664 for est_key in est_keys:
9665
9666 r2eff_err_list = []
9667
9668 for param_key in param_key_list:
9669
9670 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr]
9671
9672
9673 r2eff_err_list.append(r2eff_err)
9674
9675
9676 sum_array = sum(array(r2eff_err_list))
9677
9678
9679 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list)
9680
9681
9682 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array)
9683 text_list.append(text)
9684
9685
9686
9687 filepath = NamedTemporaryFile(delete=False).name
9688
9689 w_file = open(filepath, 'w')
9690
9691 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.")
9692
9693 for text in text_list:
9694
9695 print(text)
9696
9697
9698 w_file.write(text+"\n")
9699
9700
9701 w_file.close()
9702
9703 print("Filepath is: %s"%filepath)
9704 print("Start 'gnuplot' and write:")
9705 print("set term dumb")
9706 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9707
9708
9710 """Verification of test_r1rho_kjaergaard_missing_r1."""
9711
9712
9713
9714
9715
9716 print("\n\n################")
9717 print("Printing results")
9718 print("################\n")
9719 for model in models:
9720
9721 if model == MODEL_R2EFF:
9722 continue
9723
9724
9725 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model))
9726 print("\nModel: %s" % (model))
9727
9728
9729 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
9730
9731 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
9732
9733
9734 print("Optimised parameters for spin: %s" % (spin_string))
9735 for param in cur_spin.params + ['chi2']:
9736
9737 if param in ['r1', 'r2']:
9738 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True):
9739
9740 r20_key = generate_r20_key(exp_type=exp_type, frq=frq)
9741
9742
9743 value = getattr(cur_spin, param)[r20_key]
9744
9745
9746 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value))
9747
9748
9749 if spin_id == ':52@N':
9750 if param == 'r1':
9751 if model == MODEL_NOREX:
9752 if r2eff_estimate == 'direct':
9753 self.assertAlmostEqual(value, 1.46138805)
9754 elif r2eff_estimate == 'MC2000':
9755 self.assertAlmostEqual(value, 1.46328102)
9756 elif r2eff_estimate == 'chi2_pyt':
9757 self.assertAlmostEqual(value, 1.43820629)
9758 elif model == MODEL_DPL94:
9759 if r2eff_estimate == 'direct':
9760 self.assertAlmostEqual(value, 1.44845742)
9761 elif r2eff_estimate == 'MC2000':
9762 self.assertAlmostEqual(value, 1.45019848)
9763 elif r2eff_estimate == 'chi2_pyt':
9764 self.assertAlmostEqual(value, 1.44666512)
9765 elif model == MODEL_TP02:
9766 if r2eff_estimate == 'direct':
9767 self.assertAlmostEqual(value, 1.54354392)
9768 elif r2eff_estimate == 'MC2000':
9769 self.assertAlmostEqual(value, 1.54352369)
9770 elif r2eff_estimate == 'chi2_pyt':
9771 self.assertAlmostEqual(value, 1.55964020)
9772 elif model == MODEL_TAP03:
9773 if r2eff_estimate == 'direct':
9774 self.assertAlmostEqual(value, 1.54356410)
9775 elif r2eff_estimate == 'MC2000':
9776 self.assertAlmostEqual(value, 1.54354367)
9777 elif r2eff_estimate == 'chi2_pyt':
9778 self.assertAlmostEqual(value, 1.55967157)
9779 elif model == MODEL_MP05:
9780 if r2eff_estimate == 'direct':
9781 self.assertAlmostEqual(value, 1.54356416)
9782 elif r2eff_estimate == 'MC2000':
9783 self.assertAlmostEqual(value, 1.54354372)
9784 elif r2eff_estimate == 'chi2_pyt':
9785 self.assertAlmostEqual(value, 1.55967163)
9786 elif model == MODEL_NS_R1RHO_2SITE:
9787 if r2eff_estimate == 'direct':
9788 self.assertAlmostEqual(value, 1.41359221, 5)
9789 elif r2eff_estimate == 'MC2000':
9790 self.assertAlmostEqual(value, 1.41321968, 5)
9791 elif r2eff_estimate == 'chi2_pyt':
9792 self.assertAlmostEqual(value, 1.36303129, 5)
9793
9794 elif param == 'r2':
9795 if model == MODEL_NOREX:
9796 if r2eff_estimate == 'direct':
9797 self.assertAlmostEqual(value, 11.48392439)
9798 elif r2eff_estimate == 'MC2000':
9799 self.assertAlmostEqual(value, 11.48040934)
9800 elif r2eff_estimate == 'chi2_pyt':
9801 self.assertAlmostEqual(value, 11.47224488)
9802 elif model == MODEL_DPL94:
9803 if r2eff_estimate == 'direct':
9804 self.assertAlmostEqual(value, 10.15688372, 6)
9805 elif r2eff_estimate == 'MC2000':
9806 self.assertAlmostEqual(value, 10.16304887, 6)
9807 elif r2eff_estimate == 'chi2_pyt':
9808 self.assertAlmostEqual(value, 9.20037797, 6)
9809 elif model == MODEL_TP02:
9810 if r2eff_estimate == 'direct':
9811 self.assertAlmostEqual(value, 9.72654896, 6)
9812 elif r2eff_estimate == 'MC2000':
9813 self.assertAlmostEqual(value, 9.72772726, 6)
9814 elif r2eff_estimate == 'chi2_pyt':
9815 self.assertAlmostEqual(value, 9.53948340, 6)
9816 elif model == MODEL_TAP03:
9817 if r2eff_estimate == 'direct':
9818 self.assertAlmostEqual(value, 9.72641887, 6)
9819 elif r2eff_estimate == 'MC2000':
9820 self.assertAlmostEqual(value, 9.72759374, 6)
9821 elif r2eff_estimate == 'chi2_pyt':
9822 self.assertAlmostEqual(value, 9.53926913, 6)
9823 elif model == MODEL_MP05:
9824 if r2eff_estimate == 'direct':
9825 self.assertAlmostEqual(value, 9.72641723, 6)
9826 elif r2eff_estimate == 'MC2000':
9827 self.assertAlmostEqual(value, 9.72759220, 6)
9828 elif r2eff_estimate == 'chi2_pyt':
9829 self.assertAlmostEqual(value, 9.53926778, 6)
9830 elif model == MODEL_NS_R1RHO_2SITE:
9831 if r2eff_estimate == 'direct':
9832 self.assertAlmostEqual(value, 9.34531535, 5)
9833 elif r2eff_estimate == 'MC2000':
9834 self.assertAlmostEqual(value, 9.34602793, 5)
9835 elif r2eff_estimate == 'chi2_pyt':
9836 self.assertAlmostEqual(value, 9.17631409, 5)
9837
9838
9839 else:
9840
9841 value = getattr(cur_spin, param)
9842
9843
9844 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value))
9845
9846
9847 if spin_id == ':52@N':
9848 if param == 'phi_ex':
9849 if model == MODEL_DPL94:
9850 if r2eff_estimate == 'direct':
9851 self.assertAlmostEqual(value, 0.07599563)
9852 elif r2eff_estimate == 'MC2000':
9853 self.assertAlmostEqual(value, 0.07561937)
9854 elif r2eff_estimate == 'chi2_pyt':
9855 self.assertAlmostEqual(value, 0.12946061)
9856
9857 elif param == 'pA':
9858 if model == MODEL_TP02:
9859 if r2eff_estimate == 'direct':
9860 self.assertAlmostEqual(value, 0.88827040)
9861 elif r2eff_estimate == 'MC2000':
9862 self.assertAlmostEqual(value, 0.88807487)
9863 elif r2eff_estimate == 'chi2_pyt':
9864 self.assertAlmostEqual(value, 0.87746233)
9865 elif model == MODEL_TAP03:
9866 if r2eff_estimate == 'direct':
9867 self.assertAlmostEqual(value, 0.88828922)
9868 elif r2eff_estimate == 'MC2000':
9869 self.assertAlmostEqual(value, 0.88809318)
9870 elif r2eff_estimate == 'chi2_pyt':
9871 self.assertAlmostEqual(value, 0.87747558)
9872 elif model == MODEL_MP05:
9873 if r2eff_estimate == 'direct':
9874 self.assertAlmostEqual(value, 0.88828924, 6)
9875 elif r2eff_estimate == 'MC2000':
9876 self.assertAlmostEqual(value, 0.88809321)
9877 elif r2eff_estimate == 'chi2_pyt':
9878 self.assertAlmostEqual(value, 0.87747562)
9879 elif model == MODEL_NS_R1RHO_2SITE:
9880 if r2eff_estimate == 'direct':
9881 self.assertAlmostEqual(value, 0.94504369, 6)
9882 elif r2eff_estimate == 'MC2000':
9883 self.assertAlmostEqual(value, 0.94496541, 6)
9884 elif r2eff_estimate == 'chi2_pyt':
9885 self.assertAlmostEqual(value, 0.92084707, 6)
9886
9887 elif param == 'dw':
9888 if model == MODEL_TP02:
9889 if r2eff_estimate == 'direct':
9890 self.assertAlmostEqual(value, 1.08875840, 6)
9891 elif r2eff_estimate == 'MC2000':
9892 self.assertAlmostEqual(value, 1.08765638, 6)
9893 elif r2eff_estimate == 'chi2_pyt':
9894 self.assertAlmostEqual(value, 1.09753230, 6)
9895 elif model == MODEL_TAP03:
9896 if r2eff_estimate == 'direct':
9897 self.assertAlmostEqual(value, 1.08837238, 6)
9898 elif r2eff_estimate == 'MC2000':
9899 self.assertAlmostEqual(value, 1.08726698, 6)
9900 elif r2eff_estimate == 'chi2_pyt':
9901 self.assertAlmostEqual(value, 1.09708821, 6)
9902 elif model == MODEL_MP05:
9903 if r2eff_estimate == 'direct':
9904 self.assertAlmostEqual(value, 1.08837241, 6)
9905 elif r2eff_estimate == 'MC2000':
9906 self.assertAlmostEqual(value, 1.08726706, 6)
9907 elif r2eff_estimate == 'chi2_pyt':
9908 self.assertAlmostEqual(value, 1.09708832, 6)
9909 elif model == MODEL_NS_R1RHO_2SITE:
9910 if r2eff_estimate == 'direct':
9911 self.assertAlmostEqual(value, 1.56001812, 5)
9912 elif r2eff_estimate == 'MC2000':
9913 self.assertAlmostEqual(value, 1.55833321, 5)
9914 elif r2eff_estimate == 'chi2_pyt':
9915 self.assertAlmostEqual(value, 1.36406712, 5)
9916
9917 elif param == 'kex':
9918 if model == MODEL_DPL94:
9919 if r2eff_estimate == 'direct':
9920 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7)
9921 elif r2eff_estimate == 'MC2000':
9922 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7)
9923 elif r2eff_estimate == 'chi2_pyt':
9924 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7)
9925 elif model == MODEL_TP02:
9926 if r2eff_estimate == 'direct':
9927 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7)
9928 elif r2eff_estimate == 'MC2000':
9929 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7)
9930 elif r2eff_estimate == 'chi2_pyt':
9931 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7)
9932 elif model == MODEL_TAP03:
9933 if r2eff_estimate == 'direct':
9934 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7)
9935 elif r2eff_estimate == 'MC2000':
9936 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7)
9937 elif r2eff_estimate == 'chi2_pyt':
9938 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7)
9939 elif model == MODEL_MP05:
9940 if r2eff_estimate == 'direct':
9941 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7)
9942 elif r2eff_estimate == 'MC2000':
9943 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7)
9944 elif r2eff_estimate == 'chi2_pyt':
9945 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7)
9946 elif model == MODEL_NS_R1RHO_2SITE:
9947 if r2eff_estimate == 'direct':
9948 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6)
9949 elif r2eff_estimate == 'MC2000':
9950 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6)
9951 elif r2eff_estimate == 'chi2_pyt':
9952 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6)
9953
9954 elif param == 'chi2':
9955 if model == MODEL_NOREX:
9956 if r2eff_estimate == 'direct':
9957 self.assertAlmostEqual(value, 848.42016907, 5)
9958 elif r2eff_estimate == 'MC2000':
9959 self.assertAlmostEqual(value, 3363.95829122, 5)
9960 elif r2eff_estimate == 'chi2_pyt':
9961 self.assertAlmostEqual(value, 5976.49946726, 5)
9962 elif model == MODEL_DPL94:
9963 if r2eff_estimate == 'direct':
9964 self.assertAlmostEqual(value, 179.47041241)
9965 elif r2eff_estimate == 'MC2000':
9966 self.assertAlmostEqual(value, 710.24767560)
9967 elif r2eff_estimate == 'chi2_pyt':
9968 self.assertAlmostEqual(value, 612.72616697, 5)
9969 elif model == MODEL_TP02:
9970 if r2eff_estimate == 'direct':
9971 self.assertAlmostEqual(value, 29.33882530, 6)
9972 elif r2eff_estimate == 'MC2000':
9973 self.assertAlmostEqual(value, 114.47142772, 6)
9974 elif r2eff_estimate == 'chi2_pyt':
9975 self.assertAlmostEqual(value, 250.50838162, 5)
9976 elif model == MODEL_TAP03:
9977 if r2eff_estimate == 'direct':
9978 self.assertAlmostEqual(value, 29.29050673, 6)
9979 elif r2eff_estimate == 'MC2000':
9980 self.assertAlmostEqual(value, 114.27987534)
9981 elif r2eff_estimate == 'chi2_pyt':
9982 self.assertAlmostEqual(value, 250.04050719, 5)
9983 elif model == MODEL_MP05:
9984 if r2eff_estimate == 'direct':
9985 self.assertAlmostEqual(value, 29.29054301, 6)
9986 elif r2eff_estimate == 'MC2000':
9987 self.assertAlmostEqual(value, 114.28002272)
9988 elif r2eff_estimate == 'chi2_pyt':
9989 self.assertAlmostEqual(value, 250.04077478, 5)
9990 elif model == MODEL_NS_R1RHO_2SITE:
9991 if r2eff_estimate == 'direct':
9992 self.assertAlmostEqual(value, 34.44010543, 6)
9993 elif r2eff_estimate == 'MC2000':
9994 self.assertAlmostEqual(value, 134.14368365)
9995 elif r2eff_estimate == 'chi2_pyt':
9996 self.assertAlmostEqual(value, 278.55121388, 5)
9997
9998
9999
10000 model = 'final'
10001 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model))
10002 print("\nFinal pipe")
10003
10004
10005 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True):
10006
10007 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn)
10008
10009
10010 print("Optimised model for spin: %s" % (spin_string))
10011 param = 'model'
10012
10013
10014 value = getattr(cur_spin, param)
10015 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value))
10016
10017
10018
10019 file_names = ['r1rho_prime', 'r1']
10020
10021 for file_name_i in file_names:
10022
10023
10024 file_name = "%s.out" % file_name_i
10025
10026
10027 file_path = get_file_path(file_name, result_dir_name + sep + model)
10028
10029
10030 print("Testing file access to: %s"%file_path)
10031 self.assertTrue(access(file_path, F_OK))
10032
10033
10034 file_prod = open(file_path)
10035 lines_prod = file_prod.readlines()
10036 file_prod.close()
10037
10038
10039 for i, line in enumerate(lines_prod):
10040
10041 line_split = line.split()
10042
10043
10044 if line_split[0] == "#":
10045 print(line),
10046 continue
10047
10048
10049 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split
10050 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error)
10051
10052 if res_num == '52':
10053
10054 self.assertNotEqual(val, 'None')
10055