Package specific_analyses :: Package relax_disp :: Module checks
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.relax_disp.checks

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2013 Edward d'Auvergne                                        # 
  4  # Copyright (C) 2014 Troels E. Linnet                                         # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 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  # relax module imports. 
 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   
36 -def check_c_modules():
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 # Get the times. 43 times = get_times() 44 45 # Complain. 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
51 -def check_disp_points():
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 # Test if the curve count exists. 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 # Check each spectrum ID. 62 for id in cdp.exp_type: 63 # CPMG data. 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 # R1rho data. 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
74 -def check_exp_type(id=None):
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 # Test if the experiment type is set. 83 if not hasattr(cdp, 'exp_type'): 84 raise RelaxError("The relaxation dispersion experiment types have not been set for any spectra.") 85 86 # Individual ID. 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 # Check that at least one spectrum ID is set. 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
101 -def check_exp_type_fixed_time():
102 """Check that only fixed time experiment types have been set up. 103 104 @raises RelaxError: If exponential curves are present. 105 """ 106 107 # Loop over the id's. 108 for id in cdp.exp_type: 109 # Get the exp_type and frq. 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
117 -def check_interpolate_offset_cpmg_model(interpolate=None):
118 """Check interpolating through offsets in CPMG models. 119 120 @keyword interpolate: How to interpolate the fitted curves. Either by option "%s" which interpolate CPMG frequency or spin-lock field strength, or by option "%s" which interpole over spin-lock offset. 121 @type interpolate: str 122 @raises RelaxFuncSetupError: If the interpolate method is set to 'offset' for not-R1rho models. 123 """%(specific_analyses.relax_disp.data.INTERPOLATE_DISP, specific_analyses.relax_disp.data.INTERPOLATE_OFFSET) 124 125 # Check if interpolating against offset for CPMG models. 126 # This is currently not implemented, and will raise an error. 127 if not specific_analyses.relax_disp.data.has_r1rho_exp_type() and interpolate == specific_analyses.relax_disp.data.INTERPOLATE_OFFSET: 128 raise RelaxFuncSetupError("interpolating against Spin-lock offset for CPMG models")
129 130
131 -def check_mixed_curve_types():
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 # No experiment types set. 138 if not hasattr(cdp, 'exp_type') or not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'relax_times'): 139 return False 140 141 # Get the times. 142 times = get_times() 143 144 # Loop over all experiment types. 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 # The check. 154 if var_flag and fixed_flag: 155 raise RelaxError("Fixed time and exponential curves cannot be analysed simultaneously.")
156 157
158 -def check_model_type(model=None):
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 # Test if the model has been set. 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
175 -def check_pipe_type():
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 # Test if the pipe type is set to 'relax_disp'. 182 function_type = cdp.pipe_type 183 if function_type != 'relax_disp': 184 raise RelaxFuncSetupError(specific_analyses.setup.get_string(function_type))
185 186
187 -def check_missing_r1(model=None):
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 # Check that the model uses R1 data. 197 if model in [MODEL_NOREX] + MODEL_LIST_R1RHO_OFF_RES: 198 # If R1 ids are present. 199 if hasattr(cdp, 'ri_ids'): 200 return False 201 202 # If not present. 203 else: 204 return True 205 206 # If model does not need R1. 207 else: 208 return False
209 210
211 -def check_relax_times():
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 # Test if the experiment type is set. 218 if not hasattr(cdp, 'relax_times'): 219 raise RelaxError("The relaxation times have not been set for any spectra.") 220 221 # Check each spectrum ID. 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
227 -def check_spectra_id_setup():
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 # Perform the checks. 243 check_spectrum_ids() 244 check_exp_type() 245 check_spectrometer_frq() 246 check_disp_points() 247 check_relax_times()
248 249
250 -def check_spectrometer_frq():
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 # Test if the experiment type is set. 257 if not hasattr(cdp, 'spectrometer_frq'): 258 raise RelaxError("The spectrometer frequencies have not been set for any spectra.") 259 260 # Check each spectrum ID. 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
266 -def check_spectrum_ids():
267 """Check if spectrum IDs exist. 268 269 @raises RelaxNoPeakIntensityError: If no spectrum IDs exist. 270 """ 271 272 # The spectrum IDs structure. 273 if not hasattr(cdp, 'spectrum_ids') or len(cdp.spectrum_ids) == 0: 274 raise RelaxNoPeakIntensityError
275 276
277 -def get_times():
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 # Initialise. 285 times = {} 286 for type in cdp.exp_type_list: 287 times[type] = [] 288 289 # Not set up yet. 290 if not hasattr(cdp, 'exp_type') or not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'relax_times'): 291 return times 292 293 # Loop over all spectra IDs. 294 for id in cdp.exp_type: 295 # No time set. 296 if id not in cdp.relax_times: 297 continue 298 299 # No type set. 300 if id not in cdp.exp_type: 301 continue 302 303 # Count the number of times. 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 # Return the times dictionary. 308 return times
309