ó
™xTc           @   s'   d  d l  m Z d d d „  ƒ  YZ d S(   iÿÿÿÿ(   t   divisiont   readerc           B   sq   e  Z d  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d
 e e d
 d	 „ Z RS(   s2   A class to read the INTEGRATE.HKL file used in XDSc         C   sy   i  |  _  g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _	 g  |  _
 g  |  _ g  |  _ d S(   s   Initialise the file contents.N(   t   _headert   hklt   iobst   sigmat   xyzcalt   rlpt   peakt   corrt   maxct   xyzobst   alfbet0t   alfbet1t   psi(   t   self(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyt   __init__   s    												c         C   s   t  |  d ƒ j d ƒ d k S(   s­   Check that the file is identified as an INTEGRATE.HKL

    Params:
      filename The path to the file

    Returns:
      True/False Is the file an INTEGRATE.HKL file

    t   ri   s   !OUTPUT_FILE=INTEGRATE.HKL(   t   opent   read(   t   filename(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyt   is_integrate_hkl_file   s    c         C   sã   t  j | ƒ s' t d j | ƒ ƒ ‚ n  t | d ƒ j ƒ  } t } x� | D]ˆ } | r« | j ƒ  j d ƒ rv t	 } qI qÑ | j ƒ  j d ƒ s‘ qI n  |  j
 | j ƒ  d ƒ qI | j ƒ  j d ƒ rÄ PqI |  j | ƒ qI W|  j ƒ  d S(   sÇ   Read the INTEGRATE.HKL file.

    See http://xds.mpimf-heidelberg.mpg.de/html_doc/xds_files.html for more
    information about the file format.

    Params:
      filename The path to the file

    s    {0} is not an INTEGRATE.HKL fileR   s   !END_OF_HEADERt   !i   s   !END_OF_DATAN(   R   R   t   IOErrort   formatR   t	   readlinest   Truet   stript
   startswitht   Falset   _parse_header_linet   _parse_data_linet   _set_header_parameters(   R   R   t   linest	   in_headert   l(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyt	   read_file+   s     c         C   sO   y t  | ƒ SWn: t k
 rJ y t | ƒ SWqK t k
 rF t | ƒ SXn Xd S(   s�   Parse a string to either an int, float or string

    Params:
      s The input string

    Returns:
      The parsed value

    N(   t   intt
   ValueErrort   floatt   str(   R   t   s(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyt
   _parse_strS   s    
c         C   sY   | j  ƒ  } t | ƒ d k r/ |  j | d ƒ St g  | D] } |  j | ƒ ^ q9 ƒ Sd S(   s‘   Parse the value or array of values contained in the string

    Params:
      value The value to parse

    Returns:
      The parsed value

    i   i    N(   t   splitt   lenR*   t   tuple(   R   t   valuet   valuesR)   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyt   _parse_valuee   s    
c         C   s±  |  j  d |  _ |  j  d |  _ |  j  d |  j  d f |  _ |  j  d |  j  d f |  _ |  j  d |  _ |  j  d |  _ |  j  d	 |  _ |  j  d
 |  _ |  j  d |  _	 |  j  d |  _
 |  j  d |  _ |  j  d |  _ |  j  d |  j  d f |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  j  d |  _ |  `  d S(   s-   Get the parameters from the header dict

    t   SPACE_GROUP_NUMBERt   UNIT_CELL_CONSTANTSt   NXt   NYt   QXt   QYt   STARTING_FRAMEt   STARTING_ANGLEt   OSCILLATION_RANGEt   ROTATION_AXISs   X-RAY_WAVELENGTHt   INCIDENT_BEAM_DIRECTIONs   DIRECTION_OF_DETECTOR_X-AXISs   DIRECTION_OF_DETECTOR_Y-AXISt   ORGXt   ORGYt   DETECTOR_DISTANCEs   UNIT_CELL_A-AXISs   UNIT_CELL_B-AXISs   UNIT_CELL_C-AXISs   BEAM_DIVERGENCE_E.S.D.s   REFLECTING_RANGE_E.S.D.t   NAME_TEMPLATE_OF_DATA_FRAMESt   DETECTORt   MINPKt   CUTt   VARIANCE_MODELN(   R   t   space_groupt	   unit_cellt   detector_sizet
   pixel_sizet   starting_framet   starting_anglet   oscillation_ranget   rotation_axist
   wavelengtht   beam_vectort   detector_x_axist   detector_y_axist   detector_origint   detector_distancet   unit_cell_a_axist   unit_cell_b_axist   unit_cell_c_axist   sigma_divergencet   sigma_mosaicityt   templatet   detector_typet   minpkt   cutt   variance_model(   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyR    u   s2    c         C   sÏ   | j  d ƒ } t | ƒ d k  r% d S| d } t | ƒ d k r« xg t d t | ƒ d ƒ D]I } | | j  ƒ  } d j | d  ƒ } |  j | ƒ |  j | <| d } q[ Wn  | d } |  j | ƒ |  j | <d S(   sf   Parse a line that has been identified as a header line

    Params:
      line The line to parse

    t   =i   Ni    i   t    iÿÿÿÿ(   R+   R,   t   ranget   joinR0   R   (   R   t   linet
   name_valuet   namet   it
   value_nameR.   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyR   “   s    
 
c         C   sT  | j  ƒ  } t t | d d !ƒ t t | d ƒ } |  j j t | d d !ƒ ƒ |  j j | d ƒ |  j j | d ƒ |  j	 j t | d d !ƒ ƒ |  j
 j | d ƒ |  j j | d ƒ |  j j | d ƒ |  j j | d ƒ |  j j t | d	 d
 !ƒ ƒ |  j j t | d
 d !ƒ ƒ |  j j t | d d !ƒ ƒ |  j j | d ƒ d S(   s]   Parse a data line from the Integrate.hkl file

    Params:
      line The line to parse

    i    i   i   i   i   i	   i
   i   i   i   i   i   N(   R+   t   mapR%   R'   R   t   appendR-   R   R   R   R   R   R	   R
   R   R   R   R   (   R   R`   t   tokens(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyR   ©   s    'c         C   sÐ  | d  k r! | j d d ƒ } n  d d l m } d d l m } m } m } | j d |  j	 d | j
 d |  j ƒ ƒ } | j |  j ƒ }	 | j | |	 ƒ }
 | j |
 d	 | j |  j ƒ d
 | j |  j ƒ ƒj | j d d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ | j |
 d	 | j |  j ƒ ƒj | j d d g ƒ ƒ f
 S(   Nt   source_typet   xds_integrate_hkliÿÿÿÿ(   t   flex(   t   crystalt   millert   sgtbxRE   t   space_group_infot   numbert   datat   sigmast   labelsR   t
   sigma_iobsR   R   R   R   R	   R
   R   R   R   (    t   Nonet
   array_infot   cctbx.array_familyRj   t   cctbxRk   Rl   Rm   t   symmetryRE   Rn   RD   t   miller_indexR   t   sett   arrayt   doubleR   R   t   set_infot   customized_copyt   vec3_doubleR   R   R   R   R	   R
   t   vec2_doubleR   R   R   (   R   t   crystal_symmetryt   force_symmetryt   merge_equivalentst   base_array_infoRl   Rj   Rk   Rm   t   indicest
   miller_set(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyt   as_miller_arraysÂ   sP    		-	!	!	!	!	!	!	!	!	!	N(   t   __name__t
   __module__t   __doc__R   t   staticmethodR   R$   R*   R0   R    R   R   Rt   R   R   R‡   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyR      s   		(					N(    (   t
   __future__R    R   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/xds/integrate_hkl.pyt   <module>	   s   