Package specific_analyses :: Package model_free :: Module model
[hide private]
[frames] | no frames]

Source Code for Module specific_analyses.model_free.model

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2002-2014 Edward d'Auvergne                                   # 
  4  # Copyright (C) 2006 Chris MacRaild                                           # 
  5  # Copyright (C) 2008-2009 Sebastien Morin                                     # 
  6  #                                                                             # 
  7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  8  #                                                                             # 
  9  # This program is free software: you can redistribute it and/or modify        # 
 10  # it under the terms of the GNU General Public License as published by        # 
 11  # the Free Software Foundation, either version 3 of the License, or           # 
 12  # (at your option) any later version.                                         # 
 13  #                                                                             # 
 14  # This program is distributed in the hope that it will be useful,             # 
 15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 17  # GNU General Public License for more details.                                # 
 18  #                                                                             # 
 19  # You should have received a copy of the GNU General Public License           # 
 20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Module docstring. 
 25  """The model-free analysis parameter functions.""" 
 26   
 27  # relax module imports. 
 28  from lib.errors import RelaxError, RelaxNoSequenceError, RelaxNoTensorError 
 29  from pipe_control import diffusion_tensor 
 30  from pipe_control.mol_res_spin import exists_mol_res_spin_data, spin_loop 
 31   
 32   
33 -def determine_model_type():
34 """Determine the global model type. 35 36 @return: The name of the model type, which will be one of 'all', 'diff', 'mf', or 'local_tm'. If all parameters are fixed (and no spins selected), None is returned. 37 @rtype: str or None 38 """ 39 40 # Test if sequence data is loaded. 41 if not exists_mol_res_spin_data(): 42 raise RelaxNoSequenceError 43 44 # If there is a local tm, fail if not all residues have a local tm parameter. 45 local_tm = False 46 for spin in spin_loop(): 47 # Skip deselected spins. 48 if not spin.select: 49 continue 50 51 # No params. 52 if not hasattr(spin, 'params') or not spin.params: 53 continue 54 55 # Local tm. 56 if not local_tm and 'local_tm' in spin.params: 57 local_tm = True 58 59 # Inconsistencies. 60 elif local_tm and not 'local_tm' in spin.params: 61 raise RelaxError("All spins must either have a local tm parameter or not.") 62 63 # Check if any model-free parameters are allowed to vary. 64 mf_all_fixed = True 65 mf_all_deselected = True 66 for spin in spin_loop(): 67 # Skip deselected spins. 68 if not spin.select: 69 continue 70 71 # At least one spin is selected. 72 mf_all_deselected = False 73 74 # Test the fixed flag. 75 if not hasattr(spin, 'fixed'): 76 mf_all_fixed = False 77 break 78 if not spin.fixed: 79 mf_all_fixed = False 80 break 81 82 # No spins selected?!? 83 if mf_all_deselected: 84 # All parameters fixed! 85 if not hasattr(cdp, 'diff_tensor') or cdp.diff_tensor.fixed: 86 return None 87 88 return 'diff' 89 90 # Local tm. 91 if local_tm: 92 return 'local_tm' 93 94 # Test if the diffusion tensor data is loaded. 95 if not diffusion_tensor.diff_data_exists(): 96 # Catch when the local tm value is set but not in the parameter list. 97 for spin in spin_loop(): 98 if hasattr(spin, 'local_tm') and spin.local_tm != None and not 'local_tm' in spin.params: 99 raise RelaxError("The local tm value is set but not located in the model parameter list.") 100 101 # Normal error. 102 raise RelaxNoTensorError('diffusion') 103 104 # 'diff' model type. 105 if mf_all_fixed: 106 # All parameters fixed! 107 if cdp.diff_tensor.fixed: 108 return None 109 110 return 'diff' 111 112 # 'mf' model type. 113 if cdp.diff_tensor.fixed: 114 return 'mf' 115 116 # 'all' model type. 117 else: 118 return 'all'
119 120
121 -def model_map(model):
122 """Return the equation name and parameter list corresponding to the given model. 123 124 @param model: The model-free model. 125 @type model: str 126 @return: The equation type (either 'mf_orig' or 'mf_ext') and the model-free parameter list corresponding to the model. 127 @rtype: str, list 128 """ 129 130 # Block 1. 131 if model == 'm0': 132 equation = 'mf_orig' 133 params = [] 134 elif model == 'm1': 135 equation = 'mf_orig' 136 params = ['s2'] 137 elif model == 'm2': 138 equation = 'mf_orig' 139 params = ['s2', 'te'] 140 elif model == 'm3': 141 equation = 'mf_orig' 142 params = ['s2', 'rex'] 143 elif model == 'm4': 144 equation = 'mf_orig' 145 params = ['s2', 'te', 'rex'] 146 elif model == 'm5': 147 equation = 'mf_ext' 148 params = ['s2f', 's2', 'ts'] 149 elif model == 'm6': 150 equation = 'mf_ext' 151 params = ['s2f', 'tf', 's2', 'ts'] 152 elif model == 'm7': 153 equation = 'mf_ext' 154 params = ['s2f', 's2', 'ts', 'rex'] 155 elif model == 'm8': 156 equation = 'mf_ext' 157 params = ['s2f', 'tf', 's2', 'ts', 'rex'] 158 elif model == 'm9': 159 equation = 'mf_orig' 160 params = ['rex'] 161 162 # Block 2. 163 elif model == 'm10': 164 equation = 'mf_orig' 165 params = ['csa'] 166 elif model == 'm11': 167 equation = 'mf_orig' 168 params = ['csa', 's2'] 169 elif model == 'm12': 170 equation = 'mf_orig' 171 params = ['csa', 's2', 'te'] 172 elif model == 'm13': 173 equation = 'mf_orig' 174 params = ['csa', 's2', 'rex'] 175 elif model == 'm14': 176 equation = 'mf_orig' 177 params = ['csa', 's2', 'te', 'rex'] 178 elif model == 'm15': 179 equation = 'mf_ext' 180 params = ['csa', 's2f', 's2', 'ts'] 181 elif model == 'm16': 182 equation = 'mf_ext' 183 params = ['csa', 's2f', 'tf', 's2', 'ts'] 184 elif model == 'm17': 185 equation = 'mf_ext' 186 params = ['csa', 's2f', 's2', 'ts', 'rex'] 187 elif model == 'm18': 188 equation = 'mf_ext' 189 params = ['csa', 's2f', 'tf', 's2', 'ts', 'rex'] 190 elif model == 'm19': 191 equation = 'mf_orig' 192 params = ['csa', 'rex'] 193 194 # Block 3. 195 elif model == 'm20': 196 equation = 'mf_orig' 197 params = ['r'] 198 elif model == 'm21': 199 equation = 'mf_orig' 200 params = ['r', 's2'] 201 elif model == 'm22': 202 equation = 'mf_orig' 203 params = ['r', 's2', 'te'] 204 elif model == 'm23': 205 equation = 'mf_orig' 206 params = ['r', 's2', 'rex'] 207 elif model == 'm24': 208 equation = 'mf_orig' 209 params = ['r', 's2', 'te', 'rex'] 210 elif model == 'm25': 211 equation = 'mf_ext' 212 params = ['r', 's2f', 's2', 'ts'] 213 elif model == 'm26': 214 equation = 'mf_ext' 215 params = ['r', 's2f', 'tf', 's2', 'ts'] 216 elif model == 'm27': 217 equation = 'mf_ext' 218 params = ['r', 's2f', 's2', 'ts', 'rex'] 219 elif model == 'm28': 220 equation = 'mf_ext' 221 params = ['r', 's2f', 'tf', 's2', 'ts', 'rex'] 222 elif model == 'm29': 223 equation = 'mf_orig' 224 params = ['r', 'rex'] 225 226 # Block 4. 227 elif model == 'm30': 228 equation = 'mf_orig' 229 params = ['r', 'csa'] 230 elif model == 'm31': 231 equation = 'mf_orig' 232 params = ['r', 'csa', 's2'] 233 elif model == 'm32': 234 equation = 'mf_orig' 235 params = ['r', 'csa', 's2', 'te'] 236 elif model == 'm33': 237 equation = 'mf_orig' 238 params = ['r', 'csa', 's2', 'rex'] 239 elif model == 'm34': 240 equation = 'mf_orig' 241 params = ['r', 'csa', 's2', 'te', 'rex'] 242 elif model == 'm35': 243 equation = 'mf_ext' 244 params = ['r', 'csa', 's2f', 's2', 'ts'] 245 elif model == 'm36': 246 equation = 'mf_ext' 247 params = ['r', 'csa', 's2f', 'tf', 's2', 'ts'] 248 elif model == 'm37': 249 equation = 'mf_ext' 250 params = ['r', 'csa', 's2f', 's2', 'ts', 'rex'] 251 elif model == 'm38': 252 equation = 'mf_ext' 253 params = ['r', 'csa', 's2f', 'tf', 's2', 'ts', 'rex'] 254 elif model == 'm39': 255 equation = 'mf_orig' 256 params = ['r', 'csa', 'rex'] 257 258 259 # Preset models with local correlation time. 260 ############################################ 261 262 # Block 1. 263 elif model == 'tm0': 264 equation = 'mf_orig' 265 params = ['local_tm'] 266 elif model == 'tm1': 267 equation = 'mf_orig' 268 params = ['local_tm', 's2'] 269 elif model == 'tm2': 270 equation = 'mf_orig' 271 params = ['local_tm', 's2', 'te'] 272 elif model == 'tm3': 273 equation = 'mf_orig' 274 params = ['local_tm', 's2', 'rex'] 275 elif model == 'tm4': 276 equation = 'mf_orig' 277 params = ['local_tm', 's2', 'te', 'rex'] 278 elif model == 'tm5': 279 equation = 'mf_ext' 280 params = ['local_tm', 's2f', 's2', 'ts'] 281 elif model == 'tm6': 282 equation = 'mf_ext' 283 params = ['local_tm', 's2f', 'tf', 's2', 'ts'] 284 elif model == 'tm7': 285 equation = 'mf_ext' 286 params = ['local_tm', 's2f', 's2', 'ts', 'rex'] 287 elif model == 'tm8': 288 equation = 'mf_ext' 289 params = ['local_tm', 's2f', 'tf', 's2', 'ts', 'rex'] 290 elif model == 'tm9': 291 equation = 'mf_orig' 292 params = ['local_tm', 'rex'] 293 294 # Block 2. 295 elif model == 'tm10': 296 equation = 'mf_orig' 297 params = ['local_tm', 'csa'] 298 elif model == 'tm11': 299 equation = 'mf_orig' 300 params = ['local_tm', 'csa', 's2'] 301 elif model == 'tm12': 302 equation = 'mf_orig' 303 params = ['local_tm', 'csa', 's2', 'te'] 304 elif model == 'tm13': 305 equation = 'mf_orig' 306 params = ['local_tm', 'csa', 's2', 'rex'] 307 elif model == 'tm14': 308 equation = 'mf_orig' 309 params = ['local_tm', 'csa', 's2', 'te', 'rex'] 310 elif model == 'tm15': 311 equation = 'mf_ext' 312 params = ['local_tm', 'csa', 's2f', 's2', 'ts'] 313 elif model == 'tm16': 314 equation = 'mf_ext' 315 params = ['local_tm', 'csa', 's2f', 'tf', 's2', 'ts'] 316 elif model == 'tm17': 317 equation = 'mf_ext' 318 params = ['local_tm', 'csa', 's2f', 's2', 'ts', 'rex'] 319 elif model == 'tm18': 320 equation = 'mf_ext' 321 params = ['local_tm', 'csa', 's2f', 'tf', 's2', 'ts', 'rex'] 322 elif model == 'tm19': 323 equation = 'mf_orig' 324 params = ['local_tm', 'csa', 'rex'] 325 326 # Block 3. 327 elif model == 'tm20': 328 equation = 'mf_orig' 329 params = ['local_tm', 'r'] 330 elif model == 'tm21': 331 equation = 'mf_orig' 332 params = ['local_tm', 'r', 's2'] 333 elif model == 'tm22': 334 equation = 'mf_orig' 335 params = ['local_tm', 'r', 's2', 'te'] 336 elif model == 'tm23': 337 equation = 'mf_orig' 338 params = ['local_tm', 'r', 's2', 'rex'] 339 elif model == 'tm24': 340 equation = 'mf_orig' 341 params = ['local_tm', 'r', 's2', 'te', 'rex'] 342 elif model == 'tm25': 343 equation = 'mf_ext' 344 params = ['local_tm', 'r', 's2f', 's2', 'ts'] 345 elif model == 'tm26': 346 equation = 'mf_ext' 347 params = ['local_tm', 'r', 's2f', 'tf', 's2', 'ts'] 348 elif model == 'tm27': 349 equation = 'mf_ext' 350 params = ['local_tm', 'r', 's2f', 's2', 'ts', 'rex'] 351 elif model == 'tm28': 352 equation = 'mf_ext' 353 params = ['local_tm', 'r', 's2f', 'tf', 's2', 'ts', 'rex'] 354 elif model == 'tm29': 355 equation = 'mf_orig' 356 params = ['local_tm', 'r', 'rex'] 357 358 # Block 4. 359 elif model == 'tm30': 360 equation = 'mf_orig' 361 params = ['local_tm', 'r', 'csa'] 362 elif model == 'tm31': 363 equation = 'mf_orig' 364 params = ['local_tm', 'r', 'csa', 's2'] 365 elif model == 'tm32': 366 equation = 'mf_orig' 367 params = ['local_tm', 'r', 'csa', 's2', 'te'] 368 elif model == 'tm33': 369 equation = 'mf_orig' 370 params = ['local_tm', 'r', 'csa', 's2', 'rex'] 371 elif model == 'tm34': 372 equation = 'mf_orig' 373 params = ['local_tm', 'r', 'csa', 's2', 'te', 'rex'] 374 elif model == 'tm35': 375 equation = 'mf_ext' 376 params = ['local_tm', 'r', 'csa', 's2f', 's2', 'ts'] 377 elif model == 'tm36': 378 equation = 'mf_ext' 379 params = ['local_tm', 'r', 'csa', 's2f', 'tf', 's2', 'ts'] 380 elif model == 'tm37': 381 equation = 'mf_ext' 382 params = ['local_tm', 'r', 'csa', 's2f', 's2', 'ts', 'rex'] 383 elif model == 'tm38': 384 equation = 'mf_ext' 385 params = ['local_tm', 'r', 'csa', 's2f', 'tf', 's2', 'ts', 'rex'] 386 elif model == 'tm39': 387 equation = 'mf_orig' 388 params = ['local_tm', 'r', 'csa', 'rex'] 389 390 # Invalid model. 391 else: 392 raise RelaxError("The model '%s' is invalid." % model) 393 394 # Return the values. 395 return equation, params
396