ó
ï™xTc           @   sÇ   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  d l Z d  d l Z d  d l Z d „  Z d „  Z d „  Z e d	 k rÃ d  d l Z e e j d
 ƒ n  d S(   iÿÿÿÿ(   t   division(   t   flex(   t	   show_diffN(   t   least_squaresc       
   C   sà  d „  }  t  j j ƒ  } d d t j ƒ  } | j d t d d ƒ j ƒ  } | j ƒ  } | j	 d | j
 ƒ  t j | ƒ ƒ } | j	 d d	 | j
 ƒ  ƒ } | j ƒ  } xd t | j ƒ  ƒ D]P } | j
 ƒ  | c d
 t j j t j j d | | ƒ ƒ ƒ  d t j ƒ  7<q¶ W| j ƒ  } | j ƒ  } t j d d ƒ }	 |  | | |	 | | j ƒ  ƒ }
 |	 j | | | | j ƒ  ƒ } |  | | | | | j ƒ  ƒ } | j ƒ  } | j
 ƒ  t j | j
 ƒ  ƒ } t j | ƒ } | j	 d | ƒ j | ƒ } | j | ƒ } | j | ƒ } d } d } t j d d ƒ } t j ƒ  } x_ t | ƒ D]Q } | j t t j | d | j ƒ  | ƒ ƒ ƒ | j | | d | | ƒ q8Wt j  ƒ  } t j  ƒ  } x  t | ƒ D]’ } t j! | | | | d ƒ } | j |  | j | ƒ | j | ƒ | | | j ƒ  ƒ ƒ | j |  | j | ƒ | j | ƒ |	 | | j ƒ  ƒ ƒ q²Wt j" | ƒ j# ƒ  } t j" | ƒ j# ƒ  } | | k s¤t$ d |
 ƒ t$ d | ƒ k s¤t% ‚ | | k s¶t% ‚ t$ d |
 ƒ t$ d | ƒ k sÜt% ‚ d  S(   Nc         S   sx   | j  ƒ  } | |  j ƒ  |  j ƒ  | j ƒ  | ƒ } t j t j | t j |  j ƒ  | | j ƒ  ƒ ƒ |  j ƒ  | ƒ S(   N(	   t   as_intensity_arrayt   datat   sigmast   matht   sqrtR   t   sumt   pow2t   size(   t   fo2t   fct   wt   kt   n_paramst   fc2(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/refinement/tests/tst_weighting_schemes.pyt	   calc_goof   s    'gš™™™™™©?i
   t   anomalous_flagt   d_mingffffffæ?R   R   g¸…ëQ¸ž?i   t   sigmag      à?t   agš™™™™™¹?i    i   (&   t   smtbxt   developmentt   sucroseR   t   random_doublet   structure_factorst   Falset   f_calct   as_amplitude_arrayt   customized_copyR   R   R   R   t   rangeR   t   scitbxt   randomt   variatet   normal_distributionR   R   t   mainstream_shelx_weightingt   n_parameterst   optimise_parameterst   maxt   sort_permutationt   selectt   size_tt   appendt   intt   ceilt   doublet   size_t_ranget   mean_and_variancet   unweighted_sample_variancet   abst   AssertionError(   R   t   xsR   R   t   foR   t   iR   R   R   t   st   w2t   s2t   fc_sqt   fc_sq_over_fc_sq_maxt   permutationt   fo_sqt   n_binst   bin_maxt
   bin_limitst	   bin_countt   goofs_wt   goofs_w2t   i_bint   selR   t   b(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/refinement/tests/tst_weighting_schemes.pyt    exercise_optimise_shelxl_weights   s^    	%	.!2c          C   s†   t  j ƒ  }  |  j ƒ  d k s$ t ‚ t |  ƒ d k s< t ‚ t  j d d ƒ } | j ƒ  d k sf t ‚ t t | ƒ d ƒ s‚ t ‚ d  S(   Nt   units   w=1góŽSt$—¿?gÏfÕçj+â?t   calcs@   w=1/[\s^2^(Fo^2^)+(0.1234P)^2^+0.5678P] where P=(Fo^2^+2Fc^2^)/3(   R   t   unit_weightingt   typeR4   t   strR%   R   (   RK   t   shelx_weighting(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/refinement/tests/tst_weighting_schemes.pyt   exercise_weighting_schemesB   s    	c         C   so   d |  k r9 t  j d ƒ t j d ƒ t j  j d ƒ n  t j j ƒ  x t d ƒ D] } t	 ƒ  qS Wt
 ƒ  d  S(   Ns   --fix_random_seedsi   i
   (   R"   t   seedR   t   set_random_seedR!   t   libtbxt   utilst   show_times_at_exitR    RH   RO   (   t   argsR7   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/refinement/tests/tst_weighting_schemes.pyt   runL   s    t   __main__i   (   t
   __future__R    t   cctbx.array_familyR   t   libtbx.test_utilsR   t   libtbx.utilsRR   t   scitbx.randomR!   t   smtbx.refinementR   t   smtbx.developmentR   R"   R   RH   RO   RV   t   __name__t   syst   argv(    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/refinement/tests/tst_weighting_schemes.pyt   <module>   s   	6	
	
