Package generic_fns :: Module diffusion_tensor
[hide private]
[frames] | no frames]

Source Code for Module generic_fns.diffusion_tensor

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2003-2006 Edward d'Auvergne                                   # 
   4  #                                                                             # 
   5  # This file is part of the program relax.                                     # 
   6  #                                                                             # 
   7  # relax 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 2 of the License, or           # 
  10  # (at your option) any later version.                                         # 
  11  #                                                                             # 
  12  # relax 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 relax; if not, write to the Free Software                        # 
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
  20  #                                                                             # 
  21  ############################################################################### 
  22   
  23  from copy import deepcopy 
  24  from math import cos, pi, sin 
  25  from Numeric import Float64, array, zeros 
  26  from re import search 
  27   
  28   
29 -class Diffusion_tensor:
30 - def __init__(self, relax):
31 """Class containing the function for setting up the diffusion tensor.""" 32 33 self.relax = relax
34 35
36 - def copy(self, run1=None, run2=None):
37 """Function for copying diffusion tensor data from run1 to run2.""" 38 39 # Test if run1 exists. 40 if not run1 in self.relax.data.run_names: 41 raise RelaxNoRunError, run1 42 43 # Test if run2 exists. 44 if not run2 in self.relax.data.run_names: 45 raise RelaxNoRunError, run2 46 47 # Test if run1 contains diffusion tensor data. 48 if not self.relax.data.diff.has_key(run1): 49 raise RelaxNoTensorError, run1 50 51 # Test if run2 contains diffusion tensor data. 52 if self.relax.data.diff.has_key(run2): 53 raise RelaxTensorError, run2 54 55 # Copy the data. 56 self.relax.data.diff[run2] = deepcopy(self.relax.data.diff[run1])
57 58
59 - def data_names(self):
60 """Function for returning a list of names of data structures associated with the sequence.""" 61 62 names = [ 'diff_type', 63 'diff_params' ] 64 65 return names
66 67
68 - def default_value(self, param):
69 """ 70 Diffusion tensor parameter default values 71 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 72 73 ________________________________________________________________________ 74 | | | | 75 | Data type | Object name | Value | 76 |________________________|____________________|________________________| 77 | | | | 78 | tm | 'tm' | 10 * 1e-9 | 79 | | | | 80 | Diso | 'Diso' | 1.666 * 1e7 | 81 | | | | 82 | Da | 'Da' | 0.0 | 83 | | | | 84 | Dr | 'Dr' | 0.0 | 85 | | | | 86 | Dx | 'Dx' | 1.666 * 1e7 | 87 | | | | 88 | Dy | 'Dy' | 1.666 * 1e7 | 89 | | | | 90 | Dz | 'Dz' | 1.666 * 1e7 | 91 | | | | 92 | Dpar | 'Dpar' | 1.666 * 1e7 | 93 | | | | 94 | Dper | 'Dper' | 1.666 * 1e7 | 95 | | | | 96 | Dratio | 'Dratio' | 1.0 | 97 | | | | 98 | alpha | 'alpha' | 0.0 | 99 | | | | 100 | beta | 'beta' | 0.0 | 101 | | | | 102 | gamma | 'gamma' | 0.0 | 103 | | | | 104 | theta | 'theta' | 0.0 | 105 | | | | 106 | phi | 'phi' | 0.0 | 107 |________________________|____________________|________________________| 108 109 """ 110 111 # tm. 112 if param == 'tm': 113 return 10.0 * 1e-9 114 115 # Diso, Dx, Dy, Dz, Dpar, Dper. 116 elif param == 'Diso' or param == 'Dx' or param == 'Dy' or param == 'Dz' or param == 'Dpar' or param == 'Dper': 117 return 1.666 * 1e7 118 119 # Da, Dr. 120 elif param == 'Da' or param == 'Dr': 121 return 0.0 122 123 # Dratio. 124 elif param == 'Dratio': 125 return 1.0 126 127 # All angles. 128 elif param == 'alpha' or param == 'beta' or param == 'gamma' or param == 'theta' or param == 'phi': 129 return 0.0
130 131
132 - def delete(self, run=None):
133 """Function for deleting diffusion tensor data.""" 134 135 # Test if the run exists. 136 if not run in self.relax.data.run_names: 137 raise RelaxNoRunError, run 138 139 # Test if diffusion tensor data for the run exists. 140 if not self.relax.data.diff.has_key(run): 141 raise RelaxNoTensorError, run 142 143 # Delete the diffusion data. 144 del(self.relax.data.diff[run]) 145 146 # Clean up the runs. 147 self.relax.generic.runs.eliminate_unused_runs()
148 149
150 - def display(self, run=None):
151 """Function for displaying the diffusion tensor.""" 152 153 # Test if the run exists. 154 if not run in self.relax.data.run_names: 155 raise RelaxNoRunError, run 156 157 # Test if diffusion tensor data for the run exists. 158 if not self.relax.data.diff.has_key(run): 159 raise RelaxNoTensorError, run 160 161 # Spherical diffusion. 162 if self.relax.data.diff[run].type == 'sphere': 163 # Tensor type. 164 print "Type: Spherical diffusion" 165 166 # Parameters. 167 print "\nParameters {tm}." 168 print "tm (s): " + `self.relax.data.diff[run].tm` 169 170 # Alternate parameters. 171 print "\nAlternate parameters {Diso}." 172 print "Diso (1/s): " + `self.relax.data.diff[run].Diso` 173 174 # Fixed flag. 175 print "\nFixed: " + `self.relax.data.diff[run].fixed` 176 177 # Spheroidal diffusion. 178 elif self.relax.data.diff[run].type == 'spheroid': 179 # Tensor type. 180 print "Type: Spheroidal diffusion" 181 182 # Parameters. 183 print "\nParameters {tm, Da, theta, phi}." 184 print "tm (s): " + `self.relax.data.diff[run].tm` 185 print "Da (1/s): " + `self.relax.data.diff[run].Da` 186 print "theta (rad): " + `self.relax.data.diff[run].theta` 187 print "phi (rad): " + `self.relax.data.diff[run].phi` 188 189 # Alternate parameters. 190 print "\nAlternate parameters {Diso, Da, theta, phi}." 191 print "Diso (1/s): " + `self.relax.data.diff[run].Diso` 192 print "Da (1/s): " + `self.relax.data.diff[run].Da` 193 print "theta (rad): " + `self.relax.data.diff[run].theta` 194 print "phi (rad): " + `self.relax.data.diff[run].phi` 195 196 # Alternate parameters. 197 print "\nAlternate parameters {Dpar, Dper, theta, phi}." 198 print "Dpar (1/s): " + `self.relax.data.diff[run].Dpar` 199 print "Dper (1/s): " + `self.relax.data.diff[run].Dper` 200 print "theta (rad): " + `self.relax.data.diff[run].theta` 201 print "phi (rad): " + `self.relax.data.diff[run].phi` 202 203 # Alternate parameters. 204 print "\nAlternate parameters {tm, Dratio, theta, phi}." 205 print "tm (s): " + `self.relax.data.diff[run].tm` 206 print "Dratio: " + `self.relax.data.diff[run].Dratio` 207 print "theta (rad): " + `self.relax.data.diff[run].theta` 208 print "phi (rad): " + `self.relax.data.diff[run].phi` 209 210 # Fixed flag. 211 print "\nFixed: " + `self.relax.data.diff[run].fixed` 212 213 # Ellipsoidal diffusion. 214 elif self.relax.data.diff[run].type == 'ellipsoid': 215 # Tensor type. 216 print "Type: Ellipsoidal diffusion" 217 218 # Parameters. 219 print "\nParameters {tm, Da, Dr, alpha, beta, gamma}." 220 print "tm (s): " + `self.relax.data.diff[run].tm` 221 print "Da (1/s): " + `self.relax.data.diff[run].Da` 222 print "Dr: " + `self.relax.data.diff[run].Dr` 223 print "alpha (rad): " + `self.relax.data.diff[run].alpha` 224 print "beta (rad): " + `self.relax.data.diff[run].beta` 225 print "gamma (rad): " + `self.relax.data.diff[run].gamma` 226 227 # Alternate parameters. 228 print "\nAlternate parameters {Diso, Da, Dr, alpha, beta, gamma}." 229 print "Diso (1/s): " + `self.relax.data.diff[run].Diso` 230 print "Da (1/s): " + `self.relax.data.diff[run].Da` 231 print "Dr: " + `self.relax.data.diff[run].Dr` 232 print "alpha (rad): " + `self.relax.data.diff[run].alpha` 233 print "beta (rad): " + `self.relax.data.diff[run].beta` 234 print "gamma (rad): " + `self.relax.data.diff[run].gamma` 235 236 # Alternate parameters. 237 print "\nAlternate parameters {Dx, Dy, Dz, alpha, beta, gamma}." 238 print "Dx (1/s): " + `self.relax.data.diff[run].Dx` 239 print "Dy (1/s): " + `self.relax.data.diff[run].Dy` 240 print "Dz (1/s): " + `self.relax.data.diff[run].Dz` 241 print "alpha (rad): " + `self.relax.data.diff[run].alpha` 242 print "beta (rad): " + `self.relax.data.diff[run].beta` 243 print "gamma (rad): " + `self.relax.data.diff[run].gamma` 244 245 # Fixed flag. 246 print "\nFixed: " + `self.relax.data.diff[run].fixed`
247 248
249 - def ellipsoid(self):
250 """Function for setting up ellipsoidal diffusion.""" 251 252 # The diffusion type. 253 self.relax.data.diff[self.run].type = 'ellipsoid' 254 255 # (tm, Da, Dr, alpha, beta, gamma). 256 if self.param_types == 0: 257 # Unpack the tuple. 258 tm, Da, Dr, alpha, beta, gamma = self.params 259 260 # Scaling. 261 tm = tm * self.time_scale 262 Da = Da * self.d_scale 263 264 # Set the parameters. 265 self.set(run=self.run, value=[tm, Da, Dr], param=['tm', 'Da', 'Dr']) 266 267 # (Diso, Da, Dr, alpha, beta, gamma). 268 elif self.param_types == 1: 269 # Unpack the tuple. 270 Diso, Da, Dr, alpha, beta, gamma = self.params 271 272 # Scaling. 273 Diso = Diso * self.d_scale 274 Da = Da * self.d_scale 275 276 # Set the parameters. 277 self.set(run=self.run, value=[Diso, Da, Dr], param=['Diso', 'Da', 'Dr']) 278 279 # (Dx, Dy, Dz, alpha, beta, gamma). 280 elif self.param_types == 2: 281 # Unpack the tuple. 282 Dx, Dy, Dz, alpha, beta, gamma = self.params 283 284 # Scaling. 285 Dx = Dx * self.d_scale 286 Dy = Dy * self.d_scale 287 Dz = Dz * self.d_scale 288 289 # Set the parameters. 290 self.set(run=self.run, value=[Dx, Dy, Dz], param=['Dx', 'Dy', 'Dz']) 291 292 # Unknown parameter combination. 293 else: 294 raise RelaxUnknownParamCombError, ('param_types', self.param_types) 295 296 # Convert the angles to radians. 297 if self.angle_units == 'deg': 298 alpha = (alpha / 360.0) * 2.0 * pi 299 beta = (beta / 360.0) * 2.0 * pi 300 gamma = (gamma / 360.0) * 2.0 * pi 301 302 # Set the orientational parameters. 303 self.set(run=self.run, value=[alpha, beta, gamma], param=['alpha', 'beta', 'gamma'])
304 305
306 - def fold_angles(self, run=None, sim_index=None):
307 """Wrap the Euler or spherical angles and remove the glide reflection and translational symmetries. 308 309 Wrap the angles such that 310 311 0 <= theta <= pi, 312 0 <= phi <= 2pi, 313 314 and 315 316 0 <= alpha <= 2pi, 317 0 <= beta <= pi, 318 0 <= gamma <= 2pi. 319 320 321 For the simulated values, the angles are wrapped as 322 323 theta - pi/2 <= theta_sim <= theta + pi/2 324 phi - pi <= phi_sim <= phi + pi 325 326 and 327 328 alpha - pi <= alpha_sim <= alpha + pi 329 beta - pi/2 <= beta_sim <= beta + pi/2 330 gamma - pi <= gamma_sim <= gamma + pi 331 """ 332 333 # Arguments. 334 self.run = run 335 336 337 # Wrap the angles. 338 ################## 339 340 # Spheroid. 341 if self.relax.data.diff[self.run].type == 'spheroid': 342 # Get the current angles. 343 theta = self.relax.data.diff[self.run].theta 344 phi = self.relax.data.diff[self.run].phi 345 346 # Simulated values. 347 if sim_index != None: 348 theta_sim = self.relax.data.diff[self.run].theta_sim[sim_index] 349 phi_sim = self.relax.data.diff[self.run].phi_sim[sim_index] 350 351 # Normal value. 352 if sim_index == None: 353 self.relax.data.diff[self.run].theta = self.relax.generic.angles.wrap_angles(theta, 0.0, pi) 354 self.relax.data.diff[self.run].phi = self.relax.generic.angles.wrap_angles(phi, 0.0, 2.0*pi) 355 356 # Simulated theta and phi values. 357 else: 358 self.relax.data.diff[self.run].theta_sim[sim_index] = self.relax.generic.angles.wrap_angles(theta_sim, theta - pi/2.0, theta + pi/2.0) 359 self.relax.data.diff[self.run].phi_sim[sim_index] = self.relax.generic.angles.wrap_angles(phi_sim, phi - pi, phi + pi) 360 361 # Ellipsoid. 362 elif self.relax.data.diff[self.run].type == 'ellipsoid': 363 # Get the current angles. 364 alpha = self.relax.data.diff[self.run].alpha 365 beta = self.relax.data.diff[self.run].beta 366 gamma = self.relax.data.diff[self.run].gamma 367 368 # Simulated values. 369 if sim_index != None: 370 alpha_sim = self.relax.data.diff[self.run].alpha_sim[sim_index] 371 beta_sim = self.relax.data.diff[self.run].beta_sim[sim_index] 372 gamma_sim = self.relax.data.diff[self.run].gamma_sim[sim_index] 373 374 # Normal value. 375 if sim_index == None: 376 self.relax.data.diff[self.run].alpha = self.relax.generic.angles.wrap_angles(alpha, 0.0, 2.0*pi) 377 self.relax.data.diff[self.run].beta = self.relax.generic.angles.wrap_angles(beta, 0.0, 2.0*pi) 378 self.relax.data.diff[self.run].gamma = self.relax.generic.angles.wrap_angles(gamma, 0.0, 2.0*pi) 379 380 # Simulated alpha, beta, and gamma values. 381 else: 382 self.relax.data.diff[self.run].alpha_sim[sim_index] = self.relax.generic.angles.wrap_angles(alpha_sim, alpha - pi, alpha + pi) 383 self.relax.data.diff[self.run].beta_sim[sim_index] = self.relax.generic.angles.wrap_angles(beta_sim, beta - pi, beta + pi) 384 self.relax.data.diff[self.run].gamma_sim[sim_index] = self.relax.generic.angles.wrap_angles(gamma_sim, gamma - pi, gamma + pi) 385 386 387 # Remove the glide reflection and translational symmetries. 388 ########################################################### 389 390 # Spheroid. 391 if self.relax.data.diff[self.run].type == 'spheroid': 392 # Normal value. 393 if sim_index == None: 394 # Fold phi inside 0 and pi. 395 if self.relax.data.diff[self.run].phi >= pi: 396 self.relax.data.diff[self.run].theta = pi - self.relax.data.diff[self.run].theta 397 self.relax.data.diff[self.run].phi = self.relax.data.diff[self.run].phi - pi 398 399 # Simulated theta and phi values. 400 else: 401 # Fold phi_sim inside phi-pi/2 and phi+pi/2. 402 if self.relax.data.diff[self.run].phi_sim[sim_index] >= self.relax.data.diff[self.run].phi + pi/2.0: 403 self.relax.data.diff[self.run].theta_sim[sim_index] = pi - self.relax.data.diff[self.run].theta_sim[sim_index] 404 self.relax.data.diff[self.run].phi_sim[sim_index] = self.relax.data.diff[self.run].phi_sim[sim_index] - pi 405 elif self.relax.data.diff[self.run].phi_sim[sim_index] <= self.relax.data.diff[self.run].phi - pi/2.0: 406 self.relax.data.diff[self.run].theta_sim[sim_index] = pi - self.relax.data.diff[self.run].theta_sim[sim_index] 407 self.relax.data.diff[self.run].phi_sim[sim_index] = self.relax.data.diff[self.run].phi_sim[sim_index] + pi 408 409 # Ellipsoid. 410 elif self.relax.data.diff[self.run].type == 'ellipsoid': 411 # Normal value. 412 if sim_index == None: 413 # Fold alpha inside 0 and pi. 414 if self.relax.data.diff[self.run].alpha >= pi: 415 self.relax.data.diff[self.run].alpha = self.relax.data.diff[self.run].alpha - pi 416 417 # Fold beta inside 0 and pi. 418 if self.relax.data.diff[self.run].beta >= pi: 419 self.relax.data.diff[self.run].alpha = pi - self.relax.data.diff[self.run].alpha 420 self.relax.data.diff[self.run].beta = self.relax.data.diff[self.run].beta - pi 421 422 # Fold gamma inside 0 and pi. 423 if self.relax.data.diff[self.run].gamma >= pi: 424 self.relax.data.diff[self.run].alpha = pi - self.relax.data.diff[self.run].alpha 425 self.relax.data.diff[self.run].beta = pi - self.relax.data.diff[self.run].beta 426 self.relax.data.diff[self.run].gamma = self.relax.data.diff[self.run].gamma - pi 427 428 # Simulated theta and phi values. 429 else: 430 # Fold alpha_sim inside alpha-pi/2 and alpha+pi/2. 431 if self.relax.data.diff[self.run].alpha_sim[sim_index] >= self.relax.data.diff[self.run].alpha + pi/2.0: 432 self.relax.data.diff[self.run].alpha_sim[sim_index] = self.relax.data.diff[self.run].alpha_sim[sim_index] - pi 433 elif self.relax.data.diff[self.run].alpha_sim[sim_index] <= self.relax.data.diff[self.run].alpha - pi/2.0: 434 self.relax.data.diff[self.run].alpha_sim[sim_index] = self.relax.data.diff[self.run].alpha_sim[sim_index] + pi 435 436 # Fold beta_sim inside beta-pi/2 and beta+pi/2. 437 if self.relax.data.diff[self.run].beta_sim[sim_index] >= self.relax.data.diff[self.run].beta + pi/2.0: 438 self.relax.data.diff[self.run].alpha_sim[sim_index] = pi - self.relax.data.diff[self.run].alpha_sim[sim_index] 439 self.relax.data.diff[self.run].beta_sim[sim_index] = self.relax.data.diff[self.run].beta_sim[sim_index] - pi 440 elif self.relax.data.diff[self.run].beta_sim[sim_index] <= self.relax.data.diff[self.run].beta - pi/2.0: 441 self.relax.data.diff[self.run].alpha_sim[sim_index] = pi - self.relax.data.diff[self.run].alpha_sim[sim_index] 442 self.relax.data.diff[self.run].beta_sim[sim_index] = self.relax.data.diff[self.run].beta_sim[sim_index] + pi 443 444 # Fold gamma_sim inside gamma-pi/2 and gamma+pi/2. 445 if self.relax.data.diff[self.run].gamma_sim[sim_index] >= self.relax.data.diff[self.run].gamma + pi/2.0: 446 self.relax.data.diff[self.run].alpha_sim[sim_index] = pi - self.relax.data.diff[self.run].alpha_sim[sim_index] 447 self.relax.data.diff[self.run].beta_sim[sim_index] = pi - self.relax.data.diff[self.run].beta_sim[sim_index] 448 self.relax.data.diff[self.run].gamma_sim[sim_index] = self.relax.data.diff[self.run].gamma_sim[sim_index] - pi 449 elif self.relax.data.diff[self.run].gamma_sim[sim_index] <= self.relax.data.diff[self.run].gamma - pi/2.0: 450 self.relax.data.diff[self.run].alpha_sim[sim_index] = pi - self.relax.data.diff[self.run].alpha_sim[sim_index] 451 self.relax.data.diff[self.run].beta_sim[sim_index] = pi - self.relax.data.diff[self.run].beta_sim[sim_index] 452 self.relax.data.diff[self.run].gamma_sim[sim_index] = self.relax.data.diff[self.run].gamma_sim[sim_index] + pi
453 454
455 - def init(self, run=None, params=None, time_scale=1.0, d_scale=1.0, angle_units='deg', param_types=0, spheroid_type=None, fixed=1):
456 """Function for initialising the diffusion tensor.""" 457 458 # Arguments. 459 self.run = run 460 self.params = params 461 self.time_scale = time_scale 462 self.d_scale = d_scale 463 self.angle_units = angle_units 464 self.param_types = param_types 465 self.spheroid_type = spheroid_type 466 467 # Test if the run exists. 468 if not self.run in self.relax.data.run_names: 469 raise RelaxNoRunError, self.run 470 471 # Test if diffusion tensor data corresponding to the run already exists. 472 if self.relax.data.diff.has_key(self.run): 473 raise RelaxTensorError, self.run 474 475 # Check the validity of the angle_units argument. 476 valid_types = ['deg', 'rad'] 477 if not angle_units in valid_types: 478 raise RelaxError, "The diffusion tensor 'angle_units' argument " + `angle_units` + " should be either 'deg' or 'rad'." 479 480 # Add the run to the diffusion tensor data structure. 481 self.relax.data.diff.add_item(self.run) 482 483 # Set the fixed flag. 484 self.relax.data.diff[self.run].fixed = fixed 485 486 # Spherical diffusion. 487 if type(params) == float: 488 num_params = 1 489 self.sphere() 490 491 # Spheroidal diffusion. 492 elif (type(params) == tuple or type(params) == list) and len(params) == 4: 493 num_params = 4 494 self.spheroid() 495 496 # Ellipsoidal diffusion. 497 elif (type(params) == tuple or type(params) == list) and len(params) == 6: 498 num_params = 6 499 self.ellipsoid() 500 501 # Unknown. 502 else: 503 raise RelaxError, "The diffusion tensor parameters " + `params` + " are of an unknown type." 504 505 # Test the validity of the parameters. 506 self.test_params(num_params)
507 508
509 - def map_bounds(self, run, param):
510 """The function for creating bounds for the mapping function.""" 511 512 # Initialise. 513 self.run = run 514 515 # tm. 516 if param == 'tm': 517 return [0, 10.0 * 1e-9] 518 519 # {Diso, Dx, Dy, Dz, Dpar, Dper}. 520 if param == 'Diso' or param == 'Dx' or param == 'Dy' or param == 'Dz' or param == 'Dpar' or param == 'Dper': 521 return [1e6, 1e7] 522 523 # Da. 524 if param == 'Da': 525 return [-3.0/2.0 * 1e7, 3.0 * 1e7] 526 527 # Dr. 528 elif param == 'Dr': 529 return [0, 1] 530 531 # Dratio. 532 elif param == 'Dratio': 533 return [1.0/3.0, 3.0] 534 535 # theta. 536 elif param == 'theta': 537 return [0, pi] 538 539 # phi. 540 elif param == 'phi': 541 return [0, 2*pi] 542 543 # alpha. 544 elif param == 'alpha': 545 return [0, 2*pi] 546 547 # beta. 548 elif param == 'beta': 549 return [0, pi] 550 551 # gamma. 552 elif param == 'gamma': 553 return [0, 2*pi]
554 555
556 - def map_labels(self, run, index, params, bounds, swap, inc):
557 """Function for creating labels, tick locations, and tick values for an OpenDX map.""" 558 559 # Initialise. 560 labels = "{" 561 tick_locations = [] 562 tick_values = [] 563 n = len(params) 564 axis_incs = 5 565 loc_inc = inc / axis_incs 566 567 # Increment over the model parameters. 568 for i in xrange(n): 569 # Parameter conversion factors. 570 factor = self.return_conversion_factor(params[swap[i]]) 571 572 # Parameter units. 573 units = self.return_units(params[swap[i]]) 574 575 # Labels. 576 if units: 577 labels = labels + "\"" + params[swap[i]] + " (" + units + ")\"" 578 else: 579 labels = labels + "\"" + params[swap[i]] + "\"" 580 581 # Tick values. 582 vals = bounds[swap[i], 0] / factor 583 val_inc = (bounds[swap[i], 1] - bounds[swap[i], 0]) / (axis_incs * factor) 584 585 if i < n - 1: 586 labels = labels + " " 587 else: 588 labels = labels + "}" 589 590 # Tick locations. 591 string = "{" 592 val = 0.0 593 for j in xrange(axis_incs + 1): 594 string = string + " " + `val` 595 val = val + loc_inc 596 string = string + " }" 597 tick_locations.append(string) 598 599 # Tick values. 600 string = "{" 601 for j in xrange(axis_incs + 1): 602 string = string + "\"" + "%.2f" % vals + "\" " 603 vals = vals + val_inc 604 string = string + "}" 605 tick_values.append(string) 606 607 return labels, tick_locations, tick_values
608 609
610 - def return_conversion_factor(self, param):
611 """Function for returning the factor of conversion between different parameter units. 612 613 For example, the internal representation of tm is in seconds, whereas the external 614 representation is in nanoseconds, therefore this function will return 1e-9 for tm. 615 """ 616 617 # Get the object name. 618 object_name = self.return_data_name(param) 619 620 # tm (nanoseconds). 621 if object_name == 'tm': 622 return 1e-9 623 624 # Diso, Da, Dx, Dy, Dz, Dpar, Dper. 625 elif object_name in ['Diso', 'Da', 'Dx', 'Dy', 'Dz', 'Dpar', 'Dper']: 626 return 1e6 627 628 # Angles. 629 elif object_name in ['theta', 'phi', 'alpha', 'beta', 'gamma']: 630 return (2.0*pi) / 360.0 631 632 # No conversion factor. 633 else: 634 return 1.0
635 636
637 - def return_data_name(self, name):
638 """ 639 Diffusion tensor parameter string matching patterns 640 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 641 642 ____________________________________________________________________________________________ 643 | | | | 644 | Data type | Object name | Patterns | 645 |________________________________________________________|______________|__________________| 646 | | | | 647 | Global correlation time - tm | 'tm' | '^tm$' | 648 | | | | 649 | Isotropic component of the diffusion tensor - Diso | 'Diso' | '[Dd]iso' | 650 | | | | 651 | Anisotropic component of the diffusion tensor - Da | 'Da' | '[Dd]a' | 652 | | | | 653 | Rhombic component of the diffusion tensor - Dr | 'Dr' | '[Dd]r$' | 654 | | | | 655 | Eigenvalue associated with the x-axis of the diffusion | 'Dx' | '[Dd]x' | 656 | diffusion tensor - Dx | | | 657 | | | | 658 | Eigenvalue associated with the y-axis of the diffusion | 'Dy' | '[Dd]y' | 659 | diffusion tensor - Dy | | | 660 | | | | 661 | Eigenvalue associated with the z-axis of the diffusion | 'Dz' | '[Dd]z' | 662 | diffusion tensor - Dz | | | 663 | | | | 664 | Diffusion coefficient parallel to the major axis of | 'Dpar' | '[Dd]par' | 665 | the spheroid diffusion tensor - Dpar | | | 666 | | | | 667 | Diffusion coefficient perpendicular to the major axis | 'Dper' | '[Dd]per' | 668 | of the spheroid diffusion tensor - Dper | | | 669 | | | | 670 | Ratio of the parallel and perpendicular components of | 'Dratio' | '[Dd]ratio' | 671 | the spheroid diffusion tensor - Dratio | | | 672 | | | | 673 | The first Euler angle of the ellipsoid diffusion | 'alpha' | '^a$' or 'alpha' | 674 | tensor - alpha | | | 675 | | | | 676 | The second Euler angle of the ellipsoid diffusion | 'beta' | '^b$' or 'beta' | 677 | tensor - beta | | | 678 | | | | 679 | The third Euler angle of the ellipsoid diffusion | 'gamma' | '^g$' or 'gamma' | 680 | tensor - gamma | | | 681 | | | | 682 | The polar angle defining the major axis of the | 'theta' | 'theta' | 683 | spheroid diffusion tensor - theta | | | 684 | | | | 685 | The azimuthal angle defining the major axis of the | 'phi' | 'phi' | 686 | spheroid diffusion tensor - phi | | | 687 |________________________________________________________|______________|__________________| 688 """ 689 690 # Local tm. 691 if search('^tm$', name): 692 return 'tm' 693 694 # Diso. 695 if search('[Dd]iso', name): 696 return 'Diso' 697 698 # Da. 699 if search('[Dd]a', name): 700 return 'Da' 701 702 # Dr. 703 if search('[Dd]r$', name): 704 return 'Dr' 705 706 # Dx. 707 if search('[Dd]x', name): 708 return 'Dx' 709 710 # Dy. 711 if search('[Dd]y', name): 712 return 'Dy' 713 714 # Dz. 715 if search('[Dd]z', name): 716 return 'Dz' 717 718 # Dpar. 719 if search('[Dd]par', name): 720 return 'Dpar' 721 722 # Dper. 723 if search('[Dd]per', name): 724 return 'Dper' 725 726 # Dratio. 727 if search('[Dd]ratio', name): 728 return 'Dratio' 729 730 # alpha. 731 if search('^a$', name) or search('alpha', name): 732 return 'alpha' 733 734 # beta. 735 if search('^b$', name) or search('beta', name): 736 return 'beta' 737 738 # gamma. 739 if search('^g$', name) or search('gamma', name): 740 return 'gamma' 741 742 # theta. 743 if search('theta', name): 744 return 'theta' 745 746 # phi. 747 if search('phi', name): 748 return 'phi'
749 750
751 - def return_eigenvalues(self, run=None):
752 """Function for returning Dx, Dy, and Dz.""" 753 754 # Argument. 755 if run: 756 self.run = run 757 758 # Reassign the data. 759 data = self.relax.data.diff[self.run] 760 761 # Diso. 762 Diso = 1.0 / (6.0 * data.tm) 763 764 # Dx. 765 Dx = Diso - 1.0/3.0 * data.Da * (1.0 + 3.0 * data.Dr) 766 767 # Dy. 768 Dy = Diso - 1.0/3.0 * data.Da * (1.0 - 3.0 * data.Dr) 769 770 # Dz. 771 Dz = Diso + 2.0/3.0 * data.Da 772 773 # Return the eigenvalues. 774 return Dx, Dy, Dz
775 776
777 - def return_units(self, param):
778 """Function for returning a string representing the parameters units. 779 780 For example, the internal representation of tm is in seconds, whereas the external 781 representation is in nanoseconds, therefore this function will return the string 782 'nanoseconds' for tm. 783 """ 784 785 # Get the object name. 786 object_name = self.return_data_name(param) 787 788 # tm (nanoseconds). 789 if object_name == 'tm': 790 return 'ns' 791 792 # Diso, Da, Dx, Dy, Dz, Dpar, Dper. 793 elif object_name in ['Diso', 'Da', 'Dx', 'Dy', 'Dz', 'Dpar', 'Dper']: 794 return '1e6 1/s' 795 796 # Angles. 797 elif object_name in ['theta', 'phi', 'alpha', 'beta', 'gamma']: 798 return 'deg'
799 800
801 - def set(self, run=None, value=None, param=None):
802 """ 803 Diffusion tensor set details 804 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 805 806 If the diffusion tensor has not been setup, use the more powerful function 807 'diffusion_tensor.init' to initialise the tensor parameters. 808 809 The diffusion tensor parameters can only be set when the run corresponds to model-free 810 analysis. The units of the parameters are: 811 812 Inverse seconds for tm. 813 Seconds for Diso, Da, Dx, Dy, Dz, Dpar, Dper. 814 Unitless for Dratio and Dr. 815 Radians for all angles (alpha, beta, gamma, theta, phi). 816 817 818 When setting a diffusion tensor parameter, the residue number has no effect. As the 819 internal parameters of spherical diffusion are {tm}, spheroidal diffusion are {tm, Da, 820 theta, phi}, and ellipsoidal diffusion are {tm, Da, Dr, alpha, beta, gamma}, supplying 821 geometric parameters must be done in the following way. If a single geometric parameter is 822 supplied, it must be one of tm, Diso, Da, Dr, or Dratio. For the parameters Dpar, Dper, Dx, 823 Dy, and Dx, it is not possible to determine how to use the currently set values together 824 with the supplied value to calculate the new internal parameters. For spheroidal diffusion, 825 when supplying multiple geometric parameters, the set must belong to one of 826 827 {tm, Da}, 828 {Diso, Da}, 829 {tm, Dratio}, 830 {Dpar, Dper}, 831 {Diso, Dratio}, 832 833 where either theta, phi, or both orientational parameters can be additionally supplied. For 834 ellipsoidal diffusion, again when supplying multiple geometric parameters, the set must 835 belong to one of 836 837 {tm, Da, Dr}, 838 {Diso, Da, Dr}, 839 {Dx, Dy, Dz}, 840 841 where any number of the orientational parameters, alpha, beta, or gamma can be additionally 842 supplied. 843 """ 844 845 # Initialise. 846 geo_params = [] 847 geo_values = [] 848 orient_params = [] 849 orient_values = [] 850 851 # Loop over the parameters. 852 for i in xrange(len(param)): 853 # Get the object name. 854 param[i] = self.return_data_name(param[i]) 855 856 # Unknown parameter. 857 if not param[i]: 858 raise RelaxUnknownParamError, ("diffusion tensor", param[i]) 859 860 # Default value. 861 if value[i] == None: 862 value[i] = self.default_value(param[i]) 863 864 # Geometric parameter. 865 if param[i] in ['tm', 'Diso', 'Da', 'Dratio', 'Dper', 'Dpar', 'Dr', 'Dx', 'Dy', 'Dz']: 866 geo_params.append(param[i]) 867 geo_values.append(value[i]) 868 869 # Orientational parameter. 870 if param[i] in ['theta', 'phi', 'alpha', 'beta', 'gamma']: 871 orient_params.append(param[i]) 872 orient_values.append(value[i]) 873 874 875 # Spherical diffusion. 876 ###################### 877 878 if self.relax.data.diff[self.run].type == 'sphere': 879 # Geometric parameters. 880 ####################### 881 882 # A single geometric parameter. 883 if len(geo_params) == 1: 884 # The single parameter tm. 885 if geo_params[0] == 'tm': 886 self.relax.data.diff[self.run].tm = geo_values[0] 887 888 # The single parameter Diso. 889 elif geo_params[0] == 'Diso': 890 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * geo_values[0]) 891 892 # Cannot set the single parameter. 893 else: 894 raise RelaxError, "The geometric diffusion parameter " + `geo_params[0]` + " cannot be set." 895 896 # More than one geometric parameters. 897 elif len(geo_params) > 1: 898 raise RelaxUnknownParamCombError, ('geometric parameter set', geo_params) 899 900 901 # Orientational parameters. 902 ########################### 903 904 # ??? 905 if len(orient_params): 906 raise RelaxError, "For spherical diffusion, the orientation parameters " + `orient_params` + " should not exist." 907 908 909 # Spheroidal diffusion. 910 ####################### 911 912 elif self.relax.data.diff[self.run].type == 'spheroid': 913 # Geometric parameters. 914 ####################### 915 916 # A single geometric parameter. 917 if len(geo_params) == 1: 918 # The single parameter tm. 919 if geo_params[0] == 'tm': 920 self.relax.data.diff[self.run].tm = geo_values[0] 921 922 # The single parameter Diso. 923 elif geo_params[0] == 'Diso': 924 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * geo_values[0]) 925 926 # The single parameter Da. 927 elif geo_params[0] == 'Da': 928 self.relax.data.diff[self.run].Da = geo_values[0] 929 930 # The single parameter Dratio. 931 elif geo_params[0] == 'Dratio': 932 Dratio = geo_values[0] 933 self.relax.data.diff[self.run].Da = (Dratio - 1.0) / (2.0 * self.relax.data.diff[self.run].tm * (Dratio + 2.0)) 934 935 # Cannot set the single parameter. 936 else: 937 raise RelaxError, "The geometric diffusion parameter " + `geo_params[0]` + " cannot be set." 938 939 # Two geometric parameters. 940 elif len(geo_params) == 2: 941 # The geometric parameter set {tm, Da}. 942 if geo_params.count('tm') == 1 and geo_params.count('Da') == 1: 943 # The parameters. 944 tm = geo_values[geo_params.index('tm')] 945 Da = geo_values[geo_params.index('Da')] 946 947 # Set the internal parameter values. 948 self.relax.data.diff[self.run].tm = tm 949 self.relax.data.diff[self.run].Da = Da 950 951 # The geometric parameter set {Diso, Da}. 952 elif geo_params.count('Diso') == 1 and geo_params.count('Da') == 1: 953 # The parameters. 954 Diso = geo_values[geo_params.index('Diso')] 955 Da = geo_values[geo_params.index('Da')] 956 957 # Set the internal parameter values. 958 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * Diso) 959 self.relax.data.diff[self.run].Da = Da 960 961 # The geometric parameter set {tm, Dratio}. 962 elif geo_params.count('tm') == 1 and geo_params.count('Dratio') == 1: 963 # The parameters. 964 tm = geo_values[geo_params.index('tm')] 965 Dratio = geo_values[geo_params.index('Dratio')] 966 967 # Set the internal parameter values. 968 self.relax.data.diff[self.run].tm = tm 969 self.relax.data.diff[self.run].Da = (Dratio - 1.0) / (2.0 * tm * (Dratio + 2.0)) 970 971 # The geometric parameter set {Dpar, Dper}. 972 elif geo_params.count('Dpar') == 1 and geo_params.count('Dper') == 1: 973 # The parameters. 974 Dpar = geo_values[geo_params.index('Dpar')] 975 Dper = geo_values[geo_params.index('Dper')] 976 977 # Set the internal parameter values. 978 self.relax.data.diff[self.run].tm = 1.0 / (2.0 * (Dpar + 2.0*Dper)) 979 self.relax.data.diff[self.run].Da = Dpar - Dper 980 981 # The geometric parameter set {Diso, Dratio}. 982 elif geo_params.count('Diso') == 1 and geo_params.count('Dratio') == 1: 983 # The parameters. 984 Diso = geo_values[geo_params.index('Diso')] 985 Dratio = geo_values[geo_params.index('Dratio')] 986 987 # Set the internal parameter values. 988 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * Diso) 989 self.relax.data.diff[self.run].Da = 3.0 * Diso * (Dratio - 1.0) / (Dratio + 2.0) 990 991 # Unknown parameter combination. 992 else: 993 raise RelaxUnknownParamCombError, ('geometric parameter set', geo_params) 994 995 # More than two geometric parameters. 996 elif len(geo_params) > 2: 997 raise RelaxUnknownParamCombError, ('geometric parameter set', geo_params) 998 999 1000 # Orientational parameters. 1001 ########################### 1002 1003 # A single orientational parameter. 1004 if len(orient_params) == 1: 1005 # The single parameter theta. 1006 if orient_params[0] == 'theta': 1007 self.relax.data.diff[self.run].theta = orient_values[orient_params.index('theta')] 1008 1009 # The single parameter phi. 1010 elif orient_params[0] == 'phi': 1011 self.relax.data.diff[self.run].phi = orient_values[orient_params.index('phi')] 1012 1013 # Two orientational parameters. 1014 elif len(orient_params) == 2: 1015 # The orientational parameter set {theta, phi}. 1016 if orient_params.count('theta') == 1 and orient_params.count('phi') == 1: 1017 self.relax.data.diff[self.run].theta = orient_values[orient_params.index('theta')] 1018 self.relax.data.diff[self.run].phi = orient_values[orient_params.index('phi')] 1019 1020 # Unknown parameter combination. 1021 else: 1022 raise RelaxUnknownParamCombError, ('orientational parameter set', orient_params) 1023 1024 # More than two orientational parameters. 1025 elif len(orient_params) > 2: 1026 raise RelaxUnknownParamCombError, ('orientational parameter set', orient_params) 1027 1028 1029 # Ellipsoidal diffusion. 1030 ######################## 1031 1032 elif self.relax.data.diff[self.run].type == 'ellipsoid': 1033 # Geometric parameters. 1034 ####################### 1035 1036 # A single geometric parameter. 1037 if len(geo_params) == 1: 1038 # The single parameter tm. 1039 if geo_params[0] == 'tm': 1040 self.relax.data.diff[self.run].tm = geo_values[0] 1041 1042 # The single parameter Diso. 1043 elif geo_params[0] == 'Diso': 1044 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * geo_values[0]) 1045 1046 # The single parameter Da. 1047 elif geo_params[0] == 'Da': 1048 self.relax.data.diff[self.run].Da = geo_values[0] 1049 1050 # The single parameter Dr. 1051 elif geo_params[0] == 'Dr': 1052 self.relax.data.diff[self.run].Dr = geo_values[0] 1053 1054 # Cannot set the single parameter. 1055 else: 1056 raise RelaxError, "The geometric diffusion parameter " + `geo_params[0]` + " cannot be set." 1057 1058 # Two geometric parameters. 1059 elif len(geo_params) == 2: 1060 # The geometric parameter set {tm, Da}. 1061 if geo_params.count('tm') == 1 and geo_params.count('Da') == 1: 1062 # The parameters. 1063 tm = geo_values[geo_params.index('tm')] 1064 Da = geo_values[geo_params.index('Da')] 1065 1066 # Set the internal parameter values. 1067 self.relax.data.diff[self.run].tm = tm 1068 self.relax.data.diff[self.run].Da = Da 1069 1070 # The geometric parameter set {tm, Dr}. 1071 elif geo_params.count('tm') == 1 and geo_params.count('Dr') == 1: 1072 # The parameters. 1073 tm = geo_values[geo_params.index('tm')] 1074 Dr = geo_values[geo_params.index('Dr')] 1075 1076 # Set the internal parameter values. 1077 self.relax.data.diff[self.run].tm = tm 1078 self.relax.data.diff[self.run].Dr = Dr 1079 1080 # The geometric parameter set {Diso, Da}. 1081 elif geo_params.count('Diso') == 1 and geo_params.count('Da') == 1: 1082 # The parameters. 1083 Diso = geo_values[geo_params.index('Diso')] 1084 Da = geo_values[geo_params.index('Da')] 1085 1086 # Set the internal parameter values. 1087 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * Diso) 1088 self.relax.data.diff[self.run].Da = Da 1089 1090 # The geometric parameter set {Diso, Dr}. 1091 elif geo_params.count('Diso') == 1 and geo_params.count('Dr') == 1: 1092 # The parameters. 1093 Diso = geo_values[geo_params.index('Diso')] 1094 Dr = geo_values[geo_params.index('Dr')] 1095 1096 # Set the internal parameter values. 1097 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * Diso) 1098 self.relax.data.diff[self.run].Dr = Dr 1099 1100 # The geometric parameter set {Da, Dr}. 1101 elif geo_params.count('Da') == 1 and geo_params.count('Dr') == 1: 1102 # The parameters. 1103 Da = geo_values[geo_params.index('Da')] 1104 Dr = geo_values[geo_params.index('Dr')] 1105 1106 # Set the internal parameter values. 1107 self.relax.data.diff[self.run].Da = Da 1108 self.relax.data.diff[self.run].Da = Dr 1109 1110 # Unknown parameter combination. 1111 else: 1112 raise RelaxUnknownParamCombError, ('geometric parameter set', geo_params) 1113 1114 # Three geometric parameters. 1115 elif len(geo_params) == 3: 1116 # The geometric parameter set {tm, Da, Dr}. 1117 if geo_params.count('tm') == 1 and geo_params.count('Da') == 1 and geo_params.count('Dr') == 1: 1118 # The parameters. 1119 tm = geo_values[geo_params.index('tm')] 1120 Da = geo_values[geo_params.index('Da')] 1121 Dr = geo_values[geo_params.index('Dr')] 1122 1123 # Set the internal parameter values. 1124 self.relax.data.diff[self.run].tm = tm 1125 self.relax.data.diff[self.run].Da = Da 1126 self.relax.data.diff[self.run].Dr = Dr 1127 1128 # The geometric parameter set {Diso, Da, Dr}. 1129 elif geo_params.count('Diso') == 1 and geo_params.count('Da') == 1 and geo_params.count('Dr') == 1: 1130 # The parameters. 1131 Diso = geo_values[geo_params.index('Diso')] 1132 Da = geo_values[geo_params.index('Da')] 1133 Dr = geo_values[geo_params.index('Dr')] 1134 1135 # Set the internal parameter values. 1136 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * Diso) 1137 self.relax.data.diff[self.run].Da = Da 1138 self.relax.data.diff[self.run].Dr = Dr 1139 1140 # The geometric parameter set {Dx, Dy, Dz}. 1141 elif geo_params.count('Dx') == 1 and geo_params.count('Dy') == 1 and geo_params.count('Dz') == 1: 1142 # The parameters. 1143 Dx = geo_values[geo_params.index('Dx')] 1144 Dy = geo_values[geo_params.index('Dy')] 1145 Dz = geo_values[geo_params.index('Dz')] 1146 1147 # Set the internal tm value. 1148 if Dx + Dy + Dz == 0.0: 1149 self.relax.data.diff[self.run].tm = 1e99 1150 else: 1151 self.relax.data.diff[self.run].tm = 0.5 / (Dx + Dy + Dz) 1152 1153 # Set the internal Da value. 1154 self.relax.data.diff[self.run].Da = Dz - 0.5*(Dx + Dy) 1155 1156 # Set the internal Dr value. 1157 if self.relax.data.diff[self.run].Da == 0.0: 1158 self.relax.data.diff[self.run].Dr = (Dy - Dx) * 1e99 1159 else: 1160 self.relax.data.diff[self.run].Dr = (Dy - Dx) / (2.0*self.relax.data.diff[self.run].Da) 1161 1162 # Unknown parameter combination. 1163 else: 1164 raise RelaxUnknownParamCombError, ('geometric parameter set', geo_params) 1165 1166 1167 # More than three geometric parameters. 1168 elif len(geo_params) > 3: 1169 raise RelaxUnknownParamCombError, ('geometric parameter set', geo_params) 1170 1171 1172 # Orientational parameters. 1173 ########################### 1174 1175 # A single orientational parameter. 1176 if len(orient_params) == 1: 1177 # The single parameter alpha. 1178 if orient_params[0] == 'alpha': 1179 self.relax.data.diff[self.run].alpha = orient_values[orient_params.index('alpha')] 1180 1181 # The single parameter beta. 1182 elif orient_params[0] == 'beta': 1183 self.relax.data.diff[self.run].beta = orient_values[orient_params.index('beta')] 1184 1185 # The single parameter gamma. 1186 elif orient_params[0] == 'gamma': 1187 self.relax.data.diff[self.run].gamma = orient_values[orient_params.index('gamma')] 1188 1189 # Two orientational parameters. 1190 elif len(orient_params) == 2: 1191 # The orientational parameter set {alpha, beta}. 1192 if orient_params.count('alpha') == 1 and orient_params.count('beta') == 1: 1193 self.relax.data.diff[self.run].alpha = orient_values[orient_params.index('alpha')] 1194 self.relax.data.diff[self.run].beta = orient_values[orient_params.index('beta')] 1195 1196 # The orientational parameter set {alpha, gamma}. 1197 if orient_params.count('alpha') == 1 and orient_params.count('gamma') == 1: 1198 self.relax.data.diff[self.run].alpha = orient_values[orient_params.index('alpha')] 1199 self.relax.data.diff[self.run].gamma = orient_values[orient_params.index('gamma')] 1200 1201 # The orientational parameter set {beta, gamma}. 1202 if orient_params.count('beta') == 1 and orient_params.count('gamma') == 1: 1203 self.relax.data.diff[self.run].beta = orient_values[orient_params.index('beta')] 1204 self.relax.data.diff[self.run].gamma = orient_values[orient_params.index('gamma')] 1205 1206 # Unknown parameter combination. 1207 else: 1208 raise RelaxUnknownParamCombError, ('orientational parameter set', orient_params) 1209 1210 # Three orientational parameters. 1211 elif len(orient_params) == 3: 1212 # The orientational parameter set {alpha, beta, gamma}. 1213 if orient_params.count('alpha') == 1 and orient_params.count('beta') == 1: 1214 self.relax.data.diff[self.run].alpha = orient_values[orient_params.index('alpha')] 1215 self.relax.data.diff[self.run].beta = orient_values[orient_params.index('beta')] 1216 self.relax.data.diff[self.run].gamma = orient_values[orient_params.index('gamma')] 1217 1218 # Unknown parameter combination. 1219 else: 1220 raise RelaxUnknownParamCombError, ('orientational parameter set', orient_params) 1221 1222 # More than three orientational parameters. 1223 elif len(orient_params) > 3: 1224 raise RelaxUnknownParamCombError, ('orientational parameter set', orient_params) 1225 1226 1227 # Fold the angles in. 1228 ##################### 1229 1230 if orient_params: 1231 self.fold_angles(self.run)
1232 1233
1234 - def sphere(self):
1235 """Function for setting up spherical diffusion.""" 1236 1237 # The diffusion type. 1238 self.relax.data.diff[self.run].type = 'sphere' 1239 1240 # tm. 1241 if self.param_types == 0: 1242 # Correlation times. 1243 self.relax.data.diff[self.run].tm = self.params * self.time_scale 1244 1245 # Diffusion tensor eigenvalues. 1246 self.relax.data.diff[self.run].Diso = 6.0 / self.relax.data.diff[self.run].tm 1247 1248 # Diso 1249 elif self.param_types == 1: 1250 # Diffusion tensor eigenvalues. 1251 self.relax.data.diff[self.run].Diso = self.params * self.d_scale 1252 1253 # Correlation times. 1254 self.relax.data.diff[self.run].tm = 1.0 / (6.0 * self.relax.data.diff[self.run].Diso) 1255 1256 # Unknown parameter combination. 1257 else: 1258 raise RelaxUnknownParamCombError, ('param_types', self.param_types)
1259 1260
1261 - def spheroid(self):
1262 """Function for setting up spheroidal diffusion.""" 1263 1264 # The diffusion type. 1265 self.relax.data.diff[self.run].type = 'spheroid' 1266 1267 # Spheroid diffusion type. 1268 allowed_types = [None, 'oblate', 'prolate'] 1269 if self.spheroid_type not in allowed_types: 1270 raise RelaxError, "The 'spheroid_type' argument " + `self.spheroid_type` + " should be 'oblate', 'prolate', or None." 1271 self.relax.data.diff[self.run].spheroid_type = self.spheroid_type 1272 1273 # (tm, Da, theta, phi). 1274 if self.param_types == 0: 1275 # Unpack the tuple. 1276 tm, Da, theta, phi = self.params 1277 1278 # Scaling. 1279 tm = tm * self.time_scale 1280 Da = Da * self.d_scale 1281 1282 # Set the parameters. 1283 self.set(run=self.run, value=[tm, Da], param=['tm', 'Da']) 1284 1285 # (Diso, Da, theta, phi). 1286 elif self.param_types == 1: 1287 # Unpack the tuple. 1288 Diso, Da, theta, phi = self.params 1289 1290 # Scaling. 1291 Diso = Diso * self.d_scale 1292 Da = Da * self.d_scale 1293 1294 # Set the parameters. 1295 self.set(run=self.run, value=[Diso, Da], param=['Diso', 'Da']) 1296 1297 # (tm, Dratio, theta, phi). 1298 elif self.param_types == 2: 1299 # Unpack the tuple. 1300 tm, Dratio, theta, phi = self.params 1301 1302 # Scaling. 1303 tm = tm * self.time_scale 1304 1305 # Set the parameters. 1306 self.set(run=self.run, value=[tm, Dratio], param=['tm', 'Dratio']) 1307 1308 # (Dpar, Dper, theta, phi). 1309 elif self.param_types == 3: 1310 # Unpack the tuple. 1311 Dpar, Dper, theta, phi = self.params 1312 1313 # Scaling. 1314 Dpar = Dpar * self.d_scale 1315 Dper = Dper * self.d_scale 1316 1317 # Set the parameters. 1318 self.set(run=self.run, value=[Dpar, Dper], param=['Dpar', 'Dper']) 1319 1320 # (Diso, Dratio, theta, phi). 1321 elif self.param_types == 4: 1322 # Unpack the tuple. 1323 Diso, Dratio, theta, phi = self.params 1324 1325 # Scaling. 1326 Diso = Diso * self.d_scale 1327 1328 # Set the parameters. 1329 self.set(run=self.run, value=[Diso, Dratio], param=['Diso', 'Dratio']) 1330 1331 # Unknown parameter combination. 1332 else: 1333 raise RelaxUnknownParamCombError, ('param_types', self.param_types) 1334 1335 # Convert the angles to radians. 1336 if self.angle_units == 'deg': 1337 theta = (theta / 360.0) * 2.0 * pi 1338 phi = (phi / 360.0) * 2.0 * pi 1339 1340 # Set the orientational parameters. 1341 self.set(run=self.run, value=[theta, phi], param=['theta', 'phi'])
1342 1343
1344 - def test_params(self, num_params):
1345 """Function for testing the validity of the input parameters.""" 1346 1347 # An allowable error to account for machine precision, optimisation quality, etc. 1348 error = 1e-4 1349 1350 # tm. 1351 tm = self.relax.data.diff[self.run].tm 1352 if tm <= 0.0 or tm > 1e-6: 1353 raise RelaxError, "The tm value of " + `tm` + " should be between zero and one microsecond." 1354 1355 # Spheroid. 1356 if num_params == 4: 1357 # Parameters. 1358 Diso = 1.0 / (6.0 * self.relax.data.diff[self.run].tm) 1359 Da = self.relax.data.diff[self.run].Da 1360 1361 # Da. 1362 if Da < (-1.5*Diso - error*Diso) or Da > (3.0*Diso + error*Diso): 1363 raise RelaxError, "The Da value of " + `Da` + " should be between -3/2 * Diso and 3Diso." 1364 1365 # Ellipsoid. 1366 if num_params == 6: 1367 # Parameters. 1368 Diso = 1.0 / (6.0 * self.relax.data.diff[self.run].tm) 1369 Da = self.relax.data.diff[self.run].Da 1370 Dr = self.relax.data.diff[self.run].Dr 1371 1372 # Da. 1373 if Da < (0.0 - error*Diso) or Da > (3.0*Diso + error*Diso): 1374 raise RelaxError, "The Da value of " + `Da` + " should be between zero and 3Diso." 1375 1376 # Dr. 1377 if Dr < (0.0 - error) or Dr > (1.0 + error): 1378 raise RelaxError, "The Dr value of " + `Dr` + " should be between zero and one."
1379 1380
1381 - def unit_axes(self):
1382 """Function for calculating the unit axes of the diffusion tensor. 1383 1384 Spheroid 1385 ~~~~~~~~ 1386 1387 The unit Dpar vector is 1388 1389 | sin(theta) * cos(phi) | 1390 Dpar = | sin(theta) * sin(phi) | 1391 | cos(theta) | 1392 1393 1394 Ellipsoid 1395 ~~~~~~~~~ 1396 1397 The unit Dx vector is 1398 1399 | -sin(alpha) * sin(gamma) + cos(alpha) * cos(beta) * cos(gamma) | 1400 Dx = | -sin(alpha) * cos(gamma) - cos(alpha) * cos(beta) * sin(gamma) | 1401 | cos(alpha) * sin(beta) | 1402 1403 The unit Dy vector is 1404 1405 | cos(alpha) * sin(gamma) + sin(alpha) * cos(beta) * cos(gamma) | 1406 Dy = | cos(alpha) * cos(gamma) - sin(alpha) * cos(beta) * sin(gamma) | 1407 | sin(alpha) * sin(beta) | 1408 1409 The unit Dz vector is 1410 1411 | -sin(beta) * cos(gamma) | 1412 Dz = | sin(beta) * sin(gamma) | 1413 | cos(beta) | 1414 1415 """ 1416 1417 # Spheroid. 1418 if self.relax.data.diff[self.run].type == 'spheroid': 1419 # Initialise. 1420 Dpar = zeros(3, Float64) 1421 1422 # Trig. 1423 sin_theta = sin(self.relax.data.diff[self.run].theta) 1424 cos_theta = cos(self.relax.data.diff[self.run].theta) 1425 sin_phi = sin(self.relax.data.diff[self.run].phi) 1426 cos_phi = cos(self.relax.data.diff[self.run].phi) 1427 1428 # Unit Dpar axis. 1429 Dpar[0] = sin_theta * cos_phi 1430 Dpar[1] = sin_theta * sin_phi 1431 Dpar[2] = cos_theta 1432 1433 # Return the vector. 1434 return Dpar 1435 1436 # Ellipsoid. 1437 if self.relax.data.diff[self.run].type == 'ellipsoid': 1438 # Initialise. 1439 Dx = zeros(3, Float64) 1440 Dy = zeros(3, Float64) 1441 Dz = zeros(3, Float64) 1442 1443 # Trig. 1444 sin_alpha = sin(self.relax.data.diff[self.run].alpha) 1445 cos_alpha = cos(self.relax.data.diff[self.run].alpha) 1446 sin_beta = sin(self.relax.data.diff[self.run].beta) 1447 cos_beta = cos(self.relax.data.diff[self.run].beta) 1448 sin_gamma = sin(self.relax.data.diff[self.run].gamma) 1449 cos_gamma = cos(self.relax.data.diff[self.run].gamma) 1450 1451 # Unit Dx axis. 1452 Dx[0] = -sin_alpha * sin_gamma + cos_alpha * cos_beta * cos_gamma 1453 Dx[1] = -sin_alpha * cos_gamma - cos_alpha * cos_beta * sin_gamma 1454 Dx[2] = cos_alpha * sin_beta 1455 1456 # Unit Dy axis. 1457 Dx[0] = cos_alpha * sin_gamma + sin_alpha * cos_beta * cos_gamma 1458 Dx[1] = cos_alpha * cos_gamma - sin_alpha * cos_beta * sin_gamma 1459 Dx[2] = sin_alpha * sin_beta 1460 1461 # Unit Dz axis. 1462 Dx[0] = -sin_beta * cos_gamma 1463 Dx[1] = sin_beta * sin_gamma 1464 Dx[2] = cos_beta 1465 1466 # Return the vectors. 1467 return Dx, Dy, Dz
1468