ó
4™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 m	 Z	 d  d l
 m Z d  d l Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z e d k r'e ƒ  n  d S(   iÿÿÿÿ(   t   division(   t   xray_scattering(   t   itvc_section61_io(   t	   kissel_io(   t   international_tables_stols(   t   tiny_pse(   t   flexN(   t   OptionParser(   t   adopt_init_args(   t   easy_picklet   labeled_fitc           B   s   e  Z d  „  Z RS(   c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   t   locals(   t   selft   labelt   gaussian_fit(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyt   __init__   s    (   t   __name__t
   __module__R   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyR
      s   t   read_pickled_fitsc           B   s   e  Z d  „  Z RS(   c         C   së   d  |  _ i  |  _ xÒ | D]Ê } t j | ƒ } | d j } |  j d  k rV | |  _ nB x? | j ƒ  D]1 \ } } t |  j | ƒ t | ƒ k sc t ‚ qc W| d =t	 |  j ƒ } |  j j
 | ƒ t	 |  j ƒ | t	 | ƒ k s t ‚ q Wd  S(   Nt   fit_parameters(   t   Nonet
   parameterst   allR	   t   loadt   __dict__t   itemst   strt   AssertionErrort   lent   update(   R   t   gaussian_fit_pickle_file_namest	   file_namet   fitst   fpt   kt   vt   size_before(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyR      s    		)(   R   R   R   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyR      s   c         C   sy   g  } |  d  k r? x` t j ƒ  D] } | j | j ƒ  ƒ q Wn6 x3 t d d ƒ D]" } | j t j | ƒ j ƒ  ƒ qO W| S(   Ni   id   (	   R   R   t   wk1995_iteratort   appendR   t   xrangeR   t   tablet   symbol(   t
   kissel_dirt   resultt   wkt   atomic_number(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyt   expected_labels%   s     c      	   C   sP  d  } | d  k	 r$ t j | ƒ } n  t |  ƒ } x* | j j ƒ  D] \ } } d | G| GHq@ WHt j ƒ  } g  } d }	 xIt | ƒ D];}
 y | j	 |
 } Wn t
 k
 r¶ d G|
 GHqƒ Xd G|
 GHd  } xë| D]ã} | d  k	 r+| j | j k rù d GHq+| j | j k r+| j | j k  r(d GHq(q+n  | } | j ƒ  j ƒ  d  } | d  k	 rÁ|
 d k rÁ| j |
 } t | j d k } t j j j t j | ƒ | j j | ƒ | j j | ƒ | ƒ } n® | d  k	 rot j j | d	 t j |
 ƒ j ƒ  |
 f ƒ } t j | ƒ } | j  ƒ  | j! | j d k @} t j j j | j! j | ƒ | j" j | ƒ | j# j | ƒ | ƒ } n  | d  k	 rÍ | j$ t j% | j& ƒ  ƒ ƒ | j$ t' |
 | ƒ ƒ qÍ qÍ W|	 d
 7}	 qƒ WH|	 t( | j	 ƒ k ròd t( | j	 ƒ |	 GHHn  | j) ƒ  d k rLd GHt j* d | d t+ ƒ } | j | ƒ } t j | | ƒ } i  } xý t, | | ƒ D]ì \ } } | j- Gd | j. j/ ƒ  | f GH| | | j- d t0 | j. j/ ƒ  ƒ <| d k rX| j. } | j& ƒ  } xu t, | j1 ƒ  | j ƒ  | j2 ƒ  | ƒ D]L \ } } } } d } | d k rd } n  d | | | | | | | f GHqðWHqXqXWHn  d  S(   Ns   # %s:i    s#   # Warning: Missing scattering_type:s   scattering_type:s   # Warning: decreasing stols2   # Warning: same stol but previous has larger errors   O2-g�íµ ÷Æ°>s
   %02d_%s_rfi   s&   # Warning: %d fits were not processed.s   Summary:t   datat   reverses   n_terms=%d max_error: %.4ft   _g{®Gáz„?t    s    large errors   %4.2f %7.4f %7.4f %7.4f %7.4f%s(3   R   R   t   read_table6111R   R   R   R   t   doubleR.   R   t	   Exceptiont   stolt	   max_errort   sortt   showt   entriesR   t   scitbxt   matht   gaussiant   fitt   selectt   table_yt   table_sigmast   ost   patht   joinR   R(   R-   R   t
   read_tablet   itvc_sampling_selectiont   xt   yt   sigmasR&   t   maxt   significant_relative_errorsR
   R   t   sizet   sort_permutationt   Truet   zipR   R   t   n_termsR   t   table_xt   fitted_values(   R   t   itvc_file_nameR*   t   itvc_tabR    R"   R#   t
   max_errorst   labeled_fitst   n_processedR   t	   fit_groupt   prev_fitR>   R   t   entryt   selR   t   tabt   permt   quick_summaryt   met   lft   ret   sRH   t   at   rt   comment(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyt   run/   s–    	 
$	: 	#c         C   s  g  } x$ |  D] } | j  t j | ƒ ƒ q Wt | ƒ d k sE t ‚ g  } t j ƒ  } t j ƒ  } d } d } d } x| d j ƒ  D]ú \ }	 }
 | d j |	 d  ƒ } | d  k	 r† d |	 |
 | f } |
 | k  rò | d | |
 7} | d 7} n? |
 | k r| d |
 | 7} | d 7} n | d 7} | d 7} | j  | ƒ | j  t
 |
 | ƒ ƒ | j  t j |	 j d ƒ d ƒ j ƒ  ƒ q† q† Wxg | t f | t f g D]M \ } } t j d	 | d
 | ƒ } t j | | ƒ } x | D] } | GHqÚWHq�Wd G| GHd G| GHd G| GHd G| | | GHd  S(   Ni   i    i   s   %-10s %7.4f %7.4fs    less    %7.4fs    greater %7.4fs    equalR1   R/   R0   s   n_less:s
   n_greater:s   n_equal:s   total:(   R&   R	   R   R   R   R   R4   R   t   getR   RJ   R   R(   t   splitR-   RN   t   FalseRM   R?   (   t   argst   quick_summariesR   t   linest   max_of_errorst   atomic_numberst   n_lesst	   n_greatert   n_equalt   label_1t   error_1t   error_2t   linet   sort_keyR0   R]   t
   perm_lines(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyt   cross_check~   sH    

*%				c       	   C   s  t  d d ƒ }  |  j d d d d d d d	 d
 ƒ|  j d d d d d d d	 d ƒ|  j d d d d d d d	 d ƒ|  j ƒ  \ } } t | ƒ d k  r§ |  j ƒ  d  S| j o¶ | j sÀ t ‚ | j rä t | ƒ d k sä t ‚ n  | j st	 d | d | j d | j ƒ n
 t
 | ƒ d  S(   Nt   usages+   usage: python %prog [options] file_name ...s   -ts   --itvct   actiont   storet   metavart   FILEt   helps'   file name for international tables datas   -ks   --kisselt	   DIRECTORYs   directory name for Kissel datas   -cs   --cross_checkt
   store_truet   defaulti    s&   compare two quick_summary.pickle filesi   i   R   RS   R*   (   R   t
   add_optiont
   parse_argsR   t
   print_helpt   itvct   kisselR   t   crossRf   Rx   (   t   parsert   optionsRj   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyt   main¥   s0    	
	 		c          C   s   d d l  m }  |  j ƒ  d  S(   Niÿÿÿÿ(   t   format_gaussian_fits(   t   cctbx.eltbx.developmentR‹   RŠ   (   R‹   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyRf   ¿   s    t   __main__(   t
   __future__R    t   cctbx.eltbxR   RŒ   R   R   t   cctbx.eltbx.gaussian_fitR   R   t   cctbx.array_familyR   t   scitbx.math.gaussianR;   t   libtbx.option_parserR   t   libtbxR   R	   RB   t   objectR
   R   R.   Rf   Rx   RŠ   R   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/eltbx/development/format_gaussian_fits.pyt   <module>   s(   	
	O	'		