ó
ö™xTc           @   sO   d  d l  m Z d  d l Z d  d l Z d  d l m Z d d d „  ƒ  YZ d S(   iÿÿÿÿ(   t   divisionN(   t   Beamt   beam_factoryc        
   B   sª   e  Z d  Z d „  Z e d	 d	 d	 d	 d	 d	 d „ ƒ Z e d	 d	 d	 d	 d	 d	 d	 d	 d „ ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d „  ƒ Z RS(
   sÅ   A factory class for beam objects, which encapsulate standard beam
  models. In cases where a full cbf description is available this
  will be used, otherwise simplified descriptions can be applied.c         C   s   d  S(   N(    (   t   self(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   __init__   s    c         C   sè   | d  k s | d  k r' d } d } n  |  rm | s9 t ‚ t t t t |  ƒ ƒ t | ƒ t | ƒ t | ƒ ƒ S| r¿ | s t ‚ t t t d „  t t | ƒ ƒ ƒ t | ƒ t | ƒ t | ƒ ƒ S| sË t ‚ t t t t | ƒ ƒ ƒ Sd  S(   Ng        c         S   s   |  S(   N(    (   t   x(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   <lambda>,   s    (   t   Nonet   AssertionErrorR   t   tuplet   mapt   float(   t   sample_to_sourcet
   wavelengtht   s0t   unit_s0t
   divergencet   sigma_divergence(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt	   make_beam   s&    					c      	   C   sc  | s t  ‚ | s t  ‚ | d  k s0 | d  k r? d } d } n  |  r  | sQ t  ‚ t t t t |  ƒ ƒ t | ƒ t | ƒ t | ƒ t t t | ƒ ƒ t | ƒ ƒ S| r| s² t  ‚ t t t d „  t t | ƒ ƒ ƒ t | ƒ t | ƒ t | ƒ t t t | ƒ ƒ t | ƒ ƒ S| st  ‚ t t t t | ƒ ƒ t | ƒ t | ƒ t t t | ƒ ƒ t | ƒ ƒ Sd  S(   Ng        c         S   s   |  S(   N(    (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyR   L   s    (   R   R   R   R	   R
   R   (   R   R   R   R   t   polarizationt   polarization_fractionR   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   make_polarized_beam4   s<    									c         C   s   t  j d d d |  ƒ S(   sÇ   Construct a beam object on the principle that the beam is aligned
    with the +z axis, as is quite normal. Also assume the beam has
    polarization fraction 0.999 and is polarized in the x-z plane.R   g        g      ð?R   (   g        g        g      ð?(   R   R   (   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   simple[   s    	c         C   s   t  j d |  d | ƒ S(   s/   Construct a beam with direction and wavelength.R   R   (   R   R   (   R   R   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   simple_directionale   s    	c      	   C   s"   t  j d |  d | d | d | ƒ S(   sX   Full access to the constructor for cases where we do know everything
    that we need...R   R   R   R   (   R   R   (   R   R   t   polarization_plane_normalR   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   complexm   s
    	c   	   	   C   s  t  j d } t j ƒ  } | j |  t j ƒ | j d ƒ | j d ƒ | j d ƒ g  } x< t	 d ƒ D]. } | j d | d ƒ | j
 | j ƒ  ƒ qf W| j ƒ  } y | j ƒ  \ } } Wn d } d	 } n Xt  j | | ƒ t  j | | ƒ d	 f } t j d
 | d | d | d | ƒ S(   sá   Initialize a detector model from an imgCIF file. N.B. the
    definition of the polarization plane is not completely helpful
    in this - it is the angle between the polarization plane and the
    +Y laboratory frame vector.g     €f@t   axist	   equipmentt   sourcei   s
   vector[%d]i   g+‡ÙÎ÷ï?g        R   R   R   R   (   t   matht   pit   pycbft   cbf_handle_structt	   read_filet
   MSG_DIGESTt   find_categoryt   find_columnt   find_rowt   ranget   appendt   get_doublevaluet   get_wavelengtht   get_polarizationt   sint   cosR   R   (	   t   cif_filet   d2rt
   cbf_handlet	   directiont   jR   t   polar_fractiont   polar_anglet   polar_plane_normal(    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   imgCIFy   s,    
)	c      	   C   sü   t  j d } |  j d ƒ |  j d ƒ |  j d ƒ g  } x< t d ƒ D]. } |  j d | d ƒ | j |  j ƒ  ƒ qG W|  j ƒ  } y |  j	 ƒ  \ } } Wn d } d	 } n Xt  j
 | | ƒ t  j | | ƒ d	 f } t j d
 | d | d | d | ƒ S(   s(  Initialize a detector model from an imgCIF file. N.B. the
    definition of the polarization plane is not completely helpful
    in this - it is the angle between the polarization plane and the
    +Y laboratory frame vector. This example works from a cbf_handle,
    which is already configured.g     €f@R   R   R   i   s
   vector[%d]i   g+‡ÙÎ÷ï?g        R   R   R   R   (   R   R   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R   R   (   R/   R.   R0   R1   R   R2   R3   R4   (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   imgCIF_H§   s(    
)	N(   t   __name__t
   __module__t   __doc__R   t   staticmethodR   R   R   R   R   R   R5   R6   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyR      s    	#
.(    (   t
   __future__R    R   R   t   dxtbx_model_extR   R   (    (    (    s>   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/dxtbx/model/beam.pyt   <module>   s   