ó
¶™xTc           @   sá   d  d l  m Z d  d l m Z d  d l m Z d  d l 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 Z e j j d
 ƒ Z d Z d „  Z d d „ Z d S(   iÿÿÿÿ(   t   division(   t   pdb(   t   flexN(   t   tlso(   t   adptbx(   t   iotbx_option_parser(   t   utils(   t   SorrysL  selection = None
  .type = str
  .multiple = True
  .help = Selection for TLS groups. Extracted from PDB file header or provided           below.
combine_tls = None
  .type = bool
  .help = Combine ADP contribution from TLS matrices (from PDB file header)           with ADP in ATOM records.
extract_tls = None
  .type = bool
  .help = Fit TLS matrices to B-factors of selected sets of atoms.
output_file_name = None
  .type = str
  .help = Prefix for output files.
enforce_positive_definite_TL = True
  .type = bool
  .help = Make sure the output T and L matrices are positive definite.
sk  Author:
  Pavel Afonine

Pupose:
  - Fit TLS matrices to B-factors of selected sets of atoms. Example:
      phenix.tls model.pdb extract_tls=true selection='chain A' selection='chain B'
  - Combine B-factors computed from TLS matrices (extracted from PDB file header)
    with the B-factors from ATOM records of selected sets of atoms. Example:
      phenix.tls model.pdb selection='chain A' selection='chain B' combine_tls=true
  - The output PDB file can be of two types: contain total ADP in ATOM records
    (B_tls + B_residual) and B_residual in ATOM records.

Questions and problems:
  phenixbb@phenix-online.orgc         C   sU   |  j  ƒ  t j d |  j d d d d  ƒ } | j } | sQ | j d | ƒ | Jn  | S(   Nt   processed_pdb_filet   scattering_tablet   wk1995t   d_mint   f(   t   set_ppfR   t'   xray_structures_from_processed_pdb_fileR   t   Nonet   xray_structure_allt   show_summary(   t   mmtbx_pdb_filet   logt   silentt   xsfppft   xray_structure(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/tls/command_line.pyt   get_xrs_helper4   s    
				s
   phenix.tlsc          C   s„	  t  |  ƒ d k r d g }  n  d } d } t d | | d t ƒ j d d d	 d
 d ƒj d d d	 d
 d ƒj d |  ƒ } t j } | j j s¤ t	 j
 d d | ƒn  | j j rÈ t j d | ƒ | Jd  S| j j sá | t IJn  t	 j d | j d t d | ƒ } | j } | j d  k r)t d ƒ ‚ n  t  | j ƒ d k rMt d ƒ ‚ n  | j } | j j sˆt	 j
 d d | ƒ| j d | ƒ n  | j ƒ  } | j j ƒ  d  k s¾| j j ƒ  d  k rÍt d ƒ ‚ n  t	 j d | j d | j d | j d | ƒ }	 | j j st	 j
 d d | ƒn  t j j j d |	 j j  d ƒ d |	 j j! ƒ  ƒ }
 g  } |
 j" rã|
 j# d  k	 rt |
 j# ƒ ‚ n  |	 j$ ƒ  t% d |	 d | d | j j ƒ } t j j j& d  |
 d! |	 j' j( d" | ƒ } | j) j* } n  g  } t  | ƒ d k r| j j r| d# IJnw xt t+ | ƒ D]f \ } } | j, | j- ƒ | j j s"| d$ | d% | j- f IJt j j j. d& | d | ƒ | Jq"q"Wt  | ƒ d k rÂt  | j/ ƒ d k rÂt d' ƒ ‚ n  t  | j/ ƒ d k r| j/ } t% d |	 d | d | j j ƒ } n  | j0 | j1 g j2 t3 ƒ d% k r4t d( ƒ ‚ n  | j0 | j1 g j2 t3 ƒ d k ryt  | ƒ d k ryt d) ƒ ‚ qyn  t  | ƒ rü| j j s§t	 j
 d* d | ƒn  t	 j4 d! |	 j' j( d+ | d" | ƒ } | j j s
| d, It  | ƒ IJ| d- | j5 ƒ  j6 ƒ  IJn  d } x | D] } | | j6 ƒ  7} qW| j j sR| d. | IJ| Jn  t  | ƒ t  | ƒ k spt7 ‚ | j j süxC t8 | | ƒ D]2 \ } } | d/ | IJ| d0 | j6 ƒ  IJ| JqŒW| d1 IJx* t8 | | ƒ D] \ } } | | IJqÜWqün  | j9 } | d  k r‘t: j; j< t: j; j= | j d ƒ ƒ d } t  | j ƒ d% k r\| d2 } n  | j0 rr| d3 } q‘| j1 rˆ| d4 } q‘d  } n  | d  k	 r¯t> | d5 ƒ } n  | j1 rÖt	 j
 d6 d | ƒt j j j? d7 | d" | d8 d9 ƒ } xî d% d d% g d% d% d% g d d% d% g d% d d g d d% d g d d d% g d% d% d% g d d d% g g d: D]‚ \ } } } t j j j@ d" | d7 | d; | d< d: d= d> d? | d@ | dA | dB | jA dC dD d | ƒ } t j j jB dE | d | ƒ qZWt j j jC dF | jD ƒ  d7 | dE | ƒ } | j ƒ  } xw t+ | j5 ƒ  ƒ D]c \ } } | | dM k r)tE jF | tG | | ƒ ƒ } tG tH jI | jJ ƒ tH jI | ƒ ƒ | _J q)q)Wx | D] } | jK dG | ƒ q—Wt j j jL dE | d+ | d | ƒ n  | j0 r!	t	 j
 dH d | ƒt j j jM d" | dI | dJ | ƒ | dK IJn  | d  k	 r€	t	 j
 dL | d | ƒt	 jN d" | d |	 j' j( jO d | ƒ | jP ƒ  | dK IJn  d  S(N   Ni    s   --helps5   %s pdb_file [parameters: file or command line string]sI   Example: %s model.pdb fit_tls_to.selection='%s' fit_tls_to.selection='%s't   usaget   descriptions   --show_defaultst   actiont
   store_truet   helps,   Do not output to the screen (except errors).s   --silents   Suppress output to the screen.t   argss	   TLS toolst   outt   master_paramsR   s   No crystal symmetry found.s   No PDB file found.s   Input parameterss   No CRYST1 record found.t   pdb_file_namest   cif_objectst   crystal_symmetrys   TLS groups from PDB file headert   remark_3_recordsi   t   pdb_hierarchyR   R   t   pdb_inp_tlst   all_chain_proxiesR   s'   No TLS groups found in PDB file header.s   TLS group %d: %si   R   s@   Two TLS selection sources found: PDB file header and parameters.s;   Cannot simultaneously pereform: combine_tls and extract_tlss   No TLS selections found.s   TLS groups selectionst   selection_stringss   Number of TLS groups: s   Number of atoms: %ds!   Number of atoms in TLS groups: %ds   Selection string:
%ss   selects %d atoms.s   Ready-to-use in phenix.refine:
t   _el_als   _combine_tls.pdbs   _extract_tls.pdbt   ws7   Fit TLS matrices to B-factors of selected sets of atomst
   selectionst   valueg        i
   t   tlsos_initialt   number_of_macro_cyclest   max_iterationsid   t   refine_Tt   refine_Lt   refine_St   enforce_positive_definite_TLt   verboseiÿÿÿÿt   tlsost
   sites_cartt	   selections   Combine B_tls with B_residualt   tls_selectionst
   tls_groupss	   All done.s   Write output PDB file %s(   i    i    i    i    i    i    (Q   t   lenR   t   bannert   optiont   processt   syst   stdoutt   optionsR   R   t   print_headert   show_defaultsR   t   showt   process_command_line_argsR   t   reflection_filesR"   R   R   R    t   paramst   extractt	   unit_cellt   space_groupt   pdb_fileR!   t   mmtbxt   tlst   toolst   tls_from_pdb_inpt   pdb_inpt   extract_remark_iii_recordst   construct_hierarchyt   tls_presentt   error_stringR   R   t   extract_tls_from_pdbR   R&   R%   t
   tls_paramst	   enumeratet   appendt   selection_stringt   show_tls_one_groupR6   t   combine_tlst   extract_tlst   countt   Truet   get_atom_selectionst
   scattererst   sizet   AssertionErrort   zipt   output_file_namet   ost   patht   splitextt   basenamet   opent   generate_tlsost   tls_from_uanisosR2   t   show_tlst   u_cart_from_tlsR5   R   t   u_cart_as_u_start   tupleR   t   doublet   u_start   convert_to_isotropict   remark_3_tlst   combine_tls_and_u_localt   write_pdb_fileR$   t   close(    R   t   command_namet	   usage_fmtt   des_fmtt   command_lineR   t   processed_argsRD   RE   R   R%   R8   R   t   pdb_tlst   tls_selections_stringst   i_seqt	   tls_groupR*   t   n_atoms_in_tlst   sel_at   sel_st   ofnt   ofoR4   t   rtt   rlt   rsRk   RG   t   sct
   u_star_tlst   sel(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/tls/command_line.pyt   run@   sN    
												
	'	!!		
	)					'0#		 		/		
(   t
   __future__R    t   iotbxR   t   cctbx.array_familyR   R=   t   mmtbx_tls_extR   Rc   t   cctbxR   t   iotbx.option_parserR   t
   iotbx.philRJ   R   t   libtbx.utilsR   t   mmtbx.tls.toolst   philt   parseR   R:   R   R‰   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/tls/command_line.pyt   <module>   s    			