ó
J™xTc           @   s­  d  d l  m Z d  d l Z e j d ƒ d  d l m Z e j d ƒ d  d l m Z m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z m Z d  d l m Z d  d l m Z d „  Z d „  Z e e d d „ Z d „  Z d „  Z e d k r©d  d l Z x† d d d d d d g D]i Z  d e j! d k rŽe j! e j! j" d ƒ d Z# e$ d e# e  f d ƒ e _% n  e e j! d e  ƒ q9Wn  d S(   iÿÿÿÿ(   t   divisionNi    (   t   flex(   t   powt   pi(   t   sgtbx(   t   random_structure(   t   direct_summation_simple(   t   direct_summation_cuda_platform(   t   wall_clock_timet   show_times_at_exit(   t   approx_equal(   t   table_utilsc         C   sÒ   d d d d d d d d d g	 } | g } x{ |  D]s \	 } } } } } }	 }
 } } d	 | d
 | d
 |
 d
 | d
 | d
 | d
 | d |	 d | g	 } | j  | ƒ q1 Wt j | d t d d d d d d ƒGHd  S(   Ns   # HKLs   cpu-times	   simple-tms   fft-times   R(%)s   gpu_d-tms   gpu_f-tms   d-min(angstrom)s   %.0fs   %.2fs   %.5fs   %5.2ft
   has_headert   justifyt   leftt   prefixs   | t   postfixs    |(   t   appendR   t   formatt   True(   t   timest   headert   table_headert
   table_datat   it   tt   dt   gt   gft   gfRt   st   ft   fRt	   table_row(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_direct_scaling.pyt   show_times_vs_complexity   s    		(#"c         C   s±   t  |  j ƒ  j ƒ  ƒ GHt  |  j ƒ  j ƒ  ƒ GHt  |  j ƒ  j ƒ  ƒ GHt  |  j ƒ  j ƒ  ƒ GHHt  |  j ƒ  j |  j ƒ  ƒ ƒ GHHt  |  j ƒ  j ƒ  ƒ GHHt  |  j ƒ  j	 ƒ  ƒ GHd  S(   N(
   t   listt
   scattererst   extract_labelst   extract_occupanciest   extract_scattering_typest   extract_sitest   extract_u_cartt	   unit_cellt   extract_u_isot   extract_u_star(   t   xs(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_direct_scaling.pyt   show_diagnostics    s     c   )      C   sl  t  j d |  d | d | d d d d ƒ } | j ƒ  j ƒ  j ƒ  } g  } t ƒ  } t d d	 ƒ }	 t }
 xït d
 d ƒ D]Þ} d t | ƒ GHt	 d | ƒ } | | d } | |  j
 ƒ  j ƒ  9} t	 d | d t d ƒ } d | } t } |
 rmt ƒ  } | j d | d d d | ƒ } | j ƒ  } | j ƒ  } t ƒ  } | j d | d t ƒ  ƒ } | j ƒ  } | j ƒ  } n d } d } t ƒ  } | j d | d | ƒ } | j ƒ  } | j ƒ  } | j ƒ  } t j | j ƒ  ƒ } t ƒ  } | j d | d |	 ƒ } | j ƒ  } | j ƒ  } | j ƒ  }  t j |  j ƒ  | j ƒ  ƒ }! t j |! ƒ }" d |" | }# t ƒ  } | j d | d d ƒ }$ | j ƒ  }% |$ j ƒ  }& |& j ƒ  }' t j |' j ƒ  | j ƒ  ƒ }! t j |! ƒ }" d |" | }( | j | | | | | |# | |% |( f	 ƒ |
 rv t | j ƒ  | j ƒ  d d ƒs*t ‚ t | j ƒ  | j ƒ  d d ƒsTt ‚ qv qv Wt | d d ƒd  S(   Nt   space_group_infot   elementst   random_u_isot   volume_per_atomgš™™™™™2@t   min_distanceg333333ó?t   float_tt   floati   i   s   There are %d scatterersg      $@g       @g      @g      @g      ð?t   d_mint	   algorithmt   directt   cos_sin_tablei    g      Y@t   fftt   epsg�íµ ÷Æ°>R   s   run time vs. # reflectionsgUUUUUUÕ?(   R   t   xray_structureR*   t
   reciprocalt   volumeR   R   t   xranget   lenR   t   groupt   order_zR   t   FalseR   t   structure_factorst   elapsedt   f_calcR   t   as_amplitude_arrayR   t   sumt   datat   absR   R
   t   AssertionErrorR"   ()   R/   R0   t   anomalous_flagt   use_random_u_isot   verboseR-   t   reciprocal_volumeR   t   cuda_platformt   cuda_platform_floatt   direct_referencet   xt   number_of_reflectionst   Volumet   recip_radiusR6   R9   t   timert
   cpu_directt   cpu_timet   cpu_direct_ft   simple_directt   simple_timet   simple_direct_ft
   gpu_directt   gpu_timet   gpu_direct_ft   gpu_amplitudet   sum_ampt   gpuf_directt	   gpuf_timet   gpuf_direct_ft   gpuf_amplitudet   abs_difft   sum_difft   gpuf_Rfactort   fft_algorithmt   fft_timet   fft_ft   fft_amplitudet   fft_Rfactor(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_direct_scaling.pyt   exercise_direct-   s|    			
						'.c          C   s›   x” t  d ƒ D]† }  x} t  d ƒ D]o } xf t  d d ƒ D]U } d g |  d g | d g | | |  } d j | ƒ GHt t j d ƒ | ƒ q6 Wq  Wq Wd  S(	   Ni#   i]   ic   t   Ct   Nt   Ot    t   P1(   R?   t   joinRo   R   R/   (   Rp   Rq   t   totalR0   (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_direct_scaling.pyt   run_scattering_type_tests„   s    +c         C   sŒ   t  ƒ  d |  k } d |  k } d g d d g d d g d d	 g d
 } | | } t j d ƒ } d G| GHt | | d | d | ƒd  S(   Ns	   --verboses   --use_random_u_isoRr   i   Rq   i   Rp   i>   t   Si   Rt   s   Space groupRM   RN   (   R	   R   R/   Ro   (   t   argst
   multiplierRN   RM   R0   t   allelementst   sgi(    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_direct_scaling.pyt   runŒ   s    .
	t   __main__i
   i   i(   iP   i    i@  s	   --fileouti   s
   %s%03d.logt   w(&   t
   __future__R    t   randomt   seedt   scitbx.array_familyR   t   set_random_seedt   mathR   R   t   cctbxR   t   cctbx.developmentR   t<   cctbx.xray.structure_factors.from_scatterers_direct_parallelR   R   t   libtbx.utilsR   R	   t   libtbx.test_utilsR
   t   libtbxR   R"   R.   RC   Ro   Rw   R}   t   __name__t   syst   sizet   argvt   indext   result_baset   opent   stdout(    (    (    sQ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_direct_scaling.pyt   <module>   s4   		S		