ó
´xTc        	   @   sG   d  Z  d d l m Z d d l Z e e e d d d e d d  Z d S(   s  
Tools for analyzing disorder (or heterogeneity in general) in ensembles and
and other multi-conformer models or collections of conformations.  For building
and refinement of such models, see mmtbx.building.alternate_conformations or
mmtbx.refinement.ensemble_refinement.
i˙˙˙˙(   t   divisionNt   rmsfg      đżc	         C   s)  | d k r t   } n  | d k s* t  d d l m }	 d d l m }
 |  j   } | j   i  } d   } d   } xú |  j	   D]ě } xă | j   D]Ő } | d k	 rŔ | | j
 sq qnD | râ | j j   d k râ q n" | r| j   j d k rq n  | r%| j j   d k r%q n  | |  } | | k rT| | j | j  q |
 j | j g  | | <q Wq Wi  } x§ | j   D] \ } } | d k rę|	 d | d d  } | j   } | rÝt j | d  } n  | | | <q|
 j | j   | j    } | j |  } | | | <qW|
 j | j    } | d k rS| d IJn
 | d IJ|
 j | d d j d | d d d d  x |  j	   D] } x | j   D]u } | rü| |  } | d k rŘ| | _ q| |  } | j | |  | _ q¨| |  } | j | |  | _ q¨WqWd S(   s  
  Given an ensemble (multi-MODEL PDB hierarchy), calculate the deviation
  between copies of each atom (defined here as either the root-mean-square
  fluctuation, or the radius of the minimum covering sphere) and set the
  isotropic B-factors to this value.
  R   t   mcsi˙˙˙˙(   t   minimum_covering_sphere(   t   flexc         S   s+   |  j    } | j | j   | j |  j f S(   N(   t   fetch_labelst   chain_idt   residt   altloct   name(   t   atomt   labels(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/disorder/__init__.pyt   get_key"   s    c         S   s}   |  j  j   d k r. |  j j   d k r. |  SxH |  j   j   D]4 } | j  j   d k rA | j j   d k rA | SqA Wd  S(   Nt   CAt   C(   R	   t   stript   elementt   parentt   atomst   None(   R
   t   other(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/disorder/__init__.pyt   get_c_alpha%   s    **t   Ht   Dt   HOHR   t   pointst   epsilongš?g      đ?s   Distribution of sphere radii:s4   Distribution of root-mean-square fluctuation values:t   n_slotsi   t   ft   prefixs     t   format_cutoffss   %.2fN(   s   rmsfs   mcs(   R   R   (   R   (    R   t   null_outt   AssertionErrort   scitbx.mathR   t   scitbx.array_familyR   R   t   reset_i_seqt   modelst   i_seqR   R   R   t   resnameR	   t   appendt   xyzt   vec3_doublet	   iteritemst   radiust   matht   logt   sizet   meant   rms_differencet   doublet   valuest	   histogramt   showt   bt   get(   t   pdb_hierarchyt   include_hydrogenst   include_waterst   use_c_alpha_valuest   methodt	   selectiont   substitute_b_valuet   logarithmicR-   R   R   t	   pdb_atomst   xyz_by_atomR   R   t   modelR
   t   atom_keyt   dev_by_atomR(   R   R+   t
   mean_arrayR   t   all_devt   c_alpha(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/disorder/__init__.pyt*   set_ensemble_b_factors_to_xyz_displacement   sh     
		 	!
$(   t   __doc__t
   __future__R    R,   t   FalseR   RG   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/disorder/__init__.pyt   <module>   s   