ó
z™xTc           @   sÐ  d  d l  m Z d  d l Z d  d l m Z m Z m Z d  d l m	 Z	 m
 Z
 d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z e Z e j j d d e ƒZ d e
 f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z  d „  Z! e e e e j" d „ Z# e j" d „ Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) e j" d d „ Z* e d „ Z+ d „  Z, e j" d „ Z- e. d k rÌe- e j/ d ƒ n  d S(    iÿÿÿÿ(   t   divisionN(   t   Sorryt   null_outt    check_if_output_directory_exists(   t   adopt_init_argst   slots_getstate_setstates2#  
show_arrays = False
  .type = bool
  .help = Command-line option, prints out a list of the arrays in each file
  .style = hidden
dry_run = False
  .type = bool
  .help = Print out final configuration and output summary, but don't write           the output file
  .style = hidden
verbose = True
  .type = bool
  .help = Print extra debugging information
  .style = hidden
mtz_file
{
  crystal_symmetry
    .caption = By default, the input crystal symmetry will be used for the       output file.
    .style = auto_align menu_item
  {
    unit_cell = None
      .type = unit_cell
      .style = bold noauto
    space_group = None
      .type = space_group
      .style = bold noauto
    output_unit_cell = None
      .type = unit_cell
      .style = bold noauto
    output_space_group = None
      .type = space_group
      .style = bold noauto
    change_of_basis = None
      .type = str
      .expert_level = 2
    eliminate_invalid_indices = False
      .type = bool
      .expert_level = 2
    expand_to_p1 = False
      .type = bool
      .short_caption = Expand to P1
      .style = bold
    disable_unit_cell_check = False
      .type = bool
      .style = noauto
      .short_caption = Disable unit cell isomorphism check
    disable_space_group_check = False
      .type = bool
      .style = noauto
    eliminate_sys_absent = True
      .type = bool
      .short_caption = Eliminate systematic absences
  }
  d_max = None
    .type = float
    .short_caption = Low resolution
    .style = bold renderer:draw_hkltools_resolution_widget
  d_min = None
    .type = float
    .short_caption = High resolution
    .style = bold renderer:draw_hkltools_resolution_widget
  wavelength = None
    .type = float
    .short_caption = Wavelength
    .style = bold
  output_file = None
    .type = path
    .short_caption = Output file
    .style = file_type:mtz new_file bold noauto
  include scope libtbx.phil.interface.tracking_params
  resolve_label_conflicts = False
    .type = bool
    .help = Updates label names as necessary to avoid conflicts
    .short_caption = Automatically resolve output label conflicts
    .style = noauto bold
  exclude_reflection = None
    .multiple = True
    .optional = True
    .type = ints(size=3)
    .input_size = 100
    .style = noauto menu_item
  miller_array
    .multiple = True
    .short_caption = Output data array
    .style = fixed auto_align
  {
    file_name = None
      .type = path
      .style = noedit bold
    labels = None
      .type = str
      .short_caption = Array name
      .style = noedit bold
    output_labels = None
      .type = strings
      .optional = True
      .short_caption = Output column labels
      .input_size = 300
      .help = Most Miller arrays have more than one label, and there must be               exactly as many new labels as the number of labels in the               old array.  Note however that the output labels do not               necessarily correspond to the original array name.  (See caveat               in Phenix manual about Scalepack files.)
      .style = fixed
    column_root_label = None
      .type = str
      .optional = True
      .short_caption = Base column label
      .help = If specified, this is applied to all columns in the output         array with default prefixes and suffixes.  Overrides the         output_labels parameter.
      .input_size = 200
    d_min = None
      .type = float
      .short_caption = High resolution
    d_max = None
      .type = float
      .short_caption = Low resolution
    output_as = *auto intensities amplitudes_fw amplitudes
      .type = choice
      .short_caption = Output diffraction data as
      .caption = Automatic Intensities Amplitudes_(run_French-Wilson)         Amplitudes_(simple_conversion)
      .help = If the Miller array is amplitudes or intensities, this flag         determines the output data type.  If intensities are being converted         to amplitudes, this can optionally be done using the French and         Wilson treatment to correct weak and negative values.
    anomalous_data = *Auto merged anomalous
      .type = choice
      .caption = automatic_(keep) merge_if_present force_anomalous_output
      .short_caption = Anomalous data
      .help = Optional averaging or generation of Bijvoet mates.  Note that the         number of labels expected may change.
    force_type = *auto amplitudes intensities
      .type = choice
      .short_caption = Force observation type
      .help = If the Miller array is amplitudes or intensites, this flag         allows the observation type to be set without modifying the data.         This is primarily used for structure factors downloaded from the PDB,         which sometimes have the data type specified incorrectly.
    scale_max = None
      .type = float
      .short_caption = Scale to maximum value
      .help = Scales data such that the maximum is equal to the given value
    scale_factor = None
      .type = float
      .help = Multiplies data with the given factor
    remove_negatives = False
      .type = bool
      .short_caption = Remove negative values
    massage_intensities = False
      .type = bool
    filter_by_signal_to_noise = None
      .type = float
      .short_caption = Filter by signal-to-noise ratio
    add_b_iso = None
      .type = float
      .short_caption = Add isotropic B-factor
    add_b_aniso = 0 0 0 0 0 0
      .type = floats(size=6)
      .short_caption = Add anisotropic B-factor
    shuffle_values = False
      .type = bool
    reset_values_to = None
      .type = float
      .short_caption = Reset values to
      .help = If defined, all data values will be set to this number.  Sigmas         will be left unmodified.  Only applies to single-value floating-point         data (I, F, PHI, etc.).
  }
  r_free_flags
    .short_caption = R-free flags generation
    .style = menu_item auto_align box
  {
    generate = True
      .type = bool
      .short_caption = Generate R-free flags if not already present
      .style = bold noauto
    force_generate = False
      .type = bool
      .short_caption = Generate R-free flags even if they are already present
    new_label = FreeR_flag
      .type = str
      .short_caption = Output label for new R-free flags
      .input_size = 160
      .style = bold noauto
    include scope cctbx.r_free_utils.generate_r_free_params_str
    random_seed = None
      .type = int
      .short_caption = Seed for random number generator
      .expert_level = 2
    extend = None
      .type = bool
      .short_caption = Extend existing R-free array(s) to full resolution range
      .style = bold noauto
    old_test_flag_value = None
      .type = int
      .short_caption = Original test flag value
      .help = Overrides automatic guess of test flag value from existing set.         This will usually be 1 for reflection files generated by Phenix, and         0 for reflection files from CCP4.  Do not change unless you're sure         you know what flag to use!
      .expert_level = 2
    export_for_ccp4 = False
      .type = bool
      .short_caption = Convert R-free flags to CCP4 convention
      .help = If True, R-free flags expressed as boolean values (or 0 and 1)         will be converted to random integers from 0 to 19, where 0 denotes         the test set.  Phenix will work with either convention, but most CCP4         programs expect the test set to be 0.
      .expert_level = 2
      .style = noauto
    preserve_input_values = True
      .type = bool
      .short_caption = Preserve original flag values
      .help = If True, CCP4-style R-free flags will be left as random         integers instead of being converted to a boolean array.  This option         is not compatible with the option to export flags to the CCP4         convention.
      .style = noauto
    warn_if_all_same_value = True
      .type = bool
      .short_caption = Warn if R-free flags are all the same value
    adjust_fraction = False
      .type = bool
      .short_caption = Adjust test set size to specified fraction
      .help = If True, the R-free flags will be resized as necessary.  This         may be useful when the current set is too large or too small, but         needs to be preserved (at least in part).  The target fraction will         be relative to all possible reflections, even those not measured in         the input.  Note that this option is not compatible with preserving         input values.
    d_eps = 0.0001
      .type = float
      .short_caption = Resolution buffer
      .expert_level = 2
    relative_to_complete_set = False
      .type = bool
      .short_caption = Generate R-free flags relative to complete set
    remediate_mismatches = False
      .type = bool
      .short_caption = Remediate mismatching Friedel/Bijvoet pairs
      .help = If True, flags that differ between F+ and F- will be moved into         the test set for both reflections.  This option is incompatible with         preserving the input values as integers.
  }
}t   process_includest   array_inputc           B   s,   e  Z d  d d g Z d d „ Z d „  Z RS(   t   miller_arrayst
   file_namest   array_typesc         C   s&  d d l  m } | d  k r% i  } n  g  |  _ g  |  _ g  |  _ xßt | j j ƒ D]Ë\ } } | j	 d  k r” t
 d | d t | j ƒ f ƒ ‚ n+ t j j | j	 ƒ s¿ t
 d | j	 ƒ ‚ n  | j | j	 ƒ } | d  k rø | j | j	 d d ƒ} n  | j j ƒ  d k } | d  k rH| j | j	 ƒ } | j d ƒ | | | j	 <n  t } x¨ | j j ƒ  D]— }	 |	 j ƒ  }
 |
 j ƒ  } | | j k r^|  j j |	 ƒ |  j j | j	 ƒ t } | rât | d	 |
 j ƒ} |  j j | ƒ qõ|  j j d  ƒ q^q^W| sS t
 d
 | j | j	 f ƒ ‚ qS qS Wd  S(   Niÿÿÿÿ(   t   file_readers*   Missing file name for array %d (labels=%s)i   s.   The path '%s' does not exist or is not a file.t
   force_typet   hklt   ccp4_mtzt   original_labelss-   Couldn't find the Miller array %s in file %s!(   t   iotbxR   t   NoneR   R	   R
   t	   enumeratet   mtz_filet   miller_arrayt	   file_nameR   t   strt   labelst   ost   patht   isfilet   gett   any_filet   file_objectt	   file_typet   assert_file_typet   Falset   as_miller_arrayst   infot   label_stringt   appendt   Truet   get_original_array_types(   t   selft   paramst   input_filesR   t   i_arrayt   array_paramst
   input_filet   is_mtzt   foundR   t
   array_infoR#   t
   array_type(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   __init__  sL    				 	c         C   s¯   g  } x� t  t g D]s } xT |  j D]I } | j ƒ  r# | j ƒ  } | d  k	 rl | j ƒ  } | j | ƒ ql q# q# Wt | ƒ d k r Pq q Wt | ƒ d k r« t	 d ƒ ‚ n  | S(   Ni    s9   No unit cell found in inputs - please specify explicitly.(
   R    R%   R   t   is_experimental_datat   crystal_symmetryR   t	   unit_cellR$   t   lenR   (   R'   t
   unit_cellst   any_array_typet   arrayt   cst   uc(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   resolve_unit_cell6  s    N(   t   __name__t
   __module__t	   __slots__R   R1   R;   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR     s   )t   process_arraysc           B   sJ   e  Z e e e j e e d  „ Z e j d „ Z e j d „ Z d „  Z	 RS(   c   V      C   ss  | d  k r i  } n  t |  t ƒ  ƒ t | ƒ | j j } d d  l } d d l m }	 d d l m	 }
 d d l
 m } | d  k r› t d | d | ƒ } n  | j } | j } | j } | j r-g  } xa t | | ƒ D]P \ } } | | k r| d | IJ| j | ƒ n  | d | j ƒ  j ƒ  IJqÕ Wd  Sd	 d
 d g } d  d  d  g } t |  _ t } g  |  _ d  |  _ | j j |  _ |  j d  k rni  } x  | D]˜ } | j ƒ  s¯q—n  | j ƒ  } | d  k	 r—| j | k r/| j d  k	 r,y t | j ƒ | | j <Wq)t k
 r%} | d | j IJq)Xq,q/q—q—Wt g  | j ƒ  D] \ } } | ^ qCƒ } t  | ƒ d k r‚| j! ƒ  |  _ qnt  | ƒ d k rnt g  ƒ } xH | j ƒ  D]: \ } } | j" d ƒ rÚ| d“ k rÚq­n  | j# | ƒ q­Wt  | ƒ d k r| j! ƒ  |  _ qkt  | ƒ d k rkt$ d d d d j% g  t& t' | ƒ ƒ D] } d | ^ qHƒ ƒ ‚ qkqnn  t } } | j j( j) }  | j j( j* }! |! d  k	 r'| j j( j* j+ ƒ  }" |  j+ ƒ  j, ƒ  }# |! j+ ƒ  j, ƒ  }$ |# j- ƒ  j. ƒ  }% |$ j- ƒ  j. ƒ  }& t/ } |& |% k r<t/ } | d IJq<n | j j( j) j+ ƒ  }" | j j( j0 d  k	 ri| j j( j0 }' t/ } n | j j( j1 }' | j j( j2 r | r t$ d d ƒ ‚ n  |
 j3 d | j j( j1 d | j j( j) d t d t ƒ }( |( j4 ƒ  st$ d d t5 | j j( j1 ƒ t5 | j j( j) ƒ f ƒ ‚ n  |( j) ƒ  j, ƒ  }) |
 j3 d |' d |" d t d t ƒ }* |* j4 ƒ  sˆt$ d  d t5 |' ƒ t5 |" ƒ f ƒ ‚ n  t6 | |( ƒ \ }+ }, |+ d  k rÒ| j j7 d  k rÒt$ d! d" d# ƒ ‚ n  |, d  k r
| j j8 d  k r
t$ d$ d% d& ƒ ‚ q
n  | j j7 d  k	 r+| j j7 }+ n  | j j8 d  k	 rL| j j8 }, n  | j9 d  k	 r~t: j; | j9 ƒ | j< | j9 ƒ n  d' }- g  }. xït | j j= | | ƒ D]Õ\ }/ } } | j ƒ  } d( | |/ j> f }0 | j) ƒ  }1 | j1 ƒ  }2 | j j( j? }3 | j j( j@ }4 |1 d  k	 ra|3 ra|1 j, ƒ  |) k rat$ d) d* |0 t5 |1 ƒ t5 |( j) ƒ  ƒ f ƒ ‚ qan  |2 d  k	 rÆ|4 rÆ|2 jA |( j1 ƒ  ƒ sÆt$ d+ d, d- d. |0 t5 |2 ƒ t5 |( j1 ƒ  ƒ f ƒ ‚ qÆn  | jB d/ |( ƒ jC ƒ  } | j j( j2 rü| j2 ƒ  } nT | rP| jD ƒ  j- ƒ  j. ƒ  }5 | r;|5 d k r;| j2 ƒ  } n  | jB d/ |* ƒ } n  | jE ƒ  s°| jF ƒ  r›tG | | ƒ r›t$ d0 d1 d2 d3 d4 |0 ƒ ‚ n  | jH ƒ  jI ƒ  } n  tJ r	| d5 | jK ƒ  jL ƒ  IJ| jM ƒ  d  k	 r	| d6 | jM ƒ  jL ƒ  IJq	n  | j j( jN d  k	 r3	| r3	t$ d7 d8 ƒ ‚ q3	n  tO d9 | d: |/ d; |0 d< | d= | d> | jP ƒ }6 |6 jQ d? | j j8 d@ | j j7 ƒ }6 t  | j jR ƒ d' k rÈ	x& | j jR D] }7 |6 jS |7 ƒ }6 q¬	Wn  tT |6 | jU jI ƒ sã	tV ‚ |/ jW }8 |/ jX }9 |8 d  k	 r

d  }9 n dA tY jZ |- }8 d  }: d d  l[ }; |; j\ j] |6 ƒ }< | |- d  k	 rå
|6 j^ ƒ  r{
t_ j` dB dC | |- ƒ | |- <n, |6 ja ƒ  r§
t_ j` dC dB | |- ƒ | |- <n  t  |< ƒ t  | |- ƒ k rå
| dD | |- IJ| |- }: qå
n  |6 jK ƒ  jL ƒ  d' k rt$ dE dF dG dH dI ƒ ‚ n  tG |6 | ƒ rM|. j |6 | |9 |/ jW | f ƒ n!tJ rŸ| dJ |6 jK ƒ  jL ƒ  IJ|6 jM ƒ  d  k	 rŸ| dK |6 jM ƒ  jL ƒ  IJqŸn  |  jb dL |6 dM |8 dN |: dO | ƒ |9 d  k	 rûxŽ |9 D]  }= | j |= ƒ | j | ƒ qÔWnc t  |< ƒ }> |6 jc ƒ  r-|6 jd ƒ  r-|> dA 9}> n  x. te |> ƒ D]  }? | j d  ƒ | j | ƒ q:W|  j j |6 ƒ |- d 7}- q£Wt  |. ƒ d' k rÜd dP lf mg }@ mh }A t/ } d  }B }C t  |  j ƒ d' k r=| ji }D |A |  j ƒ }B |B jj d? |, |D d@ |+ |D ƒ }C |B jk dQ |C ƒ }E |E jL ƒ  d' k r=|C jl dQ |E ƒ }C q=n  t  |  j ƒ d k rutm jn dR dS dT dU dV to ƒ n  | jp r‡|C }B n |B d  k	 r tq |B ƒ n  d' }- x3|. D](\ }F } }9 }G } |F jr | ƒ d  }H |@ dW |F g dX | js ƒ }I |I jt d' }H |H d  k r„| js d  k	 r$| js }H q„| ju s6| jv r„t$ dY dZ d[ d\ d] d^ d_ d` da db dc dd | | j ƒ  f ƒ ‚ q„n  | jw r¦| jx s�tV ‚ |F }J n< |F jK ƒ  |H k }K tT |K | jy ƒ sÐtV ‚ |F jI de |K ƒ }J |J jC ƒ  }J |/ jz df k }L |J jE ƒ  s|J jH ƒ  jI ƒ  }J n  |J jc ƒ  r¡| jx rX| dg IJ|	 jx dh |J d= | ƒ }J n  |J j{ ƒ  }J |9 d  k	 r¡t  |9 ƒ d k r¡|B jc ƒ  s•tV ‚ t/ }L q¡n  | j| rë| di |0 IJt} |J |H ƒ }M |	 j| d9 |M dj | j~ d= | ƒ }J n  | jv r<|	 j dk |J dX |H dl |0 dm |B dn | do | jw d@ |+ d? |, d= | ƒ 	}J n  |J }6 |L rW|6 j€ ƒ  }6 n  t  | j jR ƒ d' k r˜x& | j jR D] }7 |6 jS |7 ƒ }6 q|Wn  | j� rÇ| dp |0 IJt‚ d9 |6 dX t/ ƒ }6 n  |G }8 |8 d  k rñdq tY jZ |- d }8 n  |  jb dL |6 dM |8 dN dr dO | ƒ |9 d  k	 rltƒ d9 |6 d: |/ d; |0 ds |9 ƒ xz |9 D]  }= | j |= ƒ | j | ƒ qEWnO |6 jc ƒ  r¡| jv d  d  g ƒ | jv | | g ƒ n | j d  ƒ | j | ƒ |  j j |6 ƒ |- d 7}- q­Wn  | j„ rì| sõ| j… r»t  |  j ƒ d k r-tm jn dR dS dT dU dV to ƒ n  d dt lf mh }A |A |  j ƒ }B |B jj d? |, | ji d@ |+ | ji ƒ }C | jp r„|C }B n
 tq |B ƒ |B j† dj | j~ du | j‡ dv | jˆ dw | j‰ dx | jŠ dy | j‹ ƒ }N | jŒ d  k sî| jŒ dz k rúd{ | _Œ n  | j� r)| dp |0 IJt‚ d9 |N dX t/ ƒ }6 n |N }6 t  | j jR ƒ d' k rpx& | j jR D] }7 |6 jS |7 ƒ }6 qTWn  |  jb dL |6 dM d| dN dr dO | ƒ | j | jŒ ƒ | j d} ƒ t/ |  _ n  |  j j� ƒ  }O g  |  _Ž |O |  _� t  | ƒ |O j� ƒ  k sE| d~ j% g  | D] }= d |= ^ qƒ IJ|  j� dO | ƒ t$ d€ d� d‚ ƒ ‚ n  d' }- t‘ g  | D] }= |= d' f ^ qUƒ }P t_ j’ dƒ ƒ }Q xí|  j� j“ ƒ  D]Ü}R | |- d  k	 ra|R j” ƒ  | |- k ra| |- }= |= }S |Q j• |= ƒ d  k	 rût$ d„ d… d† |= ƒ ‚ n  |P |= d' k r¾| j j– r›|= j" d‡ ƒ s5|= j" dˆ ƒ r]|= d' d‰ !dŠ |P |= d |= d‰ }= n |= dŠ |P | |- d 7}= |  jŽ j | |- | |- |= f ƒ q¾t$ d‹ dŒ d� dŽ | |- ƒ ‚ n  y |R j— |= ƒ Wn| t˜ k
 rM} d� t5 | ƒ k r^g  |O j“ ƒ  D] }T |T j” ƒ  ^ q }U t˜ d� d‘ |= d’ j% |U ƒ d’ j% | ƒ f ƒ ‚ q^qaX|P |S c d 7<n  |- d 7}- q�Wd  S(”   Niÿÿÿÿ(   t   r_free_utils(   t   crystal(   t   flexR(   R)   s   %s:s     %st   Ht   Kt   Ls   Warning: bad wavelength '%s'i   s   .mtzg        g      ð?s3   Multiple wavelengths present in input experimental s:   data arrays: %s.  Please specify the wavelength parameter s   explicitly.s   , s   %gs*   Will expand to P1 symmetry before merging.s6   Output unit cell and space group must be undefined if s   expand_to_p1 is True.R4   t   space_group_infot   assert_is_compatible_unit_cellt   force_compatible_unit_cells6   Input unit cell %s is incompatible with the specified s   space group (%s).t   space_groups7   Output unit cell %s is incompatible with the specified s/   No low-resolution cutoff could be found in the sC   parameters or input file(s); you need to explicitly set this value s   for the program to run.s0   No high-resolution cutoff could be found in the s=   parameters or input file(s); you need to explicitly set this s   value for the program to run.i    s   %s:%ss2   The point group for the Miller array %s (%s) does s:   not match the point group of the overall space group (%s).s.   The unit cell for the Miller array %s (%s) is s=   significantly different than the output unit cell (%s).  You s<   can ignore this by setting disable_unit_cell_check=True (in s7   the GUI, enable "Disable unit cell isomorphism check").R3   s4   The data in %s cannot be merged because they are in s>   integer format.  If you wish to change symmetry (or the input s?   data are unmerged), you must omit this array.  (Note also that s=   merging will fail for R-free flags if the flags for symmetry-s'   related reflections are not identical.)s     Adjusted size:  %ds            sigmas:  %ds4   You may not change symmetry when change_of_basis is s   defined.R   R+   t
   array_nameR/   t   logt   verboset   d_mint   d_maxi   t   Jt   Fs#   Recovering original column types %ss2   The array %s:%s ended up empty.  Please check the s=   resolution cutoffs to make sure they do not exclude all data s@   from the input file.  If you think the parameters were correct, s>   this is probably a bug; please contact bugs@phenix-online.org s"   with a description of the problem.s     Final size:    %ds         sigmas:    %dt   output_arrayt   default_labelt   column_typest   out(   t   get_r_free_flags_scorest   make_joined_sett   others3   Multiple Miller arrays are already present in this s<   file; the R-free flags will be generated based on the total sA   of reflections in all arrays combined.  If you want the fraction s@   of test set reflections to be relative to a specific array, you s7   should run the editor with that array separately first.R   t   test_flag_values1   The data in %s:%s appear to be R-free flags, but s9   a suitable test flag value (usually 1 or 0) could not be s<   automatically determined.  This may indicate that the flags s:   are uniform, which is not suitable for refinement; it can s<   also happen when there are exactly 3 different values used. s8    If this is not the case, you may specify the test flag s<   value manually by clicking the button labeled "R-free flags s3   generation..." and entering the value to use under s=   "Original test flag value".  Alternately, unchecking the box s=   "Warn if R-free flags are all the same value" will skip this s=   step, but you will not be able to extend the flags to higher s   resolution.t   datat	   anomalouss5   Remediating any mismatched flags for Friedel mates...R8   s   Resizing test set in %st   fractiont   r_free_flagst   array_labelt   complete_sett   accumulation_callbackt   preserve_input_valuess!   %s: converting to CCP4 conventiont   At   It   output_labels(   RV   t   max_freet   lattice_symmetry_max_deltat   use_lattice_symmetryt   use_dataman_shellst   n_shellst    t
   FreeR_flagt   ZZZZs   (new array)s   
s	   LABEL: %ss5   The number of output labels does not match the final sD   number of labels in the MTZ file.  Details have been printed to the s   console.s   [^A-Za-z0-9_\-+\(\)]s4   Invalid label '%s'.  Output labels may only contain s>   alphanumeric characters, underscore, plus and minus signs, or s   parentheses.s   (+)s   (-)iýÿÿÿs   _%ds&   Duplicate column label '%s'.  Specify s7   resolve_label_conflicts=True to automatically generate s<   non-redundant labels, or edit the parameters to provide yours   own choice of labels.s   new_label is used alreadys,   Duplicate column label '%s': current labels s,   are %s; user-specified output labels are %s.t    (   g        g      ð?(™   R   R   t   localst   validate_paramsR   R\   t   cctbx.millert   cctbxR@   RA   t   scitbx.array_familyRB   R   R   R	   R
   t   show_arrayst   zipR$   R"   R#   R    t   created_r_freet   final_arrayst   mtz_datasett
   wavelengtht   is_xray_data_arrayt   sourcet   floatt
   ValueErrort   sett	   iteritemsR5   t   popt   endswitht   addR   t   joint   sortedt   listR3   RI   t   output_space_groupt   groupt   build_derived_point_groupt   typet   numberR%   t   output_unit_cellR4   t   expand_to_p1t   symmetryt   is_compatible_unit_cellR   t   get_best_resolutionRN   RM   t   random_seedt   randomt   seedt   set_random_seedR   R   t   disable_space_group_checkt   disable_unit_cell_checkt   is_similar_tot   customized_copyt
   map_to_asuRF   t   is_unique_set_under_symmetryt   is_integer_arrayt   is_rfree_arrayt   merge_equivalentsR8   t   DEBUGRY   t   sizet   sigmast   change_of_basist   modify_arrayRL   t   resolution_filtert   exclude_reflectiont   delete_indext
   isinstancet   millert   AssertionErrort   column_root_labelRc   t   stringt	   uppercaset	   iotbx.mtzt   mtzt   default_column_typest   is_xray_amplitude_arrayt   ret   subt   is_xray_intensity_arrayt   add_array_to_mtz_datasett   anomalous_flagt%   is_xray_reconstructed_amplitude_arrayt   ranget   iotbx.reflection_file_utilsRU   RV   t   d_epsR^   t   lone_sett   concatenatet   warningst   warnt   UserWarningt   relative_to_complete_sett,   check_and_warn_about_incomplete_r_free_flagst   set_infot   old_test_flag_valuet   test_flag_valuest   warn_if_all_same_valuet   extendR`   t   remediate_mismatchest   boolt   anomalous_datat   average_bijvoet_matest   adjust_fractiont   get_r_free_as_boolR[   t   extend_flagst   generate_bijvoet_matest   export_for_ccp4t   export_r_free_flagst   validate_output_labelst   generatet   force_generatet   generate_r_free_flagsRd   Re   Rf   Rg   Rh   t	   new_labelt
   mtz_objectt   label_changest	   n_columnst   showt   dictt   compilet   columnst   labelt   searcht   resolve_label_conflictst	   set_labelt   RuntimeError(V   R'   R(   R)   t   inputs_objectRK   R_   t   symmetry_callbackt   r_free_paramsRp   R@   RA   RB   R   R	   R
   t   shown_filesR   R   R   t   label_filest   have_r_free_arrayt   file_wavelengthsR"   t   et   ft   wt   all_wavelengthst   filtered_wavelengthsRw   t   xt   change_symmetryt   change_point_groupt   input_space_groupR„   t	   output_sgt   input_point_groupt   output_point_groupt   pg_number_int   pg_number_outt	   output_uct
   input_symmt
   derived_sgt   output_symmRN   RM   t   it   r_free_arraysR+   RJ   t   array_sgt   array_uct	   ignore_sgt	   ignore_uct	   sg_numberRQ   R   RR   Rc   RS   R   t   default_typesRØ   t   n_colst   kRU   RV   t   combined_setR^   t   epst   missingt	   new_arrayt
   root_labelRX   t   flag_scoresR\   t   new_dataRÉ   t   r_free_as_boolt   new_r_free_arrayRÑ   t   usedt   invalid_charst   columnt   original_labelt   colt	   col_names(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR1   F  s6   	
							 "+?
					#%++		 				   	
	
				
+ 														
			
										*%&
($%,c         C   sÑ   |  j  j j j d  k	 rW | j d |  j  j j j d |  j  j j j d | ƒ \ } } n  |  j  j j j rx | j ƒ  } n  |  j d  k r® | j	 d | d | d |  j
 ƒ |  _ n |  j j d | d | d | ƒ d  S(   NRž   t   eliminate_invalid_indicesRT   R¦   RS   Rw   R   (   R(   R   R3   Rž   R   t   apply_change_of_basisR  t   eliminate_sys_absentRv   t   as_mtz_datasetRw   t   add_miller_array(   R'   RQ   RR   RS   RT   t   cb_op(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR°   4  s     		c         C   sU   |  j  d  k	 rQ | d IJ| d d d	 IJ|  j  j d | d d ƒ | d IJn  d  S(
   NRi   t   =i   s    Summary of output file RT   t   prefixs     s   ====================s   ====================(   RÑ   R   t   show_summary(   R'   RT   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyRÔ   J  s
    
c         C   su   |  j  d  k	 s t ‚ |  j j r7 |  j d |  j ƒ n  |  j  j d |  j j j	 ƒ |  j  j
 ƒ  } |  `  d  |  _  | S(   NRT   R   (   RÑ   R   R¥   R(   RL   RÔ   RK   t   writeR   t   output_filet   n_reflections(   R'   t   n_refl(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   finishQ  s    	(
   R<   R=   R   t   syst   stderrR1   t   stdoutR°   RÔ   R  (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR?   E  s   ÿ ïc          O   s    d d l  m } | j |  | Ž  S(   Niÿÿÿÿ(   R@   (   Rp   R@   t   get_r_free_stats(   t   argst   kwdsR@   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR   ]  s    c          O   s    d d l  m } | j |  | Ž  S(   Niÿÿÿÿ(   R@   (   Rp   R@   RÇ   (   R!  R"  R@   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyRÇ   a  s    c   	      C   sà   d  } d  } xÇ |  D]¿ } | j ƒ  } d  | j ƒ  | j ƒ  g k rd | d  k	 rd | j d | ƒ } n  yX | j ƒ  \ } } | d  k s‘ | | k rš | } n  | d  k s² | | k  r» | } n  Wq t k
 rÑ } q Xq W| | f S(   NR3   (   R   R3   RI   R4   R•   t	   d_max_mint	   Exception(	   R   Ró   t
   best_d_mint
   best_d_maxR8   t
   array_symmRN   RM   Rä   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR�   e  s     	c         C   s5   d d l  m } |  j ƒ  s( |  j ƒ  o4 | j | ƒ S(   Niÿÿÿÿ(   t   reflection_file_utils(   R   R(  R˜   t   is_bool_arrayt   looks_like_r_free_flags_info(   R   R/   R(  (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR™   w  s    c         C   s>   d d l  m } | j d |  j ƒ  d | ƒ } |  j d | ƒ S(   Niÿÿÿÿ(   R@   t   flagsRX   RY   (   Rp   R@   t   export_r_free_flags_for_ccp4RY   R•   (   R   RX   R@   t	   new_flags(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyRË   }  s
    		c         C   se   d } |  j  j ƒ  } | j ƒ  } | j ƒ  } t t | | ƒ ƒ } x | D] } | | | 7} qI W| S(   NRi   (   R   t   file_contentt   column_labelsRS   RÕ   Rs   (   R,   R   R
   R   t   mtz_columnst	   mtz_typest   mtz_crossrefRØ   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR&   „  s    c         C   sf  |  j  ƒ  } | d  k	 s t ‚ | j } | } | d d g d d g g k r{ |  j ƒ  rl d d d d g } qbd	 d
 g } nç |  j ƒ  rŸ d d d d d g } nÃ |  j ƒ  s· |  j ƒ  rb|  j ƒ  rbt | ƒ d k r|  j	 ƒ  d  k	 rd | d d | d d | d d | d g } qbt | ƒ d k rb|  j	 ƒ  d  k rbd | d d | d g } qbn  | S(   Nt   i_obst   sigmas   Intensity+-s   SigmaI+-s   I(+)s   SIGI(+)s   I(-)s   SIGI(-)Rb   t   SIGIRP   t   SIGFt   DANOt   SIGDANOt   ISYMi   s   %s(+)i    i   s   %s(-)(
   R"   R   R¥   R   R±   R²   R¬   R¯   R5   R�   (   R   R"   R   Rc   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   guess_array_output_labelsŽ  s*    	$$"c      	   C   s¼  d d l  m } | j } | d1 k rG | j d1 k rG t d | ƒ ‚ n  | j d1 k	 r_ d1 } n  t j d d | j ƒ }	 |	 j	 d ƒ }
 d1 | j
 | j g k r± t d d ƒ ‚ n  t | j | j g k rÜ t d	 d
 ƒ ‚ n  | r.| d |  j ƒ  j ƒ  IJ|  j ƒ  d1 k	 r.| d |  j ƒ  j ƒ  IJq.n  | rE| d | IJn  | j d1 k	 ro| j d k rod1 | _ n  | j d1 k	 r™| j d k r™d1 | _ n  | j } | d1 k rÐ| j d1 k rÐt d | ƒ ‚ n  | j d1 k	 rèd1 } n  t | d d1 ƒ } d1 | j
 | j g k r%t d d ƒ ‚ n  t | j | j g k rPt d	 d
 ƒ ‚ n  | r¢| d |  j ƒ  j ƒ  IJ|  j ƒ  d1 k	 r¢| d |  j ƒ  j ƒ  IJq¢n  | r¿| d |  j ƒ  IJn  |  j d | j d | j ƒ }  | rG| d |  j ƒ  IJ| d |  j ƒ  j ƒ  IJ|  j ƒ  d1 k	 rGt | ?d |  j ƒ  j ƒ  f qGn  |  j ƒ  rÕ| j d k rÕ| d | IJ|  j ƒ  s¤|  j ƒ  }  |  j ƒ  rÒ|  j ƒ  qÒq|  j ƒ  }  |  j ƒ  }  |  j ƒ  }  |  j  ƒ  n9 |  j ƒ  r| j d k r| d | IJ|  j! ƒ  }  n  | j d1 k	 rL| d | | j f IJ|  j" d | j ƒ }  n> | j
 d1 k	 rŠ| d | | j
 f IJ|  j" d | j
 ƒ }  n  t# d |  d | d  | d! | ƒ }  | j$ r4| d" | IJd1 } |  j% ƒ  } | j& d# t' d$ | j( ƒ  j ƒ  ƒ ƒ xÚ | j) ƒ  j* ƒ  D]Æ } | j) ƒ  j+ | ƒ } | j, | ƒ } | j- | j ƒ  j ƒ  ƒ } | j ƒ  } | d1 k	 r{| j, | ƒ } n  | j ƒ  j, | ƒ } | j. d% | d& | ƒ } | d1 k rÃ| j% ƒ  } q| j/ | ƒ } qW| j( ƒ  j ƒ  |  j( ƒ  j ƒ  k r+t0 d' | j( ƒ  j ƒ  |  j( ƒ  j ƒ  f ƒ ‚ n  | }  n  | j1 rÙ|  j2 ƒ  rj|  j3 ƒ  rjt d( | ƒ ‚ n  | d) | | j1 f IJ|  j ƒ  j% ƒ  } | j1 } |  j3 ƒ  r·t4 | ƒ } n  | j5 | ƒ |  j. d% | ƒ }  n  | j6 d* k rJ|  j7 ƒ  st d+ d, | ƒ ‚ n  | j6 d- k r)|  j ƒ  }  qJ| j6 d. k rJ|  j  ƒ  }  qJn  t8 |  | ƒ s¸| j d1 k	 r‡t9 d |  d | d/ | j ƒ q¸| d1 k	 r¸t: d |  d  | d | d0 | ƒ q¸n  |  S(2   sš   
  Perform various manipulations on a Miller array.  This can be applied to
  any data type, although certain options are limited to experimental data.
  iÿÿÿÿ(   RB   s   Missing output labels for %s!s   ,merged$Ri   t   ,s.   The parameters scale_factor and scale_max are s   mutually exclusive.s8   The parameters remove_negatives and massage_intensities s   are mutually exclusive.s     Starting size:  %ds            sigmas:  %ds   Processing %si    Rw   s2     Resolution before resolution filter: %.2f - %.2fRM   RN   s2                 after resolution filter: %.2f - %.2fs     Truncated size: %ds             sigmas: %dt   mergeds4   Converting array %s from anomalous to non-anomalous.RZ   s   Generating Bijvoet mates for %ss/   Scaling %s such that the maximum value is: %.6gt
   target_maxs,   Multiplying data in %s with the factor: %.6gt   factorR   RJ   R+   RK   s   Shuffling values for %st   n_binsid   RY   R�   s    Array size changed: %d versus %ds-   Resetting the values for %s is not permitted.s   Resetting values for %s to %gt   autos6   You may only override the output observation type for s;   amplitudes or intensities - the data in %s are unsupported.t
   amplitudest   intensitiesR  Rc   N(;   Rq   RB   Rc   R   R¦   R   R­   R®   R   t   splitt   scale_factort	   scale_maxR    t   remove_negativest   massage_intensitiesRY   Rœ   R�   RN   RM   t   getattrR#  R    t   frintR±   RÄ   R¯   RÅ   R²   t#   set_observation_type_xray_amplitudet	   f_sq_as_ft	   f_as_f_sqt#   set_observation_type_xray_intensityRÉ   t   apply_scalingt   modify_experimental_data_arrayt   shuffle_valuest	   deep_copyt   setup_binnert   mint   indicest   binnert
   range_usedt	   selectiont   selectt   random_permutationR•   R·   RÜ   t   reset_values_tot   is_real_arrayR˜   t   intt   fillR   Rx   R™   t   validate_column_root_labelRÌ   (   R   RJ   R+   R/   RL   t   debugRK   RB   Rc   t   labels_baset   input_labelsRw   t   combined_arrayt	   tmp_arrayt   i_bint   bin_selt	   bin_arrayt   permR�   RY   t	   new_value(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyRŸ   ¦  s   			 			 		$		%$+		
	c         C   s>  | j  r„ |  j ƒ  rq | d | IJ|  j |  j ƒ  d k ƒ }  |  j ƒ  d k	 r� |  j |  j ƒ  d k ƒ }  q� qá t d | ƒ ‚ n] | j rá |  j ƒ  rÎ | j	 d k r· |  j
 ƒ  }  qÞ t d d | ƒ ‚ qá t d d ƒ ‚ n  | j d k	 r¹|  j ƒ  st d	 d
 | ƒ ‚ n& | j d k r9t d d | ƒ ‚ n  |  j ƒ  } | d k rht d d | ƒ ‚ n& | j d ƒ sŽt d d | ƒ ‚ n  |  j ƒ  } |  j | | | j k ƒ }  n  | j d d d d d d g k ræd | _ n  | j d k	 s| j d k	 r’|  j ƒ  r5|  j ƒ  r5t d d | ƒ ‚ n  | j d k	 rb|  j d | j d t ƒ }  n  | j d k	 r’|  j d | j d t ƒ }  q’n  |  j ƒ  r| j	 d k r:| j	 d k rË|  j ƒ  }  n( d d l m } | j d |  d | ƒ }  |  j ƒ  q:n7 |  j ƒ  r:| j	 d k r:|  j ƒ  }  |  j ƒ  q:n  |  S(   sB   
  Manipulations common to amplitude and intensity arrays only.
  s   Removing negatives from %si    s&   remove_negatives not applicable to %s.RA  s,   You must output %s as amplitudes to use the s   massage_intensities option.s4   The parameter massage_intensities is only valid for s   X-ray intensity arrays.s3   Filtering by signal-to-noise is only supported for s)   amplitudes or intensities (failed on %s).s.   A value greater than zero is required for the sA   cutoff for filtering by signal to noise ratio (failed array: %s).s1   Sigma values must be defined to filter by signal s   to noise ratio (failed on %s).g        s1   The sigma values for the array %s include one or s8   more zeros - filtering by signal to noise not supported.s-   Applying a B-factor to the data in %s is not s
   permitted.t   b_isot   apply_to_sigmast   b_cartt   amplitudes_fwiÿÿÿÿ(   t   french_wilsonR   RK   RB  N(   s
   amplitudesRl  (   RF  R[  RX  RY   R�   R   R   RG  R¯   t	   output_ast   enforce_positive_amplitudest   filter_by_signal_to_noiseRx   t   all_net   add_b_anisot	   add_b_isot   is_complex_arrayt   apply_debye_waller_factorsR%   RK  Rp   Rm  t   french_wilson_scaleRJ  R¬   RL  RM  (   R   RJ   R+   RK   R�   RY   Rm  (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyRO  H  s€    		!	!						c            sÂ  ‡  ‡ f d †  } d } |  j ƒ  rv t ˆ ƒ d k rm | j d k rm t d d d ˆ  t ˆ ƒ f ƒ ‚ n  d } n|  j ƒ  rý |  j ƒ  r² |  j ƒ  d k	 r© d } qú d } q‚|  j ƒ  rß |  j ƒ  d k sÖ t	 ‚ d } q‚|  j
 ƒ  rô d	 } q‚d } n… |  j ƒ  r-|  j ƒ  d k	 r$d } q‚d
 } nU |  j ƒ  rg|  j ƒ  d k	 r^t d ˆ  ƒ ‚ n  d } n |  j
 ƒ  r|d } n d
 } | | ƒ |  j ƒ  r¾t d |  d ˆ d j ƒ  d ˆ  ƒ n  t S(   sw   
  Check output labels for consistency with selected options (done before the
  array undergoes most modifications).
  c            sø   |  d  k	 s t ‚ d d d d d } t ˆ ƒ } d |  } |  d k rW d |  } n  d	 d
 j ˆ ƒ } | d k rŒ d d
 j ˆ ƒ } n  |  | k rÀ t d d d | ˆ  | | f ƒ ‚ n4 |  | k  rô t d d d | ˆ  | | f ƒ ‚ n  d  S(   Ns   If you are sB   unsure which labels to provide, use the simpler column root label s=   instead, which will be expanded as necessary. (Note that the s:   number of input labels from non-MTZ file formats does not s@   necessarily correspond to the expected number of output labels.)s   %d arei   s   %d iss   labels "%s" haveRl   s   label "%s" hass8   You have not specified enough MTZ column labels for the s-   array %s; only the %s been specified, but %s s1   required for the output array after processing.  s8   You have specified too many column labels for the array s3   %s; the %s been specified, but only %s are allowed s(   for the output array after processing.  (   R   R¥   R5   R�   R   (   t
   n_expectedt	   msg_extrat   n_usedt   msg_expectedt   msg_used(   RJ   Rc   (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt%   raise_sorry_if_wrong_number_of_labels¥  s$    
i   R<  s   The array %s will be output as s=   amplitudes and anomalous differences with sigmas, plus ISYM. s;   Five columns will be written, but %d labels were specified.i   i   i   i   s?   Combination of sigmas and complex data not allowed for array %sR   R  i    RJ   N(   R   R²   R5   RÄ   R   R±   R[  R�   Rt  R¥   t   is_hendrickson_lattman_arrayRÜ   Rx   R^  t   upperR%   (   R   RJ   R+   Rc   R|  Rw  (    (   RJ   Rc   sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyRÌ   œ  sN    											

c         C   sÇ   | j  ƒ  } |  j ƒ  rI | j d ƒ sÃ t d d d d | ƒ ‚ qÃ nz |  j ƒ  r† | j d ƒ sÃ t d d d	 d | ƒ ‚ qÃ n= | d k sž | d k rÃ t d
 d d d | | f ƒ ‚ n  t S(   s‹   
  Check the root MTZ label for a Miller array to ensure consistency with
  data type - this is done after the array has been processed.
  Rb   s+   The column label prefix for the array '%s' s:   is inconsistent with the output array type (intensities). s;   Please use 'I' (either case) as the first character in the s   label.RP   s5   The specified column label prefix for the array '%s' s9   is inconsistent with the output array type (amplitudes). s;   Please use 'F' (either case) as the first character in the s0   You have specified the column label prefix '%s' s5   for the array '%s', which is neither intensities nor s5   amplitudes; the base labels 'I' and 'F' are reserved s   for these array data types .(   R~  R¯   t
   startswithR   R¬   R%   (   R   R  RJ   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR^  ë  s"    c         C   sb   d d l  m } t |  ƒ }  g  } x9 |  D]1 } | j | ƒ } | d  k	 r) | j | ƒ q) q) W| S(   Niÿÿÿÿ(   t   crystal_symmetry_from_any(   R   R€  R|   t   extract_fromR   R$   (   R	   R€  t   file_symmetriesR   t   symm(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   collect_symmetries
  s    c         C   sœ  g  } g  } x!|  D]} | d  k	 r | j ƒ  } | j ƒ  } | d  k	 r,| d  k	 r,| d  k rÄ | j ƒ  } xT | D]I }	 |	 j ƒ  }
 |	 j ƒ  j ƒ  | j ƒ  j ƒ  k rt t d d ƒ ‚ qt qt Wn  | d  k rx9 | D]. } | j | d d ƒ s× t d d ƒ ‚ q× q× Wn  | j | ƒ | j | ƒ q,q q W| } | } t	 | ƒ d k rg| d  k rg| d } n  t	 | ƒ d k r’| d  k r’| d } n  | | f S(   Ns3   Ambiguous space group information in input files - s#   please specify symmetry parameters.gü©ñÒMbP?gš™™™™™¹?s1   Ambiguous unit cell information in input files - i    (
   R   RF   R4   R…   R‡   Rˆ   R   R”   R$   R5   (   R‚  t   current_space_groupt   current_unit_cellt   space_groupsR6   Rƒ  RI   R4   R…   t   other_sgt   other_groupt   other_uct   consensus_space_groupt   consensus_unit_cell(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   resolve_symmetry  s8    $c         C   sS   |  j  ƒ  } | d k  rO t j d d d d d d d d	 d
 | t ƒ n  d  S(   Ng®Gáz®ï?s,   The arrays in the input file are incomplete s?   (%.1f%% of reflections missing), so the newly generated R-free sA   flags will be incomplete as well.  This will not cause a problem sA   for refinement, but may result in inconsistent flags later on if s>   you collect additional data.  You can disable this warning by s=   clicking the box labeled "Generate flags relative to maximum s2   complete set" in the R-free options dialog window.id   i   (   t   completenessR¸   R¹   Rº   (   R   RŽ  (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyR¼   2  s    i    c         C   s$   |  d IJt  j d |  d | ƒ d  S(   NsË   
# usage: iotbx.reflection_file_editor [file1.mtz ...] [parameters.eff]
#            --help      (print this message)
#            --details   (show parameter help strings)
# Dumping default parameters:
RT   t   attributes_level(   t   master_philRÔ   (   RT   R�  (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   usage>  s    c         C   s¨   d |  | j  ƒ  j ƒ  f } t | ƒ } | d d j | ƒ 7} | rš y> | j ƒ  \ } } | d 7} | d 8} | d | | f 7} Wqš t k
 r– qš Xn  | d 7} | S(   Ns7   mtz_file.miller_array {
  file_name = %s
  labels = %s
s     output_labels = Rl   gü©ñÒMbP?s     d_max = %.5f
  d_min = %.5f
t   }(   R"   R#   R:  R�   R#  R$  (   R   R   t   include_resolutiont	   param_strRc   RN   RM   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   generate_paramsG  s    


c         C   sH  t  |  j j ƒ d k r' t d ƒ ‚ n' t  |  j j ƒ d k rN t d ƒ ‚ n  d  |  j j j |  j j j g k r� t d ƒ ‚ n  |  j j j	 r1d |  j j j
 k  o° d k  n sÈ t d d ƒ ‚ n  |  j j j rê t d	 d
 ƒ ‚ n  |  j j j rt d d ƒ ‚ n  |  j j j r1t d d ƒ ‚ q1n  t d |  j j ƒ d  S(   Ni    s8   No Miller arrays have been selected for the output file.i   s$   Only 25 or fewer arrays may be used.s+   Missing or incomplete symmetry information.g      à?s8   The R-free flags fraction must be greater than zero and s   less than 0.5.s'   r_free_flags.preserve_input_values and s6   r_free_flags.export_for_ccp4 may not be used together.s9   Preserving input values of R-free flags is not supported s3   when resizing a test set to the specified fraction.s1   when correcting mismatched Friedel/Bijvoet pairs.R   (   R5   R   R   R   R   R3   RI   R4   R\   R`   R[   RÊ   RÆ   RÂ   R   R  (   R(   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyRn   Z  s*    %c          C   s'  d d l  m } d  } g  } g  } g  } g  } g  } t |  ƒ d k rP t ƒ  n  t j d d  ƒ }	 xÍ|  D]Å}
 |
 d! k r• t d |  j d ƒ ƒ t S|
 d" k r­ t	 ƒ  } qi t
 j j |
 ƒ r×t
 j j |
 ƒ } y t  j j d | ƒ } Wn t k
 rý n X| j | ƒ qi | j | ƒ } | j d k rž| j j } x7 | D]/ } | j ƒ  } | d  k	 r?| j | ƒ Pq?q?W| j | ƒ | j t
 j j | j ƒ ƒ q.| j d k r.| j j ƒ  } | d  k	 rÔ| } qÔq.qi |
 j d ƒ r÷|
 d d }
 n  y |	 j d |
 ƒ } Wn t k
 r qi X| j | ƒ qi Wi  } x‚ | D]z } | | | j <| j j ƒ  } g  } x' | D] } | j t | j | ƒ ƒ qnWd j | ƒ } | j t  j j | ƒ ƒ q?Wt j d | ƒ } | j ƒ  } | d  k	 r| j  ƒ  | j! j _" | j# ƒ  | j! j _# nò d  | j! j j" | j! j j# g k rg  | j! j$ D] } | j ^ qE} g  } x< | D]4 } t
 j j | ƒ } | | k rg| j | ƒ qgqgW| j% t& | ƒ ƒ t' d | d | j! j j" d | j! j j# ƒ \ } } | | j! j _" | | j! j _# n  | j! j( d  k r€d } xH t
 j) t
 j* ƒ  ƒ D]1 } | j d ƒ r4| j+ d ƒ r4| d 7} q4q4Wd | d | j! _( n  t
 j j | j! j( ƒ | j! _( t, | d | d | ƒ} | j- r| d IJt j. d | ƒ j/ d | ƒ | j0 r| j/ d | ƒ n  | S| j1 ƒ  | d  | j! j( IJ| S(#   Niÿÿÿÿ(   R   i    t
   home_scopes   --helps	   --optionss	   --detailsR�  s   -qs   --quietR   R   t   pdbs   --i   s   =Truet   args   
t   sourcesR‚  R…  R†  t   reflections_s   .mtzi   s   reflections_%d.mtzR)   RK   s   # showing final parameterst   python_objectRT   s   Data written to %s(   s   --helps	   --optionss	   --details(   s   -qs   --quiet(2   R   R   R   R5   R‘  R�  t!   command_line_argument_interpretert   countR%   R   R   R   R   t   abspatht   philt   parseR$  R$   R   R   t   file_serverR   R3   R   R   R  t   processR!   R•  R�   t   fetcht   extractRF   R   RI   R4   R   RÁ   R„  R�  R  t   listdirt   getcwdR   R?   t   dry_runt   formatRÔ   RL   R  (    R!  RT   R   t   crystal_symmetry_from_pdbt   crystal_symmetries_from_hklt   reflection_filest   reflection_file_namest	   user_philt
   all_arrayst   interpreterR˜  t	   full_patht	   file_philR,   R   R8   Rƒ  t   cmdline_philR)   t   file_arraysR(   R   t   file_params_strt   working_philt   pt   all_hkl_file_namest   need_symmetry_for_filesR   RI   R4   t   nR¢  (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   runr  sº    
		"	
	
t   __main__i   (0   t
   __future__R    t
   iotbx.philR   t   libtbx.utilsR   R   R   t   libtbxR   R   R¸   R�   R§   R­   R   R  R    R›   RŸ  R   R%   R�  R   t   objectR?   R   RÇ   R   R�   R™   RË   R&   R:  R  RŸ   RO  RÌ   R^  R„  R�  R¼   R‘  R•  Rn   Rº  R<   t   argv(    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/reflection_file_editor.pyt   <module>   sN   	÷:ÿ ÿ 					
	ŸP	O		
				f