ó
^™xTc           @   sA  d  d l  m Z d  d l Z d  d l m Z d  d l m Z d  d l m Z	 d  d l m
 Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z m Z d  d l m Z d  d l Z d  d l Z d d d d „ Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d d d „ Z d „  Z e  d k r=e ƒ  n  d S(   iÿÿÿÿ(   t   divisionN(   t   r3_rotation_vector_to_vector(   t   r3_rotation_vector_to_001(   t   r3_rotation_vector_to_010(   t   r3_rotation_vector_to_100(   t   matrix(   t   flex(   t   format_cpu_times(   t   Exception_expectedt   approx_equal(   t   mathi   i   iâÿÿÿc         C   sY  t  j j d d d d d d d d d d g	 ƒ } t | j d d g d ƒ sS t ‚ t | j d t ƒ d ƒ st t ‚ t | j d t ƒ d ƒ s• t ‚ t  j j d d g d ƒ } t | j d d d g ƒ sÒ t ‚ t | j d t ƒ d ƒ só t ‚ t | j d t ƒ t j	 d	 ƒ st ‚ g  } x= t
 d | d ƒ D]( } | j d
 | ƒ | j d | ƒ q5Wx> t
 | d ƒ D]+ } | j d | ƒ | j d | ƒ qsWt j d d d d d d d d d g	 ƒ } xit
 |  |  d ƒ D]S} xJt
 |  |  d ƒ D]4}	 x+t
 |  d ƒ D]}
 x| |	 |
 f | t j | |	 |
 f ƒ j g D]à} x×| D]Ï} y% t  j j d | d | d t ƒ } Wn` t k
 râ| d k s¢t ‚ y# t  j j d | d | d t ƒ Wn t k
 rØq$Xt ‚ qUXt  j j d | d | d t ƒ } t t t j | ƒ ƒ d ƒ s(t ‚ t  j j d | ƒ } t | | ƒ sRt ‚ t  j j d | ƒ } | j ƒ  } t | | ƒ sˆt ‚ | j ƒ  } t t t j | ƒ ƒ d ƒ s¸t ‚ t  j j d | ƒ } t | | ƒ sât ‚ t  j j d | ƒ } t t t j | ƒ ƒ d ƒ st ‚ t  j j d | ƒ } t | | ƒ sEt ‚ t j | ƒ } | j ƒ  sft ‚ | j ƒ  } t t | ƒ d ƒ s�t ‚ t | | ƒ s¢t ‚ | j ƒ  } t | | ƒ sÃt ‚ x^t t g D]P} t  j j d | j d | j d | ƒ d | d d ƒ } t | | ƒ s!t ‚ t  j j d | j d | j d | ƒ d | d d ƒ } | j ƒ  } t t t j | ƒ ƒ d ƒ s‡t ‚ t  j j d | ƒ } t | | ƒ s±t ‚ xl t  j j t  j j g D]R } y2 | d | j d | j d | ƒ d | d d ƒ Wn t k
 rqÊXt ‚ qÊWqÐWqUWqHWqWqüWqáWxt
 d ƒ D]} t j ƒ  } t  j j d | ƒ } | j ƒ  } t | | ƒ s�t ‚ t t j | j ƒ  ƒ | d | d | d d d	 ƒ sÍt ‚ t j | j ƒ  ƒ } t t | ƒ d ƒ sýt ‚ t  j j d | ƒ } t | | ƒ s't ‚ t j | ƒ j ƒ  } t | | ƒ sEt ‚ qEWd  S(   Nt   ri   i    i   g      à?t   degi	   iZ   i   ih  i˜þÿÿi
   g:��yª”!@g8��yª”Àg&Ías@g|Ö£Î!ã-@t   axist   anglet   qt   min_axis_lengthgñhãˆµøä>id   i   i   gªLXèz¶û?(   i    i    i    gwJëÿï?gwJëÿï?grÄZ|
 ð?(   t   scitbxR
   t&   r3_rotation_axis_and_angle_from_matrixR	   R   t   AssertionErrorR   t   Truet   Falset   pit   xranget   appendR   t   sqrt   colt   elemst$   r3_rotation_axis_and_angle_as_matrixt   RuntimeErrort-   r3_rotation_axis_and_angle_as_unit_quaternionR   t   abst%   r3_rotation_unit_quaternion_as_matrixt	   as_matrixt   as_unit_quaterniont%   r3_rotation_matrix_as_unit_quaterniont   is_r3_rotation_matrixt%   unit_quaternion_as_r3_rotation_matrixR   t    random_double_r3_rotation_matrixt   cos(   t
   axis_ranget   angle_max_divisiont   angle_min_powert   from_matrixt   anglest   dt   pt   hex_ortht   ut   vt   wR   R   R   R   t   rqt   rrt   qqt   rmt   qmt   rqmmR   t   convt   i_trial(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   exercise_axis_and_angle   sÈ    $#!!!!(		5 
$	$$				$		 "@i2   iô  c         C   s<  t  j j } t  j j } d d d d g } x�t |  ƒ D]s} t j j d d d d d d ƒ j ƒ  } | j	 ƒ  } | j
 } | d | ƒ }	 t j ƒ  }
 x t | ƒ D] } | j	 ƒ  q¡ W| d c t j ƒ  |
 7<t j ƒ  }
 x t | ƒ D] } | j ƒ  qè W| d c t j ƒ  |
 7<t j ƒ  }
 x! t | ƒ D] } | d | ƒ q/W| d	 c t j ƒ  |
 7<t j ƒ  }
 x! t | ƒ D] } | d
 |	 ƒ qyW| d c t j ƒ  |
 7<q7 Wd GHd | d | d f GHd | d	 | d f GH| d	 d k r+| d d k r+d | d | d	 | d | d f GHn  t j j ƒ  d  S(   Ni    t   ni   t   aiÿÿÿÿt   bi   R   i   R   i   s    times unit quaternion <-> matrixs        py: %.2f %.2f ss       c++: %.2f %.2f ss     ratio: %.2f %.2f(   R   R
   R    R#   R   R   R   t   randomt	   normalizeR%   R   t   timet   syst   stdoutt   flush(   t   n_trialst	   n_repeatst   cpp_umt   cpp_mut   timesR:   R7   R6   R   R   t   t0t   i_repeat(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   unit_quaternion_matrix_timingsy   s<    '	 *c         C   s§   t  t t j |  ƒ ƒ d ƒ s$ t ‚ t  t t j | ƒ ƒ d ƒ sH t ‚ t j t d |  d | ƒ ƒ } t  | t j |  ƒ | ƒ sˆ t ‚ t  | j ƒ  d ƒ s£ t ‚ d  S(   Ni   t   given_unit_vectort   target_unit_vector(   R	   R   R   R   R   R   t   vector_to_vectort   determinant(   t   gt   tR   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   check_vector_to_vector™   s
    $$"c         C   sä   t  t t j |  ƒ ƒ d ƒ s$ t ‚ t j t d |  ƒ ƒ } t  | t j |  ƒ d ƒ s^ t ‚ t  | j ƒ  d ƒ sy t ‚ t j |  ƒ j ƒ  } t  | t j |  ƒ d ƒ s° t ‚ t  | j ƒ  d ƒ sË t ‚ t  | | ƒ sà t ‚ d  S(   Ni   RM   i    (   i    i    i   (   i    i    i   (	   R	   R   R   R   R   R   t   vector_to_001RP   t   vector_to_001_rotation(   RQ   R   R.   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   check_vector_to_001    s    $""c         C   s}   t  t t j |  ƒ ƒ d ƒ s$ t ‚ t j t d |  ƒ ƒ } t  | t j |  ƒ d ƒ s^ t ‚ t  | j ƒ  d ƒ sy t ‚ d  S(   Ni   RM   i    (   i    i   i    (   R	   R   R   R   R   R   t   vector_to_010RP   (   RQ   R   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   check_vector_to_010ª   s    $"c         C   s}   t  t t j |  ƒ ƒ d ƒ s$ t ‚ t j t d |  ƒ ƒ } t  | t j |  ƒ d ƒ s^ t ‚ t  | j ƒ  d ƒ sy t ‚ d  S(   Ni   RM   i    (   i   i    i    (   R	   R   R   R   R   R   t   vector_to_100RP   (   RQ   R   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   check_vector_to_100°   s    $"i
   c      
   C   sÇ  g  d d d f D] } t  j | ƒ ^ q } xb | D]Z } xQ | D]I } x@ | | g D]1 } x( | | g D] } t d | d | ƒ qg WqS Wq? Wq2 Wt j j d ƒ r« d } n d } x#t | ƒ D]\ }	 } xt | ƒ D]ø \ }
 } |	 |
 k rõ q× n  | j | ƒ } xÈ t d | |  ƒ D]´ } d | } x  | | g D]‘ } t  j	 t
 j j d	 | d
 | ƒ ƒ } xd | | g D]U } xL | | g D]= } t | | | ƒ t | | | ƒ t | | | | ƒ q‚WqnWq6WqWq× Wq¾ Wxé t | ƒ D]Û } t  j t j ƒ  ƒ } t | | ƒ t | | ƒ t  j t j ƒ  ƒ } t | | ƒ x€ t d | |  ƒ D]l } d | } xX | | g D]I } t  j	 t
 j j d	 | d
 | ƒ ƒ | } t | | ƒ t | | ƒ qnWqOWqäWt d ƒ t d ƒ xƒ t d | |  ƒ D]o } d | } x[ | | g D]L } t  j	 t
 j j d	 d d
 | ƒ ƒ t  j d ƒ } t | ƒ t | ƒ q	WqêWx3 t | ƒ D]% } t  j t j ƒ  ƒ } t | ƒ qjWt d ƒ t d ƒ xƒ t d | |  ƒ D]o } d | } x[ | | g D]L } t  j	 t
 j j d	 d d
 | ƒ ƒ t  j d ƒ } t | ƒ t | ƒ qÙWqºWx3 t | ƒ D]% } t  j t j ƒ  ƒ } t | ƒ q:Wt d ƒ t d ƒ xƒ t d | |  ƒ D]o } d | } x[ | | g D]L } t  j	 t
 j j d	 d d
 | ƒ ƒ t  j d ƒ } t | ƒ t | ƒ q©WqŠWx3 t | ƒ D]% } t  j t j ƒ  ƒ } t | ƒ q
Wt d d ƒ } t d ƒ } t | | ƒ sct ‚ t d d ƒ } t d  ƒ } t | | ƒ s“t ‚ t d! d" ƒ } t d# ƒ } t | | ƒ sÃt ‚ d  S($   Ni   i    RQ   RR   t   osfi,  iT  i
   R   R   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    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   i    (   i    iÿÿÿÿi    (   iÿÿÿÿi    i    (   i   i    i    (   iÿÿÿÿi    i    (   R   R   RS   RB   t   platformt
   startswitht	   enumeratet   crossR   R   R   R
   R   R   t   random_double_point_on_sphereRV   RX   RZ   RO   RT   R	   R   RW   RY   (   t   angle_exponent_stepRE   R1   t   principal_vectorst   g0RJ   RQ   RR   t   max_expt   igt   itR   t   eR   R   R:   t   rtt   rgt   rvvt   rv1(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   exercise_vector_to_vector¶   s®    +#	 -








c           C   s!   t  ƒ  t ƒ  t ƒ  t ƒ  GHd  S(   N(   R;   RL   Rl   R   (    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   exercise  s    t   __main__(!   t
   __future__R    t   scitbx.mathR   R   RO   R   RT   R   RW   R   RY   R   t   scitbx.array_familyR   t   libtbx.utilsR   t   libtbx.test_utilsR   R	   t   stdlibR
   RA   RB   R;   RL   RS   RV   RX   RZ   Rl   Rm   t   __name__(    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tests/tst_r3_rotation.pyt   <module>   s0   g 		
		]	