ó
}™xTc           @   sÝ   d  Z  d d l m Z d d l j j 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 e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ e d d d „ Z d g d d d d d „ Z e e j _ d S(   sÎ  Example format for Xplor Maps:

       2 !NTITLE
 REMARKS FILENAME=""
 REMARKS scitbx.flex.double to Xplor map format
      24       0      24     120       0     120      54       0      54
 3.20420E+01 1.75362E+02 7.96630E+01 9.00000E+01 9.00000E+01 9.00000E+01
ZYX
       0
-2.84546E-01-1.67775E-01-5.66095E-01-1.18305E+00-1.49559E+00-1.31942E+00
-1.01611E+00-1.00873E+00-1.18992E+00-1.02460E+00-2.72099E-01 5.94242E-01
<deleted>
   -9999
  0.0000E+00  1.0000E+00
That is:
...a blank line
...an integer giving the number of title lines, with mandatory !NTITLE
...title lines in %-264s format
...X, Y, and Z sections giving:
       sections per unit cell, in the given direction
       ordinal of first section in file
       ordinal of last section in file
...unit cell dimensions
...slow, medium, fast section order, always ZYX
...for each slow section, the section number
...sectional data in special fortran format shown
...-9999
...map average and standard deviation
iÿÿÿÿ(   t   divisionN(   t   miller(   t   maptbx(   t   uctbx(   t   flext   griddingc           B   s/   e  Z d  „  Z d „  Z d „  Z e d „ Z RS(   c         C   s”   t  | ƒ |  _ t  | ƒ |  _ t  | ƒ |  _ x` t d | | | ƒ D]I \ } } } } | d k  sm | | k rC t d | | | | f ƒ ‚ qC qC Wd  S(   Nt   XYZi   sK   Illegal xplor map gridding for dimension %s: gridding=%d, first=%d, last=%d(   t   tuplet   nt   firstt   lastt   zipt   RuntimeError(   t   selfR   R	   R
   t   xt   nit   fit   li(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyt   __init__)   s    ( c         C   s>   d } x1 t  |  j |  j |  j ƒ D] } | d | 7} q" W| S(   Nt    s   %8di   s	   %8d%8d%8d(   R   R   R	   R
   (   R   t   resultt   triple(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyt
   format_9i82   s    "c         C   s   t  j |  j |  j t ƒ S(   N(   R   t   gridR	   R
   t   False(   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyt   as_flex_grid8   s    c         C   s�   | j  ƒ  d k r t S| sc |  j ƒ  } | j ƒ  | j ƒ  k rD t S| j ƒ  | j ƒ  k rŒ t Sn) | j ƒ  ss t S| j ƒ  |  j k rŒ t St S(   Ni   (	   t   ndR   R   t   originR
   t
   is_0_basedt   focusR   t   True(   R   t	   flex_gridt
   is_p1_cellt   self_as_flex_grid(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyt   is_compatible_flex_grid;   s         (   t   __name__t
   __module__R   R   R   R   R"   (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyR   '   s   				t   readerc           B   s#   e  Z e d  „ Z d d d „ Z RS(   c         C   sT  t  | d ƒ } | j ƒ  g  |  _ t | j ƒ  j ƒ  j d ƒ d ƒ } g  |  _ x6 t | ƒ D]( } | j ƒ  j ƒ  } |  j j | ƒ q] W| j ƒ  } g  t d d d ƒ D] } t | | | d !ƒ ^ q¨ } t	 d g  t d d d ƒ D] } | | ^ qä d	 g  t d
 d d ƒ D] } | | ^ qd g  t d d d ƒ D] } | | ^ q6ƒ |  _	 | j ƒ  } g  t d d d ƒ D] } t
 | | | d !ƒ ^ qq}	 t j |	 ƒ |  _ | j ƒ  j ƒ  }
 |
 d k sÊt ‚ | j ƒ  | rød  |  _ d  |  _ d  |  _ nX t j d | d t |  j ƒ d d |  j	 j ƒ  ƒ } | j |  _ | j |  _ | j |  _ d  S(   Nt   rt   !i    iH   i   R   i	   i   R	   i   R
   i   i   t   ZYXt	   file_namet   n_header_linesi   R   (   t   opent   readlinet   title_linest   intt   stript   splitt   xranget   rstript   appendR   t   floatR   t	   unit_cellt   AssertionErrort   closet   Nonet   datat   averaget   standard_deviationt   extt
   map_readert   lenR   (   R   R)   t   header_onlyt   ft   ntitleR   t   linet   it   valuest   paramst   ordert
   ext_reader(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyR   H   s>    
	%	6))/6
			R   c         C   sP  | d  k r t j } n  | | d It |  j ƒ IJx) |  j D] } | | d | j ƒ  IJq? W|  j } | | d IJ| | d I| j IJ| | d I| j IJ| | d I| j	 IJ| | d I|  j
 j ƒ  IJt j |  j
 ƒ } | | d | j ƒ  IJ| | d	 | j ƒ  IJ| | d
 | j ƒ  IJ| | d | j ƒ  IJd  S(   Ns   Title lines:s     s	   Gridding:s     n:    s     first:s     last: s   Total number of data points:s     min:   %.6gs     max:   %.6gs     mean:  %.6gs     sigma: %.6g(   R8   t   syst   stdoutR>   R-   R2   R   R   R	   R
   R9   t   sizeR   t
   statisticst   mint   maxt   meant   sigma(   R   t   outt   prefixRB   t   gt   stats(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyt   show_summaryj   s      	N(   R#   R$   R   R   R8   RT   (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyR%   F   s   "c   
      C   s	  | j  d | j ƒ  d | ƒ s$ t ‚ t |  d ƒ } | j d ƒ | j d t | ƒ ƒ x | D] }	 | j d |	 ƒ q^ W| j d | j ƒ  ƒ | j ƒ  | sË t j	 d |  d	 | d
 | d | d | ƒ n: t j	 d |  d	 | d | j
 d | j d
 | d | d | ƒ d  S(   NR   R    t   wbs   
s   %8d !NTITLE
s   %-264s
s   %s
R)   R5   R9   R:   R;   t   gridding_firstt   gridding_last(   R"   t   accessorR6   R+   t   writeR>   R   R7   R<   t
   map_writerR	   R
   (
   R)   R-   R5   R   R9   R    R:   R;   R@   RB   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyt   writer{   s2    	
	
			s   cctbx.miller.fft_mapc   
      C   sþ   | d  k r d } n  | d  k r0 |  j ƒ  } n  t d |  j ƒ  d | d | ƒ } |  j ƒ  } | d  k su | d  k r½ t j | ƒ }	 | d  k rŸ |	 j ƒ  } n  | d  k r½ |	 j ƒ  } q½ n  t d | d | d |  j	 ƒ  d | d	 | d
 t
 d | d | ƒ d  S(   Ni    R   R	   R
   R)   R-   R5   R   R9   R    R:   R;   (   i    i    i    (   R8   t   n_realR   t   real_mapR   RK   RN   RO   R[   R5   R   (
   R   R)   R-   RV   RW   R:   R;   t	   gridding_R9   RK   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyt!   cctbx_miller_fft_map_as_xplor_mapš   s0     	 	  (   t   __doc__t
   __future__R    t   iotbx.xplor.extt   xplorR<   t   cctbxR   R   R   t   cctbx.array_familyR   RH   t   objectR   R%   R   R[   R8   R_   t   fft_mapt   as_xplor_map(    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xplor/map.pyt   <module>   s$   6