ó
xTc           @   s   d  d l  m Z d  d l m Z d  d l m Z d  d l Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z e d k r e d e j d  n  d S(   i˙˙˙˙(   t   division(   t   only_element(   t   StringIONc         C   s§   |  j    j | j     \ } } | j   j | j    sB t  d d l m } | | j   | j    ss t  |  j   sŁ | | j	   | j	    sŁ t  n  d  S(   Ni˙˙˙˙(   t   approx_equal(
   t
   map_to_asut   common_setst   indicest   all_eqt   AssertionErrort   libtbx.test_utilsR   t   datat%   is_xray_reconstructed_amplitude_arrayt   sigmas(   t   array_1t   array_2t   at   bR   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/mtz/tst_dano.pyt   assert_equal_data_and_sigmas   s    !!!c   
         sH  d d l  m } d d l  m } d d l m } | j d d d d  } | j d | d | j d d d d  d! g  d t  j	   } | j
   j   } | j t  d k są t  | j d d  } | j d | j d d  d d | j d d  d       f d   } | d  d d l m }	   j |	 j    | d  d  S("   Ni˙˙˙˙(   t   miller(   t   crystal(   t   flext	   unit_celli   i   i   iZ   id   t   space_group_symbolt   P112t   crystal_symmetryR   i    i   t   anomalous_flagt   seedR
   t   sizei   gš?R   c            s     j  d d  j   } t   } | j d |  d d l m }  r` t j j | j	    n  | | j	   |   s| t
  t | j    } t   |  d  S(   Nt   column_root_labelt   Xt   outi˙˙˙˙(   t	   show_diff(   t   as_mtz_datasett
   mtz_objectR   t   show_column_data_human_readableR	   R   t   syst   stdoutt   writet   getvalueR   R   t   as_miller_arraysR   (   t   expected_column_datat   mtz_objt   sioR   t   ma_2(   t   mat   verbose(    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/mtz/tst_dano.pyt   recycle#   s    	 s  Column data:
-------------------------------------------------------------------------------
                    X(+)         SIGX(+)            X(-)         SIGX(-)

 0  0  1        0.517022        0.192339        0.820324         0.28626
 0  1  1        0.100114        0.445561            None            None
 1  0  0        0.402333        0.496767            None            None
 1  1  1            None            None        0.246756        0.638817
-------------------------------------------------------------------------------
(   t   observation_typess  Column data:
-------------------------------------------------------------------------------
                       X            SIGX           DANOX        SIGDANOX
                   ISYMX

 0  0  1        0.668673        0.172438       -0.303302        0.344875
                       0
 0  1  1        0.100114        0.445561            None            None
                       1
 1  0  0        0.402333        0.496767            None            None
                       0
 1  1  1        0.246756        0.638817            None            None
                       2
-------------------------------------------------------------------------------
(   i   i   i   iZ   iZ   id   (   i    i    i   (   i    i    i˙˙˙˙(   i    i   i   (   i   i    i    (   i˙˙˙˙i˙˙˙˙i˙˙˙˙(   t   cctbxR   R   t   cctbx.array_familyR   t   symmetryt   sett   miller_indext   TrueR   t   centric_flagsR
   t   countR   t   mersenne_twistert   arrayt   random_doublet
   cctbx.xrayR/   t   set_observation_typet   reconstructed_amplitude(
   R-   R   R   R   t   cst   mst   cft   mtR.   R/   (    (   R,   R-   s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/mtz/tst_dano.pyt   exercise_systematic   s6    					
c         C   s´   |  j    s t  d d l m } | j d d  } |  j | j d |  j   j     }  |  j	 d d  j
   } t | j    } t | j    d k sŁ t  t |  |  d  S(	   Ni˙˙˙˙(   R   R   i    R   R   R   s$   ccp4_mtz:X,SIGX,DANOX,SIGDANOX,ISYMX(   R   R   R1   R   R8   t   selectt   random_permutationR   R   R    R!   R   R'   t   strt   infoR   (   t   miller_arrayR   RA   R)   t   miller_array_2(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/mtz/tst_dano.pyt   recycle_dano_miller_arrayJ   s    !c         C   sU   d d  l  } | j j d |   } x- | j   D] } | j   r. t |  q. q. Wd  S(   Ni˙˙˙˙t	   file_name(   t	   iotbx.mtzt   mtzt   objectR'   R   RI   (   t   mtz_file_namet   iotbxR)   RG   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/mtz/tst_dano.pyt   recycle_dano_mtzU   s
    c         C   sÄ  |  d0 k s t  d d l m } | j d d1 d d  } d d l m } | j d2 d3 g  } | j d d g  } | j d d g  } d d l m	 } | j
 d | d | d t  }	 |	 j d | d |  }
 |
 j d d  } |  d  k	 rxe | j   D]W } | j   d  |  d! |  g k rú | j d" | j d# g  d$ | j t g   qú qú W|  d k rjd } n d# } |
 j | j | g   }
 n  | j   } d d% l m } |
 j | j    |
 j d d&  j   } t   } | d' IJ| j d( |  | J| j   d# } | d) IJ| j d* |  | J| rIt j  j! | j"    n  |  d  k r^d+ } n6 |  d k rsd, } n! |  d k rd- } n t# d.   d d/ l$ m% } | | j"   |  sŔt  d  S(4   Nt   +t   -i˙˙˙˙(   R   R   i   i   i   iU   i_   ii   R   t   P1(   R   i   i   i   iţ˙˙˙iý˙˙˙g      @g      @gš?g333333Ó?(   R   R   R   R   R
   R   R   R   s   X(%s)s   SIGX(%s)t   valuesi    t   selection_valid(   R/   t   Rs%   Resulting mtz from .as_mtz_dataset():R   s%   mtz_obj_reco.as_miller_arrays result:t   fsý  Resulting mtz from .as_mtz_dataset():
Column data:
-------------------------------------------------------------------------------
                       R            SIGR           DANOR        SIGDANOR
                   ISYMR

 1  2  3               4        0.158114              -3        0.316228
                       0
-------------------------------------------------------------------------------

mtz_obj_reco.as_miller_arrays result:
(1, 2, 3) 2.5 0.223606796247
(-1, -2, -3) 5.5 0.223606796247

sŕ  Resulting mtz from .as_mtz_dataset():
Column data:
-------------------------------------------------------------------------------
                       R            SIGR           DANOR        SIGDANOR
                   ISYMR

 1  2  3             5.5             0.3            None            None
                       2
-------------------------------------------------------------------------------

mtz_obj_reco.as_miller_arrays result:
(-1, -2, -3) 5.5 0.300000011921

sÜ  Resulting mtz from .as_mtz_dataset():
Column data:
-------------------------------------------------------------------------------
                       R            SIGR           DANOR        SIGDANOR
                   ISYMR

 1  2  3             2.5             0.1            None            None
                       1
-------------------------------------------------------------------------------

mtz_obj_reco.as_miller_arrays result:
(1, 2, 3) 2.5 0.10000000149

s   Unreachable.(   R   (   NRQ   RR   (   i   i   i   iU   i_   ii   (   i   i   i   (   i˙˙˙˙iţ˙˙˙iý˙˙˙(&   t   NoneR   R0   R   R2   R1   R   R4   t   doubleR   R3   R5   R9   R    t   columnst   labelt
   set_valuest   floatt   boolt   FalseRC   t   size_tR!   R;   R/   R<   R=   R   R"   R'   t
   show_arrayR#   R$   R%   R&   t   RuntimeErrorR	   R   (   t   missingR-   R   R>   R   t   mit   fpmt   spmR   R?   R,   t   mtz_datasett   colt   iR)   R/   t   mtz_obj_recoR*   t   ma_recot   expectedR   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/mtz/tst_dano.pyt   recycle_one_dano\   s\    		 	 		

			c         C   s@  t  } g  } x[ |  D]S } | d k rD d d l m } | d   q | d k rY t } q | j |  q Wt |  t |  d k rő d d  l } d d  l } | j	 } | j
 j d  } | rí | j | j
 j d d	 d
 | j d t    qő d GHn  x | D] }	 t |	  qü Wx$ d  d d g D] }
 t |
 |  q Wd GHd  S(   Ns   --helpi˙˙˙˙(   t   Usages4   iotbx.python tst_dano.py [your_dano.mtz] [--verbose]s	   --verbosei    t   phenix_regressiont   relative_paths+   phenix_regression/reflection_files/dano.mtzt   testt   optionals0   Skipping tests on dano.mtz: no phenix_regressionRQ   RR   t   OK(   R_   t   libtbx.utilsRn   R5   t   appendRB   t   lent   libtbx.load_envt   ost   patht   envt
   has_modulet   find_in_repositoriest   isfileRP   RX   Rm   (   t   argsR-   t   mtz_file_namest   argRn   t   libtbxRx   t   opt   have_regressionRN   Rc   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/mtz/tst_dano.pyt   runˇ   s4    	
		t   __main__R~   i   (   t
   __future__R    R   R   t	   cStringIOR   R#   R   RB   RI   RP   Rm   R   t   __name__t   argv(    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/mtz/tst_dano.pyt   <module>   s   		<			[	