ó
ü™xTc           @   s{   d  d l  m Z d  d l m Z d e f d „  ƒ  YZ e d k rw d  d l Z x& e j d D] Z e j	 e ƒ GHq\ Wn  d S(   iÿÿÿÿ(   t   division(   t   Formatt   FormatBrukerc           B   sS   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   sÚ  cctbx has no authoritative sources describing the Bruker format.
  Positive identification:  when listing the header out in 16-byte chunks,
  there are numerous chunks of the form
  KEYNAME:xxxxxxxx
  KEYNAME:xxxxxxxx
  ...in other words a 7-upper case character (or space) keyname followed by
  a colon, starting at the beginning of every fifth chunk.
  Here we will take a series of 12 of these in the first 1024 characters
  as a positive fingerprint of Bruker format.
  c         C   s­   y t  j |  d ƒ j d ƒ } Wn t k
 r5 } t SXg  } x^ t d d d ƒ D]J } | | | d !} | d d !j ƒ  rO | d d k rO | j | ƒ qO qO Wt | ƒ d k S(	   Nt   rbi   i    iP   i   i   t   :i   (	   R   t	   open_filet   readt   IOErrort   Falset   xranget   isuppert   appendt   len(   t
   image_filet   tagt   et   matchest   xt   word(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyt
   understand   s    #c         C   s)   |  j  | ƒ s t ‚ t j |  | ƒ d S(   s3   Initialise the image structure from the given file.N(   R   t   AssertionErrorR   t   __init__(   t   selfR   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyR   !   s    c         C   s&   d d l  m } | |  j ƒ |  _ d S(   sÂ   Open the image file, read the image header, copy the key / value
    pairs into an internal dictionary self._header_dictionary along with
    the length of the header in bytes self._header_size.iÿÿÿÿ(   t   BrukerImageN(   t   iotbx.detectors.brukerR   t   _image_filet   detectorbase(   R   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyt   _start(   s    c         C   s   |  j  j ƒ  S(   N(   t   _goniometer_factoryt   single_axis(   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyt   _goniometer0   s    c         C   s»   |  j  j d } |  j j d d d |  j  j d d |  j  j d |  j  j d f d	 d
 d d d |  j  j d |  j  j d f d |  j  j d |  j  j d f d d |  j  j d f d g  ƒ 	S(   s$   Return a model for a simple detectort   TWOTHETAt   sensort   CCDt   distancet   DISTANCEt   beam_centret   BEAM_CENTER_Xt   BEAM_CENTER_Yt   fast_directions   +xt   slow_directions   -yt
   pixel_sizet
   PIXEL_SIZEt
   image_sizet   SIZE1t   SIZE2t   trusted_rangei    t   CCD_IMAGE_SATURATIONt   mask(   R   t
   parameterst   _detector_factoryt   simple(   R   t   twotheta(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyt	   _detector4   s    c         C   s   |  j  j |  j j d ƒ S(   s#   Return a simple model for the beam.t
   WAVELENGTH(   t   _beam_factoryR3   R   R1   (   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyt   _beamI   s    c         C   sH   |  j  j d |  j d d d d d |  j j d d |  j j d	 d
 d ƒ S(   s+   Return the scan information for this image.t   filenamet   formatt	   BrukerCCDt   exposure_timesi   t	   osc_startt	   OSC_STARTt	   osc_widtht	   OSC_RANGEt   epochN(   t   _scan_factoryt   singleR   R   R1   t   None(   R   (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyt   _scanN   s    	(   t   __name__t
   __module__t   __doc__t   staticmethodR   R   R   R   R5   R8   RE   (    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyR      s   
					t   __main__Ni   (
   t
   __future__R    t   dxtbx.format.FormatR   R   RF   t   syst   argvt   argR   (    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatBruker.pyt   <module>   s   U