ó
YxTc           @   sŖ   d  d l  m Z d  d l m Z m Z m Z m Z d  d l m Z d  d l	 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   construct_edge_setst   extract_edge_listt   sub_edge_listt   tree_marking(   t   slots_getstate_setstateNt   cluster_managerc           B   sų   e  Z d  d d d d d d d g Z e d d  Z d	   Z d d
 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   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(    t   fixed_vertex_listst   cluster_indicest   clusterst/   merge_clusters_with_multiple_connections_passest   hinge_edgest
   loop_edgest   loop_edge_bendingst   fixed_hingesc         C   sĄ  | |  _  t |  j   d k r | rI d g | |  _ t |  g |  _ qt |  |  _ g  |  _ x+t |  D] } |  j j | g  qn Wn| s t  d g | |  _ g  |  _ x |  j  D]t } t |  d k sÜ t  x= | D]5 } |  j | d k st  t |  j  |  j | <qć W|  j j t |   q¾ WxV t |  D]H } |  j | d k rbqCn  t |  j  |  j | <|  j j | g  qCWd |  _	 d  |  _ d  |  _ d  |  _ d  |  _ d  S(   Ni    i’’’’(   R   t   lenR   t   rangeR	   t   xranget   appendt   AssertionErrort   listR
   t   NoneR   R   R   R   (   t   Ot
   n_verticest   all_in_one_rigid_bodyR   t   it   fixed_vertices(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   __init__   s8    			 				c         C   s   t  |  j  d k S(   Ni   (   R   R	   (   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR   5   s    t    c         C   s@  d d l  m } m } d d  l } | d  k r: | j } n  | | d It |  j  IJ| | d It g  |  j D] } t |  ^ qr  IJ| | d It |  j	  IJ| | d | |  j
 d  IJ| | d I| |  j  IJ| | d	 I| |  j  IJ| | d
 I| |  j  IJ| | d I| |  j  IJ|  S(   Ni’’’’(   t   xlent   plural_ss   number of fixed vertex lists:s   number of fixed vertices:s   number of clusters:s3   merge clusters with multiple connections: %d pass%st   ess   number of hinge edges:s   number of loop edges:s   number of loop edge bendings:s   number of fixed hinges:(   t   libtbx.utilsR   R   t   sysR   t   stdoutR   R   t   sumR	   R
   R   R   R   R   (   R   t   outt   prefixR   R   R!   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   show_summary8   s"     (
c         C   s   d d  l  } | d  k r$ | j } n  | r[ x. d d d d d g D] } | | | IJq@ Wn  x" |  j   D] } | | | IJqh W|  S(   Ni’’’’s$   # clusters are in square brackets []s#   # hinge edges are in parentheses ()s>   # (0, 1) -> [2, 3] means that the cluster with vertices [2, 3]s3   #   rotates around the axis through vertices (0, 1)s/   # integers are vertex indices (counting from 0)(   R!   R   R"   t,   hinge_edges_and_clusters_as_indented_strings(   R   R$   R%   t   headerR!   t   line(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt	   show_treeJ   s     c         C   sQ   i  } |  j  } x; |  j D]0 } | | d } | | k s? t  | | | <q W| S(   Ni    (   R   R   R   (   R   t   resultt   ciR   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt'   fixed_vertices_given_cluster_index_dictY   s    	c   	      C   s!  |  j  d  k s t  | | k r% d  St |  j  } | | k  r[ | | k  r[ t d   n  |  j } |  j | } |  j | } | s© t |  t |  k s© | | k  rń | | k sĮ | d k rń x | D] } | | | <qČ W| j |  | 2| Sx | D] } | | | <qų W| j |  | 2| S(   Ns>   connect_clusters(): fixed vertex lists in same connected tree.i    (	   R   R   R   R   R   t   RuntimeErrorR   R	   t   extend(	   R   t   ciit   cijt   optimizet   lfvlR,   t   ccijt   cciit   k(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   connect_clustersb   s0     	  c         C   sB   |  j  d  k s t  |  j } |  j d | | d | | d |  S(   NR0   R1   R2   (   R   R   R   R   R7   (   R   R   t   jR2   R,   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   connect_verticesz   s    	c         C   sH   |  j  } x8 t |  j  D]' \ } } x | D] } | | | <q, Wq Wd  S(   N(   R   t	   enumerateR	   (   R   R,   t   ict   cR   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   refresh_indices   s    	c            sµ     j  d  k s t  x   j D] } | j   q W  f d   }   j j |  xR t t   j  d d d  D]1 } t   j |  d k rr   j | d 3Pqr qr W  j   d  S(   Nc            sē   t  |   d k r t  |  d k r   j |  d t    j  k  }   j | d t    j  k  } | rw | s d Sq | r d Sn  t  |   t  |  k r  d St  |   t  |  k  r¼ d St  |   d k rć t |  d | d  Sd S(   Ni    i’’’’i   (   R   R   R   t   cmp(   t   at   bt   fat   fb(   R   (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   cmp_clusters   s    $       i   i’’’’i    (   R   R   R   R	   t   sortR   R   R=   (   R   R<   RC   R;   (    (   R   sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   tidy   s     &c   	   	   C   sE  x4t  r6|  j d 7_ t } xt t |  j   D]ń } xč t  r$t   } t   } xr |  j | D]c } xZ | | D]N } |  j | } | | k r qt n  | | k rµ | j |  qt | j |  qt Wqc Wt |  d k rą Pn  x> | D]6 } |  j	 d | d | d t  | k st
  t  } qē Wq= Wq4 W| s Pq q W|  j   d  S(   Ni   i    R0   R1   R2   (   t   TrueR
   t   FalseR   R   R	   t   setR   t   addR7   R   RE   (	   R   t	   edge_setst   repeatR0   t	   connectedt   multipleR   R8   R1   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt(   merge_clusters_with_multiple_connections   s.    				  *c         C   s¢   g  } x- t  t |  j   D] } | j t    q W|  j } x\ | D]T \ } } | | } | | } | | k rx qF n  | | j |  | | j |  qF W| S(   N(   R   R   R	   R   RH   R   RI   (   R   t	   edge_listR+   R   R,   R8   R0   R1   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   cluster_edge_sets²   s    	

 c            sÜ   |  j  d  k s t  g   xŗ |  j D]Æ       f d   } t    d k r\ |   q%   d }  | } t |  d k r |   q% t |  d } t  |  d k r% | | k r%  j | | f  q% q% W S(   Nc             sK   t     }  x   D] } |  j  |  q W j t t |     d  S(   N(   RH   t   updateR   t   tuplet   sorted(   R<   R   (   t   clusterRJ   R+   (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt"   add_cluster_and_connected_verticesĆ   s    i   i    (   R   R   R   R	   R   R   R   (   R   RJ   RU   R   t   esiR8   (    (   RT   RJ   R+   sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   overlapping_rigid_clustersæ   s    



"c            sh  d g t  |  j    x¼ |  j D]± } t  |  } | d k sD t  | d } |  j | } |   | <| d k r  x] | | D]N } |  j | } | | k r” q| n    | d k rĄ t d   n  d   | <q| Wq  q  Wg  } xd t |  j  D]S \ } }	 t |	  }
 x |	 D] } |
 j | |  q
W| j	 | t  |
  f  qė W  f d   } | j
 |  |   f S(   Ni    i   sb   determine_weighted_order_for_construct_spanning_tree(): fixed vertex lists in same connected tree.i’’’’c            s   t    |  d  } t    | d  } | | k r8 d S| | k  rH d S|  d | d k r` d S|  d | d k  rx d St |  d | d  S(   Ni    i’’’’i   (   t   absR>   (   R?   R@   RA   RB   (   t   fixed_vertex_info(    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt	   cmp_elemsģ   s        (   R   R	   R   R   R   R.   R:   RH   RQ   R   RD   (   R   RJ   R   t   lvfR   R0   R8   R1   t   cii_orcsRT   R<   RZ   (    (   RY   sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt4   determine_weighted_order_for_construct_spanning_treeÕ   s2    

 c            są    j  d  k s t  | d  k rL   j   s3 t  d g   _  g    _ d  S  j d |  \   t   j  } g    j D] } d | d f ^ q}  g    _ | d k r· d } n% t g   D] \ } } | ^ qĮ  } g   x% t	 | d  D] 	  j
 g   qó W| g |  x, t	 |  D] }  | d } |  | <q$Wd g |  g  }	 x°t	 |  D]¢}  | d }  | }
 |
 d d k rqfn   | d k g  d  | <|	 j
 |            	 
 f d   } d } xX   j | D]I 	 x@ | 	 D]4 
   j 
   | k r;qn  | d |  } qWqWx³t rd  } | }  | } x= t	 t |   D]) } | | | k r| } | | } qqW| d  k rĮPn  | | = | d } xn   j | D]_ 	 xV | 	 D]J 
   j 
   | k rqõn    d k r0qõn  | d |  } qõWqäW | d k s]t  d  | <|	 j
 |   | }
 |
 d d k rĢ  j   j |
 d j
 |
 d    j | j |
 d  n  x5 t	 | d d  D]  } t  |  d k rßPqßqßWPqUWqfWt |	  | k s$t   j d  t   k sEt  g  } g    _  xW |	 D]O }   j | } t |  d k r[| j
 t |     j  j
  |  q[q[W  j 2  j j |    j     j j   d  S(   Ni’’’’i    RJ   i   c            s»     d k r6  d r) t  d   n  t  d <n    d k r_   j j 	 
 f  nX d   <  }  | d }  | j |  	 
 f   <|  | k  r· | }  n  |  S(   Ni    sF   construct_spanning_trees(): fixed vertex lists in same connected tree.i’’’’i   (   R.   RF   R   R   (   t   w_maxt   cij_wot   w(   R   t   candiR\   t   cii_wo_given_ciiR1   t   doneRY   t
   have_fixedR   R   R8   (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   set_loop_or_hinge_edge  s    


 	R^   (   i’’’’i    (   R   R   R   R   R   R]   R   R	   t   maxR   R   R   RF   t   removet   countRS   R/   R=   RD   (   R   RJ   t
   n_clustersR<   R^   R0   t   orcst   ip_wot   ipt   cluster_permt   heRe   t   kpt   cwR6   t   new_clusters(    (   R   Ra   R\   Rb   R1   Rc   RY   Rd   R   R   R8   sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   construct_spanning_trees÷   s¦    		&	 	%
 
- 	
  

#	!	
c         C   s_   |  j  d  k	 s t  g  } x= t |  j   D], \ } } | d d k r+ | j |  q+ q+ W| S(   Ni    i’’’’(   R   R   R   R:   R   (   R   R+   R   Rn   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   rootsY  s    c         C   s   |  j  d  k	 s t  g  } d } xW |  j  D]L } | d d k r[ | j |  | d 7} q+ | j | |  j | d  q+ W| S(   Ni    i’’’’i   (   R   R   R   R   R   (   R   R+   t   tidRn   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   tree_idsa  s     c         C   sC  |  j  d  k	 s t  |  j d  k s* t  | d  k rU |  j   sH t  g  |  _ d  St   } xĻ |  j  D]Ä \ } } xY | | D]M } | | k r q n  | | | k s­ t  | j t t | | f    q WxY | | D]M } | | k ró qŪ n  | | | k s	t  | j t t | | f    qŪ Wqh Wt |  |  _ d  S(   N(	   R   R   R   R   R   RH   RI   RR   RS   (   R   RJ   t   lebR   R8   R6   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   find_loop_edge_bendingsm  s&    		 # 'c         C   s9  |  j  d  k	 s t  |  j d  k s* t  g  |  _ |  j   rC d  S| d  k rS d  St | d  r d d l m } | j |  } n  t	 t
 j t
 j |    } xt t |  j  d d d  D]b} |  j | \ } } | d k rķ qĀ n  | | } | | | }	 x|  j | D]9 }
 t	 |	 j | |
 | d d  } | | k  rPqqW|  j j |  j |  |  j | =|  j | } |  j | j |  j |  |  j | j   |  j } x |  j | D] }
 | | |
 <qĮW|  j | =xB t | t |  j   D]( } x |  j | D] }
 | | |
 <qWqųWqĀ W|  j j   d  S(   Nt   accessori’’’’(   t   matrixi   t   value_if_undefined(   R   R   R   R   R   t   hasattrt   scitbxRy   t   col_listRX   t   matht   cost   radiansR   R   R	   R   t	   cos_angleR   R   R/   RD   (   R   t   sitest   angular_tolerance_degRy   t   abs_cos_limitt   jct   hit   hjt   pivott   axisR   t   abs_cosR;   R,   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   fix_near_singular_hinges  sD    	  &
#
	
c         C   sŌ   |  j  d  k	 s t  t |  j   t |  j  k s9 t  d  g t |  j  } x~ t |  j  D]m \ } } |  j  | \ } } | d k r d | | <q_ |  j | } | | d  k	 sŗ t  | | d | | <q_ W| S(   Ni’’’’i    i   (   R   R   R   R   R	   R:   R   (   R   R+   R;   t   clR   R   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   root_distances£  s    $c         C   s   g  } |  j    } x t |  j  D]o \ } } |  j | } | | } | d k rg | j t |   q" | j d d | t |  t |  f  q" W| S(   Ni    s
   %s%s -> %ss     (   R   R:   R	   R   R   t   str(   R   R+   t
   root_distsR;   R   Rn   t	   root_dist(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR'   ±  s    
.c         C   s   t  d |   S(   NR   (   t   edge_classifier(   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR   ½  s    (    N(   t   __name__t
   __module__t	   __slots__RG   R   R   R   R&   RF   R*   R-   R7   R9   R=   RE   RN   RP   RW   R]   Rr   Rs   Ru   Rw   R   R   R'   R   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR      s<   												"	b				#		R   c           B   s   e  Z d    Z d   Z RS(   c         C   s  | |  _  t   |  _ xC | j D]8 } | d d k r; q n  |  j j t t |    q Wt g  | j D] } t t |   ^ qh  |  _ t	 |  j j
 |  j   d k s³ t  t | j  |  _ t	 |  j j
 |  j   d k sģ t  t	 |  j j
 |  j   d k st  d  S(   Ni    i’’’’(   R   RH   t   hinge_edge_setR   RI   RR   RS   R   t   loop_edge_setR   t   intersectionR   R   t   fixed_hinge_set(   R   R   t   e(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR   Ā  s    	  +''c         C   s„   t  t |   } | |  j k r% d S| |  j k r8 d S| |  j k rK d S|  j } g  | D] } | j | ^ q[ \ } } | | k r” | j | d d k r” d Sd S(   Nt   fixedt   hinget   loopi    i’’’’t   baset   intra(   RR   RS   R   R   R   R   R   R   (   R   t   edget   cmR   R0   R1   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   __call__Ļ  s       	&# (   R   R   R   R”   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR   Ą  s   	t
   find_pathsc           B   s   e  Z d    Z d   Z RS(   c         C   s&   | |  _  t g t |  j   |  _ d  S(   N(   RJ   RG   R   t   in_path(   R   RJ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR   Ū  s    	c            sw   |  j   |  j  i   i    g           f d    x%   D] }  d  d |  qP W   f S(   Nc            s   j  |  t  | <t } xm  | D]a } | |  k r@ q( n  |  k rv  j  d g   j   d  t } q(  | r( t } q( q( W| rt   d k rxY  | D]J } | |  k rÉ q± n    j | g   j  t     d | d |  q± Wn   j   t  | <d  S(   Ni    i   i   t   jvt   kv(   R   RF   RG   t
   setdefaultR   RH   t   pop(   R¤   R„   t   closingt   lv(   t	   dendritest   depth_first_searchRJ   R£   t   ivt   loopst   path(    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR«   å  s&    
 !	
 
R¤   R„   (   RJ   R£   (   R   R¬   R¤   (    (   RŖ   R«   RJ   R£   R¬   R­   R®   sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   search_fromß  s    		!(   R   R   R   RÆ   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR¢   Ł  s   	t	   constructc           B   sÅ   e  Z d  d d d d d g Z d d d d d d d d  Z d d d	  Z d d e d
  Z d   Z d   Z	 d   Z
 d   Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z RS(   R   RO   RJ   R   t   external_clusters_connect_countt   find_cluster_loop_repeatsi   c   	      C   sÅ  | | g j  d   d k s! t  | d  k	 s3 t  | | g j  d   d k sT t  | d  k	 ro t |  } n  | |  _ | d k } | r± | d  k s t  d  |  _ d  |  _ n! | |  _ t d | d |  |  _ | d  k r;| d  k sü t |  d k rd } q;|  j d  k	 st  t d |  j  j	 d |  } n  t
 d | d | d |  |  _
 | s||  j   |  j d	 |  n  |  j
 j   d  |  _ | d  k	 rĮ|  j   |  j d
 | d |  n  d  S(   Ni   i    R   R   RO   RJ   t   vertex_indicesR   R	   R   R   (    (   Rh   R   R   R   R   RO   RJ   R   R   t   partitions_ofR   t   _find_pathst   _process_external_clustersRE   R²   t
   build_treeR   (	   R   R   R   RO   t   external_clustersR   R   t*   near_singular_hinges_angular_tolerance_degR   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR     sD    !!				
	
	R   c         C   s  d d l  m } m } d d  l } | d  k r: | j } n  | d  k r d t t t d |  j	 d    } g  t
 |  j	  D] } | | ^ q| } n t |  |  j	 k s° t  | | d I|  j	 IJ| | d I| |  j  IJ|  j d  k r| | d IJn | | d	 | |  j  IJ|  j }	 |	 j d
 | d |  |	 j d  k	 rxJ |	 j D]< \ } }
 | | d I| | IJ| | d I| |
 IJqWWn  |  S(   Ni’’’’(   R   R   s   %%0%ddi    i   s   number of vertices:s   number of edges:s   find cluster loops: Nones   find cluster loops: %d repeat%sR$   R%   s   tardy fixed hinge:s                     (   R    R   R   R!   R   R"   R   R   Rf   R   R   R   RO   R²   R   R&   R   (   R   t   vertex_labelsR$   R%   R   R   R!   t   fmtR   R    R8   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR&   2  s*     &)
	c         C   s#   |  j  j d | d | d |  |  S(   NR$   R%   R(   (   R   R*   (   R   R$   R%   R(   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR*   J  s    c         C   s   t  d |  j  S(   NRJ   (   R   RJ   (   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR   N  s    c         C   s#  t  d |  j  } x
t |  j  D]ł} | j d |  \ } } xŁ | j   D]Ė \ } } t } g  } xf | D]^ }	 t |	  d k  r½ x- |	 D]% }
 |  j j	 d | d |
 d t
  q Wt
 } ql | j |	  ql W| rM xA | D]6 }	 x- |	 D]% }
 |  j j	 d | d |
 d t
  qč WqŪ WqM qM Wxü| j   D]ī\ } } t |  d k  rMq)n  d  g  g  g  g  g  g } x% | D] } | t |  j |  qlWd } xot d	 d
  D]^} xUt d	 t d
 d |   D]7} x.t d	 t d
 d | |   D]} | d	 7} xł | | D]ķ } xä | | D]Ų } | j |  } t |  t |  t |  k rVqn  x | | D] } | j |  } t |  t |  t |  k rqan  |  j j	 d | d | d t
  x- | D]% }
 |  j j	 d | d |
 d t
  qÄWqaWqWqWqķWqĘWq£W| d k s)t  q)Wq" Wd  S(   NRJ   R¬   i   R   R8   R2   i   i    i   i   i
   iH   (   R¢   RJ   R   R   RÆ   t   itemsRG   R   R   R9   RF   R   R   t   mint   unionR   (   R   t   fpR¬   R­   RŖ   R¤   t   loops_through_jvt
   have_smallt   l5st   loop_through_jvR„   t	   sps_to_jvt   sps_by_lengtht   sp_to_jvt   n_l1_l2_l3_lt_10t   l1t   l2t   l3t   sp1t   sp2t   sp12t   sp3t   sp123(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyRµ   Q  sT    #	. #'
" " /c      	   C   sė   d |  _  | d  k r d  S|  j j } xæ | D]· } t d |  j d |  } | j   } x | j D] \ } } t | |  d k r q` n  t | |  d k r¤ q` n  | d | | d | | d t  d  k	 r` |  j  d 7_  q` q` Wq, Wd  S(   Ni    RJ   R³   i   R   R8   R2   (	   R±   R   R   R9   R   RJ   RO   R   RF   (   R   R	   t   cvRT   t   subt   sub_edge_setst   i_subt   j_sub(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR¶   }  s    	   )c   	   	   C   sQ  |  j  d  k s t  |  j d  k r1 d |  _  d  Sd |  _  |  j } xt rL|  j  d 7_  | j d |  j  | j d |  j  } t	 d |  } t
 d t | j  d |  } | j } | j d | j  t | j  t | j  k rī Pn  xN | j D]C } | d } x0 | d D]$ } | j d | d | d	 t  } qWqų W| j   qF W|  S(
   Ni    i’’’’i   RJ   RO   R   R0   R1   R2   (   R²   R   R   RJ   R   RF   RN   RP   RO   R   R°   R   R	   R7   RE   (	   R   R    t   cest   celt   cttt   ccmt   ccR0   R1   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   find_cluster_loops  s,    					
&c         C   s=   |  j    |  j } | j d |  j  | j d |  j  |  S(   NRJ   (   RŚ   R   Rr   RJ   Rw   (   R   R    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR·   ¢  s
    
	c         C   s   |  j  j d | d |  |  S(   NR   R   (   R   R   (   R   R   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR   ©  s    c         C   s   |  j  S(   N(   t   rmsd_calculation(   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   rmsd_calculator®  s    c         C   s(   | j  | j |  j d | d |    S(   Nt   sites_cart_1t   sites_cart_2(   t   rms_differencet   selectt   rmsd_permutation(   R   RŻ   RŽ   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyRŪ   ±  s    	c         C   s{  | j    t |  j  k s! t  | j    t |  j  k sB t  d d l m } | j t |  j   } x
t |  j  D]ł \ } } t |  d k r qz n  | j   } x7 | D]/ } t |  j |  d k r± | j	 |  q± q± Wt |  d k rü qz n  | j t
 |   }	 | j |  }
 |
 j | j |   } |
 j | j |	   } | | d k  rz | j | |	  qz qz W| S(	   s)   simple, limited handling of flipped sitesi’’’’(   t   flexi   i   i   gķµ ÷Ę°>(   i   i   gé!ēż’ļ?(   t   sizeR   RJ   R   t   scitbx.array_familyRā   t   size_t_rangeR:   t   size_tR   t   reversedRą   Rß   t   set_selected(   R   RŻ   RŽ   Rā   R+   R   RV   t   n1R8   t   n1_revt   pair_1t   rmsd_1t   rmsd_2(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyRį   ·  s(    !!  c         C   s2   d d d d d d g } | r. | j  d  n  | S(   Ns   Edge colors:s7     turquoise: intra-base-cluster, six degrees of freedoms2     green:     rotatable bond, one degree of freedoms     blue:      intra-clusters(     red:       loop edge (restrained only)s1     pink:      near singular rotatable bond (fixed)s0     purple:    loop bending edge (restrained only)(   R   (   R   t   include_loop_edge_bendingsR+   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   viewer_lines_with_colors_legendĢ  s    	 
c         C   s²   g  } i d d 6d d 6d d 6d d 6d d d f d
 6} |  j  j   } x1 |  j D]& } | j | | | d |  f  qQ W| r® x* |  j  j D] } | j | d f  q Wn  | S(   Ni    i   R   R   R   R   i¶   i’   iĮ   R   R   g      ą?(   i    i   i   (   i    i   i    (   i    i    i   (   i   i    i    g×ÖÖÖÖÖę?g888888č?(   g      ą?i    g      ą?(   R   R   RO   R   R   (   R   Rī   R+   t   colorst   ecR)   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   viewer_lines_with_colorsŲ  s    $N(   R   R   R   R   R   R&   RF   R*   R   Rµ   R¶   RŚ   R·   R   RÜ   RŪ   Rį   Rļ   Rņ   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyR°   ū  s4   	&		,							(   t
   __future__R    t   scitbx.graph.utilsR   R   R   R   t   libtbxR   R~   R   t   objectR   R¢   R°   (    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/graph/tardy_tree.pyt   <module>   s   "’ ŗ"