ó
xTc           @   sĐ   d  d l  m Z d  d l Z d  d l m Z d  d l m Z m Z d  d l Z d  d l	 Z	 e j
 j d d e Z e	 j d  Z d e j f d	     YZ d
   Z d   Z e d k rĚ e e	 j d  n  d S(   i˙˙˙˙(   t   divisionN(   t   runtime_utils(   t   Sorryt   Usagesy  
french_wilson {
  file_name = None
    .type = path
    .short_caption = Reflections
    .help = '''input intensity data file (mtz)'''
    .style = bold file_type:hkl process_hkl child:iobs:intensity_labels       child:rfree:r_free_flags.label input_file
  intensity_labels = None
    .type = strings
    .style = bold renderer:draw_fobs_label_widget
    .input_size = 160
  r_free_flags.label = None
    .type = str
    .short_caption = R-free label
    .style = bold renderer:draw_rfree_label_widget
    .input_size = 160
  output_file = None
    .type = path
    .optional = True
    .help = '''Enter a .mtz output name'''
    .style = bold file_type:hkl new_file
  include scope libtbx.phil.interface.tracking_params
  keep_r_free_flags = True
    .type = bool
    .help = "Keep R-free flag data if present"
    .short_caption = Keep R-free flags if present in input file
  include scope cctbx.french_wilson.master_phil
  sigma_iobs_rejection_criterion = None
    .type=float
    .short_caption = Sigma(Iobs) rejection criterion
  wavelength = None
    .type = float
    .help = Optional, defaults to value defined in input file (if any)
}
t   process_includesc         C   s  d d l  m } d d l m } d  } g  } t j   } x¨ |  D]  } t j j	 |  rŔ | j
 |  } | j d k r | } | j | j d d |   qß | j d k rß | j | j  qß q? | j d |  }	 | j |	  q? Wt j d |  }
 |
 j   } | j j d  k r@| d  k r.t d	   qd| j | j _ n$ | d  k rd| j
 | j j  } n  | j } | j } | j d
 j   } | d  k r¨t d d   n  | j d
 j   } | d  k rÚt d d   n  d  } | j d | j d | j d t d d d d  } d d  l } | j   | _ y= | j d | j d | j j  d d  d t! d d  \ } } Wn t k
 r} d  } n X| d  k rt d   n  | j" } | d  k rř| j#   } | d  k	 rř| j" } | d  k	 rő| d | IJqőqřn  | j j$ } | j%   s/| d IJ| j&   j'   } n  | j( d | d | d | d  |  } | d  k rrt d! d"   n  | j) d  k rd# } n	 | j) } | j* d$ d% d& |  } | j+ d | d$ d'  | d  k	 rď| j, rď| j+ d | d$ d(  n  | j-   } | j. d |  | d) | IJ| S(*   Ni˙˙˙˙(   t   french_wilson(   t   file_readert   hklt   args   file_name="%s"t   philt   sourcess8   phenix.french_wilson data.mtz [params.eff] [options ...]i    s;   No crystal symmetry found.  This program requires an input s*   format with complete symmetry information.s4   No unit cell found.  This program requires an input s+   format with complete unit cell information.t	   file_namet   labelst   ignore_all_zerost   parameter_scopeR   t   parameter_namet   intensity_labelst   labelt   test_flag_valuet   disable_suitability_tests   french_wilson.r_free_flagss   Couldn't find intensities!s#   Using wavelength=%g from input files'   Merging symmetry-equivalent reflectionst   miller_arrayt   paramst   sigma_iobs_rejection_criteriont   logs=   Not enough data to accurately apply the French-Wilson method.s	    Exiting.s   french_wilson.mtzt   column_root_labelt   It
   wavelengtht   Fs   R-free-flagss   Wrote %s(/   t   cctbxR   t   iotbxR   t   Nonet   master_philt!   command_line_argument_interpretert   ost   patht   isfilet   any_filet	   file_typet   appendt   processt   file_objectt   fetcht   extractR   R   t   file_servert   miller_arrayst   crystal_symmetryR   t	   unit_cellt   get_xray_dataR   t   Truet	   cStringIOt   StringIOt   errt   get_r_free_flagst   r_free_flagsR   t   FalseR   t   infoR   t   is_unique_set_under_symmetryt   merge_equivalentst   arrayt   french_wilson_scalet   output_filet   as_mtz_datasett   add_miller_arrayt   keep_r_free_flagst
   mtz_objectt   write(   t   argst   outR   R   t   hkl_fileR
   t   interpreterR   t
   input_filet   arg_philt	   work_philt   work_paramsR   t   xray_data_serverR-   R.   t   i_obsR1   R5   R   t   eR   R7   R   t   f_obsR<   t   mtz_datasetR@   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/french_wilson.pyt   run/   s°     								
		
							
t   launcherc           B   s   e  Z d    Z RS(   c         C   s   t  d t |  j  d t j  S(   NRB   RC   (   RO   t   listRB   t   syst   stdout(   t   self(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/french_wilson.pyRO      s    (   t   __name__t
   __module__RO   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/french_wilson.pyRP      s   c         C   sJ   |  j  j d  k r! t d   n% |  j  j d  k rF t d d   n  t S(   Ns"   Please specify a reflections file.s:   No intensity labels selected; are you sure the input file s   contains appropriate data?(   R   R   R   R   R   R0   (   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/french_wilson.pyt   validate_params   s    c         C   s2   g  } |  d  k	 r( | j |  d f  n  | g  f S(   Ns   Corrected amplitudes(   R   R&   (   t   resultt   output_files(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/french_wilson.pyt
   finish_job   s    t   __main__i   (   t
   __future__R    t   libtbx.philt   libtbxR   t   libtbx.utilsR   R   R!   RR   R	   t   parseR0   R   RS   RO   t   target_with_save_resultRP   RW   RZ   RU   t   argv(    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/french_wilson.pyt   <module>   s   	#^		