1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from os import sep
24 from re import search
25 from tempfile import mkdtemp
26
27
28 from data_store import Relax_data_store; ds = Relax_data_store()
29 import dep_check
30 from pipe_control.mol_res_spin import spin_index_loop, spin_loop
31 from pipe_control import pipes
32 from lib.errors import RelaxError
33 from status import Status; status = Status()
34 from test_suite.system_tests.base_classes import SystemTestCase
35
36
38 """Class for testing various aspects specific to relaxation curve-fitting."""
39
40 - def __init__(self, methodName='runTest'):
41 """Skip the tests if the C modules are non-functional.
42
43 @keyword methodName: The name of the test.
44 @type methodName: str
45 """
46
47
48 super(Relax_fit, self).__init__(methodName)
49
50
51 if not dep_check.C_module_exp_fn:
52
53 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type])
54
55
57 """Set up for all the functional tests."""
58
59
60 self.interpreter.pipe.create('mf', 'mf')
61
62
63 ds.tmpdir = mkdtemp()
64
65
67 """Check the results of the curve-fitting."""
68
69
70 relax_times = [0.0176, 0.0176, 0.0352, 0.0704, 0.0704, 0.1056, 0.1584, 0.1584, 0.1936, 0.1936]
71 chi2 = [None, None, None, 2.916952651567855, 5.4916923952919632, 16.21182245065274, 4.3591263759462926, 9.8925377583244316, None, None, None, 6.0238341559877782]
72 rx = [None, None, None, 8.0814894819820662, 8.6478971039559642, 9.5710638183013845, 10.716551838066295, 11.143793935455122, None, None, None, 12.82875370075309]
73 i0 = [None, None, None, 1996050.9679875025, 2068490.9458927638, 1611556.5194095275, 1362887.2331948928, 1877670.5623875158, None, None, None, 897044.17382064369]
74
75
76 self.assertEqual(cdp.curve_type, 'exp')
77 self.assertEqual(cdp.int_method, ds.int_type)
78 self.assertEqual(len(cdp.relax_times), 10)
79 cdp_relax_times = sorted(cdp.relax_times.values())
80 for i in range(10):
81 self.assertEqual(cdp_relax_times[i], relax_times[i])
82
83
84 for key in cdp.sigma_I:
85 self.assertEqual(cdp.sigma_I[key], 10578.039482421433)
86 self.assertEqual(cdp.var_I[key], 111894919.29166669)
87
88
89 i = 0
90 for spin in spin_loop():
91
92 if chi2[i] == None:
93 self.assert_(not hasattr(spin, 'chi2'))
94
95
96 else:
97 self.assertAlmostEqual(spin.chi2, chi2[i])
98 self.assertAlmostEqual(spin.rx, rx[i])
99 self.assertAlmostEqual(spin.i0/1e6, i0[i]/1e6)
100
101
102 i = i + 1
103 if i >= 12:
104 break
105
106
108 """Test the relaxation curve fitting, replicating U{bug #12670<https://web.archive.org/web/https://gna.org/bugs/?12670>} and U{bug #12679<https://web.archive.org/web/https://gna.org/bugs/?12679>}."""
109
110
111 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'1UBQ_relax_fit.py')
112
113
114 file = open(ds.tmpdir + sep + 'intensities.agr')
115 lines = file.readlines()
116 file.close()
117
118
119 for i in range(len(lines)):
120
121 if search('@target', lines[i]):
122 index = i + 2
123
124
125 lines[i] = lines[i].split()
126
127
128 self.assertEqual(len(lines[index]), 2)
129 self.assertEqual(lines[index][0], '0.004')
130 self.assertEqual(lines[index][1], '487178.000000000000000')
131
132
134 """Test for zero errors in Grace plots, replicating U{bug #18789<https://web.archive.org/web/https://gna.org/bugs/?18789>}."""
135
136
137 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'curve_fitting'+sep+'bug_18789_no_grace_errors.py')
138
139
140 file = open(ds.tmpdir + sep + 'rx.agr')
141 lines = file.readlines()
142 file.close()
143
144
145 for i in range(len(lines)):
146
147 if search('@target', lines[i]):
148 index = i + 2
149
150
151 lines[i] = lines[i].split()
152
153
154 self.assertEqual(len(lines[index]), 3)
155 self.assertNotEqual(float(lines[index][2]), 0.0)
156 self.assertNotEqual(float(lines[index+1][2]), 0.0)
157
158
160 """Test for the failure of relaxation curve-fitting, replicating U{bug #19887<https://web.archive.org/web/https://gna.org/bugs/?19887>}."""
161
162
163 try:
164 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'curve_fitting'+sep+'bug_19887_curvefit_fail.py')
165
166
167 except RelaxError:
168 pass
169
170
172 """Test the relaxation curve fitting C modules."""
173
174
175 ds.int_type = 'height'
176
177
178 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit.py')
179
180
181 self.check_curve_fitting()
182
183
185 """Test the relaxation curve fitting C modules."""
186
187
188 ds.int_type = 'point sum'
189
190
191 self.script_exec(status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit.py')
192
193
194 self.check_curve_fitting()
195
196
198 """The Sparky peak height loading test."""
199
200
201 self.interpreter.state.load(state='basic_heights_T2_ncyc1', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states', force=True)
202
203
204 self.interpreter.pipe.create('new', 'relax_fit')
205
206
207 self.interpreter.sequence.read(file="Ap4Aase.seq", dir=status.install_path + sep+'test_suite'+sep+'shared_data', res_num_col=1, res_name_col=2)
208
209
210 self.interpreter.spin.name(name='N')
211
212
213 self.interpreter.spectrum.read_intensities(file="T2_ncyc1_ave.list", dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting', spectrum_id='0.0176')
214
215
216
217
218
219
220 dp_new = pipes.get_pipe('new')
221 dp_rx = pipes.get_pipe('rx')
222
223
224 for mol_index, res_index, spin_index in spin_index_loop():
225
226 new_spin = dp_new.mol[mol_index].res[res_index].spin[spin_index]
227 orig_spin = dp_rx.mol[mol_index].res[res_index].spin[spin_index]
228
229
230 self.assertEqual(dp_new.mol[mol_index].name, dp_rx.mol[mol_index].name)
231 self.assertEqual(dp_new.mol[mol_index].res[res_index].num, dp_rx.mol[mol_index].res[res_index].num)
232 self.assertEqual(dp_new.mol[mol_index].res[res_index].name, dp_rx.mol[mol_index].res[res_index].name)
233 self.assertEqual(new_spin.num, orig_spin.num)
234 self.assertEqual(new_spin.name, orig_spin.name)
235
236
237 if not orig_spin.select:
238 continue
239
240
241 if hasattr(orig_spin, 'intensities'):
242 for id in dp_new.spectrum_ids:
243 self.assertEqual(orig_spin.intensities[id], new_spin.intensities[id])
244