ó
±™xTc           @   sÆ   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	 Z
 d Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z e j d „ Z e d k rÂ e d e j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   flexN(   t   Sorrys^  phenix.model_model_distances:
  Given two PDB files output distances per atom, residue, chain, model and overall.
  It is assumed (and asserted in the code!) that the amount and order of atoms
  in both files are identical.

How to run:
  phenix.model_model_distances model_1.pdb model_2.pdb

Feedback:
  PAfonine@lbl.gov
  phenixbb@phenix-online.orgc         C   sR   |  j  ƒ  } | j  ƒ  } | j d | ƒ } | j ƒ  j ƒ  } | d | IJ| Jd  S(   Nt   others(   Overall  min/max/mean: %8.3f %8.3f %8.3f(   t   extract_xray_structuret	   distancest   min_max_meant   as_tuple(   t   h1t   h2t   logt   x1t   x2t   d(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/model_model_distances.pyt   compute_overall   s    c   
      C   sš   |  j  ƒ  } | j d ƒ } | j  ƒ  } | j d ƒ } |  j | ƒ j ƒ  } | j | ƒ j ƒ  } | j d | ƒ }	 |	 j ƒ  j ƒ  }	 | d |	 IJ| Jd  S(   Ns%   name ca or name n or name o or name cR   s(   Backbone min/max/mean: %8.3f %8.3f %8.3f(   t   atom_selection_cachet
   iselectiont   selectR   R   R   R   (
   R   R	   R
   t   selection_cache1t   isel1t   selection_cache2t   isel2R   R   R   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/model_model_distances.pyt   compute_overall_backbone   s    c         C   sº   t  |  j ƒ  ƒ d k r d  S| d IJx‰ t |  j ƒ  | j ƒ  ƒ D]l \ } } | j ƒ  j ƒ  } | j ƒ  j ƒ  } t j | | j ƒ  ƒ j ƒ  j	 ƒ  } | | j
 Id | IJqB W| Jd  S(   Ni   s   Per model (min/max/mean):s   : %-8.3f %-8.3f %-8.3f(   t   lent   modelst   zipt   atomst   extract_xyzR   t   sqrtt   dotR   R   t   id(   R   R	   R
   t   m1t   m2t   r1t   r2R   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/model_model_distances.pyt   compute_per_model+   s     
(%c         C   sÒ   t  |  j ƒ  ƒ } t  | j ƒ  ƒ } t | ƒ d k r: d  S| d IJxƒ t | | ƒ D]r \ } } | j } | j ƒ  j ƒ  } | j ƒ  j ƒ  }	 t j | |	 j	 ƒ  ƒ j
 ƒ  j ƒ  }
 | | Id |
 IJqT W| Jd  S(   Ni   s   Per chain (min/max/mean):s   : %-8.3f %-8.3f %-8.3f(   t   listt   chainsR   R   R   R   R   R   R   R   R   R   (   R   R	   R
   t   cs1t   cs2t   c1t   c2t   labelR!   R"   R   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/model_model_distances.pyt   compute_per_chain5   s     
	%c         C   s  t  |  j ƒ  ƒ } t  | j ƒ  ƒ } t | ƒ d k r: d  S| d IJxÆ t | | ƒ D]µ \ } } d d j | j ƒ  j j ƒ  | j ƒ  j ƒ  d j t  | j	 ƒ  ƒ ƒ g ƒ } | j
 ƒ  j ƒ  } | j
 ƒ  j ƒ  }	 t j | |	 j ƒ  ƒ j ƒ  j ƒ  }
 | | Id |
 IJqT W| Jd  S(   Ni   s   Per residue (min/max/mean):s   %10st   /t   _s   : %-8.3f %-8.3f %-8.3f(   R$   t   residue_groupsR   R   t   joint   parentR   t   stript   residt   unique_resnamesR   R   R   R   R   R   R   (   R   R	   R
   t   rgs1t   rgs2t   rg1t   rg2R*   R!   R"   R   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/model_model_distances.pyt   compute_per_residueB   s     
	"%c   
      C   sÍ   t  |  j ƒ  ƒ } t  | j ƒ  ƒ } t | ƒ d k r: d  S| d IJx‚ t | | ƒ D]q \ } } t j | j g ƒ } t j | j g ƒ } t j | | j ƒ  ƒ }	 | | j	 ƒ  d  Id |	 d IJqT Wd  S(   Ni   s	   Per atom:i   s   : %-8.3fi    (
   R$   R   R   R   R   t   vec3_doublet   xyzR   R   t   format_atom_record(
   R   R	   R
   t   as1t   as2t   a1t   a2R!   R"   R   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/model_model_distances.pyt   compute_per_atomR   s     
c         C   sª  | d d IJ| t  IJ| d d IJt j j d |  ƒ } | j } t | ƒ d k re t d ƒ ‚ n  t j j	 d | d ƒ } t j j	 d | d ƒ } | j
 ƒ  d  k	 rÖ | j
 ƒ  j | j
 ƒ  ƒ sÖ t d	 ƒ ‚ qÖ n  | j ƒ  } | j ƒ  } | j | ƒ st d
 ƒ ‚ n  | Jt d | d | d | ƒ t d | d | d | ƒ t d | d | d | ƒ t d | d | d | ƒ t d | d | d | ƒ t d | d | d | ƒ d  S(   Nt   -iO   t   argsi   s   Two PDB files has to given.t	   file_namei    i   s!   CRYST1 records must be identical.s5   Input PDB files have different content or atom order.R   R	   R
   (   t   legendt   mmtbxt   utilst   process_command_line_argst   pdb_file_namesR   R   t   iotbxt   pdbt   inputt   crystal_symmetry_from_cryst1t   Nonet   is_similar_symmetryt   construct_hierarchyt   is_similar_hierarchyR   R   R#   R+   R8   R@   (   RB   R
   t   inputst
   file_namest   pi1t   pi2R   R	   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/model_model_distances.pyt   run]   s0    
	 t   __main__RB   i   (   t
   __future__R    t   scitbx.array_familyR   t   syst	   iotbx.pdbRI   t   libtbx.utilsR   t   mmtbx.utilsRE   RD   R   R   R#   R+   R8   R@   t   stdoutRU   t   __name__t   argv(    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/model_model_distances.pyt   <module>   s   			
			