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