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.errors import RelaxError, RelaxFuncSetupError, RelaxNoPeakIntensityError
32 import specific_analyses
33 from specific_analyses.relax_disp.variables import EXP_TYPE_LIST_CPMG, EXP_TYPE_LIST_R1RHO
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.keys():
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.keys():
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.keys():
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
118 """Prevent both fixed time and exponential curves from being analysed simultaneously.
119
120 @raises RelaxError: If mixed curve types are present.
121 """
122
123
124 if not hasattr(cdp, 'exp_type') or not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'relax_times'):
125 return False
126
127
128 times = get_times()
129
130
131 var_flag = False
132 fixed_flag = False
133 for exp_type in times:
134 if times[exp_type] == 1:
135 fixed_flag = True
136 else:
137 var_flag = True
138
139
140 if var_flag and fixed_flag:
141 raise RelaxError("Fixed time and exponential curves cannot be analysed simultaneously.")
142
143
145 """Check that the dispersion model has been set.
146
147 @raises RelaxError: If the dispersion model has not been specified.
148 """
149
150
151 if not hasattr(cdp, 'model_type'):
152 raise RelaxError("The relaxation dispersion model has not been specified.")
153
154
156 """Check that the data pipe type is that of relaxation dispersion.
157
158 @raises RelaxFuncSetupError: If the data pipe type is not set to 'relax_disp'.
159 """
160
161
162 function_type = cdp.pipe_type
163 if function_type != 'relax_disp':
164 raise RelaxFuncSetupError(specific_analyses.setup.get_string(function_type))
165
166
168 """Check if the spectrometer frequencies have been set up.
169
170 @raises RelaxError: If the spectrometer frequencies have not been set.
171 """
172
173
174 if not hasattr(cdp, 'relax_times'):
175 raise RelaxError("The relaxation times have not been set for any spectra.")
176
177
178 for id in cdp.exp_type.keys():
179 if id not in cdp.relax_times:
180 raise RelaxError("The relaxation time has not been set for the '%s' spectrum." % id)
181
182
184 """Check that the data for each spectra ID is correctly set up.
185
186 This is an alias for the following checks:
187
188 - check_spectrum_ids()
189 - check_exp_type()
190 - check_spectrometer_frq()
191 - check_disp_points()
192 - check_relax_times()
193
194
195 @raises RelaxError: If data is missing.
196 """
197
198
199 check_spectrum_ids()
200 check_exp_type()
201 check_spectrometer_frq()
202 check_disp_points()
203 check_relax_times()
204
205
207 """Check if the spectrometer frequencies have been set up.
208
209 @raises RelaxError: If the spectrometer frequencies have not been set.
210 """
211
212
213 if not hasattr(cdp, 'spectrometer_frq'):
214 raise RelaxError("The spectrometer frequencies have not been set for any spectra.")
215
216
217 for id in cdp.exp_type.keys():
218 if id not in cdp.spectrometer_frq:
219 raise RelaxError("The spectrometer frequency has not been set for the '%s' spectrum." % id)
220
221
223 """Check if spectrum IDs exist.
224
225 @raises RelaxNoPeakIntensityError: If no spectrum IDs exist.
226 """
227
228
229 if not hasattr(cdp, 'spectrum_ids') or len(cdp.spectrum_ids) == 0:
230 raise RelaxNoPeakIntensityError
231
232
234 """Create a per-experiment dictionary of relaxation times.
235
236 @return: The dictionary of unique relaxation times.
237 @rtype: dict of float
238 """
239
240
241 times = {}
242 for type in cdp.exp_type_list:
243 times[type] = []
244
245
246 if not hasattr(cdp, 'exp_type') or not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'relax_times'):
247 return times
248
249
250 for id in cdp.exp_type.keys():
251
252 if id not in cdp.relax_times:
253 continue
254
255
256 if id not in cdp.exp_type:
257 continue
258
259
260 if cdp.relax_times[id] not in times[cdp.exp_type[id]]:
261 times[cdp.exp_type[id]].append(cdp.relax_times[id])
262
263
264 return times
265