ó
(™xTc           @   sì   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 m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z d  d	 l Z d  d	 l Z d  d
 l m Z d „  Z d „  Z d „  Z d „  Z e d k rè e ƒ  n  d	 S(   iÿÿÿÿ(   t   division(   t   miller(   t   debug_utilst   random_structure(   t   translation_search(   t   flex(   t   matrix(   t   approx_equal(   t   progress_displayed_as_fractionN(   t%   symmetrised_shifted_structure_factorsc            s  | j  d t j d t d t ƒ d d ƒ } t j d | j ƒ  d | j ƒ  d	 | j ƒ  d
 | j ƒ  d | j	 ƒ  d t
 j ƒ  d |  j ƒ  d |  j	 ƒ  ƒ j ƒ  } | j ƒ  \ } } } ‰  ‡  ‡ f d †  }	 | j ƒ  }
 x¥ |	 ƒ  D]š \ } } } | | | | | | f } t j ƒ  d k r"| } n |
 } t | |  | ƒ j | ƒ } t | j | | | | f ƒ sÝ t | | | f ƒ ‚ qÝ Wd S(   s^    where we check against the trusted correlation map implemented
  in cctbx.translation_search t   symmetry_flagst   is_isotropic_search_modelt   have_f_partt   resolution_factori   i   t   griddingt   space_groupt   anomalous_flagt   miller_indices_f_obst   f_obst   f_partt   miller_indices_p1_f_calct	   p1_f_calcc          3   si   d d l  m }  d VxM t ˆ d ƒ D]; } |  d ˆ  d ƒ |  d ˆ  d ƒ |  d ˆ  d ƒ f Vq& Wd  S(   Niÿÿÿÿ(   t	   randrangei    i   i   (   i    i    i    (   t   randomR   t   xrange(   R   t   i(   t   nt	   n_sampled(    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/symmetry_search/tests/tst_goodness_of_symmetry.pyt   sampled_indices"   s    g      à?NgUUUUUUÕ?(   t   crystal_griddingR   R
   t   Falset   fast_nv1995t   n_realR   R   t   indicest   dataR   t   complex_doublet
   target_mapt   as_intensity_arrayR   R	   t   misfitR   t   correlationt   AssertionError(   t	   f_c_in_p1t   f_ot   flagsR   R   t   correlation_mapt   nxt   nyt   nzR   t   f_o_sqR   t   jt   kt   xt   f_o_or_f_o_sqt   gos(    (   R   R   sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/symmetry_search/tests/tst_goodness_of_symmetry.pyt   exercise_value   s2    					 	c         C   s¹  d d l  m  } d d l m } | j ƒ  } x†t | ƒ D]x} t j | ƒ  | ƒ  | ƒ  f ƒ } t | |  | d t ƒj	 | ƒ }	 x-t
 d d d g ƒ D]\ }
 } t j | ƒ d } g  | d | | d	 | | | | | | d	 | | d | f D]$ } t | |  | ƒ j	 | ƒ j ^ q÷ \ } } } } } } | | d
 d | | d | | t | ƒ } | |	 j |
 | d d d d ƒs— t |
 | t | ƒ |	 j |
 | f ƒ ‚ q— Wq9 Wd S(   s:    where we use finite differences to check our derivatives iÿÿÿÿ(   R   (   t   approx_equal_relativelyt   compute_gradienti   i    gü©ñÒMbP?i   i   i<   i   i   t   relative_errorg{®Gáz„?t   near_zero_thresholdg�íµ ÷Æ°>N(   i   i    i    (   i    i   i    (   i    i    i   g333333Ã?g      è?(   R   t   scitbx.mathR7   R%   R   t   matt   colR	   t   TrueR&   t	   enumeratet   valuet   abst   gradientR(   t   tuple(   R)   R*   R+   R   R   R7   R0   R   R3   R5   R1   t   et   ht   yt   fm3t   fm2t   fm1t   f1t   f2t   f3t   finite_diff(    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/symmetry_search/tests/tst_goodness_of_symmetry.pyt   exercise_gradient0   s     !"z0c         C   s‰  | j  ƒ  j ƒ  } | G|  j r/ t j d ƒ n  |  j sr | j ƒ  j ƒ  d k rr t | ƒ d k rf Hn  d GHd  Sn  Ht	 |  j
 ƒ } | d k r— d } n  t | ƒ } xÕ t | ƒ D]Ç } t j d | d d g d	 d
 g d d g d t d t d d d t ƒ } t j | d t d d ƒj | d d ƒj ƒ  } | j ƒ  }	 | j ƒ  }
 t |
 |	 |  | ƒ t |
 |	 |  | ƒ | j ƒ  q° W| j ƒ  d  S(   Ni    i   i   s>     [ Skipped (rerun with --include_high_symmetry to override) ]i   t   space_group_infot   elementst   Ci   t   Oi   t   Nt	   use_u_isot   random_u_isot   random_u_iso_scaleg{®Gáz¤?t   use_u_anisoR   t   d_mingš™™™™™é?t	   algorithmt   direct(   t   typet   hall_symbolt   fix_seedR   t   seedt   include_high_symmetryt   groupt   order_pt   lent   intt   repeatsR   R   R   t   xray_structureR>   R   R   t	   build_sett!   structure_factors_from_scattererst   f_calct   as_amplitude_arrayt   expand_to_p1R6   RN   t   advancet   done(   R+   RO   R   t   symbolR   t   progressR   t   xst   f_cR*   R)   (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/symmetry_search/tests/tst_goodness_of_symmetry.pyt   exerciseE   s@    		  			c        
   C   s0   t  j t j d d t d d
 d t d d	 ƒd  S(   Ni   t	   call_backt   keywordsR_   R]   Rd   t   symbols_to_stderrR   i2   (   s   include_high_symmetrys   fix_seeds   repeats(   R   t   parse_options_loop_space_groupst   syst   argvRq   R   (    (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/symmetry_search/tests/tst_goodness_of_symmetry.pyt   runf   s    t   __main__(   t
   __future__R    t   cctbxR   t   cctbx.developmentR   R   R   t   scitbx.array_familyR   t   scitbxR   R<   t   libtbx.test_utilsR   t   libtbx.utilsR   R   Rv   t   cctbx.symmetry_searchR	   R6   RN   Rq   Rx   t   __name__(    (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/symmetry_search/tests/tst_goodness_of_symmetry.pyt   <module>   s    	 		!		