ó
±™xTc           @   sÙ   d  d l  m Z d  d l Z d  d l m Z m Z d  d l m Z d  d l	 Z
 d  d l Z d  d l m Z d  d l m Z d Z d „  Z d	 „  Z d
 „  Z d „  Z d d „ Z e d k rÕ e e j d ƒ d GHn  d S(   iÿÿÿÿ(   t   divisionN(   t   millert   crystal(   t   flex(   t   Sorry(   t   maptbxs¬   
output_file_name = map_to_structure_factors.mtz
  .type=str
d_min = None
  .type=float
k_blur = 1
  .type = float
b_blur  = 100
  .type = float
box = False
  .type = bool
c           C   s   t  j j t d t ƒS(   Nt   process_includes(   t   iotbxt   philt   parset   master_params_strt   True(    (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/map_to_structure_factors.pyt   master_params   s    c         C   s0   | d d IJ| |  IJ| d t  |  ƒ IJd  S(   Nt   -iO   t   *(   t   len(   t   mt   log(    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/map_to_structure_factors.pyt	   broadcast   s    
c         C   s±   |  j  ƒ  j ƒ  } t j | ƒ } t j | ƒ } d t j |  j ƒ  j ƒ  ƒ d } d | t j | | ƒ } | | } | | }	 t j d | d |	 ƒ }
 |  j	 d |
 ƒ } | S(   Ng      ð?g      @i   t   at   bt   data(
   t   phasesR   R   t   sint   cost   pow2t
   d_spacingst   expt   hendrickson_lattmant   customized_copy(   t
   f_obs_cmplt   k_blurt   b_blurt   f_model_phasest   sin_f_model_phasest   cos_f_model_phasest   sst   tt
   hl_a_modelt
   hl_b_modelt   hl_datat   hl(    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/map_to_structure_factors.pyt   get_hl!   s    #

c         C   s(   t  |  ƒ j d | ƒ } | j d |  ƒ S(   Nt   phase_sourcet   other(   t   abst   phase_transfert   map_correlation(   t   fR)   t
   map_coeffs(    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/map_to_structure_factors.pyt   get_cc-   s    c      	   C   sY  t  j j d |  d t ƒ  ƒ } t } t d d d | ƒ | j j d d ƒ | j j ƒ  } | j	 d  k	 r¤ t d d | j d | ƒ | j	 } | j d d ƒ t } n  | s¹ t d	 ƒ ‚ n  | } t d d
 d | ƒ d G| j j ƒ  GHd G| j j ƒ  GHd G| j j ƒ  GHd G| j j ƒ  GHd G| j j ƒ  GHd G| j j ƒ  GHd G| j j ƒ  GHd Gt j | j ƒ Gt j | j ƒ Gt j | j ƒ GHd G| j GH| j j ƒ  s¯t d ƒ ‚ n  | j j ƒ  } t j | j d ƒ } t j d | j  ƒ  d | j! ƒ  d | ƒ }	 | j" }
 |
 d  k rC| j# rCt  j j$ d | j d | j  ƒ  ƒ }
 n  |
 d  k rÅg  | D] } | d d ^ qV} d G| GHt% j& d | d t d | ƒ } | j' ƒ  } | j( d= ƒ | j) d  | ƒ } n t% j& d | d t d! |
 ƒ } t d d" d | ƒ | j* d d ƒ y1 | j+ d# | j j, ƒ  d$ t d t d% t ƒ } WnL t- k
 r…} t. | ƒ d& k rpd' } t | ƒ ‚ q†t t. | ƒ ƒ ‚ n X| j/ d( d) ƒ } | j0 d* t1 | ƒ d( d+ ƒ t d d, d | ƒ t2 d- | d. | j3 d/ | j4 ƒ } t5 d0 | d1 | ƒ } d2 G| GHt1 d3 | ƒ d4 k rúd5 GHd6 } | j4 } x… t6 d d7 ƒ D]t } t2 d- | d. | j3 d/ | ƒ } t5 d0 | d1 | ƒ } | | k  r”| } | } n  t1 d3 | ƒ d4 k  r@| } Pq@q@Wt2 d- | d. | j3 d/ | ƒ } d2 Gt5 d0 | d1 | ƒ GHd8 G| GHn  | j0 d* | d( d9 ƒ t d d: d | ƒ | d; I| j7 IJ| j8 ƒ  } | j9 d< | j7 ƒ d  S(>   Nt   argsR   R   s   Parameters:R   t   prefixs     s"   Processing input CCP4 map file: %ss   Map file is needed.s   Input map information:s   m.all()   :s   m.focus() :s   m.origin():s   m.nd()    :s   m.size()  :s   m.focus_size_1d():s   m.is_0_based()   :s   map: min/max/mean:s
   unit cell:s@   Map must have origin at (0,0,0): recenter the map and try again.i   t	   unit_cellt   space_group_infot   pre_determined_n_realt   map_datai   s
   max_index:t   crystal_symmetryt   anomalous_flagt	   max_indexi    t   indicest   d_mins   Complete set information:t   mapt	   use_scalet   use_sgs6   cctbx Error: Miller index not in structure factor map.s=   Too high resolution requested. Try running with larger d_min.t   column_root_labelt   Ft   miller_arrayt   F_ampls$   Convert phases into HL coefficeints:R   R   R    R0   R)   s   cc:g      ð?gü©ñÒMbP?s?   Supplied b_blur is not good. Attempting to find optimal b_blur.g     8�@id   s   b_blur_best:t   HLs   Writing output MTZ file:s     file name:t	   file_name(   i    i    i    (:   t   mmtbxt   utilst   process_command_line_argsR   t   FalseR   t   paramst   showt   extractt   ccp4_mapt   Nonet   ccp4_map_file_namet   show_summaryR   R   R   t   allt   focust   origint   ndt   sizet   focus_size_1dt
   is_0_basedR   t   mint   maxt   meant   unit_cell_parametersR   t   symmetryR   t   crystal_griddingR5   R6   R=   t   boxt   d_min_from_mapR   t	   build_setR<   t   appendR   t   show_comprehensive_summaryt   structure_factors_from_mapt	   as_doublet	   Exceptiont   strt   as_mtz_datasett   add_miller_arrayR-   R*   R   R    R2   t   ranget   output_file_namet
   mtz_objectt   write(   R3   R   t   inputst   got_mapRK   RN   R   t   n_realt   csR^   R=   t   iR;   t   complete_setR<   R   t   et   msgt   mtz_datasetR)   t   cct   cc_bestt   b_blur_bestR    Rl   (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/map_to_structure_factors.pyt   run1   sÀ    		5				!							!				t   __main__i   s	   All done.(   t
   __future__R    t   iotbx.ccp4_mapR   t   cctbxR   R   t   cctbx.array_familyR   t   mmtbx.utilsRG   t   syst   libtbx.utilsR   R   R
   R   R   R*   R2   RO   Rz   t   __name__t   argv(    (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/map_to_structure_factors.pyt   <module>   s    				x