ó
ÿ™xTc           @   s‹   d  d l  m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ e d k r‡ d  d l Z x& e j	 d D] Z
 e j e
 ƒ GHql Wn  d S(	   iÿÿÿÿ(   t   division(   t   matrix(   t   FormatSMVRigakut   FormatSMVRigakuA200c           B   sS   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   su   A class for reading SMV format Rigaku A200 images, and correctly
  constructing a model for the experiment from this.c   	      C   s<  t  j |  ƒ \ } } d d d d d d d d d	 d
 d d d d d g } x | D] } | | k rO t SqO W| d j ƒ  d j ƒ  } d d d d d d d d d g	 } x( | D]  } d | | f | k r« t Sq« Wd d g } xZ | D]R } d | | f } | | k râ d | | j ƒ  k s0d | | j ƒ  k râ t Sqâ Wt S(   s±   Check to see if this looks like a Rigaku A200 SMV format image,
    i.e. we can make sense of it. Essentially that will be if it contains
    all of the keys we are looking for.t   DETECTOR_NUMBERt   DETECTOR_NAMESt   CRYSTAL_GONIO_NUM_VALUESt   CRYSTAL_GONIO_NAMESt   CRYSTAL_GONIO_UNITSt   CRYSTAL_GONIO_VALUESt   ROTATIONt   ROTATION_AXIS_NAMEt   ROTATION_VECTORt   SOURCE_VECTORSt   SOURCE_WAVELENGTHt   SOURCE_POLARZt   DIMt   SIZE1t   SIZE2i    t   DETECTOR_DIMENSIONSt   DETECTOR_SIZEt   DETECTOR_VECTORSt   GONIO_NAMESt   GONIO_UNITSt   GONIO_VALUESt   GONIO_VECTORSt   SPATIAL_BEAM_POSITIONt   SPATIAL_DISTORTION_VECTORSs   %s%st   DETECTOR_IDENTIFICATIONt   DETECTOR_DESCRIPTIONt   raxist   a200(   R   t   get_smv_headert   Falset   splitt   stript   lowert   True(	   t
   image_filet   sizet   headert   wanted_header_itemst   header_itemt   detector_prefixt   more_wanted_header_itemst   descriptive_itemst   test(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyt
   understand   s.    		8c         C   s)   |  j  | ƒ s t ‚ t j |  | ƒ d S(   s¶   Initialise the image structure from the given file, including a
    proper model of the experiment. Easy from Rigaku A200 images as
    they contain everything pretty much we need...N(   R/   t   AssertionErrorR   t   __init__(   t   selfR&   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyR1   A   s    c         C   s@   t  j |  ƒ d d l m } | |  j ƒ |  _ |  j j ƒ  d  S(   Niÿÿÿÿ(   t
   DTREKImage(   R   t   _startt   iotbx.detectors.dtrekR3   t   _image_filet   detectorbaset
   readHeader(   R2   R3   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyR4   L   s    c         C   s2   t  t t |  j d j ƒ  ƒ ƒ } |  j j | ƒ S(   sE  Initialize the structure for the goniometer - this will need to
    correctly compose the axes given in the image header. In this case
    this is made rather straightforward as the image header has the
    calculated rotation axis stored in it. We could work from the
    rest of the header and construct a goniometer model.R   (   t   tuplet   mapt   floatt   _header_dictionaryR"   t   _goniometer_factoryt
   known_axis(   R2   t   axis(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyt   _goniometerS   s    c         C   sN  |  j  d j ƒ  d j ƒ  } t t |  j  d | j ƒ  ƒ } t j t | d  ƒ ƒ } t j t | d ƒ ƒ } t t |  j  d | j ƒ  ƒ } | | d | | d } | | d | | d } t t |  j  d | j ƒ  d  ƒ } t t |  j  d | j ƒ  d ƒ }	 t t |  j  d	 | j ƒ  ƒ }
 | d |	 d | | d |	 d | } t t |  j  d
 | j ƒ  ƒ } t t |  j  d | j ƒ  ƒ } |  j  d | j ƒ  } t |  j  d | ƒ } g  } g  } xÈ t	 | ƒ D]º \ } } t j | d | d | d !ƒ } | d k rP| j
 | j | | d t ƒƒ | j
 t j d ƒ ƒ qÝ| d k rŠ| j
 t j d ƒ ƒ | j
 | | | ƒ qÝt d | ‚ qÝW| j ƒ  | j ƒ  xL t | ƒ D]> } | | | } | | | } | | | } | | | } q¼Wt t |  j  d ƒ ƒ } d } |  j j d | j | j | j |	 |
 | | f ƒ S(   s‚   Return a model for the detector, allowing for two-theta offsets
    and the detector position. This will be rather more complex...R   i    s   %sDETECTOR_VECTORSi   s   %sSPATIAL_DISTORTION_VECTORSi   i   s   %sSPATIAL_DISTORTION_INFOs   %sDETECTOR_DIMENSIONSs   %sGONIO_VECTORSs   %sGONIO_VALUESs   %sGONIO_UNITSs   %sGONIO_NUM_VALUESt   degg        t   mmg      ð?s   unknown axis unit %st   SATURATED_VALUEt   CCD(   g        g        g        (	   g      ð?g        g        g        g      ð?g        g        g        g      ð?(   R<   R"   R#   R:   R;   R   t   colR9   t   intt	   enumeratet   appendt$   axis_and_angle_as_r3_rotation_matrixR%   t   sqrt   RuntimeErrort   reverset   ranget   _detector_factoryt   complext   elems(   R2   t   detector_namet   detector_axest
   detector_xt
   detector_yt   detector_remapt   detector_fastt   detector_slowt   beam_pixelst
   pixel_sizet
   image_sizet   detector_origint
   gonio_axest   gonio_valuest   gonio_unitst   gonio_num_axest	   rotationst   translationst   jt   unitR?   t   overloadt	   underload(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyt	   _detector_   sl    	" 


	c         C   s|   t  t |  j d j ƒ  d  ƒ } t  t |  j d j ƒ  ƒ } | d } | d } t |  j d ƒ } |  j j | | | | ƒ S(   s#   Return a simple model for the beam.R   i   R   i    i   t   SCAN_WAVELENGTH(   R:   R;   R<   R"   t   _beam_factoryRO   (   R2   t   beam_directiont   polarizationt
   p_fractiont   p_planet
   wavelength(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyt   _beamª   s    

	c         C   st   t  t |  j d j ƒ  ƒ } |  j j d ƒ } d } | d } | d } | d } |  j j |  j | | | | | ƒ S(   s+   Return the scan information for this image.R
   t   SMVi    i   i   (   R:   R;   R<   R"   t   _scan_factoryt   formatt   singleR6   (   R2   t   rotationRq   t   epocht   exposure_timet	   osc_startt	   osc_range(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyt   _scan»   s    


	(   t   __name__t
   __module__t   __doc__t   staticmethodR/   R1   R4   R@   Rf   Rn   Rx   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyR      s   ,				K	t   __main__Ni   (   t
   __future__R    t   scitbxR   t   dxtbx.format.FormatSMVRigakuR   R   Ry   t   syst   argvt   argR/   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatSMVRigakuA200.pyt   <module>   s   º