mailr5061 - in /branches/N_state_model: ./ generic_fns/structure.py maths_fns/rotation_matrix.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on February 21, 2008 - 09:07:
Author: bugman
Date: Thu Feb 21 09:07:46 2008
New Revision: 5061

URL: http://svn.gna.org/viewcvs/relax?rev=5061&view=rev
Log:
Merged revisions 5058-5060 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/1.3

........
  r5058 | bugman | 2008-02-20 18:23:52 +0100 (Wed, 20 Feb 2008) | 6 lines
  
  Renamed rotation_matrix_zyz() to R_euler_zyz().
  
  This name is more descriptive and is a better naming scheme for rotation 
matrices constructed using
  other inputs.
........
  r5059 | bugman | 2008-02-20 18:53:03 +0100 (Wed, 20 Feb 2008) | 7 lines
  
  Wrote a new function R_2vect() to generate a rotation matrix from 2 vectors.
  
  This rotation matrix is not unique because of axially symmetry allowing the 
rotation axis to be any
  vector within the symmetry plane, so the cross product with the axis-angle 
convention is used to
  define this matrix.
........
  r5060 | bugman | 2008-02-20 18:54:37 +0100 (Wed, 20 Feb 2008) | 6 lines
  
  Started writing the generic_fns.structure.cone_edge() function.
  
  This function generates a geometric shape constructed from atoms to be 
embedded into a PDB file,
  representing the outer edge of the cone.
........

Modified:
    branches/N_state_model/   (props changed)
    branches/N_state_model/generic_fns/structure.py
    branches/N_state_model/maths_fns/rotation_matrix.py

Propchange: branches/N_state_model/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: branches/N_state_model/generic_fns/structure.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/generic_fns/structure.py?rev=5061&r1=5060&r2=5061&view=diff
==============================================================================
--- branches/N_state_model/generic_fns/structure.py (original)
+++ branches/N_state_model/generic_fns/structure.py Thu Feb 21 09:07:46 2008
@@ -301,6 +301,53 @@
         return R,M
     else:
         return R
+
+
+def cone_edge(atomic_data=None, apex=None, axis=None, angle=None, 
length=None, inc=None):
+    """Add a residue to the atomic data representing a cone of the given 
angle.
+
+    A series of vectors totalling the number of increments and starting at 
the origin are equally
+    spaced around the cone axis.  The atoms representing neighbouring 
vectors will be directly
+    bonded together.  This will generate an object representing the outer 
edge of a cone.
+
+
+    @param atomic_data:     The dictionary to place the atomic data into.
+    @type atomic_data:      dict
+    @param apex:            The apex of the cone.
+    @type apex:             numpy array, len 3
+    @param axis:            The central axis of the cone.
+    @type axis:             numpy array, len 3
+    @param angle:           The cone angle in radians.
+    @type angle:            float
+    @param length:          The cone length in meters.
+    @type length:           float
+    @param inc:             The number of increments or number of vectors 
used to generate the outer
+                            edge of the cone.
+    @type inc:              int
+    """
+
+    # Initialise the rotation matrix.
+    R = zeros((3,3), float64)
+
+    # Get the rotation matrix.
+    R_2vect(R, array([0,0,1], float64), axis)
+
+    # Loop over each vector.
+    for i in xrange(inc):
+        # The azimuthal angle theta.
+        theta = 2.0 * pi * float(i) / float(inc)
+
+        # X coordinate.
+        x = cos(theta) * sin(angle)
+
+        # Y coordinate.
+        y = sin(theta)* sin(angle)
+
+        # Z coordinate.
+        z = cos(angle)
+
+        # The vector in the unrotated frame.
+        vector = array([x, y, z], float64)
 
 
 def create_diff_tensor_pdb(scale=1.8e-6, file=None, dir=None, force=False):

Modified: branches/N_state_model/maths_fns/rotation_matrix.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/maths_fns/rotation_matrix.py?rev=5061&r1=5060&r2=5061&view=diff
==============================================================================
--- branches/N_state_model/maths_fns/rotation_matrix.py (original)
+++ branches/N_state_model/maths_fns/rotation_matrix.py Thu Feb 21 09:07:46 
2008
@@ -21,11 +21,64 @@
 
###############################################################################
 
 # Python module imports.
-from numpy import dot
-from math import cos, sin
+from numpy import cross, dot
+from math import acos, cos, sin
 
 
-def rotation_matrix_zyz(matrix, alpha, beta, gamma):
+def R_2vect(R, vector_orig, vector_fin):
+    """Calculate the rotation matrix required to rotate from one vector to 
another.
+
+    For the rotation of one vector to another, there are an infinit series 
of rotation matrices
+    possible.  Due to axially symmetry, the rotation axis can be any vector 
lying in the symmetry
+    plane between the two vectors.  Hence the axis-angle convention will be 
used to construct the
+    matrix with the rotation axis defined as the cross product of the two 
vectors.  The rotation
+    angle is the arccosine of the dot product of the two unit vectors.
+
+    Given a unit vector parallel to the rotation axis, w = [x, y, z] and the 
rotation angle a,
+    the rotation matrix R is:
+
+              |  1 + (1-cos(a))*(x*x-1)   -z*sin(a)+(1-cos(a))*x*y   
y*sin(a)+(1-cos(a))*x*z |
+        R  =  |  z*sin(a)+(1-cos(a))*x*y   1 + (1-cos(a))*(y*y-1)   
-x*sin(a)+(1-cos(a))*y*z |
+              | -y*sin(a)+(1-cos(a))*x*z   x*sin(a)+(1-cos(a))*y*z   1 + 
(1-cos(a))*(z*z-1)  |
+
+    @param R:           The 3x3 rotation matrix to update.
+    @type R:            3x3 numpy array
+    @param vector_orig: The unrotated vector defined in the reference frame.
+    @type vector_orig:  numpy array, len 3
+    @param vector_fin:  The rotated vector defined in the reference frame.
+    @type vector_fin:   numpy array, len 3
+    """
+
+    # Convert the vectors to unit vectors.
+    vector_orig = vector_orig / norm(vector_orig)
+    vector_fin = vector_fin / norm(vector_fin)
+
+    # The rotation axis.
+    axis = cross(vector_orig, vector_fin)
+    x = axis[0]
+    y = axis[1]
+    z = axis[2]
+
+    # The rotation angle.
+    angle = acos(dot(vector_orig, vector_fin))
+
+    # Trig functions (only need to do this maths once!).
+    ca = cos(angle)
+    sa = sin(angle)
+
+    # Calculate the rotation matrix elements.
+    R[0,0] = 1.0 + (1.0 - ca)*(x**2 - 1.0)
+    R[0,1] = -z*sa + (1.0 - ca)*x*y
+    R[0,2] = y*sa + (1.0 - ca)*x*z
+    R[1,0] = z*sa+(1.0 - ca)*x*y
+    R[1,1] = 1.0 + (1.0 - ca)*(y**2 - 1.0)
+    R[1,2] = -x*sa+(1.0 - ca)*y*z
+    R[2,0] = -y*sa+(1.0 - ca)*x*z
+    R[2,1] = x*sa+(1.0 - ca)*y*z
+    R[2,2] = 1.0 + (1.0 - ca)*(z**2 - 1.0)
+
+
+def R_euler_zyz(matrix, alpha, beta, gamma):
     """Function for calculating the z-y-z Euler angle convention rotation 
matrix.
 
     Unit vectors




Related Messages


Powered by MHonArc, Updated Thu Feb 21 09:20:38 2008