ó
±™xTc           @   s¬   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 Z d  d l	 m
 Z
 d „  Z d Z d d d	 d
 „ Z e d k r¨ e d e j d ƒ n  d S(   iÿÿÿÿ(   t   divisionN(   t   flex(   t   easy_pickle(   t   format_valuec         C   s‡   t  j d |  d | ƒ } | j ƒ  } t | j ƒ  ƒ } xJ | D]B \ } } | j ƒ  | j ƒ  | d } d | | | f GH| } q= Wd  S(   Nt   datat   n_slotsi   s   %10.3f - %-10.3f : %d(   R   t	   histogramt   data_mint	   enumeratet   slotst
   slot_width(   R   R   t   hmt   lc_1t   s_1t   i_1t   n_1t   hc_1(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/r_factor_statistics.pyt   show_histogram
   s    s  phenix.r_factor_statistics: a tool to show Rwork, Rfree and Rfree-Rwork
                            statistics for PDB structures.

Usage:
  - running phenix.r_factor_statistics without arguments will consider all PDB
    structures;
  - runing with single numeric argument
      phenix.r_factor_statistics 2.5
    will consider structures in resolution range [2.5-0.1, 2.5+0.1]
  - one can specify left and right offsets as well as the number of bins
      phenix.r_factor_statistics 2.5 left_offset=0.1 right_offset=0.5 n_bins=10
gš™™™™™¹?i
   c         C   s±  t  } t |  ƒ d k r! t } n3 x0 |  D]( } t | ƒ j ƒ  d  k r( t } Pq( q( W| rb t GHn  d „  } d  } xã |  D]Û } t | ƒ j ƒ  } y t | ƒ } Wn t k
 r³ n X| j	 d ƒ rç | | ƒ } | d  k	 rç | } qç n  | j	 d	 ƒ r| | ƒ } | d  k	 r| } qn  | j	 d
 ƒ rx t
 | | ƒ ƒ } | d  k	 rS| } qSqx qx Wd d }	 }
 | d  k	 râd t d | ƒ j ƒ  t d | ƒ j ƒ  t d | ƒ j ƒ  t d | ƒ j ƒ  f } d | GH| | }	 | | }
 n  t j j d d d t j j ƒ } t j | ƒ } | d } | d } | d } | d k } | | d k M} | | d k M} | j | ƒ } | j | ƒ } | j | ƒ } d „  } | | ƒ } | | ƒ } | | ƒ } | | } | |	 k } | | |
 k  M} | | d k M} | | d k  M} | j | ƒ } | j | ƒ } | j | ƒ } | j | ƒ } d |	 |
 f GHt d | d | ƒ d |	 |
 f GHt d | d | ƒ d |	 |
 f GHt d | d | ƒ d G| j ƒ  GHd  S(!   Ni    t   helps   -hs   --helps   --ht   hc         S   sO   d  } y! t |  |  j d ƒ d ƒ } Wn! t k
 r: n t k
 rJ n X| S(   Nt   =i   (   t   Nonet   floatt   indext
   IndexErrort
   ValueError(   t   xt   result(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/r_factor_statistics.pyt	   get_value,   s    !  t   left_offsett   right_offsett   n_binsg    €„.AsF   phenix.r_factor_statistics %s left_offset=%s right_offset=%s n_bins=%ss   %6.3fs   %ds   Command used:

%s

t   relative_paths%   chem_data/polygon_data/all_mvd.picklet   testt   pdb_header_r_workt   pdb_header_r_freet   high_resolutiont   nonec         S   s4   t  j ƒ  } x! |  D] } | j t | ƒ ƒ q W| S(   N(   R   t   doublet   appendR   (   R   t   tmpt   x_(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/r_factor_statistics.pyt   str_to_floatZ   s    g        gš™™™™™¹?sA   Histogram of Rwork for models in PDB at resolution %4.2f-%4.2f A:R   R   sA   Histogram of Rfree for models in PDB at resolution %4.2f-%4.2f A:sJ   Histogram of Rfree-Rwork for all model in PDB at resolution %4.2f-%4.2f A:s    Number of structures considered:(   s   helps   -hs   --helps   --hR   (   t   Falset   lent   Truet   strt   lowert   help_messageR   R   R   t   countt   intR   t   stript   libtbxt   envt   find_in_repositoriest   ost   patht   isfileR   t   loadt   selectR   t   size(   t   argsR   R   R   t   need_help_msgt   argR   t   d_minR   t   dlt   drt   cmdt   filet   database_dictt
   r_work_pdbt
   r_free_pdbt   selR*   t   diff(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/r_factor_statistics.pyt   run!   s�     		     	



	
t   __main__R=   i   (   t
   __future__R    R7   t   syst   cctbx.array_familyR   R4   R   t   libtbx.load_envt   libtbx.str_utilsR   R   R0   RJ   t   __name__t   argv(    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/r_factor_statistics.pyt   <module>   s   	V