ó
Q™xTc           @   s¢   d  d l  m Z d  d l m Z d  d l Z d  d l m Z d  d l m	 Z	 d  d l
 Z
 d d d „ Z d e f d	 „  ƒ  YZ d d d d
 „ Z d d d „ Z d S(   iÿÿÿÿ(   t   division(   t   flexN(   t   abs_arg(   t   adopt_init_argsi    c         C   sŒ   t  j |  | ƒ } t  j |  | ƒ } | j ƒ  s6 t ‚ d sB | rd | Gd | j ƒ  | j ƒ  f GHn  | d k sˆ | j ƒ  | k sˆ t ‚ d  S(   Ni    s   correlation: %.4f slope: %.3f(   R   t   linear_regressiont   linear_correlationt   is_well_definedt   AssertionErrort   coefficientt   slope(   t   xt   yt   labelt   min_correlationt   verboset   xy_regrt   xy_corr(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/structure_factor_utils.pyt   check_regression   s    t	   collectorc           B   s,   e  Z d  d  d  d „ Z d „  Z d „  Z RS(   i    c         C   sV   t  |  t ƒ  ƒ t j ƒ  |  _ t j ƒ  |  _ d |  _ d |  _ d |  _ d |  _	 d  S(   Ni    (
   R   t   localsR   t   doublet   amp1t   amp2t   sum_amp1_minus_amp2_sqt   sum_amp1_sqt   sum_w_phase_errort   sum_w(   t   selfR   t   min_corr_amplt   max_mean_w_phase_errorR   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/structure_factor_utils.pyt   __init__   s    			c      
   C   s  t  | d t ƒ\ } } t  | d t ƒ\ } } d s? |  j r‰ | GHd G| G| GHd G| G| GHd	 Gd t j j d | d | d t ƒ GHn  |  j j | ƒ |  j j | ƒ |  j	 | | d 7_	 |  j
 | d 7_
 |  j | | t j j d | d | d t ƒ 7_ |  j | | 7_ d  S(
   Nt   degi    t    i   s   %.2ft   phi1t   phi2i   s                       (   R   t   TrueR   t   scitbxt   matht   phase_errorR   t   appendR   R   R   R   R   (   R   t   ht   f1t   f2t   a1t   p1t   a2t   p2(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/structure_factor_utils.pyt   add   s    c         C   sÙ   |  j  rA |  j |  j  } d s( |  j rA |  j Gd | f GHqA n  |  j r` |  j |  j |  _ n  t |  j |  j	 |  j d |  j
 |  j ƒ d s˜ |  j r± |  j d |  j f GHn  |  j rÕ |  j |  j k sÕ t ‚ n  d  S(   Ni    s   R-factor: %.3fs    ampls     mean weighted phase error: %.2f(   R   R   R   R   R   R   t   mean_w_phase_errorR   R   R   R   R   R   (   R   t   r(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/structure_factor_utils.pyt   report.   s    		
		(   t   __name__t
   __module__R   R/   R2   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/structure_factor_utils.pyR      s   		c         C   sÄ   t  |  | | | ƒ } | d k rz | j ƒ  | j ƒ  k s? t ‚ xt t | ƒ D]' \ }	 }
 | j | |	 |
 | |	 ƒ qL Wn< x9 | j ƒ  D]+ \ }	 } | j | |	 | |	 | | ƒ q‡ W| j ƒ  d  S(   Ni    (   R   t   sizeR   t	   enumerateR/   t   pairsR2   (   R   t   h1t   matchR)   R*   R   R   R   t   collt   it   f1_it   j(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/structure_factor_utils.pyt   check_correlation>   s    "#g»½×Ùß|Û=c         C   sÐ   |  j  ƒ  } t j |  j ƒ  ƒ } x¨ t |  j ƒ  ƒ D]” \ } } |  j ƒ  | } | r | G| Gt | ƒ G| | d t j GHn  t | j	 ƒ | k r4 t | j
 ƒ | k r4 | j | | | ƒ sÈ t ‚ q4 q4 Wd  S(   Ni´   (   t   space_groupR   t   argt   dataR6   t   indicest   absR%   t   pit   realt   imagt   is_valid_phaseR   (   t   miller_arrayt   epsilonR   R?   t   phasesR;   R(   t   f(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/structure_factor_utils.pyt   check_phase_restrictionsM   s    )*(   t
   __future__R    t   cctbx.array_familyR   t   scitbx.mathR$   t   libtbx.complex_mathR   t   libtbxR   R%   R   t   objectR   R>   RL   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/structure_factor_utils.pyt   <module>   s   	.