1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 from os import sep
25 from re import search
26 from string import split
27 from tempfile import mkdtemp
28
29
30 from base_classes import SystemTestCase
31 from data import Relax_data_store; ds = Relax_data_store()
32 from generic_fns.mol_res_spin import spin_index_loop, spin_loop
33 from generic_fns import pipes
34 from status import Status; status = Status()
35
36
38 """Class for testing various aspects specific to relaxation curve-fitting."""
39
41 """Set up for all the functional tests."""
42
43
44 self.interpreter.pipe.create('mf', 'mf')
45
46
47 ds.tmpdir = mkdtemp()
48
49
51 """Check the results of the curve-fitting."""
52
53
54 relax_times = [0.0176, 0.0176, 0.0352, 0.0704, 0.0704, 0.1056, 0.1584, 0.1584, 0.1936, 0.1936]
55 chi2 = [None, None, None, 2.916952651567855, 5.4916923952919632, 16.21182245065274, 4.3591263759462926, 9.8925377583244316, None, None, None, 6.0238341559877782]
56 rx = [None, None, None, 8.0814894819820662, 8.6478971039559642, 9.5710638183013845, 10.716551838066295, 11.143793935455122, None, None, None, 12.82875370075309]
57 i0 = [None, None, None, 1996050.9679875025, 2068490.9458927638, 1611556.5194095275, 1362887.2331948928, 1877670.5623875158, None, None, None, 897044.17382064369]
58
59
60 self.assertEqual(cdp.curve_type, 'exp')
61 self.assertEqual(cdp.int_method, ds.int_type)
62 self.assertEqual(len(cdp.relax_times), 10)
63 cdp_relax_times = sorted(cdp.relax_times.values())
64 for i in range(10):
65 self.assertEqual(cdp_relax_times[i], relax_times[i])
66
67
68 for key in cdp.sigma_I:
69 self.assertEqual(cdp.sigma_I[key], 10578.03948242143)
70 self.assertEqual(cdp.var_I[key], 111894919.29166666)
71
72
73 i = 0
74 for spin in spin_loop():
75
76 if chi2[i] == None:
77 self.assert_(not hasattr(spin, 'chi2'))
78
79
80 else:
81 self.assertAlmostEqual(spin.chi2, chi2[i])
82 self.assertAlmostEqual(spin.rx, rx[i])
83 self.assertAlmostEqual(spin.i0/1e6, i0[i]/1e6)
84
85
86 i = i + 1
87 if i >= 12:
88 break
89
90
92 """Test the relaxation curve fitting, replicating bug #12670 and bug #12679."""
93
94
95 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'1UBQ_relax_fit.py')
96
97
98 file = open(ds.tmpdir + sep + 'intensities.agr')
99 lines = file.readlines()
100 file.close()
101
102
103 for i in xrange(len(lines)):
104
105 if search('@target', lines[i]):
106 index = i + 2
107
108
109 lines[i] = split(lines[i])
110
111
112 self.assertEqual(len(lines[index]), 2)
113 self.assertEqual(lines[index][0], '0.004')
114 self.assertEqual(lines[index][1], '487178.0')
115
116
118 """Test for zero errors in Grace plots, replicating bug #18789."""
119
120
121 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'curve_fitting'+sep+'bug_18789_no_grace_errors.py')
122
123
124 file = open(ds.tmpdir + sep + 'rx.agr')
125 lines = file.readlines()
126 file.close()
127
128
129 for i in xrange(len(lines)):
130
131 if search('@target', lines[i]):
132 index = i + 2
133
134
135 lines[i] = split(lines[i])
136
137
138 self.assertEqual(len(lines[index]), 3)
139 self.assertNotEqual(float(lines[index][2]), 0.0)
140 self.assertNotEqual(float(lines[index+1][2]), 0.0)
141
142
144 """Test the relaxation curve fitting C modules."""
145
146
147 ds.int_type = 'height'
148
149
150 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit.py')
151
152
153 self.check_curve_fitting()
154
155
157 """Test the relaxation curve fitting C modules."""
158
159
160 ds.int_type = 'point sum'
161
162
163 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_fit.py')
164
165
166 self.check_curve_fitting()
167
168
170 """The Sparky peak height loading test."""
171
172
173 self.interpreter.state.load(state='basic_heights_T2_ncyc1', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states', force=True)
174
175
176 self.interpreter.pipe.create('new', 'relax_fit')
177
178
179 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)
180
181
182 self.interpreter.spin.name(name='N')
183
184
185 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')
186
187
188
189
190
191
192 dp_new = pipes.get_pipe('new')
193 dp_rx = pipes.get_pipe('rx')
194
195
196 for mol_index, res_index, spin_index in spin_index_loop():
197
198 new_spin = dp_new.mol[mol_index].res[res_index].spin[spin_index]
199 orig_spin = dp_rx.mol[mol_index].res[res_index].spin[spin_index]
200
201
202 self.assertEqual(dp_new.mol[mol_index].name, dp_rx.mol[mol_index].name)
203 self.assertEqual(dp_new.mol[mol_index].res[res_index].num, dp_rx.mol[mol_index].res[res_index].num)
204 self.assertEqual(dp_new.mol[mol_index].res[res_index].name, dp_rx.mol[mol_index].res[res_index].name)
205 self.assertEqual(new_spin.num, orig_spin.num)
206 self.assertEqual(new_spin.name, orig_spin.name)
207
208
209 if not orig_spin.select:
210 continue
211
212
213 if hasattr(orig_spin, 'intensities'):
214 for id in dp_new.spectrum_ids:
215 self.assertEqual(orig_spin.intensities[id], new_spin.intensities[id])
216