ó
B™xTc           @   sŒ   d  d l  m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d e f d	 „  ƒ  YZ
 d
 e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   division(   t   uctbx(   t   matrixt   gruber_parameterizationc           B   s’   e  Z 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 RS(   c         C   s–   | d  k r d } n  | j ƒ  } | d |  _ | d |  _ | d |  _ d | d |  _ d | d |  _ d | d |  _ | j ƒ  d	 | |  _	 d  S(
   Ngñhãˆµøä>i    i   i   i   i   i   g      @gUUUUUUÕ?(
   t   Nonet   metrical_matrixt   at   bt   ct   dt   et   ft   volumet   epsilon(   t   selft	   unit_cellt   relative_epsilont   sym_mat3(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   __init__   s     	c         C   s(   |  j  |  j |  j |  j |  j |  j f S(   N(   R   R   R   R	   R
   R   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   as_gruber_matrix   s    c         C   s4   |  j  |  j |  j |  j d |  j d |  j d f S(   Ni   (   R   R   R   R	   R
   R   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   as_niggli_matrix   s    c         C   s4   |  j  |  j |  j |  j d |  j d |  j d f S(   Ni   (   R   R   R   R   R
   R	   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   as_sym_mat3   s    c         C   s   t  j d |  j ƒ  ƒ S(   NR   (   R   R   R   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   as_unit_cell   s    c         C   s   | | |  j  k  S(   N(   R   (   R   t   xt   y(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   eps_lt   s    c         C   s   |  j  | | ƒ S(   N(   R   (   R   R   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   eps_gt!   s    c         C   s#   |  j  | | ƒ p! |  j  | | ƒ S(   N(   R   (   R   R   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   eps_eq$   s    c         C   sä   |  j  } |  j |  j |  j } } } d } d } | d | ƒ rN | d 7} n | | d ƒ sj | d 7} n  | d | ƒ r† | d 7} n | | d ƒ s¢ | d 7} n  | d | ƒ r¾ | d 7} n | | d ƒ sÚ | d 7} n  | | f S(   Ni    i   (   R   R	   R
   R   (   R   t   ltR	   R
   R   t   n_zerot
   n_positive(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   def_test'   s"    	      c         C   s4   |  j  ƒ  \ } } | d k p3 | d k o3 | d k S(   Ni   i    i   (   R   (   R   R   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   def_gt_04   s    c         C   s6   |  j  ƒ  \ } } | d k r" d S| d k r2 d Sd S(   Ni   i   i    i   (   R   (   R   R   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   type8   s      c         C   s¢   |  j  } |  } | | j | j ƒ r( t S| | j | j ƒ rA t S| t | j ƒ | j ƒ r` t S| t | j ƒ | j ƒ r t S| t | j ƒ | j ƒ rž t St	 S(   N(
   R   R   R   t   FalseR   t   absR	   R
   R   t   True(   R   t   gtt   s(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   meets_primary_conditions>   s    	     c         C   s€   |  j  ƒ  s t S|  j ƒ  } | d k r, t S| d k r| |  j } |  } | | j | j | j | j | j d ƒ r| t Sn  t	 S(   Ni    i   (
   R'   R"   R!   R   R	   R
   R   R   R   R$   (   R   R!   R   R&   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   meets_main_conditionsH   s      	. c         C   s¦   |  j  ƒ  s t S|  j } |  j } |  } | | j | j ƒ re | t | j ƒ t | j ƒ ƒ re t Sn  | | j | j	 ƒ r¢ | t | j ƒ t | j
 ƒ ƒ r¢ t Sn  t S(   N(   R(   R"   R   R   R   R   R#   R	   R
   R   R   R$   (   R   t   eqR%   R&   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   is_buerger_cellR   s     		! ! c         C   sÄ  |  j  ƒ  s t S|  j } |  j } |  } | | j | j ƒ r` | | j | j | j ƒ r` t Sn  | | j | j ƒ r˜ | | j | j | j ƒ r˜ t Sn  | | j | j ƒ rÐ | | j | j | j ƒ rÐ t Sn  | | j | j ƒ rÿ | | j d ƒ sÿ t Sn  | | j | j ƒ r.| | j d ƒ s.t Sn  | | j | j ƒ r]| | j d ƒ s]t Sn  | | j | j | j | j | j d ƒ rÀ| | j | j | j | j | j d ƒ rÀt Sn  t	 S(   Ni    (
   R*   R"   R   R   R	   R   R   R
   R   R$   (   R   R)   R%   R&   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   is_niggli_cell]   s6     		      .. N(   t   __name__t
   __module__R   R   R   R   R   R   R   R   R   R   R    R!   R'   R(   R*   R+   (    (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyR      s   											
	
	t   iteration_limit_exceededc           B   s   e  Z RS(    (   R,   R-   (    (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyR.   r   s    t   reduction_basec           B   sb   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   c      
   C   s\   | d  k r d |  _ n	 | |  _ t j |  | | ƒ t j d ƒ |  _ d |  _ d |  _ d  S(   Niè  i   i    iÿÿÿÿ(	   i   i    i    i    i   i    i    i    i   (   iÿÿÿÿiÿÿÿÿiÿÿÿÿ(	   R   t   _iteration_limitR   R   R   t   sqrt   _r_invt   _n_iterationst   _last_after_all_obtuse_action(   R   R   R   t   iteration_limit(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyR   v   s    		c         C   s   |  j  S(   N(   R0   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyR5   €   s    c         C   s   |  j  S(   N(   R2   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   r_invƒ   s    c         C   s>   d d l  m } | j | j | j |  j j d ƒ ƒ ƒ j ƒ  S(   Niÿÿÿÿ(   t   sgtbxi   (   t   cctbxR7   t   change_of_basis_opt   rt_mxt   rot_mxR2   t   elemst   inverse(   R   R7   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyR9   †   s    c         C   s   |  j  S(   N(   R3   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   n_iterations‹   s    c         C   s_   |  j  |  j k r4 t d |  j ƒ  |  j f ƒ ‚ n  |  j t j | ƒ 9_ |  j  d 7_  d  S(   Ns'   %s iteration limit exceeded (limit=%d).i   (   R3   R0   R.   t   _nameR2   R   R1   (   R   t   m_elems(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt	   cb_updateŽ   s    c      
   C   sC   |  j  d ƒ |  j |  j |  _ |  _ |  j |  j |  _ |  _ d  S(   Ni    iÿÿÿÿ(	   i    iÿÿÿÿi    iÿÿÿÿi    i    i    i    iÿÿÿÿ(   RA   R   R   R
   R	   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt	   n1_action–   s    c      
   C   sC   |  j  d ƒ |  j |  j |  _ |  _ |  j |  j |  _ |  _ d  S(   Niÿÿÿÿi    (	   iÿÿÿÿi    i    i    i    iÿÿÿÿi    iÿÿÿÿi    (   RA   R   R   R   R
   (   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt	   n2_action›   s    c      
   C   sË   |  j  } d \ } } } | |  j d ƒ r3 d } n  | |  j d ƒ rN d } n  | |  j d ƒ ri d } n  |  j | d d d | d d d | f	 ƒ t |  j ƒ |  _ t |  j ƒ |  _ t |  j ƒ |  _ d  S(   Ni   i    iÿÿÿÿ(   i   i   i   (   R   R	   R
   R   RA   R#   (   R   R   t   it   jt   k(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   n3_true_action    s    	 	 	 	(c         C   s…  |  j  } |  j } d d d g } d } | |  j d ƒ rF d | d <n | |  j d ƒ sa d } n  | |  j d ƒ r€ d | d <n | |  j d ƒ s› d } n  | |  j d ƒ rº d | d <n | |  j d ƒ sÕ d } n  | d | d | d d k  r| d k st ‚ d | | <n  |  j | d d d d | d d d d | d f	 ƒ t |  j ƒ |  _ t |  j ƒ |  _ t |  j ƒ |  _ d  S(   Ni   iÿÿÿÿi    i   (   R   R   R	   R
   R   t   AssertionErrorRA   R#   (   R   R   R%   R   t   z(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   n3_false_action«   s.    		  	  	  	 4(   R,   R-   R   R5   R6   R9   R>   RA   RB   RC   RG   RJ   (    (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyR/   t   s   	
								t   minimum_reduction_mixinc           B   s2   e  Z d  Z d d d d „ Z d „  Z d „  Z RS(   st   Development and regression test code. Do not use for applications.
     Use uctbx.fast_minimum_reduction instead.
  i   i   c         C   s¬   | |  _  | |  _ d |  _ | j ƒ  d  \ } } } | | | f |  _ |  j j d |  _ y/ |  j j |  d | d d d | ƒt	 |  _
 Wn t k
 r§ t |  _
 n Xd  S(   Ni    i   i   R   R   R5   (   t"   multiplier_significant_change_testt   min_n_no_significant_changet   _n_no_significant_changeR   t!   _last_abc_significant_change_testt	   __class__t	   __bases__t	   reductionR   R"   t*   termination_due_to_significant_change_testt   StopIterationR$   (   R   R   R5   RL   RM   R   R   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyR   Ã   s    			c         C   s   t  S(   N(   R"   (   R   R   R   (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyR   Õ   s    c         C   s°   |  j  |  j |  j f } |  j } t g  t | |  j ƒ D]& \ } } | | | | | | ^ q7 ƒ } | d k rš |  j d 7_ |  j |  j k r£ t	 Sn	 d |  _ | |  _ t
 S(   Ni    i   (   i    i    i    (   R   R   R   RL   t   tuplet   zipRO   RN   RM   R"   R$   (   R   t   abct   mt   newt   lastt   change(    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   significant_change_testØ   s    	?		N(   R,   R-   t   __doc__R   R   R   R\   (    (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyRK   ¾   s   	N(   t
   __future__R    R8   R   t   scitbxR   t   objectR   t   RuntimeErrorR.   R/   RK   (    (    (    sH   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/reduction_base.pyt   <module>   s   mJ