ó
xTc           @   sĘ  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	 Z
 d  d l Z
 d  d l
 m Z i! d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d	 d  6d d! 6d d" 6d d# 6d d$ 6d d% 6d d& 6d d' 6d d( 6d d) 6d d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d8 6d9 d: 6d; d< 6Z i! d5 d= 6d7 d> 6d9 d? 6d; d@ 6d+ dA 6d dB 6d	 dC 6d dD 6d	 dE 6dF dG 6dH dI 6dJ dK 6dL dM 6dN dO 6d dO 6dP dQ 6d dQ 6dR dS 6dT dU 6d dV 6d dW 6d dX 6d dY 6dZ d[ 6d\ d] 6d d^ 6d d_ 6d d` 6d da 6d- d. 6d/ d0 6d1 d2 6d3 d4 6Z db   Z e
 j j dc  Z d e j dd  Z de e f df     YZ dg   Z e dh k rĆe e j di  n  d S(j   i˙˙˙˙(   t   divisionN(   t   flex(   t   plural_s(   t   Usage(   t   reflection_file_utilss   _refln.F_meas_aut   FOBSs   _refln.F_meas_sigma_aut   SIGFOBSs   _refln.F_squared_meast   IOBSs   _refln.F_squared_sigmat   SIGIOBSs   _refln.pdbx_F_pluss   FOBS(+)s   _refln.pdbx_F_plus_sigmas
   SIGFOBS(+)s   _refln.pdbx_F_minuss   FOBS(-)s   _refln.pdbx_F_minus_sigmas
   SIGFOBS(-)s   _refln.pdbx_I_pluss   IOBS(+)s   _refln.pdbx_I_plus_sigmas
   SIGIOBS(+)s   _refln.pdbx_I_minuss   IOBS(-)s   _refln.pdbx_I_minus_sigmas
   SIGIOBS(-)s   F-obss   SIGF-obss   F-obs(+)s   SIGF-obs(+)s   F-obs(-)s   SIGF-obs(-)s   I-obss   SIGI-obss   I-obs(+)s   SIGI-obs(+)s   I-obs(-)s   SIGI-obs(-)s   _refln.pdbx_r_free_flags   R-free-flagss   _refln.pdbx_HL_A_isot   HLAs   _refln.pdbx_HL_B_isot   HLBs   _refln.pdbx_HL_C_isot   HLCs   _refln.pdbx_HL_D_isot   HLDs   _refln.pdbx_FWTt   2FOFCWTs   _refln.pdbx_PHWTt	   PH2FOFCWTs   _refln.pdbx_DELFWTt   FOFCWTs   _refln.pdbx_DELPHWTt   PHFOFCWTt   FWTt   PHWTt   DELFWTt   DELPHWTt   FREEt   Ft   SIGFt   FPt   SIGFPs   _refln.F_calc_aut   FCs   _refln.phase_calct   PHICs   _refln.phase_meast   PHIBs
   _refln.fomt   FOMs   _refln.intensity_meast   Is   _refln.intensity_sigmat   SIGIs   _refln.F_part_aut   FPARTs   _refln.phase_partt   PHIPs   F(+)s   SIGF(+)s   F(-)s   SIGF(-)s   _refln.pdbx_anom_differencet   DPs!   _refln.pdbx_anom_difference_sigmat   SIGDPs   I(+)s   SIGI(+)s   I(-)s   SIGI(-)c         C   sŁ   | j  d  r | d  } n8 | j  d  r8 | d  } n | j  d	  rT | d  } n  |  j |  } | d  k r | j d d  j d d  } |  j |  } n  | S(
   Nt   xrayiű˙˙˙t   neutroniř˙˙˙t   _Xt   _Niţ˙˙˙t    (   R&   R'   (   t   endswitht   gett   Nonet   replace(   t   mtz_to_cif_label_dictt	   mtz_labelt	   cif_label(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/mtz_as_cif.pyt   mtz_to_cif_labelV   s    sx  
mtz_as_cif
  .short_caption = MTZ as mmCIF
  .caption = This program will convert reflections in MTZ format to mmCIF,     suitable for PDB deposition.  Note that phenix.refine can also write     mmCIF files directly if desired.
  .style = auto_align box     caption_img:icons/custom/phenix.reflection_file_editor.png
{
mtz_file = None
  .type = path
  .multiple = True
  .short_caption = MTZ file
  .style = file_type:mtz input_file bold
output_file = None
  .type = path
  .help = Optional output file name to override default
  .optional = True
  .help = 'Enter a .cif output name'
  .style = file_type:cif bold new_file
mtz_labels = None
  .help = Custom input labels for unknown MTZ columns
  .short_caption = Custom input labels
  .type = strings
cif_labels = None
  .help = Custom output labels for unknown mmCIF columns
  .short_caption = Custom output labels
  .type = strings
}
c      	   C   sÄ  d d l  m } | } | d  k rU t  j j d |  d t d d  } | j j   } n  t | j	 j
  d k r| t d   n  | j	 } g  } xk | j
 D]` } | j |  } | j d	  | j j   d
 k rß t d |   n  | j | j j    q Wt |  d k st  i  }	 | j d  k	 r| j d  k	 rt | j  t | j  k sYt  x6 t | j | j  D] \ }
 } |	 j |
 |  qoWn  g  } x%t | j
 |  D]\ } } | d | IJt | d |	 j } t j j t j j |   d } | j } | d  k r| d } n  t  j j  j   } | d d  k	 rT| d j! | | <n  | d d  k	 r|| d j! | | d <n  t" | d  / } | d | j# IJ| | IJ| j |  Wd  QXqŤW| S(   Ni˙˙˙˙(   t   file_readert   argst   master_philt   reflection_file_defs   mtz_as_cif.mtz_filei    s5   phenix.mtz_as_cif data.mtz [params.eff] [options ...]t   hklt   ccp4_mtzs9   Error reading '%s' - only MTZ files may be used as input.s   Converting %st   custom_cif_labels_dicts   .reflections.cifR$   R%   t   _neutront   wbs3   Writing data and map coefficients to CIF file:
  %s($   t   iotbxR1   R+   t   philt   process_command_line_with_filesR3   t   workt   extractt   lent
   mtz_as_cift   mtz_fileR   t   any_filet   check_file_typet   file_objectt	   file_typet   Sorryt   appendt   file_contentt   AssertionErrort
   mtz_labelst
   cif_labelst   zipt
   setdefaultt   mtz_as_cif_blockst
   cif_blockst   ost   patht   splitextt   basenamet   output_filet   cift   modelt	   cif_blockt   opent   name(   R2   t   paramst   outR1   t   work_paramst   cmdlinet   mtz_objectst	   file_namet
   input_fileR7   R.   R/   t   output_filest   mtz_file_namet
   mtz_objectRO   t   prefixRT   t	   cif_modelt   f(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/mtz_as_cif.pyt   run   sZ    		$""	

RN   c           B   s   e  Z d d d d   Z RS(   c         C   s  i d  d 6d  d 6|  _ | d  k r/ t j } n  | j   } d  } d  } d  } d  }	 d  }
 d  } d  } i  } | j t  | j t  | d  k	 rĄ | j |  n  g  } xg| D]_} | j   j	 } | d } t
 j | j    r6d | k r| j   } | j d d  g } n  | j d!  r*| }
 qŽ | }	 qŽ nx | j d  rf| j d"  r]| } qŽ| } nH | j d  s| j d	  rŽ| j d  j d#  rĽ| } qŽ| } n  g  } x* | D]" } t | |  } | j |  qťW| j d   d k r9x: t |  D], \ } } | | d  k r| j |  qqWqŽ n  | j d   d k sTt  | d j d  j d$  ryd } n d } | d j d%  r°| d k r§| } q°| } n  |  j j |  d  k rót j j d | d | d d  |  j | <qŽ |  j | j | d | qŽ Wt |  rW| d t t |   d d j |  f IJ| d IJn  t d g  } |  j d d  k	 r| j d  n  | d  k rÁ| d  k	 rÁ|  j d j d | d d&  n  | d  k rů| d  k	 rů|  j d j d | d d'  n  x| D]} | d k rn|	 } | } | } |  j d d  k r|	 d  k	 r|  j d d  k	 r|
 d  k r|	 }
 qn! | d k r|
 } | } | } n  |  j | d  k	 rÎ| d  k	 rÎ|  j | j d | d d  n  | d  k s | d  k rěq n  | d  k rt
 j  d |  } n  | d  k	 st  | j! d t" j# | j$   d   } | j   } | j% |  } | j&   j' | j( d  d  | j&   j' | j&   | k d  | d  k	 rč| j   } | j% |  } | j&   j' | j) d  d  n  |  j | j d | d d   q Wd  S((   NR$   R%   i    s   (+)R(   R'   s   F-obs-filtereds   F-obss   I-obss   _refln.F_meass   _refln.F_squared_meass   _refln.pdbx_F_s   _refln.pdbx_I_t   arrayt   column_namest   formatt   mmcifs    Warning: Unknown mtz label%s: %si   s   , sR     Use mtz_labels and cif_labels keywords to provide translation for custom labels.s   _refln.F_meas_aus   _refln.F_meas_sigma_aut   column_names   _refln.pdbx_r_free_flagt   miller_arrayt   datat   .t   oRf   t   <s   _refln.status(   s   neutrons   _N(   s   neutrons   _N(   s   neutrons   _N(   s   neutrons   _N(   s   _refln.F_meass   _refln.F_squared_meass   _refln.pdbx_F_s   _refln.pdbx_I_(   s   _refln.F_meas_aus   _refln.F_meas_sigma_au(   s   _refln.F_meas_aus   _refln.F_meas_sigma_au(*   R+   RO   t   syst   stdoutt   as_miller_arrayst   updatet   phenix_to_cif_labels_dictt   ccp4_to_cif_labels_dictt   infot   labelsR   t   looks_like_r_free_flags_infot   average_bijvoet_matesR,   R)   t
   startswitht   stripR0   RG   t   countt	   enumerateRI   R*   R:   RU   t   miller_arrays_as_cif_blockt   add_miller_arrayR?   R   t   joint   sett   addt   guess_r_free_flag_valueRh   R   t
   std_stringt   sizet   match_indicesRn   t   set_selectedt   pair_selectiont   single_selection(   t   selfRc   R7   t   logt   test_flag_valuet   miller_arraysR   t   input_observations_xrayt   input_observations_neutront   r_free_xrayt   r_free_neutront   f_obs_filtered_xrayt   f_obs_filtered_neutront   mtz_to_cif_labels_dictt   unknown_mtz_labelsRh   Ry   t   labelRi   R.   R/   t   it	   data_typet
   data_typest   r_freet	   input_obst   f_obs_filteredt   refln_statust   input_obs_non_anomt   matcht   f_obs_filtered_non_anom(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/mtz_as_cif.pyt   __init__ľ   sÚ     
						
  			&

	 	$""N(   t   __name__t
   __module__R+   RŁ   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/mtz_as_cif.pyRN   ł   s   c         C   s+   t  |  j j  d k r' t d   n  t S(   Ni    s   No MTZ file(s) specified!(   R?   R@   RA   RF   t   True(   RZ   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/mtz_as_cif.pyt   validate_params:  s    t   __main__i   (   t
   __future__R    RP   Rr   t   cctbx.array_familyR   t   libtbx.utilsR   R   t
   iotbx.philR:   t   iotbx.cif.modelR   Rv   Rw   R0   R;   t   parseR3   R+   Rs   Rg   t   objectRN   R§   R¤   t   argv(    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/mtz_as_cif.pyt   <module>   s¨   

			0	