ó
×™xTc           @   s|  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 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 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 e f d „  ƒ  YZ d d „ Z d d „ Z d „  Z d d d d d d e d „ Z  e j! j" d d e ƒZ# d „  Z$ d d „ Z% d S(   iÿÿÿÿ(   t   division(   t   xmanip_tasks(   t   reflection_file_reader(   t   reflection_file_utils(   t   crystal_symmetry_from_anyN(   t   crystal(   t   sgtbx(   t   adptbx(   t   flex(   t   matrix(   t   Sorryt	   multi_out(   t   StringIOt   quick_rt_mxc        	   B   si   e  Z d  d l m Z d d d d d d d d d g	 d	 d „ Z d „  Z d „  Z d „  Z d
 d „ Z	 RS(   iÿÿÿÿ(   R	   i   i    c         C   s(   t  j | ƒ |  _ t j | ƒ |  _ d  S(   N(   R	   t   sqrt   rmR   t   doublet   tv(   t   selft   rt   t(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt   __init__   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyR      s    c         C   s   |  j  S(   N(   R   (   R   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyR      s    c         C   sC   t  d |  j j ƒ  d |  j d |  j d |  j d f ƒ } | S(   NR   R   i    i   i   (   R   R   t   inverseR   (   R   t   tmp(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyR      s    ?c         C   sƒ   | d  k r t j } n  | J| d IJ| |  j ƒ  j d t d d ƒ IJ| d IJx" |  j ƒ  D] } | d | Iq_ W| J| Jd  S(   Ns   R :t   one_row_per_linet   formats   %6.3fs   T :(   t   Nonet   syst   stdoutR   t   mathematica_formt   TrueR   (   R   t   outt   item(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt   show    s    
"
(   i    i    i    N(
   t   __name__t
   __module__t   scitbxR	   R   R   R   R   R   R!   (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyR      s   			c         C   sh  | d  k r t j } n  g  } d d d d d g } d d d d	 d
 d d g } xt |  | ƒ D]\ } } | d  k r d } n  t | d ƒ } x5 | D]- }	 | j |	 ƒ r– | t |	 ƒ d  } Pq– q– Wx5 | D]- }
 | j |
 ƒ rÎ | t |
 ƒ d } PqÎ qÎ Wt | ƒ d k r| d } n  | t | ƒ d d k rO| t | ƒ d  } n  | j | | ƒ q^ W| S(   Nt   Ft   It   SIGt   HLAt   HLs   (+)s   (-)t   PLUSt   MINUSt   +t   -t   MINUt    i    i   t   _(	   R   R   R   t   zipt   strt   endswitht   lent
   startswitht   append(   t   labelst   label_appendixR   t   new_label_roott   standard_prefixt   standard_postfixt   labelt   appt   tmp_roott   postt   pre(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt   construct_output_labels,   s.    	c         C   sŒ   | d  k r t j } n  t j j |  ƒ s= t d |  ƒ ‚ n  t j d |  ƒ } | j	 d | ƒ } t
 j | ƒ } | j d | d d d | ƒ S(   Ns   No such file: >%s<t	   file_namet   crystal_symmetryR<   t   command_line_switchs   xray_data.labelst   f(   R   R   R   t   ost   patht   isfileR
   R   t   any_reflection_filet   as_miller_arraysR   t   label_tablet   select_array(   RB   R7   t   xst   logt   reflection_filet   miller_arraysRK   (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt	   read_dataN   s    			c      $   C   s²   d d d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ g$ } |  } |  | k r® | j  |  ƒ | t | ƒ } | | } n  | S(%   Nt   At   Bt   Ct   Dt   ER%   t   Gt   HR&   t   Jt   Kt   Lt   Mt   Nt   Ot   Pt   Qt   Rt   St   Tt   Ut   Vt   Wt   Xt   Yt   Zt   0t   1t   2t   3t   4t   5t   6t   7t   8t   9(   t   indexR4   (   t   chain_idt	   incrementt   idst   resultt	   new_index(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt   chain_name_modifier\   s    !!!i   c         C   s"  | d  k	 s t ‚ | d  k r* t j } n  | } | d  k rE |  } n  | d  k	 rb | d | IJn  | r… | d t | j ƒ  ƒ IJn d  } | j ƒ  } | j d |  j ƒ  ƒ | j	 d |  j
 ƒ  j ƒ  t j ƒ | j ƒ  }	 x) |	 j ƒ  D] }
 t |
 j | ƒ |
 _ qé W| |	 j d | ƒ IJd  S(   Ns	   REMARK %ss   REMARK Space group: %st   new_xyzt   new_bRC   (   R   t   AssertionErrorR   R   R2   t   space_group_infot   atomst   set_xyzt
   sites_cartt   set_bt
   scattererst   extract_u_isoR   t   u_as_b_factort   construct_hierarchyt   chainsRz   t   idt   as_pdb_string(   t   input_xray_structuret   input_crystal_symmetryt	   input_pdbR   t   chain_id_incrementt   additional_remarkt   print_cryst_and_scaleRM   t	   pdb_atomst	   hierarchyt   chain(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt   write_as_pdb_fileg   s*      			sË  xmanip{
  input{
    unit_cell=None
    .type=unit_cell
    .help="Unit cell parameters"
    space_group=None
    .type=space_group
    .help="space group"
    xray_data
    .multiple=True
    .help="Scope defining xray data. Multiple scopes are allowed"
    {
      file_name=None
      .type=path
      .help="file name"
      labels=None
      .type=str
      .help="A unique label or unique substring of a label"
      label_appendix=None
      .type=str
      .help="Label appendix for output mtz file"
      name = None
      .type = str
      .help="An identifier of this particular miller array"
      write_out=None
      .type=bool
      .help="Determines if this data is written to the output file"

    }
    model
    .help="A model associated with the miller arrays. Only one model can be defined."
    {
      file_name=None
      .type=path
      .help="A model file"
    }
  }
  parameters{
    action = *reindex manipulate_pdb manipulate_miller
    .type=choice
    .help="Defines which action will be carried out."
    reindex
    .help="Reindexing parameters. Acts on coordinates and miller arrays."
    {
      standard_laws = niggli *reference_setting primitive_setting invert user_supplied
      .type=choice
      .help="Choices of reindexing operators. Will be applied on structure and miller arrays."
      user_supplied_law='h,k,l'
      .type=str
      .help="User supplied operator."
    }
    manipulate_miller
    .help="Acts on a single miller array or a set of miller arrays."
    {
      include scope mmtbx.xmanip_tasks.master_params
    }
    manipulate_pdb
    .help="Manipulate elements of a pdb file"
    {
      task = set_b apply_operator *None
      .type=choice
      .help="How to manipulate a pdb file"
      set_b{
        b_iso = 30
        .type=float
        .help="new B value for all atoms"
      }
      apply_operator{
        standard_operators = *user_supplied_operator user_supplied_cartesian_rotation_matrix
        .type=choice
        .help="Possible operators"
        user_supplied_operator = "x,y,z"
        .type=str
        .help="Actualy operator in x,y,z notation"
        user_supplied_cartesian_rotation_matrix
        .help="Rotation,translation matrix in cartesian frame"
        {
          r = None
          .type=str
          .help="Rotational part of operator"
          t = None
          .type = str
          .help="Translational part of operator"
        }
        invert = False
        .type = bool
        .help = "Invert operator given above before applying on coordinates"
        concatenate_model=False
        .type=bool
        .help="Determines if new chain is concatenated to old model"
        chain_id_increment=1
        .type=int
        .help="Cain id increment"
      }
    }
  }
  output
  .help="Output files"
  {
    logfile=xmanip.log
    .type=str
    .help="Logfile"
    hklout=xmanip.mtz
    .type=str
    .help="Ouptut miller indices and data"
    xyzout=xmanip.pdb
    .type=str
    .help="output PDB file"
  }
}
t   process_includesc         C   s   d |  GHd  S(   NsH  
#phil __OFF__
		%s

A program for the manipulation of xray data objects (coordinates and reflection files).

The keywords are sumarized below:

#phil __ON__
xmanip {
  input {
    unit_cell = None
    space_group = None
    xray_data {
      file_name = None
      labels = None
      label_appendix = None
      name = None
      write_out = None
    }
    model {
      file_name = None
    }
  }
  parameters {
    action = reindex manipulate_pdb *manipulate_miller
    reindex {
      standard_laws = niggli *reference_setting invert user_supplied
      user_supplied_law = "h,k,l"
    }
    manipulate_miller {
      task = get_dano get_diso lsq_scale sfcalc *custom None
      output_label_root = "FMODEL"
      get_dano {
        input_data = None
      }
      get_diso {
        native = None
        derivative = None
        use_intensities = True
        use_weights = True
        scale_weight = True
      }
      lsq_scale {
        input_data_1 = None
        input_data_2 = None
        use_intensities = True
        use_weights = True
        scale_weight = True
      }
      sfcalc {
        fobs = None
        output = *2mFo-DFc mFo-DFc complex_fcalc abs_fcalc intensities
        use_bulk_and_scale = *as_estimated user_upplied
        bulk_and_scale_parameters {
          d_min = 2
          overall {
            b_cart {
              b_11 = 0
              b_22 = 0
              b_33 = 0
              b_12 = 0
              b_13 = 0
              b_23 = 0
            }
            k_overall = 0.1
          }
          solvent {
            k_sol = 0.3
            b_sol = 56
          }
        }
      }
      custom{
        code = print >> out, "hello world"
      }
    }
    manipulate_pdb{
      task = apply_operator *set_b
      apply_operator{
        operator = "x,y,z"
        invert=False
        concatenate_model=False
        chain_id_increment=1
      }
      set_b{
        b_iso = 30
      }
    }
  }
  output {
    logfile = "xmanip.log"
    hklout = "xmanip.mtz"
    xyzout = "xmanip.pdb"
  }
}
#phil __END__


Further details can be found in the documentation.

  (    (   t   command_name(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt
   print_helpù   s    fs   phenix.xmanipc   B      C   sy  t  |  ƒ d k s6 d |  k s6 d |  k s6 d |  k rF t d | ƒ n/t ƒ  } d |  k rw | 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	 rR| j | ƒ t }	 n  WqÜt k
 ri‚  qÜt k
 ry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 ƒ  } g  } d  } xE | j j j D]4 } | j d  k	 r[| j t j d | j ƒ ƒ q[q[W| j j j j d  k	 rÌt j d | j j j j ƒ } n  t  j! d | j j j" d | j j j# ƒ } t  j$ d  | | g | ƒ } | d  k	 rV| j" ƒ  | j j _" t% j& d | j# ƒ  ƒ | j j _# n  | d IJt j' d | ƒ } | j( d | ƒ | d IJ| j j j" d  k r°t d ƒ ‚ n  | j j j# d  k rÔt d ƒ ‚ n  g  } g  } g  } g  } i  } t  | j j j ƒ d k rét  j! d | j j j" d | j j j# ƒ } t) j* d  | d! t d" g  ƒ } d } x8| j j j D]'} | j d  k	 rkd  } t+ | j | j, | ƒ } | J| d# IJ| d$ IJ| d  k rÑt d% ƒ ‚ n  | j- d& | ƒ | J| j | ƒ | j | j. ƒ  j, ƒ | j | j/ ƒ d' t0 | ƒ } | j1 d  k	 rC| j1 } n  | j2 | ƒ rat d( ƒ ‚ n  | j3 i | | 6ƒ | d) 7} | j | j4 ƒ qkqkWt5 | | ƒ } x¬ t6 t  | ƒ ƒ D]˜ } d } x‰ t6 | d) t  | ƒ ƒ D]n } x> t7 | | | | ƒ D]% \ } }  | |  k rü| d) 7} qüqüW| d* k rÞ| d+ t0 | | ƒ IJqÞqÞWq¸Wx’ t6 t  | ƒ ƒ D]{ } xr t6 | d) t  | ƒ ƒ D]W } | | | | k r‡| | rÞ| | rÛ| d, IJ| | IJt d- ƒ ‚ qÛqÞq‡q‡WqgWn  d  }! d  }" | j j j j d  k	 rkt j8 j d | j j j j ƒ }! |! j9 d  | ƒ }" | d. IJ| d/ IJ|" j- d& | ƒ | Jn  t
 }# t
 }$ g  }% d  }& | j j: j; d0 k rt }# t< j= | | |" | j j: j= | ƒ }' | j |' ƒ | j j: j= j> }( |( d  k röd1 }( n  | j |( ƒ | j t ƒ n  | j j: j; d2 k r
t }# | j- ƒ  | j? ƒ  }) | j@ ƒ  }* | jA ƒ  }+ | jB ƒ  }, d  }- | j j: jC jD d3 k r�|) }- n  | j j: jC jD d4 k r°|* }- n  | j j: jC jD d5 k rÑ|+ }- n  | j j: jC jD d6 k r	t% jE | j j: jC jF ƒ }- n  | j j: jC jD d7 k r(	|, }- n  |- d  k rC	t d8 ƒ ‚ n  | d9 IJ| d: IJ| d; I|- jG ƒ  IJ| d< I|- jH ƒ  IJ| d= I|- jI ƒ  IJx? | D]7 } d  }. | d  k	 r 	| jJ |- ƒ }. |% j |. ƒ q 	q 	W|! d  k	 r
t }$ |" jJ |- ƒ }& q
n  |# rt  |% ƒ d k r#
| }% n  | J| d> IJ| d? IJ| J| d@ IJd  }/ t  |% ƒ d k rç
d }0 xA t6 t  | ƒ ƒ D]- }1 | |1 rz
|1 }0 |% |0 d  k	 r§
Pq§
qz
qz
W|% |0 d  k	 rç
|% |0 jK ƒ  }2 |2 jL dA | |0 ƒ }/ qç
n  |/ d  k	 rƒxT t7 |% |0 d) | |0 d) ƒ D]3 \ } }3 | d  k	 r|/ jM dB | dA |3 ƒ }/ qqW| dC | j jN jO IJ|/ jP ƒ  jQ d | j jN jO ƒ n  |& d  k	 rôtR | j jN jS dD ƒ }4 | dE | j jN jS IJtT dF |! dG |& d |4 dH d dI dJ | ƒ |4 jU ƒ  n  | |& g jV d  ƒ d* k r| dK IJqn  | j j: j; dL k r| j j: jW jX dM k rDd  }5 | j j: jW jY jZ dN k rªt% j[ | j j: jW jY j\ dO de ƒ}5 | dR I|5 jH ƒ  IJn  | j j: jW jY jZ dS k r¿| j j: jW jY j] }6 d  }7 d  }8 dT |6 j^ k r
|6 j^ j_ dT ƒ }7 n |6 j^ j_ dU ƒ }7 dT |6 j^ k r@|6 j` j_ dT ƒ }8 n |6 j` j_ dU ƒ }8 g  }9 g  }: x! |7 D] }1 |9 j ta |1 ƒ ƒ qeWt  |9 ƒ dV k rªt dW |6 j^ ƒ ‚ n  x! |8 D] }1 |: j ta |1 ƒ ƒ q±Wt  |: ƒ dX k röt dY |6 j` ƒ ‚ n  |: }: tb |9 |: ƒ }5 | dZ IJ|5 j( ƒ  tc jd |" j" ƒ  je ƒ  ƒ }; |; jf ƒ  |5 j^ ƒ  |; }7 |; jf ƒ  tc jg th |5 j` ƒ  ƒ ƒ }8 | J| d[ IJtb d\ |7 ji ƒ  d] th |8 ƒ ƒ }5 |5 j( d | ƒ | Jn  | j j: jW jY jj rõ|5 jf ƒ  }5 | J| d^ IJ| Jn  |" jk ƒ  }< tl jm ƒ  }= xb |< D]Z }> |5 j^ ƒ  tc jg |> ƒ }? tl jn |? ƒ tl jn |5 j` ƒ  jo ƒ  ƒ }? |= j tp |? ƒ ƒ qW|" jq ƒ  }& |& jr |= ƒ tR | j jN jS dD ƒ }4 | dE | j jN jS IJ| j j: jW jY js rýtT dF |! dG |" d |4 dH d dI d  d_ t ƒ n  tT dF |! dG |& d |4 dH | j j: jW jY jt dI d  d_ t
 ƒ |4 jU ƒ  n  | j j: jW jX d` k r| j j: jW ju rÂ| j j: jW jv }@ |" jw da |@ ƒ }& | J| db |@ IJ| dc | j jN jS IJ| Jn  tR | j jN jS dD ƒ }4 tT dF |! dG |& d |4 dH d dI d  d_ t ƒ |4 jU ƒ  qn  tR | j jN jx dD ƒ }A | dd | j jN jx IJ|A | jy ƒ  d t  | jy ƒ  ƒ d) !IJ|A jU ƒ  d  S(f   Ni    s   --helps   --hs   -hR•   s   --quietR<   R   t   file_objectt
   log_buffert
   home_scopet	   map_coefss   #phil __OFF__s   ==========================s             XMANIP          s   reindexing and other tasksRB   t   args2   ##----------------------------------------------##s   ## Unknown file or keyword:s   Unknown file or keyword: %st   sourcest	   unit_cellR~   t   groups   #phil __ON__t   python_objectR   s   #phil __END__s   unit cell not specifieds   space group not specifiedRC   t   force_symmetryt   reflection_filess   Summary info of observed datas   =============================s%   Failed to read data. see errors aboveRE   t   COL_s7   Non unique dataset name. Please change the input scripti   i   sU   
***** You are trying to import the data with label(s) %s more then one time. ***** 
s   Output label roots:s+   Output labels are not unique. Modify input.s   Atomic model summarys   ====================t   manipulate_millert   UNSPECIFIEDt   reindext   nigglit   reference_settingt   invertt   user_suppliedt   primitive_settings)   No change of basis operation is supplied.s   Supplied reindexing law:s   ========================s   hkl notation: s   xyz notation: s   abc notation: s'   The data has been reindexed/manipulateds&   --------------------------------------s   Writing output files....t   column_root_labelt   miller_arrays   Writing mtz file with name %st   ws   Wring pdb file to: %sRŒ   RŠ   R�   RŽ   s   Generated by %ss7   No input reflection of coordinate files have been givent   manipulate_pdbt   apply_operatort   user_supplied_operatort   t_deni   i   s   Applied operator : t'   user_supplied_cartesian_rotation_matrixt   ,t    i	   s/   Invalid rotation matrix. Please check input: %si   s4   Invalid translational vector. Please check input: %ss+   User supplied cartesian matrix and vector: s$   Operator in fractional coordinates: R   R   s    Taking inverse of given operatorR�   R‚   t   values#   All B-values have been set to %5.3fs   Writing PDB file %ss   Writing log file with name %s  i`   (z   R4   R–   R   t   registerR   R   R   t   master_paramst!   command_line_argument_interpreterR   t   FalseRF   RG   RH   t   iotbxt   philt   parseR6   R   t   KeyboardInterruptt	   Exceptiont   processR
   t   fetcht   extractt   xmanipt   inputt	   xray_dataRB   R   t   extract_fromt   modelR   t   symmetryR�   t   space_groupt   select_crystal_symmetryR   R~   R   R!   R   t   reflection_file_serverRQ   R7   t   show_summaryt   infoR8   R2   t   namet   has_keyt   updatet	   write_outRA   t   rangeR1   t   pdbt   xray_structure_simplet
   parameterst   actionR   R£   t   output_label_roott!   change_of_basis_op_to_niggli_cellt'   change_of_basis_op_to_reference_settingt"   change_of_basis_op_to_inverse_handt'   change_of_basis_op_to_primitive_settingR¥   t   standard_lawst   change_of_basis_opt   user_supplied_lawt   as_hklt   as_xyzt   as_abct   change_basist
   map_to_asut   as_mtz_datasett   add_miller_arrayt   outputt   hkloutt
   mtz_objectt   writet   opent   xyzoutR“   t   closet   countR®   t   taskR¯   t   standard_operatorst   rt_mxR°   R²   R   t   splitR   t   floatR   R	   R   t   orthogonalization_matrixR   t   colt   listt   as_floatR¨   t
   sites_fracR   t   vec3_doubleR   t	   as_doublet   tuplet   deep_copy_scattererst   set_sites_fract   concatenate_modelR�   R‚   t   b_isot	   set_b_isot   logfilet   getvalue(B   t   argsR•   RN   t   string_buffert   string_buffer_plotst   phil_objectst   argument_interpreterR›   t   command_line_paramst   arg_is_processedt   effective_paramst   paramst   hkl_xst   pdb_xsRÄ   t   phil_xst   combined_xst
   new_paramsRP   R7   R8   t   write_itt   namest   xray_data_serverRì   R¬   t	   this_nameRÖ   t   iit   testt   jjt	   lab_name1t	   lab_name2t	   pdb_modelRÆ   t   write_miller_arrayt   write_pdb_filet   new_miller_arrayst	   new_modelt
   new_millerR>   t	   to_nigglit   to_referencet
   to_inverset   to_primitivet   cb_opt   new_miller_arrayt   mtz_datasett   firstR    R   t   new_roott   pdb_fileRï   t   rtt   tmp_rt   tmp_tt	   tmp_tmp_rt	   tmp_tmp_tt   ot   sitest	   new_sitest   sitet   new_siteRý   t   logger(    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt   runa  s|   6					




    

		$

					


 $# 



 

			
				

	



			

%
!
(
'(&   t
   __future__R    t   mmtbxR   Rº   R   R   R   t
   iotbx.philt	   iotbx.pdbt   cctbxR   R   R   t   cctbx.array_familyR   t   scitbx.mathR	   t   libtbx.utilsR
   R   t	   cStringIOR   R   RF   t   objectR   R   RA   RQ   Rz   R   R“   R»   R¼   R·   R–   R3  (    (    (    s:   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/xmanip.pyt   <module>   s:   "		o	h