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