Package lib :: Package alignment :: Module alignment_tensor
[hide private]
[frames] | no frames]

Source Code for Module lib.alignment.alignment_tensor

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008,2013 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  """Module for the manipulation of alignment tensors.""" 
 24   
 25  # Python imports. 
 26  from math import pi 
 27  from numpy.linalg import eigvals 
 28   
 29  # relax module imports. 
 30  from lib.periodic_table import periodic_table 
 31  from lib.physical_constants import h_bar, kB, mu0 
 32   
 33   
34 -def calc_chi_tensor(A, B0, T):
35 """Convert the alignment tensor into the magnetic susceptibility (chi) tensor. 36 37 A can be either the full tensor (3D or 5D), a component Aij of the tensor, Aa, or Ar, anything that can be multiplied by the constants to convert from one to the other. 38 39 40 @param A: The alignment tensor or alignment tensor component. 41 @type A: numpy array or float 42 @param B0: The magnetic field strength in Hz. 43 @type B0: float 44 @param T: The temperature in Kalvin. 45 @type T: float 46 @return: A multiplied by the PCS constant. 47 @rtype: numpy array or float 48 """ 49 50 # B0 in Tesla. 51 B0 = 2.0 * pi * B0 / periodic_table.gyromagnetic_ratio('1H') 52 53 # The conversion factor. 54 conv = 15.0 * mu0 * kB * T / B0**2 55 56 # Return the converted value. 57 return conv * A
58 59
60 -def dAi_dAxx(A):
61 """The dAi/dAxx gradient. 62 63 This function will modify the A matrix to be equal to:: 64 65 dAi | 1 0 0 | 66 ---- = | 0 0 0 | 67 dAxx | 0 0 -1 | 68 69 70 @param A: The alignment tensor object. 71 @type A: numpy rank-2 3D tensor 72 """ 73 74 # Set all elements. 75 A[0, 0] = 1.0; A[0, 1] = 0.0; A[0, 2] = 0.0 76 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 0.0 77 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = -1.0
78 79
80 -def dAi_dAyy(A):
81 """The dAi/dAyy gradient. 82 83 This function will modify the A matrix to be equal to:: 84 85 dAi | 0 0 0 | 86 ---- = | 0 1 0 | 87 dAyy | 0 0 -1 | 88 89 90 @param A: The alignment tensor object. 91 @type A: numpy rank-2 3D tensor 92 """ 93 94 # Set all elements. 95 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 0.0 96 A[1, 0] = 0.0; A[1, 1] = 1.0; A[1, 2] = 0.0 97 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = -1.0
98 99
100 -def dAi_dAxy(A):
101 """The dAi/dAxy gradient. 102 103 This function will modify the A matrix to be equal to:: 104 105 dAi | 0 1 0 | 106 ---- = | 1 0 0 | 107 dAxy | 0 0 0 | 108 109 110 @param A: The alignment tensor object. 111 @type A: numpy rank-2 3D tensor 112 """ 113 114 # Set all elements. 115 A[0, 0] = 0.0; A[0, 1] = 1.0; A[0, 2] = 0.0 116 A[1, 0] = 1.0; A[1, 1] = 0.0; A[1, 2] = 0.0 117 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = 0.0
118 119
120 -def dAi_dAxz(A):
121 """The dAi/dAxz gradient. 122 123 This function will modify the A matrix to be equal to:: 124 125 dAi | 0 0 1 | 126 ---- = | 0 0 0 | 127 dAxz | 1 0 0 | 128 129 130 @param A: The alignment tensor object. 131 @type A: numpy rank-2 3D tensor 132 """ 133 134 # Set all elements. 135 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 1.0 136 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 0.0 137 A[2, 0] = 1.0; A[2, 1] = 0.0; A[2, 2] = 0.0
138 139
140 -def dAi_dAyz(A):
141 """The dAi/dAyz gradient. 142 143 This function will modify the A matrix to be equal to:: 144 145 dAi | 0 0 0 | 146 ---- = | 0 0 1 | 147 dAyz | 0 1 0 | 148 149 150 @param A: The alignment tensor object. 151 @type A: numpy rank-2 3D tensor 152 """ 153 154 # Set all elements. 155 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 0.0 156 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 1.0 157 A[2, 0] = 0.0; A[2, 1] = 1.0; A[2, 2] = 0.0
158 159
160 -def kappa(nuc1='15N', nuc2='1H'):
161 """Function for calculating the kappa constant. 162 163 The kappa constant is:: 164 165 kappa = -3/(8pi^2).gI.gS.mu0.h_bar, 166 167 where gI and gS are the gyromagnetic ratios of the I and S spins, mu0 is the permeability of 168 free space, and h_bar is Planck's constant divided by 2pi. 169 170 @param nuc1: The first nucleus type. 171 @type nuc1: str 172 @param nuc2: The first nucleus type. 173 @type nuc2: str 174 @return: The kappa constant value. 175 @rtype: float 176 """ 177 178 # Gyromagnetic ratios. 179 gI = periodic_table.gyromagnetic_ratio(nuc1) 180 gS = periodic_table.gyromagnetic_ratio(nuc2) 181 182 # Kappa. 183 return -3.0/(8.0*pi**2) * gI * gS * mu0 * h_bar
184 185
186 -def maxA(tensor):
187 """Find the maximal alignment - the Azz component in the alignment frame. 188 189 @param tensor: The alignment tensor object. 190 @type tensor: numpy rank-2 3D tensor 191 @return: The Azz component in the alignment frame. 192 """ 193 194 # Return the value. 195 return max(abs(eigvals(tensor)))
196 197
198 -def to_5D(vector_5D, tensor):
199 """Convert the rank-2 3D alignment tensor matrix to the 5D vector format. 200 201 @param vector_5D: The 5D vector object to populate. The vector format is {Axx, Ayy, Axy, Axz, 202 Ayz}. 203 @type vector_5D: numpy 5D vector 204 @param tensor: The alignment tensor object. 205 @type tensor: numpy rank-2 3D tensor 206 """ 207 208 # Convert the matrix form to the vector form. 209 vector_5D[0] = tensor[0, 0] 210 vector_5D[1] = tensor[1, 1] 211 vector_5D[2] = tensor[0, 1] 212 vector_5D[3] = tensor[0, 2] 213 vector_5D[4] = tensor[1, 2]
214 215
216 -def to_tensor(tensor, vector_5D):
217 """Convert the 5D vector alignment tensor form to the rank-2 3D matrix from. 218 219 @param tensor: The alignment tensor object, in matrix format, to populate. 220 @type tensor: numpy rank-2 3D tensor 221 @param vector_5D: The 5D vector object. The vector format is {Axx, Ayy, Axy, Axz, Ayz}. 222 @type vector_5D: numpy 5D vector 223 """ 224 225 # Convert the vector form to the matrix form. 226 tensor[0, 0] = vector_5D[0] 227 tensor[0, 1] = vector_5D[2] 228 tensor[0, 2] = vector_5D[3] 229 tensor[1, 0] = vector_5D[2] 230 tensor[1, 1] = vector_5D[1] 231 tensor[1, 2] = vector_5D[4] 232 tensor[2, 0] = vector_5D[3] 233 tensor[2, 1] = vector_5D[4] 234 tensor[2, 2] = -vector_5D[0] -vector_5D[1]
235