ó
ø™xTc           @   so   d  d l  m Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l m Z d d d „  ƒ  YZ	 d S(	   iÿÿÿÿ(   t   divisionN(   t   Scan(   t   scan_helper_image_files(   t   scan_helper_image_formatst   scan_factoryc           B   sz   e  Z d  Z e e d „ ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z RS(   sg   A factory for scan instances, to help with constructing the classes
  in a set of common circumstances.c      	   C   sm  d d l  m } t | t ƒ sW |  d |  d d } g  t | ƒ D] } | ^ qB } n� |  d |  d d } t | ƒ } | | k ræ | d k r³ g  t | ƒ D] } d ^ qž } qæ | j g  t | | ƒ D] } | d ^ qÊ ƒ } n  g  t | ƒ D] }	 | |	 ^ qó }
 t t	 t
 t |  ƒ ƒ t	 t
 t | ƒ ƒ | j t t
 t | ƒ ƒ ƒ | j t t
 t |
 ƒ ƒ ƒ | ƒ S(   Niÿÿÿÿ(   t   flexi   i    (   t   scitbx.array_familyR   t
   isinstancet   listt   ranget   lent   extendt   sortedR   t   tuplet   mapt   intt   floatt   double(   t   image_ranget   exposure_timest   oscillationt   epochst   degR   t
   num_imagest   it   num_expt   jt
   epoch_list(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyt	   make_scan   s$    ""-#c         C   si   d d l  } t j | j j |  ƒ d ƒ } | d k r@ d } n  t j | | f | | | f i | | 6ƒ S(   s.   Construct an scan instance for a single image.iÿÿÿÿNg        (   t   osR   t   image_to_indext   patht   splitt   NoneR   R   (   t   filenamet   formatR   t	   osc_startt	   osc_widtht   epochR   t   index(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyt   single3   s    	c         C   s/   t  j ƒ  } | j |  t  j ƒ t j |  | ƒ S(   s,   Initialize a scan model from an imgCIF file.(   t   pycbft   cbf_handle_structt	   read_filet
   MSG_DIGESTR   t   imgCIF_H(   t   cif_filet
   cbf_handle(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyt   imgCIF?   s    c         C   sy   | j  ƒ  } | j ƒ  d } | j ƒ  } t | j ƒ  ƒ } t j |  ƒ } | j | ƒ t j	 | | f | | i | | 6ƒ S(   sp   Initialize a scan model from an imgCIF file handle, where it is
    assumed that the file has already been read.i    (
   t   get_integration_timet   get_timestampt   construct_goniometerR   t   get_rotation_rangeR   R   t   __swig_destroy__R   R   (   R.   R/   t   exposuret	   timestampt   goniot   anglesR'   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyR-   H   s    c         C   s   t  |  d |  d ƒ S(   s_   Sum a list of scans wrapping the sligtly clumsy idiomatic method:
    sum(scans[1:], scans[0]).i   i    (   t   sum(   t   scans(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyt   addZ   s    c         C   sM   t  j |  ƒ \ } } t  j | | ƒ } g  | D] } t  j | | | ƒ ^ q. S(   sÎ   Get a list of files which appear to match the template and
    directory implied by the input filename. This could well be used
    to get a list of image headers to read and hence construct scans
    from.(   R   t   image_to_template_directoryt   template_directory_to_indicest!   template_directory_index_to_image(   R"   t   templatet	   directoryt   indicesR'   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyt   search`   s
    c         C   s    |  j  ƒ  d k r t j S|  j  ƒ  d k r2 t j S|  j  ƒ  d k sV |  j  ƒ  d k r] t j S|  j  ƒ  d k rv t j S|  j  ƒ  d k r� t j St d |  ‚ d S(	   sì   Return the correct format token for a given name, for example:

    cbf, CBF
    smv, SMV
    tiff, tif, TIFF
    raxis, RAXIS
    mar, MAR

    to the appropriate static token which will be used as a handle
    everywhere else in this.t   CBFt   SMVt   TIFt   TIFFt   RAXISt   MARs   name %s not knownN(   t   upperR   t
   FORMAT_CBFt
   FORMAT_SMVt   FORMAT_TIFFt   FORMAT_RAXISt
   FORMAT_MARt   RuntimeError(   t   name(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyR#   p   s    $(   t   __name__t
   __module__t   __doc__t   staticmethodt   TrueR   R(   R0   R-   R<   RC   R#   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyR      s   	(    (
   t
   __future__R    R)   t   copyt   dxtbx_model_extR   t   scan_helpersR   R   R   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/scan.pyt   <module>   s   