ó
T™xTc           @   s  d  d l  m Z d  d l Z d  d l Z e j j d ƒ Z d  d l	 Td  d l 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 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 m Z d  d l m Z d  d l m Z d  d l m Z m  Z  m! Z! d  d l m" Z" m# Z# d  d l$ Z d  d l% m& Z& m' Z' d  d l( Z( d  d l) Z) d  d l* Z* d  d l+ Z+ d  d l, Z, d  d l- Z- d  d l m. Z. e j* j/ ƒ  Z0 e j1 Z1 d „  Z2 d e j3 f d „  ƒ  YZ3 d e4 f d „  ƒ  YZ5 d „  Z6 d e
 j7 f d „  ƒ  YZ8 e9 e9 e9 d „ Z: d „  Z; d  e4 f d! „  ƒ  YZ< d" „  Z= d# e8 f d$ „  ƒ  YZ> d% f  d& „  ƒ  YZ? d' e4 f d( „  ƒ  YZ@ d) e4 f d* „  ƒ  YZA d+ e jB f d, „  ƒ  YZC e9 eD eD d- „ ZE d. d/ „ ZF d0 e4 f d1 „  ƒ  YZG d S(2   iÿÿÿÿ(   t   divisionNt   cctbx_miller_ext(   t   *(   t   crystal(   t   maptbx(   t   sgtbx(   t   lattice_symmetry(   t   uctbx(   t   r_free_utils(   t   flex(   t   fftpack(   t   iround(   t   complex_math(   t   store(   t   adopt_init_args(   t   show_string(   t   Sorryt   Keept   plural_s(   t
   group_argst   Auto(   t   countt   izip(   t   matrixc         C   s8   t  | ƒ t j k s t ‚ |  d  k r+ d  S|  j | ƒ S(   N(   t   typet   typest	   SliceTypet   AssertionErrort   Nonet   __getitem__(   t   arrayt   slice_object(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   _slice_or_none'   s     t   binnerc           B   sÔ   e  Z d  „  Z d „  Z d „  Z e e d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 e e d e d	 d e d
 „ Z e e d e d	 d d d d „ Z d e e d e e d	 d d d d „
 Z d d e e d „ Z RS(   c         C   s’   t  j j |  | | j ƒ  ƒ | j ƒ  |  _ | j ƒ  |  _ | j ƒ  j ƒ  d k rd | j ƒ  |  _ n | j ƒ  |  _ d  |  _
 d  |  _ t |  _ d  S(   Ni    (   t   extR!   t   __init__t   indicest   space_group_infot   anomalous_flagt   sizet   d_mint   _completeness_d_minR   t   _counts_givent   _counts_completet   Falset   _have_format_strings(   t   selft   binningt
   miller_set(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#   .   s    		c         C   sX   t  |  j ƒ  |  j ƒ  ƒ t d t j d |  j ƒ  d |  j ƒ d |  j ƒ  d |  j ƒ f S(   Nt   crystal_symmetryt	   unit_cellR%   R$   R&   (	   R/   R2   t   limitst   setR   t   symmetryR%   t   miller_indicesR&   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __getinitargs__:   s    		c         C   sR   |  j  d  k rK g  |  _  x0 |  j ƒ  D] } |  j  j |  j | ƒ ƒ q% Wn  |  j  S(   N(   R*   R   t	   range_allt   appendR   (   R.   t   i_bin(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   counts_givenF   s
    	 g�íµ ÷Æ°>c      	   C   sÆ   |  j  d  k r¿ |  j t t f k s* t ‚ t d t j d |  j	 ƒ  d |  j
 ƒ d |  j d |  j d | ƒ } | sƒ | j ƒ  } n  | s˜ | j ƒ  } n  t d |  d | ƒ } | j ƒ  |  _  n  |  j  S(	   NR1   R2   R%   R&   R(   i   R/   R0   (   R+   R   R&   R,   t   TrueR   t	   build_setR   R5   R2   R%   R)   t   select_acentrict   select_centricR!   R;   (   R.   t   include_centrict   include_acentrict   d_min_tolerancet   complete_sett   binner_complete(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   counts_completeM   s    		c         C   s   |  j  |  j ƒ  ƒ j ƒ  S(   N(   t   array_indicest   i_bin_d_too_largeR'   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   n_bin_d_too_largea   s    c         C   s   |  j  |  j ƒ  ƒ j ƒ  S(   N(   RF   t   i_bin_d_too_smallR'   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   n_bin_d_too_smalld   s    c         C   s   |  j  ƒ  |  j ƒ  S(   N(   RH   RJ   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   n_bin_d_too_large_or_smallg   s    c         C   s^  |  j  sZt |  _  t d t t |  j ƒ  ƒ ƒ ƒ } d | |  _ d d | d d d |  _ t d |  j d ƒ d	 ƒ } d
 | |  _	 d | } d j
 | d |  j	 g ƒ |  _ d j
 |  j	 d |  j	 g ƒ |  _ d j
 |  j	 d | g ƒ |  _ d t t t |  j ƒ  ƒ ƒ ƒ |  _ d t t t |  j ƒ  ƒ ƒ ƒ |  _ d |  j d |  j d |  _ n  d  S(   Ni   s
   bin %%%dd:t    i   i   i   s   unused:s   %.4fi    s   %%%d.4ft   -s   %%%dds   %%-%ddt   [t   /t   ](   R-   R<   t   maxt   lent   strt   n_bins_usedt   fmt_bint
   fmt_unusedt   bin_d_ranget   fmt_bin_ranget   joint   fmt_bin_range_firstt   fmt_bin_range_usedt   fmt_bin_range_lastR;   t   fmt_counts_givenRE   t   fmt_counts_completet   fmt_both_counts(   R.   t   nt   blank_d(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   _setup_format_stringsj   s    		!
!%%t   dc	         C   si  | d  k	 r | } d } n  | d k s- t ‚ | d k rN | d  k	 sN t ‚ n  |  j ƒ  | |  j ƒ  k }	 | |  j ƒ  k }
 g  } | r¾ |	 s” |
 r§ | j |  j ƒ q¾ | j |  j | ƒ n  |  j | ƒ } | r| d k rg  | D] } t	 j
 | ƒ ^ qæ } nº | d k r>g  | D] } t	 j t	 j
 | ƒ ƒ ^ q} n€ | d k rxg  | D] } t	 j t	 j
 | ƒ ƒ ^ qQ} nF | d k r¾g  | D]* } t	 j t	 j
 | ƒ d | d t ƒ^ q‹} n  |	 rß| j |  j | d ƒ q|
 r | j |  j | d	 ƒ q| j |  j t | ƒ ƒ n  | rN| j |  j |  j | |  j | f ƒ n  | rad
 j | ƒ S| Sd  S(   NRc   t	   d_star_sqt   stolt   stol_sqt	   two_thetat
   wavelengtht   degi   i    RL   (   Rc   s	   d_star_sqs   stols   stol_sqs	   two_theta(   R   R   Rb   RG   RI   R9   RV   RU   RW   R   t   d_as_d_star_sqt   d_star_sq_as_stolt   d_star_sq_as_stol_sqt   d_star_sq_as_two_thetaR<   RZ   R\   R[   t   tupleR_   R*   R+   RY   (   R.   R:   t   show_bin_numbert   show_bin_ranget   show_d_ranget   show_countst   bin_range_asRh   t   join_stringt   is_firstt   is_lastt   resultt	   bin_ranget   bin_d(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   bin_legend{   sL    		
%++7t    c	   
      C   sq   | d  k r t j } n  xR |  j ƒ  D]D }	 | | |  j d |	 d | d | d | d | d | d | ƒ IJq% Wd  S(   NR:   Ro   Rp   Rq   Rr   Rs   Rh   (   R   t   syst   stdoutR8   Rz   (
   R.   Ro   Rp   Rq   Rr   Rs   Rh   t   ft   prefixR:   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   show_summary°   s    	 c         C   s}  t  | ƒ |  j ƒ  k s t ‚ |
 d  k r6 t j }
 n  | rK |  j ƒ  } n |  j ƒ  } d  } x| D]û } |  j d | d | d | d | d | d | d |	 ƒ } |
 | | I| | d  k	 r[t	 | | t
 ƒ sÝ | d  k rî |
 | | Iq[t	 | t
 ƒ r|
 | | | Iq[| d |  d | d	 | ƒ } | d  k	 r[t  | ƒ d
 k r[|
 | Iq[n  |
 Jqd W| d  k	 ryt  | ƒ Sd  S(   NR:   Ro   Rp   Rq   Rr   Rs   Rh   R!   t   datai    (   RR   t
   n_bins_allR   R   R|   R}   R8   t
   range_usedRz   t
   isinstanceRS   (   R.   R�   t   data_fmtRo   Rp   Rq   Rr   t   show_unusedRs   Rh   R~   R   t   i_binst   legendR:   t   s(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt	   show_dataÄ   s:     		  
s   ---c         C   so  t  | ƒ |  j ƒ  k s t ‚ | r3 |  j ƒ  } n |  j ƒ  } g  } xÿ | D]÷ }	 |  j d |	 d | d t d d d t d d d d d	 t ƒ }
 |
 } | |	 d k	 r)t	 | |	 t
 ƒ sÃ | d k r× | j | |	 ƒ q6t	 | t
 ƒ rþ | j | | |	 ƒ q6| d
 |  d |	 d | ƒ } | j | ƒ n | j | ƒ | j | ƒ qL Wd d | g } t j j d | d | ƒ S(   s2   
    Export table rows for display elsewhere.
    R:   Ro   Rp   Rq   Rr   Rs   Rc   Rh   Rt   R!   R�   s   Resolution ranges   N(obs)/N(possible)t   column_headerst
   table_rowsN(   RR   R‚   R   R8   Rƒ   Rz   R<   R   R,   R„   RS   R9   t   libtbxt   table_utilst   simple_table(   R.   R�   t
   data_labelR…   t   replace_none_withRo   R†   R‡   RŒ   R:   Rˆ   t   rowR‰   t   labels(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_simple_tableí   s:    
		N(   t   __name__t
   __module__R#   R7   R;   R<   RE   RH   RJ   RK   Rb   R   Rz   R€   RŠ   R,   R”   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR!   ,   sN   							.!t   binned_datac           B   sG   e  Z d d  „ Z d e e d e e d d d d d „
 Z d d „ Z RS(   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R!   R�   R…   (   R.   R!   R�   R…   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#     s    		Rc   R{   c         C   sj   | d  k r |  j } n  |  j j d |  j d | d | d | d | d | d | d | d	 | d
 |	 d |
 ƒ S(   NR�   R…   Ro   Rp   Rq   Rr   R†   Rs   Rh   R~   R   (   R   R…   R!   RŠ   R�   (   R.   R…   Ro   Rp   Rq   Rr   R†   Rs   Rh   R~   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   show  s     	c         C   s:   | d k r |  j } n  |  j j d |  j d | d | ƒ S(   sE   
    Export table rows for display elsewhere.  (Used in Xtriage)
    R�   R�   R…   N(   R   R…   R!   R”   R�   (   R.   R�   R…   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR”   8  s     	N(   R•   R–   R   R#   R<   R˜   R”   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR—     s   c         C   s5   i  } x( t  t |  ƒ ƒ D] } | | |  | <q W| S(   N(   t   xrangeRR   (   R$   Rw   t   i(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   make_lookup_dictD  s    R4   c        	   B   s   e  Z d  Z dk d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e e e e e d „ Z dk dk d	 „ Z d
 „  Z dk d d „ Z dk e d „ Z dk d d „ Z d dk d „ Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d  „  Z# d! „  Z$ d" „  Z% d# d$ „ Z& d% „  Z' dk dk dk dk dk dk d& e d' „ Z( d( „  Z) d) „  Z* dk dk d* „ Z+ d+ „  Z, d, „  Z- d- „  Z. d. „  Z/ d/ „  Z0 d0 dk dk dk d1 „ Z1 e d0 dk dk d2 d3 „ Z2 d4 „  Z3 e dk d5 „ Z4 d6 „  Z5 d7 „  Z6 e d8 „ Z7 dk dk d9 „ Z8 d: d: d: d; „ Z9 e: d< „ Z; e: d= „ Z< e: e d> „ Z= e: d? „ Z> e: d@ „ Z? e: dA „ Z@ dB e dC „ ZA dB e dD „ ZB dE dF dG e: e dH dI dJ „ ZC dK „  ZD dE dF dG e dk e dH dI dL „ ZE dE dF e dH dI dM „ ZF e dN „ ZG dO „  ZH e: dP „ ZI e dQ „ ZJ dR „  ZK dl dk dk dk dk dT e: dU „ ZL e e dk e dV „ ZM dk e dm dk dk dk dk dk dW „ ZN dX „  ZO dk e dk dk dk dk dk dY „ ZP d: d: e d: d: dZ „ ZQ d[ d\ d] d& d^ „ ZR e: dk dk dk d_ „ ZS d: d: dk d` da „ ZT db „  ZU dc „  ZV dd „  ZW de „  ZX df „  ZY e: dg „ ZZ dk dk dk dk dk dh „ Z[ di „  Z\ dj „  Z] RS(n   s  
  Basic class for handling sets of Miller indices (h,k,l), including sorting
  and matching functions, symmetry handling, generation of R-free flags, and
  extraction of associated statistics.  Does not actually contain data, but
  this can be added using the array(...) method.
  c         C   sM   | d  t t f k s t ‚ t j j |  | ƒ | |  _ | |  _ d  |  _	 d  S(   N(
   R   R,   R<   R   R   R5   t   _copy_constructort   _indicest   _anomalous_flagt   _binner(   R.   R1   R$   R&   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#   R  s
    		c         C   s8   t  j j |  | ƒ | j |  _ | j |  _ d  |  _ d  S(   N(   R   R5   Rœ   R�   Rž   R   RŸ   (   R.   t   other(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRœ   Y  s    c         C   s   |  j  S(   sz   
    Return a reference to the internal array of indices.

    :returns: a cctbx.array_family.flex.miller_index array
    (   R�   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR$   _  s    c         C   s   |  j  S(   s6   Indicate whether the set or array is anomalous or not.(   Rž   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR&   g  s    c         C   s   |  j  ƒ  j ƒ  S(   s5   Return the number of reflections in the set or array.(   R$   R'   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR'   k  s    c         C   s   t  d |  d |  j d |  j ƒ S(   sd   
    Create a copy of the set, keeping references to the same crystal symmetry
    and indices.
    R1   R$   R&   (   R4   R�   Rž   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   copyo  s    	c         C   s�   |  j  ƒ  } | d k	 r3 t j  d | j ƒ  ƒ } n  |  j ƒ  d k rN d } n t |  j ƒ  ƒ } t d t j d | d | ƒ d |  j	 ƒ  j
 ƒ  d |  j ƒ  ƒ S(   s‡   
    Create a copy of the set, also copying the crystal symmetry and indices.

    :returns: a set object with all-new attributes.
    t
   parametersR1   R2   t   space_group_symbolR$   R&   N(   R2   R   R   R¢   R%   RS   R4   R   R5   R$   t	   deep_copyR&   (   R.   R2   R£   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¤   y  s    			c         C   s‚   | t  k r |  } n  | t  k r0 |  j ƒ  } n  | t  k rK |  j ƒ  } n  t j j | d | d | ƒ} t d | d | d | ƒ S(   s‰   
    Create a copy of the set, optionally changing the symmetry, indices,
    and/or anomalous flag (default = keep all unmodified).
    R2   R%   R1   R$   R&   (   R   R$   R&   R   R5   t   customized_copyR4   (   R.   R1   R$   R&   R2   R%   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¥   �  s    
 	  	c         C   sy   | d k	 r0 | j ƒ  |  j j ƒ  k s0 t ‚ n  | d k	 r` | j ƒ  |  j j ƒ  k s` t ‚ n  t d |  d | d | ƒ S(   sõ   
    Create an array object, given data and/or sigma arrays of identical
    dimensions to the indices array.

    :param data: a flex array (any format) or None
    :param sigmas: a flex array (any format, but almost always double) or None
    R0   R�   t   sigmasN(   R   R'   R�   R   R   (   R.   R�   R¦   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR   ¢  s
    $$c         C   sa   t  | ƒ t j k s t ‚ |  j ƒ  d  k	 s3 t ‚ t d |  d |  j ƒ  j | ƒ d |  j ƒ  ƒ S(   NR1   R$   R&   (	   R   R   R   R   R$   R   R4   R   R&   (   R.   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR   °  s    R{   c         C   sr   | d k r t j } n  | | d It |  j ƒ  ƒ IJ| | d I|  j ƒ  IJt j j |  d | d | ƒ|  S(   s   Minimal Miller set summarys   Number of Miller indices:s   Anomalous flag:R~   R   N(	   R   R|   R}   RR   R$   R&   R   R5   R€   (   R.   R~   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR€   ¸  s      c      
   C   s§  | d k	 s t ‚ |  j ƒ  } | r9 |  j ƒ  j ƒ  } n |  j ƒ  } t j ƒ  } t j ƒ  } t j ƒ  } xM t | ƒ D]? \ } }	 | j |	 d ƒ | j |	 d ƒ | j |	 d ƒ qv Wd }
 t j	 t j
 | ƒ ƒ |
 t j	 t j
 | ƒ ƒ |
 t j	 t j
 | ƒ ƒ |
 } } } |  j ƒ  j ƒ  } d } d } t | d ƒ } x^ t | ƒ D]P \ } }	 | j |	 ƒ } | | | | | d |
 | d |
 | d |
 f IJqOWd S(	   sk  
    Write out Miller indices as pseudo-waters for visualization.  Note that
    this treats the indices as literal coordinates (times a scale factor),
    and the distances between points will not correspond to the distances
    in reciprocal space.

    See cctbx/miller/display.py and crys3d/hklview for an alternative (but
    less lightweight) approach.
    i    i   i   id   s/   CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f P1        sC   HETATM%5d  O   HOH %5d    %8.3f%8.3f%8.3f  1.00  1.00           O  t   wN(   R   R   R2   t   expand_to_p1R$   R	   t   intt	   enumerateR9   RQ   t   abst   reciprocal_parameterst   opent   reciprocal_space_vector(   R.   t	   file_nameR¨   t   ucR$   t   ht   kt   lt   i_mit   mit   scalet   sht   skt   slt   rpt   c1fmtt   fmtt   oft   rsv(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   miller_indices_as_pdb_fileÀ  s,    
 2$c         C   s:  | d k r t j } n  |  j d | d | ƒ |  j ƒ  } |  j ƒ  d k	 rï | j ƒ  } |  j ƒ  j ƒ  } | j	 t
 ƒ } | | d I| IJ| d k r½ |  j d | ƒ } | | d IJn  | j ƒ  j ƒ  j	 t
 ƒ } | | d I| IJn  |  j ƒ  d k	 r‰| j ƒ  } | | d | IJ|  j ƒ  d k	 r‰|  j ƒ  j ƒ  d k r‰| r‰| j d	 d
 ƒ | j d t
 ƒ }	 |	 j }
 |
 j ƒ  d d k s–t ‚ |
 j ƒ  d d k s²t ‚ |
 j ƒ  d
 } |
 j ƒ  d
 } | d k r| d | d
 k r| | d | | IJn  | |
 j ƒ  d 7} | d k rD| | d | | IJn  |  j ƒ  r†|  j ƒ  sh|  j ƒ  r†| | d |  j ƒ  IJq†q‰n  |  j ƒ  d k	 r6| j ƒ  r6| r6| j ƒ  \ } } | | d I| j ƒ  j ƒ  IJ| | d I| j ƒ  | IJt |  t ƒ r6|  j  ƒ  r6| | d | j! ƒ  IJq6n  |  S(   s1   Display comprehensive Miller set or array summaryR~   R   s   Systematic absences:i    t	   selections.   Systematic absences not included in following:s   Centric reflections:s   Resolution range: %.6g %.6gt   n_binsi   t   use_binningi   s&   Completeness in resolution range: %.6gs&   Completeness with d_max=infinity: %.6gs0   Anomalous completeness in resolution range: %.6gs   Bijvoet pairs:s   Lone Bijvoet mates:s   Anomalous signal: %.4fN("   R   R|   R}   R€   R¡   R%   t   is_unique_set_under_symmetryt   sys_absent_flagsR�   R   R<   t   selectt   centric_flagsR2   t   resolution_rangeR$   R'   t   setup_binnert   completenessR!   R;   R   RE   R&   t   is_xray_intensity_arrayt   is_xray_amplitude_arrayt   anomalous_completenesst   match_bijvoet_matest   pairst	   n_singlesR„   R   t   is_real_arrayt   anomalous_signal(   R.   R~   R   t
   no_sys_absRÃ   RÄ   t	   n_sys_abst	   n_centrict	   d_max_mint   completeness_d_max_d_minR!   t   n_obst
   n_completet   asut   matches(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   show_comprehensive_summaryà  sd     	 

 
iô  c         C   sî   | d k r t j } n  |  j d | ƒ x¿ |  j ƒ  j ƒ  D]« } |  j ƒ  j | ƒ } |  j | ƒ } | j ƒ  \ } } | j	 d | ƒ } | j
 t ƒ }	 |  j ƒ  j d | d t d t ƒ }
 d } | | | |
 | |	 f IJ| j ƒ  q; Wd S(   s6   
    Display the completeness in resolution bins.
    t   reflections_per_bint   d_maxR:   Ro   Rr   s   %3d: %-17s %4.2f %6dN(   R   R|   R}   RÈ   R!   Rƒ   RÀ   RÅ   RÕ   RÉ   R   R<   Rz   R,   t   flush(   R.   RÜ   t   outR:   t   selt   self_selRÝ   R(   t   complt   n_reft   d_rangeR¼   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   show_completeness  s     c         C   sR   |  j  ƒ  t k s* |  j  ƒ  t k s* t ‚ |  j d t j j |  d |  j  ƒ  ƒƒ S(   NR1   R&   (   R&   R,   R<   R   R¥   R   R5   t   reflection_intensity_symmetry(   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRæ   &  s    *	c         C   sL   |  j  ƒ  } | r- | j d |  j ƒ  ƒ } n  |  j d | j |  j ƒ  ƒ ƒ S(   s„   
    Generate a boolean Miller array flagging those reflections which are
    systematically absent under the current symmetry.
    R&   R�   (   t   space_groupt(   build_derived_reflection_intensity_groupR&   R   t   is_sys_absentR$   (   R.   t   integral_onlyt   effective_group(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÄ   ,  s
    	c         C   s"   t  |  |  j ƒ  j |  j ƒ  ƒ ƒ S(   sG   
    Generate a boolean Miller array flagging centric reflections.
    (   R   Rç   t
   is_centricR$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÆ   8  s    c         C   s+   t  |  |  j ƒ  j |  j ƒ  |  j ƒ  ƒ ƒ S(   s  
    Generate a Miller array (with integer data) indicating the multiplicity of
    each unique reflection.  (If the set or array is already symmetry-unique,
    the multiplicity will be 1 for every reflection.)

    :returns: array object with flex.int data
    (   R   Rç   t   multiplicityR$   R&   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   multiplicities@  s    c         C   s"   t  |  |  j ƒ  j |  j ƒ  ƒ ƒ S(   N(   R   Rç   t   epsilonR$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   epsilonsL  s    c         C   s"   t  |  |  j ƒ  j |  j ƒ  ƒ ƒ S(   N(   R   R2   Rd   R$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRd   Q  s    c         C   s.   t  |  t j |  j ƒ  j |  j ƒ  ƒ d ƒ ƒ S(   Ni   i   g      ø?(   R   R	   t   powR2   Rd   R$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   d_star_cubedU  s    c         C   s"   t  |  |  j ƒ  j |  j ƒ  ƒ ƒ S(   sW   
    Generate a double Miller array containing the resolution d of each
    index.
    (   R   R2   Rc   R$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   d_spacingsY  s    c         C   s"   t  |  |  j ƒ  j |  j ƒ  ƒ ƒ S(   N(   R   R2   Rf   R$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   sin_theta_over_lambda_sqa  s    c         C   s(   t  |  |  j ƒ  j |  j ƒ  | | ƒ ƒ S(   s[   
    Generate a double Miller array containing the scattering angle of each
    index.
    (   R   R2   Rg   R$   (   R.   Rh   Ri   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRg   e  s    c         C   s"   t  j |  j ƒ  j |  j ƒ  ƒ ƒ S(   s;   
    High-resolution limit.
    :returns: Python float
    (   R   t   d_star_sq_as_dR2   t   max_d_star_sqR$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR(   m  s    c         C   s   |  j  ƒ  j |  j ƒ  ƒ S(   N(   R2   t   min_max_d_star_sqR$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR÷   t  s    c         C   s,   t  g  |  j ƒ  D] } t j | ƒ ^ q ƒ S(   sO   
    Low- and high-resolution limits.
    :returns: Python tuple of floats
    (   Rn   R÷   R   Rõ   (   R.   Rd   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÕ   w  s    c         C   s   t  |  j ƒ  ƒ S(   N(   t
   index_spanR$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRø     s    c         C   s"   |  j  ƒ  } | j ƒ  | j ƒ  f S(   s!   Return the range of h,k,l indices(   Rø   t   minRQ   (   R.   t   span(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   min_max_indices‚  s    c         C   s5   |  j  j | ƒ } | d k r' d } n
 | | } | S(   se  
    Returns the element `ary` coresponding to the `miller_index` if
    `miller_index exists, otherwise returns None.

    :param miller_index: Miller index as a 3-tuple
    :type miller_index: tuple
    :param ary: any array (e.g. self.data(), self.sigmas())
    :type ary: sequence (list, array, etc)
    :returns: type of contents of `ary`, or None
    N(   R�   t   first_indexR   (   R.   t   aryt   miller_indext   firstRw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   at_first_index‡  s
    	
c         C   s   |  j  j | ƒ S(   sC  
    Returns the first index of the item  matching
    `miller_index`. If the `miller_index` is not found in `self`,
    then returns ``None``.

    :param miller_index: Miller index as a 3-tuple
    :type miller_index: tuple
    :returns: int, None -- index of first occurrence of
              `miller_index` or None
    (   R�   Rü   (   R.   Rþ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRü   ™  s    c   	      C   sÈ   |  j  ƒ  \ } } t t | d ƒ | d ƒ } t t | d ƒ | d ƒ } t t | d ƒ | d ƒ } d | | | g k s„ t ‚ |  j ƒ  j ƒ  d  \ } } } d | | d | | d | | f S(   sR   
    Returns the effective resolution limits along the reciprocal space axes.
    i    i   i   i   g      ð?N(   Rû   RQ   R«   R   R   R2   R¬   (	   R.   t   min_mit   max_mit   max_ht   max_kt   max_lt   astt   bstt   cst(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   d_min_along_a_b_c_star¦  s    g{®Gáz„?c         C   s   d |  j  ƒ  d | S(   Ni   i   (   R(   (   R.   t	   tolerance(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt!   minimum_wavelength_based_on_d_min²  s    c         C   s
   |  j  ƒ  S(   s   Synonym for d_max_min().(   RÕ   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÇ   µ  s    i2   c	   	      C   sX   |  j  d |  j ƒ  j d |  j ƒ  d | d | d | d | d | d | d	 | d
 | ƒ 	ƒ S(   sž  
    Given an isotropic or anisotropic displacement or B-factor, alculate
    resolution-dependent scale factors corresponding to the indices.
    (Note that to simply apply one of the input parameters to an existing
    Miller array, you can call array.apply_debye_waller_factors)

    :param u_iso: Isotropic displacement (in Angstroms)
    :param b_iso: Isotropic B-factor (8*pi^2*u_iso^2)
    :param u_cart: Anisotropic displacement tensor
    :param b_cart: Anisotropic B-factor
    :param u_star: Anisotropic displacement tensor in fractional space
    :param u_cif: Anisotropic displacement tensor, dimensionless basis
    :returns: cctbx.miller.array object
    R�   R6   t   u_isot   b_isot   u_cartt   b_cartt   u_cift   u_start   exp_arg_limitt   truncate_exp_arg(   R   R2   t   debye_waller_factorsR$   (	   R.   R  R  R  R  R  R  R  R  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR  ¹  s    c         C   s(   |  j  d t ƒ \ } } | j ƒ  j ƒ  S(   s#   Return the number of Bijvoet pairs.t#   assert_is_unique_set_under_symmetry(   RÍ   R,   RÎ   R'   (   R.   RÙ   RÚ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   n_bijvoet_pairsØ  s    	c         C   s   t  d |  d |  j ƒ  d t ƒ S(   sg   
    Return a copy of the set using the same indices but with the anomalous flag
    set to false.
    R1   R$   R&   (   R4   R$   R,   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_non_anomalous_setÞ  s    c         C   sÉ   | | g j  d ƒ d k s! t ‚ |  j ƒ  j ƒ  d k rB t } nh | d k	 rw d |  j ƒ  |  j ƒ  j ƒ  | k } n3 | d k	 r˜ |  j ƒ  | k } n |  j ƒ  d k } t d |  d |  j ƒ  d | ƒ S(   sÍ   
    Set the anomalous flag automatically depending on whether the data
    contain Bijvoet pairs (optionally given minimum cutoffs).

    :returns: a copy of the set with (maybe) a new anomalous flag
    i    i   R1   R$   R&   N(   R   R   R   R$   R'   R,   R  R4   (   R.   t   min_n_bijvoet_pairst   min_fraction_bijvoet_pairsR&   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   auto_anomalousè  s    !	c         C   s4   t  j d |  j ƒ  j ƒ  d |  j ƒ  d |  j ƒ  ƒ S(   sG   
    Determine whether the indices in the set are symmetry-unique.
    t   space_group_typeR&   R6   (   R"   RÃ   R%   R   R&   R$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÃ   ÿ  s    	c         C   s4   t  j d |  j ƒ  j ƒ  d |  j ƒ  d |  j ƒ  ƒ S(   NR  R&   R6   (   R"   t   unique_under_symmetry_selectionR%   R   R&   R$   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR    s    	c         C   s;   |  j  ƒ  } | j ƒ  |  j ƒ  j ƒ  k r. |  S|  j | ƒ S(   N(   R  R'   R$   RÅ   (   R.   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   unique_under_symmetry  s     c         C   s   |  j  ƒ  j ƒ  j |  j ƒ  ƒ S(   së   
    Indicate whether the array is entirely contained within the reciprocal
    space asymmetric unit (ASU).  Warning: this calls map_to_asu internally,
    so it is better to simply call map_to_asu without checking in many cases.
    (   t
   map_to_asuR$   t   all_eq(   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt	   is_in_asu  s    c         C   se   |  j  ƒ  j ƒ  } |  j ƒ  } | d k r3 t } n  t |  j ƒ  j ƒ  | | ƒ t |  | |  j ƒ  ƒ S(   sµ   
    Convert all indices to lie within the canonical asymmetric unit for the
    current space group (while preserving anomalous flag).  Required for many
    downstream steps.
    N(	   R$   R¤   R&   R   R<   R  R%   R   R4   (   R.   Rš   R&   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR    s    	g�íµ ÷Æ°>c      	   C   s+  |  j  ƒ  t t f k s t ‚ |  j ƒ  j ƒ  d k r[ t d |  d |  j  ƒ  d t j ƒ  ƒ S| d	 k	 r† t
 d |  d |  j  ƒ  d | ƒ S| d	 k } | r§ |  j ƒ  } n  | } | d	 k	 rÊ | d | 9} n  t
 d |  d |  j  ƒ  d | d | ƒ } | r#| j | j ƒ  j ƒ  | d t k ƒ } n  | Sd	 S(
   s]  
    Generate the complete set of Miller indices expected for the current
    symmetry, excepting systematic absences.

    :param d_min_tolerance: tolerance factor for d_min (avoid precision errors)
    :param d_min: High-resolution limit (default = d_min of current set)
    :param d_max: Low-resolution limit (default = d_max of current set)
    i    R1   R&   R$   t	   max_indexi   R(   RÝ   N(   R&   R,   R<   R   R$   R'   R4   R	   Rþ   R   R=   R(   RÅ   Ró   R�   t   fp_eps_double(   R.   RB   R(   RÝ   R!  t   d_min_was_nonet   d_min_exactRw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRC   ,  s4    
  	&i   c   
      C   s  | d k s t  ‚ | sf |  j d | d | ƒ } t |  j ƒ  j ƒ  t d | j ƒ  j ƒ  ƒ d ƒ | S|  j ƒ  d
 k	 s~ t  ‚ g  } xf t |  j ƒ  j	 ƒ  |  j ƒ  j
 ƒ  ƒ D]= \ } }	 |	 d k rÔ | j | ƒ q¬ | j | | |	 ƒ q¬ Wt d |  j ƒ  d | d d	 ƒ S(   sµ  
    Calculate the (fractional) completeness of the array relative to the
    theoretical complete set, either overall or in resolution bins.  By default
    the current low-resolution limit will be used.

    :param d_min_tolerance: tolerance factor for d_min (avoid precision errors)
    :param d_max: Low-resolution limit (default = d_max of current set)
    :param multiplier: Factor to multiply the result by (usually 1 or 100)
    i    RB   RÝ   i   g      ð?R!   R�   R…   s   %5.3fN(   R   RC   Rù   R$   R'   RQ   R!   R   t   zipR;   RE   R9   R—   (
   R.   RÂ   RB   t   return_failRÝ   t
   multiplierRC   R�   t   n_givenRØ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÉ   P  s    	+ c         C   s   t  j |  j ƒ  j ƒ  t ƒ S(   N(   R	   t   boolR$   R'   R<   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   all_selectioni  s    c         C   sh   |  j  ƒ  d k	 s t ‚ | d k r3 |  j ƒ  } n  | rC | } n  |  j  ƒ  j | ƒ } t |  | | ƒ S(   s  
    Select a subset of reflections.

    :param selection: flex.bool or flex.size_t selection
    :param negate: select the inverse of the selection array
    :param anomalous_flag: anomalous flag for the new set
    :returns: a new set with a subset of indices
    N(   R$   R   R   R&   RÅ   R4   (   R.   RÀ   t   negateR&   Rš   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÅ   l  s    	 
c         C   s   |  j  |  j ƒ  j ƒ  ƒ S(   sl   
    Select only acentric reflections.

    :returns: A Miller set or array (depending on object type).
    (   RÅ   RÆ   R�   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR>   |  s    c         C   s   |  j  |  j ƒ  j ƒ  ƒ S(   sk   
    Select only centric reflections.

    :returns: A Miller set or array (depending on object type).
    (   RÅ   RÆ   R�   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR?   „  s    c         C   s#   |  j  d |  j ƒ  j ƒ  d | ƒ S(   NRÀ   R+  (   RÅ   RÄ   R�   (   R.   R+  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   remove_systematic_absencesŒ  s    	c         C   s¤   |  j  ƒ  } |  j ƒ  j ƒ  } | j d ƒ s3 t ‚ t j | ƒ } | d k	 rq | d k rq | | d | k M} n  | d k	 r  | d k r  | | d | k M} n  | S(   se   
    Obtain the selection (flex.bool array) corresponding to the specified
    resolution range.
    i    i   N(   R*  Rd   R�   t   all_geR   R	   t   sqrtR   (   R.   RÝ   R(   Rw   Rd   t   d_star(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   resolution_filter_selection‘  s      i    c         C   s(   |  j  d |  j d | d | ƒ d | ƒ S(   sû   
    Select a subset within the indicated resolution range.

    :param d_max: Low-resolution cutoff
    :param d_min: High-resolution cutoff
    :param negate: Select outside this range instead
    :returns: set or array depending on object type
    RÀ   RÝ   R(   R+  (   RÅ   R0  (   R.   RÝ   R(   R+  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   resolution_filterž  s    		c         C   sU   | r |  j  | ƒ s t ‚ n  |  j ƒ  | j ƒ  k s< t ‚ t |  j ƒ  | j ƒ  ƒ S(   N(   t   is_similar_symmetryR   R&   t   match_indicesR$   (   R.   R    t   assert_is_similar_symmetry(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR3  «  s    c         C   s4   | j  d |  d | ƒ j ƒ  } |  j | j d ƒ ƒ S(   sØ   
    Match the indices in the current set and another set, and return a set
    (or array) containing only those reflections present in both.  Assumes that
    both sets are already in the asymmetric unit (ASU).
    R    R4  i   (   R3  RÎ   RÅ   t   column(   R.   R    R4  RÎ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   common_set±  s    	c         C   sn   | j  d |  d | ƒ } | r4 | j ƒ  s4 t ‚ n  | j ƒ  } |  j | j d ƒ ƒ | j | j d ƒ ƒ g S(   sn   
    Like common_set(other), but returns a tuple containing matching copies of
    both sets (or arrays).
    R    R4  i   i    (   R3  t   have_singlesR   RÎ   RÅ   R5  (   R.   R    R4  t   assert_no_singlesRÚ   RÎ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   common_sets¼  s    		c         C   s(   |  j  | j d |  d | ƒ j d ƒ ƒ S(   sá   
    Match the indices in the current set and another set, and return a set
    (or array) containing reflections which are present only in the current
    set.  Assumes that both sets are already in the asymmetric unit.
    R    R4  i   (   RÅ   R3  t   singles(   R.   R    R4  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   lone_setÍ  s    c         C   sF   | j  d |  d | ƒ } |  j | j d ƒ ƒ | j | j d ƒ ƒ g S(   sq   
    Like lone_set(other), but returns a tuple containing the reflections
    unique to each set (or array).
    R    R4  i   i    (   R3  RÅ   R:  (   R.   R    R4  RÚ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt	   lone_sets×  s
    		c         C   s¦   |  j  ƒ  d t f k s t ‚ |  j ƒ  d k	 s6 t ‚ |  j ƒ  d k	 r~ |  j ƒ  } t | j ƒ  j ƒ  | j ƒ  d | ƒ} n |  } t | j ƒ  d | ƒ} | | f S(   s‘   
    Group Bijvoet mates (or Friedel mates) together, returning an object that
    allows enumeration over matching pairs and/or singletons.
    R  N(	   R&   R   R<   R   R$   R%   R  RÍ   R   (   R.   R  RÙ   RÚ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÍ   â  s    	t
   resolutionc   	      C   s†  | d	 k s t  ‚ | t t g k s* t  ‚ | d k ra t j d |  j ƒ  j |  j ƒ  ƒ d | ƒ S| d k rQ|  j ƒ  j ƒ  } t	 |  j
 ƒ  j ƒ  t | ƒ |  j ƒ  j ƒ  } t	 |  j
 ƒ  j ƒ  t | ƒ |  j ƒ  j ƒ  } | | k } t j |  j ƒ  j ƒ  d ƒ } | j | j ƒ  d ƒ t | ƒ j | ƒ j ƒ  | } t j d | d | ƒ St j d t |  j ƒ  ƒ j |  j ƒ  ƒ d | ƒ Sd S(
   sÿ   
    Generate the selection array (flex.size_t object) to reorder the array
    by resolution or Miller index.

    :param by_value: sort type, must be "resolution" or "packed_indices"
    :param reverse: invert order
    :returns: flex.size_t object
    R=  t   packed_indicest   asu_indicesR�   t   reversei    g{®Gáz„?N(   R=  R>  s   asu_indices(   R   R,   R<   R	   t   sort_permutationR2   Rd   R$   R¤   R  R%   R   RÆ   R�   t   doubleR'   t   set_selectedt
   iselectionRø   t   packt	   as_double(	   R.   t   by_valueR@  R?  t   asu_indices_anomRÆ   t   friedel_mate_flagst   offsetR�   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRA  õ  s$    		"	c         C   s   |  j  |  j d | d | ƒ ƒ S(   ss   
    Reorder reflections by resolution or Miller index.

    :param by_value: 'resolution' or 'packed_indices'
    RG  R@  (   RÅ   RA  (   R.   RG  R@  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   sort  s    gš™™™™™¹?iÐ  g      @i   t   cnsc         C   s�   | d k s t  ‚ | r- | d k s- t  ‚ n  | s[ |  j d | d | d | d | d	 | ƒ S|  j d | d | d
 | d | d | d	 | ƒ Sd S(   sË  
    Create an array of R-free flags for the current set, keeping anomalous
    pairs together.  Requires that the set already be unique under symmetry,
    and generally assumes that the set is in the ASU.

    :param fraction: fraction of reflections to flag for the test set
    :param max_free: limit on size of test set, overrides fraction
    :param lattice_symmetry_max_delta: limit on lattice symmetry calculation
    :param use_lattice_symmetry: given the current symmetry, determine the     highest possible lattice symmetry and generate flags for that symmetry,     then expand to the current (lower) symmetry if necessary.  This is almost     always a good idea.
    :param use_dataman_shells: generate flags in thin resolution shells to     avoid bias due to non-crystallographic symmetry.
    :param n_shells: number of resolution shells if use_dataman_shells=True
    :param format: convention of the resulting flags.  'cns' will return a     boolean array (True = free), 'ccp4' will return an integer array from     0 to X (0 = free, X dependent on fraction), 'shelx' will return an     integer array with values 1 (work) or -1 (free).

    :returns: a boolean or integer Miller array, depending on format.
    RL  t   ccp4t   shelxi    t   fractiont   max_freet   use_dataman_shellst   n_shellst   formatt	   max_deltaN(   RL  RM  RN  (   R   t   generate_r_free_flags_basict)   generate_r_free_flags_on_lattice_symmetry(   R.   RO  RP  t   lattice_symmetry_max_deltat   use_lattice_symmetryRQ  RR  RS  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   generate_r_free_flags  s    c         C   s"   t  j d |  j ƒ  d |  j ƒ  ƒ S(   s{   Get crystal symmetry of the miller set

    :returns: a new crystal.symmetry object
    :rtype: cctbx.crystal.symmetry
    R2   R%   (   R   R5   R2   R%   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR1   N  s    	c	         C   s�  |  j  ƒ  j ƒ  }	 |	 d k r- t d ƒ ‚ n  |	 }
 |  j ƒ  rn |  j ƒ  d } | j ƒ  j ƒ  | j ƒ  }
 n  |  j ƒ  s€ t ‚ | d k	 rÞ | d k o¡ | d k  s· t d d ƒ ‚ n  | d k sÉ t ‚ | t
 k sÞ t ‚ n  | d k	 r@| d k	 sü t ‚ t |
 | | ƒ t |
 ƒ } | d k s+t ‚ | t
 k s@t ‚ n  | rŒ| sSt ‚ | d k set ‚ | d k swt ‚ | d k sŒt ‚ n  |  j ƒ  } |  j | ƒ } t j | j ƒ  d | ƒ} t j d | j ƒ  d	 | d
 t
 ƒ } | j ƒ  j d | d t j | j  ƒ  j ƒ  d ƒ ƒ j ƒ  } | j ƒ  j ƒ  } | j ƒ  } | j  ƒ  j ƒ  } | j  ƒ  j ƒ  } d } | sÑ| r¶| d k r•t d d ƒ ‚ n  t j d | d | d | ƒ } qOt j | | d | ƒ} n~ t j ƒ  } t | | ƒ d } x? t  | ƒ D]1 } t j! | ƒ } t j" | ƒ } | j# | ƒ qþWt j t$ | d | !ƒ ƒ } | j  ƒ  } | j% d t j" d | j ƒ  j& | ƒ d t' ƒ d t' ƒ } | j d | d d ƒ } | j( ƒ  } | j d t j d | j ƒ  d	 | j) ƒ  ƒ ƒ } | j ƒ  j ƒ  } |  j ƒ  r| j* ƒ  } n  | j | j+ ƒ  ƒ j ƒ  } | j, |  j ƒ  ƒ } | j d |  j  ƒ  d | j- ƒ  ƒ } | j, |  ƒ } | j  ƒ  j. |  j  ƒ  ƒ s™t ‚ | S(   s¯  
    Generate R-free flags by converting to the highest possible lattice
    symmetry (regardless of intensity symmetry), creating flags, and expanding
    back to the original symmetry.  This is a safeguard against reflections
    that are correlated due to twinning being split between the work and test
    sets.

    This method should usually not be called directly, but rather through
    set.generate_r_free_flags(...).
    i    s9   An array of size zero is given for Free R flag generationi   g      à?s6   R-free flags fraction must be greater than 0 and less s	   than 0.5.RT  R2   Rç   t   assert_is_compatible_unit_cellR1   R�   RM  s5   CCP4 convention not available when generating R-free s   flags in resolution shells.t   n_reflt   fraction_freeRÁ   RS  R$   R@  R¦   N(/   R$   R'   R   R&   RÍ   RÎ   RÏ   RÃ   R   R   R,   Rù   t   floatt!   change_of_basis_op_to_niggli_cellt   change_basisR   t   groupR2   R   R5   R   R¥   R	   RB  R  t   merge_equivalentst   average_bijvoet_matesR   t   assign_r_free_flags_by_shellst   assign_random_r_free_flagst   size_tR©   R™   t   random_doubleRA  t   extendt   listRÅ   Rd   R<   R¨   Rç   t   generate_bijvoet_matest   inverseR6  R�   R  (   R.   RO  RP  RT  t   return_integer_arrayt   n_partitionsRQ  RR  RS  t
   n_originalt	   n_non_anoRÚ   t   cb_op_to_nigglit   tmp_mat   lattice_groupt
   lattice_xst	   tmp_flagst   n_non_ano_lat_symR`   Rw   t   n_timest   iit   tmpR$   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRV  X  s¢    
		'							!c         C   sæ  | d k o | d k  s+ t  d d ƒ ‚ n  | rP | d k  rP t  d d ƒ ‚ n  | d k	 r{ | d k r{ t  d d	 ƒ ‚ n  |  j ƒ  rõ |  j ƒ  d
 } | j d ƒ } | j d ƒ } | j d ƒ }	 | j d ƒ }
 | j ƒ  j ƒ  | j ƒ  } ~ n$ |  j	 ƒ  st
 ‚ |  j ƒ  j ƒ  } | d k	 rDt | | t d
 | ƒ ƒ } n  | rŠ| d k rit  d d ƒ ‚ n  t j d | d | d | ƒ } n t j d | d | d | ƒ } |  j ƒ  sÃ|  j ƒ  } ne |  j ƒ  j | ƒ } | j |  j ƒ  j |	 ƒ ƒ | j |  j ƒ  j |
 ƒ ƒ | j ƒ  | k s(t
 ‚ | j d t j d |  j ƒ  j | ƒ d t ƒ d t ƒ } |  j ƒ  s}|  j d | ƒ S~ | d k r³d } t j |  j ƒ  j ƒ  d
 ƒ } nW | d k ræd } t j |  j ƒ  j ƒ  d
 ƒ } n$ t } t j |  j ƒ  j ƒ  t ƒ } | j ƒ  } | |	 j ƒ  } | |  } | j | | ƒ | j | ƒ | j | ƒ k sdt
 ‚ | j | | ƒ | j | ƒ d | j | ƒ k sœt
 ‚ ~ ~ ~ | j |	 | | | !ƒ ~	 | j |
 | | ƒ ~
 |  j d | ƒ S(   sº   
    Generate R-free flags, without taking lattice symmetry into account (not
    recommended).  Should not normally be called directly - use
    generate_r_free_flags(...) instead.
    i    g      à?s6   R-free flags fraction must be greater than 0 and less s	   than 0.5.i   s9   You must use at least 5 resolution shells when assigning s   R-free flags this way.s6   The maximum number of free reflections must either be s   None, or a positive number.i   t   +RM   RM  s5   CCP4 convention not available when generating R-free s   flags in resolution shells.R[  R\  RÁ   RS  R$   R�   R@  RN  iÿÿÿÿi   N(   R   R   R&   RÍ   t   pairs_hemisphere_selectionR:  RÎ   R'   RÏ   RÃ   R   R$   Rù   RQ   R   Rc  Rd  RÅ   Rg  R	   RA  R2   Rd   R<   R   R©   R)  R,   RC  R   (   R.   RO  RP  RQ  RR  RS  RÚ   t   sel_ppt   sel_pmt   sel_spt   sel_smR`   Rw   R$   t   test_flag_valuet   result_fullt   i_ppt   i_pp_spt   r_pp(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRU  Ë  sŠ    						!!
$(c      	   C   st   t  j d |  j ƒ  ƒ d } | r/ | d 9} n | d t j 9} |  j d |  j ƒ  j d |  j ƒ  d | d | ƒ ƒ S(	   NR'   g      à?ih  i   R�   R6   t   phasesRi   (	   R	   Rf  R'   t   matht   piR   Rç   t   nearest_valid_phasesR$   (   R.   Ri   t   random_phases(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt0   random_phases_compatible_with_phase_restrictions!  s     c         C   sX   t  | t ƒ r! t j | ƒ } n  t j |  d t j j |  | ƒ d | j	 |  j
 ƒ  ƒ ƒS(   s&  Get a transformation of the miller set with a new basis specified by cb_op

    :param cb_op: object describing the desired transformation of the basis
    :type cb_op: string or sgtbx.change_of_basis_operator

    :returns: a new miller set with the new basis
    :rtype: cctbx.miller.set
    R1   R$   (   R„   RS   R   t   change_of_basis_opR4   R¥   R   R5   R_  t   applyR$   (   R.   t   cb_op(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR_  *  s
    	 c      	   C   sy   |  j  ƒ  d  k	 s t ‚ |  j ƒ  d  k	 s0 t ‚ |  j ƒ  d  k	 sH t ‚ t d |  j ƒ  d |  j ƒ  d |  j ƒ  d | ƒ S(   NRç   R&   R$   t   build_iselection(   R%   R   R   R$   R&   t   expand_to_p1_iselectionRç   (   R.   RŒ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR�  8  s    c         C   sS   |  j  d | ƒ } t d |  j ƒ  d | j d |  j ƒ  ƒ } | rO | | j f S| S(   sæ   Get a transformation of the miller set to spacegroup P1

    :returns: a new set of parameters (symmetry, miller indices, anomalous_flag) in spacegroup P1
    :rtype: set(cctbx.crystal.symmetry, cctbx.miller.indices, boolean)
    RŒ  R1   R$   R&   (   R�  R4   t   cell_equivalent_p1R$   R&   RD  (   R.   t   return_iselectiont   proxyRw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¨   B  s    	c         C   s7   |  j  ƒ  t k s t ‚ t j |  d t j j |  ƒ ƒS(   NR1   (   R&   R,   R   R4   R¥   R   R5   t   patterson_symmetry(   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR‘  Q  s    g      @i   c         C   ss   | d
 k r' | d
 k r' |  j ƒ  } n  t j d |  j ƒ  d | d | d | d | d |  j ƒ  d | d | d	 | ƒ 	S(   s×   
    Calculate real-space grid for FFT given array crystal symmetry, d_min, and
    desired resolution-dependent spacing.  The actual grid dimensions will be
    adjusted to suit the needs of the FFT algorithm.
    R2   R(   t   resolution_factort   stept   symmetry_flagsR%   t   mandatory_factorst	   max_primet   assert_shannon_samplingN(   R   R(   R   t   crystal_griddingR2   R%   (   R.   R’  R(   t	   grid_stepR”  R•  R–  R—  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR˜  V  s     	c   
      C   sb  | j  ƒ  d k r0 | j ƒ  d k r0 | j ƒ  s6 t ‚ t | t j ƒ rW | j ƒ  } n  t | t j ƒ s� t | t j	 ƒ s� t ‚ | t
 t f k s™ t ‚ t | t j ƒ rBt j | j ƒ  ƒ } | j ƒ  s*| sÙ t ‚ | j ƒ  | j ƒ  k s÷ t ‚ t j | t j | j ƒ  ƒ j | j ƒ  ƒ ƒ } ql| sl| j ƒ  } qln* | sW| j ƒ  } n  t j | j ƒ  ƒ } | j | ƒ } | r¹|  j ƒ  j ƒ  t j | j ƒ  ƒ j ƒ  } | | 9} n  | d
 k rÔ|  j ƒ  } n  | rt j  j! d |  j" ƒ  d | d |  j# ƒ  d | d t ƒ } n- t j  j! d | d |  j# ƒ  d | d t ƒ } | j$ ƒ  }	 t% d |  d	 |	 ƒ S(   s  
    Run FFT on a real-space map to calculate structure factors corresponding to
    the current set of Miller indices.

    :param map: flex.double map with 3D flex.grid accessor
    :param in_place_fft: perform the FFT in place instead of creating a copy of
      the map first
    :param use_scale: perform volume-scaling using current unit cell
    :param anomalous_flag: determines anomalous_flag for output array
    :param use_sg: use space-group symmetry
    :returns: array with same Miller indices and complex_double data
    i    i   Rç   R&   R6   t   complex_mapt   conjugate_flagR0   R�   N(&   t   focus_size_1dt   ndt
   is_0_basedR   R„   R	   R©   RF  RB  t   complex_doubleR,   R<   R
   t   real_to_complex_3dt   focust	   is_paddedt   n_realR   R¡   t   gridt   m_realt	   set_focusR¤   t   complex_to_complex_3dt   forwardR2   t   volumeR   t   colt   productR   R&   t   structure_factorst   from_mapRç   R$   R�   R   (
   R.   t   mapt   in_place_fftt	   use_scaleR&   t   use_sgt   fftR¶   R­  R�   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   structure_factors_from_mapn  sJ    6 *3	c
         C   s�   d d l  m }
 | d k r; |
 j j d | d |  d | ƒ S|
 j j d |  d | d | d | d	 | d
 | d | d |	 ƒ d | d |  d | ƒ S(   s¦  
    Calculate structure factors for an :py:class:`cctbx.xray.structure` object
    corresponding to the current set of Miller indices.  Can use either FFT
    or direct summation.

    :param xray_structure: :py:class:`cctbx.xray.structure` object
    :param algorithm: switch method to calculate structure factors - can be
      'direct' or 'fft'
    :returns: array with same Miller indices and complex_double data
    iÿÿÿÿ(   t   xrayt   directt   xray_structureR0   t   cos_sin_tablet   grid_resolution_factort   quality_factort   u_baset   b_baset   wing_cutofft   exp_table_one_over_step_sizet	   algorithm(   t   cctbxR´  R¬  t   from_scatterers_directt   from_scatterers(   R.   R¶  R¾  R·  R¸  R¹  Rº  R»  R¼  R½  R´  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt!   structure_factors_from_scatterers£  s$    	c   	      C   sÌ   d d l  m } t j ƒ  } t ƒ  } xF | j ƒ  D]8 \ } } | j | j j | ƒ j	 ƒ  ƒ | j | ƒ q2 Wt
 j d | d | d | j d | j d |  j ƒ  d |  j ƒ  d	 |  j ƒ  ƒ j } t |  | ƒ S(
   sß    A miller.array whose data N(h) are the normalisations to convert
    between E's and F's:
    E(h) = F(h) / N(h)
    The argument wilson_plot shall feature attributes
    - wilson_intensity_scale_factor
    - wilson_b
    iÿÿÿÿ(   t   eltbxt   form_factorsRî   t   wilson_intensity_scale_factort   wilson_bR$   R2   Rç   (   R¿  RÃ  R	   RB  t   shared_gaussian_form_factorst   itemsR9   t   xray_scatteringt   wk1995t   fetchR"   t   amplitude_normalisationRÅ  RÆ  R$   R2   Rç   t   normalisationsR   (	   R.   t   asu_contentst   wilson_plotRÃ  Rî   t	   gaussianst   chemical_typet
   multiplicyR�   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   amplitude_normalisationsÉ  s     				c
   
      C   sR   |  j  d | d |  j d | d | d | d | d | d | d	 | d
 |	 ƒ j ƒ  ƒ S(   Nt   f_obs_factort   f_calcR¶  R¾  R·  R¹  Rº  R»  R¼  R½  (   t   f_obs_minus_f_calcRÂ  RÕ  (
   R.   RÔ  R¶  t   structure_factor_algorithmR·  R¹  Rº  R»  R¼  R½  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt!   f_obs_minus_xray_structure_f_calcã  s    		c         C   s  | s$ | d k s$ | d k s$ t  ‚ | sH | d k sH | d k sH t  ‚ | rÊ | d k rc d } n  | d k rx d } n  t t |  j ƒ  ƒ | d ƒ } | | k ró t t |  j ƒ  ƒ | d ƒ } qó n) | ró t t |  j ƒ  ƒ | d ƒ } n  | d k st  ‚ |  j ƒ  d k	 st  ‚ |  j ƒ  j ƒ  d k sG| d k sGt  ‚ |  j d t |  j ƒ  | |  j ƒ  | | ƒ ƒ |  j	 ƒ  S(   s`   
    Create internal resolution binner object; required for many other methods
    to work.
    i    iÈ   i   g      à?R/   N(
   R   R©   RR   R$   R2   R   R'   RÂ   R/   R!   (   R.   RÝ   R(   t   auto_binningRÜ   RÁ   t	   n_per_bin(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÈ   ÷  s$    $$ 	 	 &#*	%id   g-Cëâ6?i   c            s«  | d k s t  ‚ | |  j ƒ  j ƒ  k sF | d |  j ƒ  j ƒ  k re t j |  j ƒ  j ƒ  t ƒ g S|  j ƒ  j ƒ  j ƒ  } d t j	 | ƒ } t j
 | ƒ ‰  ˆ  d ‰ ˆ  | ‰ ˆ  | d } |  j ƒ  j ƒ  } | ˆ ‰ ‡  ‡ ‡ ‡ f d †  }	 |	 ƒ  }
 t |
 ƒ | k r<ˆ  t ˆ  ƒ d ˆ | d ‰ |	 ƒ  }
 n  g  } x  t |
 ƒ D]’ \ } } | t |
 ƒ d k  rœ| |
 | d } } | j | | g ƒ qO| t |
 ƒ d k rO|
 | d |
 | } } | j | | g ƒ qOqOWg  } x· t | ƒ D]© \ } } | \ } } | d k r?| | | k } | | | k M} nU | t | ƒ d k rx| | k } | | | | k M} n | | k } | | | k M} | j | ƒ qøW| t | ƒ d } | t | ƒ d } | j t ƒ | j t ƒ d k  r| t | ƒ d  } | j | | Bƒ | } n  g  } x{ t | ƒ D]m \ } } | j t ƒ | k  r�t | ƒ d d k r�| t | ƒ d | B| t | ƒ d <q0| j | ƒ q0W| } | S(   s‹   
    Create resolution bins on a logarithmic scale.  See Urzhumtsev et al.
    (2009) Acta Crystallogr D Biol Crystallogr. 65:1283-91.
    i   i   g      ð?i    c             s¹   t  j d t  j ˆ ƒ ƒ g }  ˆ } xL | t j ˆ  ƒ k rs t  j d t  j | ƒ ƒ } |  j | ƒ | ˆ 7} q( Wt t j ˆ  ƒ | ƒ } t  j d t  j | ƒ ƒ } |  j | ƒ |  S(   Ni   (   R„  R.  t   expR	   RQ   R9   Rù   (   R3   t   lnss_minRc   (   t   lnsst   s0t   s1R“  (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   get_limits#  s    i   (   R   R$   R'   R	   R)  R<   RK  Ró   R�   t   pow2t   logRR   Rª   R9   R   (   R.   t&   n_reflections_in_lowest_resolution_bint   epst   max_number_of_binst   min_reflections_in_bint   d_spacings_sortedt   sst   s2Ró   Rà  R3   RÎ   Rš   Rc   t   d1t   d2t
   selectionst   pRÝ   R(   Rà   R¹   t   spt   new_selectionst   new_selt   si(    (   RÝ  RÞ  Rß  R“  sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   log_binning  sd    


	 "	+)c         C   sß   | s | d  k	 s t ‚ | s0 | d  k	 s0 t ‚ | d k sN | d  k sN t ‚ | rŸ |  j ƒ  j ƒ  } t j | ƒ } t j | ƒ } ~ | d  k rŸ d } qŸ n  | d k s± t ‚ |  j d t |  j	 ƒ  |  j
 ƒ  | | | ƒ ƒ S(   Ni    gü©ñÒMbp?g        R/   (   R   R   Ró   R�   R	   Rù   RQ   RÂ   R/   R2   R$   (   R.   RÙ  RÝ   R(   t   d_star_sq_stepRó   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   setup_binner_d_star_sq_stepW  s     	g»½×Ùß|Û=c         C   sv  | d k s t  ‚ | d k s$ t  ‚ t | t ƒ s9 t  ‚ | d k sK t  ‚ | d k s] t  ‚ | d k  so t  ‚ |  j ƒ  j ƒ  } | d k r­ | j | d | d k ƒ } n  | d k rÙ | j | d | d k  ƒ } n  | j ƒ  d k sñ t  ‚ t d t | j ƒ  t	 | ƒ ƒ ƒ } | j ƒ  t	 | ƒ } | j t
 j | ƒ ƒ } t
 j ƒ  } | j | d ƒ | d k r�| j d | d d | ƒ n" | j t d | d d | ƒ ƒ | j ƒ  d } xP t d | ƒ D]? }	 t |	 | ƒ }
 | j | |
 d | ƒ |
 | k rÏPqÏqÏW| d k r>| j d | d d | ƒ n | j | d d | ƒ |  j d t |  j ƒ  | ƒ ƒ S(   Ni    g      à?g      ð?i   i   iÿÿÿÿR/   (   R   R„   R©   Rd   R�   RÅ   R'   RQ   R   R]  R	   RA  RB  t   reserveR9   R™   RÂ   R/   R2   (   R.   RÝ   R(   RÜ   t   d_toleranceRd   RÁ   R3   t   mR:   Rš   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   setup_binner_counting_sortedm  s<      % "  c         C   s   |  j  S(   sU   
    Return a reference to the current resolution binner (or None if undefined).
    (   RŸ   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR!   ’  s    c         C   s   t  | |  ƒ |  _ |  j S(   s|   
    Use the resolution binning of the specified binner object (does not need
    to be from an identically sized set).
    (   R!   RŸ   (   R.   R/   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÂ   ˜  s    c         C   s   |  j  d | j ƒ  ƒ S(   sp   
    Use the resolution binning of the specified set (does not need to be an
    identical set of indices).
    R/   (   RÂ   R!   (   R.   R    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   use_binning_of   s    c         C   s4   |  j  ƒ  j | j  ƒ  ƒ s! t ‚ | j |  _ |  j S(   sQ   
    Use the exact binner of another set, which must have identical indices.
    (   R$   R  R   RŸ   (   R.   R    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   use_binner_of§  s    !c         C   s   d  |  _ d  S(   N(   R   RŸ   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   clear_binner¯  s    c         C   sm   | r |  j  | ƒ s t ‚ n  |  j ƒ  | j ƒ  k s< t ‚ t d |  d |  j j | j ƒ  ƒ d |  j ƒ  ƒ S(   su   
    Combine two Miller sets.  Both must have the same anomalous flag, and
    similar symmetry is also assumed.
    R1   R$   R&   (   R2  R   R&   R4   R�   t   concatenateR$   (   R.   R    R4  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRü  ²  s    c      	   C   sÓ   | d  k	 r9 | d  k s t ‚ d d d g j | ƒ } n  | d  k	 r‡ | d  k r] | d  k sc t ‚ t d |  j ƒ  d | d | ƒ } n? d  | | g k sŸ t ‚ t d |  j ƒ  d | d | d | ƒ } |  j | ƒ S(	   NR±   R²   R³   R$   t
   slice_axist   slice_indext   slice_startt	   slice_end(   R   R   t   indext   simple_sliceR$   t   multi_sliceRÅ   (   R.   t   axist
   axis_indexRþ  Rÿ  R   RÀ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   slice¿  s     	c         C   s7   t  | ƒ d k s t ‚ |  j ƒ  | k } |  j | ƒ S(   sA   
    Remove all reflections with the specified Miller index.
    i   (   RR   R   R$   RÅ   (   R.   t   hklt   sele(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   delete_index×  s    c         C   sX   t  j |  j ƒ  j ƒ  t ƒ } x* | j ƒ  D] } | |  j ƒ  | k M} q+ W|  j | ƒ S(   s]   
    Delete multiple reflections, as specified by the Miller indices of
    another set.
    (   R	   R)  R$   R'   R<   RÅ   (   R.   R    R  R  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   delete_indicesß  s    NgUUUUUUÕ?gUUUUUUÕ?(^   R•   R–   t   __doc__R   R#   Rœ   R$   R&   R'   R¡   R¤   R   R¥   R   R   R€   R,   R¿   RÛ   Rå   Ræ   RÄ   RÆ   Rî   Rð   Rd   Rò   Ró   Rô   Rg   R(   R÷   RÕ   Rø   Rû   R   Rü   R	  R  RÇ   R  R  R  R  RÃ   R  R  R   R  RC   RÉ   R*  RÅ   R>   R?   R,  R0  R1  R<   R3  R6  R9  R;  R<  RÍ   RA  RK  RY  R1   RV  RU  Rˆ  R_  R�  R¨   R‘  R˜  R³  RÂ  RÓ  RØ  RÈ   Rò  Rô  Rø  R!   RÂ   Rù  Rú  Rû  Rü  R  R	  R
  (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR4   J  s4  					
		 4																			
								#			
 
)	lQ		
	5	G!						c         C   s¾   | d k	 r` | | g j d ƒ d k s- t ‚ t |  t |  j ƒ  j ƒ  | | ƒ j ƒ  | ƒ } nZ t |  t |  j ƒ  |  j ƒ  j ƒ  | | ƒ j ƒ  | ƒ } | d k	 rº | j	 d | ƒ } n  | S(   s¸  
  Given crystal symmetry, anomalous flag, and resolution limits, create a
  complete set object.

  :param crystal_symmetry: cctbx.crystal.symmetry object
  :param anomalous_flag: Boolean, indicates whether to generate anomalous indices
  :param d_min: High-resolution limit (optional if max_index is specified)
  :param d_max: Low-resolution limit (optional)
  :param max_index: highest-resolution Miller index
  :returns: a set object
  i   RÝ   N(
   R   R   R   R4   t   index_generatorR%   R   t   to_arrayR2   R1  (   R1   R&   R(   RÝ   R!  Rw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR=   ë  s(    !		 c         C   s_   t  |  ƒ d k s t ‚ t ƒ  } x! |  D] } | j | j ƒ  ƒ q( W|  d j d | j ƒ  ƒ S(   Ni    R$   (   RR   R   t   union_of_indices_registryt   updateR$   R¥   t   as_array(   t   miller_setst   uoit   ms(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   union_of_sets  s
    	t
   array_infoc        
   B   sz   e  Z d  Z d d d d e e d d d d „	 Z d „  Z e e e e e e e e e d „	 Z d „  Z	 d „  Z
 d „  Z RS(   sf   
  Container for metadata associated with a Miller array, including labels
  read from a data file.
  c
   
      C   s   t  |  t ƒ  ƒ d  S(   N(   R   t   locals(
   R.   t   sourcet   source_typet   historyR“   t   mergedt   systematic_absences_eliminatedt   crystal_symmetry_from_filet   type_hints_from_fileRh   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#     s    
c         C   s8   d  |  _ |  j j | ƒ t |  d ƒ s4 d  |  _ n  d  S(   NRh   (   R   R  t   __dict__R  t   hasattrRh   (   R.   t   state(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __setstate__%  s    	c
   
      C   s  | t  k r |  j } n  | t  k r0 |  j } n  | t  k rH |  j } n  | t  k r` |  j } n  | t  k rx |  j } n  | t  k r� |  j } n  | t  k r¨ |  j } n  | t  k rÀ |  j } n  |	 t  k rØ |  j	 }	 n  t
 d | d | d | d | d | d | d | d | d	 |	 ƒ 	S(
   sw   
    Create a modified copy of the array_info object, keeping all attributes
    that are not explicitly modified.
    R  R  R  R“   R  R  R  R  Rh   (   R   R  R  R  R“   R  R  R  R  Rh   R  (
   R.   R  R  R  R“   R  R  R  R  Rh   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¥   +  s8         c         C   s^   g  } |  j  d  k	 r( | j |  j  ƒ n  |  j rA | j d ƒ n  |  j rZ | j d ƒ n  | S(   NR  R  (   R“   R   Rg  R  R9   R  (   R.   t   part_2(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_string_part_2Q  s    		c         C   s/   |  j  ƒ  } t | ƒ d k r+ d j | ƒ Sd S(   s¯   
    A combined representation of the data labels extracted from the input file.
    This is generally how downstream programs will identify and select Miller
    arrays.
    i    t   ,N(   R#  RR   RY   R   (   R.   R"  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   label_string[  s     c         C   s°   g  } |  j  d  k	 r. | j t |  j  ƒ ƒ n( |  j d  k	 rV | j t |  j ƒ ƒ n  |  j ƒ  } t | ƒ d k r� | j d j | ƒ ƒ n  t | ƒ d k r£ d Sd j | ƒ S(   Ni    R$  R   t   :(   R  R   R9   RS   R  R#  RR   RY   (   R.   Rw   R"  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __str__e  s    N(   R•   R–   R  R   R,   R#   R!  R   R¥   R#  R%  R'  (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR    s.   		
	
c         C   sN   |  d  k r t d  ƒ Sy |  j j d t |  ƒ f SWn t k
 rI d SXd  S(   Ns	   , size=%dt   Unknown(   R   RS   t	   __class__R•   RR   t	   Exception(   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   raw_array_summaryr  s     
R   c           B   sÃ  e  Z d  Z dÅ dÅ d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z dÅ d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e e e e e e e e e dÅ d „
 Z e  d „ Z! e e e e e d „ Z" d „  Z# d  „  Z$ d! „  Z% d" „  Z& dÅ d d# „ Z' d$ d% „ Z( d$ dÅ d& „ Z) d' d( dÅ d) „ Z* d* d+ d, „ Z+ d- d. „ Z, d/ d+ d0 „ Z- d1 d2 „ Z. d/ d3 „ Z/ d1 d4 „ Z0 dÅ d5 „ Z1 e  d6 „ Z2 dÅ e  d7 „ Z3 e4 d8 „ Z5 e4 e4 d9 „ Z6 e  d: d; „ Z7 d+ dÅ dÅ d< d< d= „ Z8 d> e4 d? „ Z9 d@ „  Z: dÅ e4 dA „ Z; dÅ dB „ Z< e  dC „ Z= dD „  Z> dE e4 dÅ dF „ Z? dG „  Z@ dÅ dÅ dH „ ZA dI „  ZB dJ „  ZC dÅ dÅ dK „ ZD dL „  ZE dM „  ZF dN „  ZG e4 d+ dÅ dÅ e  dO „ ZH dP „  ZI e4 dQ „ ZJ e4 e4 e4 dR „ ZK e4 d( dÅ dS „ ZL dT e  d( dU „ ZM e4 dV „ ZN e4 dW „ ZO e4 dÅ dX „ ZP e4 dÅ dY „ ZQ e4 dÅ dZ „ ZR e4 d[ „ ZS e4 d\ „ ZT d] d^ dÅ d d_ „ ZU d` „  ZV dÅ e4 e4 da „ ZW e4 dÅ db „ ZX e4 e4 dc „ ZY e4 dd „ ZZ e4 de „ Z[ dÅ dÅ df „ Z\ dÅ dg „ Z] dÅ dÅ dÅ dÅ dÅ dÅ e  dh e4 di „	 Z^ e4 e4 e4 e4 dj „ Z_ e4 e4 dk „ Z` e4 e4 e4 dl „ Za e4 e4 dm „ Zb e4 e4 dn „ Zc e4 e4 e4 do „ Zd dp dq „ Ze e4 dr „ Zf ds „  Zg dt „  Zh d: du „ Zi d: dv „ Zj dÅ dw „ Zk dx „  Zl dy „  Zm e4 dz „ Zn d{ „  Zo d| „  Zp e4 d} „ Zq d~ dÅ e  d „ Zr d€ „  Zs d� „  Zt e4 dÅ d d‚ „ Zu e4 dƒ „ Zv d„ „  Zw d… „  Zx d† „  Zy d‡ „  Zz dˆ „  Z{ d‰ „  Z| dŠ „  Z} d‹ „  Z~ dŒ „  Z e4 e  d� „ Z€ dÅ d dÅ dŽ „ Z� d� „  Z‚ dÆ dÅ dÅ dÅ dÅ dÅ d‘ e  dÅ d’ „	 Zƒ dÅ d“ „ Z„ d” d• „ Z… d– dÅ d— „ Z† dÅ d˜ d˜ d– dÅ d™ „ Z‡ dp dÇ dÅ dÅ dÅ dÅ d‘ e  dÅ dš „	 Zˆ dÈ dÅ dÅ dÅ d‘ e  dÅ e4 e4 d› „	 Z‰ dÅ e4 dœ „ ZŠ dÅ g  dÅ dÅ d� „ Z‹ dÅ dÅ dÅ dÅ e4 dž „ ZŒ dÅ dÅ dÅ dŸ d  d¡ dÅ d¢ „ Z� d£ „  ZŽ dÅ d¤ d¥ „ Z� e  dÅ dÅ dÅ d¦ „ Z� dÅ d§ „ Z‘ dÅ d¨ „ Z’ dÅ dÅ e4 d© „ Z“ dÅ dÅ dÅ dª „ Z” e• e” ƒ Z” d« „  Z– d¬ „  Z— d­ d® e4 d¯ „ Z˜ dÅ dÅ dÅ d° „ Z™ d± „  Zš dÉ dÊ dË e4 d² „ Z› d� d³ „ Zœ d´ „  Z� d� dµ „ Zž d¶ „  ZŸ d· „  Z  e4 d: e4 d¸ „ Z¡ e4 d¹ „ Z¢ dº „  Z£ d» „  Z¤ d¼ „  Z¥ d½ „  Z¦ e  dÅ d¾ „ Z§ dÅ dÅ d¿ e  e  e  dÅ dÀ „ Z¨ e© jª d dÁ „ Z« dÂ dÅ dÃ „ Z¬ dÂ dÄ „ Z­ RS(Ì   sâ   
  Extension of the set class with addition of data and (optional) sigmas
  flex arrays, plus an optional array_info object and an optional flag for
  the observation type (amplitude, intensity, or reconstructed amplitude).
  c         C   s8   t  j |  | ƒ | |  _ | |  _ d  |  _ d  |  _ d  S(   N(   R4   Rœ   t   _datat   _sigmasR   t   _infot   _observation_type(   R.   R0   R�   R¦   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#     s
    			c         C   sD   t  j |  | ƒ | j |  _ | j |  _ | j |  _ | j |  _ d  S(   N(   R4   Rœ   R,  R-  R.  R/  (   R.   R    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRœ   †  s
    c         C   s   | |  _  |  S(   N(   R.  (   R.   t   info(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   set_info�  s    	c         C   s_   d d l  m } t | t ƒ r. | j ƒ  } n  | d  k sR t | | j ƒ sR t ‚ | |  _ |  S(   Niÿÿÿÿ(   t   observation_types(	   t
   cctbx.xrayR2  R„   R   t   observation_typeR   t   anyR   R/  (   R.   R4  R2  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   set_observation_type“  s    $	c         C   s#   d d l  m } |  j | j ƒ  ƒ S(   s1   
    Flag the array as X-ray amplitudes (F).
    iÿÿÿÿ(   R2  (   R3  R2  R6  t	   amplitude(   R.   R2  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt#   set_observation_type_xray_amplitude›  s    c         C   s#   d d l  m } |  j | j ƒ  ƒ S(   s2   
    Flag the array as X-ray intensities (I).
    iÿÿÿÿ(   R2  (   R3  R2  R6  t	   intensity(   R.   R2  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt#   set_observation_type_xray_intensity¢  s    c         C   s   |  j  S(   N(   R,  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR�   ©  s    c         C   s   |  j  S(   N(   R-  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¦   ¬  s    c         C   s@   | d  k	 r3 | j ƒ  |  j ƒ  j ƒ  k s3 t ‚ n  | |  _ d  S(   N(   R   R'   R$   R   R-  (   R.   R¦   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   set_sigmas¯  s    'c         c   sx   |  j  ƒ  d  k	 rI x_ t |  j ƒ  |  j ƒ  |  j  ƒ  ƒ D] } | Vq7 Wn+ x( t |  j ƒ  |  j ƒ  ƒ D] } | Vqe Wd  S(   N(   R¦   R   R   R$   R�   (   R.   t   item(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __iter__´  s
    +"c         C   s   |  j  S(   sB   
    Return the associated info object, or None if undefined.
    (   R.  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR0  ¼  s    R{   c         C   sw   t  j |  d | d | ƒ|  j ƒ  d  k	 rs t |  j ƒ  t ƒ rs |  j ƒ  j } | d  k	 rs | | d | IJqs n  |  S(   NR~   R   s   Wavelength: %.4f(   R4   RÛ   R0  R   R„   R  Rh   (   R.   R~   R   Rh   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÛ   Â  s    'c         C   s   |  j  S(   s³   
    Return the (experimental) data type, if defined.  See the module
    cctbx.xray.observation_types for details.

    :returns: an object from cctbx.xray.observation_types
    (   R/  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR4  Ê  s    c         C   s¦   |  j  ƒ  d  k	 s t ‚ |  j ƒ  d  k	 s0 t ‚ |  j ƒ  j ƒ  |  j  ƒ  j ƒ  k sZ t ‚ |  j ƒ  d  k	 r™ |  j ƒ  j ƒ  |  j  ƒ  j ƒ  k s™ t ‚ n  t j |  ƒ S(   N(   R$   R   R   R�   R'   R¦   R4   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR'   Ó  s    *-c         C   s   t  |  j ƒ  t j ƒ S(   N(   R„   R�   R	   t
   std_string(   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   is_string_arrayÛ  s    c         C   s   t  |  j ƒ  t j ƒ S(   N(   R„   R�   R	   R)  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   is_bool_arrayÞ  s    c         C   sF   t  |  j ƒ  t j ƒ pE t  |  j ƒ  t j ƒ pE t  |  j ƒ  t j ƒ S(   N(   R„   R�   R	   R©   t   longRe  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   is_integer_arrayá  s    c         C   s.   t  |  j ƒ  t j ƒ p- t  |  j ƒ  t j ƒ S(   N(   R„   R�   R	   R]  RB  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÐ   æ  s    c         C   s   t  |  j ƒ  t j ƒ S(   N(   R„   R�   R	   RŸ  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   is_complex_arrayê  s    c         C   s   t  |  j ƒ  t j ƒ S(   N(   R„   R�   R	   t   hendrickson_lattman(   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   is_hendrickson_lattman_arrayí  s    c         C   s&   d d l  m } t |  j ƒ  | j ƒ S(   Niÿÿÿÿ(   R2  (   R3  R2  R„   R4  R7  (   R.   R2  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRË   ð  s    c         C   s&   d d l  m } t |  j ƒ  | j ƒ S(   Niÿÿÿÿ(   R2  (   R3  R2  R„   R4  t   reconstructed_amplitude(   R.   R2  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt%   is_xray_reconstructed_amplitude_arrayô  s    c         C   s&   d d l  m } t |  j ƒ  | j ƒ S(   Niÿÿÿÿ(   R2  (   R3  R2  R„   R4  R9  (   R.   R2  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÊ   ù  s    c         C   s   |  j  ƒ  p |  j ƒ  S(   N(   RË   RÊ   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   is_xray_data_arrayý  s    c         C   s=   t  d |  d |  j ƒ  d |  j ƒ  ƒ j |  j ƒ  ƒ j |  ƒ S(   sI   
    Create a new array object using references to internal objects.
    R0   R�   R¦   (   R   R�   R¦   R1  R0  R6  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¡      s    c         C   s”   d } d } |  j ƒ  d k	 r3 |  j ƒ  j ƒ  } n  |  j ƒ  d k	 rZ |  j ƒ  j ƒ  } n  t d t j |  ƒ d | d | ƒ j |  j ƒ  ƒ j |  ƒ S(   sG   
    Clone the array, making copies of all internal array objects.
    R0   R�   R¦   N(	   R   R�   R¤   R¦   R   R4   R1  R0  R6  (   R.   Rc   R‰   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¤     s      	c         C   sÙ   | t  k r |  } n  | t  k r0 |  j ƒ  } n  | t  k rK |  j ƒ  } n  |
 t  k rf |  j ƒ  }
 n  |	 t  k r� |  j ƒ  }	 n  t j | d | d | d | d | d | ƒ} t d | d | d | ƒ j |	 ƒ j	 |
 ƒ S(	   NR1   R$   R&   R2   R%   R0   R�   R¦   (
   R   R�   R¦   R0  R4  R4   R¥   R   R6  R1  (   R.   R0   R�   R¦   R1   R$   R&   R2   R%   R4  R0  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¥     s$     	    	c         C   sÆ   |  j  ƒ  | j  ƒ  g j d  ƒ d k r… |  j ƒ  j d | j ƒ  d | ƒ j d |  j ƒ  j | j ƒ  ƒ d |  j  ƒ  j | j  ƒ  ƒ ƒ S|  j ƒ  j d | j ƒ  ƒ j d |  j ƒ  j | j ƒ  ƒ ƒ Sd  S(   Ni    R    R4  R�   R¦   (   R¦   R   R   R4   Rü  R   R�   (   R.   R    R4  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRü  3  s    '!c         C   s+   t  j |  d | d | d | d | d | ƒS(   sA   
    Return the basic cctbx.miller.set object for the array.
    R1   R$   R&   R2   R%   (   R4   R¥   (   R.   R1   R$   R&   R2   R%   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR4   >  s    	c         C   s   t  j |  d d ƒS(   s4   
    Create a copy of the array without sigmas.
    R¦   N(   R   R¥   R   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   discard_sigmasN  s    c         C   s4   |  j  ƒ  s t ‚ t j |  d t j |  j ƒ  ƒ ƒS(   NR�   (   RC  R   R   R¥   R	   t   conjR�   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt	   conjugateT  s    c         C   s   |  j  d |  j ƒ  j ƒ  ƒ S(   sz   
    Create a copy of the array with the data converted to a flex.double type.
    Will fail for incompatible arrays.
    R�   (   R   R�   RF  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRF  X  s    c      	   C   sC   t  d t j |  | ƒ d t |  j ƒ  | ƒ d t |  j ƒ  | ƒ ƒ S(   NR0   R�   R¦   (   R   R4   R   R    R�   R¦   (   R.   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR   _  s    c         C   s³   | d  k r t j } n  | | d |  j j I|  j ƒ  IJ| | d I|  j ƒ  IJ| | d It |  j ƒ  ƒ IJ| | d It |  j	 ƒ  ƒ IJt
 j |  d | d | ƒ|  S(   Ns   Miller %s info:s   Observation type:s   Type of data:s   Type of sigmas:R~   R   (   R   R|   R}   R)  R•   R0  R4  R+  R�   R¦   R4   R€   (   R.   R~   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR€   e  s     
  i   c         C   sm  | j  ƒ  s t ‚ |  j  ƒ  s$ t ‚ |  j ƒ  d  k	 s< t ‚ |  j ƒ  | j ƒ  k sZ t ‚ t | |  j ƒ  ƒ } |  } | } | j ƒ  } t j | j	 ƒ  | j	 ƒ  ƒ | j ƒ  } | j	 ƒ  t j
 | j	 ƒ  ƒ } t j | d t ƒ|  } | j | ƒ } | j | ƒ } | j | ƒ }	 | j | ƒ } | j ƒ  }
 | j ƒ  j	 ƒ  } t d |
 d | d | d |	 d | d | ƒ S(   NR@  R$   t   fo_sqt   fc_sqt   delta_f_sq_over_sigmat   fc_over_fc_maxRó   (   RÊ   R   R¦   R   R'   Rù   t   as_amplitude_arrayR	   R«   R�   RQ   RA  R<   RÅ   R$   Ró   R   (   R.   t	   f_calc_sqt   n_reflectionst   fo2t   fc2t   fct
   delta_f_sqRO  t   permRN  R$   Ró   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   disagreeable_reflectionso  s.    )c      
   C   s¼   | d  k r t j } n  |  j | d | ƒ} | d IJx~ t | j j ƒ  ƒ D]g } | d | j | I| d | j j ƒ  | | j	 j ƒ  | | j
 | | j | | j | f IJqM W| S(   NRR  sR     h   k   l       Fo^2      Fc^2   |Fo^2-Fc^2|/sig(F^2)   Fc/max(Fc)  d spacing(A)s   %3i %3i %3is1    %9.2f %9.2f        %9.2f         %9.2f     %9.2f(   R   R|   R}   RX  t   rangeRL  R'   R$   R�   RM  RN  RO  Ró   (   R.   RQ  RR  Rß   Rw   Rš   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   show_disagreeable_reflectionsˆ  s     
 
g{®Gáz”?g      @c      	   C   s   t  d |  d | d | d | ƒ S(   Nt   miller_arrayt#   unit_cell_relative_length_tolerancet"   unit_cell_absolute_angle_tolerancet   working_point_group(   t6   crystal_symmetry_is_compatible_with_symmetry_from_file(   R.   R\  R]  R^  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR_  ”  s
    g      è?g�íµ ÷Æ°>c         C   s•   d  } |  j ƒ  d  k	 r‘ |  j ƒ  j ƒ  d k r‘ t } |  j ƒ  | k j t ƒ } |  j ƒ  j ƒ  } t | ƒ t | ƒ } | | k r‘ t } q‘ n  | S(   Ni    (   R   R¦   R'   R<   R   R]  R,   (   R.   t   critical_ratioRï   Rw   t	   suspectedt   allt   ratio(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   sigmas_are_sensiblež  s    *g      Àc         C   sH  |  j  ƒ  s t ‚ |  j ƒ  d k	 s* t ‚ |  j ƒ  s< t ‚ |  j |  j ƒ  d k ƒ }  |  j ƒ  |  j ƒ  } |  j | | k ƒ }  t j |  j ƒ  |  j ƒ  d |  j ƒ  |  j ƒ  ƒ } t j |  j ƒ  | d ƒ } d | | |  j ƒ  d | |  j ƒ  |  j ƒ  } t j d | ƒ } |  j	 d | d | ƒ j
 |  j ƒ  ƒ } | S(   s  
    Takes in an intensity array (including negatives) and spits out amplitudes.
    The basic assumption is that
    P(Itrue) \propto exp(-(Itrue-Iobs)**2/(2*s))
    where Itrue>=0 (positivity constraint on error free amplitudes).
    For amplitudes, this results in
    P(Ftrue) \propto 2 Ftrue exp( -(Ftrue**2-Iobs)**2/(2s) )
    A Gaussian approximation is fitted to the Mode of this distribution.
    An analytical solution exists and is implemented below.
    This method does not require any Wilson statistics assumptions.
    i    g       @g      ð?g      @R�   R¦   N(   RÊ   R   R¦   R   Rd  RÅ   R�   R	   R.  R¥   R6  RP  (   R.   t   i_sig_levelt   i_sigit   dett   f_saddlet   s_saddleRw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   enforce_positive_amplitudes©  s    7	t   xtal_3_7c   	      C   s8  d d l  m } |  j ƒ  d k s4 |  j ƒ  s4 t ‚ i | j d 6| j d 6} | j | ƒ } | d k r² t	 d t
 | ƒ d d j g  | j ƒ  D] } t
 | ƒ ^ q� ƒ ƒ ‚ n  |  j ƒ  d k rå t |  | |  j ƒ  ƒ j ƒ } n6 | |  j ƒ  |  j ƒ  | ƒ } t |  | j | j ƒ } |  j ƒ  r4| j ƒ  n  | S(	   sõ   
    Given an intensity/F^2 array (or undefined observation type), return the
    equivalent amplitudes.  Note that negative intensities will be discarded;
    for French-Wilson treatment, call the separate array.french_wilson()
    method.
    iÿÿÿÿ(   R´  Rk  t   crystalss   Unknown f_sq_as_f algorithm=%s
s     Possible choices are: s   , N(   R¿  R´  R4  R   RÊ   R   t   array_f_sq_as_f_xtal_3_7t   array_f_sq_as_f_crystalst   gett   RuntimeErrorR   RY   t   keysR¦   R   R�   R~   t   sigma_fR8  (	   R.   R¾  R
  R´  t
   converterst	   converterR‰   Rw   t   r(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt	   f_sq_as_fÈ  s     $
F!t   simplec   	      C   s„  | d
 k s t  ‚ d d l m } |  j ƒ  d k sF |  j ƒ  sF t  ‚ |  j ƒ  d k r| t |  | j |  j	 ƒ  ƒ j
 ƒ } në | d k rÁ | j |  j	 ƒ  |  j ƒ  ƒ } t |  | j
 | j ƒ } n¦ t j ƒ  } t j ƒ  } xp t |  j	 ƒ  |  j ƒ  ƒ D]S \ } } | j | d ƒ | j d t d | ƒ t t d t | ƒ | ƒ ƒ ƒ qõ Wt d |  d | d	 | ƒ } |  j ƒ  r€| j ƒ  n  | S(   sP   
    Convert amplitudes (and associated sigmas, if present) to intensities.
    Rw  t   shelxliÿÿÿÿ(   R´  i   g{®Gáz„?R0   R�   R¦   (   Rw  Rx  N(   R   R¿  R´  R4  R   RË   R¦   R   t   array_f_as_f_sqR�   t   f_sqt
   sigma_f_sqR	   RB  R%  R9   RQ   R«   R:  (	   R.   R¾  R´  Rw   Ru  Rz  t   s_sqR~   R‰   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt	   f_as_f_sqã  s"    $$(:c         C   sr   |  j  ƒ  r@ t d |  d t j |  j ƒ  ƒ d |  j ƒ  ƒ j ƒ  S|  j ƒ  sR t ‚ |  j	 ƒ  rn |  j
 d | ƒ S|  S(   s˜   
    Convert the array to simple amplitudes if not already in that format.
    Only valid for complex (i.e. F,PHI), intensity, or amplitude arrays.
    R0   R�   R¦   R¾  (   RC  R   R	   R«   R�   R¦   R8  RÐ   R   RÊ   Rv  (   R.   R¾  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRP  ý  s    .c         C   sT   |  j  ƒ  r" |  j ƒ  j d | ƒ S|  j ƒ  s4 t ‚ |  j ƒ  sP |  j d | ƒ S|  S(   sŽ   
    Convert the array to intensities if not already in that format.  Only valid
    for complex (F,PHI), amplitude, or intensity arrays.
    R¾  (   RC  RP  R}  RÐ   R   RÊ   (   R.   R¾  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_intensity_array	  s    c         C   sî   |  j  ƒ  j ƒ  } |  j ƒ  j ƒ  } |  j ƒ  s< |  j ƒ  rd t |  j ƒ  j ƒ  |  j ƒ  | | ƒ nY | d k r• t |  j ƒ  j ƒ  |  j ƒ  | ƒ n( t |  j ƒ  j ƒ  |  j ƒ  | | | ƒ t
 t |  | |  j ƒ  ƒ | |  j ƒ  ƒ j |  ƒ S(   sµ   
    Convert all indices to lie within the canonical asymmetric unit for the
    current space group (while preserving anomalous flag).  Required for many
    downstream steps.
    N(   R$   R¤   R�   RC  RE  R  R%   R   R&   R   R   R4   R¦   R6  (   R.   Ri   Rš   Rc   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR  	  s$    		
	*c         C   s'  | r |  j  | ƒ s t ‚ n  |  j ƒ  j ƒ  | j ƒ  j ƒ  k sH t ‚ |  j ƒ  | j ƒ  k sf t ‚ t | j ƒ  |  j ƒ  ƒ j ƒ  } |  j ƒ  j | ƒ j | j ƒ  ƒ s± t ‚ |  j	 ƒ  } |  j
 ƒ  } | d  k	 rç | j | ƒ } n  | d  k	 r| j | ƒ } n  t d | d | d | ƒ j |  ƒ S(   NR0   R�   R¦   (   R2  R   R$   R'   R&   R3  t   permutationRÅ   R  R�   R¦   R   R   R6  (   R.   R    R4  Rí  Rc   R‰   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt	   adopt_set1	  s    *!*  c         C   sþ  |  j  ƒ  j ƒ  |  j ƒ  j ƒ  k s* t ‚ |  j ƒ  d  k	 r{ |  j ƒ  j ƒ  |  j ƒ  j ƒ  k sf t ‚ | d  k	 s{ t ‚ n  | j d |  d | ƒ j ƒ  } t | |  j  ƒ  j	 ƒ rÞ | j ƒ  | j ƒ  k sÏ t ‚ | j
 ƒ  } n$ |  j  ƒ  j	 | j ƒ  j ƒ  | ƒ } | j | j d ƒ |  j  ƒ  j | j d ƒ ƒ ƒ |  j ƒ  d  k rNd  } nš t | |  j ƒ  j	 ƒ r“| j ƒ  | j ƒ  k s„t ‚ | j
 ƒ  } n$ |  j ƒ  j	 | j ƒ  j ƒ  | ƒ } | j | j d ƒ |  j ƒ  j | j d ƒ ƒ ƒ | j d | d | ƒ S(   NR    R4  i    i   R�   R¦   (   R�   R'   R$   R   R¦   R   R3  RÎ   R„   R)  R¤   RC  R5  RÅ   R   (   R.   R    t   data_substitutet   sigmas_substituteR4  RÎ   R�   R¦   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   matching_set?	  s0    **	+	+c   
      C   s3  |  j  | ƒ \ } } | rA d t j | j ƒ  j ƒ  ƒ d } n  t | ƒ j ƒ  t | ƒ j ƒ  } } d } | rà t j j d t j	 | ƒ d | d | ƒ } d t j | j ƒ  j ƒ  ƒ d } | j
 t j | | j ƒ } n9 t j | | ƒ }	 |	 d k rt j | | ƒ |	 } n  | j d | j ƒ  | ƒ S(	   Ng      ð?g      @i   t   xt   yt   zi    R�   (   R9  R	   Rá  Ró   R�   R«   t   scitbxR„  t   gaussian_fit_1d_analyticalR.  t   aRÛ  t   bt   sumR¥   (
   R.   R    t   resolution_dependentR‰   t   oRè  t   scale_factorRu  t   ss_othert   den(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¶   `	  s     &%*#!c         C   s1  |  | } } | r( | j  d | ƒ } n  | rš t | j ƒ  t j ƒ sL t ‚ | j | ƒ \ } } | j d | ƒ } | j | ƒ \ } }	 | j	 | ƒ } n  | j
 | ƒ }
 | j ƒ  j	 |
 j ƒ  ƒ } | j ƒ  j	 |
 j ƒ  ƒ } d  } | j ƒ  d  k	 r| j ƒ  j	 |
 j ƒ  ƒ } n  |  j d | d | d | ƒ S(   NR    t   phase_sourceR�   R$   R¦   (   R¶   R„   R�   R	   RŸ  R   R9  t   phase_transferR<  Rü  R;  R$   R   R¦   R¥   (   R.   R    R¶   t   replace_phasesR‰   R�  t   s_ct   c_ot   s_lt   c_lt   olt   d_newt   i_newt
   sigmas_new(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   complete_witho	  s      i   c         C   sŸ  |  j  ƒ  | j  ƒ  k s t ‚ |  j ƒ  d  k s6 t ‚ |  j d | ƒ \ } } |  j d | ƒ \ } } d } | rê t j t j | j	 ƒ  ƒ t j | j	 ƒ  ƒ ƒ }	 |	 d k rê t j t j | j	 ƒ  ƒ t j | j	 ƒ  ƒ ƒ |	 } qê n  | j	 ƒ  | j	 ƒ  | }
 |
 j
 | j	 ƒ  | ƒ |
 j
 | j	 ƒ  | | ƒ | j ƒ  } | j
 | j ƒ  ƒ | j
 | j ƒ  ƒ t d |  j ƒ  d | d |  j  ƒ  ƒ } | j d |
 ƒ S(   NR    i   i    R1   R$   R&   R�   (   R&   R   R¦   R   R9  R<  R	   R‹  R«   R�   Rg  R$   R4   R1   R   (   R.   R    R¶   t   scale_for_lonest   f1_ct   f2_ct   f1_lt   f2_lt   scale_k1R�  t   result_datat   result_indicesR  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   combine€	  s(    1;iÿÿÿÿc         C   sU  |  j  d | d | d | ƒ } t |  j ƒ  | j ƒ  ƒ } |  j ƒ  } |  j ƒ  }	 |	 d  k	 rl |	 j ƒ  }	 n  |  j ƒ  }
 |
 d  k	 r“ |
 j ƒ  }
 n  | j d ƒ } | j ƒ  } | d k rÉ | j ƒ  } np | j	 | j ƒ  j
 | ƒ ƒ } |	 d  k	 r|	 j |	 j ƒ  | | ƒ n  |
 d  k	 r9|
 j |
 j ƒ  | | ƒ n  |  j d | d |	 d |
 ƒ S(	   NRB   R(   RÝ   i   i    R$   R�   R¦   (   RC   R3  R$   R�   R   R¤   R¦   R:  R'   Rü  RÅ   t   resizeR¥   (   R.   RB   R(   RÝ   t   new_data_valuet   new_sigmas_valuet   csRÚ   Rš   Rc   R‰   R  R`   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   complete_array–	  s(    	    R=  c         C   sæ   | t  t f k s t ‚ | d	 k rB t j |  d | d | ƒ} n  | d k rp t j d |  j ƒ  d | ƒ } nr | d k r§ t j d t j |  j ƒ  ƒ d | ƒ } n; t | t	 ƒ rÉ t
 d | ƒ ‚ n t j d | d | ƒ } | S(
   sH  
    Generate the selection array (flex.size_t object) to reorder the array
    by resolution, Miller index, data values, or absolute data values.

    :param by_value: sort type, must be "resolution", "packed_indices", "data",
                     or "abs"
    :param reverse: invert order
    :returns: flex.size_t object
    R=  R>  R?  RG  R@  R�   R«   s   Unknown: by_value=%s(   s
   resolutions   packed_indicess   asu_indices(   R,   R<   R   R4   RA  R	   R�   R«   R„   RS   t
   ValueError(   R.   RG  R@  Rw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRA  °	  s    
		"	c         C   sO   |  j  ƒ  } |  j ƒ  r0 t j |  j  ƒ  ƒ } n  t t j |  ƒ | |  j ƒ  ƒ S(   N(   R�   RC  R	   R«   R   R4   R‘  R¦   (   R.   R�   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR‘  Ë	  s    c   	      C   s�  |  j  ƒ  d
 k	 s t ‚ |  j ƒ  d
 k	 s0 t ‚ |  j ƒ  d
 k	 sH t ‚ |  j ƒ  d
 k	 s` t ‚ d
 } d
 } i t d 6t d 6j |  j ƒ  j	 j
 d
 ƒ } | d
 k	 r| d
 k s¶ t ‚ |  j ƒ  d
 k sÎ t ‚ | d |  j ƒ  d |  j ƒ  d |  j ƒ  d |  j ƒ  ƒ } | j } n| d
 k	 r¸| t t g k s7t ‚ |  j ƒ  d
 k sOt ‚ t |  j ƒ  t j ƒ smt ‚ t d |  j ƒ  d |  j ƒ  d |  j ƒ  d |  j ƒ  d | ƒ } | j } nl | d
 k sÊt ‚ |  j ƒ  } |  j ƒ  j | j ƒ } |  j ƒ  d
 k	 r|  j ƒ  j | j ƒ } n  | j } t d |  j ƒ  d | j d |  j ƒ  ƒ j d | d	 | ƒ j |  ƒ } | r‹| d
 k	 s�t ‚ | | f S| S(   s-   
    Generate the equivalent P1 dataset.
    RŸ  RD  Rç   R&   R$   R�   Ri   R1   R¦   N(   R%   R   R   R$   R&   R�   t   expand_to_p1_complext    expand_to_p1_hendrickson_lattmanRo  R)  R•   R¦   Rç   R,   R<   R„   R	   RB  t   expand_to_p1_phasesR�  RÅ   RD  R4   RŽ  R   R6  (	   R.   t	   phase_degR�  t	   p1_sigmasRD  t   expand_typet   p1t   p1_dataRw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¨   Ô	  s\    
			
c      	   C   sí  t  | t ƒ r! t j | ƒ } n  | t k s9 | t k r{ |  j ƒ  sK t ‚ t d | d |  j	 ƒ  d |  j
 ƒ  d | ƒ } nÏ |  j ƒ  r± t d | d |  j	 ƒ  d |  j
 ƒ  ƒ } n™ |  j ƒ  sÕ |  j ƒ  sÕ |  j ƒ  rt d | j |  j	 ƒ  ƒ d |  j
 ƒ  j ƒ  ƒ } nB |  j ƒ  r>t d | d |  j	 ƒ  d |  j
 ƒ  ƒ } n t d ƒ ‚ d  } |  j ƒ  d  k	 r•t  |  j ƒ  t j ƒ s€t ‚ |  j ƒ  j ƒ  } n  t d t d	 t j j |  | ƒ d | j	 d
 |  j ƒ  ƒ d | j
 d | ƒ j |  j  ƒ  ƒ S(   NR‹  t
   indices_int   data_inRi   R$   R�   s#   Unsupported miller.array data type.R0   R1   R&   R¦   (!   R„   RS   R   R‰  R,   R<   RÐ   R   t   change_basis_phases_doubleR$   R�   RC  t   change_basis_complex_doubleR@  RB  R   RŠ  R¤   RE  t    change_basis_hendrickson_lattmanRp  R   R¦   R	   RB  R   R4   R   R5   R_  R&   R6  R4  (   R.   R‹  Ri   Rw   t   result_sigmas(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR_  
  sJ     		c         C   sÉ   |  j  ƒ  s t ‚ |  j |  j | ƒ d | ƒ\ } } | j ƒ  | j ƒ  k sT t ‚ | j ƒ  | j ƒ  } } | t j | ƒ } t j | ƒ } t j	 t j
 | ƒ d ƒ } d t j d t j | | ƒ S(   sÀ    The factor phi_{sym} quantifying whether complex structure factors
    are invariant under the given symmetry operator, as used in Superflip.
    Ref: J. Appl. Cryst. (2008). 41, 975-984
    R4  i   i   (   RC  R   R9  R_  R'   R�   R	   RJ  R«   Rñ   t   argR„  R…  t   mean_weighted(   R.   t   opR4  R~   t   op_ft   cc_sft   weightst   delta(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   symmetry_agreement_factor/
  s    c         C   sÄ   | j  ƒ  s t ‚ |  j ƒ  j | j ƒ  ƒ s3 t ‚ |  j ƒ  | j ƒ  k sQ t ‚ |  j  ƒ  r„ t d |  d | |  j ƒ  | j ƒ  ƒ St d |  d | |  j ƒ  t j | j ƒ  ƒ ƒ j	 d | ƒ Sd  S(   NR0   R�   R‘  (
   RC  R   R$   R  R&   R   R�   R	   R«   R’  (   R.   RÔ  RÕ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÖ  A
  s    !)g»½×Ùß|Û=c      
   C   së  |  j  ƒ  d k	 s t ‚ t | d ƒ r6 | j  ƒ  } n  t |  j  ƒ  t j ƒ sl t |  j  ƒ  t j ƒ sl t ‚ t | t j ƒ s¨ t | t j ƒ s¨ t | t j ƒ s¨ t ‚ t | t j ƒ r| d k rÒ t	 ƒ  } n t	 d | ƒ } | d |  j
 ƒ  d |  j ƒ  d | ƒ } n  t |  j  ƒ  t j ƒ r2|  j  ƒ  } n t j |  j  ƒ  ƒ } |  j
 ƒ  d k	 s_t ‚ t | t j ƒ r®t d |  d t |  j
 ƒ  |  j ƒ  | | | ƒ d |  j ƒ  ƒ St d |  d t |  j
 ƒ  |  j ƒ  | | | ƒ d |  j ƒ  ƒ S(	   s2  Combines phases of phase_source with self's data if real (keeping
    the sign of self's data) or with self's amplitudes if complex.

    Centric reflections are forced to be compatible with the phase restrictions.

    phase_source can be a miller.array or a plain flex array.

    epsilon is only used when phase_source is a complex array. If both the
    real and the imaginary part of phase_source[i] < epsilon the phase is
    assumed to be 0.

    deg is only used if phase_source is an array of doubles.
    deg=True indicates that the phases are given in degrees,
    deg=False indicates phases are given in radians.

    phase_integrator_n_steps is only used if phase_source is an
    array of Hendrickson-Lattman coefficients. The centroid
    phases are determined on the fly using the given step size.
    R�   t   n_stepsRç   R6   t    hendrickson_lattman_coefficientsR0   R¦   N(   R�   R   R   R  R„   R	   RŸ  RB  RD  t   phase_integratorRç   R$   R«   R   R’  R¦   (   R.   R‘  Rï   Ri   t   phase_integrator_n_stepst
   integratorR�   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR’  O
  sN    						c         C   s3   d t  j t j |  j ƒ  j ƒ  ƒ } |  j | ƒ S(   Ni   (   R„  R…  R	   Rf  R�   R'   R’  (   R.   R‡  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   randomize_phases�
  s    &c         C   s    |  j  ƒ  s t ‚ | d  k s0 | d  k s0 t ‚ | d  k rf | d  k rT t ƒ  } qf t d | ƒ } n  t d |  d | d |  j ƒ  d |  j ƒ  d |  j ƒ  ƒ ƒ S(   NRÂ  R0   R�   Rç   R6   RÃ  (   RE  R   R   RÄ  R   Rç   R$   R�   (   R.   RÂ  RÆ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   phase_integrals“
  s    c         C   s@  |  j  ƒ  d  k	 s t ‚ t | t ƒ r` t j | j ƒ  |  j ƒ  ƒ d k sQ t ‚ | j  ƒ  } n  t j |  j  ƒ  ƒ } t | t j	 ƒ sŸ t | t j
 ƒ sŸ t ‚ t | t j	 ƒ rÃ t j | ƒ } n | } t j j d | d | ƒ } t j |  j  ƒ  ƒ } t j | ƒ } | d k st ‚ t j | | ƒ } | | d t j S(   Ni    t   phi1t   phi2i´   (   R�   R   R   R„   R   R	   t   orderR$   Rº  RŸ  RB  R‡  R„  t   phase_errorR«   R‹  R…  (   R.   R‘  R²  t   p2t   eR§   t   sum_wt   sum_we(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   mean_weighted_phase_error¢
  s    **c         C   sü   |  j  ƒ  d  k	 s t ‚ t | t ƒ r` t j | j ƒ  |  j ƒ  ƒ d k sQ t ‚ | j  ƒ  } n  t j |  j  ƒ  ƒ } t | t j	 ƒ sŸ t | t j
 ƒ sŸ t ‚ t | t j	 ƒ rÃ t j | ƒ } n | } t j t j j d | d | ƒ ƒ } | d t j S(   Ni    RÉ  RÊ  i´   (   R�   R   R   R„   R   R	   RË  R$   Rº  RŸ  RB  t   meanR‡  R„  RÌ  R…  (   R.   R‘  R²  RÍ  RÎ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   mean_phase_error´
  s    **$c         C   s¬   |  j  ƒ  s t ‚ | d k r? t j |  j ƒ  j ƒ  t ƒ } n  d d l } | d k rl | j	 d d ƒ } n  t
 j d |  j ƒ  d | d | d | d	 | ƒ } |  j d | ƒ S(
   s*   
    Add random error to reflections.
    iÿÿÿÿNi    i@B R�   RÀ   t   amplitude_errort   phase_error_degt   random_seed(   RC  R   R   R	   R)  R$   R'   R<   t   randomt   randintR"   t   randomize_amplitude_and_phaseR�   R¥   (   R.   RÔ  RÕ  RÀ   RÖ  R×  t   new_data(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÙ  Â
  s     ! 		c         C   s�   |  j  ƒ  d k	 s t ‚ |  j ƒ  \ } } | j d ƒ } | j | j  ƒ  ƒ } d } | j ƒ  d k	 r~ | j | j ƒ  ƒ } n  t t	 | | d t
 ƒ| | ƒ S(   sm   
    Returns an array object with DANO (i.e. F(+) - F(-)) as data, and
    optionally SIGDANO as sigmas.
    Rx  R&   N(   R�   R   R   RÍ   t   miller_indices_in_hemispheret   minusR¦   t   additive_sigmasR   R4   R,   (   R.   RÙ   RÚ   Rš   Rc   R‰   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   anomalous_differencesÓ
  s    c         C   sp   | d k s t  ‚ |  j ƒ  d  k	 s* t  ‚ |  j ƒ  \ } } d j | ƒ } | j d | j ƒ  j | ƒ d t ƒ S(   NRx  RM   s   +-RÀ   R&   (   Rx  RM   (	   R   R�   R   RÍ   R  RÅ   RÎ   R5  R,   (   R.   t   plus_or_minusRÙ   RÚ   t   i_column(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   hemisphere_acentricsá
  s    	c         C   sh   |  j  ƒ  d  k	 s t ‚ |  j ƒ  \ } } t g  d D]- } | j d | j ƒ  j | ƒ d t ƒ ^ q4 ƒ S(   Ni    i   RÀ   R&   (   i    i   (	   R�   R   R   RÍ   Rn   RÅ   RÎ   R5  R,   (   R.   RÙ   RÚ   Rà  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   hemispheres_acentricsê
  s
    c      	   C   s  |  j  ƒ  r |  j ƒ  s t ‚ | sÁ |  j ƒ  } | rW | j d | d | d | ƒ } n  | j ƒ  j ƒ  } | j t ƒ d k r‚ d S| j	 | ƒ } | j
 ƒ  }	 |  j ƒ  }
 t |
 j
 ƒ  |	 d ƒ S|  j ƒ  d k	 sÙ t ‚ g  } x~ |  j ƒ  j ƒ  D]j } |  j ƒ  j | ƒ } |  j	 | ƒ } |  j ƒ  j | ƒ \ } } | j | j d | d | d | ƒ ƒ qò Wt d |  j ƒ  d | d	 d
 ƒ S(   sÔ   
    Return the percent of acenric reflections with both h,k,l and -h,-k,-l
    observed (only meaningful for amplitude and intensity arrays).  By default
    this is calculated relative to the complete set.
    RÝ   R(   RB   i    g      ð?t   relative_to_complete_setR!   R�   R…   s   %5.3fN(   R&   RÐ   R   Rb  RC   RÆ   R�   R   R,   RÅ   R'   RÞ  Rù   R!   R   R8   RÀ   RW   R9   RÌ   R—   (   R.   RÂ   RB   RÝ   R(   Rã  R  RÆ   t   merged_acentrict
   n_acentrict
   anom_diffst   resultsR:   Rà   t	   array_selt	   d_max_bint	   d_min_bin(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÌ   ó
  s.    c         C   sD  |  j  ƒ  s |  S|  j ƒ  } |  j ƒ  d k	 r› | j ƒ  } |  j ƒ  j ƒ  } | j t ƒ } | d k r} |  j	 d | ƒ } n  | j
 ƒ  j ƒ  j t ƒ } n  |  j ƒ  d k	 r@| j  ƒ  r@| r@| j ƒ  \ } } | j ƒ  j ƒ  }	 | j ƒ  | }
 |
 d k r@|	 d |
 | k  r@|  j ƒ  j ƒ  } | j ƒ  j |  ƒ }  q@n  |  S(   s‘   
    Convert anomalous array into nonanomalous if the number of Bijvoet pairs is
    too small compared to the number of lone Bijvoet mates.
    i    RÀ   g      ð?N(   R&   R¡   R%   R   RÃ   RÄ   R�   R   R<   RÅ   RÆ   RÍ   RÎ   R'   RÏ   t   as_non_anomalous_arrayRa  R   R6  (   R.   t	   thresholdRÒ   RÃ   RÄ   RÓ   RÔ   RÙ   RÚ   t   n_pairst   n_lone_matesR  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt6   convert_to_non_anomalous_if_ratio_pairs_lone_less_than  s(      c   
      C   s¸  | s |  j  ƒ  d k	 s t ‚ | sE|  j |  j ƒ  d k ƒ } |  j ƒ  r[ | j ƒ  } n  | j ƒ  \ } } | j ƒ  j ƒ  | j ƒ  j ƒ  k s— t ‚ | j ƒ  j ƒ  d k r³ d St	 j
 t	 j | j ƒ  | j ƒ  ƒ ƒ } | d k sí t ‚ t	 j
 t	 j | j ƒ  ƒ t	 j | j ƒ  ƒ ƒ } | d k s0t ‚ t j d | | ƒ Sg  } xK |  j  ƒ  j ƒ  D]7 } |  j  ƒ  j | ƒ }	 | j |  j |	 ƒ j ƒ  ƒ q^Wt d |  j  ƒ  d | d d ƒ S(   s�  Get the anomalous signal according to this formula:

    .. math::
       \sqrt{\dfrac{<||F(+)|-|F(-)||^2>}{\frac{1}{2} (<|F(+)|>^2 + <|F(-)|>^2)}}

    :param use_binning: If 'True' the anomalous signal will be calculated for     each bin of the data set individually
    :type use_binning: boolean
    :returns: the anomalous signal
    :rtype: float or cctbx.miller.binned_data
    i    i   R!   R�   R…   s   %7.4fN(   R!   R   R   RÅ   R�   RÊ   Rv  Râ  R'   R	   RÒ  Rá  R„  R.  R8   RÀ   R9   RÑ   R—   (
   R.   RÂ   t   obst   f_plust   f_minust   mean_sq_difft   mean_sum_sqRç  R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÑ   +  s(    * ( c         C   s×  | | g j  t ƒ d k s! t ‚ |  j ƒ  rÏt d d ƒ } | j |  j ƒ  |  j ƒ  |  j ƒ  ƒ } | rå |  j	 ƒ  j ƒ  } t
 j t j d ƒ | ƒ } | j | d ƒ } t
 j t j d ƒ | ƒ } | j | d ƒ } | | } n  | s| rþ t
 j | ƒ S|  j d | ƒ } | SqÓ|  j ƒ  d
 k	 s/t ‚ g  }	 xu |  j ƒ  j ƒ  D]a }
 |  j ƒ  j |
 ƒ } | j | ƒ } d } | j ƒ  d k rœt
 j | ƒ } n  |	 j | ƒ qHWt d |  j ƒ  d |	 d d	 ƒ Sn d
 Sd
 S(   sT  Get phase entropy as measured in terms of an base-360 entropy
    (base-2 for centrics).

    An entropy of 0, indicates that the phase uncertainity is as low as possible
    An entropy of 1 however, indicates that the uncertainty is maximal:
    all phases are equally likely!

    :param return_binned_data: if 'True' you receive a binned object rather     then a raw array
    :type return_binned_data: boolean
    :param exponentiate: whether or not to exponentiate the entropy. This will     return a phase uncertainty in degrees (or the 'alphabet size')
    :type exponentiate: boolean
    i   RÂ  ih  g       @i    R�   R!   R…   s   %7.4fN(   R   R<   R   RE  t   phase_entropyt   relative_entropyRç   R$   R�   RÆ   R	   RÛ  R„  Râ  RC  RÒ  R   R!   R   R8   RÀ   RÅ   R'   R9   R—   (   R.   t   exponentiatet   return_binned_datat   return_meanRÆ  Rw   RÆ   t   cent   acent   binned_resultsR:   Rà   t   sel_dataRÒ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRõ  K  s6    !'"c         C   sÇ  |  j  ƒ  s t ‚ | s1 |  j ƒ  d	 k	 s1 t ‚ |  j ƒ  d	 k	 sI t ‚ t | ƒ } | sH|  j |  j ƒ  d k ƒ } |  j ƒ  r‘ | j	 ƒ  } n  | j ƒ  j
 ƒ  d k r­ | S| j ƒ  \ } } | j ƒ  j
 ƒ  | j ƒ  j
 ƒ  k sé t ‚ t j | j ƒ  | j ƒ  ƒ } t j | j ƒ  | j ƒ  | j ƒ  | j ƒ  ƒ } t j | d k ƒ j ƒ  }	 | j |	 d ƒ } | | }
 | j ƒ  j t j | j ƒ  d k ƒ j ƒ  d ƒ } | j ƒ  | } | j ƒ  j t j | j ƒ  d k ƒ j ƒ  d ƒ } | j ƒ  | } |
 | k | | k @| | k @j t ƒ } |
 j
 ƒ  d k rA| |
 j
 ƒ  S| Sn  g  } xW |  j ƒ  j ƒ  D]C } |  j ƒ  j | ƒ } | j |  j | ƒ j d | d | ƒ ƒ qaWt d |  j ƒ  d | d d ƒ S(
   s®   Fraction of reflections for which
    (:math:`\dfrac{|\Delta I|}{\sigma_{dI}}` > cutoff and
    :math:`min(\dfrac{I_{+}}{\sigma_{+}},\dfrac{I_{-}}{\sigma_{-}})` > cutoff
    i    i   t   cutoffR&  R!   R�   R…   s   %7.4fN(   R&   R   R!   R   R¦   R]  RÅ   R�   RË   R}  R'   Râ  R	   t   fabsR.  R)  RD  RC  R   R<   R8   RÀ   R9   t   measurabilityR—   (   R.   RÂ   Rþ  R&  Rð  t   i_plust   i_minust   topt   bottomt   zerosRc  t   i_plus_sigmat   i_minus_sigmat   measRç  R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR   |  s>     *3
33)R9  c         C   s®  |  j  ƒ  s t ‚ |  j |  j ƒ  d k ƒ } | d k rT |  j ƒ  rT | j ƒ  } n' | d k r{ |  j ƒ  r{ | j ƒ  } n  | j ƒ  \ } } | j ƒ  j	 ƒ  | j ƒ  j	 ƒ  k s· t ‚ | j ƒ  | j ƒ  d } t
 j | j ƒ  | j ƒ  ƒ } | r^|  j ƒ  d  k	 st ‚ t
 j | j ƒ  | j ƒ  ƒ }	 t
 j | j ƒ  | j ƒ  | j ƒ  | j ƒ  ƒ }
 t
 j |
 d k ƒ j ƒ  } |
 j | d ƒ }
 |	 |
 } | j ƒ  j t
 j | j ƒ  d k ƒ j ƒ  d ƒ }
 | j ƒ  |
 } | j ƒ  j t
 j | j ƒ  d k ƒ j ƒ  d ƒ }
 | j ƒ  |
 } | | k | | k @| | k @} | j | ƒ } | j | ƒ } n  | j	 ƒ  | j	 ƒ  k s|t ‚ | d k } | j | ƒ } | j | ƒ } | | S(   Ni    R7  R9  i   i   (   R&   R   RÅ   R�   RÊ   Rv  RË   R}  Râ  R'   R	   Rÿ  R¦   R   R.  R)  RD  RC  (   R.   t   obs_typet   measurable_onlyRþ  Rð  R  R  t   i_meant   d_anoR  R  R  Rc  R  R  R  t   non_zero_sele(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   bijvoet_ratios¤  s@    *
'' c         C   sô   | s |  j  ƒ  d k	 s t ‚ | s� |  j ƒ  j ƒ  d k rA d St j |  j ƒ  ƒ d } | d k rj d St j |  j ƒ  ƒ | Sg  } xK |  j  ƒ  j	 ƒ  D]7 } |  j  ƒ  j
 | ƒ } | j |  j | ƒ j ƒ  ƒ qš Wt d |  j  ƒ  d | d d ƒ S(   s   <data^2>/(<data>)^2i    i   R!   R�   R…   s   %7.4fN(   R!   R   R   R$   R'   R	   RÒ  R�   t   mean_sqR8   RÀ   R9   RÅ   t   second_momentR—   (   R.   RÂ   t   mean_data_sqRw   R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR  É  s       c         C   s  | s |  j  ƒ  d k	 s t ‚ d } |  j ƒ  rM |  j ƒ  } | j |  ƒ n |  } | sž | j ƒ  j ƒ  d k ru d St j	 | j
 ƒ  ƒ } | d k rš d S| Sg  } xK | j  ƒ  j ƒ  D]7 } | j  ƒ  j | ƒ } | j | j | ƒ j ƒ  ƒ q· Wt d | j  ƒ  d | d d ƒ S(   s   <F^2>i    R!   R�   R…   s   %7.4fN(   R!   R   R   RË   R}  Rù  R$   R'   R	   RÒ  R�   R8   RÀ   R9   RÅ   RÏ  R—   (   R.   RÂ   Rð  t	   mean_dataRw   R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÏ  ×  s$       c         C   si  | s |  j  d k	 s t ‚ | sð |  j ƒ  j ƒ  d k r> | Sd } |  j ƒ  rƒ |  j ƒ  rk |  j ƒ  } n  |  j ƒ  rƒ |  } qƒ n  | d k	 ré | j	 | j
 ƒ  d k ƒ } | j ƒ  j ƒ  d k rÆ | St j | j ƒ  | j
 ƒ  ƒ } | Sd Sn  g  } xQ |  j  ƒ  j ƒ  D]= } |  j  ƒ  j | ƒ } | j |  j	 | ƒ j d | ƒ ƒ q	Wt d |  j  ƒ  d | d d ƒ S(   s   <I/sigma_I>i    R&  R!   R�   R…   s   %7.4fN(   R!   R   R   R$   R'   RÐ   RË   R}  RÊ   RÅ   R¦   R	   RÒ  R�   R8   RÀ   R9   t   i_over_sig_iR—   (   R.   RÂ   R&  Rð  t   i_sig_iRw   R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR  ë  s0      &c         C   s>  | s |  j  d k	 s t ‚ | sÅ |  j ƒ  j ƒ  d k r> | Sd } |  j ƒ  rƒ |  j ƒ  rk |  j ƒ  } n  |  j ƒ  rƒ |  } qƒ n  | d k	 r¾ t	 j
 | j ƒ  | j ƒ  j ƒ  j ƒ  ƒ } | S| Sn  g  } xQ |  j  ƒ  j ƒ  D]= } |  j  ƒ  j | ƒ } | j |  j | ƒ j d | ƒ ƒ qÞ Wt d |  j  ƒ  d | d d ƒ S(   s    <I/epsilon> i    R&  R!   R�   R…   s   %7.4fN(   R!   R   R   R$   R'   RÐ   RË   R}  RÊ   R	   RÒ  R�   Rð   RF  R8   RÀ   R9   RÅ   t$   mean_of_intensity_divided_by_epsilonR—   (   R.   RÂ   R&  Rð  t   weighted_meanRw   R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR    s.     c         C   sæ   | s |  j  d k	 s t ‚ | sm |  j ƒ  j ƒ  d k r> | St j |  j ƒ  |  j ƒ  j ƒ  j	 ƒ  ƒ } | Sg  } xQ |  j  ƒ  j
 ƒ  D]= } |  j  ƒ  j | ƒ } | j |  j | ƒ j d | ƒ ƒ q† Wt d |  j  ƒ  d | d d ƒ S(   s    <sigma^2/epsilon> i    R&  R!   R�   R…   s   %7.4fN(   R!   R   R   R¦   R'   R	   RÒ  Rð   R�   RF  R8   RÀ   R9   RÅ   t(   mean_of_squared_sigma_divided_by_epsilonR—   (   R.   RÂ   R&  R  Rw   R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR  #  s     c         C   sG   |  j  ƒ  r |  } n" |  j ƒ  } | r7 | j |  ƒ n  | j d | ƒ S(   s7   <I^2>/(<I>)^2 (2.0 for untwinned, 1.5 for twinned data)RÂ   (   RÊ   R}  Rú  R  (   R.   RÂ   R‰  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   second_moment_of_intensities8  s    	c         C   sÙ   |  j  ƒ  s |  } n" |  j ƒ  } | r7 | j |  ƒ n  | j d | ƒ } | d k rY d S| sg d | Sg  } xJ | j D]? } | d k s• | d k r¥ | j d ƒ qw | j d | ƒ qw Wt d | j ƒ  d | d d ƒ S(	   s;   (<F>)^2/<F^2> (0.785 for untwinned, 0.885 for twinned data)RÂ   i   i    R!   R�   R…   s   %7.4fN(	   RÊ   Rv  Rú  R  R   R�   R9   R—   R!   (   R.   RÂ   R‰  R  Rw   t   sm(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   wilson_ratioB  s     	   i
   t   usedc      	   C   sm  |  j  ƒ  s t ‚ | d k s$ t ‚ | | d IJ| d  k	 rQ |  j d | ƒ n |  j ƒ  d  k	 si t ‚ g  } g  } d  } xet |  j ƒ  d | ƒ ƒ  D]G} |  j ƒ  j | ƒ }	 |  j ƒ  j |	 ƒ }
 |
 j	 t
 ƒ } |
 j ƒ  | } | j | ƒ | j | ƒ |  j ƒ  j | ƒ } | d  k r˜t d t t |  j ƒ  j ƒ  ƒ ƒ ƒ } d | } | | d Id t | ƒ I| d	 I| d
 Id IJd | } n  | | d I| I| | I| | Id d | t d | | ƒ IJq˜ W|  j ƒ  j	 t
 ƒ } |  j ƒ  j ƒ  | } | | d Id t | ƒ d I| | I| | Id d | t d | | ƒ IJ| | f S(   NR  Rb  s.   Number of work/free reflections by resolution:RÁ   t   range_i   s   %%%dsRL   t   workt   frees    %frees   %%%dds   %5.1f%%g      Y@i   t   overall(   R  s   all(   R@  R   R   RÈ   R!   t   getattrRÀ   R�   RÅ   R   R<   R'   R9   Rz   RQ   RR   RS   R$   (   R.   RÁ   t   binner_rangeRß   R   t   n_workst   n_freesR¼   R:   Rà   t   flagst   n_freet   n_workRˆ   t   width(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   show_r_free_flags_infoS  s>    #'
(#(c         C   s¹   |  j  ƒ  s t ‚ t j d d ƒ } t j d d ƒ } |  j ƒ  } | j ƒ  } d } xO t | ƒ D]A \ } } | ra | d 7} | j | d ƒ | j | | ƒ qa qa Wt	 d | d | ƒ S(   Ni   i    t   reflection_countst   free_fractions(
   R@  R   R	   Re  RB  R�   R'   Rª   R9   R   (   R.   t   rct   ffRc   R`   t   cRš   R~   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   r_free_flags_accumulationy  s    
c         C   s:  | s |  j  ƒ  d k	 s t ‚ |  j ƒ  d k sO |  j ƒ  sO |  j ƒ  sO t ‚ | j ƒ  d k s | j ƒ  s | j ƒ  s t ‚ | j ƒ  j ƒ  |  j ƒ  j ƒ  k s© t ‚ | sµ|  j ƒ  j ƒ  d k rË d S| rá |  | } } n |  j	 d | d t
 ƒ \ } } t j | j ƒ  ƒ } t j | j ƒ  ƒ } | t k rut j | | ƒ } | d k rŽ| t j | | ƒ | 9} qŽn | d k	 rŽ| | 9} n  t j t j | | ƒ ƒ t j | ƒ Sg  } x] |  j  ƒ  j ƒ  D]I }	 |  j  ƒ  j |	 ƒ }
 | j |  j |
 ƒ j | j |
 ƒ | | ƒ ƒ qÎWt d |  j  ƒ  d | d d ƒ S(	   sÙ   Get the R1 factor according to this formula

    .. math::
       R1 = \dfrac{\sum{||F| - k|F'||}}{\sum{|F|}}

    where F is self.data() and F' is other.data() and
    k is the factor to put F' on the same scale as Fi    R    R8  R!   R�   R…   s   %7.4fN(   R!   R   R   R4  RC  RË   R$   R'   R�   R9  R<   R	   R«   R   R‹  R8   RÀ   R9   RÅ   t	   r1_factorR—   (   R.   R    RŽ  t   assume_index_matchingRÂ   R�  R-  R�  Rç  R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR/  ‡  s6    	* !'c         C   sÝ   |  j  ƒ  d k	 s t ‚ | d k r3 |  j ƒ  } n  | rC | } n  |  j  ƒ  j | ƒ } d } |  j ƒ  d k	 rˆ |  j ƒ  j | ƒ } n  d } |  j ƒ  d k	 r¸ |  j ƒ  j | ƒ } n  t t |  | | ƒ | | ƒ j	 |  ƒ S(   s  
    Select a sub-array.

    :param selection: flex.bool or flex.size_t selection
    :param negate: select the inverse of the selection array
    :param anomalous_flag: anomalous flag for the new set
    :returns: a new array with a subset of indices and data/sigmas
    N(
   R$   R   R   R&   RÅ   R�   R¦   R   R4   R6  (   R.   RÀ   R+  R&   Rš   Rc   R‰   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÅ   ¬  s    	 
  c         C   sÅ   | rL | j  ƒ  } t |  j ƒ  j ƒ  t | ƒ t |  j ƒ  j ƒ  | ƒ } n t |  j ƒ  | ƒ } y  |  j | j d ƒ d | ƒSWn= t	 k
 rÀ } d t
 | ƒ k r´ t	 d ƒ ‚ qÁ t	 | ‚ n Xd  S(   Ni    R+  s<   CCTBX_ASSERT(miller_indices_[1].size() == size_processed(1))s\   cctbx.miller.array.select_indices(): This method can only be used reliably on a merged array(   R¤   R  Rç   R   R<   R3  R$   RÅ   t   pair_selectionRp  RS   (   R.   R$   t   map_indices_to_asuR+  t   matched_indicesRÎ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   select_indicesÀ  s     c         C   se   |  j  ƒ  d k	 s t ‚ |  j ƒ  d k	 s0 t ‚ t j |  j  ƒ  ƒ |  j ƒ  | k } |  j | | ƒ S(   s–   
    Return a copy of the array filtered to remove reflections whose value is
    less than cutoff_factor*sigma (or the reverse, if negate=True).
    N(   R�   R   R   R¦   R	   R«   RÅ   (   R.   t   cutoff_factorR+  R$  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   sigma_filterÒ  s    %c         C   s›   d  } |  j ƒ  } | d  k	 r— | j ƒ  d k r— t j | ƒ d k rN d } q— | j d ƒ } | sr | sr t ‚ n  | r— t j |  j ƒ  | ƒ } q— n  | S(   Ni    g        (   R   R¦   R'   R	   Rù   t   all_neR   R�   (   R.   t   return_none_if_zero_sigmasRw   R¦   t   sigmas_all_not_equal_zero(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   min_f_over_sigmaÜ  s    	c         C   sï   | | g j  d ƒ d k s! t ‚ |  j ƒ  d k	 s9 t ‚ d } | d k	 rŒ t j t j |  j ƒ  ƒ ƒ } | d k r |  j ƒ  S| | } n  |  j ƒ  | } |  j ƒ  d k	 rÁ |  j ƒ  | } n  |  j	 d | d | ƒ j
 |  j ƒ  ƒ j |  ƒ S(   s2  
    Apply a scale factor to the data (and optionally sigmas).

    :param target_max: target maximum value for the scaled data - the scale
                       factor will be determined automatically
    :param factor: explicit scale factor
    :returns: custumozed copy with scaled data and sigmas
    i   i    R�   R¦   N(   R   R   R   R�   R	   RQ   R«   R¤   R¦   R¥   R1  R0  R6  (   R.   t
   target_maxt   factorR‰   t   current_maxRc   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   apply_scalingê  s    	! 
 c   
      C   s®  | d  k r! | j ƒ  j ƒ  } n  |  j ƒ  j | j ƒ  ƒ sB t ‚ |  j | ƒ sW t ‚ |  j d | ƒ | j |  ƒ t j	 |  j ƒ  j ƒ  d ƒ } xØ |  j
 ƒ  j ƒ  D]Ä } |  j
 ƒ  j | ƒ } |  j | ƒ } | j | ƒ } d } t j t j | j ƒ  ƒ t j | j ƒ  ƒ ƒ }	 |	 d k rYt j t j | j ƒ  ƒ t j | j ƒ  ƒ ƒ |	 } n  | j | | ƒ q¥ W| d k j t ƒ | j ƒ  k s”t ‚ | j d | j ƒ  | ƒ S(   NRÜ   iÿÿÿÿg      ð?i    R�   (   R   R$   R'   R  R   R2  RÈ   Rù  R	   RB  R!   Rƒ   RÀ   RÅ   R‹  R«   R�   RC  R   R<   R   (
   R.   R    RÜ   R¶   R:   Rà   t   f1t   f2t   scale_R�  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   multiscale   s$    !18'i2   c
         C   s“   |  j  d | d | d | d | d | d | d | d |	 ƒ j ƒ  }
 |  j ƒ  |
 } |  j ƒ  } | d k	 r} | r} | |
 } n  |  j d	 | d
 | ƒ S(   si  
    Given an isotropic or anisotropic displacement or B-factor, apply
    resolution-dependent scale factors to the data (and optionally sigmas).

    :param u_iso: Isotropic displacement (in Angstroms)
    :param b_iso: Isotropic B-factor (8*pi^2*u_iso^2)
    :param u_cart: Anisotropic displacement tensor
    :param b_cart: Anisotropic B-factor
    :param u_star: Anisotropic displacement tensor in fractional space
    :param u_cif: Anisotropic displacement tensor, dimensionless basis
    :param apply_to_sigmas: Also scale sigma values (if present)
    :returns: cctbx.miller.array object with scaled data
    R  R  R  R  R  R  R  R  R�   R¦   N(   R  R�   R¦   R   R¥   (   R.   R  R  R  R  R  R  t   apply_to_sigmasR  R  t   dwsRc   R‰   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   apply_debye_waller_factors  s    	c   	   	   C   sˆ  | t  k s | t  k s t ‚ | sñ |  j ƒ  j ƒ  d k r@ d  S| r’ | r’ | sg t j |  j ƒ  ƒ St j |  j ƒ  |  j ƒ  j ƒ  j	 ƒ  ƒ Sn  | s° t j
 |  j ƒ  ƒ } n* t j |  j ƒ  |  j ƒ  j ƒ  j	 ƒ  ƒ } | rí t j | ƒ S| S|  j ƒ  d  k	 s	t ‚ g  } x] |  j ƒ  j ƒ  D]I } |  j ƒ  j | ƒ } | j |  j | ƒ j d | d | d | ƒ ƒ q"Wt d |  j ƒ  d | ƒ S(   Ni    t   use_multiplicitiest   squaredt   rmsR!   R�   (   R,   R   R�   R'   R   R	   RÒ  R»  Rî   RF  R  t   mean_sq_weightedR„  R.  R!   R8   RÀ   R9   RÅ   R—   (	   R.   RÂ   RF  RG  RH  Rw   R�   R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÒ  6  s6     		 c         C   s   |  j  d | d | d t ƒ S(   NRÂ   RF  RG  (   RÒ  R<   (   R.   RÂ   RF  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR  W  s    	c         C   s–   |  j  d | d | d | ƒ } | s2 |  j ƒ  | S|  j ƒ  j ƒ  } xG |  j ƒ  j ƒ  D]3 } | j | d  k	 rW | j | c | | 9<qW qW W| Sd  S(   NRÂ   RF  RG  (   RÒ  R'   R!   t   countsRƒ   R�   R   (   R.   RÂ   RF  RG  RÒ  RJ  Rš   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR‹  ]  s    		c         C   s   |  j  d | d | d t ƒ S(   NRÂ   RF  RG  (   R‹  R<   (   R.   RÂ   RF  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   sum_sqk  s    	c         C   s   |  j  d | d | d t ƒ S(   NRÂ   RF  RH  (   RÒ  R<   (   R.   RÂ   RF  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRH  q  s    	c   	      C   s®   |  j  d | d | ƒ } t j |  j ƒ  ƒ } | sF | | | k } nX |  j ƒ  } xI |  j ƒ  j ƒ  D]5 } | |  j ƒ  j | ƒ | | | j | k BM} qe W|  j | | ƒ S(   NRÂ   RF  (	   RH  R	   R«   R�   R*  R!   Rƒ   RÀ   RÅ   (	   R.   R5  RÂ   RF  R+  RH  t   abs_datat   keepR:   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   rms_filterw  s    		i    c         C   sã   | s6 t  |  j ƒ  |  j ƒ  |  j ƒ  |  j ƒ  ƒ } n© t j ƒ  } xš |  j ƒ  j ƒ  D]† } |  j ƒ  j	 | ƒ } | j
 t ƒ d k r• | j d ƒ qU | j t  |  j ƒ  |  j ƒ  |  j ƒ  j | ƒ |  j ƒ  j | ƒ ƒ ƒ qU W| S(   Ni    (   t   statistical_meanRç   R&   R$   R�   R	   RB  R!   Rƒ   RÀ   R   R<   R9   RÅ   (   R.   RÂ   Rw   R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRO  ‰  s    -	c   
      C   s%  |  j  ƒ  d  k	 s t ‚ |  j ƒ  j ƒ  |  j ƒ  j ƒ  k sB t ‚ d } g  } x¡ |  j  ƒ  j ƒ  D]� } |  j  ƒ  j | ƒ } |  j ƒ  j | ƒ } | j	 | ƒ } | r¹ | j ƒ  | } n  t
 | | ƒ } | j | | t
 d | j ƒ  ƒ f ƒ qa Wd t d | ƒ }	 t d |  j  ƒ  d | d |	 ƒ S(   Ni    i   s   %%%dd %%6.4fs   %dR!   R�   R…   (   R!   R   R   R�   R'   R$   R8   RÀ   RÅ   R   RQ   R9   RR   R—   (
   R.   t   data_value_to_countt   count_not_equalt   max_nRç  R:   Rà   t   data_selR`   R…   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   count_and_fraction_in_binsš  s    * *c         C   sÇ   |  j  ƒ  d  k s$ |  j ƒ  s$ t ‚ |  j d t ƒ } |  j ƒ  j ƒ  } xo |  j ƒ  j	 ƒ  D][ } |  j ƒ  j
 | ƒ } | j ƒ  d k r[ | j | |  j ƒ  j | ƒ | | d ƒ q[ q[ Wt |  | ƒ S(   NRÂ   i    i   (   R4  R   RÊ   R   RO  R<   R�   R¤   R!   Rƒ   RF   R'   RC  RÅ   R   (   R.   t   s_meanR£  R:   Rà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   remove_patterson_origin_peak«  s    $,c         C   s\   |  j  ƒ  d  k s$ |  j ƒ  s$ t ‚ t d |  d |  j ƒ  t j |  j ƒ  j ƒ  j	 ƒ  ƒ ƒ S(   NR0   R�   (
   R4  R   RË   R   R   R�   R	   R.  Rð   RF  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   quasi_normalized_as_normalized¶  s    $c   
      C   s}  |  j  ƒ  d k	 s t ‚ |  j  ƒ  j ƒ  d k s6 t ‚ |  j ƒ  j d ƒ sQ t ‚ |  j ƒ  d k su |  j ƒ  su t ‚ |  j ƒ  j ƒ  j	 ƒ  } t
 j ƒ  } xž |  j  ƒ  j ƒ  D]Š } |  j  ƒ  j | ƒ } t
 j |  j ƒ  j | ƒ ƒ } | j ƒ  d k r)| j | ƒ } | | } | j t
 j | ƒ ƒ q¬ | j d ƒ q¬ W|  j  ƒ  j | | ƒ }	 |	 j d ƒ sgt ‚ t |  t
 j |	 ƒ ƒ S(   s   A miller.array whose data N(h) are the normalisations to convert
    between locally normalised E's and F's:
    E(h) = F(h) / N(h)

    self features the F's, which are then binned with the current binner
    and N(h) is the average of F's in the bin h belongs to.
    i    N(   R!   R   R   RK   R�   R-  R4  RË   Rð   RF  R	   RB  Rƒ   RÀ   Rá  RÅ   R'   R9   RÒ  t   interpolatet   all_gtR   R.  (
   R.   t   d_star_powerRð   t   mean_f_sq_over_epsilonR:   Rà   t   sel_f_sqt   sel_epsilonst   sel_f_sq_over_epsilont   mean_f_sq_over_epsilon_interp(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   amplitude_quasi_normalisations¼  s$    $
c         C   s2   |  j  | ƒ } |  j ƒ  | j ƒ  } t |  | ƒ S(   N(   R`  R�   R   (   R.   RZ  RÍ  t   q(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt!   quasi_normalize_structure_factorsØ  s    c   
      C   s  |  j  ƒ  j ƒ  | j  ƒ  j ƒ  k s* t ‚ |  j  ƒ  j ƒ  | j  ƒ  j ƒ  k sT t ‚ |  j ƒ  sf t ‚ | j ƒ  sx t ‚ | d  k	 rÃ | j ƒ  s– t ‚ |  j  ƒ  j ƒ  | j  ƒ  j ƒ  k sÃ t ‚ n  |  j d |  j ƒ  ƒ j d | ƒ j ƒ  } t	 j
 | j ƒ  ƒ } | | } | d  k	 r+| | j ƒ  } n  | d  k rkt	 j t	 j |  j ƒ  ƒ t	 j |  j ƒ  ƒ ƒ } nE t	 j | j ƒ  | j ƒ  t	 j |  j ƒ  ƒ t	 j |  j ƒ  ƒ ƒ } t	 j t	 j | j ƒ  ƒ t	 j | j ƒ  ƒ ƒ } t j | | ƒ }	 |	 d k st ‚ |  j d | |	 ƒ S(   NR�   R‘  i    (   R$   R'   R   RÐ   RC  R   R   R�   R’  R	   RJ  R‹  R«   R„  R.  (
   R.   R‘  RÕ  t   fomR?  R@  t   coefft   f3t   f4R�  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt!   phased_translation_function_coeffÝ  s*    **-
4,1c         C   s%   t  |  t j |  j ƒ  ƒ |  j ƒ  ƒ S(   s™   
    Return a copy of the array with data replaced by absolute values, i.e.
    complex arrays will be converted to amplitudes.  Enables abs(array).
    (   R   R	   R«   R�   R¦   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __abs__õ  s    c         C   s:   t  |  j ƒ  t j ƒ s t ‚ t |  t j |  j ƒ  ƒ ƒ S(   N(   R„   R�   R	   RŸ  R   R   t   norm(   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRi  ü  s    c         C   s   t  |  t j |  j ƒ  | ƒ ƒ S(   N(   R   R	   Rº  R�   (   R.   Ri   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRº     s    c         C   s@   t  |  j ƒ  t j ƒ s t ‚ |  j ƒ  d k s6 t ‚ t |  ƒ S(   s?   
    For a complex array, return array of absolute values.
    N(   R„   R�   R	   RŸ  R   R¦   R   R«   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   amplitudes  s    c         C   s@   t  |  j ƒ  t j ƒ s t ‚ |  j ƒ  d  k s6 t ‚ |  j ƒ  S(   N(   R„   R�   R	   RŸ  R   R¦   R   Ri  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   intensities  s    c         C   sC   t  |  j ƒ  t j ƒ s t ‚ |  j ƒ  d k s6 t ‚ |  j | ƒ S(   sV   
    For a complex array, return the array of its phases (in radians by default).
    N(   R„   R�   R	   RŸ  R   R¦   R   Rº  (   R.   Ri   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRƒ    s    t   gaussianc         C   s   t  |  | d | d | ƒS(   sã   
    Given a non-unique array, merge the symmetry-related reflections (keeping
    anomalous flag).

    :returns: a merge_equivalents object, from which the merged array may     be extracted by calling the array() method.
    t   incompatible_flags_replacementt   use_internal_variance(   Ra  (   R.   R¾  Rm  Rn  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRa    s    
	c         C   s4   t  d |  j ƒ  d |  j ƒ  d |  j ƒ  ƒ j |  ƒ S(   NR0   R�   R¦   (   R   R  R�   R¦   R6  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRë  '  s    c         C   sf   |  j  ƒ  s |  j ƒ  rL |  j ƒ  j ƒ  j ƒ  j ƒ  j d |  ƒ j ƒ  j ƒ  S|  j ƒ  j ƒ  j ƒ  Sd S(   sg   
    Given an anomalous array, merge the anomalous pairs and return the
    non-anomalous average.
    R1   N(   RC  RE  R¨   Rë  Ra  R   R¥   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRb  -  s    !c         C   sÃ  |  j  d | ƒ j ƒ  } | j t ƒ } | d k r7 |  S| d k	 rÝ | rR d } n d } t |  j ƒ  t j ƒ sˆ t |  j ƒ  t j ƒ r¦ t j	 |  j ƒ  ƒ } d } n d } d } | | d | | t
 | ƒ d | f IJn  |  j d	 | ƒ }	 | d k	 r¿| d k	 r¸| | d
 IJt j | j | ƒ ƒ }
 | | d |
 IJ| | j ƒ  k r¸t j | j | ƒ ƒ } | | d | IJ| d k rµ| |
 d k rµ| | d |
 | IJqµq¸n  | Jn  |	 S(   sf   
    Remove all reflections which should be systematically absent in the current
    space group.
    Rê   i    s	   integral R{   R&  t   .s$   Removing %d %ssystematic absence%s%si   RÀ   s     Average absolute value of:s       Absences: %.6gs         Others: %.6gg#B’¡œÇ;s          Ratio: %.6gN(   RÄ   R�   R   R<   R   R„   R	   RB  RŸ  R«   R   RÅ   RÒ  R'   (   R.   Rê   Râ  R   RÄ   R`   Ra  t   data_absR-  Rw   t   mean_absencest   mean_others(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   eliminate_sys_absent>  s>    	  		
!
c         C   s"   |  j  d |  j d | ƒ j ƒ  ƒ S(   NRÀ   Rê   (   RÅ   RÄ   R�   (   R.   Rê   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   select_sys_absentb  s    c         C   s;  |  j  ƒ  d k	 s t ‚ |  j ƒ  d k	 s0 t ‚ t | ƒ t |  ƒ k r_ t |  |  j ƒ  | ƒ S| j  ƒ  d k	 sw t ‚ | j ƒ  d k	 s� t ‚ t |  j  ƒ  | j  ƒ  ƒ } | j d ƒ } | j |  j ƒ  | j ƒ  ƒ } d } |  j	 ƒ  d k	 r"| j	 ƒ  d k	 r"| j
 |  j	 ƒ  | j	 ƒ  ƒ } n  t t |  | ƒ | | ƒ S(   s   Overload the '+' operator.i    N(   R$   R   R   R�   R   R   R3  t   paired_miller_indicest   plusR¦   RÝ  R4   (   R.   R    t   matchRš   Rc   R‰   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __add__f  s    $!c         C   so   |  j  ƒ  d  k	 s t ‚ |  j ƒ  d  k	 s0 t ‚ |  j ƒ  } | | 9} |  j ƒ  } | d  k	 rk | | 9} n  |  S(   N(   R$   R   R   R�   R¦   (   R.   R    R�   R¦   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __imul__x  s    
 c         C   sj   t  | t ƒ rP |  j ƒ  j | j ƒ  ƒ s0 t ‚ |  j d |  j ƒ  | j ƒ  ƒ S|  j ƒ  } | | 9} | S(   NR�   (   R„   R   R$   R  R   R¥   R�   R¤   (   R.   R    Rw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __mul__�  s    ! 
c         C   so   |  j  ƒ  d  k	 s t ‚ |  j ƒ  d  k	 s0 t ‚ |  j ƒ  } | | } |  j ƒ  } | d  k	 rk | | } n  |  S(   N(   R$   R   R   R�   R¦   (   R.   R    R�   R¦   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __itruediv__‰  s    
 c         C   s   |  j  ƒ  } | | } | S(   s/    This requires from __future__ import division (   R¤   (   R.   R    Rw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   __truediv__’  s    
c         C   s>   |  j  | g ƒ } t | j ƒ  ƒ d k s0 t ‚ | j ƒ  d S(   sA   Extract the value of the array for the specified reflection h,k,li   i    (   R4  RR   R�   R   (   R.   R  t	   hkl_array(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   value_at_index˜  s    c         C   s   |  j  |  j | ƒ S(   s,  
    Returns the value of data of the first index matching
    `miller_index`. If the `miller_index` is not found in `self`,
    then returns ``None``.

    :param miller_index: Miller index as a 3-tuple
    :type miller_index: tuple
    :returns: int, float, complex, None -- data value or None
    (   R   R,  (   R.   Rþ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   data_at_first_indexž  s    
c         C   s(   |  j  d k	 s t ‚ |  j |  j  | ƒ S(   s0  
    Returns the value of sigmas of the first index matching
    `miller_index`. If the `miller_index` is not found in `self`,
    then returns ``None``.

    :param miller_index: Miller index as a 3-tuple
    :type miller_index: tuple
    :returns: int, float, complex, None -- sigmas value or None
    N(   R-  R   R   R   (   R.   Rþ   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   sigma_at_first_indexª  s    
c      	   C   sY  |  j  ƒ  r |  S|  j ƒ  j ƒ  } |  j ƒ  j ƒ  } | j | j | ƒ ƒ d } d } |  j ƒ  d k	 rî |  j ƒ  j ƒ  } |  j ƒ  rª | j t	 j
 | j | ƒ ƒ ƒ qî |  j ƒ  rÕ | j | j | ƒ j
 ƒ  ƒ qî | j | j | ƒ ƒ n  |  j ƒ  d k	 r+|  j ƒ  j ƒ  } | j | j | ƒ ƒ n  t d t d |  d | d t ƒ d | d | ƒ S(   sp   
    If the array is not already anomalous, expand to generate anomalous pairs
    (without changing data).
    R0   R1   R$   R&   R�   R¦   N(   R&   RÆ   R�   R$   R¤   Rg  RÅ   R   RC  R	   RJ  RE  R¦   R   R4   R<   (   R.   Rà   R$   R�   R¦   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRi  ·  s0     "	c   	      C   sº  | r |  j  | ƒ s t ‚ n  |  j ƒ  s0 t ‚ | j ƒ  sB t ‚ | sa |  j ƒ  d k	 sa t ‚ |  } | j ƒ  r� | j ƒ  r� | j ƒ  } n( | j ƒ  r· | j ƒ  r· | j ƒ  } n  | j d | d | ƒ \ } } | s÷ t j	 | j
 ƒ  | j
 ƒ  ƒ S| j |  ƒ g  } xŽ |  j ƒ  j ƒ  D]z } | j ƒ  j | ƒ } t j	 | j
 ƒ  j | ƒ | j
 ƒ  j | ƒ ƒ } | j ƒ  s„| j d ƒ q| j | j ƒ  ƒ qWt d | j ƒ  d | d d ƒ S(   sÛ  
    Calculate correlation coefficient between two arrays (either globally or
    binned).

    :param other: another array of real numbers
    :param use_binning: calculate CC in resolution bins (default = calculate
                         a single global value)
    :param assert_is_similar_symmetry: check that arrays have compatible
                                       crystal symmetry
    :returns: a Python float (if use_binning=False), or a binned_data object
    R    R4  R!   R�   R…   s   %6.3fN(   R2  R   RÐ   R!   R   R&   Ri  R9  R	   t   linear_correlationR�   Rù  R8   RÀ   RÅ   t   is_well_definedR9   t   coefficientR—   (	   R.   R    RÂ   R4  t   lhsR�   R:   Rà   t   correlation(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR…  Õ  s2    	 c         C   s™  | d k r t j } n  |  j ƒ  j ƒ  |  j ƒ  j ƒ  k sB t ‚ |  j ƒ  r¸ | d k	 r¸ x8t |  j ƒ  |  j ƒ  ƒ D]; \ } } | | t	 | ƒ I| It
 j | d | ƒIJqv WnÝ |  j ƒ  d k rxÈ t |  j ƒ  |  j ƒ  ƒ D]& \ } } | | t	 | ƒ I| IJqæ Wn‚ |  j ƒ  j ƒ  |  j ƒ  j ƒ  k s=t ‚ xU t |  j ƒ  |  j ƒ  |  j ƒ  ƒ D]/ \ } } } | | t	 | ƒ I| I| IJqbW|  S(   s"   Listing of Miller indices and dataRi   N(   R   R|   R}   R�   R'   R$   R   RC  R%  RS   R   t   abs_argR¦   (   R.   R~   R   Ri   R±   Rc   R‰   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt
   show_arrayý  s     *(6(!*4$c         C   s©   t  j |  j ƒ  ƒ } t  j | j ƒ  ƒ } |  j ƒ  j ƒ  } | j ƒ  j ƒ  } t j t  j | ƒ t  j | ƒ ƒ } | d k r¥ t  j | | t  j | | ƒ ƒ | Sd  S(   Ni    (
   R	   R«   R�   Rƒ  R„  R.  RK  R‹  t   cosR   (   R.   R    Rê  Rë  R²  RÍ  R<  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   map_correlation  s    %&i   i   c
   
      C   sr   | d k	 r% t d | d |  d |	 ƒ St d |  j d | d | d | d | d | d	 | d
 | ƒ d |  d |	 ƒ Sd S(   sa  
    Calculate the FFT for the array, assuming the data are complex doubles.

    :param resolution_factor: when multiplied times the resolution limit, gives
                              the approximate grid spacing of the map.
    :param d_min: High-resolution cutoff
    :param crystal_gridding: optional gridding to use (overrides automatic
                             gridding)
    :param symmetry_flags: specifies how the grid should be constructed to
                           handle symmetry
    :param f_000: Optional F(0,0,0) value (scalar added to entire map)
    :returns: an fft_map object
    R˜  t   fourier_coefficientst   f_000R(   R’  R™  R”  R•  R–  R—  N(   R   t   fft_mapR˜  (
   R.   R’  R(   R™  R˜  R”  R•  R–  R—  R‹  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRŒ    s     		c         C   s¶   |  j  ƒ  s t ‚ |  } |  j ƒ  j ƒ  j ƒ  d k rE | j ƒ  } n  | j ƒ  s` | j ƒ  } n  t j	 d | j
 ƒ  d | j ƒ  d | ƒ } | d k	 rž | | S| |  j ƒ  j ƒ  Sd S(   s©   
    Calculates the exact map value at the specified fractional coordinate
    using direct Fourier summation.  Relatively slow but avoids interpolation
    errors.
    i   R6   R�   t	   site_fracN(   RC  R   R%   R   t   numberR¨   R&   Ri  R   t   direct_summation_at_pointR$   R�   R   R2   R©  (   R.   R�  t   sigmat
   map_coeffsR‹  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR�  ?  s    		id   c         C   sÅ  t  |  j ƒ  t j ƒ s t ‚ |  j ƒ  } | j |  ƒ } |  j d | ƒ g  } x¢ |  j ƒ  j	 ƒ  D]Ž } |  j ƒ  j
 | ƒ } |  j ƒ  j d | d t d t ƒ } |  j d | ƒ } | j ƒ  \ }	 }
 t j | j ƒ  ƒ } | j |	 |
 | g ƒ qb Wt j ƒ  } t j ƒ  } x‚ t | j ƒ  j ƒ  | j ƒ  ƒ D]_ \ } } xP | D]H } | | d k rA| | d k rA| j | d ƒ | j | ƒ PqAqAWq.Wt |  | d	 t ƒ} t | | ƒ } |  j d
 | ƒ S(   NRÜ   R:   Ro   Rr   RÀ   i   i    i   R&   R    (   R„   R�   R	   RB  R   RC   R;  RÈ   R!   Rƒ   RÀ   Rz   R,   RÅ   RÕ   RÒ  R9   Rþ   R%  Ró   R$   R4   R   Rœ  (   R.   RÜ   R©  t   lsRw   R:   Rà   Rä   t   sselRÝ   R(   t	   data_meant	   data_loneR$   Rc   Rµ   Ru  t   lmst   la(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   complete_with_bin_averageT  s0    . g      Ð?c      	   C   sŸ   |  j  ƒ  s t ‚ |  j d | ƒ } | j ƒ  | j ƒ  } t j d | d | d | ƒ |  } | d  k	 r} |  j d | ƒ } n  | j	 d | d t
 d t d	 t ƒ S(
   NR’  R�   t
   mean_scalet   n_iterationsR(   R®  R°  R&   R±  (   RC  R   RŒ  t   apply_volume_scalingt   real_map_unpaddedR   t   hoppe_gassman_modificationR   RC   R³  R<   R,   (   R.   R™  Rš  R’  R(   RŒ  t   map_dataR[  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   hoppe_gassmann_modificationn  s    
 	g      @c      	   C   sŒ  |  j  ƒ  s t ‚ |  j d | ƒ } | j ƒ  | j ƒ  } | j ƒ  } ~ t j | j ƒ  ƒ }	 t j	 | j ƒ  ƒ }
 |	 |
 k rŒ |
 } } nH t
 j | d t d | j ƒ  ƒ ƒ} | j d | d | d | ƒ \ } } t
 j d | d | d	 | d
 | ƒ } | d  k r|  j ƒ  } n  | j d | d t d |  j ƒ  d t ƒ } | d  k rR|  } n  d d „ } | d | d | ƒ } | d  k rˆ| } n  | S(   NR’  RÁ   iè  R®  t   vol_cutoff_plus_percentt   vol_cutoff_minus_percentRž  R£  t   cutoffpt   cutoffmR°  R&   R±  iô  c         S   s*  | j  ƒ  j ƒ  |  j  ƒ  j ƒ  k s* t ‚ |  j | ƒ \ } } t d | j  ƒ  j ƒ  ƒ } | j d | ƒ | j | ƒ d t j | j	 ƒ  j  ƒ  ƒ d } t j
 ƒ  } t j
 ƒ  } x× | j ƒ  j ƒ  D]Ã } | j ƒ  j | ƒ }	 t | ƒ j |	 ƒ j  ƒ  }
 t | ƒ j |	 ƒ j  ƒ  } t j |
 | ƒ } t j | | ƒ } | d k sT| d k rXd  S| j | | ƒ | j t j | j |	 ƒ ƒ ƒ qÅ W| j ƒ  d k rt j j d t j | ƒ d | ƒ } d t j | j	 ƒ  j  ƒ  ƒ d } | j t j | | j ƒ } n
 | d } | j d	 | j  ƒ  | ƒ S(
   Niô  RÜ   g      ð?g      @i    i   R„  R…  R�   (   R�   R'   R   R9  Rù   RÈ   Rù  R	   Rá  Ró   RB  R!   Rƒ   RÀ   R«   RÅ   R‹  R   R9   RÒ  R‡  R„  Rˆ  R.  R‰  RÛ  RŠ  R¥   (   R?  R@  RÜ   t   f1_t   f2_Rè  R¶   t   ss_binR:   Rà   t   sel_f1t   sel_f2R`   Rc   Ru  t   k_isotropic(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¶   £  s0    *# #$#!
R?  R@  (   RC  R   RŒ  t   apply_sigma_scalingRœ  R£  R	   Rù   t   as_1dRQ   R   t	   histogramR'   t   get_percentile_cutoffst   denmod_simpleR   RC   R³  R<   R&   (   R.   RC   R   R¡  R’  t   scale_toRŒ  Rž  R£  t	   value_mint	   value_maxR¢  R£  t   histt   sfR¶   Rw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   double_step_filtration~  sD    
$			 		 	 	c         C   sC  |  j  ƒ  } t j | j ƒ  j ƒ  ƒ } d | t j | } d t j | ƒ | t j | ƒ t j	 | d ƒ } |  j
 d | d | d | d | d | d | d	 |	 d
 |
 ƒ } | j ƒ  | j t j | j ƒ  | ƒ ƒ } | j d | j ƒ  | ƒ } t
 d |  j d | d | d | d | d | d | d	 |	 ƒ d | ƒ j ƒ  } | S(   Ni   i   R’  R(   R™  R”  R•  R–  R—  R‹  R�   R˜  RŠ  (   RC   R	   R.  Rô   R�   R„  R…  t   sinRˆ  Rñ   RŒ  R›  R³  Rá  Rœ  R   R˜  (   R.   t   radiust   mean_solvent_densityR’  R(   R™  R”  R•  R–  R—  R‹  RC   Re   R§   t   sphere_reciprocalR²  t   tempt   fourier_coeff(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   local_standard_deviation_map¿  s8    4		
		c
         C   s[   |  j  ƒ  }
 t d |
 j d | d | d | d | d | d | ƒ d |
 d	 | d
 | d |	 ƒ S(   s.   
    Calculate an unphased Patterson map.
    R˜  R’  R(   R”  R•  R–  R—  t   f_pattR‹  t
   sharpeningt   origin_peak_removal(   R‘  t   patterson_mapR˜  (   R.   R’  R(   R”  R•  R–  R—  R‹  R½  R¾  R¼  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¿  è  s    		c         C   s0   d d l  m } | j d |  d | d | ƒ d S(   s8   
    Write reflections to a SHELX-format .hkl file.
    iÿÿÿÿ(   t   hklfR[  t   file_objectt   normalise_if_format_overflowN(   t   iotbx.shelxRÀ  t!   miller_array_export_as_shelx_hklf(   R.   RÁ  RÂ  RÀ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   export_as_shelx_hklf  s
    	c         C   s<   d d l  m } | |  d | d | d | d | d | ƒd S(	   s1   
    Write reflections to a CNS-format file.
    iÿÿÿÿ(   t   export_as_cns_hklRÁ  R¯   R0  t   array_namest   r_free_flagsN(   t   iotbx.cns.miller_arrayRÆ  (   R.   RÁ  R¯   R0  RÇ  RÈ  t   implementation(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÆ    s    		c         C   s?   d d l  m } | d |  d | d | d | d | d | ƒ d	 S(
   s¤  
    Write data in unmerged scalepack format.

    :param file_object: filehandle-like object
    :param file_name: output file to write
    :param batch_numbers: integer array indicating the batch (image) numbers
                          corresponding to the indices (optional)
    :param spindle_flags: integer array indicating the position of the
                          reflections on the detector (optional)
    iÿÿÿÿ(   t   writert   i_obsRÁ  R¯   t   batch_numberst   spindle_flagst%   scale_intensities_for_scalepack_mergeN(   t'   iotbx.scalepack.no_merge_original_indexRË  (   R.   RÁ  R¯   RÍ  RÎ  RÏ  RË  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   export_as_scalepack_unmerged  s    R   t   projectt   datasetc	         C   s”   d d l  }	 | d k r? |  j ƒ  }
 |
 d k	 r? |
 j } q? n  | d k rT d } n  |	 j j |  d | d | d | d | d | d	 | d
 | d | ƒS(   s•   
    Generate an iotbx.mtz.dataset object for the array, which can be extended
    with additional arrays and eventually written to an MTZ file.
    iÿÿÿÿNg      ð?t   column_root_labelt   column_typest   label_decoratort   titlet   crystal_namet   project_namet   dataset_nameRh   (   t	   iotbx.mtzR   R0  Rh   t   mtzt   miller_array_as_mtz_dataset(   R.   RÔ  RÕ  RÖ  R×  RØ  RÙ  RÚ  Rh   t   iotbxR0  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_mtz_dataset8  s     	c         C   s"   d d  l  } | j j |  | ƒ j S(   Niÿÿÿÿ(   t	   iotbx.cift   cift   miller_arrays_as_cif_blockt	   cif_block(   R.   t
   array_typeRÞ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_cif_blockV  s    t   globalc         C   sZ   | d  k r t j } n  d d  l } | j j j ƒ  } |  j d | ƒ | | <| | IJd  S(   NiÿÿÿÿRä  (   R   R|   R}   Rà  Rá  t   modelRå  (   R.   Rä  Rß   t	   data_nameRÞ  Rá  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_cif_simple[  s     c         C   sA   d d l  } | j j d |  d | d | d | d | d | ƒ d S(	   s$   
    Write phases to .phs file.
    iÿÿÿÿNR.   Rß   t   scale_amplitudesRƒ  t
   phases_degt   figures_of_merit(   t   iotbx.phasesRƒ  t   miller_array_as_phases_phs(   R.   Rß   Rê  Rƒ  Rë  Rì  RÞ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_phases_phsc  s    	c         C   s`   | d k rM d d l m } |  j ƒ  } | j d d ƒ | j | | ƒ } n  t j |  | | ƒ S(   s‡    Overriden version of set.amplitude_normalisation which computes
    the Wilson parameters from the array data if wilson_plot is None. iÿÿÿÿ(   t
   statisticsRÁ   i   N(   R   R¿  Rð  RP  RÈ   RÏ  R4   RÓ  (   R.   RÎ  RÏ  Rð  t   f_obs(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÓ  u  s    c         C   s   t  |  | | ƒ S(   N(   t   normalised_amplitudes(   R.   RÎ  RÏ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRò    s    c         C   s¤  |  j  ƒ  d k r d S| s5 |  j ƒ  d k	 s5 t ‚ | rP | d k sP t ‚ n  | d k	 rƒ | j ƒ  |  j  ƒ  j ƒ  k sƒ t ‚ n  | j ƒ  s• t ‚ | j ƒ  |  j  ƒ  j ƒ  k s¹ t ‚ | sþ|  j  ƒ  j ƒ  d k rÛ d S|  j  ƒ  } |  j ƒ  r| j ƒ  j  ƒ  } n t j	 | j  ƒ  ƒ } | d k	 r™| d k  s;t ‚ | t j
 |  j  ƒ  ƒ | k } | j | ƒ } | j | ƒ } | d k	 r™| j | ƒ } q™n  | d k rÌt j | | ƒ t j t j | ƒ ƒ St j | | | ƒ t j | t j | ƒ ƒ Sn  g  } x~ |  j ƒ  j ƒ  D]j }	 |  j ƒ  j |	 ƒ } d }
 | d k	 rV| j | ƒ }
 n  | j |  j | ƒ j | j | ƒ |
 ƒ ƒ qWt d |  j ƒ  d | d d ƒ S(   s&  
    The analytical expression for the least squares scale factor.

    K = sum(w * yo * yc) / sum(w * yc^2)

    If the optional cutoff_factor argument is provided, only the reflections
    whose magnitudes are greater than cutoff_factor * max(yo) will be included
    in the calculation.
    i    i   R!   R�   R…   s   %7.4fN(   R�   R   R!   R   R'   RC  RÊ   Ri  R	   R«   RQ   RÅ   R‹  Rá  R8   RÀ   R9   RŽ  R—   (   R.   RÕ  R¿  R5  RÂ   Rð  t   calcRà   Rç  R:   t   weights_sel(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRŽ  „  sH      '$ ')c      	   C   se   d d l  } d d l  m } | j j d | d | d | d | j ƒ j } | d k	 r] | | S| Sd S(   sg   
    Class method for building an array from a CIF file (or filehandle).
    Depends on iotbx.cif.
    iÿÿÿÿN(   t   buildersRÁ  t	   file_patht   data_block_namet   data_structure_builder(   Rà  Rõ  Rá  t   cctbx_data_structures_from_cift   miller_array_buildert   miller_arraysR   (   t   clsRÁ  Rö  R÷  RÞ  Rõ  t   arrays(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   from_cif³  s    c         C   s„   |  j  ƒ  s t ‚ |  j ƒ  j ƒ  } |  j ƒ  j |  j ƒ  | ƒ } d | | t j | d ƒ | } | d 7} t	 j | d ƒ } | S(   sŒ  
    Extinction parameter x, where Fc is multiplied by:
      k[1 + 0.001 x Fc^2 wavelength^3 / sin(2theta)]^(-1/4)

    See SHELX-97 manual, page 7-7 for more information.

    Note: The scale factor, k, is not applied nor calculated by
          this function. The scale factor should be calculated
          and applied ***AFTER*** the application of the extinction
          corrections.
    gü©ñÒMbP?i   i   g      ð¿i   g      Ð¿(
   RC  R   R~  R�   R2   t   sin_two_thetaR$   R„  Rñ   R	   (   R.   R„  Rh   RT  t   sin_2_thetat
   correction(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   shelxl_extinction_correctionÄ  s    "
c         C   s,   |  j  | | ƒ } |  j d |  j ƒ  | ƒ S(   NR�   (   R  R¥   R�   (   R.   R„  Rh   R  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt"   apply_shelxl_extinction_correctionØ  s    gš™™™™™©?gš™™™™™¹?c         C   sy  | j  ƒ  j |  j  ƒ  ƒ s! t ‚ | j ƒ  rE t j | j ƒ  ƒ } n | j ƒ  j ƒ  } |  j ƒ  j ƒ  } t j | ƒ d k  r‚ d St j
 | ƒ } t j | | ƒ } | d k r´ d S| | | 9} t t j | ƒ t j | ƒ ƒ }	 |	 d k ró d S| d |	 9} | d |	 9} d | d | }
 |
 | } d |
 } | } | |
 | | k  | | | | k B} | ru| | | f S| S(   s‡         Preconditions (not checked explicitly):
        self is amplitude array,
        f_calc is complex array or amplitude array.
    i    i   N(   R$   R  R   RC  R	   R«   R�   R¤   Rù   R   RK  R‹  RQ   (   R.   RÕ  t
   offset_lowt   offset_hight   also_return_x_and_yR„  R…  t   sum_xxt   sum_xyR‰   t   m_lowt   b_lowt   m_hight   b_highRw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt"   f_obs_f_calc_fan_outlier_selectionÜ  s4    
!!
c      	   C   s¡  |  j  ƒ  d  k s0 |  j ƒ  s0 |  j ƒ  s0 t ‚ |  j ƒ  sB t ‚ |  j ƒ  d  k	 sZ t ‚ d d l m } d
 } | d  k	 r… | } n  | d  k	 rX| j	 ƒ  |  j
 ƒ  j	 ƒ  k sµ t ‚ | d  k pÐ t | ƒ d k sÚ t ‚ | j |  j
 ƒ  |  j ƒ  |  j ƒ  | | | ƒ } t d t d |  d | j
 d |  j ƒ  ƒ d | j d	 | j ƒ j |  ƒ | _ n3 | j |  j
 ƒ  |  j ƒ  |  j ƒ  | ƒ } |  | _ | | _ | | _ | S(   Niÿÿÿÿ(   t   observationsi    R0   R1   R$   R&   R�   R¦   (    (   R4  R   RË   RÊ   R   RÐ   R¦   R3  R  R'   R$   RR   R�   R   R4   R&   R6  RL  t   ref_twin_fractionst   ref_twin_components(   R.   t   scale_indicest   twin_fractionst   twin_componentsR  t   tw_cmpsRw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_xray_observations  s6    	$%		$			c         K   sE   |  j  ƒ  s t ‚ d d l m } t | ƒ } |  | d <| j | �  S(   sÿ   
    Perform French-Wilson treatment of X-ray intensities to estimate the "true"
    intensities, replacing very weak and/or negative values, and takes the
    square root to obtain amplitudes.

    :returns: an array of all-positive X-ray amplitudes
    iÿÿÿÿ(   t   french_wilsonR[  (   RÊ   R   R¿  R  t   dictt   french_wilson_scale(   R.   t   kwdsR  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR  #  s
    
c         C   s  d d l  } |  j ƒ  j ƒ  } | j j | ƒ } | j ƒ  } t j | t t j | ƒ t j | ƒ ƒ ƒ } t	 j
 | j | ƒ ƒ }	 t j | ƒ } t j ƒ  }
 xî |  j ƒ  D]à } t j | ƒ | } t j | t | ƒ ƒ } t	 j
 | j | ƒ ƒ } | j | ƒ } | |	 } d } | d k r~| d k s2t ‚ | | } t d t | ƒ ƒ d k  rad } n  d t	 j t	 j | ƒ } n  |
 j | ƒ q« WxJ t d d ƒ D]9 } |
 | k } d | j t ƒ | j ƒ  | k rŸPqŸqŸW| rò|  j d	 | ƒ S|  j d	 | ƒ S(
   sÔ   
    Remove reflections corresponding to a cone shape in reciprocal space with
    the apex at the origin.  Used to simulate incomplete data due to poor
    alignment of the crystal with the goniometer axis.
    iÿÿÿÿNi    g      ð?gü©ñÒMbP?i´   i   g      Y@RÀ   (   t   scitbx.matrixR2   t   fractionalization_matrixR   t   sqrt	   transposeR	   RB  Rh  R„  R.  t   dotR$   R   R«   R…  t   acosR9   RY  R   R<   R'   RÅ   (   R.   t   fraction_percentt   vertext   axis_point_1t   axis_point_2R+  R‡  t   fmR  t   axis_lengtht   opening_anglest   pointt   point_minus_vertext   point_minus_vertex_lengtht	   numeratort   denominatort   opening_angle_deg_for_pointRc  t   oaRà   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   remove_cone1  s>    )

 	#  c         C   só  |  j  ƒ  d  k r d  S|  j d t ƒ } d \ } } } xkt | j ƒ  | j ƒ  | j  ƒ  | j ƒ  j ƒ  ƒ D]6\ } } } }	 |  j ƒ  j	 | ƒ }
 | d d k rá | d d k rá | | | k rá | d  k rá |	 | d f } n  | d d k r0| d d k r0| | | k r0| d  k r0|	 | d f } n  | d d k r| d d k r| | | k r| d  k r|	 | d f } n  | | | g j
 d  ƒ d k rk Pqk qk W| | | g j
 d  ƒ d k sí| d | d | d g j
 d ƒ d k ræ|  j ƒ  \ } } d „  } | | d | d ƒ } | | d | d ƒ } | | d | d ƒ } |  j ƒ  \ } } } | d  k s~| d d k r�| | f } n  | d  k s©| d d k r¸| | f } n  | d  k sÔ| d d k ræ| | f } qæn  | | | f S(   NR@  i   i    i   c         S   sF   t  |  ƒ | k r |  St  |  ƒ | k  r, | St  |  ƒ | k rB | Sd  S(   N(   R«   (   R‰  RŠ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   helperk  s       (   NNN(   R¦   R   RK  R<   R%  R$   R�   Ró   R2   R®   R   Rû   R	  (   R.   t   sigma_cutofft   sortedt   h_cutt   k_cutt   l_cutRµ   R~   R‰   Rc   R¾   R  R  R/  t   hmt   kmt   lmt   dht   dkt   dl(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt,   ellipsoidal_resolutions_and_indices_by_sigmaZ  s<     !%<<< *	   c         C   sL  |  j  ƒ  d  k r d  S|  j d t ƒ } g  g  g  } } } xt | j ƒ  | j ƒ  | j  ƒ  | j ƒ  j ƒ  ƒ D]Ó \ } } } } | | }	 | d d k rÉ | d d k rÉ | j | | d |	 f ƒ n  | d d k r| d d k r| j | | d |	 f ƒ n  | d d k rp | d d k rp | j | | d |	 f ƒ qp qp Wd GHd GHxô t	 t
 t | ƒ t
 t | ƒ t | ƒ ƒ ƒ ƒ D]Â }
 d d } y d	 | |
 } Wn t k
 r½| } n Xy d	 | |
 } Wn8 t k
 r
t | j ƒ  ƒ d k r| } q| } n Xy d	 | |
 } Wn t k
 r6d
 } n X| G| G| GHq‚Wd  S(   NR@  i   i    i   s0   a*                      b*                    c*sA   d         h   F/sigma   d        k  F/sigma   d        l  F/sigmaRL   i   s   %7.3f %4d %8.3fR{   (   R¦   R   RK  R<   R%  R$   R�   Ró   R9   R™   RQ   RR   R*  t   strip(   R.   R1  R±   R²   R³   Rµ   R~   R‰   Rc   t   data_over_sigmaRš   t   blancR  R  R  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt*   show_mean_data_over_sigma_along_a_b_c_starx  s@     !%
      !7
  
  	
  
c         C   so  |  j  d | ƒ \ } } } |  j ƒ  j ƒ  } t | d | d ƒ } t | d | d ƒ } t | d | d ƒ } | | | g j d  ƒ d k r� |  j ƒ  St j |  j	 ƒ  j
 ƒ  t ƒ }	 |  j ƒ  }
 |  j ƒ  } x‰ t |  j	 ƒ  ƒ D]u \ } } |  j ƒ  j | ƒ } t j | d | d | d | d | d | d ƒ } | d k ræ t |	 | <qæ qæ W|  j d |	 ƒ S(   NR0  i   i    i   RÀ   (   R;  R2   R¬   R«   R   R   R¤   R	   R)  R$   R'   R,   R�   R¦   Rª   R®   R„  R.  R<   RÅ   (   R.   R0  R2  R3  R4  Rº   t   ehmt   ekmt   elmRÀ   R�   R¦   R´   Rµ   R¾   Ru  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   ellipsoidal_truncation_by_sigma�  s"    	 
; c         C   sá   |  j  ƒ  j ƒ  } t j | j ƒ  t ƒ j ƒ  } | | k | | k @} | j ƒ  } t j | j ƒ  ƒ } | j | ƒ } | j	 | | ƒ |  j ƒ  j | ƒ }	 d }
 |  j ƒ  d k	 rË |  j ƒ  j | ƒ }
 n  |  j d |	 d |
 ƒ S(   s›   
    Randomly shuffle reflections within a given resolution range.  Used for
    control refinements to validate the information content of a dataset.
    R�   R¦   N(   Ró   R�   R	   R)  R'   R<   RD  t   random_permutationRÅ   RC  R   R¦   R¥   (   R.   RÝ   R(   Ró   t   all_iselt   range_selectiont
   range_iselRW  t   range_isel_permutedR�   R¦   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   permute_d_range£  s    c         C   sr   |  j  ƒ  s t S|  j ƒ  j ƒ  } |  j | ƒ } | } | j t ƒ d k rX | j ƒ  S|  j | ƒ } | j ƒ  S(   sÞ   
    Determine whether the array contains unmerged experimental observations
    or not.  In some files only the centric reflections will appear to be
    unmerged, so we specifically check the acentrics (if present).
    i    (   RÊ   R,   RÆ   R�   RÅ   R   R<   RÃ   (   R.   RÆ   t   centricst   acentric_flagst	   acentrics(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   is_unmerged_intensity_arrayµ  s     c         C   sI   |  j  ƒ  s t ‚ |  j d | ƒ j ƒ  } | j d ƒ } t | d | ƒS(   s   
    Calculate the correlation between two randomly assigned pools of unmerged
    data ("CC 1/2").  If desired the mean over multiple trials can be taken.
    See Karplus PA & Diederichs K (2012) Science 336:1030-3 for motivation.
    This method assumes that the reflections still have the original indices
    and maps them to the ASU first; the underlying compute_cc_one_half
    function skips this method.
    R&   R>  t   n_trials(   RÊ   R   R¥   R  RK  t   compute_cc_one_half(   R.   RÂ   RN  R&   t	   tmp_array(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   cc_one_halfÆ  s
    		c      	   C   sÒ  |  j  ƒ  s t ‚ |  j d t ƒ j ƒ  } | j d ƒ } | s't d | j ƒ  d | j ƒ  d | j	 ƒ  d t
 ƒ } t d |  d | j d t ƒ } | j ƒ  s¢ t ‚ t d	 | d
 | j ƒ } | j ƒ  } t d	 | d
 | j ƒ } | j ƒ  } | j ƒ  j | j ƒ  ƒ st ‚ | j d | d t
 ƒ j ƒ  S| j d |  ƒ g  }	 xs | j ƒ  j ƒ  D]_ }
 | j ƒ  j |
 ƒ } | j | ƒ } | j ƒ  d k rœ|	 j d ƒ qP|	 j | j ƒ  ƒ qPWt d | j ƒ  d
 |	 d d ƒ S(   sŠ   
    Calculate the correlation of the anomalous differences of two randomly
    assigned half-datasets (starting from unmerged data).
    R&   R>  t   unmerged_indicest   unmerged_datat   unmerged_sigmast   weightedR1   R$   R0   R�   R    RÂ   i    R!   R…   s   %6.3fN(   RÊ   R   R¥   R<   R  RK  t   split_unmergedR$   R�   R¦   R,   R4   RÃ   R   t   data_1RÞ  t   data_2R  R…  Rƒ  Rù  R!   R8   RÀ   RÅ   R'   R9   R   t"   half_dataset_anomalous_correlationR—   (   R.   RÂ   RP  t   split_datasetst   base_sett   array1t   dano1t   array2t   dano2R�   R:   Rà   t	   bin_array(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRY  Õ  sB    			!c         O   s   |  j  | | Ž  S(   s>   
    Alias for array.half_dataset_anomalous_correlation()
    (   RY  (   R.   t   argsR  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   cc_anomý  s    c         C   sÅ   |  j  ƒ  s t ‚ |  j d t ƒ j ƒ  } | j ƒ  sK | j ƒ  j ƒ  } n  | j ƒ  } | j	 ƒ  j
 d | ƒ } t j t j | j ƒ  ƒ ƒ } t j t j | j ƒ  ƒ ƒ } | d k s½ t ‚ | | S(   sI  Calculate R_anom, which measures the agreement between Friedel mates.
    Unlike CC_anom and various other R-factors (such as R_pim, which it is
    usually compared to), this requires merged data.

    .. math::
      R_{anom} = \dfrac{\sum_{hkl}{|I_{hkl} - I_{-h,-k,-l}|}}{\sum_{hkl}{\left \langle I_{hkl} \right \rangle}}
    R&   R    i    (   RÊ   R   R¥   R<   R  RÃ   Ra  R   RÞ  Rb  R6  R	   R‹  R«   R�   (   R.   RP  R  R  R*  R+  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   r_anom  s    	c         C   sa  | d k	 r( d | k o# d k n s. t ‚ | d k	 s@ t ‚ |  j ƒ  } | j ƒ  rg | j ƒ  } n  | j ƒ  sy t ‚ t j | d d d d ƒ} | j ƒ  j	 ƒ  d k r» t
 d ƒ ‚ n  t j | ƒ } | j | ƒ j ƒ  } | j d	 | d
 t ƒ \ } } d | | j ƒ  | | j ƒ  } | d }	 | j d | d |	 ƒ j ƒ  }
 |  j ƒ  r]|
 j ƒ  S|
 S(   s  
    Apply a twin law to the data, returning an array of the same original type.

    :params twin_law: a valid twin law expressed as h,k,l operations
    :params alpha: predicted twin fraction (0 to 0.5)
    :returns: a new array with synthetically twinned data
    g        g      à?t   r_deni   t   t_deni   i   s>   The determinant of the provided twin law is not equal to unityR    R4  g      ð?g      Y@R�   R¦   N(   R   R   R  RË   R}  RÊ   R   t   rt_mxRu  t   determinantR   R‰  R_  R9  R,   R�   R¥   R:  Rv  (   R.   t   twin_lawt   alphaRP  R‹  t	   new_arrayt   xat   xbRÚ  t
   new_sigmast   twinned(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt	   twin_data  s*    ."

c         C   s  | d k	 r( d | k o# d k n s. t ‚ | d k	 s@ t ‚ |  j ƒ  } | j ƒ  rg | j ƒ  } n  | j ƒ  sy t ‚ t j | d d d d ƒ} | j ƒ  j	 ƒ  d k r» t
 d ƒ ‚ n  t j | ƒ } | j | ƒ j ƒ  } | j d	 | d
 t ƒ \ } } | j ƒ  | j ƒ  k st ‚ | j ƒ  } | j ƒ  } | j ƒ  } | j ƒ  }	 d | | | | d d | }
 d } t j d d | d | | ƒ d d | } | d k	 rÜ| t j t j | d ƒ | |	 d ƒ } n  | j d |
 d | ƒ j d	 |  ƒ } |  j ƒ  r| j ƒ  S| S(   s  
    Detwin data using a known twin fraction, returning an array with the same
    original data type.

    :params twin_law: a valid twin law expressed as h,k,l operations
    :params alpha: predicted twin fraction (0 to 0.5)
    :returns: a new array with detwinned data
    g        g      à?Rd  i   Re  i   i   s>   The determinant of the provided twin law is not equal to unityR    R4  g      ð?g       @i   R�   R¦   N(   R   R   R  RË   R}  RÊ   R   Rf  Ru  Rg  R   R‰  R_  R9  R,   R'   R�   R¦   R„  R.  R	   Rñ   R¥   R6  Rv  (   R.   Rh  Ri  RP  R‹  Rj  t   i_old1t   i_old2t   s_old1t   s_old2RÚ  Rm  t   tmp_multt	   detwinned(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   detwin_data7  s<    	."/.	
c         C   s®  | d k r t j } n  |  } | d IJ| d k rC | j ƒ  } nš | d k r^ | j ƒ  } n | d k ry | j ƒ  } nd | d k r” | j ƒ  } nI y t j | ƒ } Wn3 t	 k
 rÜ } t
 d d | t | ƒ f ƒ ‚ n X| j ƒ  j ƒ  j ƒ  r| d IJ| d	 I| j ƒ  IJn
 | d
 IJ| d | j ƒ  | j ƒ  j ƒ  f IJ| j ƒ  j ƒ  j ƒ  } | d I| IJ| d k  r©| d k r©| d IJ| d IJ| d IJn  | rl| j d | j ƒ  ƒ } t j | j ƒ  j ƒ  | ƒ }	 |	 }
 | j |
 ƒ } | j |	 ƒ } | d It j | j ƒ  ƒ IJt | j ƒ  ƒ d k rc| d It j | j ƒ  ƒ IJn  | } n  | j d | ƒ } | d IJt j  j! | d d d | ƒ| | f S(   s-  
    Encapsulates a variety of reindexing operations, including handling for a
    variety of corner cases.

    :param change_of_basis: Python str for change-of-basis operator
    :param eliminate_invalid_indices: remove reflections with non-integral
      indices
    :returns: new Miller array
    s   Change of basis:t   to_reference_settingt   to_primitive_settingt   to_niggli_cellt   to_inverse_hands-   The change-of-basis operator '%s' is invalid s   (original error: %s)s<     Change of basis operator in both h,k,l and x,y,z notation:s      s-     Change of basis operator in x,y,z notation:s       %s [Inverse: %s]s     Determinant:i    s@     **************************************************************s@     W A R N I N G: This change of basis operator changes the hand!R6   s"     Mean value for kept reflections:s%     Mean value for invalid reflections:R‹  s)     Crystal symmetry after change of basis:R   s       R~   N("   R   R|   R}   t'   change_of_basis_op_to_reference_settingt'   change_of_basis_op_to_primitive_settingR^  t"   change_of_basis_op_to_inverse_handR   R‰  R«  R   RS   t   c_invt   tt   is_zerot   as_hklt   as_xyzRj  R-  Ru  Rg  t%   apply_results_in_non_integral_indicesR$   R	   R)  R'   RÅ   RÒ  R�   RR   R_  R   R5   R€   (   R.   t   change_of_basist   eliminate_invalid_indicesRß   R[  R‹  RÎ  Rc   Rà   t   tossRM  t
   keep_arrayt
   toss_arrayt   processed_array(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   apply_change_of_basisd  sb    


		

	
gü©ñÒMbP?c         C   sx  | d k r t j } n  | | g j d ƒ d k s9 t ‚ |  } | j ƒ  }	 |	 j ƒ  }
 | d IJ|	 j d | d d ƒ | j ƒ  } | j ƒ  }	 | d IJ|	 j d | d d ƒ | d k rÍ t	 j
 | ƒ } n  | j ƒ  } | j ƒ  |
 j ƒ  k  r$| r| d IJ| j ƒ  } q$t j d d	 ƒ n  |	 j ƒ  } | j ƒ  j ƒ  } d
 | k oYd k  n rß| j ƒ  rßt	 j d ƒ } | j | ƒ } | j ƒ  d | j ƒ  d k rß| d IJ| j | ƒ } | j ƒ  }	 |	 j ƒ  } qßn  | j ƒ  j | ƒ s«| } | j ƒ  j | ƒ } | d | IJ| d t | j ƒ  ƒ IJ| d t | j ƒ  ƒ IJ| j ƒ  } | j ƒ  } t | | ƒ | } | | k r«t j d d | d t ƒ q«n  t j d | d | ƒ } | j d | ƒ } | j  d d d t! d | ƒ \ } } | r!| j" ƒ  r!| j# ƒ  j$ ƒ  } n  | rT| j% ƒ  } | j& ƒ  } | j' d | ƒ } n  | d IJ| j d | d d ƒ | S(   sá  
    Encapsulates all operations required to convert the original data to a
    different symmetry (e.g. as suggested by Xtriage).  This includes
    reindexing and adjusting the unit cell parameters if necessary, and
    expansion to P1 (for moving to lower symmetry) or merging equivalents.

    :param space_group_symbol: Python str for space group symbol (any format)
    :param space_group_info: Pre-defined sgtbx.space_group_info object
    :param volume_warning_threshold: Cutoff for relative change in unit cell
      volume beyond which a warning is issued.
    :param expand_to_p1_if_necessary: When moving to lower symmetry, expand the
      data to P1 first.
    :param remove_systematic_absences: eliminate reflections that are
      systematically absent in the new symmetry.
    :param merge_non_unique: merge reflections that are no longer symmetry-
      unique under the new symmetry.
    :param log: filehandle-like object
    :returns: Miller array in the new symmetry
    i   s   Current symmetry:R~   R   s     s   Niggli cell symmetry:s1   Changing to lower symmetry, expanding to P1 firsts6   This operation will result in incomplete data without s   symmetry expansion!i�   iÃ   s   a,-b,-ciÿÿÿÿs   Reindexing with a,-b,-cs5   Coercing unit cell into parameters compatible with %ss     Old cell: %ss     New cell: %ss3   This operation will change the unit cell volume by s   more than %.1f%%.id   R2   R%   R1   R„  Rw  R…  Rß   R    s   New Miller array:N((   R   R|   R}   R   R   R1   Rç   R€   t   niggli_cellR   R%   R`  t   n_smxR¨   t   warningst   warnR2   R   RŽ  t   is_reference_settingR‰  R_  R¢   t   is_compatible_unit_cellt   average_unit_cellRS   R©  R«   t   UserWarningR   R5   R¥   RŠ  R<   RÃ   Ra  R   R¤   R,  R;  (   R.   R£   R%   t   volume_warning_thresholdt   expand_to_p1_if_necessaryR,  t   merge_non_uniqueRâ  R[  t   symmt   space_group_oldt   space_group_newR2   RŽ  R‹  t   unit_cell_newt   unit_cell_oldt   volume_startt
   volume_newt   volume_change_fractiont   symm_newt   ma_oldR’  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   change_symmetry¥  sz    !


	( 
				
c         C   s   t  |  ƒ j d | d | ƒ S(   sÑ  
    For each possible space group sharing the same basic intensity symmetry,
    show a list of possible systematically absent reflections and corresponding
    I/sigmaI.  Note that if the data have already been processed in a specific
    space group rather than the basic point group, for example P212121 instead
    of P222, all systematically absent reflections are likely to have been
    removed already.

    :returns: a systematic_absences_info object
    Rß   R   (   t   systematic_absences_infoR˜   (   R.   Rß   R   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt%   show_all_possible_systematic_absences  s    g      @c         C   sY   d d l  } | j j d ƒ s- t d ƒ ‚ n  d d l m } | j d |  d | d | ƒ S(	   sÙ   
    Detect translational pseudosymmetry and twinning, using methods in
    Xtriage.  Returns a mmtbx.scaling.twin_analyses.twin_law_interpretation
    object.  (Requires mmtbx to be configured to be functional.)
    iÿÿÿÿNt   mmtbxs)   mmtbx is required for this functionality.(   t   twin_analysesR.   R(   Râ  (   t   libtbx.load_envt   envt
   has_modulet   ImportErrort   mmtbx.scalingR¤  t   analyze_intensity_statistics(   R.   R(   Râ  R�   R¤  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRª    s    	c         C   s   |  j  d | ƒ j ƒ  S(   sÉ   
    Convenience method for identifying twinned data.  Note that this is
    hugely inefficient if any other Xtriage analyses are planned, since it
    discards the other results.  Requires mmtbx.
    R(   (   Rª  t   has_twinning(   R.   R(   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR«     s    NgUUUUUUÕ?gUUUUUUÕ?gUUUUUUÕ?(   i    i    i    (   i    i    i    (   i    i    i   (®   R•   R–   R  R   R#   Rœ   R1  R6  R8  R:  R�   R¦   R;  R=  R0  RÛ   R4  R'   R?  R@  RB  RÐ   RC  RE  RË   RG  RÊ   RH  R¡   R¤   R   R¥   R<   Rü  R4   RI  RK  RF  R   R€   RX  RZ  R_  Rd  Rj  Rv  R}  RP  R~  R  R€  Rƒ  R,   R¶   Rœ  R¥  Rª  RA  R‘  R¨   R_  RÁ  RÖ  R’  RÇ  RÈ  RÑ  RÓ  RÙ  RÞ  Rá  Râ  RÌ   Rï  RÑ   Rõ  R   R  R  RÏ  R  R  R  R  R  R(  R.  R/  RÅ   R4  R6  R:  R>  RB  RE  RÒ  R  R‹  RK  RH  RN  RO  RT  RV  RW  R`  Rb  Rg  Rh  Ri  Rº  Rj  Rk  Rƒ  Ra  Rë  Rb  Rs  Rt  Rx  Ry  Rz  R{  R|  R~  R  R€  Ri  R…  R‡  R‰  RŒ  R�  R˜  RŸ  R´  R»  R¿  RÅ  RÆ  RÑ  Rß  Rå  Ré  Rï  RÓ  Rò  RŽ  Rþ  t   classmethodR  R  R  R  R  R.  R;  R?  RC  RI  RM  RQ  RY  Rb  Rc  Ro  Rv  RŠ  R   R|   R}   R¢  Rª  R«  (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR   y  s  																													
		4'	?									 0($
"	$
								$											 %	
 < 	
.		#	(			(				/?VR_  c           B   s#   e  Z d  d d d „ Z d „  Z RS(   g{®Gáz”?g      @c         C   s2  | |  _  t |  _ t |  _ | j ƒ  } | d  k sB | j d  k rF d  S| j j ƒ  } | d  k	 r§ | j ƒ  } | d  k	 r§ | j d | d | d | ƒ r§ t	 |  _ q§ n  | j j
 ƒ  } | d  k	 r.| d  k rø | j
 ƒ  }	 |	 d  k	 rø |	 j ƒ  } qø n  | d  k	 r.| j ƒ  }
 |
 | k r+t	 |  _ q+q.n  d  S(   NR    t   relative_length_tolerancet   absolute_angle_tolerance(   R[  R<   t   unit_cell_is_compatiblet   space_group_is_compatibleR0  R   R  R2   t   is_similar_toR,   Rç   t   build_derived_point_group(   R.   R[  R\  R]  R^  R0  t   ucfR°   t   sgft   sgt   point_group_from_file(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#   -  s2    			 	
c         C   s6  |  j  } g  } d | t | j ƒ  ƒ f g } |  j sƒ | j d ƒ | j d t | j ƒ  j j ƒ  ƒ d t | j ƒ  ƒ g ƒ n  |  j sØ | j d ƒ | j d t | j ƒ  j j	 ƒ  ƒ d t | j	 ƒ  ƒ g ƒ n  t
 | ƒ d k r2t
 | ƒ d	 k rd
 g } n  d j d | d | d f d g | ƒ Sd  S(   Ns     %s: %ss	   unit cells     Unit cell from file: s       Working unit cell: s   space groups     Space group from file: s       Working space group: i    i   s   crystal symmetrys   
s$   Working %s is not compatible with %ss    from reflection file:(   R[  RS   R0  R¯  R9   Rg  R  R2   R°  R%   RR   RY   R   (   R.   t   data_descriptiont   mat   whatt   msg(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   format_error_messageJ  s,    			 N(   R•   R–   R   R#   R»  (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR_  +  s   Rò  c           B   s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   s!    E-values and related statistics c         C   sÃ   | j  ƒ  s t ‚ | j | | ƒ } | j ƒ  | j ƒ  } t d t d | j ƒ  d | j ƒ  ƒ j ƒ  d | ƒ j	 ƒ  |  _
 t j | ƒ } t j t j | d ƒ ƒ |  _ | d k j t ƒ |  _ d  S(   NR0   R1   R$   R�   i   i   (   RË   R   RÓ  R�   R   R4   R1   R$   R  R8  t   _arrayR	   Rá  R‹  R«   t   _sum_e_sq_minus_1R   R<   t   _n_e_greater_than_2(   R.   R[  RÎ  RÏ  RÍ  RÎ  t   e_sq(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#   e  s    		c         C   s   |  j  S(   N(   R¼  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR   s  s    c         C   s   |  j  |  j j ƒ  S(   N(   R½  R¼  R'   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   mean_e_sq_minus_1v  s    c         C   s   d |  j  |  j j ƒ  S(   Ng      Y@(   R¾  R¼  R'   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   percent_e_sq_gt_2y  s    N(   R•   R–   R  R   R#   R   RÀ  RÁ  (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRò  b  s
   		Ra  c           B   sŒ   e  Z d  Z d d e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d d d d „ Z RS(   s  
  Wrapper for merging redundant observations to obtain a symmetry-unique
  array.  This also calculates some useful statistics resulting from the
  merging operation.  Normally this would not be instantiated directly, but
  instead obtained by calling array.merge_equivalents(...).
  Rl  c      	   C   sÌ  | d k s t  ‚ d |  _ d |  _ d |  _ |  _ |  _ |  _ d |  _ d |  _	 | j
 ƒ  j j } i t j d 6t j d 6t j d 6t j d 6j | d ƒ } | d k	 r«| j ƒ  } | j d d ƒ } ys | d k r| | j ƒ  j | ƒ | j
 ƒ  j | ƒ d	 | ƒ}	 n- | | j ƒ  j | ƒ | j
 ƒ  j | ƒ ƒ }	 WnA t k
 r€}
 d
 t |
 ƒ k rzt t |
 ƒ d ƒ ‚ n  ‚  n Xd } ~ t |	 d ƒ rt|	 j	 |  _	 qtnÉt | j
 ƒ  t j ƒ rFt j | ƒ } | j d d ƒ } | j ƒ  d k	 rÂ| d k rMt j  | j ƒ  j | ƒ | j
 ƒ  j | ƒ | j ƒ  j | ƒ d | ƒ}	 ni | d k rªt j! | j ƒ  j | ƒ | j
 ƒ  j | ƒ | j ƒ  j | ƒ ƒ }	 |	 j" |  _ n t d ƒ ‚ |	 j } n6 t j# | j ƒ  j | ƒ | j
 ƒ  j | ƒ ƒ }	 d } ~ |	 j$ |  _ |	 j% |  _ |	 j& |  _ |	 j' |  _ |	 j( |  _ |	 j) |  _ n. t d t* | j
 ƒ  ƒ t* | j ƒ  ƒ f ƒ ‚ t+ d t d | d |	 j d | j, ƒ  ƒ d |	 j
 d | ƒ j- | ƒ |  _. |	 j/ |  _0 d S(   s�   
    :param miller_array: a non-unique array of experimental data
    :param algorithm: merging method (options are "gaussian" or "shelx")
    Rl  RN  R)  R©   RŸ  RD  RG  R>  Rm  s%   merge_equivalents_exact: incompatibles!    (mismatch between Friedel mates)t   n_incompatible_flagsRn  s*   Programming error (should be unreachable).sO   cctbx.miller.merge_equivalents: unsupported array type:
  data: %s
  sigmas: %sR0   R1   R$   R&   R�   R¦   N(   s   gaussians   shelx(   s   bools   int(1   R   R   t	   _r_lineart	   _r_squaret   _r_intt   _r_merget   _r_meast   _r_pimt   _inconsistent_equivalentsRÂ  R�   R)  R•   R"   t   merge_equivalents_exact_boolt   merge_equivalents_exact_intt   merge_equivalents_complext   merge_equivalents_hlRo  R  RA  R$   RÅ   Rp  RS   R   R  R„   R	   RB  R4   R¦   t   merge_equivalents_obst   merge_equivalents_shelxt   inconsistent_equivalentst   merge_equivalents_realt   r_lineart   r_squaret   r_intt   r_merget   r_meast   r_pimt   reprR   R&   R6  R¼  t   redundanciest   _redundancies(   R.   R[  R¾  Rm  Rn  t   data_type_strt
   merge_typet	   asu_arrayRW  t	   merge_extRÎ  R¦   t   asu_set(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#   „  s’    				


(		c         C   s   |  j  S(   s)   
    Return the merged Miller array.
    (   R¼  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR   Û  s    c         C   s   |  j  j d |  j ƒ S(   sq   
    Return an array representing the redundancy or multiplicity of each
    reflection in the merged array.
    R�   (   R¼  R   RÚ  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÙ  á  s    c         C   s)   |  j  d k r d S|  j j d |  j  ƒ S(   s7   R-linear = sum(abs(data - mean(data))) / sum(abs(data))R�   N(   RÃ  R   R¼  R   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÒ  è  s     c         C   s)   |  j  d k r d S|  j j d |  j  ƒ S(   s5   R-square = sum((data - mean(data))**2) / sum(data**2)R�   N(   RÄ  R   R¼  R   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÓ  í  s     c         C   s   |  j  S(   N(   RÅ  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÔ  ò  s    c         C   s   |  j  S(   sà   
    Standard (but flawed) metric of dataset internal consistency.

    .. math::
       R_{merge} = \dfrac{\sum_{hkl}{\sum_{i}{|I_{i}(hkl) - \left \langle I_{i}(hkl) \right \rangle|}}}{\sum_{hkl}{\sum_{i}{I_{i}(hkl)}}}
    (   RÆ  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÕ  õ  s    c         C   s   |  j  S(   so  
    Alternate metric of dataset internal consistency.  Explained in detail in
    Diederichs K & Karplus PA (1997) Nature Structural Biology 4:269-275.

    .. math::
       R_{meas} = \dfrac{\sum_{hkl}{ {\left \{ N(hkl) / [N(hkl) - 1] \right \} }^{1/2} \times \sum_{i}{|I_{i}(hkl) - \left \langle I_{i}(hkl) \right \rangle|}}}{\sum_{hkl}{\sum_{i}{I_{i}(hkl)}}}
    (   RÇ  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÖ  þ  s    c         C   s   |  j  S(   sX  
    Alternate metric of dataset internal consistency or quality.  Explained in
    detail in Weiss MS (2001) J Appl Cryst 34:130-135.

    .. math::
       R_{meas} = \dfrac{\sum_{hkl}{ {\left \{ 1 / [N(hkl) - 1] \right \} }^{1/2} \times \sum_{i}{|I_{i}(hkl) - \left \langle I_{i}(hkl) \right \rangle|}}}{\sum_{hkl}{\sum_{i}{I_{i}(hkl)}}}
    (   RÈ  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR×    s    c         C   s   |  j  d  k r |  j  Sd S(   Ni    (   RÉ  R   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRÐ    s    c         C   s2   t  j |  j ƒ  j ƒ  ƒ t  j |  j ƒ  j ƒ  ƒ S(   N(   R	   R‹  R   R¦   R�   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   r_sigma  s    i
   R{   c         C   sÉ  | d  k r t j } n  |  j ƒ  j ƒ  } | j d | ƒ | j d t ƒ } |  j ƒ  j ƒ  d k } |  j	 ƒ  } | d  k	 r­ | j
 | ƒ } | j | ƒ | j d t ƒ } n  |  j ƒ  }	 |	 d  k	 rö |	 j
 | ƒ }	 |	 j | ƒ |	 j d t ƒ }
 n  d d d d g } | d  k r$| j d ƒ n | j d ƒ |	 d  k rM| j d ƒ n | j d	 ƒ | g } g  | d
 D] } t | ƒ ^ qn} xË| j j ƒ  D]º} | j j d | d t ƒ g } | j j | ƒ } |  j ƒ  j
 | ƒ j ƒ  } | j ƒ  d
 k r| j d d g ƒ n4 | j d t j | ƒ ƒ | j d t j | ƒ ƒ | j | d  k rf| j d ƒ n | j d | j | ƒ | d  k s�| j | d  k r­| j d ƒ n | j d | j | ƒ |	 d  k sä|
 j | d  k rô| j d ƒ n | j d |
 j | ƒ | j | ƒ g  t | | ƒ D]! \ } } t | t | ƒ ƒ ^ q)} q–W| d  k	 rw| | |  j	 j IJn  |	 d  k	 rš| | |  j j IJn  | d  k	 s²|	 d  k	 rÃ| | d IJn  t j t j | d d !ƒ ƒ d } d t | d
 | g | d ƒ } d d d | d d d g } x= | |	 g D]/ } | d  k rW| j d ƒ q5| j d ƒ q5W| | | t | ƒ j ƒ  IJd t | ƒ } x, | D]$ } | | | t | ƒ j ƒ  IJq�Wd  S(   NRÁ   RÂ   i   R{   t   Mint   Maxt   Means   R-linears   R-squarei    R:   Rr   s   %ds   %.3fs   %.4fs/   In these sums single measurements are excluded.i   s   %%%ds  %%%ds  %%%ds  %%%dst
   RedundancyRL   i
   i   s   Mean  s(   %%%ds  %%%ds  %%%ds  %%%ds  %%%ds  %%%ds(   R   R|   R}   RÙ  RF  RÈ   RÒ  R<   R�   RÒ  RÅ   Rù  RÓ  R9   RR   R!   R8   Rz   R,   RÀ   R'   Rg  R	   Rù   RQ   R%  R  R‹  R©   Rn   t   rstrip(   R.   RÁ   Rß   R   RÙ  t   red_meanRÀ   RÒ  t   r_l_meanRÓ  t   r_s_meant   fieldst   linest   fieldt   max_lengthsR:   Rà   Ru  t   max_lenR`   R¼   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR€     s~       	#8#  N(   R•   R–   R  R   R<   R#   R   RÙ  RÒ  RÓ  RÔ  RÕ  RÖ  R×  RÐ  Rà  R€   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRa  }  s   U								
	
		RŒ  c           B   s¤   e  Z d  Z d d „ Z d „  Z e d „ Z e d „ Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d e d „ Z d d d g d „ Z d d d „ Z RS(   sN  
  Container for an FFT from reciprocal space (complex double) into real space.
  Normally this is obtained by calling array.fft_map(...), not instantiated
  directly outside this module.  If the input array is anomalous, the
  resulting map will be a flex.complex_double (with grid accessor), otherwise
  it will be a flex.double.
  c         C   sÛ  t  j j |  | ƒ | j ƒ  t t f k s1 t ‚ | j ƒ  j |  j ƒ  ƒ sR t ‚ | j	 ƒ  |  j	 ƒ  k sp t ‚ t
 | j ƒ  t j ƒ sŽ t ‚ | j ƒ  |  _ |  j ƒ  sÍ t j |  j ƒ  ƒ } | j ƒ  } n! t j |  j ƒ  ƒ } | j ƒ  } t  j j d |  j	 ƒ  d |  j ƒ  d | j ƒ  d | j ƒ  d |  j ƒ  d t j | ƒ d t ƒ } | d  k	 r�| j ƒ  d d	 k svt ‚ t | ƒ | j ƒ  d <n  t |  _ |  j ƒ  s¿| j | j ƒ  ƒ |  _ n | j | j ƒ  ƒ |  _ d  S(
   NRç   R&   R6   R¬  R£  t   map_gridR›  i    y                (    R   R˜  Rœ   R&   R,   R<   R   R2   R±  Rç   R„   R�   R	   RŸ  Rž   R
   R   R£  t	   n_complexR§  R`   R¬  t   to_mapR$   R¤  R   Rš  t   complext   _real_map_accessedt   backwardt	   _real_mapt   _complex_map(   R.   R˜  RŠ  R‹  t   rfftRï  t   cfftR®  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#   c  s4    !		c         C   s   |  j  S(   N(   Rž   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR&   �  s    c         C   sU   |  j  ƒ  sA |  j j ƒ  s( | s( t ‚ | r: t |  _ n  |  j St j |  j ƒ Sd S(   sn   
    Extract the real component of the FFT'd map.

    :returns: a flex.double object with grid accessor.
    N(	   R&   Rô  R¢  R   R<   Rò  R	   t   realRõ  (   R.   t   direct_access(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   real_map„  s    c         C   sx   | r |  j  s t ‚ n  |  j d t ƒ } | j ƒ  s; | S| rU t j d | ƒ | St j | t j	 | j
 ƒ  ƒ ƒ Sd S(   s¢   
    Extract the real component of the FFT'd map, removing any padding required
    for the FFT grid.

    :returns: a flex.double object with grid accessor.
    Rù  R®  N(   Rò  R   Rú  R,   R¢  R   t   unpad_in_placeR¡   R	   R¤  R¡  (   R.   t   in_placeRw   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRœ  ’  s     c         C   s   |  j  ƒ  s t ‚ |  j S(   N(   R&   R   Rõ  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRš  £  s    c         C   s   t  j |  j d t ƒ ƒ S(   NRù  (   R   Rð  Rú  R,   (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRð  §  s    c         C   s1   |  j  ƒ  s |  j | 9_ n |  j | 9_ |  S(   N(   R&   Rô  Rõ  (   R.   R¶   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR>  ª  s    c         C   s)   |  j  d d t j |  j ƒ  ƒ j ƒ  ƒ S(   NR¶   i   (   R>  R   Rª  R£  R«  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   apply_fourier_scaling±  s    c         C   s    |  j  d d |  j ƒ  j ƒ  ƒ S(   s/   
    Volume-scale the map values in place.
    R¶   i   (   R>  R2   R©  (   R.   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR›  ´  s    c         C   s]   |  j  ƒ  } | j ƒ  d k r" |  Sd | j ƒ  } |  j ƒ  rM t | ƒ } n  |  j d | ƒ S(   s.   
    Sigma-scale the map values in place.
    i    i   R¶   (   Rð  R�  R&   Rñ  R>  (   R.   Rð  R¶   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRª  º  s    c         C   s.   |  j  ƒ  j d | d |  j d t ƒ d | ƒ S(   NR¢   R®  Rù  t   verify_symmetry(   t   tagst   peak_searchRú  R,   (   R.   R¢   Rþ  (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR   Æ  s    s   cctbx.miller.fft_mapc         C   sï   d d l  m } |  j d t ƒ } | d k r7 d } n  | d k rŠ t |  j ƒ  ƒ } | d k rŠ t g  | D] } | d ^ qk ƒ } qŠ n  t | ƒ d k s¢ t ‚ | j	 d | d |  j
 ƒ  d	 |  j ƒ  d
 | d | d | d t j | ƒ ƒ d S(   sD   
    Write the real component of the map to a CCP4-format file.
    iÿÿÿÿ(   t   ccp4_mapRù  i    i   i
   R¯   R2   Rç   t   gridding_firstt   gridding_lastRž  R“   N(   i    i    i    (   i    i    i    (   RÞ  R  Rú  R,   R   Rn   R£  RR   R   t   write_ccp4_mapR2   Rç   R	   R>  (   R.   R¯   R  R  R“   R  Rž  R`   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_ccp4_mapÌ  s     	)c         C   s¼   d d l  m } |  j d t ƒ } | d k r7 d } n  | d k rŠ t |  j ƒ  ƒ } | d k rŠ t g  | D] } | d ^ qk ƒ } qŠ n  | j d | d |  j ƒ  d | d	 | d
 | ƒ d S(   sD   
    Write the real component of the map to a DSN6-format file.
    iÿÿÿÿ(   t   dsn6Rù  i    i   R¯   R2   R  R  Rž  N(   i    i    i    (   i    i    i    (	   RÞ  R  Rú  R,   R   Rn   R£  t   write_dsn6_mapR2   (   R.   R¯   R  R  R  Rž  R`   (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   as_dsn6_mapæ  s    	)N(   R•   R–   R  R   R#   R&   R<   Rú  Rœ  Rš  Rð  R>  Rý  R›  Rª  R   R  R  (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRŒ  [  s"   							c         C   sÅ   | j  ƒ  s t ‚ | r7 | j d t ƒ | j ƒ  } n  | j ƒ  } | rh | j d t ƒ | j ƒ  } n  t | d | j ƒ  t	 j
 | j ƒ  j ƒ  d ƒ ƒ} | d  k	 rµ | | } n  t |  | | ƒ S(   NRÙ  R�   i   (   t   is_patterson_symmetryR   RÈ   R<   Rb  R}  RV  R   R�   R	   RŸ  R'   R   RŒ  (   R˜  R¼  R‹  R½  R¾  t   i_patt(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¿  ü  s    1i   c   	   
   C   så   g  } |  j  |  j ƒ  d k ƒ }  x³ t | ƒ D]¥ } d } | d k r_ t t j ƒ  d ƒ } n  d } } t d |  j ƒ  d |  j ƒ  d |  j ƒ  d | ƒ } | j	 } | j
 } t j | | ƒ j ƒ  } | j | ƒ q. Wt | ƒ | S(	   sÝ   
  Implementation of array.cc_one_half, assuming that the reflections are
  already in the ASU.  Because the implementation uses random numbers, the
  function has the option to calculate the mean over multiple trials.
  i    i   i'  RR  RS  RT  t   seedN(   RÅ   R¦   RY  R©   R×  R   RV  R$   R�   RW  RX  R	   R�  Rƒ  R9   R‹  (	   t   unmergedRN  t   cc_allR„  R  RW  RX  RZ  t   cc(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyRO    s"    
			R¡  c           B   s,   e  Z d  Z d d „ Z e j d d „ Z RS(   s¦  
  Container for information about possible systematically absent reflections in
  the array, trying both the current space group and all intensity-equivalent
  groups (i.e. all possible screw axis combinations).  This object would
  normally be instantiated directly from a Miller array, but is self-contained
  to enable saving as part of Xtriage results.

  :param obs: X-ray intensity (preferred) or amplitude array
  c         C   sR  | |  _  t |  _ | j ƒ  d  k	 s* t ‚ | j d ƒ } | j ƒ  r] | j ƒ  } t	 |  _ n  | j
 ƒ  so t ‚ | j ƒ  s� | j ƒ  j ƒ  } n  | j ƒ  r« | j ƒ  } n  | j ƒ  |  _ |  j d  k	 sÏ t ‚ |  j j ƒ  } |  j j ƒ  j ƒ  } | j d | j ƒ  ƒ j ƒ  } g  |  _ d |  _ d |  _ x| D]} | j | j ƒ  ƒ j ƒ  } | j | j ƒ  ƒ j ƒ  } t | ƒ }	 |	 |  j k r–|	 |  _ n  t | ƒ d k rýt | ƒ |  j k rÏt | ƒ |  _ n  | j | ƒ }
 |  j j | j ƒ  |
 f ƒ q3t | ƒ d k r.|  j j | j ƒ  t f ƒ q3|  j j | j ƒ  d  f ƒ q3Wd  S(   NR>  R%   i    (    t   was_filteredR,   t   input_amplitudesR¦   R   R   RK  RË   R}  R<   RÊ   RÃ   Ra  R   R&   Rb  R%   t&   reflection_intensity_equivalent_groupsR`  R²  R¥   R0  RC   t"   space_group_symbols_and_selectionst   n_possible_maxt   n_found_maxRé   R$   RD  RR   RÅ   R9   (   R.   Rð  R  t
   all_groupst   point_groupt   complete_selR`  t
   absent_selt   all_possiblet
   n_possiblet   absences(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR#   3  sF    						R{   c      	   C   sk  |  j  d k r | d IJ|  S|  j r3 | d IJn  x1|  j D]&\ } } d } t | ƒ t |  j ƒ k rs d } n  | t k rš | | d | | f IJq= | d k rÁ | | d | | f IJq= | | d | | f IJx‡ t | j ƒ  ƒ D]s \ } } | j	 ƒ  | } | j
 ƒ  | }	 d	 | }
 |	 d k rC| | d
 |
 IJqì | | d |
 | |	 f IJqì Wq= W|  S(   s‚   
    For each possible space group, show a list of possible systematically
    absent reflections and corresponding I/sigmaI.
    i    sC   No systematic absences possible in any intensity-equivalent groups.s  Please note that the input data were amplitudes, which means that weaker
reflections may have been modified by French-Wilson treatment or discarded
altogether, and the original intensities will not be recovered.  For best
results, use intensities as input.
R{   s    (input space group)s%   %s%s: no systematic absences possibles   %s%s: no absences founds   %s%s:s   (%4d, %4d, %4d)s     %s: i/sigi = undefineds     %s: i/sigi = %6.1fN(   R  R  R  RS   R%   R,   R   Rª   R$   R�   R¦   (   R.   Rß   R   t
   group_infoR  t
   group_notet   i_hklR  R9  R�  t   indices_fmt(    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR˜   Z  s6    			


N(   R•   R–   R  R   R#   R|   R}   R˜   (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyR¡  )  s   	'(H   t
   __future__R    t   cctbx.sgtbxR¿  t   boost.pythont   boostt   pythont
   import_extR"   R   R   R   R   R   R   R   t   cctbx.array_familyR	   R‡  R
   t   scitbx.matht   libtbx.math_utilsR   R�   R   t   scitbx.python_utils.miscR   R   t   libtbx.str_utilsR   t   libtbx.utilsR   R   R   R   R   t   libtbx.table_utilst	   itertoolsR   R   R�  R×  R„  R   t   timeR|   R   t!   floating_point_epsilon_double_getR"  t   generate_r_free_params_strR    R!   t   objectR—   R›   R5   R4   R   R=   R  R  R+  R   R_  Rò  Ra  R˜  RŒ  R,   R¿  RO  R¡  (    (    (    sC   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/miller/__init__.pyt   <module>   s†   
		ì,	ÿ ÿ ÿ ÿ ÿ ¦!	^	ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ÿ ½7Þ¡