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) 2013-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.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   
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.keys(): 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.keys(): 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.keys(): 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_mixed_curve_types():
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 # No experiment types set. 124 if not hasattr(cdp, 'exp_type') or not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'relax_times'): 125 return False 126 127 # Get the times. 128 times = get_times() 129 130 # Loop over all experiment types. 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 # The check. 140 if var_flag and fixed_flag: 141 raise RelaxError("Fixed time and exponential curves cannot be analysed simultaneously.")
142 143
144 -def check_model_type():
145 """Check that the dispersion model has been set. 146 147 @raises RelaxError: If the dispersion model has not been specified. 148 """ 149 150 # Test if the model has been set. 151 if not hasattr(cdp, 'model_type'): 152 raise RelaxError("The relaxation dispersion model has not been specified.")
153 154
155 -def check_pipe_type():
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 # Test if the pipe type is set to 'relax_disp'. 162 function_type = cdp.pipe_type 163 if function_type != 'relax_disp': 164 raise RelaxFuncSetupError(specific_analyses.setup.get_string(function_type))
165 166
167 -def check_relax_times():
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 # Test if the experiment type is set. 174 if not hasattr(cdp, 'relax_times'): 175 raise RelaxError("The relaxation times have not been set for any spectra.") 176 177 # Check each spectrum ID. 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
183 -def check_spectra_id_setup():
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 # Perform the checks. 199 check_spectrum_ids() 200 check_exp_type() 201 check_spectrometer_frq() 202 check_disp_points() 203 check_relax_times()
204 205
206 -def check_spectrometer_frq():
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 # Test if the experiment type is set. 213 if not hasattr(cdp, 'spectrometer_frq'): 214 raise RelaxError("The spectrometer frequencies have not been set for any spectra.") 215 216 # Check each spectrum ID. 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
222 -def check_spectrum_ids():
223 """Check if spectrum IDs exist. 224 225 @raises RelaxNoPeakIntensityError: If no spectrum IDs exist. 226 """ 227 228 # The spectrum IDs structure. 229 if not hasattr(cdp, 'spectrum_ids') or len(cdp.spectrum_ids) == 0: 230 raise RelaxNoPeakIntensityError
231 232
233 -def get_times():
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 # Initialise. 241 times = {} 242 for type in cdp.exp_type_list: 243 times[type] = [] 244 245 # Not set up yet. 246 if not hasattr(cdp, 'exp_type') or not hasattr(cdp, 'spectrum_ids') or not hasattr(cdp, 'relax_times'): 247 return times 248 249 # Loop over all spectra IDs. 250 for id in cdp.exp_type.keys(): 251 # No time set. 252 if id not in cdp.relax_times: 253 continue 254 255 # No type set. 256 if id not in cdp.exp_type: 257 continue 258 259 # Count the number of times. 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 # Return the times dictionary. 264 return times
265