ó
Z÷Ic           @   sž  d  d l  Z  d  d l Z d Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 d d „  ƒ  YZ e d k ršd  d l m Z e d d d ƒ Z e d d d ƒ Z e d d d ƒ Z e d d d ƒ Z e j ƒ  e GHe	 e e e ƒ GHe
 e e e e ƒ Z e d k s!t ‚ d Ge GHe e e ƒ Z e e e ƒ Z e GHe j e ƒ GHe j e ƒ GHe j e  j e ƒ ƒ GHe e GHe d GHe d GHe e GHe d GHe d GHe e GHe d GHe d GHe e GHe d GHe d GHe j ƒ  GHe j ƒ  GHd e d <e GHe d GHe  j e ƒ GHd GHe ƒ  e  j Z e e d ƒ e d ƒ ƒ Z  e  j ƒ  e e e  ƒ Z! e e! ƒ \ Z" Z# e e" GHe  e# GHHn  d S(   iÿÿÿÿNs3   Vector class, including rotation-related functions.c   
      C   s  d t  j |  ƒ d } t d | ƒ } t d | ƒ } t  j | ƒ } | d k  rf d t d d d ƒ f S| t  j k  rÑ |  d	 |  d
 } |  d |  d } |  d |  d } t | | | ƒ } | j ƒ  | | f S|  d } |  d } |  d }	 | | k rI| |	 k rIt  j | | |	 d ƒ } |  d d | } |  d d | } n™ | | k r£| |	 k r£t  j | | |	 d ƒ } |  d d | } |  d d | } n? t  j |	 | | d ƒ } |  d d | } |  d d | } t | | | ƒ } | j ƒ  t  j | f Sd S(   sI   
    Return angles, axis pair that corresponds to rotation matrix m.
    g      à?i   iÿÿÿÿgVçž¯Ò<g        i    i   N(   i   i   (   i   i   (   i    i   (   i   i    (   i   i    (   i    i   (   i    i    (   i   i   (   i   i   (   i    i   (   i    i   (   i    i   (   i   i   (   i    i   (   i   i   (	   t   numpyt   tracet   maxt   mint   arccost   Vectort   pit	   normalizet   sqrt(
   t   mt   tt   anglet   xt   yt   zt   axist   m00t   m11t   m22(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt	   m2rotaxis   s<    





c         C   s@   |  j  ƒ  }  | j ƒ  } |  j | ƒ } | |  | t j | ƒ S(   s  
    Returns the vector between a point and
    the closest point on a line (ie. the perpendicular
    projection of the point on the line).

    @type line: L{Vector}
    @param line: vector defining a line

    @type point: L{Vector}
    @param point: vector defining the point
    (   t
   normalizedt   normR   R    t   cos(   t   linet   pointt   npR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   vector_to_axis7   s    c   	      C   sD  | j  ƒ  } | j ƒ  t j |  ƒ } t j |  ƒ } d | } | j ƒ  \ } } } t j d ƒ } | | | | | d <| | | | | | d <| | | | | | d <| | | | | | d	 <| | | | | d
 <| | | | | | d <| | | | | | d <| | | | | | d <| | | | | d <| S(   sŒ  
    Calculate a left multiplying rotation matrix that rotates
    theta rad around vector.

    Example: 
    
        >>> m=rotaxis(pi, Vector(1,0,0))
        >>> rotated_vector=any_vector.left_multiply(m)

    @type theta: float
    @param theta: the rotation angle


    @type vector: L{Vector}
    @param vector: the rotation axis

    @return: The rotation matrix, a 3x3 Numeric array.
    i   i   i    i   (   i   i   (   i    i    (   i    i   (   i    i   (   i   i    (   i   i   (   i   i   (   i   i    (   i   i   (   i   i   (   t   copyR   R    R   t   sint	   get_arrayt   zeros(	   t   thetat   vectort   ct   sR
   R   R   R   t   rot(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt	   rotaxis2mI   s"    

c         C   s–   |  j  ƒ  | j  ƒ  |  | j ƒ  d k  r7 t j d ƒ S|  | } | j  ƒ  | j ƒ  } d | _ t j d ƒ } | d t j | t j | ƒ ƒ } | S(   s   
    Return a (left multiplying) matrix that mirrors p onto q.

    Example:
        >>> mirror=refmat(p,q)
        >>> qq=p.left_multiply(mirror)
        >>> print q, qq # q and qq should be the same

    @type p,q: L{Vector}
    @return: The mirror operation, a 3x3 Numeric array. 
    gñhãˆµøä>i   i   i   (   i   i   (   R   R   R    t   identityR   t   shapet   dott	   transpose(   t   pt   qt   pqt   bt   it   ref(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   refmats   s    



	#c         C   s*   t  j t | |  ƒ t |  |  ƒ ƒ } | S(   sL  
    Return a (left multiplying) matrix that rotates p onto q.

    Example:
        >>> r=rotmat(p,q)
        >>> print q, p.left_multiply(r)

    @param p: moving vector
    @type p: L{Vector}

    @param q: fixed vector
    @type q: L{Vector}

    @return: rotation matrix that rotates p onto q
    @rtype: 3x3 Numeric array
    (   R    R'   R/   (   R)   R*   R#   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   rotmat‹   s    &c         C   s!   |  | }  | | } |  j  | ƒ S(   sÜ   
    Calculate the angle between 3 vectors
    representing 3 connected points.

    @param v1, v2, v3: the tree points that define the angle
    @type v1, v2, v3: L{Vector}
    
    @return: angle
    @rtype: float
    (   R   (   t   v1t   v2t   v3(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt
   calc_angleŸ   s    

c         C   s†   |  | } | | } | | } | | } | | } | | }	 | j  | ƒ }
 y# | j  |	 ƒ d k rm |
 }
 n  Wn t k
 r n X|
 S(   së   
    Calculate the dihedral angle between 4 vectors
    representing 4 connected points. The angle is in
    ]-pi, pi].

    @param v1, v2, v3, v4: the four points that define the dihedral angle
    @type v1, v2, v3, v4: L{Vector}
    gü©ñÒMbP?(   R   t   ZeroDivisionError(   R1   R2   R3   t   v4t   abt   cbt   dbt   ut   vt   wR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   calc_dihedral®   s    	





R   c           B   s¿   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s	   3D vectorc         C   sm   | d  k rK | d  k rK t | ƒ d k r3 d ‚ n  t j | d ƒ |  _ n t j | | | f d ƒ |  _ d  S(   Ni   s0   Vector: x is not a list/tuple/array of 3 numberst   d(   t   Nonet   lenR    t   arrayt   _ar(   t   selfR   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __init__Ê   s
    	c         C   s#   |  j  \ } } } d | | | f S(   Ns   <Vector %.2f, %.2f, %.2f>(   RB   (   RC   R   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __repr__Ô   s    c         C   s   |  j  } t | ƒ S(   s   Return Vector(-x, -y, -z)(   RB   R   (   RC   t   a(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __neg__Ø   s    
c         C   sB   t  | t ƒ r" |  j | j } n |  j t j | ƒ } t | ƒ S(   s$   Return Vector+other Vector or scalar(   t
   isinstanceR   RB   R    RA   (   RC   t   otherRF   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __add__Ý   s    c         C   sB   t  | t ƒ r" |  j | j } n |  j t j | ƒ } t | ƒ S(   s$   Return Vector-other Vector or scalar(   RH   R   RB   R    RA   (   RC   RI   RF   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __sub__å   s    c         C   s   t  |  j | j ƒ S(   s"   Return Vector.Vector (dot product)(   t   sumRB   (   RC   RI   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __mul__í   s    c         C   s    |  j  t j | ƒ } t | ƒ S(   s   Return Vector(coords/a)(   RB   R    RA   R   (   RC   R   RF   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __div__ñ   s    c         C   sï   t  | t ƒ rË |  j \ } } } | j \ } } } t j j t j | | f | | f f ƒ ƒ } t j j t j | | f | | f f ƒ ƒ }	 t j j t j | | f | | f f ƒ ƒ }
 t | |	 |
 ƒ S|  j t j | ƒ } t | ƒ Sd S(   s5   Return VectorxVector (cross product) or VectorxscalarN(   RH   R   RB   R    t   linalgt   detRA   (   RC   RI   RF   R,   R!   R>   t   et   ft   c1t   c2t   c3(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __pow__ö   s    -.-c         C   s   |  j  | S(   N(   RB   (   RC   R-   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __getitem__  s    c         C   s   | |  j  | <d  S(   N(   RB   (   RC   R-   t   value(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   __setitem__  s    c         C   s   t  j t |  j |  j ƒ ƒ S(   s   Return vector norm(   R    R   RL   RB   (   RC   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyR   	  s    c         C   s   t  t |  j |  j ƒ ƒ S(   s   Return square of vector norm(   t   absRL   RB   (   RC   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   normsq  s    c         C   s   |  j  |  j ƒ  |  _  d S(   s   Normalize the VectorN(   RB   R   (   RC   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyR     s    c         C   s   |  j  ƒ  } | j ƒ  | S(   s&   Return a normalized copy of the Vector(   R   R   (   RC   R;   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyR     s    
c         C   sU   |  j  ƒ  } | j  ƒ  } |  | | | } t | d ƒ } t d | ƒ } t j | ƒ S(   s    Return angle between two vectorsi   iÿÿÿÿ(   R   R   R   R    R   (   RC   RI   t   n1t   n2R!   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyR     s    c         C   s   t  j |  j ƒ S(   s+   Return (a copy of) the array of coordinates(   R    RA   RB   (   RC   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyR   %  s    c         C   s   t  j | |  j ƒ } t | ƒ S(   s   Return Vector=Matrix x Vector(   R    R'   RB   R   (   RC   t   matrixRF   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   left_multiply)  s    c         C   s   t  j |  j | ƒ } t | ƒ S(   s   Return Vector=Vector x Matrix(   R    R'   RB   R   (   RC   R^   RF   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   right_multiply.  s    c         C   s   t  |  j ƒ S(   s    Return a deep copy of the Vector(   R   RB   (   RC   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyR   3  s    N(   t   __name__t
   __module__t   __doc__R?   RD   RE   RG   RJ   RK   RM   RN   RV   RW   RY   R   R[   R   R   R   R   R_   R`   R   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyR   Ç   s(   
														
			t   __main__(   t   randomi    i   s	   DIHEDRAL i   i   i
   t   ROT(    (   i   i   i   (   i   i   i   (   i   i   i   (   i   i   i   ($   R    t   sysRc   R   R   R$   t   rotaxisR/   R0   R4   R=   R   Ra   t   numpy.randomRe   R1   R2   R3   R6   R   t   diht   AssertionErrorR.   R#   R_   R`   R(   R   R[   RA   R   R   R   R	   t   canglet   caxis(    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Vector.pyt   <module>   sp   	+		(				p
													
	
		