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

Source Code for Module specific_analyses.model_free.parameters

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2014 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  6  #                                                                             # 
  7  # This program is free software: you can redistribute it and/or modify        # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation, either version 3 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # This program is distributed in the hope that it will be useful,             # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 19  #                                                                             # 
 20  ############################################################################### 
 21   
 22  # Module docstring. 
 23  """The model-free analysis parameter functions.""" 
 24   
 25  # Python module imports. 
 26  from math import pi 
 27  from numpy import array, float64, int8, zeros 
 28  from re import match 
 29   
 30  # relax module imports. 
 31  from lib.errors import RelaxError 
 32  from pipe_control import diffusion_tensor 
 33  from pipe_control.mol_res_spin import spin_loop 
 34  from specific_analyses.model_free.model import determine_model_type 
 35   
 36   
37 -def are_mf_params_set(spin):
38 """Test if the model-free parameter values are set. 39 40 @param spin: The spin container object. 41 @type spin: SpinContainer instance 42 @return: The name of the first parameter in the parameter list in which the 43 corresponding parameter value is None. If all parameters are set, then None 44 is returned. 45 @rtype: str or None 46 """ 47 48 # Deselected residue. 49 if spin.select == 0: 50 return 51 52 # Loop over the model-free parameters. 53 for j in range(len(spin.params)): 54 # Local tm. 55 if spin.params[j] == 'local_tm' and spin.local_tm == None: 56 return spin.params[j] 57 58 # S2. 59 elif spin.params[j] == 's2' and spin.s2 == None: 60 return spin.params[j] 61 62 # S2f. 63 elif spin.params[j] == 's2f' and spin.s2f == None: 64 return spin.params[j] 65 66 # S2s. 67 elif spin.params[j] == 's2s' and spin.s2s == None: 68 return spin.params[j] 69 70 # te. 71 elif spin.params[j] == 'te' and spin.te == None: 72 return spin.params[j] 73 74 # tf. 75 elif spin.params[j] == 'tf' and spin.tf == None: 76 return spin.params[j] 77 78 # ts. 79 elif spin.params[j] == 'ts' and spin.ts == None: 80 return spin.params[j] 81 82 # Rex. 83 elif spin.params[j] == 'rex' and spin.rex == None: 84 return spin.params[j] 85 86 # r. 87 elif spin.params[j] == 'r' and spin.r == None: 88 return spin.params[j] 89 90 # CSA. 91 elif spin.params[j] == 'csa' and spin.csa == None: 92 return spin.params[j]
93 94
95 -def assemble_param_names(model_type, spin_id=None):
96 """Function for assembling a list of all the model parameter names. 97 98 @param model_type: The model-free model type. This must be one of 'mf', 'local_tm', 99 'diff', or 'all'. 100 @type model_type: str 101 @param spin_id: The spin identification string. 102 @type spin_id: str 103 @return: A list containing all the parameters of the model-free model. 104 @rtype: list of str 105 """ 106 107 # Initialise. 108 param_names = [] 109 110 # Diffusion tensor parameters. 111 if model_type == 'diff' or model_type == 'all': 112 # Spherical diffusion. 113 if cdp.diff_tensor.type == 'sphere': 114 param_names.append('tm') 115 116 # Spheroidal diffusion. 117 elif cdp.diff_tensor.type == 'spheroid': 118 param_names.append('tm') 119 param_names.append('Da') 120 param_names.append('theta') 121 param_names.append('phi') 122 123 # Ellipsoidal diffusion. 124 elif cdp.diff_tensor.type == 'ellipsoid': 125 param_names.append('tm') 126 param_names.append('Da') 127 param_names.append('Dr') 128 param_names.append('alpha') 129 param_names.append('beta') 130 param_names.append('gamma') 131 132 # Model-free parameters (spin specific parameters). 133 if model_type != 'diff': 134 # Loop over the spins. 135 for spin in spin_loop(spin_id): 136 # Skip deselected spins. 137 if not spin.select: 138 continue 139 140 # Add the spin specific model-free parameters. 141 param_names = param_names + spin.params 142 143 # Return the parameter names. 144 return param_names
145 146
147 -def assemble_param_vector(spin=None, spin_id=None, sim_index=None, model_type=None):
148 """Assemble the model-free parameter vector (as numpy array). 149 150 If the spin argument is supplied, then the spin_id argument will be ignored. 151 152 @keyword spin: The spin data container. 153 @type spin: SpinContainer instance 154 @keyword spin_id: The spin identification string. 155 @type spin_id: str 156 @keyword sim_index: The optional MC simulation index. 157 @type sim_index: int 158 @keyword model_type: The optional model type, one of 'all', 'diff', 'mf', or 'local_tm'. 159 @type model_type: str or None 160 @return: An array of the parameter values of the model-free model. 161 @rtype: numpy array 162 """ 163 164 # Initialise. 165 param_vector = [] 166 167 # Determine the model type. 168 if not model_type: 169 model_type = determine_model_type() 170 171 # Diffusion tensor parameters. 172 if model_type == 'diff' or model_type == 'all': 173 # Normal parameters. 174 if sim_index == None: 175 # Spherical diffusion. 176 if cdp.diff_tensor.type == 'sphere': 177 if hasattr(cdp.diff_tensor, 'tm'): 178 param_vector.append(cdp.diff_tensor.tm) 179 else: 180 param_vector.append(None) 181 182 # Spheroidal diffusion. 183 elif cdp.diff_tensor.type == 'spheroid': 184 if hasattr(cdp.diff_tensor, 'tm'): 185 param_vector.append(cdp.diff_tensor.tm) 186 param_vector.append(cdp.diff_tensor.Da) 187 param_vector.append(cdp.diff_tensor.theta) 188 param_vector.append(cdp.diff_tensor.phi) 189 else: 190 param_vector += [None, None, None, None] 191 192 # Ellipsoidal diffusion. 193 elif cdp.diff_tensor.type == 'ellipsoid': 194 if hasattr(cdp.diff_tensor, 'tm'): 195 param_vector.append(cdp.diff_tensor.tm) 196 param_vector.append(cdp.diff_tensor.Da) 197 param_vector.append(cdp.diff_tensor.Dr) 198 param_vector.append(cdp.diff_tensor.alpha) 199 param_vector.append(cdp.diff_tensor.beta) 200 param_vector.append(cdp.diff_tensor.gamma) 201 else: 202 param_vector += [None, None, None, None, None, None] 203 204 # Monte Carlo diffusion tensor parameters. 205 else: 206 # Spherical diffusion. 207 if cdp.diff_tensor.type == 'sphere': 208 param_vector.append(cdp.diff_tensor.tm_sim[sim_index]) 209 210 # Spheroidal diffusion. 211 elif cdp.diff_tensor.type == 'spheroid': 212 param_vector.append(cdp.diff_tensor.tm_sim[sim_index]) 213 param_vector.append(cdp.diff_tensor.Da_sim[sim_index]) 214 param_vector.append(cdp.diff_tensor.theta_sim[sim_index]) 215 param_vector.append(cdp.diff_tensor.phi_sim[sim_index]) 216 217 # Ellipsoidal diffusion. 218 elif cdp.diff_tensor.type == 'ellipsoid': 219 param_vector.append(cdp.diff_tensor.tm_sim[sim_index]) 220 param_vector.append(cdp.diff_tensor.Da_sim[sim_index]) 221 param_vector.append(cdp.diff_tensor.Dr_sim[sim_index]) 222 param_vector.append(cdp.diff_tensor.alpha_sim[sim_index]) 223 param_vector.append(cdp.diff_tensor.beta_sim[sim_index]) 224 param_vector.append(cdp.diff_tensor.gamma_sim[sim_index]) 225 226 # Model-free parameters (spin specific parameters). 227 if model_type != 'diff': 228 # The loop. 229 if spin: 230 loop = [spin] 231 else: 232 loop = spin_loop(spin_id) 233 234 # Loop over the spins. 235 for spin in loop: 236 # Skip deselected spins. 237 if not spin.select: 238 continue 239 240 # Skip spins with no parameters. 241 if not hasattr(spin, 'params'): 242 continue 243 244 # Loop over the model-free parameters. 245 for i in range(len(spin.params)): 246 # local tm. 247 if spin.params[i] == 'local_tm': 248 if sim_index == None: 249 param_vector.append(spin.local_tm) 250 else: 251 param_vector.append(spin.local_tm_sim[sim_index]) 252 253 # S2. 254 elif spin.params[i] == 's2': 255 if sim_index == None: 256 param_vector.append(spin.s2) 257 else: 258 param_vector.append(spin.s2_sim[sim_index]) 259 260 # S2f. 261 elif spin.params[i] == 's2f': 262 if sim_index == None: 263 param_vector.append(spin.s2f) 264 else: 265 param_vector.append(spin.s2f_sim[sim_index]) 266 267 # S2s. 268 elif spin.params[i] == 's2s': 269 if sim_index == None: 270 param_vector.append(spin.s2s) 271 else: 272 param_vector.append(spin.s2s_sim[sim_index]) 273 274 # te. 275 elif spin.params[i] == 'te': 276 if sim_index == None: 277 param_vector.append(spin.te) 278 else: 279 param_vector.append(spin.te_sim[sim_index]) 280 281 # tf. 282 elif spin.params[i] == 'tf': 283 if sim_index == None: 284 param_vector.append(spin.tf) 285 else: 286 param_vector.append(spin.tf_sim[sim_index]) 287 288 # ts. 289 elif spin.params[i] == 'ts': 290 if sim_index == None: 291 param_vector.append(spin.ts) 292 else: 293 param_vector.append(spin.ts_sim[sim_index]) 294 295 # Rex. 296 elif spin.params[i] == 'rex': 297 if sim_index == None: 298 param_vector.append(spin.rex) 299 else: 300 param_vector.append(spin.rex_sim[sim_index]) 301 302 # r. 303 elif spin.params[i] == 'r': 304 if sim_index == None: 305 param_vector.append(spin.r) 306 else: 307 param_vector.append(spin.r_sim[sim_index]) 308 309 # CSA. 310 elif spin.params[i] == 'csa': 311 if sim_index == None: 312 param_vector.append(spin.csa) 313 else: 314 param_vector.append(spin.csa_sim[sim_index]) 315 316 # Unknown parameter. 317 else: 318 raise RelaxError("Unknown parameter.") 319 320 # Return a numpy array. 321 return array(param_vector, float64)
322 323
324 -def conv_factor_rex():
325 """Calculate and return the Rex conversion factor. 326 327 @return: The Rex conversion factor. 328 @rtype: float 329 """ 330 331 # No frequency info. 332 if not hasattr(cdp, 'spectrometer_frq'): 333 raise RelaxError("No spectrometer frequency information is present in the current data pipe.") 334 335 # The 1st spectrometer frequency. 336 if hasattr(cdp, 'ri_ids'): 337 frq = cdp.spectrometer_frq[cdp.ri_ids[0]] 338 339 # Take the highest frequency, if all else fails. 340 else: 341 frqs = sorted(cdp.spectrometer_frq.values()) 342 frq = frqs[-1] 343 344 # The factor. 345 return 1.0 / (2.0 * pi * frq)**2
346 347
348 -def disassemble_param_vector(model_type, param_vector=None, spin=None, spin_id=None, sim_index=None):
349 """Disassemble the model-free parameter vector. 350 351 @param model_type: The model-free model type. This must be one of 'mf', 'local_tm', 352 'diff', or 'all'. 353 @type model_type: str 354 @keyword param_vector: The model-free parameter vector. 355 @type param_vector: numpy array 356 @keyword spin: The spin data container. If this argument is supplied, then the spin_id 357 argument will be ignored. 358 @type spin: SpinContainer instance 359 @keyword spin_id: The spin identification string. 360 @type spin_id: str 361 @keyword sim_index: The optional MC simulation index. 362 @type sim_index: int 363 """ 364 365 # Initialise. 366 param_index = 0 367 368 # Diffusion tensor parameters of the Monte Carlo simulations. 369 if sim_index != None and (model_type == 'diff' or model_type == 'all'): 370 # Spherical diffusion. 371 if cdp.diff_tensor.type == 'sphere': 372 # Sim values. 373 cdp.diff_tensor.set(param='tm', value=param_vector[0], category='sim', sim_index=sim_index) 374 375 # Parameter index. 376 param_index = param_index + 1 377 378 # Spheroidal diffusion. 379 elif cdp.diff_tensor.type == 'spheroid': 380 # Sim values. 381 cdp.diff_tensor.set(param='tm', value=param_vector[0], category='sim', sim_index=sim_index) 382 cdp.diff_tensor.set(param='Da', value=param_vector[1], category='sim', sim_index=sim_index) 383 cdp.diff_tensor.set(param='theta', value=param_vector[2], category='sim', sim_index=sim_index) 384 cdp.diff_tensor.set(param='phi', value=param_vector[3], category='sim', sim_index=sim_index) 385 diffusion_tensor.fold_angles(sim_index=sim_index) 386 387 # Parameter index. 388 param_index = param_index + 4 389 390 # Ellipsoidal diffusion. 391 elif cdp.diff_tensor.type == 'ellipsoid': 392 # Sim values. 393 cdp.diff_tensor.set(param='tm', value=param_vector[0], category='sim', sim_index=sim_index) 394 cdp.diff_tensor.set(param='Da', value=param_vector[1], category='sim', sim_index=sim_index) 395 cdp.diff_tensor.set(param='Dr', value=param_vector[2], category='sim', sim_index=sim_index) 396 cdp.diff_tensor.set(param='alpha', value=param_vector[3], category='sim', sim_index=sim_index) 397 cdp.diff_tensor.set(param='beta', value=param_vector[4], category='sim', sim_index=sim_index) 398 cdp.diff_tensor.set(param='gamma', value=param_vector[5], category='sim', sim_index=sim_index) 399 diffusion_tensor.fold_angles(sim_index=sim_index) 400 401 # Parameter index. 402 param_index = param_index + 6 403 404 # Diffusion tensor parameters. 405 elif model_type == 'diff' or model_type == 'all': 406 # Spherical diffusion. 407 if cdp.diff_tensor.type == 'sphere': 408 # Values. 409 cdp.diff_tensor.set(param='tm', value=param_vector[0]) 410 411 # Parameter index. 412 param_index = param_index + 1 413 414 # Spheroidal diffusion. 415 elif cdp.diff_tensor.type == 'spheroid': 416 # Values. 417 cdp.diff_tensor.set(param='tm', value=param_vector[0]) 418 cdp.diff_tensor.set(param='Da', value=param_vector[1]) 419 cdp.diff_tensor.set(param='theta', value=param_vector[2]) 420 cdp.diff_tensor.set(param='phi', value=param_vector[3]) 421 diffusion_tensor.fold_angles() 422 423 # Parameter index. 424 param_index = param_index + 4 425 426 # Ellipsoidal diffusion. 427 elif cdp.diff_tensor.type == 'ellipsoid': 428 # Values. 429 cdp.diff_tensor.set(param='tm', value=param_vector[0]) 430 cdp.diff_tensor.set(param='Da', value=param_vector[1]) 431 cdp.diff_tensor.set(param='Dr', value=param_vector[2]) 432 cdp.diff_tensor.set(param='alpha', value=param_vector[3]) 433 cdp.diff_tensor.set(param='beta', value=param_vector[4]) 434 cdp.diff_tensor.set(param='gamma', value=param_vector[5]) 435 diffusion_tensor.fold_angles() 436 437 # Parameter index. 438 param_index = param_index + 6 439 440 # Model-free parameters. 441 if model_type != 'diff': 442 # The loop. 443 if spin: 444 loop = [spin] 445 else: 446 loop = spin_loop(spin_id) 447 448 # Loop over the spins. 449 for spin in loop: 450 # Skip deselected spins. 451 if not spin.select: 452 continue 453 454 # Loop over the model-free parameters. 455 for j in range(len(spin.params)): 456 # Local tm. 457 if spin.params[j] == 'local_tm': 458 if sim_index == None: 459 spin.local_tm = param_vector[param_index] 460 else: 461 spin.local_tm_sim[sim_index] = param_vector[param_index] 462 463 # S2. 464 elif spin.params[j] == 's2': 465 if sim_index == None: 466 spin.s2 = param_vector[param_index] 467 else: 468 spin.s2_sim[sim_index] = param_vector[param_index] 469 470 # S2f. 471 elif spin.params[j] == 's2f': 472 if sim_index == None: 473 spin.s2f = param_vector[param_index] 474 else: 475 spin.s2f_sim[sim_index] = param_vector[param_index] 476 477 # S2s. 478 elif spin.params[j] == 's2s': 479 if sim_index == None: 480 spin.s2s = param_vector[param_index] 481 else: 482 spin.s2s_sim[sim_index] = param_vector[param_index] 483 484 # te. 485 elif spin.params[j] == 'te': 486 if sim_index == None: 487 spin.te = param_vector[param_index] 488 else: 489 spin.te_sim[sim_index] = param_vector[param_index] 490 491 # tf. 492 elif spin.params[j] == 'tf': 493 if sim_index == None: 494 spin.tf = param_vector[param_index] 495 else: 496 spin.tf_sim[sim_index] = param_vector[param_index] 497 498 # ts. 499 elif spin.params[j] == 'ts': 500 if sim_index == None: 501 spin.ts = param_vector[param_index] 502 else: 503 spin.ts_sim[sim_index] = param_vector[param_index] 504 505 # Rex. 506 elif spin.params[j] == 'rex': 507 if sim_index == None: 508 spin.rex = param_vector[param_index] 509 else: 510 spin.rex_sim[sim_index] = param_vector[param_index] 511 512 # r. 513 elif spin.params[j] == 'r': 514 if sim_index == None: 515 spin.r = param_vector[param_index] 516 else: 517 spin.r_sim[sim_index] = param_vector[param_index] 518 519 # CSA. 520 elif spin.params[j] == 'csa': 521 if sim_index == None: 522 spin.csa = param_vector[param_index] 523 else: 524 spin.csa_sim[sim_index] = param_vector[param_index] 525 526 # Unknown parameter. 527 else: 528 raise RelaxError("Unknown parameter.") 529 530 # Increment the parameter index. 531 param_index = param_index + 1 532 533 # Calculate all order parameters after unpacking the vector. 534 if model_type != 'diff': 535 # The loop. 536 if spin: 537 loop = [spin] 538 else: 539 loop = spin_loop(spin_id) 540 541 # Loop over the spins. 542 for spin in loop: 543 # Skip deselected residues. 544 if not spin.select: 545 continue 546 547 # Normal values. 548 if sim_index == None: 549 # S2. 550 if 's2' not in spin.params and 's2f' in spin.params and 's2s' in spin.params: 551 spin.s2 = spin.s2f * spin.s2s 552 553 # S2f. 554 if 's2f' not in spin.params and 's2' in spin.params and 's2s' in spin.params: 555 if spin.s2s == 0.0: 556 spin.s2f = 1e99 557 else: 558 spin.s2f = spin.s2 / spin.s2s 559 560 # S2s. 561 if 's2s' not in spin.params and 's2' in spin.params and 's2f' in spin.params: 562 if spin.s2f == 0.0: 563 spin.s2s = 1e99 564 else: 565 spin.s2s = spin.s2 / spin.s2f 566 567 # Simulation values. 568 else: 569 # S2. 570 if 's2' not in spin.params and 's2f' in spin.params and 's2s' in spin.params: 571 spin.s2_sim[sim_index] = spin.s2f_sim[sim_index] * spin.s2s_sim[sim_index] 572 573 # S2f. 574 if 's2f' not in spin.params and 's2' in spin.params and 's2s' in spin.params: 575 if spin.s2s_sim[sim_index] == 0.0: 576 spin.s2f_sim[sim_index] = 1e99 577 else: 578 spin.s2f_sim[sim_index] = spin.s2_sim[sim_index] / spin.s2s_sim[sim_index] 579 580 # S2s. 581 if 's2s' not in spin.params and 's2' in spin.params and 's2f' in spin.params: 582 if spin.s2f_sim[sim_index] == 0.0: 583 spin.s2s_sim[sim_index] = 1e99 584 else: 585 spin.s2s_sim[sim_index] = spin.s2_sim[sim_index] / spin.s2f_sim[sim_index]
586 587
588 -def linear_constraints(num_params, model_type=None, spin=None, spin_id=None, scaling_matrix=None):
589 """Set up the model-free linear constraint matrices A and b. 590 591 Standard notation 592 ================= 593 594 The order parameter constraints are:: 595 596 0 <= S2 <= 1 597 0 <= S2f <= 1 598 0 <= S2s <= 1 599 600 By substituting the formula S2 = S2f.S2s into the above inequalities, the additional two 601 inequalities can be derived:: 602 603 S2 <= S2f 604 S2 <= S2s 605 606 Correlation time constraints are:: 607 608 te >= 0 609 tf >= 0 610 ts >= 0 611 612 tf <= ts 613 614 te, tf, ts <= 2 * tm 615 616 Additional constraints used include:: 617 618 Rex >= 0 619 0.9e-10 <= r <= 2e-10 620 -300e-6 <= CSA <= 0 621 622 623 Rearranged notation 624 =================== 625 626 The above inequality constraints can be rearranged into:: 627 628 S2 >= 0 629 -S2 >= -1 630 S2f >= 0 631 -S2f >= -1 632 S2s >= 0 633 -S2s >= -1 634 S2f - S2 >= 0 635 S2s - S2 >= 0 636 te >= 0 637 tf >= 0 638 ts >= 0 639 ts - tf >= 0 640 Rex >= 0 641 r >= 0.9e-10 642 -r >= -2e-10 643 CSA >= -300e-6 644 -CSA >= 0 645 646 647 Matrix notation 648 =============== 649 650 In the notation A.x >= b, where A is an matrix of coefficients, x is an array of parameter 651 values, and b is a vector of scalars, these inequality constraints are:: 652 653 | 1 0 0 0 0 0 0 0 0 | | 0 | 654 | | | | 655 |-1 0 0 0 0 0 0 0 0 | | -1 | 656 | | | | 657 | 0 1 0 0 0 0 0 0 0 | | 0 | 658 | | | | 659 | 0 -1 0 0 0 0 0 0 0 | | -1 | 660 | | | | 661 | 0 0 1 0 0 0 0 0 0 | | S2 | | 0 | 662 | | | | | | 663 | 0 0 -1 0 0 0 0 0 0 | | S2f | | -1 | 664 | | | | | | 665 |-1 1 0 0 0 0 0 0 0 | | S2s | | 0 | 666 | | | | | | 667 |-1 0 1 0 0 0 0 0 0 | | te | | 0 | 668 | | | | | | 669 | 0 0 0 1 0 0 0 0 0 | . | tf | >= | 0 | 670 | | | | | | 671 | 0 0 0 0 1 0 0 0 0 | | ts | | 0 | 672 | | | | | | 673 | 0 0 0 0 0 1 0 0 0 | | Rex | | 0 | 674 | | | | | | 675 | 0 0 0 0 -1 1 0 0 0 | | r | | 0 | 676 | | | | | | 677 | 0 0 0 0 0 0 1 0 0 | | CSA | | 0 | 678 | | | | 679 | 0 0 0 0 0 0 0 1 0 | | 0.9e-10 | 680 | | | | 681 | 0 0 0 0 0 0 0 -1 0 | | -2e-10 | 682 | | | | 683 | 0 0 0 0 0 0 0 0 1 | | -300e-6 | 684 | | | | 685 | 0 0 0 0 0 0 0 0 -1 | | 0 | 686 687 688 @param num_params: The number of parameters in the model. 689 @type num_params: int 690 @keyword model_type: The model type, one of 'all', 'diff', 'mf', or 'local_tm'. 691 @type model_type: str 692 @keyword spin: The spin data container. If this argument is supplied, then the 693 spin_id argument will be ignored. 694 @type spin: SpinContainer instance 695 @keyword spin_id: The spin identification string. 696 @type spin_id: str 697 @keyword scaling_matrix: The diagonal, square scaling matrix. 698 @type scaling_matrix: numpy diagonal matrix 699 """ 700 701 # Upper limit flag for correlation times. 702 upper_time_limit = 1 703 704 # Initialisation (0..j..m). 705 A = [] 706 b = [] 707 zero_array = zeros(num_params, float64) 708 i = 0 709 j = 0 710 711 # Diffusion tensor parameters. 712 if model_type != 'mf' and diffusion_tensor.diff_data_exists(): 713 # Spherical diffusion. 714 if cdp.diff_tensor.type == 'sphere': 715 # 0 <= tm <= 200 ns. 716 A.append(zero_array * 0.0) 717 A.append(zero_array * 0.0) 718 A[j][i] = 1.0 719 A[j+1][i] = -1.0 720 b.append(0.0 / scaling_matrix[i, i]) 721 b.append(-200.0 * 1e-9 / scaling_matrix[i, i]) 722 i = i + 1 723 j = j + 2 724 725 # Spheroidal diffusion. 726 elif cdp.diff_tensor.type == 'spheroid': 727 # 0 <= tm <= 200 ns. 728 A.append(zero_array * 0.0) 729 A.append(zero_array * 0.0) 730 A[j][i] = 1.0 731 A[j+1][i] = -1.0 732 b.append(0.0 / scaling_matrix[i, i]) 733 b.append(-200.0 * 1e-9 / scaling_matrix[i, i]) 734 i = i + 1 735 j = j + 2 736 737 # Prolate diffusion, Da >= 0. 738 if cdp.diff_tensor.spheroid_type == 'prolate': 739 A.append(zero_array * 0.0) 740 A[j][i] = 1.0 741 b.append(0.0 / scaling_matrix[i, i]) 742 i = i + 1 743 j = j + 1 744 745 # Add two to i for the theta and phi parameters. 746 i = i + 2 747 748 # Oblate diffusion, Da <= 0. 749 elif cdp.diff_tensor.spheroid_type == 'oblate': 750 A.append(zero_array * 0.0) 751 A[j][i] = -1.0 752 b.append(0.0 / scaling_matrix[i, i]) 753 i = i + 1 754 j = j + 1 755 756 # Add two to i for the theta and phi parameters. 757 i = i + 2 758 759 else: 760 # Add three to i for the Da, theta and phi parameters. 761 i = i + 3 762 763 # Ellipsoidal diffusion. 764 elif cdp.diff_tensor.type == 'ellipsoid': 765 # 0 <= tm <= 200 ns. 766 A.append(zero_array * 0.0) 767 A.append(zero_array * 0.0) 768 A[j][i] = 1.0 769 A[j+1][i] = -1.0 770 b.append(0.0 / scaling_matrix[i, i]) 771 b.append(-200.0 * 1e-9 / scaling_matrix[i, i]) 772 i = i + 1 773 j = j + 2 774 775 # Da >= 0. 776 A.append(zero_array * 0.0) 777 A[j][i] = 1.0 778 b.append(0.0 / scaling_matrix[i, i]) 779 i = i + 1 780 j = j + 1 781 782 # 0 <= Dr <= 1. 783 A.append(zero_array * 0.0) 784 A.append(zero_array * 0.0) 785 A[j][i] = 1.0 786 A[j+1][i] = -1.0 787 b.append(0.0 / scaling_matrix[i, i]) 788 b.append(-1.0 / scaling_matrix[i, i]) 789 i = i + 1 790 j = j + 2 791 792 # Add three to i for the alpha, beta, and gamma parameters. 793 i = i + 3 794 795 # Model-free parameters. 796 if model_type != 'diff': 797 # The loop. 798 if spin: 799 loop = [spin] 800 else: 801 loop = spin_loop(spin_id) 802 803 # Loop over the spins. 804 for spin in loop: 805 # Skip deselected spins. 806 if not spin.select: 807 continue 808 809 # Save current value of i. 810 old_i = i 811 812 # Loop over the model-free parameters. 813 for l in range(len(spin.params)): 814 # Local tm. 815 if spin.params[l] == 'local_tm': 816 if upper_time_limit: 817 # 0 <= tm <= 200 ns. 818 A.append(zero_array * 0.0) 819 A.append(zero_array * 0.0) 820 A[j][i] = 1.0 821 A[j+1][i] = -1.0 822 b.append(0.0 / scaling_matrix[i, i]) 823 b.append(-200.0 * 1e-9 / scaling_matrix[i, i]) 824 j = j + 2 825 else: 826 # 0 <= tm. 827 A.append(zero_array * 0.0) 828 A[j][i] = 1.0 829 b.append(0.0 / scaling_matrix[i, i]) 830 j = j + 1 831 832 # Order parameters {S2, S2f, S2s}. 833 elif match('s2', spin.params[l]): 834 # 0 <= S2 <= 1. 835 A.append(zero_array * 0.0) 836 A.append(zero_array * 0.0) 837 A[j][i] = 1.0 838 A[j+1][i] = -1.0 839 b.append(0.0 / scaling_matrix[i, i]) 840 b.append(-1.0 / scaling_matrix[i, i]) 841 j = j + 2 842 843 # S2 <= S2f and S2 <= S2s. 844 if spin.params[l] == 's2': 845 for m in range(len(spin.params)): 846 if spin.params[m] == 's2f' or spin.params[m] == 's2s': 847 A.append(zero_array * 0.0) 848 A[j][i] = -1.0 849 A[j][old_i+m] = 1.0 850 b.append(0.0) 851 j = j + 1 852 853 # Correlation times {te, tf, ts}. 854 elif match('t[efs]', spin.params[l]): 855 # te, tf, ts >= 0. 856 A.append(zero_array * 0.0) 857 A[j][i] = 1.0 858 b.append(0.0 / scaling_matrix[i, i]) 859 j = j + 1 860 861 # tf <= ts. 862 if spin.params[l] == 'ts': 863 for m in range(len(spin.params)): 864 if spin.params[m] == 'tf': 865 A.append(zero_array * 0.0) 866 A[j][i] = 1.0 867 A[j][old_i+m] = -1.0 868 b.append(0.0) 869 j = j + 1 870 871 # te, tf, ts <= 2 * tm. (tf not needed because tf <= ts). 872 if upper_time_limit: 873 if not spin.params[l] == 'tf': 874 if model_type == 'mf': 875 A.append(zero_array * 0.0) 876 A[j][i] = -1.0 877 b.append(-2.0 * cdp.diff_tensor.tm / scaling_matrix[i, i]) 878 else: 879 A.append(zero_array * 0.0) 880 A[j][0] = 2.0 881 A[j][i] = -1.0 882 b.append(0.0) 883 884 j = j + 1 885 886 # Rex. 887 elif spin.params[l] == 'rex': 888 A.append(zero_array * 0.0) 889 A[j][i] = 1.0 890 b.append(0.0 / scaling_matrix[i, i]) 891 j = j + 1 892 893 # Bond length. 894 elif spin.params[l] == 'r': 895 # 0.9e-10 <= r <= 2e-10. 896 A.append(zero_array * 0.0) 897 A.append(zero_array * 0.0) 898 A[j][i] = 1.0 899 A[j+1][i] = -1.0 900 b.append(0.9e-10 / scaling_matrix[i, i]) 901 b.append(-2e-10 / scaling_matrix[i, i]) 902 j = j + 2 903 904 # CSA. 905 elif spin.params[l] == 'csa': 906 # -300e-6 <= CSA <= 0. 907 A.append(zero_array * 0.0) 908 A.append(zero_array * 0.0) 909 A[j][i] = 1.0 910 A[j+1][i] = -1.0 911 b.append(-300e-6 / scaling_matrix[i, i]) 912 b.append(0.0 / scaling_matrix[i, i]) 913 j = j + 2 914 915 # Increment i. 916 i = i + 1 917 918 # Convert to numpy data structures. 919 A = array(A, int8) 920 b = array(b, float64) 921 922 return A, b
923 924
925 -def units_rex():
926 """Return the units for the Rex parameter. 927 928 @return: The field strength dependent Rex units. 929 @rtype: str 930 """ 931 932 # No frequency info. 933 if not hasattr(cdp, 'frq_labels') or len(cdp.frq_labels) == 0: 934 return '' 935 936 # The units. 937 return cdp.frq_labels[0] + ' MHz'
938