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

Source Code for Module lib.frame_order.conversions

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 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  """Functions for creating or calculating the rotor axis for the frame order models.""" 
 24   
 25  # Python module imports. 
 26  from numpy import array, cross, dot, float64, zeros 
 27  from numpy.linalg import norm 
 28   
 29  # relax module imports. 
 30  from lib.geometry.coord_transform import cartesian_to_spherical, spherical_to_cartesian 
 31  from lib.geometry.rotations import axis_angle_to_R, euler_to_R_zyz 
 32   
 33  # Module variables. 
 34  R = zeros((3, 3), float64)    # A rotation matrix. 
 35  Z_AXIS = array([0, 0, 1], float64) 
 36   
 37   
38 -def convert_axis_alpha_to_spherical(alpha=None, pivot=None, point=None):
39 """Convert the axis alpha angle to spherical angles theta and phi. 40 41 @keyword alpha: The axis alpha angle, defined as the angle between a vector perpendicular to the pivot-CoM vector in the xy-plane and the rotor axis. 42 @type alpha: float 43 @keyword pivot: The pivot point on the rotation axis. 44 @type pivot: numpy rank-1 3D array 45 @keyword point: The reference point in space. 46 @type point: numpy rank-1 3D array 47 @return: The theta and phi spherical angles. 48 @rtype: float, float 49 """ 50 51 # Create the axis. 52 axis = create_rotor_axis_alpha(alpha=alpha, pivot=pivot, point=point) 53 54 # Coordinate system transform. 55 r, theta, phi = cartesian_to_spherical(axis) 56 57 # Return the angles. 58 return theta, phi
59 60
61 -def create_rotor_axis_alpha(alpha=None, pivot=None, point=None):
62 """Create the rotor axis from the axis alpha angle. 63 64 @keyword alpha: The axis alpha angle, defined as the angle between a vector perpendicular to the pivot-CoM vector in the xy-plane and the rotor axis. 65 @type alpha: float 66 @keyword pivot: The pivot point on the rotation axis. 67 @type pivot: numpy rank-1 3D array 68 @keyword point: The reference point in space. 69 @type point: numpy rank-1 3D array 70 @return: The rotor axis as a unit vector. 71 @rtype: numpy rank-1 3D float64 array 72 """ 73 74 # The CoM-pivot unit vector - the norm of the system (the pivot is defined as the point on the axis closest to the point). 75 n = point - pivot 76 n /= norm(n) 77 78 # The vector perpendicular to the CoM-pivot vector and in the xy plane. 79 mu_xy = cross(Z_AXIS, n) 80 mu_xy /= norm(mu_xy) 81 82 # Rotate the vector about the CoM-pivot axis by the angle alpha. 83 axis_angle_to_R(n, alpha, R) 84 axis = dot(R, mu_xy) 85 86 # Return the new axis. 87 return axis
88 89
90 -def create_rotor_axis_euler(alpha=None, beta=None, gamma=None):
91 """Create the rotor axis from the Euler angles. 92 93 @keyword alpha: The alpha Euler angle in the zyz notation. 94 @type alpha: float 95 @keyword beta: The beta Euler angle in the zyz notation. 96 @type beta: float 97 @keyword gamma: The gamma Euler angle in the zyz notation. 98 @type gamma: float 99 @return: The rotor axis as a unit vector. 100 @rtype: numpy rank-1 3D float64 array 101 """ 102 103 # Initialise the 3D frame. 104 frame = zeros((3, 3), float64) 105 106 # Euler angle to rotation matrix conversion. 107 euler_to_R_zyz(alpha, beta, gamma, frame) 108 109 # Return the z-axis component. 110 return frame[:, 2]
111 112
113 -def create_rotor_axis_spherical(theta=None, phi=None):
114 """Create the rotor axis from the spherical coordinates. 115 116 @keyword theta: The polar spherical angle. 117 @type theta: float 118 @keyword phi: The azimuthal spherical angle. 119 @type phi: float 120 @return: The rotor axis as a unit vector. 121 @rtype: numpy rank-1 3D float64 array 122 """ 123 124 # Initialise the axis. 125 axis = zeros(3, float64) 126 127 # Parameter conversion. 128 spherical_to_cartesian([1.0, theta, phi], axis) 129 130 # Return the new axis. 131 return axis
132