ó
I™xTc           @   s•   d  d l  m Z d  d l m Z d  d l Z d  d l j j Z d  d l	 m
 Z
 d d d „ Z d „  Z d	 d
 „ Z d „  Z e d k r‘ e ƒ  n  d S(   iÿÿÿÿ(   t   division(   t   flexN(   t   milleri,  g{®Gáz„?c         C   sª   |  j  ƒ  d j } |  j ƒ  j ƒ  d } t j ƒ  } t j ƒ  } d } xV | d k rŸ | | 7} | | d d f }	 | j |	 ƒ }
 | j | ƒ | j |
 ƒ qJ W| | f S(   Ni    iöÿÿÿi
   (   t
   scattererst   sitet	   unit_cellt
   parametersR   t   doublet   eight_point_interpolationt   append(   t   xrst   map_datat   n_stepst	   step_sizet   atom_centert   a_cellt   distt   rhot   xt   pointt   density_value_at_point_e(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_mem.pyt   map_1d   s    
c         C   s^   |  j  ƒ  | j  ƒ  k s t ‚ t j |  ƒ }  t j | ƒ } t j |  | ƒ t j | | ƒ S(   N(   t   sizet   AssertionErrorR   t   abst   sum(   R   t   y(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_mem.pyt   scale   s    g�íµ ÷Æ°>c         C   sr   |  d | k } | |  d | k  M} | j  t ƒ d k s? t ‚ | j | ƒ } | j | ƒ } t j | | ƒ d S(   Ni    i   (   t   countt   TrueR   t   selectR   R   (   R   t   r1t   r2t   epst   selt   r1_t   r2_(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_mem.pyt   r_factor   s    c          C   sS  d }  t  j j d d  d |  ƒ j ƒ  } | j d d d d ƒ j ƒ  } | j d d	 ƒ } | j ƒ  | j	 ƒ  } t
 d
 | d | j ƒ  t j | ƒ ƒ \ } } | j d d d d ƒ j ƒ  } t j d | d | ƒ } | j ƒ  | j	 ƒ  }	 t
 d
 | d |	 ƒ \ }
 } t | | ƒ } | | } t d |
 d | d | ƒ } t j d | d | ƒ j ƒ  } d | G| GHd } xd d d g D]	} t j d | d | j ƒ  d | d d	 d t d | d d d t ƒ } t
 d
 | d | j ƒ \ } } t | | ƒ } | | } t d |
 d | d | ƒ } t j d | d | ƒ j ƒ  } | j d t ƒ Gd  Gd! | G| GH| d" k  sht | ƒ ‚ | d# k swt | ƒ ‚ qwWt j d | d | j ƒ  d d$ d d	 d% d& d' d( d t d d d d) d t ƒ 
} t
 d
 | d | j ƒ \ } } t | | ƒ } | | } t d |
 d | d | ƒ } t j d | d | ƒ j ƒ  } | j d t ƒ Gd  Gd! | G| GH| d* k  s{t | ƒ ‚ | d# k s“t | ƒ ‚ t j d | d | j ƒ  d d$ d d	 d% d& d' d( d+ | d t d d d d) d t ƒ } t
 d
 | d | j ƒ \ } } t | | ƒ } | | } t d |
 d | d | ƒ } t j d | d | ƒ j ƒ  } | j d t ƒ Gd  Gd! | G| GH| d, k  s�t | ƒ ‚ | d- k s¨t | ƒ ‚ t d. d/ ƒ } | j ƒ  | j ƒ  k oà| j ƒ  k n sët ‚ xC t | | | | ƒ D], \ } } } } | d0 | | | | f IJqW| j ƒ  | j ƒ  d1 GHd2 GHd  S(3   Ns�   
CRYST1    5.000    5.000    5.000  90.00  90.00  90.00 P 1
HETATM    1  C    C      1       0.000   0.000   0.000  1.00  5.00           C
END
t   source_infot   linest   d_ming¤p=
×£Ð?t	   algorithmt   directt   resolution_factorgš™™™™™¹?R
   R   ge(åÿÿ÷?t   crystal_griddingt   fourier_coefficientsR   R   R    R   s   Initial dist: %6.3fg®Gáz®ç?t   flatt   ldet   min_shiftedt   ft   f_000t   lamt   verboset	   start_mapt   max_iterationsi  t   detect_convergencet   *s   dist: %6.3fg-Cëâ6:?g+‡ÙÎ÷ï?g{®Gáz„?t   lambda_increment_factorg)\�Âõ(ð?t   betag      à?i   gü©ñÒMbp?t   xray_structuregš™™™™™©?gV-²�ïï?t   gpt   ws   %15.12f %15.12f %15.12f %15.12fs    gnuplot command to show results:s²   
plot [-3:3] [-0.1:1.1] "gp" using 1:2 with lines title "exact" lw 3, "gp" using 1:3 with lines title "synthesis" lw 3 lc rgb "black", "gp" using 1:4 with lines title "MEM" lw 3
(    t   iotbxt   pdbt   inputt   Nonet   xray_structure_simplet   structure_factorst   f_calct   fft_mapt   apply_sigma_scalingt   real_map_unpaddedR   t	   deep_copyR   t   maxR   R   R%   t   linear_correlationt   coefficientt   memt   runR2   t   FalseR   t   showR   R   t   openR   t   zipt   closet   write_mtz_file(   t   pdb_strR
   t   fct   fft_map_reft   map_data_reft   r_rt   rho_rt   F_0t	   fft_map_0t
   map_data_0t   r_st   rho_st   sct   Rt   ccR3   R5   t   mt   r_mt   rho_mt   oft   rR   R    t   r3(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_mem.pyRM   #   s~    !
"		

'	
!'
!'
!4(

t   __main__(   t
   __future__R    t   scitbx.array_familyR   t	   iotbx.pdbR>   t   cctbx.maptbx.memt   maptbxRL   t   cctbxR   R   R   R%   RM   t   __name__(    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/regression/tst_mem.pyt   <module>   s   		P