ó
[™xTc           @   s�   d  d l  m Z d  d l m Z d  d l m Z d  d l Z d  d l Z d e f d „  ƒ  YZ	 d „  Z
 e d k r} e
 ƒ  n  d S(	   iÿÿÿÿ(   t   division(   t   flex(   t   chebyshev_polynomeNt   functionc           B   sJ   e  Z d  d d d „ Z d „  Z d	 d „ Z d „  Z d „  Z d „  Z RS(
   id   g      @g     €F@c         C   s¾   | |  _  | |  _ | |  _ | |  _ d d t j t | d ƒ ƒ | |  _ d d |  j |  j |  _ d |  j d <t j	 |  j  ƒ d d |  _
 |  j ƒ  t |  j  d d 
|  j
 ƒ |  _ d  S(	   Ng      ð?g       @i   g      à?g:Œ0âŽyE>i    g        g      ð¿(   t   nt   mt   kt   d_maxR   t   doublet   ranget   xt   rt   random_doublet   coefst
   load_coefsR   t   polynome(   t   selfR   R   R   R   (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyt   __init__	   s    				(
c         C   s?   t  |  j ƒ } x) t |  j | ƒ D] \ } } | G| GHq" Wd  S(   N(   t
   get_p_of_rR
   t   zipR   (   R   t   resultR   t   y(    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyt   show   s    c         C   ss   | d  k r, t j |  j ƒ d d |  _ n$ t | ƒ |  j k sG t ‚ | |  _ t |  j d d 
|  j ƒ |  _ d  S(   Ng      à?g       @g      ð¿g      ð?(	   t   NoneR   R   R   R   t   lent   AssertionErrorR   R   (   R   R   (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyR      s
     	c         C   sF   t  j d | | |  j ƒ } t  j |  j j | ƒ ƒ } | | } | S(   Ng      ð?(   R   t   powR   t   expR   t   f(   R   R
   t   baset   exp_polR   (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyR   %   s    
c         C   s4   d | d |  j  } t j | | ƒ | | } | S(   Ng      à?i   (   R   R   t   sin(   R   t   qR
   R   t   sinc(    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyt   get_sinc+   s    c         C   sr   t  j j | ƒ } | j ƒ  } | j ƒ  } |  j | ƒ } |  j | | ƒ } | | } | | }	 t j |	 ƒ }
 |
 S(   N(	   t   scitbxt   matht   gauss_legendre_engineR
   t   wR   R"   R   t   sum(   R   R    t   nit   glet   x_intt   w_intt   p_of_rR!   t   tbit   wtbiR   (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyt	   integrate0   s    

N(	   t   __name__t
   __module__R   R   R   R   R   R"   R/   (    (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyR      s   	
		c          C   sÿ   t  d d ƒ }  d d d d d d d	 d
 d d d d d d d d d g } g  } x' | D] } | j |  j | d ƒ ƒ qU Wx€ t | t t | ƒ ƒ ƒ D]c \ } } | G| GxK t d d ƒ D]: } d t |  j | | ƒ | | ƒ t | | d ƒ Gq¸ WHq” Wd  S(   Ni   id   gü©ñÒMbP?g{®Gáz„?g{®Gáz”?gš™™™™™©?gš™™™™™¹?g333333Ã?gš™™™™™É?g333333Ó?gš™™™™™Ù?g      à?g333333ã?gffffffæ?gš™™™™™é?gÍÌÌÌÌÌì?g      ð?gš™™™™™ñ?g333333ó?iZ   i   g      Y@g‚vIhÂ%<=(   R   t   appendR/   R   R	   R   t   abs(   R   t   q_trialst   ref_integralsR    t   jjt   ii(    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyt   example;   s    9(8t   __main__(   t
   __future__R    t   scitbx.array_familyR   t   scitbx.mathR   R#   R$   t   objectR   R8   R0   (    (    (    sb   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/examples/integrating_a_weighted_sinc_function.pyt   <module>   s   3	