1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module for functions for checking different aspects of the dispersion setup.
25
26 These functions raise various RelaxErrors to help the user understand what went wrong. To avoid circular imports, these functions must be independent and not import anything from the specific_analyses.relax_disp package (the variables module is an exception).
27 """
28
29
30 from dep_check import C_module_exp_fn
31 from lib.dispersion.variables import EXP_TYPE_LIST_CPMG, EXP_TYPE_LIST_R1RHO, MODEL_LIST_R1RHO_OFF_RES, MODEL_NOREX
32 from lib.errors import RelaxError, RelaxFuncSetupError, RelaxNoPeakIntensityError
33 import specific_analyses
34
35
37 """Check for the presence of the compiled C-modules.
38
39 @raises RelaxError: If the compiled C-module is not present and exponential curves are required.
40 """
41
42
43 times = get_times()
44
45
46 for exp_type in times:
47 if len(times[exp_type]) > 1 and not C_module_exp_fn:
48 raise RelaxError("The exponential curve-fitting C module cannot be found.")
49
50
52 """Check that the CPMG frequencies or spin-lock field strengths have been set up.
53
54 @raises RelaxError: If the dispersion point data is missing.
55 """
56
57
58 if not hasattr(cdp, 'dispersion_points'):
59 raise RelaxError("The CPMG frequencies or spin-lock field strengths have not been set for any spectra.")
60
61
62 for id in cdp.exp_type:
63
64 if cdp.exp_type[id] in EXP_TYPE_LIST_CPMG:
65 if id not in cdp.cpmg_frqs:
66 raise RelaxError("The nu_CPMG frequency has not been set for the '%s' spectrum." % id)
67
68
69 elif cdp.exp_type[id] in EXP_TYPE_LIST_R1RHO:
70 if id not in cdp.spin_lock_nu1:
71 raise RelaxError("The spin-lock field strength has not been set for the '%s' spectrum." % id)
72
73
75 """Check if the experiment type have been set up for one or all IDs.
76
77 @param id: The experiment ID string. If not set, then all spectrum IDs will be checked.
78 @type id: None or str
79 @raises RelaxError: When the experiment type for the given ID is missing or, when not given, if the dispersion experiment type has not been set.
80 """
81
82
83 if not hasattr(cdp, 'exp_type'):
84 raise RelaxError("The relaxation dispersion experiment types have not been set for any spectra.")
85
86
87 if id != None:
88 if id not in cdp.exp_type:
89 raise RelaxError("The dispersion experiment type for the experiment ID '%s' has not been set." % id)
90
91
92 else:
93 found = False
94 for id in cdp.spectrum_ids:
95 if id in cdp.exp_type:
96 found = True
97 if not found:
98 raise RelaxError("The relaxation dispersion experiment type has not been set any spectra.")
99
100
102 """Check that only fixed time experiment types have been set up.
103
104 @raises RelaxError: If exponential curves are present.
105 """
106
107
108 for id in cdp.exp_type:
109
110 exp_type = cdp.exp_type[id]
111 frq = cdp.spectrometer_frq[id]
112
113 if specific_analyses.relax_disp.data.count_relax_times(exp_type = exp_type, frq = frq, ei = cdp.exp_type_list.index(cdp.exp_type[id])) > 1:
114 raise RelaxError("The experiment '%s' is not of the fixed relaxation time period data type." % exp_type)
115
116
129
130
132 """Prevent both fixed time and exponential curves from being analysed simultaneously.
133
134 @raises RelaxError: If mixed curve types are present.
135 """
136
137
138 if not hasattr(cdp, 'exp_type') or not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'relax_times'):
139 return False
140
141
142 times = get_times()
143
144
145 var_flag = False
146 fixed_flag = False
147 for exp_type in times:
148 if times[exp_type] == 1:
149 fixed_flag = True
150 else:
151 var_flag = True
152
153
154 if var_flag and fixed_flag:
155 raise RelaxError("Fixed time and exponential curves cannot be analysed simultaneously.")
156
157
159 """Check that the dispersion model has been set.
160
161 @keyword model: The model which to select.
162 @type model: str
163 @raises RelaxError: If the dispersion model has not been specified.
164 """
165
166
167 if not hasattr(cdp, 'model_type'):
168 if model != None:
169 text = "The relaxation dispersion model '%s' has not been specified. Set by: relax_disp.select_model('%s')." % (model, model)
170 else:
171 text = "The relaxation dispersion model has not been specified."
172 raise RelaxError(text)
173
174
176 """Check that the data pipe type is that of relaxation dispersion.
177
178 @raises RelaxFuncSetupError: If the data pipe type is not set to 'relax_disp'.
179 """
180
181
182 function_type = cdp.pipe_type
183 if function_type != 'relax_disp':
184 raise RelaxFuncSetupError(specific_analyses.setup.get_string(function_type))
185
186
188 """Check if R1 data is missing for the model.
189
190 @keyword model: The model to test for.
191 @type model: str
192 @return: Return True if R1 data is not available for the model.
193 @rtype: bool
194 """
195
196
197 if model in [MODEL_NOREX] + MODEL_LIST_R1RHO_OFF_RES:
198
199 if hasattr(cdp, 'ri_ids'):
200 return False
201
202
203 else:
204 return True
205
206
207 else:
208 return False
209
210
212 """Check if the spectrometer frequencies have been set up.
213
214 @raises RelaxError: If the spectrometer frequencies have not been set.
215 """
216
217
218 if not hasattr(cdp, 'relax_times'):
219 raise RelaxError("The relaxation times have not been set for any spectra.")
220
221
222 for id in cdp.exp_type:
223 if id not in cdp.relax_times:
224 raise RelaxError("The relaxation time has not been set for the '%s' spectrum." % id)
225
226
228 """Check that the data for each spectra ID is correctly set up.
229
230 This is an alias for the following checks:
231
232 - check_spectrum_ids()
233 - check_exp_type()
234 - check_spectrometer_frq()
235 - check_disp_points()
236 - check_relax_times()
237
238
239 @raises RelaxError: If data is missing.
240 """
241
242
243 check_spectrum_ids()
244 check_exp_type()
245 check_spectrometer_frq()
246 check_disp_points()
247 check_relax_times()
248
249
251 """Check if the spectrometer frequencies have been set up.
252
253 @raises RelaxError: If the spectrometer frequencies have not been set.
254 """
255
256
257 if not hasattr(cdp, 'spectrometer_frq'):
258 raise RelaxError("The spectrometer frequencies have not been set for any spectra.")
259
260
261 for id in cdp.exp_type:
262 if id not in cdp.spectrometer_frq:
263 raise RelaxError("The spectrometer frequency has not been set for the '%s' spectrum." % id)
264
265
267 """Check if spectrum IDs exist.
268
269 @raises RelaxNoPeakIntensityError: If no spectrum IDs exist.
270 """
271
272
273 if not hasattr(cdp, 'spectrum_ids') or len(cdp.spectrum_ids) == 0:
274 raise RelaxNoPeakIntensityError
275
276
278 """Create a per-experiment dictionary of relaxation times.
279
280 @return: The dictionary of unique relaxation times.
281 @rtype: dict of float
282 """
283
284
285 times = {}
286 for type in cdp.exp_type_list:
287 times[type] = []
288
289
290 if not hasattr(cdp, 'exp_type') or not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'relax_times'):
291 return times
292
293
294 for id in cdp.exp_type:
295
296 if id not in cdp.relax_times:
297 continue
298
299
300 if id not in cdp.exp_type:
301 continue
302
303
304 if cdp.relax_times[id] not in times[cdp.exp_type[id]]:
305 times[cdp.exp_type[id]].append(cdp.relax_times[id])
306
307
308 return times
309