ó
ü™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   FormatXPARMc           B   se   e  Z d  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(
   s.   An image reading class for XDS XPARM.XDS filesc         C   s   d d l  m } | |  ƒ S(   sV   Check to see if this looks like an CBF format image, i.e. we can
    make sense of it.iÿÿÿÿ(   t   is_recognized_file(   t$   rstbx.cftbx.coordinate_frame_helpersR   (   t
   image_fileR   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyt
   understand   s    c         C   s)   t  j |  | ƒ |  j | ƒ s% t ‚ d S(   s3   Initialise the image structure from the given file.N(   R   t   __init__R   t   AssertionError(   t   selfR   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyR      s    c         C   s   |  j  |  j ƒ d S(   sK   Open the image file as a cbf file handle, and keep this somewhere
    safe.N(   t   _convert_to_cbf_conventiont   _image_file(   R	   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyt   _start    s    c         C   s&  d d l  m } d d l m } | | ƒ } | j d ƒ |  _ | j d ƒ |  _ | j d ƒ |  _ | j d ƒ |  _ | j d ƒ |  _	 | j d	 ƒ |  _
 | j d
 ƒ |  _ | j d ƒ |  _ | j d ƒ |  _ | j d ƒ |  _ d |  _ | j d ƒ |  _ | j d ƒ } t | j | ƒ ƒ |  _ d S(   s•   Get the parameters from the XPARM file and convert them to CBF
    conventions.

    Params:
        xparm_handle The handle to the xparm file.

    iÿÿÿÿ(   t   coordinate_frame_converter(   t   matrixt   detector_origint   rotation_axist   detector_fastt   detector_slowt
   wavelengtht   detector_size_fast_slowt   detector_pixel_size_fast_slowt   starting_anglet   oscillation_ranget   starting_frameg        t   sigma_divergencet   sample_to_sourceN(   t&   rstbx.cftbx.coordinate_frame_converterR   t   scitbxR   t   gett   _detector_origint   _rotation_axist
   _fast_axist
   _slow_axist   _wavelengtht   _image_sizet   _pixel_sizet   _starting_anglet   _oscillation_ranget   _starting_framet   _divergencet   _sigma_divergencet   tuplet   colt   _beam_vector(   R	   t   xparm_filenameR   R   t   cfct   sample_vector(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyR
   '   s"    	c         C   s   |  j  j |  j ƒ S(   s%   Return a working goniometer instance.(   t   _goniometer_factoryt
   known_axisR   (   R	   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyt   _goniometerD   s    c      	   C   s=   |  j  j |  j  j d ƒ |  j |  j |  j |  j |  j d ƒ S(   s#   Return a working detector instance.t   unknowni    (   i    i    (   t   _detector_factoryt   complext   sensorR   R    R!   R$   R#   (   R	   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyt	   _detectorH   s    	c      	   C   s1   |  j  j d |  j d |  j d |  j d |  j ƒ S(   s   Return a working beam instance.R   R   t
   divergenceR   (   t   _beam_factoryt	   make_beamR,   R"   R(   R)   (   R	   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyt   _beamO   s
    			c         C   s†   d d l  } d d l m } |  j |  j f } |  j |  j f } d } | j j |  j ƒ } | j	 } |  j
 j | d | d g d t ƒS(   s   Return a working scan instance.iÿÿÿÿN(   t   scan_helper_image_formatst   #g        i    t   deg(   t   ost   dxtbx.model.scan_helpersR<   R'   R%   R&   t   patht   dirnameR   t
   FORMAT_CBFt   _scan_factoryt	   make_scant   True(   R	   R?   R<   t   image_ranget   oscillationt   templatet	   directoryt   format(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyt   _scanW   s    	c         C   s   t  d ƒ ‚ d S(   s?   Get the raw image data. For GXPARM.XDS file raise am exception.s'   GXPARM.XDS does not support image data!N(   t   IOError(   R	   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyt   get_raw_datag   s    (   t   __name__t
   __module__t   __doc__t   staticmethodR   R   R   R
   R2   R7   R;   RL   RN   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyR      s   							t   __main__Ni   (
   t
   __future__R    t   dxtbx.format.FormatR   R   RO   t   syst   argvt   argR   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/format/FormatXPARM.pyt   <module>
   s   ]