ó
©™xTc           @   s3  d  d l  m Z d  d l m Z d  d l m Z m Z m Z d  d l Z	 d  d l	 m
 Z
 d  d l	 m Z d  d l	 m Z d  d l Z d  d l m Z d  d	 l m Z d  d
 l m Z m Z d  d l Z d  d l Z d  d l m Z e j ƒ  Z e	 j j e j ƒ  ƒ Z d „  Z e d k r/e e j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   crystal(   t   Sorryt   date_and_timet	   multi_outN(   t   reflection_file_reader(   t   reflection_file_utils(   t   crystal_symmetry_from_any(   t   pair_analyses(   t   StringIO(   t	   pre_scalet
   make_param(   t   fa_estimationc       	   C   sÅ
  t  |  ƒ d k r% t j d d ƒ nœ
d |  k r9 d GHnˆ
d |  k rM d GHnt
d |  k rl t j d d ƒ nU
d |  k r‹ t j d d	 ƒ n6
t ƒ  } d
 |  k r¼ | j d d d t j ƒ n  t ƒ  } t ƒ  } | j d d d | ƒ t ƒ  } | d IJ| J| t ƒ  IJ| J| Jg  } t j	 d d ƒ } d  } xˆ|  D]€} d  }	 t }
 | d
 k r\t }
 n  t j j | ƒ ry t j j d | ƒ }	 Wn$ t k
 r�‚  n t k
 r­n X|	 d  k	 rÐ| j |	 ƒ t }
 n  |	 d  k r÷t j d | d t ƒ } n  | d  k	 rt| } t }
 qtn_ y8 | j d | ƒ }	 |	 d  k	 rL| j |	 ƒ t }
 n  Wn$ t k
 rc‚  n t k
 rsn X|
 s5| d IJ| d I| IJ| d IJ| Jt d | ƒ ‚ q5q5Wt j d | ƒ } | j ƒ  } d  } | j j j j j  GHt! j" d | j j j j j  ƒ } | j j j j# d  k rO| j$ ƒ  | j j j _# | d IJn  | j j j j% d  k rŒ| j% ƒ  | j j j _% | d IJn  | j j j j# d  k r³t d ƒ ‚ n  | j j j j% d  k rÚt d ƒ ‚ n  t& j' d | j j j j% d t( | j j j j# ƒ ƒ } } t j d | ƒ } t j) d | ƒ } | d  IJ| d! IJ| j d" | d | j j j* ƒ | d# IJ| Jt+ j, d$ | d% t d& g  ƒ } d  } | j- d | j j j j j  d' | j j j j j. d( t d) d* ƒ } | j/ ƒ  } | j0 ƒ  j1 | j2 ƒ  dL k ƒ } | j1 | j3 ƒ  d k ƒ } | j4 ƒ  rB| j5 ƒ  } n | j6 ƒ  r]t7 | ƒ } n  | j8 ƒ  sxt d+ ƒ ‚ n  | j9 d, | ƒ d  } | j- d | j j j j: j  d' | j j j j: j. d( t d) d- ƒ } | j/ ƒ  } | j0 ƒ  j1 | j2 ƒ  dM k ƒ } | j1 | j3 ƒ  d k ƒ } | j4 ƒ  r3| j5 ƒ  } n | j6 ƒ  rNt7 | ƒ } n  | j8 ƒ  sit d. ƒ ‚ n  | j9 d, | ƒ | j; ƒ  s‹t< ‚ | j; ƒ  s�t< ‚ | J| d/ IJ| d0 IJ| j= d1 | ƒ | Jt> j? | | j j j@ jA | j j jB ƒ } | jC jD ƒ  } ~ | J| d2 IJ| d0 IJ| j= d1 | ƒ | Jt> j? | | j j j@ jA | j j jB ƒ } | jC jD ƒ  } ~ | J| d3 IJ| d4 IJ| J| d5 IJ| d6 IJ| d7 IJ| JtE jF d8 | d9 | d" | ƒ } | jG ƒ  } | j0 ƒ  | J| d: IJ| d; IJ| JtH jI | | | j j j@ jJ ƒ } | jC jD ƒ  } | jK jD ƒ  } ~ | J| d< IJ| d= IJ| JtE jL | | ƒ } tE jM | | ƒ } | jN } | jN } | d  k	 r³| J| d> | jN IJn  | d  k	 r	| d? | jN IJ| J| d@ IJ| dA IJ| dB IJ| dC IJ| Jn  | j j j j jO d  k	 rƒ	| j j j j: jO d  k	 rƒ	| j j j j jO | j j j j: jO } | dD IJ| dE | IJ| Jqƒ	n  | j j j j jP d  k	 r4
| j j j j: jP d  k	 r4
| j j j j: jO d  k	 r1
| j j j j jP | j j j j: jP | j j j j: jO } | dF IJ| dG | IJ| Jq1
q4
n  tH jQ | | | | | j j jH ƒ } | J| dH IJ| dI IJ| J| jR } | jS dJ dK | j j jT jU ƒ } | jV ƒ  jW d | j j jT jX ƒ d  S(N   Ni    t   expert_levelid   s   --helps   no help availables   --hs   --show_defaultss   --show_defaults_alli
   s   --quiett   labelt   stdoutt   file_objectt
   log_buffers   #phil __OFF__t
   home_scopet   scalingt	   file_namet   ensure_read_accesst   args2   ##----------------------------------------------##s%   ## Unknown phil-file or phil-command:s'   Unknown file format or phil command: %st   sourcess   Using symmetry of native datas   Using cell of native datas   No space group defineds   No unit cell definedt	   unit_cellt   space_group_symbolt   python_objects   Effective parameterss   #phil __ON__t   outs   #phil __END__t   crystal_symmetryt   force_symmetryt   reflection_filest   labelst   ignore_all_zerost   parameter_scopes(   scaling.input.SIR_scale.xray_data.natives'   miller_array_native is not a real arrayt   infos,   scaling.input.SIR_scale.xray_data.derivatives+   miller_array_derivative is not a real arrays   Wavelength 1s   ============t   fs   Wavelength 2s(   Checking for possible reindexing schemess(   ----------------------------------------s,   Reindexing operator derived as described in:s2   Grosse-Kunstleve, Afonine, Sauter & Adams. (2005).s)     IUCr Computing Commission Newsletter 5.t   set_at   set_bs)   Relative scaling of 2-wavelength mad datas)   -----------------------------------------s   Estimating f" and f' ratioss   ----------------------------s(     The estimate of f"(w1)/f"(w2) is %3.2fs1     The estimate of (f'(w1)-f'(w2))/f"(w2) is %3.2fs:     The quality of these estimates depends to a large extends5     on the quality of the data. If user supplied valuess4     of f" and f' are given, they will be used instead s     of the estimates.s"       Using user specified f" valuess+         user specified f"(w1)/f"(w2) is %3.2fs)       Using user specified f" and f' valuess*        user specified f"(w1)/f"(w2) is %3.2fs   writing mtz files   ----------------t   column_root_labelt   F(   i    i    i    (   i    i    i    (Y   t   lent   master_paramst   showR   t   registert   sysR   R	   R   t!   command_line_argument_interpretert   Nonet   Falset   Truet   ost   patht   isfilet   iotbxt   philt   parset   KeyboardInterruptt	   Exceptiont   appendR   t   any_reflection_filet   processR   t   fetcht   extractR   t   inputt	   xray_datat   wavelength1R   R   t   extract_fromt   space_groupt   space_group_infoR   R   t   symmetryt   strt   formatR   R   t   reflection_file_servert   get_xray_dataR   R"   t
   map_to_asut   selectt   indicest   datat   is_xray_intensity_arrayt	   f_sq_as_ft   is_complex_arrayt   abst   is_real_arrayt   set_infot   wavelength2t   anomalous_flagt   AssertionErrort   show_comprehensive_summaryR
   t
   pre_scalert   scaling_strategyt   pre_scaler_protocolt   basict   x1t	   deep_copyR   t
   reindexingt   select_and_transformR   t   combined_scalingt   iso_protocolt   x2t   f_double_prime_ratiot"   delta_f_prime_f_double_prime_ratiot   ratiot   f_double_primet   f_primet   twmad_fa_drivert	   fa_valuest   as_mtz_datasett   outputt   outlabelt
   mtz_objectt   writet   hklout(    t   argst   logt   string_buffert   string_buffer_plotst	   log_plotst   phil_objectst   argument_interpretert   reflection_fileR   t   command_line_paramst   arg_is_processedt   effective_paramst   paramst   crystal_symmetry_natR   t
   new_paramst   xray_data_servert   miller_array_w1t   info_nativet   miller_array_w2t   info_w2t   w1_pre_scalet   w2_pre_scalet   reindex_objectt   scalert   fdpratiot
   fpfdpratiot   k1t   k2t   fa_gent   fat   mtz_dataset(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/scaling/twmad_scale.pyt   run   sÖ   				
			  		  

		


						








		




				







	

		t   __main__i   (    t
   __future__R    t   cctbxR   t   libtbx.utilsR   R   R   t
   iotbx.philR4   R   R   R   t   mmtbx.scalingt   mmtbxR   t   libtbx.str_utilsR	   R
   R   R,   R1   R   t	   phil_legot   params_generatorR5   R6   t   default_2wmadR)   R�   t   __name__t   argv(    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/scaling/twmad_scale.pyt   <module>   s$   	ÿ 8