Package lib :: Package frame_order :: Module iso_cone_torsionless
[hide private]
[frames] | no frames]

Source Code for Module lib.frame_order.iso_cone_torsionless

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009-2012,2014 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 handling of Frame Order.""" 
 24   
 25  # Python module imports. 
 26  from math import cos, pi 
 27  from numpy import divide, dot, eye, float64, multiply, swapaxes, tensordot 
 28  try: 
 29      from scipy.integrate import dblquad 
 30  except ImportError: 
 31      pass 
 32   
 33  # relax module imports. 
 34  from lib.frame_order.matrix_ops import pcs_pivot_motion_torsionless_qr_int, pcs_pivot_motion_torsionless_quad_int, rotate_daeg 
 35   
 36   
37 -def compile_1st_matrix_iso_cone_torsionless(matrix, R_eigen, cone_theta):
38 """Generate the 1st degree Frame Order matrix for the torsionless isotropic cone. 39 40 @param matrix: The Frame Order matrix, 1st degree to be populated. 41 @type matrix: numpy 3D, rank-2 array 42 @param R_eigen: The eigenframe rotation matrix. 43 @type R_eigen: numpy 3D, rank-2 array 44 @param cone_theta: The cone opening angle. 45 @type cone_theta: float 46 """ 47 48 # Zeros. 49 matrix[:] = 0.0 50 51 # Pre-calculate trig values. 52 cos_theta = cos(cone_theta) 53 54 # Diagonal values. 55 matrix[0, 0] = cos_theta + 3.0 56 matrix[1, 1] = matrix[0, 0] 57 matrix[2, 2] = 2.0*cos_theta + 2.0 58 59 # Rotate and return the frame order matrix. 60 return 0.25 * rotate_daeg(matrix, R_eigen)
61 62
63 -def compile_2nd_matrix_iso_cone_torsionless(matrix, Rx2_eigen, cone_theta):
64 """Generate the rotated 2nd degree Frame Order matrix for the torsionless isotropic cone. 65 66 The cone axis is assumed to be parallel to the z-axis in the eigenframe. 67 68 69 @param matrix: The Frame Order matrix, 2nd degree to be populated. 70 @type matrix: numpy 9D, rank-2 array 71 @param Rx2_eigen: The Kronecker product of the eigenframe rotation matrix with itself. 72 @type Rx2_eigen: numpy 9D, rank-2 array 73 @param cone_theta: The cone opening angle. 74 @type cone_theta: float 75 """ 76 77 # Zeros. 78 matrix[:] = 0.0 79 80 # Repetitive trig calculations. 81 cos_tmax = cos(cone_theta) 82 cos_tmax2 = cos_tmax**2 83 84 # Diagonal. 85 matrix[0, 0] = (3.0*cos_tmax2 + 6.0*cos_tmax + 15.0) / 24.0 86 matrix[1, 1] = (cos_tmax2 + 10.0*cos_tmax + 13.0) / 24.0 87 matrix[2, 2] = (4.0*cos_tmax2 + 10.0*cos_tmax + 10.0) / 24.0 88 matrix[3, 3] = matrix[1, 1] 89 matrix[4, 4] = matrix[0, 0] 90 matrix[5, 5] = matrix[2, 2] 91 matrix[6, 6] = matrix[2, 2] 92 matrix[7, 7] = matrix[2, 2] 93 matrix[8, 8] = (cos_tmax2 + cos_tmax + 1.0) / 3.0 94 95 # Off diagonal set 1. 96 matrix[0, 4] = matrix[4, 0] = (cos_tmax2 - 2.0*cos_tmax + 1.0) / 24.0 97 matrix[0, 8] = matrix[8, 0] = -(cos_tmax2 + cos_tmax - 2.0) / 6.0 98 matrix[4, 8] = matrix[8, 4] = matrix[0, 8] 99 100 # Off diagonal set 2. 101 matrix[1, 3] = matrix[3, 1] = matrix[0, 4] 102 matrix[2, 6] = matrix[6, 2] = -matrix[0, 8] 103 matrix[5, 7] = matrix[7, 5] = -matrix[0, 8] 104 105 # Rotate and return the frame order matrix. 106 return rotate_daeg(matrix, Rx2_eigen)
107 108
109 -def pcs_numeric_qr_int_iso_cone_torsionless(points=None, max_points=None, theta_max=None, c=None, full_in_ref_frame=None, r_pivot_atom=None, r_pivot_atom_rev=None, r_ln_pivot=None, A=None, R_eigen=None, RT_eigen=None, Ri_prime=None, pcs_theta=None, pcs_theta_err=None, missing_pcs=None):
110 """Determine the averaged PCS value via numerical integration. 111 112 @keyword points: The Sobol points in the torsion-tilt angle space. 113 @type points: numpy rank-2, 3D array 114 @keyword max_points: The maximum number of Sobol' points to use. Once this number is reached, the loop over the Sobol' torsion-tilt angles is terminated. 115 @type max_points: int 116 @keyword theta_max: The half cone angle. 117 @type theta_max: float 118 @keyword c: The PCS constant (without the interatomic distance and in Angstrom units). 119 @type c: numpy rank-1 array 120 @keyword full_in_ref_frame: An array of flags specifying if the tensor in the reference frame is the full or reduced tensor. 121 @type full_in_ref_frame: numpy rank-1 array 122 @keyword r_pivot_atom: The pivot point to atom vector. 123 @type r_pivot_atom: numpy rank-2, 3D array 124 @keyword r_pivot_atom_rev: The reversed pivot point to atom vector. 125 @type r_pivot_atom_rev: numpy rank-2, 3D array 126 @keyword r_ln_pivot: The lanthanide position to pivot point vector. 127 @type r_ln_pivot: numpy rank-2, 3D array 128 @keyword A: The full alignment tensor of the non-moving domain. 129 @type A: numpy rank-2, 3D array 130 @keyword R_eigen: The eigenframe rotation matrix. 131 @type R_eigen: numpy rank-2, 3D array 132 @keyword RT_eigen: The transpose of the eigenframe rotation matrix (for faster calculations). 133 @type RT_eigen: numpy rank-2, 3D array 134 @keyword Ri_prime: The array of pre-calculated rotation matrices for the in-frame torsionless isotropic cone motion, used to calculate the PCS for each state i in the numerical integration. 135 @type Ri_prime: numpy rank-3, array of 3D arrays 136 @keyword pcs_theta: The storage structure for the back-calculated PCS values. 137 @type pcs_theta: numpy rank-2 array 138 @keyword pcs_theta_err: The storage structure for the back-calculated PCS errors. 139 @type pcs_theta_err: numpy rank-2 array 140 @keyword missing_pcs: A structure used to indicate which PCS values are missing. 141 @type missing_pcs: numpy rank-2 array 142 """ 143 144 # Clear the data structures. 145 pcs_theta[:] = 0.0 146 pcs_theta_err[:] = 0.0 147 148 # Fast frame shift. 149 Ri = dot(R_eigen, tensordot(Ri_prime, RT_eigen, axes=1)) 150 Ri = swapaxes(Ri, 0, 1) 151 152 # Unpack the points. 153 theta, phi = points 154 155 # Loop over the samples. 156 num = 0 157 for i in range(len(points[0])): 158 # The maximum number of points has been reached (well, surpassed by one so exit the loop before it is used). 159 if num == max_points: 160 break 161 162 # Outside of the distribution, so skip the point. 163 if theta[i] > theta_max: 164 continue 165 166 # Calculate the PCSs for this state. 167 pcs_pivot_motion_torsionless_qr_int(full_in_ref_frame=full_in_ref_frame, r_pivot_atom=r_pivot_atom, r_pivot_atom_rev=r_pivot_atom_rev, r_ln_pivot=r_ln_pivot, A=A, Ri=Ri[i], pcs_theta=pcs_theta, pcs_theta_err=pcs_theta_err, missing_pcs=missing_pcs) 168 169 # Increment the number of points. 170 num += 1 171 172 # Default to the rigid state if no points lie in the distribution. 173 if num == 0: 174 # Fast identity frame shift. 175 Ri_prime = eye(3, dtype=float64) 176 Ri = dot(R_eigen, tensordot(Ri_prime, RT_eigen, axes=1)) 177 Ri = swapaxes(Ri, 0, 1) 178 179 # Calculate the PCSs for this state. 180 pcs_pivot_motion_torsionless_qr_int(full_in_ref_frame=full_in_ref_frame, r_pivot_atom=r_pivot_atom, r_pivot_atom_rev=r_pivot_atom_rev, r_ln_pivot=r_ln_pivot, A=A, Ri=Ri, pcs_theta=pcs_theta, pcs_theta_err=pcs_theta_err, missing_pcs=missing_pcs) 181 182 # Multiply the constant. 183 multiply(c, pcs_theta, pcs_theta) 184 185 # Average the PCS. 186 else: 187 multiply(c, pcs_theta, pcs_theta) 188 divide(pcs_theta, float(num), pcs_theta)
189 190
191 -def pcs_numeric_quad_int_iso_cone_torsionless(theta_max=None, c=None, r_pivot_atom=None, r_ln_pivot=None, A=None, R_eigen=None, RT_eigen=None, Ri_prime=None):
192 """Determine the averaged PCS value via numerical integration. 193 194 @keyword theta_max: The half cone angle. 195 @type theta_max: float 196 @keyword c: The PCS constant (without the interatomic distance and in Angstrom units). 197 @type c: float 198 @keyword r_pivot_atom: The pivot point to atom vector. 199 @type r_pivot_atom: numpy rank-1, 3D array 200 @keyword r_ln_pivot: The lanthanide position to pivot point vector. 201 @type r_ln_pivot: numpy rank-1, 3D array 202 @keyword A: The full alignment tensor of the non-moving domain. 203 @type A: numpy rank-2, 3D array 204 @keyword R_eigen: The eigenframe rotation matrix. 205 @type R_eigen: numpy rank-2, 3D array 206 @keyword RT_eigen: The transpose of the eigenframe rotation matrix (for faster calculations). 207 @type RT_eigen: numpy rank-2, 3D array 208 @keyword Ri_prime: The empty rotation matrix for the in-frame isotropic cone motion, used to calculate the PCS for each state i in the numerical integration. 209 @type Ri_prime: numpy rank-2, 3D array 210 @return: The averaged PCS value. 211 @rtype: float 212 """ 213 214 # Perform numerical integration. 215 result = dblquad(pcs_pivot_motion_torsionless_quad_int, -pi, pi, lambda phi: 0.0, lambda phi: theta_max, args=(r_pivot_atom, r_ln_pivot, A, R_eigen, RT_eigen, Ri_prime)) 216 217 # The surface area normalisation factor. 218 SA = 2.0 * pi * (1.0 - cos(theta_max)) 219 220 # Return the value. 221 return c * result[0] / SA
222