ó
žxTc           @   sj   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d e f d     YZ d S(   i’’’’(   t   divisionN(   t   Formatt   FormatRAXISc           B   sS   e  Z d  Z e d    Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   s9   A class to support the RAXIS detector format from Rigaku.c         C   s&   t  j |   j d  d k r" t St S(   sc   See if this looks like an RAXIS format image - clue is first
    5 letters of file should be RAXIS.i   t   RAXIS(   R   t	   open_filet   readt   Truet   False(   t
   image_file(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyt
   understandU   s    c         C   s)   |  j  |  s t  t j |  |  d  S(   N(   R	   t   AssertionErrorR   t   __init__(   t   selfR   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyR   _   s    c         C   s   t  j |  j  j d  |  _ |  j d d !j   d k rO d |  _ d |  _ n d |  _ d |  _ d	 d
 l m	 } | |  j  |  _
 |  j
 j   d  S(   Ni   i,  i6  t   SGIs   >fs   >is   <fs   <ii’’’’(   t
   RAXISImage(   R   R   t   _image_fileR   t   _header_bytest   stript   _ft   _it   iotbx.detectors.raxisR   t   detectorbaset
   readHeader(   R   R   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyt   _startf   s    			c         C   s)  |  j  } |  j } |  j } t j | | d d ! d } t j | | d d ! d } xÄt |  D]¶} t j | | d | d d | d ! d } t j | | d | d d | d ! d } t j | | d | d d	 | d ! d }	 t j | | d
 | d d | d ! d }
 t j | | d | d d | d ! d } t j | | d | d d | d ! d } | | k rŚt j | d  d k  s”t  t j |  d k  s¼t  t j |	  d k  st  qb t j |
 d  d k  słt  t j | d  d k  sb t  qb W|  j	 j
   S(   s   Return a model for the goniometer from the values stored in the
    header. Assumes same reference frame as is used for the Saturn
    instrument.iX  i\  i    iŌ  iŲ  i   i`  id  ih  i  i   i  i¬  i°  iĄ  iÄ  i   gü©ńŅMbP?g     f@(   R   R   R   t   structt   unpackt   ranget   matht   fabsR
   t   _goniometer_factoryt   single_axis(   R   t   it   ft   headert   n_axest	   scan_axist   jt   axis_xt   axis_yt   axis_zt
   axis_startt   axis_endt   axis_offset(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyt   _goniometert   s&    			------#c         C   sŽ  |  j  } |  j } |  j } t j | | d d ! d } t j | | d d ! d } t j | | d d ! d } | d k s t  | d k s t  | d k sØ t  t j | | d d ! d } t j | | d d ! d } t j | | d d	 ! d }	 t j | | d	 d
 ! d }
 t j | | d d ! d } t j | | d d ! d } t j | | d d ! d } t j | | d d ! d } | |	 | |
 f } |  j j d | | d d d | |	 |
 f | | f d g   S(   sŅ   Return a model for the detector as defined in the image header,
    with the additional knowledge about how things are arranged i.e. that
    the principle rotation axis vector points from the sample downwards.i@  iD  i    iH  iL  i   i  i  i  i  iX  i\  i,  i0  i  i   i$  t   IMAGE_PLATEs   +ys   -xs   +xi@B (   i    i@B (   R   R   R   R   R   R
   t   _detector_factoryt	   two_theta(   R   R   R    R!   t   det_ht   det_vt   det_ft   nxt   nyt   dxt   dyt   distanceR.   t   beam_xt   beam_yt   beam(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyt	   _detector   s*    				c         C   s<   t  j |  j |  j d d ! d } |  j j d d d |  S(	   sg   Return a simple model for the beam. This assumes a laboratory source
    which has an unpolarized beam.i$  i(  i    g        g      š?g      ą?(   g        g        g      š?(   g        g      š?g        (   R   R   R   R   t   _beam_factoryt   complex(   R   t
   wavelength(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyt   _beamÅ   s    #c         C   sH  |  j  } |  j } |  j } |  j j d  } t j | | d d ! d } t t | d d !j	   j
 d   \ } } } t j t j | | | d d d  j    }	 t j | | d d	 ! d }
 t j | | d
 |
 d d |
 d ! d } t j | | d |
 d d |
 d ! d } | | } |  j j |  j | | | | |	  S(   s+   Return the scan information for this image.R   i  i  i    i   i  t   -iŌ  iŲ  i  i   i  i¬  i°  (   R   R   R   t   _scan_factoryt   formatR   R   t   mapt   intR   t   splitt   timet   mktimet   datetimet	   timetuplet   singleR   (   R   R   R    R!   RA   t   exposure_timet   yt   mt   dt   epocht   st	   osc_startt   osc_endt	   osc_range(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyt   _scanĪ   s    			.---
	(   t   __name__t
   __module__t   __doc__t   staticmethodR	   R   R   R+   R:   R>   RS   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyR   R   s   
			(	)		(	   t
   __future__R    RE   RG   R   R   t   dxtbx.format.FormatR   R   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatRAXIS.pyt   <module>I   s   