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 sep
26 from os.path import dirname
27 from tempfile import mkdtemp, NamedTemporaryFile
28
29
30 from data_store import Relax_data_store; ds = Relax_data_store()
31 from pipe_control.mol_res_spin import spin_loop
32 from status import Status; status = Status()
33 from test_suite.system_tests.base_classes import SystemTestCase
34
35
37 """TestCase class for the functional tests for the support of different spectrum intensity calculation or errors, signal to noise and plotting."""
38
39
41 """Set up for all the functional tests."""
42
43
44 ds.tmpdir = mkdtemp()
45 self.tmpdir = ds.tmpdir
46
48 """Setup intensity data.
49
50 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).
51 """
52
53
54 pipe_name = 'base pipe'
55 pipe_bundle = 'relax_disp'
56 pipe_type = 'relax_disp'
57
58
59 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type)
60
61 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'
62
63
64 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path)
65
66
67 self.interpreter.spin.isotope(isotope='15N')
68
69
70 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height')
71
72
73 ncycfile=open(data_path + sep + 'ncyc.txt', 'r')
74
75
76 ncyclist = []
77
78 i = 0
79 for line in ncycfile:
80 ncyc = line.split()[0]
81 time_T2 = float(line.split()[1])
82 vcpmg = line.split()[2]
83 set_sfrq = float(line.split()[3])
84 rmsd_err = float(line.split()[4])
85
86
87 if float(vcpmg) == 0.0:
88 vcpmg = None
89 else:
90 vcpmg = round(float(vcpmg), 3)
91
92
93 ncyclist.append(int(ncyc))
94
95
96 current_id = "Z_A%s"%(i)
97
98
99 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG')
100
101
102 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id)
103
104
105 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz')
106
107
108 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2)
109
110
111 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg)
112
113 i += 1
114
115
116 self.interpreter.spectrum.error_analysis_per_field()
117
118
119 ds.data = [
120 [1, 1711.104, 3040.110, 8.514, 121.681, +5.586445e+05, 'A3N-HN', 1.0000, 1.7492, 0.9997, 1.0075, 1.0081, 0.8991, 1.0205, 0.9893, 1.0145, 1.0078, 1.0133, 1.0020, 0.9995, 1.0020, 1.0249, 1.7571, 1.0016],
121 [2, 2011.491, 4112.494, 8.025, 117.805, +6.213668e+05, 'E4N-HN', 1.0000, 1.6032, -0.8322, 0.9920, 0.9951, 0.8300, 0.9458, 0.9689, 0.9246, 0.9936, 0.9914, 0.9842, 1.0011, 0.8529, 0.9727, 1.5845, 0.9822],
122 [3, 1974.019, 2629.250, 8.086, 123.166, +4.592940e+05, 'F5N-HN', 1.0000, 1.8235, 0.8614, 1.0135, 1.0134, 0.8825, 0.9332, 0.9772, 0.9273, 0.9803, 0.9986, 1.0000, 1.0012, 0.8923, 0.9421, 1.8102, 1.0062],
123 [4, 1608.518, 3683.374, 8.681, 119.356, +5.293190e+05, 'D6N-HN', 1.0000, 1.6865, 0.8531, 1.0052, 1.0065, 0.8530, 0.9280, 0.9594, 0.8989, 0.9914, 1.0115, 0.9743, 1.0063, 0.8177, 0.9264, 1.6855, 0.9981],
124 ]
125
126 ds.rmsd = [2.47e+03, 2.34e+03, 2.41e+03, 2.42e+03, 2.45e+03, 2.42e+03, 2.42e+03, 2.44e+03, 2.39e+03, 2.4e+03, 2.42e+03, 2.46e+03, 2.41e+03, 2.45e+03, 2.45e+03, 2.39e+03, 2.45e+03]
127
128
130 """Test calculation of signal to noise ratio.
131 """
132
133
134
135 self.setup_signal_noise_ratio()
136
137
138 self.interpreter.spectrum.sn_ratio()
139
140
141 i = 0
142 for cur_spin, cur_spin_id in spin_loop(return_id=True, skip_desel=True):
143
144 self.assertEqual(cur_spin_id, ":%s@N"%ds.data[i][6][1])
145
146
147 for j in range(17):
148
149 data_int = ds.data[i][j+7] * ds.data[i][5]
150 pint = cur_spin.peak_intensity['Z_A%i'%j]
151 self.assertEqual(pint, data_int)
152
153
154 data_rmsd = ds.rmsd[j]
155 self.assertEqual(cur_spin.baseplane_rmsd['Z_A%i'%j], data_rmsd)
156
157
158
159 pint_err = cur_spin.peak_intensity_err['Z_A%i'%j]
160 self.assertEqual(pint_err, ds.rmsd[j])
161
162
163 sn_ratio = data_int / data_rmsd
164 self.assertEqual(cur_spin.sn_ratio['Z_A%i'%j], sn_ratio)
165 self.assertEqual(cur_spin.sn_ratio['Z_A%i'%j], pint/pint_err)
166
167
168 i += 1
169
170
172 """Test grace plotting function for plotting the intensities per residue.
173 """
174
175
176
177 self.setup_signal_noise_ratio()
178
179
180 self.interpreter.deselect.spin(spin_id=':4@N', boolean='AND', change_all=False)
181
182
183 show_grace = False
184 if show_grace:
185 outfile= NamedTemporaryFile(delete=False).name
186 filedir = dirname(outfile)
187 else:
188 filedir = self.tmpdir
189 outfile = 'int.agr'
190
191 self.interpreter.grace.write(x_data_type='res_num', y_data_type='peak_intensity', file=outfile, dir=filedir, force=True)
192
193
194 if show_grace:
195 self.interpreter.grace.view(file=outfile, dir=filedir, grace_exe='xmgrace')
196
197
199 """Test grace plotting function for plotting the signal to noise ratio per residue.
200 """
201
202
203 self.setup_signal_noise_ratio()
204
205
206 self.interpreter.spectrum.sn_ratio()
207
208
209 self.interpreter.deselect.spin(spin_id=':4@N', boolean='AND', change_all=False)
210
211
212 show_grace = False
213 if show_grace:
214 outfile= NamedTemporaryFile(delete=False).name
215 filedir = dirname(outfile)
216 else:
217 filedir = self.tmpdir
218 outfile = 'int_sn.agr'
219
220 self.interpreter.grace.write(x_data_type='res_num', y_data_type='sn_ratio', file=outfile, dir=filedir, force=True)
221
222
223 if show_grace:
224 self.interpreter.grace.view(file=outfile, dir=filedir, grace_exe='xmgrace')
225
226
228 """Test the deselect.sn_ratio for signal to noise ratios, where all ID should evaluate to True.
229 """
230
231
232 self.setup_signal_noise_ratio()
233
234
235 self.interpreter.spectrum.sn_ratio()
236
237
238 self.interpreter.deselect.sn_ratio(ratio=400.0, operation='<', all_sn=True)
239
240
241 spin_ids_sel = []
242 spin_ids_desel = []
243
244
245 for cur_spin, cur_spin_id in spin_loop(return_id=True, skip_desel=False):
246 if cur_spin.select:
247 spin_ids_sel.append(cur_spin_id)
248 else:
249 spin_ids_desel.append(cur_spin_id)
250
251
252 self.assertEqual(spin_ids_sel, [':3@N', ':4@N'])
253 self.assertEqual(spin_ids_desel, [':5@N', ':6@N'])
254
255
257 """Test the deselect.sn_ratio for signal to noise ratios, where any ID should evaluate to True.
258 """
259
260
261 self.setup_signal_noise_ratio()
262
263
264 self.interpreter.spectrum.sn_ratio()
265
266
267 self.interpreter.deselect.sn_ratio(ratio=200.0, operation='<', all_sn=False)
268
269
270 spin_ids_sel = []
271 spin_ids_desel = []
272
273
274 for cur_spin, cur_spin_id in spin_loop(return_id=True, skip_desel=False):
275 if cur_spin.select:
276 spin_ids_sel.append(cur_spin_id)
277 else:
278 spin_ids_desel.append(cur_spin_id)
279
280
281 self.assertEqual(spin_ids_sel, [':3@N'])
282 self.assertEqual(spin_ids_desel, [':4@N', ':5@N', ':6@N'])
283
284
286 """Test the select.sn_ratio for signal to noise ratios, where all ID should evaluate to True.
287 """
288
289
290 self.setup_signal_noise_ratio()
291
292
293 self.interpreter.spectrum.sn_ratio()
294
295
296 self.interpreter.deselect.all()
297
298
299 self.interpreter.select.sn_ratio(ratio=400.0, operation='<', all_sn=True)
300
301
302 spin_ids_sel = []
303 spin_ids_desel = []
304
305
306 for cur_spin, cur_spin_id in spin_loop(return_id=True, skip_desel=False):
307 if cur_spin.select:
308 spin_ids_sel.append(cur_spin_id)
309 else:
310 spin_ids_desel.append(cur_spin_id)
311
312
313 self.assertEqual(spin_ids_sel, [':5@N', ':6@N'])
314 self.assertEqual(spin_ids_desel, [':3@N', ':4@N'])
315
316
318 """Test the select.sn_ratio for signal to noise ratios, where any ID should evaluate to True.
319 """
320
321
322 self.setup_signal_noise_ratio()
323
324
325 self.interpreter.spectrum.sn_ratio()
326
327
328 self.interpreter.deselect.all()
329
330
331 self.interpreter.select.sn_ratio(ratio=200.0, operation='<', all_sn=False)
332
333
334 spin_ids_sel = []
335 spin_ids_desel = []
336
337
338 for cur_spin, cur_spin_id in spin_loop(return_id=True, skip_desel=False):
339 if cur_spin.select:
340 spin_ids_sel.append(cur_spin_id)
341 else:
342 spin_ids_desel.append(cur_spin_id)
343
344
345 self.assertEqual(spin_ids_sel, [':4@N', ':5@N', ':6@N'])
346 self.assertEqual(spin_ids_desel, [':3@N'])
347