ó
@™xTc           @   s  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 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 Z d  d l Z d „  Z d „  Z e d k rþ e d e j d k ƒ e ƒ  GHn  d S(   iÿÿÿÿ(   t   division(   t   flex(   t   xray(   t   miller(   t   crystal(   t   maptbx(   t   lbfgs(   t   ifloort   iceil(   t   format_cpu_times(   t   StringIONc      	   C   sž  x—t  d ƒ D]‰} t j t j d d ƒ d d ƒ } | j ƒ  } xž t  d ƒ D]� } t d |  d | d | ƒ } t j | j d	 ƒ t j d ƒ }	 t j	 |	 j
 |	 ƒ ƒ }	 |	 d
 | k r¿ Pn  | d I| j d	 IJ| j } qO Wx° t | j | j ƒ  ƒ D]– \ }
 } | | IJ| | IJ| | d	 IJ| |
 IJt j |
 ƒ t j | ƒ }	 t j	 |	 j
 |	 ƒ ƒ }	 | |	 I| IJ|	 | d
 k sŽt ‚ | Jqü Wq Wd  S(   Nid   t   sizei   g      à?i   t	   basic_mapt
   sites_cartt   delta_hi    i   s
   recycling:(   i    i    i    (   t   xrangeR   t   vec3_doublet   random_doublet	   deep_copyR   t   doubleR   t   matht   sqrtt   dott   zipt   AssertionError(   R   R   t   xray_structuret   outt   i_trialR   t   tmp_sites_cartt   it   reft   tempt   sitet   sitec(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/tst_real_space_refinement.pyt   testing_function_for_rsfit   s0    #	#%


c         C   sa  |  r t  j } n	 t ƒ  } t j d ƒ } t j ƒ  } t j d d d d ƒ } t j	 d | d t
 j t j d	 d
 d d ƒ g ƒ ƒ } t j d | d t d d ƒ } | j d | ƒ j ƒ  } | j ƒ  } | j ƒ  | j ƒ  }	 d }
 t j t j ƒ  |	 |	 j ƒ  | j ƒ  j ƒ  | j ƒ  | j ƒ  ƒ } t | |
 | | ƒ | j ƒ  j d ƒ } | j ƒ  j d ƒ } g  t | j ƒ  | ƒ D] \ } } t | | ƒ ^ qw} g  t | j ƒ  | ƒ D] \ } } t  | | ƒ ^ q¯} t j! |	 | | ƒ } t j t j" ƒ  | | j ƒ  | j ƒ  j ƒ  | j ƒ  | j ƒ  ƒ } t | |
 | | ƒ | j ƒ  j d ƒ } | j ƒ  j d ƒ } g  t | j ƒ  | ƒ D] \ } } t | | ƒ ^ q{} g  t | j ƒ  | ƒ D] \ } } t  | | ƒ ^ q³} t j! |	 | | ƒ } t j t j# ƒ  | | j$ ƒ  | j% ƒ  j& ƒ  |	 j ƒ  | j ƒ  j ƒ  | j ƒ  | j ƒ  d t' ƒ
 } t | |
 | | ƒ d  S(   Ni    t	   unit_celli
   iZ   t   space_group_symbols   P 1t   crystal_symmetryt
   scattererst   labelt   CR    t   anomalous_flagt   d_mini   R   g{®Gázt?iûÿÿÿi   g      à?(   i
   i
   i
   iZ   iZ   iZ   (   i    i    i    (   iûÿÿÿiûÿÿÿiûÿÿÿ(   i   i   i   (   i    i    i    (   i
   i
   i
   ((   t   syst   stdoutR
   R   t   out_of_bounds_clampt   out_of_bounds_raiseR   t   symmetryR   t	   structureR   t   xray_scatterert	   scattererR   t	   build_sett   Falset!   structure_factors_from_scattererst   f_calct   fft_mapt   apply_sigma_scalingt   real_map_unpaddedR   t   basic_map_unit_cell_flagt   focusR#   t   orthogonalization_matrixt	   as_handleR"   t   fractionalizeR   t   n_realR   R   t   copyt   basic_map_non_symmetric_flagt   basic_map_asu_flagt   space_groupt   direct_space_asut   as_float_asut   True(   t   verboseR   R-   R.   R%   R   t
   miller_setR6   R7   t   real_mapR   R   t   minfract   maxfract   nt   bt   gridding_firstt   gridding_lastt   data(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/tst_real_space_refinement.pyt   exercise_real_space_refinement(   sx    				!			
			88			88						t   __main__s	   --verbosei   (   t
   __future__R    t   cctbx.array_familyR   t   cctbxR   R   R   R   t"   cctbx.maptbx.real_space_refinementR   t   libtbx.math_utilsR   R   t   libtbx.utilsR	   t	   cStringIOR
   R   R+   R"   RQ   t   __name__t   argv(    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/tst_real_space_refinement.pyt   <module>   s    		G