ó
Ü™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
 Z e j j d ƒ Z d  d l m Z d  d	 l m Z d  d l Z d  d
 l m Z d  d l Z d  d l Z d e f d „  ƒ  YZ d „  Z e d k re j ƒ  Z e ƒ  d e j ƒ  e GHn  d S(   iÿÿÿÿ(   t   division(   t   flex(   t   miller(   t   random_structure(   t   space_group_infoNt   cctbx_asymmetric_map_ext(   t   composite_omit_map(   t   maptbx(   t   approx_equalt   omit_p1_specificc           B   s   e  Z d  Z d d „ Z RS(   sñ   
  Composite full-omit map: omit entire box in real-space corresponding to Fmodel,
  which includs atomic model and non-atomic model (bulk-solvent and scales).
  ASU maps are not use, so this is limited to P1 only. Use for this test only.
  c      
      sƒ  | j  ƒ  j ƒ  j ƒ  } | j ƒ  d k s0 t ‚ d  ‡  f d † } | j ƒ  } t j d ˆ  d | ƒ } | j	 ƒ  }	 | j
 d t j | j ƒ  j ƒ  d ƒ ƒ }
 t j d |	 j ƒ  d | ƒ } t j t j | j ƒ ƒ |  _ t j ƒ  |  _ xFt | j | j ƒ D]/\ } } t j d	 d d
 |	 d | d | ƒ } | j d | d t d t d t ƒ } t j j  d | j  ƒ  d | j! ƒ  d | d |
 ƒ } |  j j" | j# ƒ  ƒ | d | d | ƒ } | d d | d d | d d g } t j$ | | | ƒ } | j% t j | j& ƒ  ƒ ƒ t j' d | d
 |  j d | d | ƒ qý W|  j j( ƒ  } |  j | |  _ | j  ƒ  j d |  j d t d t d t ƒ |  _) d  S(   Ni   c            sF   |  j  ƒ  j d | d t d t ƒ } t j d ˆ  d | ƒ } | j ƒ  S(   Nt   map_typet
   isotropizet   fill_missingt   crystal_griddingt   fourier_coefficients(   t   electron_density_mapt   map_coefficientst   Truet   FalseR   t   fft_mapt   real_map_unpadded(   t   fmodelR
   t   external_complete_sett   f_mapR   (   R   (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/tst_composite_omit_map.pyt   get_map   s    			R   R   t   datai    t   n_realt   fractiont   valuet   map_data_tot   startt   endt   mapt	   use_scalet   anomalous_flagt   use_sgt   f_obst   r_free_flagst   f_calct   f_maskR   R
   i   t   map_data_from(*   R$   t   space_groupt   typet   numbert   AssertionErrort   Nonet   f_model_scaled_with_k1R   R   R   t   customized_copyR   t   complex_doubleR   t   sizeR   t   boxest   focust   doublet   gridR   t
   map_resultt   rt   zipt   startst   endst   set_box_copyt   structure_factors_from_mapR   R   t   mmtbxt   f_modelt   managerR%   t   appendt   r_workt   copyt   reshapet   allt   set_boxt   sample_standard_deviationR   (   t   selfR   R   R
   t   box_size_as_fractiont   sgtR   R>   R   t   f_model_map_datat   zero_complex_mat   bt   st   et   f_model_map_data_omitt   f_model_omitt   fmodel_t
   f_map_datat   etmpt   boxt   sd(    (   R   sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/tst_composite_omit_map.pyt   __init__   s`    				!		"					'			N(   t   __name__t
   __module__t   __doc__R-   RV   (    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/tst_composite_omit_map.pyR	      s   c          C   s1  t  j d t d ƒ d d d t d d, d d d ƒ }  |  j d d ƒ t |  j d d ƒ j ƒ  ƒ } |  j d d ƒ |  j	 d d ƒ } |  j
 | ƒ }  t j j d |  d | ƒ } | j d t ƒ | j ƒ  j d | j ƒ  j ƒ  d t j d d ƒ } t d | d | j ƒ  d d d  d! ƒ } t j d | d | j ƒ  d" t d d d# d$ d% d& d  d! ƒ } t | j | j ƒ sot ‚ d' „  } t | j ƒ j ƒ  j ƒ  j ƒ  GHt | j ƒ j ƒ  j ƒ  j ƒ  GHt t j  d( t | j ƒ j ƒ  d) t | j ƒ j ƒ  ƒ j! ƒ  d ƒ st ‚ t | d( | j d) | j ƒ d* ƒ s-t ‚ d+ S(-   s†   
  This test makes sure that composite full omit maps calculated using Marat's
  ASU map code and not using ASU maps exactly match.
  R   s   P 1t   volume_per_atomiú   t   general_positions_onlyt   elementst   Ct   Nt   Ot   Si2   t   min_distanceg      ð?t   tablet   wk1995t   d_mini   t   mean_distanceg333333Ó?R   gš™™™™™¹?t   xray_structureR$   t   update_f_part1t   symmetry_flagst   resolution_factorg      Ð?R   R   R
   t   FoRH   gš™™™™™©?t   full_resolution_mapt   n_debias_cyclesi   t    neutral_volume_box_cushion_widthi    c         S   s‘   t  j t |  ƒ j ƒ  ƒ }  t  j t | ƒ j ƒ  ƒ } t  j |  | ƒ t  j | | ƒ } t  j t  j |  | | ƒ ƒ t  j |  | | ƒ d S(   Ni   (   R   t   absR   t   sum(   t   xt   yt   sc(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/tst_composite_omit_map.pyt   r_factor}   s    $Rp   Rq   g        N(   R]   R^   R_   R`   ("   R   Rf   R   R   t   scattering_type_registryRn   t   structure_factorsR&   t   shake_sites_in_placet   random_remove_sites_selectiont   selectR=   R>   R?   t   update_all_scalesR$   R   Rd   R   t   use_space_group_symmetryR	   t	   deep_copyt   cfomt   runR   R7   R,   R   R   t   min_max_meant   as_tupleR   t   linear_correlationt   coefficient(   t   xrsR$   t   selR   R   t   r1t   r2Rs   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/tst_composite_omit_map.pyR}   T   sR    	
								  *	t   __main__s   Time: %6.4f(   t
   __future__R    t   scitbx.array_familyR   t   cctbxR   t   cctbx.developmentR   t   cctbx.sgtbxR   t   boost.pythont   boostt   pythont
   import_extt   asu_map_extt
   mmtbx.mapsR   R|   R   R=   t   libtbx.test_utilsR   t   mmtbx.f_modelt   timet   objectR	   R}   RW   t   t0(    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/tst_composite_omit_map.pyt   <module>   s$   E	6