ó
¨™xTc           @   sè   d  d l  m Z d  d l 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  d l
 m Z d  d l m Z m Z d  d	 l m Z d  d l Z d  d l Z d
 Z e j j d ƒ Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   division(   t   outlier_rejection(   t   absolute_scalingN(   t   flex(   t   miller(   t   adptbx(   t   Sorryt   null_out(   t   Autos~   
  hklout = None
    .type = path
  hklout_type=mtz sca *Auto
    .type = choice
  label_extension="massaged"
    .type = str
sÉ  
    aniso
      .help="Parameters dealing with anisotropy correction"
      .short_caption = Anisotropy correction
      .style = box auto_align
    {
      action=*remove_aniso None
        .type=choice
        .caption = Remove_anisotropy None
        .help="Remove anisotropy?"
        .style = bold
      final_b=*eigen_min eigen_mean user_b_iso
        .help="Final b value"
        .type=choice
        .caption = Minimum_eigenvalue Mean_eigenvalue User_specified
        .short_caption = Final B-factor source
      b_iso=None
        .type=float
        .help="User specified B value"
        .short_caption = User-specified B-factor
    }
    outlier
      .help="Outlier analyses"
      .short_caption = Outlier analyses
      .style = box auto_align
    {
      action=*extreme basic beamstop None
        .help="Outlier protocol"
        .type=choice
        .short_caption = Outlier rejection protocol
      parameters
        .help="Parameters for outlier detection"
      {
        basic_wilson{
          level = 1E-6
            .type=float
            .short_caption = Basic Wilson level
        }
        extreme_wilson{
          level = 0.01
            .type=float
            .short_caption = Extreme Wilson level
        }
        beamstop{
          level = 0.001
            .type=float
            .short_caption = Beamstop level
          d_min = 10.0
            .type=float
            .short_caption = Max. resolution
            .style = resolution
        }
      }
    }
    symmetry
      .short_caption = Detwinning
      .style = box auto_align
    {
      action = detwin twin *None
        .type = choice
        .short_caption = Action
        .style = bold
      twinning_parameters{
        twin_law = None
          .type = str
          .short_caption = Twin law
          .input_size = 120
          .style = bold
        fraction = None
          .type = float
          .short_caption = Detwinning fraction
          .style = bold
      }
    }
t   massage_datac           B   s2   e  Z d d  d d „ Z d „  Z e d d „ Z RS(   id   i    c         C   sY  | |  _  | j ƒ  j | ƒ j ƒ  j ƒ  |  _ | |  _ |  j d  k rT t j	 |  _ n  |  j d k rr t
 ƒ  |  _ n  |  j |  _ |  j  j j d k rt j d |  j d | d | ƒ } d | _ | j d | ƒ | j |  _ | j |  _ | j |  _ |  j  j j d k r| j d	 } nr |  j  j j d
 k r@t j | j ƒ } nH |  j  j j d k r‚|  j  j j d  k	 spt ‚ |  j  j j } n d } | | | d d d g } t j | j ƒ  t j  | ƒ ƒ }	 t j! |  j d | j ƒ |  _ t j! |  j d |	 ƒ |  _ |  j j | ƒ |  _ n  t" j# |  j d  d |  j ƒ}
 |  j |  _$ |  j  j% j d k r¡|  j d IJ|  j d IJ|
 j& d |  j  j% j' j( j) d t* ƒ } | |  _$ n  |  j  j% j d k r|  j d IJ|  j d IJ|
 j+ d |  j  j% j' j, j) d t* ƒ } | |  _$ n  |  j  j% j d k rz|  j d IJ|  j d IJ|
 j- d |  j  j% j' j. j) d |  j  j% j' j. j/ d t* ƒ } | |  _$ n  |  j  j% j d k rž|  j |  _$ n  |  j$ |  _0 |  j  j1 j d k rƒ|  j  j1 j2 j3 } | d  k rìt4 d ƒ ‚ n+ d | k od k n st4 d ƒ ‚ n  |  j J|  j d  IJ|  j d! IJ|  j J|  j d" | IJ|  j$ j5 d# |  j  j1 j2 j6 d$ | ƒ j7 ƒ  |  _0 n½ |  j  j1 j d% k r@|  j  j1 j2 j6 } |  j  j1 j2 j3 } | d  k r×t4 d& ƒ ‚ n+ d | k oîd k n st4 d ƒ ‚ n  |  j d' | | f IJ|  j$ j8 d# | d$ | ƒ j7 ƒ  |  _0 n  |  j0 d  k	 sUt ‚ d  S((   Nt   silentt   remove_anisot   miller_arrayt
   n_residuest   n_basesi    t   outt	   eigen_mini   t
   eigen_meant
   user_b_isoi   g        t   basics1   Non-outliers found by the basic wilson statisticss   protocol will be written out.t   p_basic_wilsont   return_datat   extremes9   Non-outliers found by the extreme value wilson statisticst   p_extreme_wilsont   beamstops&   Outliers found for the beamstop shadows0   problems detection protocol will be written out.t   levelt   d_mint   Nonet   twins.   Twin fraction not specified, not twinning datag      à?s(   Twin fraction must be between 0 and 0.5.s   Twinning given datas   -------------------s1   Artifically twinning the data with fraction %3.2ft   twin_lawt   alphat   detwins0   Twin fraction not specified, not detwinning datas/  

Attempting to detwin data
-------------------------
Detwinning data with:
  - twin law:      %s
  - twin fraciton: %.2f

BE WARNED! DETWINNING OF DATA DOES NOT SOLVE YOUR TWINNING PROBLEM!
PREFERABLY, REFINEMENT SHOULD BE CARRIED OUT AGAINST ORIGINAL DATA
ONLY USING A TWIN SPECIFIC TARGET FUNCTION!

(9   t   paramst	   deep_copyt   set_observation_typet   merge_equivalentst   arrayR   R   R   t   syst   stdoutR   t   no_aniso_arrayt   anisot   actionR   t   ml_aniso_absolute_scalingt   p_scalet   showt   aniso_p_scalet   u_start   aniso_u_start   b_cartt   aniso_b_cartt   final_bt   eigen_valuesR   t   meant   b_isot   AssertionErrorR   t   u_cart_as_u_start	   unit_cellt   b_as_ut   anisotropic_correctionR   t   outlier_managert   new_miller_arrayt   outliert   basic_wilson_outlierst
   parameterst   basic_wilsonR   t   Truet   extreme_wilson_outlierst   extreme_wilsont   beamstop_shadow_outliersR   R   t   final_arrayt   symmetryt   twinning_parameterst   fractionR   t	   twin_dataR   t   as_intensity_arrayt   detwin_data(   t   selfR   R?   R   R   R   t   aniso_scale_and_bt   b_uset   b_cart_aniso_removedt   u_star_aniso_removedR;   t   basic_arrayt   extreme_arrayt   beamstop_arrayR   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/scaling/massage_twin_detwin_data.pyt   __init__e   sÈ    															
c         C   s   |  j  S(   N(   RE   (   RL   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/scaling/massage_twin_detwin_data.pyR   ò   s    t   massagedc   	      C   s  t  | ƒ d k rR t j j | ƒ \ } } | d k rC | d } qR t d ƒ ‚ n  | d k sj t | ƒ ‚ | d k rª d d  l } | j j j	 d	 | d
 |  j
 d t ƒ nq | d k rd  } |  j
 j ƒ  rÔ d } n  |  j
 j ƒ  rì d } n  |  j
 j d | | ƒ } | j ƒ  j	 | ƒ n  d  S(   NR   s   .mtzs   .scai   s"   Unknown or unsupported output typet   mtzt   scaiÿÿÿÿt	   file_nameR   t%   scale_intensities_for_scalepack_merget   It   Ft   column_root_label(   s   .mtzs   .sca(   RV   RW   (   t   strt   ost   patht   splitextR   R6   t   iotbx.scalepack.merget	   scalepackt   merget   writeRE   RA   R   t   is_xray_intensity_arrayt   is_xray_amplitude_arrayt   as_mtz_datasett
   mtz_object(	   RL   RX   t   output_typet   label_extensiont   baset   extt   iotbxt
   base_labelt   mtz_dataset(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/scaling/massage_twin_detwin_data.pyt
   write_dataõ   s*    	
		N(   t   __name__t
   __module__R   RT   R   R   Rp   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/scaling/massage_twin_detwin_data.pyR	   d   s   ˆ	(   t
   __future__R    t   mmtbx.scalingR   R   t   mmtbxt
   iotbx.philRm   t   cctbx.array_familyR   t   cctbxR   R   t   libtbx.utilsR   R   t   libtbxR   t   os.pathR^   R%   t   output_params_strt   philt   parset   master_paramst   objectR	   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/scaling/massage_twin_detwin_data.pyt   <module>   s   		J	