ó
ÉÝ{Tc           @   sŒ   d  Z  d d l Td d l Z d d l Z d f  d „  ƒ  YZ d f  d „  ƒ  YZ d f  d	 „  ƒ  YZ d
 „  Z d „  Z	 d d „ Z
 d „  Z d S(   si  
     python/ui/model_symmetry.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2009 University of York, CCLRC
     Copyright (C) 2012 STFC

     This library is free software: you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public License
     version 3, modified in accordance with the provisions of the 
     license to address the requirements of UK law.
 
     You should have received a copy of the modified GNU Lesser General 
     Public License along with this library.  If not, copies may be 
     downloaded from http://www.ccp4.ac.uk/ccp4license.php
 
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU Lesser General Public License for more details.
iÿÿÿÿ(   t   *Nt   model_symmetryc           B   sä  e  Z i g  d  6d d 6d d 6d d 6d d 6Z d d	 g Z d d
 g Z d „  Z g  d „ Z d „  Z d d „ Z d d „ Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z g  d „ Z d „  Z d d „ Z d d „ Z d d d d „ Z g  d d „ Z g  d „ Z g  d „ Z d „  Z g  g  d  „ Z d! „  Z d" „  Z d# „  Z d$ „  Z d% „  Z d d d& d' „ Z d( „  Z d) „  Z  d* „  Z! d+ „  Z" d, „  Z# d- „  Z$ d. „  Z% d/ „  Z& d0 „  Z' d1 „  Z( d2 „  Z) d3 „  Z* d4 d d5 „ Z+ RS(6   t   symmetry_matest    t   MolDisp_neighb_selectiong      @t   MolDisp_neighb_radiust   search_radiusi   t   search_ncellss	   all atomst   traces   catrace or monomersc         K   sŒ   | |  _  g  |  _ t ƒ  j d d d d d d g ƒ|  _ d |  _ g  |  _ g  |  _ g  |  _ g  |  _	 g  |  _
 d |  _ t j d	 |  _ d  S(
   NR   t   excludet   blackt   whitet   redt   blueiÿÿÿÿi   i    (   t   MolData_namet   biomol_listt   MGCOLOURt   nextt   previous_colourt   firstSymModelt   symmetry_MolDisp_objectst   symmetry_colourst   symmetry_visibleR   t   pending_symmetry_matest   MolDisp_visibleR   t   MolDisp_selection_menut   MolDisp_selection(   t   selfR   t   kw(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   __init__'   s    		'							c         C   s†   g  } xy | D]q } d d g j  | d ƒ s? | j d d ƒ n  | d d k rq t | ƒ d k rq | d d !} n  | j | ƒ q W| S(   Nt   xt   ni    i   i   (   t   countt   insertt   lent   append(   R   t   matest   updated_matest   item(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   version_update_mates:   s     " c         C   s   t  |  j ƒ j S(   N(   t   dataR   t   molHnd(   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR)   J   s    c         C   s€   g  |  _  |  j ƒ  j ƒ  } | d k r4 d d d g S|  j  sv x6 t | ƒ D]% } |  j  j |  j ƒ  j | ƒ ƒ qJ Wn  d d g S(   sE   
    Get symmetry info from PDB and create menu of symops_titles
    i    i   s.   No symmetry operations defined for space groupif   R   (   t   symops_titlesR)   t   GetNumberOfSymOpst   rangeR#   t   GetSymOp(   R   t   pdbfilet   nSymOpsR   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   check_symmetryP   s    	
	c         C   s*   t  | ƒ } | d s& | d |  _ n  d  S(   Ni    i   (   t   readPDBRemark350R   (   R   R.   t   rv(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   load_biomoleculeu   s    
 c         C   s   t  |  j ƒ S(   N(   R"   R*   (   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   nofCrystalSymops|   s    c         C   s6   i |  j  d 6|  j d 6|  j d 6|  j d 6|  j d 6S(   NR   R   R   R   R   (   R   R   R   R   R   (   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt	   getParams‚   s
    


c         C   sJ   xC d d d d d g D], } | j  | ƒ r t |  | | | ƒ q q Wd  S(   NR   R   R   R   R   (   t   has_keyt   setattr(   R   t   paramst   key(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt	   setParams‹   s     c         C   sé   g  } g  } g  } g  } g  } x� |  j  D]v } | d d k r( | j |  j | d ƒ | j t | d ƒ ƒ | j t | d ƒ ƒ | j t | d ƒ ƒ q( q( Wi | d 6| d 6| d	 6| d
 6|  j ƒ  d 6|  j d 6|  j d 6} | S(   Ni    R   i   i   i   i   t   symopt   tran_at   tran_bt   tran_ct	   model_numt   visiblet   colour(   R   R#   R*   t   strt   get_symmetry_modelsR   R   (   R   R;   R<   R=   R>   R@   R&   t   pars(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   getGuiParams’   s    Cc         C   su   g  } xh |  j  D]] } | d d k r6 | j | ƒ q | d d k r | j d | d j ƒ  | d f ƒ q q W| S(   Ni    R   R   i   i   (   R   R#   R5   (   R   R$   R&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   getSymmetryMates¥   s    +c         C   s>  |  j  | ƒ } g  } d  } xo | D]g } | d d k r| t | d t ƒ r| t d | d ƒ } | j d | | d g ƒ q" | j | ƒ q" Wd } | rÕ g  |  _ g  |  _ t ƒ  j d d d d	 d
 d g ƒ|  _	 n  |  j j
 |  j | ƒ ƒ |  j j
 |  j | ƒ ƒ |  j | d | ƒ| r:d GH|  j ƒ  j ƒ  } n  d  S(   Ni    R   i   R8   i   R   R	   R
   R   R   R   t   replaces>   FIXME (model_symmetry.py) - A preference here for aromaticize.(   R'   t   Nonet
   isinstancet   BiomoleculeDefinitionR#   R   R   R   R   R   t   extendt   assignColourst   assignVisiblet   buildSymmetryMatesR)   t   GetMolBonds(   R   t	   sym_matesR%   t   biomolR&   RG   t   output(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   setSymmetryMates²   s&    $		*c         C   s¤  d d  l  } d d  l } t | | j ƒ r| d k r: d S| j | d ƒ } t | ƒ d k s¡ t | d ƒ d k  s¡ t | d ƒ d k s¡ t | d ƒ d k r¥ d SyY d t | d ƒ t | d d ƒ d	 t | d d ƒ d	 t | d d ƒ d	 g } Wqd SXn  |  j j | ƒ r5|  j j	 | ƒ |  j
 S|  j j | ƒ rk|  j j	 | ƒ t |  j ƒ |  j
 S|  j j | ƒ t |  j ƒ t |  j ƒ |  j
 d Sd  S(
   Niÿÿÿÿt   1_555i   t   _i   i    i   R   i   (   t   typest   stringRI   t
   StringTypet   splitR"   t   intR   R    t   indexR   R   R#   (   R   R;   RV   RW   RY   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   getPendingSymmetryMateÖ   s"     UY$i    c         C   s7   |  j  r$ |  j |  j  d | ƒ} n d } g  |  _  | S(   NRG   i    (   R   RN   (   R   RG   R2   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   makePendingSymmetryMateò   s
    		c      	   C   sú   g  } g  } g  } x¿ t  t | d ƒ ƒ D]§ } |  j j | d | ƒ r) | j d |  j j | d | ƒ t | d | ƒ t | d | ƒ t | d | ƒ g ƒ | j | d | ƒ | j | d | ƒ q) q) W| |  _ | |  _ |  j	 | d ƒ d  S(	   NR;   R   R<   R=   R>   R@   RA   i   (
   R,   R"   R*   R    R#   R[   RZ   R   R   RN   (   R   R8   R#   R$   R@   t   colourst   ii(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   setGuiParamsý   s     :		t   allc   !      C   sH  d d  l  } d } d d g j | j | ƒ ƒ sx t |  j ƒ j d d | d ƒ } | d rk d d	 | g S| d
 } n  |  j ƒ  j ƒ  \ } } }	 }
 } } |  j ƒ  j ƒ  } |  j ƒ  j	 | d d t
 j d t
 j d d d d d t
 j ƒ |  j ƒ  j | ƒ } t t j | | ƒ ƒ } t t j | | ƒ ƒ } t t j | |	 ƒ ƒ } t t | j ƒ  | ƒ ƒ d
 } t t | j ƒ  | ƒ ƒ d
 } t t | j ƒ  |	 ƒ ƒ d
 } t | | | d | ƒ } t | | | d | ƒ } t | | | d | ƒ } g  } d } d } g  } x$| D]} | r.Pn  x	| D]} | rEPn  xî | D]æ } | r\Pn  xÓ t d t |  j ƒ ƒ D]¹ } | r…Pn  | | | | g d d d d g k ru|  j ƒ  j | d
 | | | | | ƒ }  |  d k r| d
 } | j d | | | | g ƒ n |  d k  r!| j |  ƒ n  | r.Pq.ququWqLWq5WqW| | g S(   NiÿÿÿÿRa   R   t   commandt   {s   } and /1/*/*.*/*;*i    i   s   Error parsing selection: i   R    R   (   RW   R    t   stripR(   R   t   parse_selectionR)   t   GetCellInfot   NewSelectiont   SelectAtomst   mmdbt   ANY_RESt   SKEY_NEWt   CentreOfCoordinatesAsCartesianRZ   t   matht   ceilt   abst   get_xt   get_yt   get_zR,   R"   R*   t   IfSymmetryNeighboursR#   (!   R   t	   selectiont   radiust	   xtl_limitRW   t   neighb_selHndR2   t   at   bt   ct   alphat   betat   gammet	   allSelHndt   centret   xshiftst   yshiftst   zshiftst   xofft   yofft   zofft   xtl_range_xt   xtl_range_yt   xtl_range_zR   t	   interruptt   n_newt   n_errort   it   jt   kt   nsymt	   ncontacts(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   findSymmetryNeighbours  s^    #
$=       $
 c         C   sç  d d  l  } |  j d k  r7 |  j ƒ  j ƒ  d |  _ n  t |  j ƒ j ƒ  |  j ƒ  j ƒ  } | j d d | ƒ } |  j ƒ  j	 t
 ƒ d } | rt | ƒ d k rVt |  j ƒ d k rVxœ t t t | ƒ t |  j ƒ ƒ ƒ D]s } | | |  j | k rÜ |  j j | ƒ } | | }	 |  j | |  j | |	 ƒ |  j j | |	 ƒ | d } qÜ qÜ Wn  t | ƒ t |  j ƒ k  rxL t t | ƒ t |  j ƒ ƒ D], } |  j ƒ  j d t | |  j ƒ ƒ }
 q�Wx@ t t | ƒ t |  j ƒ ƒ D] } |  j j ƒ  | d } qßWqn  | s(t | ƒ t |  j ƒ k rud } | rFt |  j ƒ } n  x, | | D] } |  j | ƒ | d } qQWn  | r±|  j ƒ  j ƒ  |  j ƒ  j ƒ  t |  j ƒ j ƒ  n  |  j ƒ  j | t ƒ | rãt |  j ƒ j ƒ  n  | S(   Niÿÿÿÿi    i   i   t   /(   t
   pygl_coordR   R)   t   GetNumberOfModelsR(   R   t   resetSelHandlest   GetTransformt   matrixt   UnSetTransformt   TrueR"   R   R,   t   mint   popt   resetTransformR!   t   DeleteModelRB   t   makeSymmetryMatet   FinishStructEditt   MakeAllSelIndexesRO   t   SetTransformt   Falset   redraw_all_objects(   R   R   RG   R“   t   tt   oldMt   nBuiltR   t   undo_transformt	   transformt   rct   firstR&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRN   P  sL    '+
%*%" c         C   s~   g  } xq | D]i } |  j  j | ƒ ri |  j  j | ƒ t |  j ƒ k  ri | j |  j |  j  j | ƒ ƒ q | j d ƒ q W| S(   Ni   (   R   R    R[   R"   R   R#   (   R   R   t
   visibilityR&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRM   �  s    3#c         C   s„   g  } xw | D]o } |  j  j | ƒ ri |  j  j | ƒ t |  j ƒ k  ri | j |  j |  j  j | ƒ ƒ q | j |  j ƒ  ƒ q W| S(   N(   R   R    R[   R"   R   R#   t
   nextColour(   R   R   R^   R&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRL   ›  s    3#c         C   s1   t  ƒ  j |  j d d d d d g ƒ|  _ |  j S(   NR	   R
   R   R   R   (   R   R   R   (   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR¬   §  s    *c         C   s  | r‡ | d d k rH |  j  ƒ  j | | d | d | d | d ƒ q‡ | d } | d } | j | ƒ } |  j  ƒ  j | | t ƒ n  | r| d d k rÏ |  j  ƒ  j | | d | d | d | d ƒ q| d } | d } | j | ƒ } |  j  ƒ  j | | t ƒ n  d  S(   Ni    R   i   i   i   i   (   R)   t   ApplySymmetrytoModelt
   getTMatrixt   ApplyTransformtoModelR™   (   R   t   imodelt   old_matet   new_mateRQ   t   itrant   vmat(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRœ   ¯  s     #

#

c         C   s“   | d d k rN | d } | d } | j  | ƒ } |  j ƒ  j d | ƒ } n1 |  j ƒ  j d | d | d | d | d ƒ } |  j j | ƒ | S(   Ni    R   i   i   i   i   (   R®   R)   t   GenerateTransformedModelt   GenerateSymmetryModelR   R#   (   R   R;   RQ   R³   R´   t   nm(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRž   Ç  s    

1c         C   sH   g  } x; t  t |  j ƒ ƒ D]$ } | j d t | |  j ƒ ƒ q W| S(   NR’   (   R,   R"   R   R#   RB   R   (   R   t   modelsR_   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRC   Ú  s    "c         C   s   |  j  S(   N(   R   (   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   get_symmetry_coloursä  s    c         C   s   |  j  | ƒ d  S(   N(   RS   (   R   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   update_data_statusé  s    c         C   s�   d d  l  } g  } xX t | j ƒ  ƒ D]D } | j | ƒ rS | j d | | g ƒ q% | j d | | g ƒ q% W|  j | d d ƒ} |  j ƒ  | S(   NiÿÿÿÿR   RG   i   (   t   mmdb2R,   t   getNofTransformst
   isIdentityR#   RN   t   showSymmetryMates(   R   RQ   Ri   R$   R³   R¦   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   buildBiomoleculeñ  s    
i   c         C   sß   | d k r d d g S| rF |  j  | ƒ } | sF d d | d g Sn  |  j j | ƒ ru d |  j j | ƒ |  j g S| s‰ d d | g S|  j | g d d ƒ|  j j | ƒ rÎ d |  j j | ƒ |  j g Sd d | g Sd  S(	   NRT   i    i   s   Symmetry id s    not interpretables   No symmetry mate for RG   s"   Failed to build symmetry mate for (   t   interpretSymidR   R    R[   R   RN   (   R   t   symidR;   t   build(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   symmetryMateModelNo  s     
 c   	      C   s	  d d  l  } d d  l } | j | d ƒ } t | ƒ d k sR t | d ƒ d k rV d S| j | d d ƒ } | d k  sŠ | |  j ƒ  k rŽ d Sg  } xO t d ƒ D]A } | j | d | d ƒ } | d k  rÑ d S| j | d ƒ q¡ Wd	 | d | d | d | d g S(
   NiÿÿÿÿRU   i   i   i   R   i    i   R   (   RW   t   utilsRY   R"   t   safeIntR4   R,   R#   (	   R   RÁ   RW   RÄ   t   ssR;   t   vR_   t   jj(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRÀ     s    (   c         C   s"  d } d d  l  } d d  l } t | | j ƒ rj | j ƒ  } t | ƒ ra | j | d d ƒ } qj d } n  | d k r d } nŸ | |  j } | d k r| t |  j ƒ k  r|  j | } | d d k rt	 | d d ƒ d t	 d | d	 ƒ t	 d | d
 ƒ t	 d | d ƒ } qn  | S(   NR   iÿÿÿÿi    i   t   1_000R   RU   i   i   i   i   (
   RV   RÄ   RI   RX   RY   R"   RÅ   R   R   RB   (   R   t   modelRÁ   RV   RÄ   t   splitmodR_   t   op(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt
   modelSymid,  s    		!Tc         C   sD  d } d d  l  } d d  l } t | | j ƒ rj | j ƒ  } t | ƒ ra | j | d d ƒ } qj d } n  | d k r d } nÁ | |  j } | d k r@| t |  j ƒ k  r@|  j | } | d d k r@| d d k r@| d t |  j	 ƒ k  r@|  j	 | d d t
 | d ƒ d	 t
 | d
 ƒ d	 t
 | d ƒ } q@n  | S(   NR   iÿÿÿÿi    i   s   x,y,z, 0,0,0R   t    i   t   ,i   i   (   RV   RÄ   RI   RX   RY   R"   RÅ   R   R   R*   RB   (   R   RÊ   R;   RV   RÄ   RË   R_   RÌ   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt
   modelSymopA  s    		!9Mc   
      C   sB  t  |  d ƒ s d St | ƒ \ } } | r/ d Sxt t |  j ƒ ƒ D]õ } t | |  j | ƒ } d } xm t d ƒ D]_ } | t | | d t | | d ƒ ƒ } x, t d ƒ D] } | t | | | ƒ } q± Wqt W| d k  rE t | d ƒ d }	 x< t d ƒ D]. } |	 t t	 t | | d ƒ ƒ d ƒ }	 qW|	 SqE Wd S(	   Nt   symops_reprR   g        i   gü©ñÒMbP?i   RU   i   (
   t   hasattrt
   parseSymOpR,   R"   RÑ   t   symopDifRo   t   roundRB   RZ   (
   R   R;   R2   t   rept   nnt   dift   ssumR_   RÈ   t   sid(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   symop2SymidW  s$      * ,c         C   sB   | |  j  } | d k r> | t |  j ƒ k  r> | |  j | <n  d  S(   Ni    (   R   R"   R   (   R   RÊ   R@   R_   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   setVisibilitym  s    !c         C   sB   | |  j  } | d k r> | t |  j ƒ k  r> | |  j | <n  d  S(   Ni    (   R   R"   R   (   R   RÊ   RA   R_   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt	   setColouru  s    !c         C   sX   g  } x9 |  j  D]. } t |  j | ƒ } | r | j | ƒ q q W| |  _  t |  j  ƒ S(   N(   R   t   dispR   R#   R"   (   R   t   current_MolDisp_objectst   obj_namet   obj(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   check_MolDisp_objects}  s     	c         C   s7   |  j  ƒ  } | s |  j ƒ  n  |  j ƒ  |  j ƒ  d  S(   N(   Râ   t   create_MolDispt   select_MolDispt   colour_MolDisp(   R   t   ndisp(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR¾   ‰  s
     
c      	   C   s�   d d  l  } t |  j ƒ } | j d | d |  j d ƒ } | j d d ƒ t ƒ  j d |  j d | j d | j d	 d ƒ |  j	 j
 | j ƒ d  S(
   Niÿÿÿÿt   parentt   namet	   _symmetryR«   i   t   parent_namet   object_typet   resize(   RÊ   R(   R   t   MolDispt   set_visibilityt   DISPLAYTABLEt
   addDispObjRë   Rè   R   R#   (   R   RÊ   t   molobjt   dispobj(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRã   ’  s    .c         C   s6   x/ |  j  D]$ } t ƒ  j d | ƒ } g  |  _  q
 Wd  S(   NRè   (   R   Rï   t   deleteDispObj(   R   Rà   Rá   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   delete_MolDisp�  s    c   	      C   s[  |  j  s |  j r d  S|  j d } g  } d } d } xS |  j D]H } | d } | rA | j d t | ƒ ƒ | d t | ƒ d } qA qA W| r| d d !} t j j |  j ƒ rÔ t j	 t j j
 |  j ƒ } n d } | rd | d	 | d
 } d } qn  xR |  j  D]G } t |  j | ƒ } | j j i | d 6| d 6| d 6ƒ | j ƒ  qWd  S(   Ni   R   t
   nmr_modelsR’   s    or i    iüÿÿÿs   { s    } and {s    }t   cidt   select(   R   R   R   R#   RB   R   R   R    R   t   MolDisp_selection_commandR[   RÞ   R   t	   SelHandlet   setSelParamst   set_reapply_selection(	   R   R_   Rõ   Rö   R÷   t   ivist   seleRà   Rò   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRä   ¤  s2     
c         C   s¬   d d g g } |  j  d } xB |  j D]7 } | d } | j | d  d t | ƒ d g g ƒ q& WxD |  j D]9 } t |  j | ƒ } | j j	 d i d d 6| d	 6ƒ qk Wd  S(
   Nt   greyR   i   R’   s
   /*/*,*/*:*t	   colparamst   rulest   colour_modet   colour_rules(
   R   R   R#   RH   RB   R   RÞ   R   t   model_colourt
   set_colour(   R   R   RÊ   t   colRà   Rò   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRå   Â  s    
+iÿÿÿÿc         C   s¤   d } | r- |  j  | k r- | |  _  d } n  | d k r„ | |  j k r„ | |  _ |  j rq |  j ƒ  |  j ƒ  n
 |  j ƒ  d } n  | r  |  j r  |  j ƒ  n  | S(   Ni    i   (   R   R   Rã   Rå   Rô   Rä   (   R   R@   Rt   t   redraw(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt
   setMolDispÑ  s    				

	 (,   t   __name__t
   __module__t
   initialiseR   Rø   R   R'   R)   R0   R3   R4   R5   R:   RE   RF   RS   R\   R]   R`   R‘   RN   RM   RL   R¬   Rœ   Rž   RC   R¹   Rº   R¿   RÃ   RÀ   RÍ   RÐ   RÛ   RÜ   RÝ   Râ   R¾   Rã   Rô   Rä   Rå   R  (    (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR      s^   
		%						$	??			
																t   BiomoleculeTransformc        	   B   sŒ   e  Z d  d d d d  d d d d  g	 Z d d d g Z d Z i  d „ Z d „  Z i  d „ Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   g      ð?g        gü©ñÒMbP?c         K   s   | j  | ƒ |  j | ƒ d  S(   N(   t   updateR:   (   R   R8   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR   ï  s    c         C   s,   i |  j  d 6|  j d 6|  j d 6|  j d 6S(   Nt   idt   chainst   rotationt   translation(   R  R  R  R  (   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR5   ó  s
    


c         C   sk   | j  d d ƒ |  _ | j  d g  ƒ |  _ |  j j ƒ  | j  d t j ƒ |  _ | j  d t j ƒ |  _ d  S(   NR  R   R  R  R  (	   t   getR  R  t   sortR  t   IDENTITY_ROTR  t   IDENTITY_TRANR  (   R   R8   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR:   ú  s
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R  R  R  (   R   R  R  R  (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   setTransform  s    		c         C   s}   x? t  d ƒ D]1 } t |  j | t j | ƒ t j k r d Sq Wx4 t  d ƒ D]& } t |  j | ƒ t j k rO d SqO Wd S(   Ni	   i    i   i   (   R,   Ro   R  R  R  t   IDENTITY_TOLERANCER  (   R   R_   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR½     s    'c         C   s  d d  l  } d d  l } | j d ƒ } |  j d | d <|  j d | d <|  j d | d <d | d <|  j d | d <|  j d | d	 <|  j d	 | d
 <d | d <|  j d
 | d <|  j d | d <|  j d | d <d | d <|  j d | d <|  j d | d <|  j d | d <d | d <| S(   Niÿÿÿÿi   i    i   i   g        i   i   i   i   i   i   i	   i
   i   i   i   i   g      ð?i   (   R»   R“   t   doubleaR  R  (   R   Ri   R“   RÇ   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR®     s(    



	c   	      C   s×   t  | ƒ d k r$ d Gt  | ƒ GHn¯ d d  l } d d  l } g  } g  } xq | D]i } | j | ƒ } x4 t d d ƒ D]# } | j | j | | d ƒ ƒ qt W| j | j | d d ƒ ƒ qO W|  j | d | | ƒ d  S(   Ni   s3   ERROR in BiomoleculeTransforms.addBIOMT input linesiÿÿÿÿi   i   g        i    (   R"   RW   RÄ   RY   R,   R#   t	   safeFloatR  (	   R   t   linesRW   RÄ   t   rotmatt	   translatet   linet   fieldsR_   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   setBIOMT0  s     !!c         C   s2   d G|  j  GHd G|  j Gd G|  j Gd G|  j GHd  S(   Ns   CHAINS: R  s
   rotation: R  (   R  R  R  R  (   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt	   printInfo>  s    (   R  R	  R  R  R  R   R5   R:   R  R½   R®   R  R  (    (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR  ç  s   !					!	RJ   c           B   s€   e  Z i  d  „ Z d „  Z d „  Z d g  g  d „ Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z RS(   c         K   s   | j  | ƒ |  j | ƒ d  S(   N(   R  R:   (   R   R8   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR   L  s    c         C   s�   | j  d d ƒ |  _ | j  d d ƒ |  _ g  |  _ xU | j  d g  ƒ D]A } t | t ƒ rn |  j j | ƒ qF |  j j t d | ƒ ƒ qF Wd  S(   Nt   labelR   t   commentst   transform_listR8   (   R  R   R!  R"  RI   R  R#   (   R   R8   R&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR:   P  s    	c         C   sL   g  } x$ |  j  D] } | j | j ƒ  ƒ q Wi |  j d 6|  j d 6| d 6S(   NR   R!  R"  (   R"  R#   R5   R   R!  (   R   R"  R&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR5   Z  s    

R   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   R"  R!  (   R   t   biomoleculeR"  R!  (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   setDatac  s    		c         C   s:   d G|  j  GHd G|  j GHx |  j D] } | j ƒ  q" Wd  S(   Nt   BIOMOLECULER!  (   R   R!  R"  R  (   R   R&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR  h  s    c         C   s   t  |  j ƒ S(   N(   R"   R"  (   R   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR¼   n  s    c         C   s:   | d k  s! | t  |  j ƒ k r% d S|  j | j ƒ  Sd  S(   Ni    iÿÿÿÿ(   R"   R"  R½   (   R   t   nt(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR½   q  s    !c         C   s7   | d k  s! | t  |  j ƒ k r% d  S|  j | j Sd  S(   Ni    (   R"   R"  RH   R  (   R   R&  (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   getRotationw  s    !c         C   s7   | d k  s! | t  |  j ƒ k r% d  S|  j t j Sd  S(   Ni    (   R"   R"  RH   t   mtR  (   R   R&  (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   getTranslation}  s    !c         C   s4   | d k r, | |  j  k  r, |  j  | j ƒ  Sd Sd  S(   Ni    R   (   R"  R  (   R   R&  (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt	   getChainsƒ  s    c         C   s:   | d k  s! | t  |  j ƒ k r% d  S|  j | j ƒ  Sd  S(   Ni    (   R"   R"  RH   R®   (   R   R&  (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR®   ‰  s    !c         C   s”   d d  l  } |  j ƒ  d k r" d Sg  } x' | D] } | j | j | d ƒ ƒ q/ Wt |  j d ƒ ƒ d k sˆ |  j d ƒ | j ƒ  k rŒ d Sd Sd  S(   Niÿÿÿÿi   i    R’   (   RW   R¼   R#   Rd   R"   R*  R  (   R   t   chainsInModelRW   t   chn_listR&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   noTransformNeeded�  s      6(   R  R	  R   R:   R5   R$  R  R¼   R½   R'  R)  R*  R®   R-  (    (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRJ   G  s   	
									c         C   s%  y& t  |  ƒ } | j ƒ  } | j ƒ  Wn d d g SXd d  l } d d  l } | j | d ƒ } t | ƒ } g  } d } g  }	 g  }
 d } d } xJ| | d k  rÝ| d } | | } | d d !d k rÊ| d } | j | d ƒ d k rb|
 r*t ƒ  } | j	 | |
 |	 ƒ } | s*| j
 | ƒ q*n  | j | j | | j | d ƒ d	 ƒ d ƒ } g  }	 qÚ| j | d
 ƒ d k rg  } x{ | j | | d
 ƒ d k rý| j | | | j | d
 ƒ d d ƒ } x$ | D] } | j
 | j | ƒ ƒ qÐW| d } qƒW| d } qÚ| j | d ƒ d k r�g  } x= t d ƒ D]/ } | j
 | | | | j | d ƒ d ƒ q6W|
 j
 t d | ƒ ƒ |
 d j | ƒ | d } qÚ| rÚ|
 rÚ|	 j
 | j | d ƒ ƒ qÚq” | d k r” Pq” q” W|
 rt ƒ  } | j	 | |
 |	 ƒ } | s| j
 | ƒ qn  d | g S(   Ni   s   Error reading fileiÿÿÿÿs   
i    i
   s
   REMARK 350s   BIOMOLECULE:i   s   CHAINS:i   RÏ   t   BIOMT1i   t   BIOMTi   R  i   (   t   opent   readt   closeRW   RÄ   RY   R"   t   findRJ   R$  R#   RÅ   Rd   R,   R  R  (   t   filenamet   ft   textRW   RÄ   R  t   nLinest   biomol_def_listR#  R!  R"  R_   t   foundrem350R  Rá   R2   R  t   chnsR&   t   ttRÈ   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyR1   �  sj    


	 /	* -  	 c         C   sh  d d  l  } d d  l } y& t |  ƒ } | j ƒ  } | j ƒ  Wn d d g SX| j | d ƒ } t | ƒ } g  } d } d }	 xº |	 | d k  r;|	 d }	 | |	 }
 |
 d d !GH|
 d d !d k r.| d } |	 Gd G|
 GH| j d	 |
 d
 ƒ } | r8| j ƒ  } | j	 | d | j
 | d ƒ g ƒ q8q‚ | r‚ Pq‚ q‚ Wg  } x | D] } | j	 | d ƒ qIW| S(   Niÿÿÿÿi   s   Error reading files   
i    i
   s
   REMARK 290R  s   ([ ]*)(\d+)([ ]*)(.*)i   i   (   RW   t   reR0  R1  R2  RY   R"   t   matcht   groupsR#   Rd   (   R4  RW   R<  R5  R6  R  R7  t   hitst   foundrem290R_   R  t   mt   gpst   symopsR&   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   readPDBRemark290ä  s:    


* R   c   
      C   sö  d d  l  } |  j d ƒ } t | ƒ d k r7 d d g Sg  } x¬| D]¤} | j ƒ  j ƒ  } | j d | ƒ } | d d k rˆ | d =n, d	 d
 g j | d ƒ s´ | j d d	 ƒ n  d d d d g } d } x| d t | ƒ k  rÚd d d g j | | d ƒ rFd
 d d	 g j | | ƒ d | d d d g j | | d ƒ <n‡ | | d j d ƒ }	 t |	 ƒ d k r†t |	 d ƒ | d <n" t	 |	 d ƒ t	 |	 d ƒ | d <| | d
 k rÍ| d d | d <n  | d } qÏ W| j
 | ƒ qD Wd | g S(   NiÿÿÿÿRÏ   i   i   s.   Symop should have three comma-separated fieldss   ([+,-])i    R   t   +t   -R   t   yt   zR’   g      ð¿i   (   R<  RY   R"   t   lowerRd   R    R!   R[   RZ   t   floatR#   (
   R;   R<  t   chr_xyzt   rep_xyzt   ch0t   chRy   RÖ   R_   R×   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRÓ     s4     

 A" c         C   sl   g  } x_ t  d ƒ D]Q } g  } x5 t  d ƒ D]' } | j |  | | | | | ƒ q, W| j | ƒ q W| S(   Ni   i   (   R,   R#   (   t   sym1t   sym2RØ   R_   t   ddRÈ   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyRÔ   (  s    %(   t   __doc__t   global_definitionsR»   Ri   Rm   R   R  RJ   R1   RD  RÓ   RÔ   (    (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_symmetry.pyt   <module>   s   
ÿ ÿ Ñ`V	G	""