ó
7™xTc           @   sä   d  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 „  Z d	 „  Z e e d
 „ Z e e d „ Z d „  Z e d k rà e e
 j ƒ d k rÖ e e
 j d e e ƒ qà e ƒ  n  d S(   s[   
Construct all subgroup graphs and their relations between them from a single space group.
iÿÿÿÿ(   t   division(   t   sgtbx(   t   show_cosets(   t   pointgroup_tools(   t   debug_utilsNc         C   s“   i  } x† |  D]~ } xu |  | D]i } | d  k	 r | j | ƒ rm | | } | j | ƒ | j i | | 6ƒ q‡ | j i | g | 6ƒ q q Wq W| S(   N(   t   Nonet   has_keyt   appendt   update(   t   dictt   new_dictt   itemt   valuet   tmp(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/maximum_subgroups.pyt   reverse_dict   s    
"c         C   sõ   g  } | j  |  ƒ r" | |  } n  i  } x" | D] } | j i t | 6ƒ q/ Wg  } xp | D]h } i  } | j  | ƒ r‚ | | } n  t } x7 | D]/ }	 |	 | k r� | j i t |	 6ƒ t }
 q� q� WqZ Wx( | D]  }	 | |	 rÍ | j |	 ƒ qÍ qÍ W| S(   N(   R   R   t   Truet   FalseR   (   t   sg_namet   reverse_grapht	   subgroupst   maximalt   sgt   resultt   trial_sgR   t,   is_trial_sg_a_subgroup_of_items_in_subgroupsR   t#   is_trial_sg_a_subgroup_of_subgroups(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/maximum_subgroups.pyt   get_maximal_subgroup   s(    
c         C   sR  t  j |  ƒ j ƒ  } t  j d ƒ j ƒ  } t j | | t t ƒ } t t  j |  ƒ ƒ } t | j	 j
 ƒ } t | | ƒ } | rcd GHxw | | D]k }	 d }
 |
 |	 d t |	 ƒ d t | j	 j |	 | ƒ d t t | j	 j |	 | ƒ ƒ d 7}
 |
 GHqŽ WHd GHx# | D] }	 d }
 |
 |	 7}
 |
 GHq
WHHHd GHxa | D]$ }	 d	 GHt j |	 | ƒ d	 GHHHHHq8Wn2 d
 |  GHx# | D] }	 d }
 |
 |	 7}
 |
 GHqsWHHH| rNd GHt  j |  ƒ } x– | D]Ž }	 t  j |	 ƒ } | j ƒ  } t } y/ | j | ƒ } t } | Gd G| j | ƒ GHWn t k
 rn X| s¶d | | | j | ƒ f GHq¶q¶WHHHn  d  S(   Nt   p1sƒ   Subgroups of input space groups which can be constructed by introducing one single operator (and group completion) in the subgroup:s          i   t    iZ   s7   Maximal subgroup detected in the full sub-group-graph: sH    Cosets for each maximal sub-group and the input space group are listed:sA   -----------------------------------------------------------------s   Maximal subgroups of %s: sI   Minimal supergroups generated by the sub-groups of the input space group:s    is a minimal supergroup of s-   %s (%s) is a minimal supergroup of %s     [*](   R   t   space_group_infot   groupR   t   point_group_graphR   R   t   strR   t   grapht   oR   t   lent   edge_objectsR   t   runt'   change_of_basis_op_to_reference_settingt   change_basist	   Exception(   t   sg1t   show_allt   reverset   sg_hight   sg_lowt   graph_objectt
   highest_sgt   rev_dictt   maximal_subgroupsR   t   linet   tmp_sgt   tmp_sgsgt   cb_opt   okait   new_sg(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/maximum_subgroups.pyt   create_all_subgroups6   sp    Z	
		
	 "c         C   s   t  |  | | ƒ d  S(   N(   R8   (   R)   t   showR+   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/maximum_subgroups.pyt
   run_singlew   s    c          C   s7   t  j t t t t ƒ }  x |  D] } t | ƒ q Wd  S(   N(   R   t   get_test_space_group_symbolsR   R   R:   (   t   sglistR   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/maximum_subgroups.pyt   run_allz   s    t   __main__i   (   t   __doc__t
   __future__R    t   cctbxR   t   cctbx.sgtbxR   R   t   cctbx.developmentR   t   sysR   R   R   R   R8   R:   R=   t   __name__R#   t   argv(    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/maximum_subgroups.pyt   <module>   s   		A	