ó
÷™xTc           @   sg   d  d l  m Z d  d l Z d  d l m Z d „  Z d „  Z d „  Z d d
 d „  ƒ  YZ d	 „  Z	 d S(   iÿÿÿÿ(   t   divisionN(   t   matrixc         C   sÚ  t  t t |  d ƒ j ƒ  j ƒ  ƒ } t | ƒ d k s< t ‚ t | d ƒ } | d d !\ } } | d d !} | d } | d d !} t  t | d d	 !ƒ \ } }	 | d	 d
 !\ }
 } | d
 } | d d !\ } } | d d !| d d !} } | d d !} t | d ƒ } | d d !} | d d !| d d !| d d !} } } i | d 6| d 6| d 6| d 6| d 6| d 6| d 6|	 d 6|
 d 6| d 6| d 6| d 6| d  6| d! 6| d" 6| d# 6| d$ 6| d% 6| d& 6| d' 6| d( 6} | S()   st   Parse the XDS XPARM file, which contains a description of the detector
  and experimental geometry, to a dictionary.t   ri*   i    i   i   i   i   i
   i   i   i   i   i   i   i   i   i!   i$   i'   t   starting_framet	   phi_startt	   phi_widtht   axist
   wavelengtht   beamt   nxt   nyt   pxt   pyt   distancet   oxt   oyt   xt   yt   normalt
   spacegroupt   cellt   at   bt   c(   t   mapt   floatt   opent   readt   splitt   lent   AssertionErrort   int(   t   xds_xparm_filet   dataR   R   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   t   results(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/detector_helpers.pyt   read_xds_xparm   s0    $

)##&c         C   s‘  |  \ } } } | \ } } } t  j | j | j | j ƒ j ƒ  } | j ƒ  d d k  s` t ‚ t  j | j | j | j ƒ j ƒ  }	 |	 j ƒ  d d k  s¢ t ‚ | j | ƒ t j rÙ | j	 | ƒ }
 | j | ƒ } nL t j
 | j | ƒ t j ƒ d k  r| j	 | ƒ }
 t j } n | }
 d } |
 j | ƒ } | } | j | | ƒ } | j | ƒ } | | } t j
 | j ƒ  d ƒ d k  s�t ‚ | S(   s»   Compute reference frame rotation to rotate from the original frame
  given by original = (x, y, z) to the to reference frame given by
  final = (_x, _y, _z). Returns M where M.x = _x etc.g      ð?gH¯¼šò×z>g        (   R   t   sqrt   elemst	   transposet   determinantR   t   anglet   matht   pit   crosst   fabst$   axis_and_angle_as_r3_rotation_matrix(   t   originalt   finalR   R   t   zt   _xt   _yt   _zt   Ot   Ft   _ra_xt   _a_xt   _m_xt   _ra_zt   _a_zt   _m_zt   _m(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/detector_helpers.pyt   compute_frame_rotation6   s*    &&%
%c         C   s$   |  j  d ƒ |  j d ƒ |  j ƒ  S(   s:   Given a cbf handle, get the value for the undefined pixel.t   array_intensitiest   undefined_value(   t   find_categoryt   find_columnt   get_doublevalue(   t
   cbf_handle(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/detector_helpers.pyt   find_undefined_valuea   s    t   detector_helper_sensorsc           B   sD   e  Z d  Z d Z d Z d Z d Z e d „  ƒ Z e d „  ƒ Z	 RS(   sÀ   A helper class which allows enumeration of detector sensor technologies
  which should help in identifying specific detectors when needed. These are
  currently limited to IMAGE_PLATE CCD PAD.t
   SENSOR_CCDt
   SENSOR_PADt   SENSOR_IMAGE_PLATEt   SENSOR_UNKNOWNc         C   s,   |  t  j t  j t  j t  j g k r( t St S(   N(   RE   RF   RG   RH   RI   t   Truet   False(   t   sensor_type(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/detector_helpers.pyt   check_sensorr   s    	c           C   s   t  j t  j t  j g S(   N(   RE   RF   RG   RH   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/detector_helpers.pyt   all{   s    (
   t   __name__t
   __module__t   __doc__RF   RG   RH   RI   t   staticmethodRM   RN   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/detector_helpers.pyRE   h   s   	c         C   s<  d d l  m } |  j | j ƒ  ƒ \ } } | j t t | ƒ ƒ ƒ } | j | ƒ | } x‡ |  D] } | j | j ƒ  ƒ }	 |	 | j | j ƒ  ƒ | d | j | j	 ƒ  ƒ | d }
 | j
 d | j ƒ  d | j	 ƒ  d |
 ƒ q` W|  j | j ƒ  ƒ \ } } | j | ƒ | j t t | ƒ ƒ ƒ j ƒ  d k  s8t ‚ d	 S(
   s_    detector and beam are dxtbx objects,
      mosflm_beam_centre is a tuple of mm coordinates.
  iÿÿÿÿ(   R   i    i   t	   fast_axist	   slow_axist   origing�íµ ÷Æ°>N(   t   scitbxR   t   get_ray_intersectiont   get_s0t   colt   tuplet   reversedt
   get_origint   get_fast_axist   get_slow_axist   set_local_framet   lengthR   (   t   detectorR   t   mosflm_beam_centreR   t   panel_idt   old_beam_centret   new_beam_centret   origin_shiftt   panelt
   old_origint
   new_origin(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/detector_helpers.pyt   set_mosflm_beam_centre‚   s    (    (
   t
   __future__R    R)   RV   R   R#   R=   RD   RE   Rj   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/detector_helpers.pyt   <module>   s   
	(	+	