ó
ÉÝ{Tc           @   sT   d  Z  d d l Z d d l m Z d d l Z d d l Z d e f d „  ƒ  YZ d S(   sK  
     python/ui/intersel.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC

     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ÿÿÿÿN(   t
   Dependencyt	   CInterSelc        
   B   s1  e  Z d  d d g Z d d d g Z d Z d Z d d d „ Z d	 „  Z d
 „  Z	 d „  Z
 d d d d d d d d „ Z d d d „ Z d d d d d d „ Z d d „ Z d „  Z d d „ Z d d d d d „ Z d d d d d d d d d d „	 Z d d d d d d d d d „ Z d d d d d „ Z RS(   s   OR: add to current selections*   EXCLude: exclude from selection (=and not)s%   AND - atom must be in both selectionst   ort   exclt   andi   t   ALLc         C   s‡   | |  _  | |  _ d  |  _ d  |  _ d |  _ g  |  _ d |  _ d |  _ d |  _	 d |  _
 g  |  _ d |  _ t j |  ƒ |  j ƒ  d  S(   Nt    R   i    t   advancedR   (   t   moldispt
   CSelectiont   Nonet   skeletont   saved_style_modet   gui_user_selt   user_sel_ranget   operatort   not_operatort   object_typet   interface_modet   gui_user_sel_stackt   nameR    t   __init__t   set_skeleton(   t   selfR   R	   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyR   *   s    												c         C   só   |  j  r% |  j d d ƒ d  |  _  n  t ƒ  j d d d d d d ƒ t j j j d |  j j	 ƒ |  j
 r£ |  j j d	 k r£ y |  j j d
 |  j
 ƒ Wq£ q£ Xn  y5 d  |  j _ t |  j d ƒ r× d |  j j d <n  Wn n Xt j |  ƒ d  S(   Nt   modeiÿÿÿÿt   vertext   featuret   user_selt   deletei   t   mol_userselectt   FATBONDSt
   style_modet   selection_paramst   offt   interactive_sele_gui(   R   t   handle_skeletonR
   t   ATOMPICKINGt   popup_requestt   GUIt   instst   DeleteGUIWindowR   R   R   R	   t   stylet	   set_styleR   t   hasattrR    R    R   (   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyR   >   s$    	c         C   s   d |  j  j ƒ  d S(   Ns   model.s
   .CInterSel(   R	   t   name_string(   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyR,   V   s    c   
      K   s‘  t  ƒ  j d ƒ \ } } } | |  j j k r: d d d g Sd d d g } d d d g } |  j r� | j d	 d
 |  j d ƒ | j d	 d ƒ n  d g j |  j ƒ r­ d } n d } d |  j ƒ  d g d d d d g d d g g d d d d g d | g d d g g d d d d d d d  d! d" d# d$ g d d% d& d! d" d# d$ g g d d g d d' g g d d( d d | | g d d g d d) g g d d* d d d d! d# g d d! d# g g d d g d d+ g g d d, d d g d d- g g d d. d d/ g d d d0 d1 d2 g d3 d4 d5 g g d |  j	 g g g } d6 d7 g d8 d g d9 d g d9 d* g d9 d( g g }	 |  j
 rq|	 j d: d, g ƒ n  |	 j d9 d. g ƒ d | |	 g S(;   Nt   atomR   s   Start residue ranges   Start atom ranges   Start chain ranget   start_residuet
   start_atomt   start_chaini    s   End range from i   t   endR   t   1t   0t   RETURNs   .handle_user_sel_popupt   PARAMt   selected_atomt   TYPEt   textt   INITIALs   %atomid%t   excludet   _logicalt   LABELs   Exclude next selectiont   add_user_selt   TYPEDEFt   menus
   side chains
   main chaint   residuet   SSEt   chaint   allt   sidet   mains   Select this..t   add_user_ranges   Atom/res/chain range..t   add_user_neighbs   Neighbhood of this..t   undos	   Undo lastt   skeleton_selections   Skeleton atomss   no skeletons	   all atomss   trace and monomerst   OFFR   t   CALIGANDt   labt   Selectt   cbt   prt   com(   R$   t   get_last_pickedR	   t   parentR   t   insertt   countR   R,   RI   R   t   append(
   R   t   keywordst   molobjt   dispobjt   atomptrt
   range_menut   range_aliasR:   t   paramst   display(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyt   user_sel_popup\   sf    	 															 R   c      	   K   s¼  | r_ | d k r d |  _  n	 d |  _  t j j j d |  j j d d d |  j  g g g ƒ n  | s d d	 l m }	 t ƒ  j	 d
 ƒ \ }
 } } |	 d ƒ } d d d d d d d d d g	 } x% t
 d d ƒ D] } | | | | <qÍ W|
 j j | | ƒ } ~ n  | rœ| d k r\|  j  d k r*d } n |  j  d k rBd } n  |  j d | d d ƒ d S| d
 k rq| } nd d g j | ƒ rÃd d  l } d d  l } |  j j j d d
 d d d | ƒ } | d k rÛ| d } n
 | d } |  j j j d | ƒ } | d s‹| j ƒ  } t j ƒ  } t j |  j j j | d | ƒ } | j ƒ  } xF t
 d | ƒ D]5 } | j | | ƒ } | | j | j ƒ  ƒ d } q]W| d d !} |  j j j j | d ƒ q‹nÈ | d k rgt ƒ  j	 d
 ƒ \ }
 } } |	 d ƒ } x! t
 d d ƒ D] } d | | <qWd d  l } | j |
 j j | | ƒ ƒ } | r`| j  | ƒ d } q‹d  Sn$ |  j j j d d
 d | d | ƒ } |  j | ƒ d S| r| d
 k r·| } n$ |  j j j d d
 d | d | ƒ } |  j j! d i | d  6d! d |  j j d" |  j" ƒ  d# ƒ n | r	| d d$ !d% k r‹d d  l } | j  | d& ƒ \ } } |  j j j d d
 d | d | ƒ } | | g |  _# q¸| d' k r¸|  j# r¸|  j j j d d
 d |  j# d d | ƒ } |  j d( |  j# d d) | d) |  j# d ƒ d |  _# q¸n¯ | r"|  j d d* ƒ n– | r¸| d+ k r\|  j$ rµd |  _$ |  j% d d ƒ qµq¸|  j$ sŠd |  _$ | t& _' |  j% d d ƒ q¸| |  j' k r¸| t& _' |  j% d d ƒ q¸n  d  S(,   NR2   R   R   R   R5   R   t   UPDATEiÿÿÿÿ(   t   intaR-   i	   i    i   RC   R   t   selR   t   resetRD   RE   t   inpt   outR@   t   atomIDs    and not mains	    and maint   commandt   ,RA   i   t	   selparamst
   neighb_selt
   gui_offsett   return_methods   .handlei   t   startt   _R1   s   range t    RH   RJ   ((   R   R&   R'   t   UpdateGUIWindowR   R   t	   atom_utilR`   R$   RQ   t   ranget   molHndt   AtomLabel_maskt
   append_selRT   t   mmdb2t   stringR	   RR   t   convertAtomIDt   parse_selectiont
   newPPCAtomt
   pygl_coordt   intpt   mmutt   GetAtomSelIndext   valuet	   getPCAtomt   stript   GetAtomNamet   DeleteSelectiont   ListSecStructuret   splitt   define_neighbR,   R   t
   ifskeletonR#   R   RI   (   R   R=   R6   RG   RF   R:   RH   RI   RV   R`   RW   RX   RY   t   maskt   py_maskt   iRa   t   mmdbRv   t   cmdt   rvt   selAtomst	   selindexpt   natomst   nt   pcatt   subRl   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyt   handle_user_sel_popupš   sº    	! 			

"!  	$)						c         K   s¦   | d k s- | d k r1 d d g j  | ƒ r1 d  S|  j j d | d | ƒ } | d sa | d re d  S| \ } } } } |  j j j | ƒ \ }	 }
 |  j d	 |
 ƒ d  S(
   Nt   dismisst   rangest   addR   t   kwt   widgeti    i   Ra   (   RT   R   t   interpret_selectionR	   RR   t   list_to_commandRt   (   R   R˜   t   exitRV   t   retvalt   statust   separamsRa   t   aliasRŒ   Rf   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyt   handle_selection  s    !  RU   c         C   sË  d d  l  } d d  l } d d  l } |  j j |  j ƒ | d k r‡| sM d  S| re | j | ƒ } n  | d k rz | }	 n	 |  j }	 |	 r© | j d | ƒ r© d | } n  | j	 d d | ƒ } | j	 d d	 | ƒ } | j	 d
 d | ƒ } |  j st
 | ƒ |  _ qÌ| r_| j |  j ƒ | j	 d d |  j ƒ |  _ |  j d t
 | ƒ d t
 | ƒ |  _ qÌ|  j d |  j d t
 | ƒ |  _ nE| d k rÖt |  j ƒ d k  r¯d g S|  j j ƒ  |  _ |  j j ƒ  |  _ nö d g j | ƒ rý| j | ƒ |  _ nÏ d g j | ƒ rÌ| j	 d d | ƒ |  _ | j	 d d |  j ƒ |  _ | j	 d d	 |  j ƒ |  _ | j	 d
 d |  j ƒ |  _ | j	 d d |  j ƒ |  _ | j	 d d |  j ƒ |  _ | j	 d d |  j ƒ |  _ n  | d k rƒ| j	 d d |  j ƒ }
 | j	 d d |
 ƒ }
 | j	 d	 d |
 ƒ }
 | j	 d d
 |
 ƒ }
 |
 ssd |  _ |  j j d d d d d d ƒ |  j j d d ƒ qƒ|  j j j d  |
 d! d ƒ } | d" d" k rÍ|  j j ƒ  |  _ t j j j d# ƒ d g S| rë| j | d$ d ƒ} n | j |
 d$ d ƒ} t | ƒ d% k r"| d" d% !} n  |  j j d d d |
 d d ƒ t | ƒ d k rm|  j j | d | ƒ qƒ|  j j d | ƒ n  t j j j d& |  j j d' d d( d) | j |  j ƒ g g g g ƒ d  S(*   NiÿÿÿÿRU   R   s   ^nots   not t   &s   &amp;t   <s   &lt;t   >s   &gt;s   <br>$s    <br> Rn   RH   i   i   t   updateRb   s   <br>s    or s	    <br> or s    and s
    <br> and s    excl s    <br> excl s   &ampt   selectt   cidR   s   No selectionRf   t   testi    s#   Can not interpret selection commandt   tcl_safei   R   t   OBJECTt	   CONFIGURER8   (   Rv   t   ret   utilsR   RU   R   R€   R   t   matchR’   t   strR   t   lent   popRT   R	   t   set_selectiont   update_selectionRR   Rx   R&   R'   t   WarningMessaget   oneWordRo   R   R   t   tclSafe(   R   Ra   R   R   R   t
   user_aliasRv   R«   R¬   t   notopt   sel0RŒ   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyRt     s‚      			+( 	 i    c      
   C   sQ  | d k rÑ i  } d | d <i  } d | d <|  j  d k r� d | d <|  j j j r� g  | d <x+ |  j j j D] } | d j | ƒ qn Wq� n  d	 d  l } | j |  j j j d
 | d | d |  d d ƒ|  _ n| | d k  r|  j rö |  j j	 ƒ  n  d  |  _ nK |  j sd  S|  j  d k r:|  j j d d d d ƒ n |  j j d d ƒ d  S(   Ni    t	   THINBONDSR   RC   R¥   RK   t   catracet   monomersiÿÿÿÿRh   t   styleparamst   master_applicationt   display_table_visible(   RI   R	   RR   R»   RU   t   modelt   MolDispR   R   R   R
   R±   (   R   R   R)   Ra   t   monR¿   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyR#   …  s0    



	 	 c         C   s„   |  j  rP |  j r3 |  j j d d ƒ |  j ƒ  d  S|  j d d ƒ |  j ƒ  n0 |  j ro |  j j d d ƒ n  |  j d ƒ d  Sd  S(   Nt
   visibilityR2   R   i   R3   i    (   R†   R   t   set_visibilityt   set_fatbondsR#   (   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyR   £  s    		
	 c         C   s—   |  j  j d k r d  S| rh |  j  j d k s@ |  j  j d k r“ |  j  j |  _ |  j  j d d ƒ q“ n+ |  j r“ |  j  j d |  j ƒ d  |  _ n  d  S(   NRÀ   t   BONDSR¹   R   R   (   R	   R   R   R   R*   R
   (   R   R   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyRÄ   µ  s     	c   
      C   s�  d d  l  } d d  l } | r* | |  _ n  | s6 | rU |  j d | d | d | ƒ n  | j | ƒ | k rs d } n  | r| j d d | ƒ |  _ | j d d	 |  j ƒ |  _ | j d
 d |  j ƒ |  _ | j d d |  j ƒ |  _ | j d d |  j ƒ |  _ | j d d |  j ƒ |  _ n	 d |  _ d d g } | j t ƒ  j	 ƒ  ƒ d d g } | j t ƒ  j	 ƒ  ƒ |  j d k r.d d |  j
 j j g d d g d d g d d d d  d! d d" d# d g g g g d$ d! d% d& d g d g d' g d d( d d" d# d g g g g d) d* g g d$ d  d% d+ d, d- g d d. d d  d d/ d" d# d g g g g d0 d1 g g d$ d/ d% d2 | | g d) d g g d$ d d3 d4 g d) | j | ƒ g g d$ d5 d% d2 |  j |  j g d) |  j g d d d d5 g g g d$ d6 d3 d7 g d) |  j g d d d d6 g g g d$ d8 d3 d7 g d) |  j g d d d d8 d d d" d# d g g g g g d$ d9 d% d2 d: d; g d< d= g g d) |  j g d d d d9 g g g d> d d3 d? g d@ dA | j |  j ƒ g g g dB dC dD dE dF g dG d8 g d0 dH g dE dI g dG d9 g d0 dJ g g dD d0 dK g dE dL g dG d5 g dG d6 g d0 dM g g dD d0 dN dO g dE dP g dG d! g d0 dQ dO g g dR d g dD dE dS g d0 dT g dG d/ g dE dU g d0 dV g dG d g dE dW g dG d  g g	 dX dY d0 dZ g dE d[ g g d\ d0 d] g g d^ d0 d_ g g d` da g g g g g }	 t j j j db |  j j |  |	 ƒ n/ |  j dc k r]t j j j db |  j j ƒ n  t ƒ  j dd de df d dg dh di |  j ƒ  dj ƒ d  S(k   NiÿÿÿÿR   R¶   t   user_old_aliasR   R¢   s   &lt;R£   s   &gt;R¡   s   &amp;s    or s	    <br> or s    and s
    <br> and s    excl s    <br> excl s
   this models
   all modelst   thist   genericR   t   TITLEs   Atom Selection for t   ICONs
    Selectiont   HELPs   selection#interactivet   RETURN_METHODt   set_user_selectiont   RETURN_LISTt   saveR¥   s   user_sel::textt   ALIASR5   R>   t   postmenut   15t   handleR9   s   selection..t	   varbuttonR2   R3   t   handle_savet	   save_modeR<   t   SaveR?   R7   t   _text30R   R   R;   R†   RI   s	   all atomss   trace and monomersR   RK   R©   t
   TextEditorRª   R8   t   DISPLAYt   WINDOWt   LINEt   MESSAGEs<   Show the unselected atoms in the model so they can be pickedt   WIDGETt   Shows   Show CA trace or all atomss+   molecule skeleton for interactive selections   Combine next selection bys,   Use operator to merge next entered selections   NOT the next selections   Select from menus   -italics&   Choose selection command from the menus@   OR right-click on atom for pop-up menu OR edit text window belowt   DRAWs8   Save selection command for this model or for general uses   Save fors5   Enter a one word identifier for the selection commands   as named selection:s   Save selection command nowt   BUTTONSt   okt   Applys   Apply selection nowRH   s	   Undo lastt   clears   Clear selectionR”   t   CLOSER   t   simpleR   R   R   t   moduleR¿   t   methods   .user_sel_popup(   R¬   R«   R   RÍ   R´   R’   R   t   extendt	   MODELINFOt   list_loadedR	   RR   t
   name_labelRµ   t   operator_menut   operator_aliasR   R   R†   RI   R&   R'   t   CreateGUIWindowR   R   R(   R$   R%   R,   (
   R   R   R   R¶   RÆ   R¬   R«   t   save_mode_menut   save_mode_aliast   desc(    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyt   define_userselectÅ  sâ     
																											& c
         K   s
  |	 d k r d  S| d k rÛ d d  l  } | j d |  j j d d d d d	 g ƒ \ } } | j d
 d | g ƒ | j d d | g ƒ | j d d d d g g ƒ d d | g g } | j | ƒ t j j j d |  | ƒ n+| d k r|  j	 j
 d d |  j j d |  j ƒ  d ƒ nï | d k rS|  j	 j d d |  j j d |  j ƒ  d ƒ n³ | d k r�|  j	 j d d |  j j d |  j ƒ  d ƒ nw |  j j d i  d |
 d | ƒ } | d
 sÅ| d rÉd  S| \ } } } } |  j	 j j | ƒ \ } } |  j d | ƒ d  S(   NR”   R¥   iÿÿÿÿt   moldatat   not_requiredt
   not_selectR"   t   remove_usert   save_currenti    t	   WINDOW_IDi   t   PARENTi   RÌ   RÓ   t   RETURN_WIDGETRÚ   t   PULLDOWNt   mol_selectionR2   Rj   R   Rk   s   .handle_selectionRh   R—   R˜   i   Ra   (   R¿   t   define_selection_menuR   RR   RS   Ré   R&   R'   Rï   R	   R…   R   R,   t   define_rangest   define_propertyR™   Rš   Rt   (   R   t	   post_menut   windowRR   t   _neighbt   _rangest	   _propertyt   _cidR˜   R›   RV   R¿   t   guidefR?   R]   Rœ   R�   Rh   Ra   RŸ   RŒ   Rf   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyRÓ   P  s8     ! c	         K   s2  d d  l  }
 d d  l } | r+ | |  _ d  S| rD t | ƒ |  _ d  S| rg | t _ |  j d d ƒ d  S| rŸ t | ƒ |  j k rŸ t | ƒ |  _ |  j	 ƒ  d  S| d k r¼ |  j
 ƒ  ~  d  S| d k râ |  j d d d d ƒ d  S| d	 k r|  j d d	 ƒ d  S| d
 k s| r.|  j d | d d ƒ d  Sd  S(   NiÿÿÿÿR   i    R”   Rä   Ra   R   Rb   RH   Râ   (   R«   R¬   R   t   intR   R   RI   R#   R†   R   R   Rt   (   R   R¶   R   R†   RI   R   R   R›   R˜   RV   R«   R¬   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyRÍ   v  s:    		

RÇ   c   
   	   K   sV  d d  l  } | s9 t j j j d d d |  j j ƒd  S| sf t j j j d d d |  j j ƒd  S| j d d | ƒ } |  j j j	 d | d	 d
 ƒ } | d d k rÐ t j j j d d d |  j j ƒd  S| d
 d k sò t
 | ƒ d k  r| } d }	 n | } | d }	 |	 r?|  j j d d d | d | d |	 ƒ n  |  j j |	 | ƒ d  S(   Niÿÿÿÿs9   Please enter a short name for the selection before savingRR   R   s&   Please enter a selection before savings   <br>Rn   Rf   R§   i   i    s   Selection is not interpretablei   R   i   t	   overwriteR2   RÖ   RŸ   t	   selection(   R«   R&   R'   R³   R   R   R’   R	   RR   Rx   R¯   t   save_current_selectionR²   (
   R   RÏ   RÖ   R¶   R   RV   R«   RŒ   RŸ   Ra   (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyRÕ   ¤  s*    ###"	
N(   t   __name__t
   __module__Rí   Rî   R†   RI   R
   R   R   R,   R^   R“   R    Rt   R#   R   RÄ   Ró   RÓ   RÍ   RÕ   (    (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyR      s:   				>xf	Š	$+(   t   __doc__R&   t   dataobjR    R|   Rz   R   (    (    (    s?   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/intersel.pyt   <module>   s
   