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

Source Code for Module maths_fns.pcs

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008, 2010 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 calculation of pseudocontact shifts.""" 
 25   
 26  # Python imports. 
 27  from numpy import dot, sum 
 28   
 29   
30 -def ave_pcs_tensor(dj, vect, N, A, weights=None):
31 """Calculate the ensemble average PCS, using the 3D tensor. 32 33 This function calculates the average PCS for a set of XH bond vectors from a structural ensemble, using the 3D tensorial form of the alignment tensor. The formula for this ensemble average PCS value is:: 34 35 _N_ 36 \ T 37 <delta_ij(theta)> = > pc . djc . mu_jc . Ai . mu_jc, 38 /__ 39 c=1 40 41 where: 42 - i is the alignment tensor index, 43 - j is the index over spins, 44 - c is the index over the states or multiple structures, 45 - N is the total number of states or structures, 46 - theta is the parameter vector, 47 - djc is the PCS constant for spin j and state c, 48 - pc is the population probability or weight associated with state c (equally weighted to 1/N if weights are not provided), 49 - mu_jc is the unit vector corresponding to spin j and state c, 50 - Ai is the alignment tensor. 51 52 The PCS constant is defined as:: 53 54 mu0 15kT 1 55 dj = --- ----- ---- , 56 4pi Bo**2 r**3 57 58 where: 59 - mu0 is the permeability of free space, 60 - k is Boltzmann's constant, 61 - T is the absolute temperature, 62 - Bo is the magnetic field strength, 63 - r is the distance between the paramagnetic centre (electron spin) and the nuclear spin. 64 65 66 @param dj: The PCS constants for each structure c for spin j. This should be an array with indices corresponding to c. 67 @type dj: numpy rank-1 array 68 @param vect: The electron-nuclear unit vector matrix. The first dimension corresponds to the structural index, the second dimension is the coordinates of the unit vector. The vectors should be parallel to the vector connecting the paramagnetic centre to the nuclear spin. 69 @type vect: numpy matrix 70 @param N: The total number of structures. 71 @type N: int 72 @param A: The alignment tensor. 73 @type A: numpy rank-2 3D tensor 74 @param weights: The weights for each member of the ensemble (the last member need not be supplied). 75 @type weights: numpy rank-1 array 76 @return: The average PCS value. 77 @rtype: float 78 """ 79 80 # Initial back-calculated PCS value. 81 val = 0.0 82 83 # No weights given. 84 if weights == None: 85 pc = 1.0 / N 86 weights = [pc] * N 87 88 # Missing last weight. 89 if len(weights) < N: 90 pN = 1.0 - sum(weights, axis=0) 91 weights = weights.tolist() 92 weights.append(pN) 93 94 # Back-calculate the PCS. 95 for c in xrange(N): 96 val = val + weights[c] * dj[c] * dot(vect[c], dot(A, vect[c])) 97 98 # Return the average PCS. 99 return val
100 101
102 -def ave_pcs_tensor_ddeltaij_dAmn(dj, vect, N, dAi_dAmn, weights=None):
103 """Calculate the ensemble average PCS gradient element for Amn, using the 3D tensor. 104 105 This function calculates the average PCS gradient for a set of electron-nuclear spin unit vectors (paramagnetic to the nuclear spin) from a structural ensemble, using the 3D tensorial form of the alignment tensor. The formula for this ensemble average PCS gradient element is:: 106 107 _N_ 108 ddelta_ij(theta) \ T dAi 109 ---------------- = > pc . djc . mu_jc . ---- . mu_jc, 110 dAmn /__ dAmn 111 c=1 112 113 where: 114 - i is the alignment tensor index, 115 - j is the index over spins, 116 - m, the index over the first dimension of the alignment tensor m = {x, y, z}. 117 - n, the index over the second dimension of the alignment tensor n = {x, y, z}, 118 - c is the index over the states or multiple structures, 119 - theta is the parameter vector, 120 - Amn is the matrix element of the alignment tensor, 121 - djc is the PCS constant for spin j and state c, 122 - N is the total number of states or structures, 123 - pc is the population probability or weight associated with state c (equally weighted to 1/N if weights are not provided), 124 - mu_jc is the unit vector corresponding to spin j and state c, 125 - dAi/dAmn is the partial derivative of the alignment tensor with respect to element Amn. 126 127 128 @param dj: The PCS constants for each structure c for spin j. This should be an array with indices corresponding to c. 129 @type dj: numpy rank-1 array 130 @param vect: The electron-nuclear unit vector matrix. The first dimension corresponds to the structural index, the second dimension is the coordinates of the unit vector. The vectors should be parallel to the vector connecting the paramagnetic centre to the nuclear spin. 131 @type vect: numpy matrix 132 @param N: The total number of structures. 133 @type N: int 134 @param dAi_dAmn: The alignment tensor derivative with respect to parameter Amn. 135 @type dAi_dAmn: numpy rank-2 3D tensor 136 @param weights: The weights for each member of the ensemble (the last member need not be supplied). 137 @type weights: numpy rank-1 array 138 @return: The average PCS gradient element. 139 @rtype: float 140 """ 141 142 # Initial back-calculated PCS gradient. 143 grad = 0.0 144 145 # No weights given. 146 if weights == None: 147 pc = 1.0 / N 148 weights = [pc] * N 149 150 # Missing last weight. 151 if len(weights) < N: 152 pN = 1.0 - sum(weights, axis=0) 153 weights = weights.tolist() 154 weights.append(pN) 155 156 # Back-calculate the PCS gradient element. 157 for c in xrange(N): 158 grad = grad + weights[c] * dj[c] * dot(vect[c], dot(dAi_dAmn, vect[c])) 159 160 # Return the average PCS gradient element. 161 return grad
162 163
164 -def pcs_tensor(dj, mu, A):
165 """Calculate the PCS, using the 3D alignment tensor. 166 167 The PCS value is:: 168 169 T 170 delta_ij(theta) = dj . mu_j . Ai . mu_j, 171 172 where: 173 - i is the alignment tensor index, 174 - j is the index over spins, 175 - theta is the parameter vector, 176 - dj is the PCS constant for spin j, 177 - mu_j i the unit vector corresponding to spin j, 178 - Ai is the alignment tensor. 179 180 The PCS constant is defined as:: 181 182 mu0 15kT 1 183 dj = --- ----- ---- , 184 4pi Bo**2 r**3 185 186 where: 187 - mu0 is the permeability of free space, 188 - k is Boltzmann's constant, 189 - T is the absolute temperature, 190 - Bo is the magnetic field strength, 191 - r is the distance between the paramagnetic centre (electron spin) and the nuclear spin. 192 193 194 @param dj: The PCS constant for spin j. 195 @type dj: float 196 @param mu: The unit vector connecting the electron and nuclear spins. 197 @type mu: numpy rank-1 3D array 198 @param A: The alignment tensor. 199 @type A: numpy rank-2 3D tensor 200 @return: The PCS value. 201 @rtype: float 202 """ 203 204 # Return the PCS. 205 return dj * dot(mu, dot(A, mu))
206