ó
k™xTc           @   sý   d  d l  m Z d  d l m Z d  d l Z d  d l Z d  d l m Z d  d l Z d  d l	 Z	 d e j
 f d „  ƒ  YZ d e j
 f d „  ƒ  YZ e j ƒ  j e ƒ Z e j ƒ  j e ƒ Z e j e e g ƒ Z e d	 k rù e j d
 d ƒ j e ƒ n  d S(   iÿÿÿÿ(   t   division(   t   so3_lie_algebraN(   t   flext   TestElementc           B   sA   e  Z e j j d  ƒ Z d Z d Z d „  Z d „  Z	 d „  Z
 RS(   i   i
   gü©ñÒMbP?c         C   sI   t  j j d | ƒ } |  j |  j | j ƒ  | j ƒ  j ƒ  d d ƒ d  S(   Nt   matrixi    i   (   R   t   elementt   from_rotation_matrixt   assertAlmostEqualt   IDENTITYt	   transposet   exponentialt   norm_sq(   t   selfR   t   le(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_so3_lie_algebra.pyt   run_tests_with   s
     c         C   su   xn t  |  j ƒ D]] } t j ƒ  } t j ƒ  t j |  j } t j	 j
 t j j | | ƒ ƒ } |  j d | ƒ q Wd  S(   NR   (   t   ranget   SAMPLE_SIZER   t   random_double_point_on_spheret   random_doublet   matht   pit   SINGULARITY_GUARDt   scitbxR   t   sqrt$   r3_rotation_axis_and_angle_as_matrixR   (   R   t   it   axist   anglet   rotmat(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_so3_lie_algebra.pyt   test_random_matrices   s    	c         C   s   |  j  d |  j ƒ d  S(   NR   (   R   R   (   R   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_so3_lie_algebra.pyt   test_identity$   s    (   t   __name__t
   __module__R   R   t   identityR   R   R   R   R   R   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_so3_lie_algebra.pyR      s   			
t   TestAveragingc           B   s&   e  Z d  Z d Z d „  Z d „  Z RS(   gš™™™™™¹?i
   c   
   	   C   s)  t  j j t j ƒ  ƒ } t j ƒ  t j } g  t |  j	 ƒ D] } t j ƒ  d |  j
 ^ q; } t  j j d g  | D]+ } t  j j t  j j | | | ƒ ƒ ^ qq ƒ } | t | ƒ t | ƒ } t  j j | ƒ } | j t  j j | j ƒ ƒ }	 |  j t |	 ƒ d d ƒ |  j | j ƒ  |	 | d ƒ d  S(   Ng      à?t   matricesg      ð?i   (   R   R   t   colR   R   R   R   R   R   R   t	   MAX_ERRORt,   r3_rotation_average_rotation_via_lie_algebraR   R   t   sumt   lent&   r3_rotation_axis_and_angle_from_matrixt   dotR   R   t   absR   (
   R   R   t   centreR   t   errorst   et   averageR   t   aaft	   alignment(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_so3_lie_algebra.pyt
   test_angle.   s    08c         C   s  d } t  j ƒ  t j } t j j t j j | | ƒ ƒ } g  t |  j	 ƒ D]> } t j j t j j t  j
 ƒ  t  j ƒ  d |  j ƒ ƒ ^ qJ } g  | D] } | | ^ q• } t j j d | ƒ } t j j t j j | Œ  ƒ }	 |	 j ƒ  | }
 |  j |
 t j j ƒ  d d ƒ d  S(	   Ngfú×�²î×?gÏO¾“dÅß?g,ü£‚°é?g      à?R#   i    i   (   gfú×�²î×?gÏO¾“dÅß?g,ü£‚°é?(   R   R   R   R   R   R   R   R   R   R   R   R%   R&   t1   r3_rotation_average_rotation_matrix_from_matricesR	   R   R   R   R   (   R   R   R   R   R   t   missetst   missetR#   t   aver_liet	   aver_quatt   diff(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_so3_lie_algebra.pyt	   test_axisD   s    	Q			(   R   R    R%   R   R2   R9   (    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_so3_lie_algebra.pyR"   )   s   	t   __main__t	   verbosityi   (   t
   __future__R    t   scitbx.mathR   t   scitbx.matrixR   t   scitbx.array_familyR   t   unittestR   t   TestCaseR   R"   t
   TestLoadert   loadTestsFromTestCaset   suite_elementt   suite_averagingt	   TestSuitet   alltestsR   t   TextTestRunnert   run(    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/tst_so3_lie_algebra.pyt   <module>   s"   8		