ó
‘™xTc           @   s�   d  d l  m Z d  d l Z d  d l m Z d  d l Z d  d l Z d  d l Z e j	 j
 d ƒ Z d d d d „ Z d „  Z d S(   iÿÿÿÿ(   t   divisionN(   t   Sorrys9  
import_data
  .short_caption = Import data and add/extend R-free flags
  .caption = This utility is used to combine new data with an existing set of     R-free flags, or create new flags if necessary.  All arrays in the data     file will be included to the output.  The reflection file     editor offers additional options for file manipulation.
  .style = box auto_align caption_img:icons/custom/phenix.reflection_file_editor.png
{
  data_file = None
    .type = path
    .short_caption = Data file
    .style = bold file_type:hkl input_file
  flags_file = None
    .type = path
    .short_caption = File with R-free flags
    .style = file_type:hkl input_file
  output_file = None
    .type = path
    .style = bold file_type:hkl new_file
  fraction_free = 0.05
    .type = float
    .short_caption = Fraction to flag for R-free
    .help = Typically between 0.05 and 0.1.  This option is ignored if an       existing set of flags is being extended.
  ignore_shells = False
    .type = bool
    .short_caption = Disable check for test sets in thin shells
    .style = noauto
}
c   #      C   s‘  | d  k r t j } n  t | ƒ d d l m } d d l m } d d l m } | j | j	 j
 d d ƒ} | j d ƒ | j j } g  } d d d	 g }	 g  }
 t } xú | D]ò } | j | | j ƒ  ƒ r t } | j	 j d  k	 r t d
 | j	 j
 ƒ ‚ q n  | j ƒ  rPd |	 k r4|	 j d d d d g ƒ qf|	 j d d d d g ƒ n |	 j | j ƒ  j ƒ | j ƒ  } | j ƒ  s“| j ƒ  j ƒ  } n  | j | ƒ q® W| j | ƒ j ƒ  } | s~| j	 j d  k	 r~| j | j	 j d d ƒ} | j d ƒ | j j d | j d d  d d  d t d d  d t ƒ } t  | ƒ d k rZt d | j	 j ƒ ‚ n3 t  | ƒ d k r�t d d d | j	 j ƒ ‚ n  | d \ } } |	 j | j ƒ  j ƒ | j ƒ  j ƒ  j ƒ  } | j! d | j" ƒ  | k ƒ } | j# | ƒ } | j$ ƒ  j% ƒ  } | j" ƒ  j& t ƒ | j" ƒ  j% ƒ  } | d k re| j' d  | d t ƒ \ } } } } t( | j$ ƒ  j% ƒ  d! ƒ } | | d" k  s£| d! k s£| | k  rõ| j	 j) sèt d# d$ d% d& d' d( d) d* d+ | j	 j ƒ ‚ qõ| d, IJn  | d- k r2d d. l* m+ } | j d | j, | t ƒ ƒ } n | j- d/ | d0 d  d1 t ƒ } | j. d2 | ƒ } n | } | j | ƒ q~n  | d j/ d3 d4 ƒ } xC t0 | d ƒ D]1 \ } } | j1 d  | d3 d5 t2 j3 | d ƒ q¥W| j4 ƒ  } x1 t0 | j5 ƒ  ƒ D] \ } }  |  j6 |	 | ƒ qùW| j	 j7 d  k r]t8 j9 j: | j	 j
 ƒ \ }! }" |! d6 | j	 _7 n  | j; d | j	 j7 ƒ | d7 | j	 j7 IJ| j	 j7 S(8   Niÿÿÿÿ(   t   reflection_file_editor(   t   reflection_file_utils(   t   file_readert
   force_typet   hklt   Ht   Kt   Ls1   The data file (%s) already contains R-free flags.s   F(+)s   F_rec(+)s   SIGF_rec(+)s   F_rec(-)s   SIGF_rec(-)s   SIGF(+)s   F(-)s   SIGF(-)t	   file_namet   labelt   test_flag_valuet   disable_suitability_testt   parameter_scopet   return_all_valid_arraysi    s*   No R-free flags were found in the file %s.i   s6   Multiple valid sets of R-free flags were found in the s<   file %s.  Please use the reflection file editor to select a s   single set of flags.t   datat   miller_arrayg{®Gázt?id   s+   The R-free flags in %s appear to have been s9   assigned in thin resolution shells.  PHENIX is unable to s6   properly extend flags created in this manner.  If you s?   prefer to ignore this check and want to create new flags using s=   random assignment, or if you think this message is in error, s0   you can use the reflection file editor instead. s5   (To view the distribution of R-free flags, click the s8   toolbar button "Other tools" and select "Inspect R-free s   flags".)s   WARNING: ignoring thin shellsi   (   t   flext   fraction_freet   max_freet   use_lattice_symmetryt   othert   column_root_labelt   As   %ss
   _flags.mtzs   Data and flags written to %s(<   t   Nonet   syst   stdoutt   validate_paramst   iotbxR   R   R   t   any_filet   import_datat	   data_filet   check_file_typet   file_servert   miller_arrayst   Falset   is_rfree_arrayt   infot   Truet
   flags_fileR   t%   is_xray_reconstructed_amplitude_arrayt   extendt   labelst
   map_to_asut   is_unique_set_under_symmetryt   merge_equivalentst   arrayt   appendt   make_joined_sett   complete_sett   get_r_free_flagsR
   t   lent   customized_copyR   t   lone_sett   indicest   sizet   countt   get_r_free_statst   intt   ignore_shellst   scitbx.array_familyR   t   boolt   generate_r_free_flagst   concatenatet   as_mtz_datasett	   enumeratet   add_miller_arrayt   stringt	   uppercaset
   mtz_objectt   columnst	   set_labelt   output_filet   ost   patht   splitextt   write(#   t   argst   paramst   outR   R   R   t   data_inR#   t
   new_arraysR+   t   warningst   have_r_freeR/   R2   t   flags_int   flags_and_valuest	   old_flagsR   t   missing_sett	   n_missingR   t   n_binst   n_freet   sset   accut   min_binsR   t   missing_flagst	   new_flagst   mtz_outt   it   mtz_objt   columnt   baset   ext(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/gui_tools/import_data_and_flags.pyt   run.   s¼    
					%	(!				c         C   sV   |  j  j d  k r! t d ƒ ‚ n1 t j j |  j  j ƒ sR t d |  j  j ƒ ‚ n  t S(   Ns   Please specify a data file.s   %s is not a recognizable file.(   R   R    R   R   RJ   RK   t   isfileR'   (   RO   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/gui_tools/import_data_and_flags.pyR   ™   s
    (    (   t
   __future__R    t   libtbx.philt   libtbxt   libtbx.utilsR   RD   RJ   R   t   philt   parset   master_philR   Rg   R   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/gui_tools/import_data_and_flags.pyt   <module>   s   		k