Package lib :: Package structure :: Package represent :: Module diffusion_tensor
[hide private]
[frames] | no frames]

Source Code for Module lib.structure.represent.diffusion_tensor

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003-2010,2012-2014 Edward d'Auvergne                         # 
  4  # Copyright (C) 2008 Sebastien Morin                                          # 
  5  #                                                                             # 
  6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  7  #                                                                             # 
  8  # This program is free software: you can redistribute it and/or modify        # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation, either version 3 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # This program is distributed in the hope that it will be useful,             # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Python module imports. 
 24  from numpy import array, dot, float64, transpose 
 25   
 26  # relax module imports. 
 27  from lib.structure.geometric import generate_vector_dist, generate_vector_residues 
 28   
 29   
30 -def diffusion_tensor(mol=None, tensor=None, tensor_diag=None, diff_type=None, rotation=None, axes=None, sim_axes=None, com=None, scale=1.8e-6):
31 """Create the structural representation of the diffusion tensor. 32 33 @keyword mol: The molecule container. 34 @type mol: MolContainer instance 35 @keyword tensor: The diffusion tensor. 36 @type tensor: numpy rank-2, 3D array 37 @keyword tensor_diag: The diagonalised diffusion tensor in tensor frame. 38 @type tensor_diag: numpy rank-2, 3D array 39 @keyword diff_type: The type of diffusion tensor. This can be one of 'sphere', 'oblate', 'prolate', 'ellipsoid'. 40 @type diff_type: str 41 @keyword rotation: The diffusion tensor rotation matrix. 42 @type rotation: numpy rank-2, 3D array 43 @keyword axes: The axis system of the tensor. For the spheroids this is one vector, for the ellipsoid it should be three vectors. 44 @type axes: list of numpy rank-1, 3D arrays 45 @keyword sim_axes: The axis systems of the tensor for each simulation. For the spheroids this is one vector, for the ellipsoid it should be three vectors. The first dimension is the axis type (x, y, or z), the second is the simulation, and the third is the vector. 46 @type sim_axes: None or list of lists of numpy rank-1, 3D arrays 47 @keyword com: The centre of mass of the diffusion structure. 48 @type com: numpy rank-1, 3D array 49 @keyword scale: The scaling factor for the diffusion tensor. 50 @type scale: float 51 """ 52 53 # Initialise. 54 ############# 55 56 # Initialise the residue number. 57 res_num = 1 58 59 # Add the central atom. 60 mol.atom_add(pdb_record='HETATM', atom_num=1, atom_name='R', res_name='COM', res_num=res_num, pos=com, segment_id=None, element='C') 61 62 # Increment the residue number. 63 res_num = res_num + 1 64 65 66 # Vector distribution. 67 ###################### 68 69 # Print out. 70 print("\nGenerating the geometric object.") 71 72 # Swap the x and y axes for the prolate spheroid (the vector distributions are centred on the z-axis). 73 if diff_type == 'prolate': 74 # 90 deg rotation about the diffusion frame z-axis. 75 z_rot = array([[ 0, -1, 0], 76 [ 1, 0, 0], 77 [ 0, 0, 1]], float64) 78 79 # Rotate the tensor and rotation matrix. 80 rotation = dot(transpose(rotation), z_rot) 81 tensor = dot(z_rot, dot(tensor_diag, transpose(z_rot))) 82 tensor = dot(rotation, dot(tensor, transpose(rotation))) 83 84 # Swap the x and z axes for the oblate spheroid (the vector distributions are centred on the z-axis). 85 if diff_type == 'oblate': 86 # 90 deg rotation about the diffusion frame y-axis. 87 y_rot = array([[ 0, 0, 1], 88 [ 0, 1, 0], 89 [ -1, 0, 0]], float64) 90 91 # Rotate the tensor and rotation matrix. 92 rotation = dot(transpose(rotation), y_rot) 93 tensor = dot(y_rot, dot(tensor_diag, transpose(y_rot))) 94 tensor = dot(rotation, dot(tensor, transpose(rotation))) 95 96 # The distribution. 97 generate_vector_dist(mol=mol, res_name='TNS', res_num=res_num, centre=com, R=rotation, warp=tensor, scale=scale, inc=20) 98 99 # Increment the residue number. 100 res_num = res_num + 1 101 102 103 # Axes of the tensor. 104 ##################### 105 106 # Create the unique axis of the spheroid. 107 if diff_type in ['oblate', 'prolate']: 108 # Print out. 109 print("\nGenerating the unique axis of the diffusion tensor.") 110 print(" Scaling factor: " + repr(scale)) 111 112 # Generate the axes representation. 113 res_num = generate_vector_residues(mol=mol, vector=axes[0], atom_name='Dpar', res_name_vect='AXS', sim_vectors=sim_axes[0], res_num=res_num, origin=com, scale=scale, neg=True) 114 115 116 # Create the three axes of the ellipsoid. 117 if diff_type == 'ellipsoid': 118 # Print out. 119 print("Generating the three axes of the ellipsoid.") 120 print(" Scaling factor: " + repr(scale)) 121 122 # Generate the axes representation. 123 res_num = generate_vector_residues(mol=mol, vector=axes[0], atom_name='Dx', res_name_vect='AXS', sim_vectors=sim_axes[0], res_num=res_num, origin=com, scale=scale, neg=True) 124 res_num = generate_vector_residues(mol=mol, vector=axes[1], atom_name='Dy', res_name_vect='AXS', sim_vectors=sim_axes[1], res_num=res_num, origin=com, scale=scale, neg=True) 125 res_num = generate_vector_residues(mol=mol, vector=axes[2], atom_name='Dz', res_name_vect='AXS', sim_vectors=sim_axes[2], res_num=res_num, origin=com, scale=scale, neg=True)
126