ó
:™xTc           @   s‡   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d „  Z	 d d d	 d
 d „ Z
 d „  Z e d k rƒ e ƒ  n  d S(   s    - Generates random structures
   - Computes structure factors
   - Randomizes phases given a fudge factor
   - Computes fft map
   - Determines skewness of map
iÿÿÿÿ(   t   division(   t   sgtbx(   t   random_structure(   t   flexc         C   s  d | k o d k n s" t  ‚ t j |  j ƒ  t ƒ } |  j ƒ  j ƒ  } | } | j | ƒ } | j | ƒ } t j d | j ƒ  ƒ d | k  } | j	 | | j | ƒ d ƒ | t j d | j ƒ  ƒ d d | 7} | j	 | | ƒ | j	 | | ƒ |  j
 | d t ƒS(   Ni    i   t   sizeg      à?i´   ih  t   deg(   t   AssertionErrorR   t   argt   datat   Truet   centric_flagst   selectt   random_doubleR   t   set_selectedt   phase_transfer(   t   f_calct   fudge_factort   phasesR
   t   acentric_flagst   centric_phasest   acentric_phasest   sel(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/map_skewness.pyt   randomize_phases   s    ""i
   i   i   iÈ   c      	   C   s>  t  j d |  d d g | d | d t ƒ } | j ƒ  H| j d | d t ƒ j ƒ  } | j ƒ  Hx× t | d ƒ D]Å } | t | ƒ } t	 | | ƒ }	 | j
 |	 ƒ }
 |	 j ƒ  j ƒ  } | t j | ƒ } t j t j | d	 ƒ ƒ } t j t j | d
 ƒ ƒ d } | d k st ‚ | | } d Gd | |
 | f GHqp WHd  S(   Nt   space_group_infot   elementst   Set   volume_per_atomt   random_u_isot   d_mint   anomalous_flagi   i   i   g       @i    s-   fudge factor, phase difference, map skewness:s   %4.2f, %5.2f, %.4gg      ø?(   R   t   xray_structureR	   t   show_summaryt   structure_factorst   FalseR   t   xranget   floatR   t   mean_weighted_phase_errort   fft_mapt   real_map_unpaddedR   t   meant   powR   (   R   t   n_test_pointst   n_sitesR   R   t	   structureR   t   i_fudge_factorR   t   randomized_f_calct   mwpet   rhot   rho_rho_bart   numt   dent   skewness(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/map_skewness.pyt   skewness_calculation   s0    		
	

c          C   s(   x! d D] }  t  t j |  ƒ ƒ q Wd  S(   Ns   P 1s   C 2s
   P 21 21 21s   R 32s   F 4 3 2(   s   P 1s   C 2s
   P 21 21 21s   R 32s   F 4 3 2(   R4   R   R   (   t   space_group_symbol(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/map_skewness.pyt   run8   s    t   __main__N(   t   __doc__t
   __future__R    t   cctbxR   t   cctbx.developmentR   t   cctbx.array_familyR   R   R4   R6   t   __name__(    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/map_skewness.pyt   <module>   s   		