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