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

     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.
t	   ModelInfoc           B   sˆ  e  Z d  Z g  Z d „  Z d  d „ Z d „  Z d „  Z d  g  d „ Z d  g  d d d d „ Z	 d  d  g  d d	 „ Z
 d  d d
 „ Z d „  Z d  d „ Z d  d „ Z d  i  d „ Z d  d  d  d d „ Z d  d  d  d  d  d d „ Z d  d  d  d d d „ Z d  d  d „ Z d  d  d  d „ Z d  d  d „ Z d  d  d „ Z d „  Z d  d  d „ Z g  d  d „ Z d d d  d  g  d „ Z d  d „ Z RS(   t    c         C   s¡   d d  l  } d d  l } |  t _ i  |  _ i  |  _ d d | j j | j ƒ  d ƒ g } | |  j d <i  |  _	 x- |  j j
 ƒ  D] \ } } |  j | | ƒ q} Wd  S(   Niÿÿÿÿt	   dotCCP4MGs   generic.ccp4mgt   generic(   t   utilst   osR    t   instst   ModInfot	   user_filet   patht   joint
   get_CCP4MGt   generic_selectiont   itemst   restore(   t   selfR   R   t   filenamet   set(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   __init__   s    			$	c         C   sÀ   x* | j  ƒ  D] \ } } t |  | | ƒ q Wd d l } d d l } xt |  j j  ƒ  D]c \ } } t | | j ƒ s¢ d | j j | ƒ d | g } | |  j | <n  |  j	 d | d | ƒ qU Wd S(   sU   
    Restore data - called from DisplayTableShadow on program
    initialisation
    iÿÿÿÿNt   FULLPATHi   R   R   (
   R   t   setattrt   typesR   R   t
   isinstancet   ListTypeR	   t   splitR   (   R   t   paramst   keyt   valueR   R   R   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt	   setparams1   s     c         C   s   i  } |  j  | d <| S(   sª   
    Save status - called from DisplayTableShadow
    Presently saves list of user_defined_files i.e. any
    loaded .ccp4mg which are not associated with a PDB file
    R   (   R   (   R   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt	   getparamsE   s    c         C   s:   x3 |  j  j ƒ  D]" \ } } |  j d | d | ƒ q Wd  S(   NR   R   (   R   R   t   save(   R   R   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   save_user_filesQ   s    c   
      C   s.  d d l  } d d l } d d l } | s> |  j j | ƒ rB d S| sž |  j j | ƒ rj |  j | } qž d d l } | j | ƒ } | r— | j } qž d Sn  | j	 j
 | d ƒ d d } y4 | j d k rà t | d ƒ }	 n t | d	 ƒ }	 Wn d
 SXy% | j |  j | |	 ƒ |	 j ƒ  Wn n Xd S(   s   
    Save ModInfo class to .ccp4mg file
    "set" is the GUI label for the set of data - usually
    the PDB filename root
    iÿÿÿÿNi   i   i    s   .ccp4mgt   win32t   wt   wbi   (   R   t   picklet   sysR   t   has_keyR   t   global_definitionst   dataR   R	   t   splitextt   platformt   opent   dumpt   close(
   R   R   R   R   R#   R$   R&   t   dobjt   pickle_filet   f(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyR   Y   s4     i    i   c         C   s  d d l  } d d l } | r> |  j j | ƒ r> | r> d g S| d k r} d d l } d d | j j | j ƒ  d ƒ g }	 nY | rÏ | j j | d ƒ d d }
 | d |
 | j j | d	 ƒ d d g }	 n d g S| j j	 |	 d	 ƒ s~| r~| s| j
 | d ƒ } n  t ƒ  |  j | <|  j | j d
 | d	 ƒ | rO|	 |  j | <n  | d	 k rt|  j d | d | ƒ n  d	 g Sn  d } y& t |	 d	 d ƒ } | j | ƒ } Wn d	 d |	 d	 g SX| sëd d l } | j
 | d ƒ } n  | |  j | <| r|	 |  j | <n  d g S(   s›   
    Restore ModInfo class from a .ccp4mg file
    For GUI purposes the data has a name "set" which is uusually
    the filename root of the PDB file 
    iÿÿÿÿNi    R   R   s   generic.ccp4mgi   s   .ccp4mgi   t   pdbfileR   R   t   rs   Error reading file (   R   R#   R   R%   R   R	   R
   R   R(   t   existst   fileRoott
   initialiseR   R   t   NoneR*   t   load(   R   R   R   R   t   overridet   createR   R#   R   R.   t   namet   objR/   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyR   Š   sH    .  
 c         K   s³   | d k r d  Sd d  l  } d d  l } | rV | rV | j j | d ƒ d d } n  | sp | j j | ƒ rt d Sy | j | ƒ Wn' | j j j d | d | ƒ d SXd S(	   Nt   deleteiÿÿÿÿi   i    s   .ccp4mgi   s    Error attempting to delete file s7   \nPlease remove it or there will be problems handling\n(   R   t   GUIR	   R(   R2   t   removeR   t   WarningMessage(   R   R.   t   exitR   t   checkt   keywordsR   R<   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyR;   Å   s      ! c         C   sB   |  j  j | ƒ r> |  j  | =|  j j | ƒ r> |  j | =q> n  d S(   s   
    Close the data set
    N(   R   R%   R   (   R   R   R@   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyR,   Ú   s    
 c         C   s8   |  j  j ƒ  } | j d ƒ d k r4 | j d ƒ n  | S(   s5   
    Return a list of the loaded sets of ModInfo
    R   i    (   R   t   keyst   countR=   (   R   t   menu(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   list_loadedä   s     c         C   s¥   d d  l  } t | | j ƒ s* | g } n  xt t t | ƒ ƒ D]` } | | d k sc | | d k r= | j | ƒ x* |  j j ƒ  D] } | j | | ƒ q€ Wq= q= W| S(   Niÿÿÿÿt   *R   (	   R   R   R   t   ranget   lent   popR   RB   t   insert(   R   R   R   t   it   item(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   interpret_setî   s      c         C   s%   |  j  j | ƒ r |  j  | Si  Sd  S(   N(   R   R%   (   R   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   get_set  s    c         C   s   | |  j  | <d  S(   N(   R   (   R   R   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   set_set  s    c   
      C   sá   | s d i  g S|  j  | ƒ } i  } x¯ | D]§ } |  j j | ƒ r, t |  j | | ƒ r, t |  j | | ƒ } | r© | j | ƒ rÐ | | | | <| r¦ d | g SqÐ qÓ x' | j ƒ  D] \ } }	 |	 | | <q¶ Wq, q, Wd | g S(   sG  
    Return a status,dictionary where dictionary is the data of type
    'info' (eg user_selection)
    from the given set(s) - or if set == '' or set=='*' then all sets 
    either return a whole dictionary (key='') or dictionary with the item 'key'
    if first is true then only return first key that satisfies criteria
    i   i    (   RM   R   R%   t   hasattrt   getattrR   (
   R   t   infoR   R   t   firstt   outputt   sR'   t   kt   v(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   get_info  s    	 
( c   	      C   sì   | s | s | r d Sg  } |  j  j | ƒ s[ t  ƒ  |  j  | <|  j  | j d | ƒ n  t |  j  | | ƒ rŠ t |  j  | | ƒ } n i  } | | | <t |  j  | | | ƒ | j | ƒ | rè x! | D] } |  j d | ƒ qË Wn  d S(   Ni   R0   R   i    (   R   R%   R4   RP   RQ   R   t   appendR   (	   R   RR   R   R   R   R0   R   t   changedt   dic(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   add_info2  s      
c   	      C   sn  |  j  | ƒ } t | ƒ d k r< |  j j | d ƒ r< d S| sJ | rN d Sg  } xß | D]× } |  j j | ƒ r[ t |  j | | ƒ r[ | d k rÇ y% t |  j | | ƒ | j | ƒ Wq/q/Xq2y^ t |  j | | ƒ } | j | ƒ r| | =t |  j | | ƒ n  | j | ƒ | r$d SWq2q2Xq[ q[ W| s@d S| rjx! | D] } |  j	 d | ƒ qMWn  d S(   sq   
    Delete the data of type 'info' (eg user_selection) with given key
    optionally from the given set(s) 
    i   i    i   RF   R   (
   RM   RH   R   R%   RP   t   delattrRY   RQ   R   R   (	   R   RR   R   R   RS   R   RZ   RU   R[   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   delete_infoL  s<    )  (  c         C   s  d d l  } t | | d i  ƒ } t | | i  ƒ } g  } | j d ƒ rn x" | d D] } | j | ƒ qT Wn  |  j d | d d d | d ƒ \ } }	 | rÕ |	 rÕ x/ |	 | d j ƒ  D] \ }
 } | | |
 <q¸ Wn  |  j d | d d d | ƒ \ } }	 | rs|	 rsxj |	 | j ƒ  D]U \ }
 } |
 d k rbx: | D]% } | j | ƒ s6| j | ƒ q6q6Wq| | |
 <qWn  g  } g  } | rãxs | D]P } | j | ƒ rÂ| j | | ƒ | j | ƒ qŒ| j | ƒ | j | ƒ qŒWn | j ƒ  } | j ƒ  } | | | g S(	   sº   
    Get definitions for menus to select by amino acid/element/etc
    Precedence of definitions: from the model (from .ccp4mg), from
    generic or from selection_protocols.py file
    iÿÿÿÿNt   _groupst   ORDERR   RR   t   selection_protocolsR   (	   Ra   RQ   R%   RY   RX   R   RC   t   valuesRB   (   R   t   typeR   Ra   t   groupst   namest   orderRL   t   statusR[   R   R   RD   t   alias(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   get_protocol_menuv  sB     !  c      
   C   sU  d d l  } d d l } g  } t | | i  ƒ } | j d ƒ rd x" | d D] } | j | ƒ qJ Wn  |  j d | d g d d d | d	 d
 ƒ \ }	 }
 |
 j | ƒ s° i  |
 | <n  |
 | j d ƒ rþ x8 |
 | d D]% } | j | ƒ sÒ | j | ƒ qÒ qÒ Wn  | j | ƒ s| j | ƒ n  | |
 | d <|  j d | d d d | d |
 | ƒ d S(   s1   
    Get a list of the residue/element types
    iÿÿÿÿNR`   R   R   RR   Ra   R   RS   i   R   (   Ra   R   RQ   R%   RY   RX   RC   R\   (   R   R   R   t   new_nameRa   R   Rf   t   std_seleRL   Rg   t   sel_prot(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   add_name§  s(        c   
   	   C   sP  d d l  } d d l } g  } | d k r4 |  j ƒ  St | | i  ƒ } | j d ƒ rz x" | d D] } | j | ƒ q` Wn  |  j d | d g d d d	 | d
 d ƒ \ } }	 | rL|	 j | ƒ rLt |	 | | j ƒ rxp |	 | D]% } | j	 | ƒ sá | j | ƒ qá qá WqL|	 | j d ƒ rLx& |	 | d D] } | j | ƒ q/WqLn  | S(   s1   
    Get a list of the residue/element types
    iÿÿÿÿNt	   conflictsR`   R   R   RR   Ra   R   RS   i   (
   Ra   R   t   get_monomer_lib_conflictsRQ   R%   RY   RX   R   R   RC   (
   R   R   R   Ra   R   Rf   Rk   RL   Rg   Rl   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt	   get_namesÃ  s(    
   c         C   si   |  j  d | d | ƒ } | s" d S| d } t | ƒ d k rB | Sx  | d D] } | d | } qM W| S(   NR   R   R   i    i   t   ,(   Rp   RH   (   R   R   R   t	   name_listt   textRL   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   get_names_stringà  s     
  c   	      C   sÊ   d d  l  } d d  l } d d  l } t j sÃ | j j | j ƒ  d d ƒ } | j j | j d d d d ƒ } | j | ƒ } g  } x2 | D]* } | j	 | j j
 | ƒ d d d !ƒ q‰ W| t _ n  t j S(	   NiÿÿÿÿR'   t   monomer_libraryt   CCP4_MGDATARF   s   *_EL.cifi    iùÿÿÿ(   R   R   t   globR    t   monomer_library_elementsR	   R
   R   t   environRY   R   (	   R   R   R   Rw   t   monlibt   search_patht   element_filest   ele_listRL   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyRo   ê  s    $	"(c      	   C   s½   g  } | r | d g } n	 d g } |  j  d | d g d d d | d d ƒ \ } } | rn | rn | | } n  | s˜ d d	 l } | j j | d	 ƒ } n  | r¹ |  j d
 | d | ƒ } n  | S(   sc   
    Get the expansion of a selection alias
    Precedence is given to user defined selections
    R   R   RR   t   user_selectionR   RS   i   iÿÿÿÿNt   input(   RX   Ra   R   t   getR5   t   apply_patches(   R   Rh   R   t   expandedt   set_listRg   R~   Ra   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   expand_selection_aliasú  s    	 c   
      C   s½  d d l  } | s | S| d d k r9| d } | j d | ƒ } xê | r.| j ƒ  d } |  j d | d | ƒ } | s™ | j d | d d	 | ƒ } n€ t | ƒ d k rÏ | j d | d | d | ƒ } nJ | d } x  | d D] }	 | d
 |	 } qä W| j d | d | | ƒ } | j d | ƒ } qE Wd | g St | ƒ d k rl| d |  j | d d | ƒg St | ƒ d k rµ| d |  j | d d | ƒ|  j | d d | ƒg S| Sd S(   s�   
    Substitute for selection aliases such as 'amino_acid' - can be
     model specific definition of list of residue types / element types
    iÿÿÿÿNi    i   s	   %([^%]+)%R   R   t   %R   Rq   i   (   t   reR5   t   searchRd   Rp   t   subRH   R�   (
   R   R   R   R†   t   defnt   matchRc   Re   Rˆ   RL   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyR�     s2    
	 $
 
!t   methodc      
   C   s  i d d 6d d 6} | j  | ƒ s' d  S| | } d d  l } d }	 | d k rf d }
 | | d	 } n d
 }
 | | d } d } |  j d | d | ƒ \ } } | r¨ d S| d k rÕ |  j d | d d ƒ \ } } n  d d  l } | j ƒ  } | d k rx| j ƒ  D]õ \ } } | s(| j | ƒ r| j | ƒ } | d sû| | | j d | | d | ƒ| j d | d | d | ƒ} | d k r¯| | j d d | d | ƒ} n  | j  | ƒ rä| | j d | | | d | ƒ} n  | d d !|
 } qûqqWn| d k rx	| j ƒ  D]ø \ } } | s=| j | ƒ rg  } xI | D]A } | j | d ƒ } | d sJ| j	 | d | d g ƒ qJqJW| | | j d | | d | ƒ| j d | | d | d d ƒ} | d k rÿ| | j d d | d | ƒ} n  | d d !|
 } qqWn  | S(   Nt   SelectionSchemeR~   t   ColourSchemet   user_colour_schemesiÿÿÿÿi   R‹   s    )

s    (t   }s    = {R   R   RR   t   user_selparamsi    R9   t   stylet	   selectioni   R   t   contextt	   selparamst   colourst   indenti
   (
   R%   R   RX   t   model_selectiont   SelectionParserR   RC   t   list_to_commandt   picture_defn_itemRY   (   R   t   pretty_printR‘   R   RR   RB   Rh   t   pic_def_classR   R–   t   b_endt   b_startt   streamRg   t	   info_dictt   info_selparamsR—   t   SPR9   R‰   t   comRT   t   coldef(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   save_picture_definitionD  s\    

 
 !
   "&
 " " "c   	      C   sÇ   g  } g  } | r" | j  | ƒ n  | j  d ƒ | j |  j ƒ  ƒ x~ | D]v } |  j d | g d d ƒ \ } } | sI g  } x! | j ƒ  D] } | j  | ƒ q‰ W| r¿ | j  | | g ƒ q¿ qI qI W| S(   NR   R   RR   RŽ   (   RY   t   extendRE   RX   RB   (	   R   t   MolDatat   scheme_listt   setsR   Rg   RŽ   t   col_listt   col(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   getColourSchemeNamesz  s      	 N(   t   __name__t
   __module__R   Rx   R   R   R   R   R   R   R;   R,   RE   RM   RN   RO   RX   R\   R^   Ri   Rm   Rp   Rt   Ro   R„   R�   R5   R¥   R¬   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyR       s6   			1;
	

 *1
	 *5R   c           B   s   e  Z d  „  Z d d „ Z RS(   c         C   s   d  S(   N(    (   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   initœ  s    R   c         C   s:   d d  l  } d d  l } | j |  _ | r6 | |  _ n  d  S(   Niÿÿÿÿ(   t   versionR   t   ccp4mg_versionR0   (   R   R0   R°   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyR4   ¡  s
    (   R­   R®   R¯   R4   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyR   ”  s   	N(   t   __doc__R    R   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/ModelInfo.pyt   <module>   s   ÿ ÿ }