ó
ÉÝ{Tc           @   sM   d  Z  d d l Td d l Z d Z d e Z e d Z d d	 d „  ƒ  YZ d S(
   sB  
     pygl/Quat.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2005 University of York, CCLRC

     This library is free software: you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public License
     version 3, modified in accordance with the provisions of the 
     license to address the requirements of UK law.
 
     You should have received a copy of the modified GNU Lesser General 
     Public License along with this library.  If not, copies may be 
     downloaded from http://www.ccp4.ac.uk/ccp4license.php
 
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU Lesser General Public License for more details.
iÿÿÿÿ(   t   *Ng-DTû!	@g     €f@i´   t   Quatc           B   s’   e  Z d  Z d „  Z d d d 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 RS(   s   
     Quaternion class
     c         C   s£   t  | d | d | d d | d ƒ } t  | d | d | d d | d ƒ } t  | d | d | d d | d ƒ } |  j | ƒ |  j | ƒ |  j | ƒ d  S(   Ni    i   i   (   R   t   postMult(   t   selft   xaxist   yaxist   zaxist   drott   rotxt   rotyt   rotz(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyt   rotate_about_axes    s    (((i    iÿÿÿÿc         C   s`   d d d d g |  _  | d k r7 |  j | | | ƒ n  | d k r\ |  j | | | | ƒ n  d S(   sc   
        Constructor, specify wi=0 for build with x,y,z and
        wi = 1 for x,y,z,angle
        g      ð?g        i    i   N(   t   dvalt   sett   seta(   R   t   xt   yt   zt   wit   angle(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyt   __init__(   s
    c         C   s   d d d d g |  _  d S(   s)   
        Reset to unit rotation.
        g      ð?g        N(   R   (   R   (    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyt   reset5   s    c         C   s…   t  d d d d d d | ƒ} t  d d d d d d | ƒ} t  d d d d d d | ƒ} |  j | ƒ |  j | ƒ |  j | ƒ d S(   s>   
        Set to given rotations about x,y and z axes.
        g      ð?g        R   i   R   N(   R   t   setqR   (   R   R   R   R   t   xQt   yQt   zQ(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR   ;   s    c         C   s   | j  |  _  d S(   s   
        Copy dval from other quaternion. This
        should be used where we currently have
        dodginess in MG.
        N(   R   (   R   t   qfrom(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR   H   s    c         C   sÈ   | t  } t | | | | | | ƒ } | d k  r> d GHn  | | } | | } | | } t | d ƒ |  j d <| t | d ƒ |  j d <| t | d ƒ |  j d <| t | d ƒ |  j d <d S(	   sC   
        Set rotation angle about 
        specified axis.
        g•Ö&è.>s   zero length in Quat normg       @i    i   i   i   N(   t
   DEG_TO_RADt   sqrtt   cosR   t   sin(   R   R   R   R   R   t   radius(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR   P   s    
 


c         C   s9   t  ƒ  } g  | _ | j j |  j ƒ |  j | | ƒ d S(   s6   
        Post-multiply by another quaternion.
        N(   R   R   t   extendt
   multAndSet(   R   t   qt   temp(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR   d   s    		c         C   sˆ  | j  d | j  d | j  d | j  d | j  d | j  d | j  d | j  d |  j  d <| j  d | j  d | j  d | j  d | j  d | j  d | j  d | j  d |  j  d <| j  d | j  d | j  d | j  d | j  d | j  d | j  d | j  d |  j  d <| j  d | j  d | j  d | j  d | j  d | j  d | j  d | j  d |  j  d <d S(   s<   
        Set self to be product of quat1 and quat2.
        i    i   i   i   N(   R   (   R   t   quat1t   quat2(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR!   m   s    aaac         C   s   t  j |  j ƒ |  _ d S(   s&   
        Normailze the dvals.
        N(   t   utilt	   normalizeR   (   R   (    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR'   €   s    c         C   s…   |  j  ƒ  t ƒ  } g  | _ | j j |  j d ƒ | j j |  j d ƒ | j j |  j d ƒ | j j |  j d ƒ | j ƒ  S(   Ni    i   i   i   (   R'   R   R   t   appendt	   getMatrix(   R   t   quat(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyt   getInvMatrix†   s    
		c         C   s…   |  j  ƒ  t ƒ  } g  | _ | j j |  j d ƒ | j j |  j d ƒ | j j |  j d ƒ | j j |  j d ƒ | j ƒ  S(   Ni    i   i   i   (   R'   R   R   R(   t   getMatrix_c(   R   R*   (    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyt   getInvMatrix_c‘   s    
		c   	      C   s  |  j  ƒ  |  j d } |  j d } |  j d } |  j d } | | } | | } | | } g  g  g  g  g } | d j d d | | ƒ | d j d | | | | ƒ | d j d | | | | ƒ | d j d ƒ | d j d | | | | ƒ | d j d d | | ƒ | d j d | | | | ƒ | d j d ƒ | d j d | | | | ƒ | d j d | | | | ƒ | d j d d | | ƒ | d j d ƒ | d j d ƒ | d j d ƒ | d j d ƒ | d j d ƒ | S(   s-   
        Return the rotation matrix.
        i    i   i   i   g      ð?g       @g        (   R'   R   R(   (	   R   t   wR   R   R   t   xxt   yyt   zzt   M(    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR)   œ   s4    



!!!!!!c         C   sK  d d  l  } | j d ƒ } |  j ƒ  } | d d | d <| d d | d <| d d | d <| d d | d <| d d | d <| d d | d <| d d | d	 <| d d | d
 <| d d | d <| d d | d <| d d | d <| d d | d <| d d | d <| d d | d <| d d | d <| d d | d <| S(   Niÿÿÿÿi   i    i   i   i   i   i   i   i   i   i	   i
   i   i   i   i   i   (   t   point_funcst   doubleaR)   (   R   R3   t   cmatR2   (    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR,   Ä   s(    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R!   R'   R+   R-   R)   R,   (    (    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyR      s   												((    (   R8   t   mathR&   t   PIt
   RAD_TO_DEGR   R   (    (    (    s6   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/pygl/Quat.pyt   <module>   s   


