Package maths_fns :: Module alignment_tensor
[hide private]
[frames] | no frames]

Source Code for Module maths_fns.alignment_tensor

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008 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 numpy.linalg import eigvals 
 27   
 28   
29 -def dAi_dAxx(A):
30 """The dAi/dAxx gradient. 31 32 This function will modify the A matrix to be equal to:: 33 34 dAi | 1 0 0 | 35 ---- = | 0 0 0 | 36 dAxx | 0 0 -1 | 37 38 39 @param A: The alignment tensor object. 40 @type A: numpy rank-2 3D tensor 41 """ 42 43 # Set all elements. 44 A[0, 0] = 1.0; A[0, 1] = 0.0; A[0, 2] = 0.0 45 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 0.0 46 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = -1.0
47 48
49 -def dAi_dAyy(A):
50 """The dAi/dAyy gradient. 51 52 This function will modify the A matrix to be equal to:: 53 54 dAi | 0 0 0 | 55 ---- = | 0 1 0 | 56 dAyy | 0 0 -1 | 57 58 59 @param A: The alignment tensor object. 60 @type A: numpy rank-2 3D tensor 61 """ 62 63 # Set all elements. 64 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 0.0 65 A[1, 0] = 0.0; A[1, 1] = 1.0; A[1, 2] = 0.0 66 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = -1.0
67 68
69 -def dAi_dAxy(A):
70 """The dAi/dAxy gradient. 71 72 This function will modify the A matrix to be equal to:: 73 74 dAi | 0 1 0 | 75 ---- = | 1 0 0 | 76 dAxy | 0 0 0 | 77 78 79 @param A: The alignment tensor object. 80 @type A: numpy rank-2 3D tensor 81 """ 82 83 # Set all elements. 84 A[0, 0] = 0.0; A[0, 1] = 1.0; A[0, 2] = 0.0 85 A[1, 0] = 1.0; A[1, 1] = 0.0; A[1, 2] = 0.0 86 A[2, 0] = 0.0; A[2, 1] = 0.0; A[2, 2] = 0.0
87 88
89 -def dAi_dAxz(A):
90 """The dAi/dAxz gradient. 91 92 This function will modify the A matrix to be equal to:: 93 94 dAi | 0 0 1 | 95 ---- = | 0 0 0 | 96 dAxz | 1 0 0 | 97 98 99 @param A: The alignment tensor object. 100 @type A: numpy rank-2 3D tensor 101 """ 102 103 # Set all elements. 104 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 1.0 105 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 0.0 106 A[2, 0] = 1.0; A[2, 1] = 0.0; A[2, 2] = 0.0
107 108
109 -def dAi_dAyz(A):
110 """The dAi/dAyz gradient. 111 112 This function will modify the A matrix to be equal to:: 113 114 dAi | 0 0 0 | 115 ---- = | 0 0 1 | 116 dAyz | 0 1 0 | 117 118 119 @param A: The alignment tensor object. 120 @type A: numpy rank-2 3D tensor 121 """ 122 123 # Set all elements. 124 A[0, 0] = 0.0; A[0, 1] = 0.0; A[0, 2] = 0.0 125 A[1, 0] = 0.0; A[1, 1] = 0.0; A[1, 2] = 1.0 126 A[2, 0] = 0.0; A[2, 1] = 1.0; A[2, 2] = 0.0
127 128
129 -def maxA(tensor):
130 """Find the maximal alignment - the Azz component in the alignment frame. 131 132 @param tensor: The alignment tensor object. 133 @type tensor: numpy rank-2 3D tensor 134 @return: The Azz component in the alignment frame. 135 """ 136 137 # Return the value. 138 return max(abs(eigvals(tensor)))
139 140
141 -def to_5D(vector_5D, tensor):
142 """Convert the rank-2 3D alignment tensor matrix to the 5D vector format. 143 144 @param vector_5D: The 5D vector object to populate. The vector format is {Axx, Ayy, Axy, Axz, 145 Ayz}. 146 @type vector_5D: numpy 5D vector 147 @param tensor: The alignment tensor object. 148 @type tensor: numpy rank-2 3D tensor 149 """ 150 151 # Convert the matrix form to the vector form. 152 vector_5D[0] = tensor[0, 0] 153 vector_5D[1] = tensor[1, 1] 154 vector_5D[2] = tensor[0, 1] 155 vector_5D[3] = tensor[0, 2] 156 vector_5D[4] = tensor[1, 2]
157 158
159 -def to_tensor(tensor, vector_5D):
160 """Convert the 5D vector alignment tensor form to the rank-2 3D matrix from. 161 162 @param tensor: The alignment tensor object, in matrix format, to populate. 163 @type tensor: numpy rank-2 3D tensor 164 @param vector_5D: The 5D vector object. The vector format is {Axx, Ayy, Axy, Axz, Ayz}. 165 @type vector_5D: numpy 5D vector 166 """ 167 168 # Convert the vector form to the matrix form. 169 tensor[0, 0] = vector_5D[0] 170 tensor[0, 1] = vector_5D[2] 171 tensor[0, 2] = vector_5D[3] 172 tensor[1, 0] = vector_5D[2] 173 tensor[1, 1] = vector_5D[1] 174 tensor[1, 2] = vector_5D[4] 175 tensor[2, 0] = vector_5D[3] 176 tensor[2, 1] = vector_5D[4] 177 tensor[2, 2] = -vector_5D[0] -vector_5D[1]
178