ó
‚™xTc           @   s-  d  Z  d d l m Z d d l m Z d d l m Z d d l Z d d l Z	 d d l
 Z
 d d l Z d e f d „  ƒ  YZ d „  Z d	 „  Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d d „ Z d e f d „  ƒ  YZ e e d „ Z d e f d „  ƒ  YZ d S(   s   
Tools for handling plottable data, usually similar to CCP4's loggraph format
(which may be parsed and output by this module).
iÿÿÿÿ(   t   division(   t   adopt_init_args(   t   SorryNt	   plot_datac           B   s   e  Z d  „  Z d „  Z RS(   c         C   sœ   | |  _  | |  _ | |  _ | |  _ | |  _ d |  _ g  |  _ g  |  _ | d  k	 r˜ t	 | ƒ t	 |  j ƒ k su t
 ‚ |  j j | ƒ |  j j | ƒ n  d  S(   Nt   A(   t
   plot_titlet   x_labelt   y_labelt   x_datat   commentst   domain_flagt   y_legendt   y_datat   Nonet   lent   AssertionErrort   append(   t   selfR   R   R   R   R   R   R	   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   __init__   s    								!c         C   sE   t  | ƒ t  |  j ƒ k s! t ‚ |  j j | ƒ |  j j | ƒ d  S(   N(   R   R   R   R   R   R   (   R   R   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   add_data*   s    !(   t   __name__t
   __module__R   R   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyR      s   	c   	      C   só  | J| J| d |  j  IJ| d IJ| d |  j Id } x3 t t |  j ƒ d ƒ D] } | d | d 7} qT W| d |  j | d  f IJ| d	 IJ|  j } d
 } t j | d ƒ } | d
 k r× | j	 d d ƒ } n  d | } xq t t |  j ƒ ƒ D]Z } |  j
 | } d
 } t j | d ƒ } | d
 k rC| j	 d d ƒ } n  | d | 7} q÷ W| d | IJ| d	 IJxu t t |  j ƒ ƒ D]^ } d |  j | } x6 t t |  j ƒ ƒ D] } | d |  j | | 7} q°W| d | IJqƒW| d	 IJd  S(   Ns   $TABLE: %s:s   $GRAPHSs   :%st    i   s   %d,s   :%s:%s:iÿÿÿÿs   $$i    t    t   _s   %ss      %ss   %s   $$ s   %fs      %f(   R   R	   t   rangeR   R   R
   R   t   stringt   findt   replaceR   R   (	   R   t   outputt   index_stringt   iit
   tmp_legendt   spacest   label_stringt   data_stringt   jj(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   plot_data_loggraph2   s>    
 
	

c         C   sÇ   |  d  k s t |  ƒ d k r" g  Sg  } x" |  d D] } | j | g ƒ q3 Wt |  ƒ d k rÃ xa |  d D]R } t | ƒ t | ƒ k sŽ t ‚ x+ t | ƒ D] \ } } | | j | ƒ q› Wqj Wn  | S(   Ni    i   (   R   R   R   R   t	   enumerate(   t   tablet	   new_tablet   elemt   rowt   i(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt
   flip_tableY   s    t
   table_datac           B   sy  e  Z d  Z d d d d d d d d d d e e e d d „ Z d „  Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 d „  Z d „  Z d „  Z d d d	 „ Z d
 „  Z d „  Z d d d „ Z d „  Z d d d „ Z d d e d „ Z d d d „ Z e d „ Z e d d „ Z e d „ Z d „  Z d „  Z d „  Z d g  d „ Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" RS(    s€  
  Container for tabular data.  Originally this was solely used as a container
  for CCP4 'loggraph' plots, but it can also be used to display tables that
  are not intended to be plotted.  A variety of output formats are supported,
  including export to JSON for eventual HTML display.  If graphs are defined,
  these objects can be passed to the loggraph frontend in wxtbx.plots.
  c         C   sÁ   t  |  t ƒ  ƒ | d  k	 rM t | ƒ t |	 ƒ k o? d k n sM t ‚ n  |
 d  k	 r™ t g  |
 D] } t | ƒ ^ qc ƒ } t | ƒ d k s™ t ‚ n  t |  _ i  |  _ d |  _	 d |  _
 d  S(   Ni   i
   t   GRAPH(   R   t   localsR   R   R   t   sett   Falset   _is_completet   _graphst   _column_widtht	   plot_type(   R   t   titlet   column_namest   column_typest   column_labelst   column_formatst   graph_namest   graph_typest   graph_labelst   graph_columnst   dataR	   t   x_is_inverse_d_mint    first_two_columns_are_resolutiont   force_exact_x_labelst   reference_markst   columnt   lengths(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyR   n   s    1%			c         C   se   |  j  j | ƒ t |  d ƒ s+ d  |  _ n  t |  d ƒ sF d  |  _ n  t |  d ƒ sa d  |  _ n  d  S(   NRA   RB   RC   (   t   __dict__t   updatet   hasattrR   RA   RB   RC   (   R   t   state(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   __setstate__Š   s    c         C   s   t  |  j d ƒ S(   Ni    (   R   R?   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   n_rows“   s    c         C   s   t  |  j ƒ S(   N(   R   R?   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   n_cols—   s    c         C   s   t  |  j ƒ S(   N(   R   R;   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   n_graphs›   s    c         C   sš   |  j  d  k r$ | j ƒ  g |  _  n |  j  j | j ƒ  ƒ |  j d  k rX | g |  _ n |  j j | ƒ |  j d  k r† | g |  _ n |  j j | ƒ d  S(   N(   R;   R   t   stripR   R<   R>   (   R   t   namet   typet   columns(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt	   add_graphŸ   s    c         C   sï  t  j d ƒ } t  j d ƒ } t  j d ƒ } t  j d ƒ } d& } t | t ƒ rc | j d ƒ } n | } g  } xw | D]o }	 t }
 |	 j ƒ  } | j d ƒ rØ | d k rØ t  j	 d d | ƒ j d ƒ } | j
 | ƒ qv | j | ƒ qv Wd	 } xÞ| D]Ö} | d
 k rn‹| j d ƒ r?| j	 d
 | j d ƒ d ƒ |  _ nW| j d ƒ rj| d } t }
 d |  _ n,| j d ƒ r•| d } t }
 d |  _ n| d& k	 rÌ| d	 k rÌ| d k rÌ| | 7} t }
 nÊ | d k rB| j	 d
 | j	 d
 | ƒ ƒ } |  j d& k r–| j ƒ  } g  | D] } t  j	 d d | ƒ ^ q|  _ q–nT | d k r–| d	 d !d k r–g  | j ƒ  D] } t | ƒ ^ qn} |  j | ƒ n  d | k rö | | j d ƒ 7} | d k r¹| d& k rÚ| d  } n$ |
 rþ| d k rþ| | d  7} n  t  j	 d d
 t  j	 d d
 | ƒ ƒ } | j d ƒ } d	 } x� | t | ƒ k  rµ| | d j d ƒ } |  j d | | d | | d d g  | D] } t | ƒ d ^ q‹ƒ | d 7} q:WqÌ| d k rÌPqÌqö qö Wxù t |  j ƒ D]è \ } } g  } xq | D]i } | d& k s#t | ƒ j ƒ  d' k r3| j d& ƒ qùt | ƒ | k rU| j t ƒ qù| j t ƒ qùWt | k ràg  } x= | D]5 } | d& k r¡| j | ƒ q| j t | ƒ ƒ qW| |  j | <qàqàW|  j d	 d( k rët |  _ n  d& S()   sK   
    Parse CCP4 loggraph format and populate internal data structures.
    s   ^\s*s   \s*$s   \$\$\.*s   \$\$ loggraph \$\$.*s   
s   $$s   \$\$s   $$
i    R   s   $TABLEt   :i   s   $GRAPHSi   R.   s   $SCATTERi	   t   SCATTERR   R   i   i   iþÿÿÿs   :\s*$s   ^\s*:t   ,RO   RP   RQ   i   t   nant   infs   -infs   1/d^2s   1/d**2s	   1/resol^2N(   RV   RW   s   -inf(   s   1/d^2s   1/d**2s	   1/resol^2(   t   ret   compileR   t
   isinstancet   strt   splitR1   RN   t
   startswitht   subt   extendR   R6   t   TrueR5   R9   t   _atoft   add_rowt   countR   RR   t   _atoiR&   R?   t   lowert   intR@   (   R   t   loggraph_linest   initial_spacest   trailing_spacest   trailing_dollarst   trailing_dollars_phasert   graph_linest   linest   processed_linest   raw_linet   is_graph_linet   linet   sublinest   sections_passedt
   clean_lineR9   t   lblt   xt   fieldst   graph_stringR+   t   col_strst   x_strRD   t   column_is_intst   newcol(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   import_loggraph­   sš    %

$
		1%$$$ c         C   sœ   |  j  d  k s$ t |  j  ƒ d k rF g  | D] } | g ^ q+ |  _  nR t |  j  ƒ t | ƒ k sg t ‚ x. t | ƒ D]  \ } } |  j  | j | ƒ qt Wd  S(   Ni    (   R?   R   R   R   R&   R   (   R   R*   Rv   R+   t   value(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRb     s
    $"!c         C   sì   |  j  d  k s$ t |  j  ƒ d k r9 t | ƒ g |  _  n5 t |  j  d ƒ t | ƒ k s^ t ‚ |  j  j | ƒ | d  k	 r« |  j d  k r˜ | g |  _ q« |  j j | ƒ n  | d  k	 rè |  j d  k rÕ | g |  _ qè |  j j | ƒ n  d  S(   Ni    (   R?   R   R   t   listR   R   R7   R9   (   R   RD   t   column_namet   column_label(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt
   add_column  s    $%  c         C   so   t  | t ƒ s t ‚ |  j d  k r( | Sg  |  j D] } t | ƒ ^ q2 } t | ƒ } | | k  rk | } n  | S(   N(   RZ   Rf   R   R9   R   R   t   max(   R   t	   precisiont   labt   label_widthst   cwidth(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   _max_column_width  s     "	c         C   s   |  j  r | d S| S(   Ng      à¿(   R@   (   R   Rv   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   get_value_as_resolution"  s    	c         C   s€  | d  k r g  S|  j d  k	 r|  j r° |  j d |  j | d ƒ } |  j d |  j | d ƒ } d | | f g } | g  t |  j d | d ƒ D] \ } } | | ^ q• S|  j rÞ t j d | d ƒ g | d } n  g  t |  j | ƒ D] \ } } | | ^ qñ Snn d }	 | d  k	 r3d d | f }	 n  d }
 | d  k	 rXd	 d | f }
 n  g  | D] } |
 t | |	 ƒ ^ q_Sd  S(
   Ni    i   s   %s - %si   s   %-gs   %s-.%dgt   %s   %ss   %s-%ds(	   R   R:   RA   R‰   t   zipR@   t   matht   sqrtt   ftoa(   R   R*   R„   t   column_widtht   d_maxt   d_mint   frowt   fRv   t   f1t   f2(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   _format_num_row'  s&     	6	%0c         C   s;   | d  k r g  Sd d | f } g  | D] } | | ^ q' S(   Ns   %s-%dsRŠ   (   R   (   R   t   labelsR�   R”   R…   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   _format_labels=  s     i   i    c         C   sn  |  j  } | d  k	 r' t | ƒ d k s- t ‚ |  j | ƒ } |  j |  j | ƒ } t | ƒ } |  j d  k	 r| | |  j 7} n  t	 j
 d ƒ } d j |  j |  j | ƒ ƒ } | | j d | ƒ 7} t | d ƒ }	 d d | f }
 x‚ t |	 ƒ D]t } g  | D] } | | ^ qù } |  j | | | ƒ } d j g  | D] } |
 | ^ q1ƒ } | | j d | ƒ 7} qì Wt | ƒ S(   Ni    s   \ *$R   R   s   %s-%dsRŠ   (   R?   R   R   R   Rˆ   R˜   R9   t   _formatting_bufferR6   RX   RY   t   joinR^   t   xrangeR–   R[   (   R   R„   t   indentR?   R�   t   column_headerst   outRi   R—   t   nrowsR”   t   jt   colR*   R’   t   cvt   frows(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   format_simpleB  s$    	$&c         C   sÿ  |  j  } | d k	 r' t | ƒ d k s- t ‚ |  j } |  j rS d g | d } n  | g } xP t |  j ƒ D]? } g  | D] } | | ^ qy }	 | j |  j	 |	 d | ƒƒ ql Wg  }
 xJ t t | ƒ ƒ D]6 } |
 j t
 g  | D] } t | | ƒ ^ qÞ ƒ ƒ qÈ W| rh|  j rFt
 |
 d ƒ } |
 d g | g t |
 ƒ d }
 qht
 |
 ƒ } | g t |
 ƒ }
 n  g  } x> t |
 | ƒ D]- \ } } d d | f } | j | | ƒ q~Wd j | ƒ } d d t | ƒ f } t | ƒ d	 } d
 | } t | ƒ } | | 7} | d | |  j d 7} | d | d d !d 7} | d | d 7} | d | d d !d 7} x‡ t |  j ƒ D]v } g  } xF t |
 | | d ƒ D]- \ } } d d | f } | j | | ƒ q•Wd j | ƒ } | d | d 7} qqW| | 7} t | ƒ S(   st  Formats the table for printout in a log file, with equal-width
    columns and cell boundaries, e.g.:
      -------------------------------
      | Title                       |
      |-----------------------------|
      | col1    | col1    | col3    |
      |-----------------------------|
      | 0.1     | 5       | *       |
      -------------------------------
    i    s
   Res. rangei   R„   i   s   %s-%dsRŠ   s    | i   t   -s   | s    |t   |iÿÿÿÿN(   R?   R   R   R   R9   RA   R›   RK   R   R–   Rƒ   R‹   Rš   R™   R6   R[   (   R   R„   Rœ   t   equal_widthsR?   R9   t   formatted_rowsR    R¡   R*   t   column_widthst   rt   max_wR�   t   cwt   clR”   R•   t   table_widtht   sep_lineRž   R’   R¢   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   formatV  sR    	$			 4	%

$
c      
   C   sý  |  j  } |  j } |  j } |  j } |  j } | d k	 rK t | ƒ d k sQ t ‚ | d k sr t | t	 ƒ sr t ‚ | d k sœ t | ƒ t | ƒ k sœ t ‚ d |  j
 } | d 7} | d k rÛ g  | D] }	 d ^ qÆ } n  xh t | ƒ D]Z \ }
 } | d | 7} | d | |
 d j g  | |
 D] } d | d	 ^ q ƒ f 7} qè W| d
 7} t j d ƒ } g  | D] } | j d | ƒ ^ qf} | d k rÊt |  j | ƒ t g  | D] } t | ƒ ^ q©ƒ ƒ } n  d d | f } d d | f } g  | D] } | j d | ƒ ^ qñ} | d d j g  | D] } | | ^ q"ƒ 7} | d
 7} t j d ƒ } x– t t | d ƒ ƒ D]~ } g  | D] } | | ^ qz} |  j | | | ƒ } g  | D] } | | ^ q¬} | | j d d j | ƒ ƒ 7} | d 7} qmW| d
 7} | S(   sE   
    Create CCP4 loggraph format text for embedding in logfiles.
    i    s   $TABLE: %s
s   $GRAPHS
R   s   :%s
s   :%s:%s:
RU   s   %di   s   $$
s   [\ ]{1,}R   s   %s.%dgRŠ   s   %s-%dss   %s $$
s     s   \ *$R   s   
N(   R?   R>   R;   R<   R9   R   R   R   RZ   Rf   R6   R&   Rš   RX   RY   R^   Rƒ   Rˆ   R›   R–   (   R   R„   R�   R?   R>   R;   R<   R9   Rž   t   graphR+   t
   graph_nameRv   t	   re_spacesR…   R—   R”   R•   Ri   R    R¡   R*   R’   R¢   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   format_loggraph�  sH    					$!*
7
%+%.

c         C   s    d d  l  } |  j } | d  k r@ g  |  j D] } d ^ q+ } n  i |  j d 6|  j d 6|  j d 6| d 6|  j d 6|  j d 6|  j d	 6} | rœ | j	 | ƒ S| S(
   NiÿÿÿÿR   R6   R>   R;   R<   R9   R@   R?   (
   t   jsonR<   R   R;   R6   R>   R9   R@   R?   t   dumps(   R   t   convertRµ   R<   R±   t   export_dict(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   export_json¹  s    	




c         C   s‰   |  j  } |  j r& d g | d } n  | g } xS t |  j ƒ D]B } g  |  j D] } | | ^ qO } | j |  j | d | ƒƒ q? W| S(   Ns
   Res. rangei   R„   (   R9   RA   R›   RK   R?   R   R–   (   R   R·   R„   R9   R¨   R    R¡   R*   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   export_rowsË  s    			  c         C   s@   d d  l  } i |  j d 6|  j ƒ  d 6} | r< | j | ƒ S| S(   NiÿÿÿÿR6   t   rows(   Rµ   R6   Rº   R¶   (   R   R·   Rµ   R¸   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   export_json_table×  s    
c         C   s   t  |  j ƒ S(   N(   R,   R?   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   as_rowsá  s    c         C   s&   t  |  j ƒ d k s t ‚ |  j d S(   Ni   i    (   R   R;   R   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt	   only_plotä  s    c         C   s   |  j  d  k	 r |  j  d Sd  S(   Ni    (   RC   R   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   get_reference_marksè  s    c         C   s$  |  j  } |  j } |  j } |  j } |  j } | d  k	 r| | k r| | k rU d  S| j | ƒ } |  j | | ƒ }	 t | ƒ t | ƒ k r³ g  | | D] }
 | |
 ^ qš } n g  } d  } d  } |  j	 d  k	 rê |  j	 | \ } } n  t
 | |	 d | | | ƒ | | <n  | | St | ƒ d k r | |  j k rd  } t | d t ƒ r}|  j | ƒ } g  | D] }
 | |
 ^ qd} no t | d t ƒ rìg  } x$ | D] } | j | j | ƒ ƒ q�W|  j | ƒ }	 g  | D] }
 | |
 ^ qÓ} n  |	 d  k rüd  St
 d  |	 d | ƒ | | <n  | | Sd  S(   Nt   ploti   i    (   R;   R9   R>   R?   R3   R   t   indext   _extract_data_columnR   R=   t
   graph_dataRZ   Rf   R[   R   (   R   R²   t   column_listR;   R9   R>   R?   R3   t   nt   gdataR+   R—   t   x_axist   y_axist   n_listR¡   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt	   get_graphí  sJ    					$  c         C   sQ   | |  j  k r4 t d | d j |  j  ƒ f ƒ ‚ n  |  j  j | ƒ } |  j | S(   Ns;   Couldn't find column %s in this table.  (Valid columns: %s)RU   (   R9   t   RuntimeErrorRš   RÁ   R?   (   R   R�   R+   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   get_column_by_label  s    c         C   s^   t  | ƒ t  |  j ƒ k s! t ‚ |  j } g  | D]# } g  | | D] } | ^ qB ^ q1 } | S(   N(   R   R?   R   (   R   RÄ   R?   R+   Rv   t   new_data(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRÂ     s    !	0c         C   s
   |  j  ƒ  S(   N(   R¤   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   __str__#  s    c         C   s   |  j  d S(   Ni    (   R?   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   get_x_values&  s    c         C   sQ   |  j  s t ‚ |  j d } g  } x( | D]  } | j t j d | ƒ ƒ q) W| S(   Ni    g      ð?(   R@   R   R?   R   RŒ   R�   (   R   t   oldxt   newxRv   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   get_x_as_resolution)  s    N(#   R   R   t   __doc__R   R1   R   RJ   t   propertyRK   RL   RM   RR   R}   Rb   R‚   Rˆ   R‰   R–   R˜   R¤   R`   R°   R´   R¹   Rº   R¼   R½   R¾   R¿   RÊ   RÌ   RÂ   RÎ   RÏ   RÒ   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyR-   f   sT   				W					:)
			(				RÃ   c           B   s)   e  Z d  d d d d „ Z d d „ Z RS(   RÀ   c         C   sÂ   | |  _  | |  _ | |  _ | d  k s9 t | ƒ d k rp d |  _ g  t d t | ƒ ƒ D] } d ^ qX |  _ n< | d |  _ g  t d t | ƒ ƒ D] } | | ^ q“ |  _ | |  _ | |  _	 d  S(   Ni    t   Xi   t   Y(
   RO   R?   RP   R   R   R   R›   t   y_labelst   x_axis_labelt   y_axis_label(   R   RO   R?   RP   t   data_labelsRÇ   RÈ   R+   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyR   2  s    				./	c         C   sÿ   g  } |  j  } xé t d t | ƒ ƒ D]Ò } g  } g  } xª t d t | | ƒ ƒ D]� } | d | d  k	 rQ | | | d  k	 r¬ | j | d | ƒ | j | | | ƒ qà | d  k	 rà | j | d | ƒ | j | ƒ qà qQ qQ W| j | | f ƒ q% W| S(   Ni   i    (   R?   R›   R   R   R   (   R   t   fill_in_missing_yt   plotsR?   R+   t   plot_xt   plot_yR    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt	   get_plots@  s    	 N(   R   R   R   R   Rß   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRÃ   1  s   	t   histogram_datac           B   s   e  Z RS(    (   R   R   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRà   Q  s   c         C   s1   y t  j |  ƒ } Wn t k
 r, d  } n X| S(   N(   R   t   atoft	   ExceptionR   (   t   fstringt   val(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRa   T  s
    
c         C   s1   y t  j |  ƒ } Wn t k
 r, d  } n X| S(   N(   R   t   atoiRâ   R   (   t   istringRä   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRd   [  s
    
s   %.6gc         C   s   |  d  k r d S| |  Sd  S(   Nt   *(   R   (   Rä   t   format_string(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRŽ   c  s    R™   c           B   s8   e  Z d  d „ Z d „  Z d „  Z d „  Z d „  Z RS(   i    c         C   s   d | |  _  g  |  _ d  S(   NR   (   t   _initial_spacet   _buffer(   R   Rœ   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyR   j  s    c         C   s   |  j  j |  j | ƒ d  S(   N(   Rê   R   Ré   (   R   t   strdata(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   writen  s    c         C   s   |  j  | ƒ d  S(   N(   Rì   (   R   Rë   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyR   q  s    c         C   s   |  j  | ƒ |  S(   N(   Rì   (   R   Rë   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   __add__t  s    c         C   s   d j  |  j ƒ d } | S(   Ns   
(   Rš   Rê   (   R   Rž   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRÎ   x  s    (   R   R   R   Rì   R   Rí   RÎ   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyR™   i  s
   			c   	      C   sV  |  d  k	 s | d  k	 s t ‚ | s9 t |  ƒ j ƒ  } n  d  } g  } d } xÇ | D]¿ } | j ƒ  } t j d | ƒ rˆ | g } d } qR | d d k ré | d  k	 ré | j | ƒ | | j d ƒ 7} | d k r| j | ƒ d  } qqR | d k  rR | d  k	 rR | j | ƒ qR qR Wg  } x4 | D], } t	 d  ƒ } | j
 | ƒ | j | ƒ q"W| S(   Ni    s   \$TABLE\s*:iþÿÿÿs   $$i   (   R   R   t   opent	   readlinesRN   RX   t   matchR   Rc   R-   R}   (	   t	   file_namet	   log_linest   current_linest
   tables_rawt   sections_readRq   t   tablest   loggrapht   t(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   import_ccp4i_logfile|  s2    		t   simple_matplotlib_plotc           B   s/   e  Z d  Z d d d d e d „ Z d „  Z RS(   sÀ   
  Class for writing a Matplotlib plot to a static image file without a GUI.
  This should be subclassed and combined with whatever mixin is used to
  actually responsible for the plotting.
  i   i   t   whitec   	      C   s¹   t  |  t ƒ  ƒ y, d d  l } d d  l } d d l m } Wn$ t k
 rb } | GHt d ƒ ‚ n X| j j	 | d d d d | ƒ|  _ | r£ |  j j
 j d ƒ n  | |  j ƒ |  _ d  S(	   Niÿÿÿÿ(   t   FigureCanvasAggs/   Plotting requires that matplotlib be installed.iH   t	   linewidthi    t	   facecolorg        (   R   R/   t
   matplotlibt   matplotlib.figuret   matplotlib.backends.backend_aggRü   t   ImportErrorR   t   figuret   Figuret   figurePatcht	   set_alphat   canvas(	   R   t   figure_sizet	   font_sizet   title_font_sizeRþ   t   transparentRÿ   Rü   t   e(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyR   �  s    c         C   sÅ   | d  k	 r | d k s t ‚ t j j | ƒ \ } } | d k ra |  j j | d d d d ƒn` | d k rŒ |  j j | d d d d ƒn5 | d	 k r± |  j j | d d
 ƒn t d t ƒ ‚ d  S(   NR   s   .pdft   orientationt	   landscapeR°   t   pdfs   .pst   pss   .pngt   pngs   Extension %s not supported(	   R   R   t   ost   patht   splitextR  t   savefigRË   t   s(   R   Rñ   t   baset   ext(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt
   save_image³  s    (   i   i   (   R   R   RÓ   R1   R   R  (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyRú   —  s   (   RÓ   t
   __future__R    t   libtbxR   t   libtbx.utilsR   R   t   os.pathR  RŒ   RX   t   objectR   R%   R,   R-   RÃ   Rà   Ra   Rd   RŽ   R™   R   Rù   Rú   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/data_plots.pyt   <module>   s(   #	'	ÿ Ì 		