ó
³™xTc           @   s  d  d l  m Z d  d l m Z d  d l Z d  d l m Z d  d l m 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 d  d
 l m Z m Z d  d l m Z d  d l Z d  d l Z e j j d ƒ Z d „  Z d „  Z e d k re e j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   write_as_pdb_fileN(   t   reflection_file_utils(   t   crystal_symmetry_from_any(   t   crystal(   t   sgtbx(   t   flex(   t   matrix(   t   Sorryt	   multi_out(   t   StringIOsÛ  reindex_utils{
  input{
    unit_cell=None
    .type=unit_cell
    space_group=None
    .type=space_group
    xray_data{
      file_name=None
      .type=path
      labels=None
      .type=str
    }
    model{
      file_name=None
      .type=path
    }
  }
  parameters{
    action = *reindex operator manipulate_pdb
    .type=choice
    chain_id_increment = 0
    .type=int
    inverse=False
    .type=bool
    reindex{
      standard_laws = niggli *reference_setting invert user_supplied
      .type=choice
      user_supplied_law='h,k,l'
      .type=str
    }
    apply_operator{
      standard_operators = *user_supplied
      .type=choice
      user_supplied_operator="x,y,z"
      .type=str
      concatenate_model=False
      .type=bool
    }
    manipulate_pdb{
      set_b = True
      .type=bool
      b_iso = 30
      .type=float
    }
  }
  output{
    logfile=reindex.log
    .type=str
    hklout=reindexed.mtz
    .type=str
    xyzout=reindexmodel.pdb
    .type=str
  }
}
c           C   s   d GHt  j ƒ  d  S(   Ns”   
mmtbx.reindex:

Allows one to quickly reindex a dataset and apply the effect on the
atomic coordinates as well.

The keywords are sumarized below:
(   t   master_paramst   show(    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/examples/reindex.pyt
   print_helpH   s    c   &      C   sï
  t  |  ƒ d k r t ƒ  nÏ
d |  k r2 t ƒ  n¹
d |  k rH t ƒ  n£
d |  k r^ t ƒ  n�
t ƒ  } d |  k r� | j d d d t j ƒ n  t ƒ  } t ƒ  } | j d d	 d | ƒ g  } t j d
 d ƒ } | d IJ| d IJ| d IJ| d IJ| d IJ| Jx1|  D])} d  } t
 } t j j | ƒ r•y; t j j d | ƒ } | d  k	 rj| j | ƒ t } n  Wqôt k
 r�‚  qôt k
 r‘qôXn_ y8 | j d | ƒ } | d  k	 rÌ| j | ƒ t } n  Wn$ t k
 rã‚  n t k
 rón X| s| d IJ| d I| IJ| d IJ| Jt d | ƒ ‚ qqWt j d | ƒ }	 |	 j ƒ  }
 |
 j } d  } d  } | j j j d  k	 rŸt j d | j j j ƒ } n  | j j j d  k	 rÒt j d | j j j ƒ } n  t  j! d | j j" d | j j# ƒ } t  j$ d  | | g | g ƒ } | j" ƒ  | j _" | j% ƒ  | j _# | d IJt j& d |
 ƒ } | j' d | ƒ | d IJ| j j" d  k r�t d ƒ ‚ n  | j j# d  k r°t d ƒ ‚ n  d  } | j j j d  k	 r9t  j! d | j j" d | j j# ƒ } t( j) d | d t d  g  ƒ } | j* d | j j j d! | j j j+ d" t d# d$ d% d! ƒ } | j, ƒ  } | j- ƒ  } | j. | j/ ƒ  dP k ƒ } | j. | j0 ƒ  d k ƒ } | j1 ƒ  d  k	 rÇ| j. | j1 ƒ  d k ƒ } n  | j2 ƒ  râ| j3 ƒ  } n | j4 ƒ  rýt5 | ƒ } n  | j6 | ƒ | J| d& IJ| d' IJ| j7 d( | ƒ | Jn  d  } | j j j d  k	 r©t j8 j d | j j j ƒ } | j9 d | ƒ } | d) IJ| d* IJ| j7 ƒ  | Jn  | j: j; d+ k r8| j< ƒ  } | j= ƒ  } | j> ƒ  } d  } | j: j? } | j@ d, k r	| } nB | j@ d- k r!| } n* | j@ d. k r9| } n tA jB | jC ƒ } | d  k rft d/ ƒ ‚ n  | j: jD r�| jD ƒ  } n  | d0 IJ| d1 IJ| d2 I| jE ƒ  IJ| d3 I| jF ƒ  IJ| d4 I| jG ƒ  IJd  } | d  k	 rû| jH | ƒ } n  d  } | d  k	 r| jH | ƒ } n  | J| d5 IJ| d6 IJ| J| d7 IJ| d  k	 r–| d8 | jI jJ IJ| jK d9 d: ƒ } | jL ƒ  jM d | jI jJ ƒ n  | d  k	 rtN | jI jO d; ƒ } | d< | jI jO IJtP d= | d> | d | d? | j: jQ d@ dA ƒ | dB IJ| jR ƒ  n  | | g jS d  ƒ dC k r8| dD IJq8n  | j: j; dE k rå	tA jT | j: jU jV dF dQ ƒ} | j: jD rƒ| jD ƒ  } n  | J| dI I| jF ƒ  IJ| J| jW ƒ  }  tX jY ƒ  }! xb |  D]Z }" | jZ ƒ  t[ j\ |" ƒ }# tX j] |# ƒ tX j] | j^ ƒ  j_ ƒ  ƒ }# |! j t` |# ƒ ƒ qÀW| ja ƒ  } | jb |! ƒ tN | jI jO d; ƒ } | d< | jI jO IJ| j: jU jc r�	tP d= | d> | d | d? d d@ d  dJ t ƒ n  tP d= | d> | d | d? | j: jQ d@ d  dJ t
 ƒ | dB IJ| jR ƒ  n  | j: j; dK k r®
| j: jd je rW
| j j: jd jf }$ | jg dL |$ ƒ } | J| dM |$ IJ| dN | jI jO IJ| Jn  tN | jI jO d; ƒ } tP d= | d> | d | d? d d@ d  dJ t ƒ | dB IJ| jR ƒ  n  tN | jI jh d; ƒ }% | dO | jI jh IJ| J|% | ji ƒ  IJd  S(R   Ni    s   --helps   --hs   -hs   --quiett   labelt   stdoutt   file_objectt
   log_buffert
   home_scopet	   map_coefss   #phil __OFF__s   =================s       REINDEX      s   A reindexing toolt	   file_namet   args2   ##----------------------------------------------##s   ## Unknown file or keyword:s   Unknown file or keyword: %st   sourcest	   unit_cellt   space_group_infos   #phil __ON__t   python_objectt   outs   #phil __END__s   unit cell not specifieds   space group not specifiedt   crystal_symmetryt   force_symmetryt   reflection_filest   labelst   ignore_all_zerost   parameter_scopes   reindex_utils.input.xray_datat   parameter_names   Summary info of observed datas   =============================t   fs   Atomic model summarys   ====================t   reindext   nigglit   reference_settingt   inverts)   No change of basis operation is supplied.s   Supplied reindexing law:s   ========================s   hkl notation: s   xyz notation: s   abc notation: s&   The data and model have been reindexeds&   --------------------------------------s   Writing output files....s   writing mtz file with name %st   column_root_labelt   FOBSt   ws   Wring pdb file to: %st	   input_pdbt   input_xray_structuret   chain_id_incrementt   additional_remarks   Generated by mmtbx reindext   ENDi   s7   No input reflection of coordinate files have been givent   operatort   t_deni   i   s   Applied operator : t   print_cryst_and_scalet   manipulate_pdbt   values#   All B-values have been set to %5.3fs   Writing PDB file %ss   Writing log file with name %s(   i    i    i    i`   (j   t   lenR   R	   t   registert   sysR   R
   R   t!   command_line_argument_interpretert   Nonet   Falset   ost   patht   isfilet   iotbxt   philt   parset   appendt   Truet   KeyboardInterruptt	   Exceptiont   processR   t   fetcht   extractt   reindex_utilst   inputt	   xray_dataR   R   t   extract_fromt   modelR   t   symmetryR   t   space_groupt   select_crystal_symmetryR   t   formatR   R   t   reflection_file_servert   get_xray_dataR   t   infot
   map_to_asut   selectt   indicest   datat   sigmast   is_xray_intensity_arrayt	   f_sq_as_ft   is_complex_arrayt   abst   set_infot   show_summaryt   pdbt   xray_structure_simplet
   parameterst   actiont!   change_of_basis_op_to_niggli_cellt'   change_of_basis_op_to_reference_settingt"   change_of_basis_op_to_inverse_handR#   t   standard_lawsR   t   change_of_basis_opt   user_supplied_lawt   inverset   as_hklt   as_xyzt   as_abct   change_basist   outputt   hkloutt   as_mtz_datasett
   mtz_objectt   writet   opent   xyzoutR   R,   t   closet   countt   rt_mxt   apply_operatort   user_supplied_operatort
   sites_fracR   t   vec3_doublet   rR   t   colt   doublet   tt	   as_doublet   tuplet   deep_copy_scattererst   set_sites_fract   concatenate_modelR2   t   set_bt   b_isot	   set_b_isot   logfilet   getvalue(&   t   argst   logt   string_buffert   string_buffer_plotst   phil_objectst   argument_interpreterR   t   command_line_paramst   arg_is_processedt   effective_paramst   params_roott   paramst   hkl_xst   pdb_xst   phil_xst   combined_xst
   new_paramst   miller_arrayt   xray_data_serverRR   t	   pdb_modelRK   t	   to_nigglit   to_referencet
   to_inverset   cb_opt   prt   new_miller_arrayt	   new_modelt   mtz_datasett   pdb_fileRv   t   sitest	   new_sitest   sitet   new_siteR…   t   logger(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/examples/reindex.pyRG   S   sÈ   



					




    

				

					




			




		
(


t   __main__i   (   t
   __future__R    t   mmtbx.xmanipR   t	   iotbx.pdbR=   R   R   t
   iotbx.philt   cctbxR   R   t   cctbx.array_familyR   t   scitbx.mathR   t   libtbx.utilsR   R	   t	   cStringIOR
   R6   R:   R>   R?   R   R   RG   t   __name__t   argv(    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/examples/reindex.pyt   <module>   s&   	7			ÿ '