ó
ÉÝ{Tc           @   s^   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l Td e f d „  ƒ  YZ d S(   s™  
     python/ui/picture_wizard.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009 University of York
     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ÿÿÿÿN(   t   Application(   t   *t   picture_wizardc           B   s  e  Z d Z i d  d 6d d 6d d 6d d 6d d 6Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z	 d d d d „ Z
 d d d „ Z d d „ Z g  d d „ Z d d d d d d „ Z d d „ Z d d d „ Z d d d d d d „ Z d i  i  d d d e d „ Z d d „ Z RS(   s$   Ribbons:Blend_colour_N_to_C_terminust   default_drawing_stylei    t   show_wizard_choicest   keep_display_objectst   hide_unselected_dataobjt   recentrec         C   sý   |  t  _ x- t  j j ƒ  D] \ } } t |  | | ƒ q Wg  |  _ t j j t j	 d d ƒ |  _
 xa t j j t j ƒ  d d ƒ g D]> } t j j | ƒ rƒ |  j j | ƒ rƒ |  j j | ƒ qƒ qƒ Wt j |  d ƒ d |  _ i  |  _ i  |  _ g  |  _ d  S(   Nt   CCP4_MGDATAt   picture_wizard_filest   dataR   t    (   R   t   instst
   initialiset   itemst   setattrt   user_master_dirst   ost   patht   joint   environt
   master_dirt   utilst
   get_CCP4MGt   existst   countt   appendR    t   __init__t   selected_snapshott   previous_chosent   previous_chosen_dataobjt   last_picked_atom(   t   selft   keyt   valuet   dir(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyR   2   s    		(%			c         C   s   t  j  j |  ƒ d  S(   N(   R    t   open(   R    (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyR$   H   s    c         C   s,   t  j r d  t  _ n  t j j |  ƒ ~  d  S(   N(   R   R   t   NoneR    t   delete(   R    (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyR&   M   s    	 c         C   s7   i  } x* t  j j ƒ  D] } t |  | ƒ | | <q W| S(   N(   R   R   t   keyst   getattr(   R    t   parst   item(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt	   getparamsT   s    c         C   sz   xs | j  ƒ  D]e \ } } | d k rb |  j d | d d ƒ } t j j | ƒ sb d GHd GHq qb n  t |  | | ƒ q Wd  S(   NR   t   drawing_stylet   modet   mgpics3   Default wizard drawing style could not be restored.s3   Possibly restoring a status file from before 2.8.0.(   R   t   snapshot_fileR   R   R   R   (   R    t   paramsR!   R"   t   filename(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt	   setparams\   s    	R   c         C   sÖ  | r! |  j  d | d d ƒ } n  t j j | ƒ sA d d | g St j | d ƒ } | sg d d | g Sy | j ƒ  } Wn* y | j ƒ  Wn n Xd d | g SXy | j ƒ  Wn n Xd	 d  l } d	 d  l	 } | j
 d
 | ƒ } t | ƒ d k r| d k rd | g Sd d g Sn± x® | d D]¢ }	 | j |	 | ƒ }
 | j |	 d ƒ } |
 d k r&|
 | k  r&d d g j | ƒ r³d | j |	 | d ƒ j d ƒ j d ƒ j d ƒ g Sd |	 | d g Sq&q&Wd d g S(   NR,   R-   R.   i   s   No file t   rs   Error opening file s   Error reading file iÿÿÿÿs	   #SECTION t   SCRIPTi    R   s   
t   TITLEt   NOTESs   """(   R/   R   R   R   R   t   openFilet   readt   closet   ret   stringt   splitt   lent   findR   t   stript   rstript   lstrip(   R    R1   t   sectionR,   t   ft   textR:   R;   t   sec_listt   sec_textt   isect   jsec(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt   read_mgpic_file_sectioni   sB       
6c   	      B   s  |  j  d | d | d d ƒ } d } | d r2 | S| d sd i d d 6d	 d
 6d d 6d d 6g } n„ g  } i  } i  } y | d | | f d  UWn n Xx0 d d g D]" } | j | ƒ r¦ | | } q¦ q¦ W| j d ƒ rè | d } n  | r| rþ d | g Sd | g Sn d d | g Sd  S(   NR1   R,   RB   t   CHOICESi    i   t   MolData1t   namet   MolDatat   typet   Modelt   labelt   allt   choicest   QUERYiÿÿÿÿs   Error reading choices from (   RI   t   has_key(	   R    R1   R,   t   rett   queryRR   t   globst   locsR!   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt   read_mgpic_file_choices–   s4    


  
c         C   s   | |  _  d  S(   N(   R   (   R    RL   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt   set_default_drawing_style¹   s    i   c         C   s%  d d  l  } d d  l } | r' g  } n d g } d g } xÑ|  j g |  j g D]º} x±| D]©} t j j | ƒ r\ g  }	 x¢ | j  t j j | d ƒ ƒ D]‚ }
 t j j |
 ƒ } t j j	 |
 ƒ r™ d d d g j
 | ƒ d k r™ t | j  t j j |
 d ƒ ƒ ƒ d k r™ |	 j | ƒ q™ q™ WxF d	 d
 d g D]5 } |	 j
 | ƒ r/|	 j | ƒ |	 j d | ƒ q/q/Wxš|	 D]�} g  } xM | j  t j j | | d ƒ ƒ D]* } | j t j j | ƒ d d d !ƒ q�Wt j j t j j | | d ƒ ƒ rµy¯ t t j j | | d ƒ ƒ } | j ƒ  } | j ƒ  g  } xJ | D]A } | j ƒ  | k r4| j | j ƒ  ƒ | j | j ƒ  ƒ q4q4Wx | D] } | j | ƒ q€W| } Wq¿| j ƒ  q¿Xn
 | j ƒ  g  } x» | D]³ } |  j d t j j | | | d ƒ d d ƒ } t | ƒ d k r>| d d k r>| d j ƒ  d k r>qÌn  |  j d t j j | | | d ƒ ƒ \ } } | j | | g ƒ qÌWt | ƒ d k ro| r±| j | | g ƒ qþxJ | D]? } | j | j d d | d | ƒ ƒ | j | d | ƒ q¸WqoqoWq\ q\ WqO W| r| S| | f Sd  S(   Niÿÿÿÿs	   All atomst	   all_atomsR   t   cvst   CVSR   i    t   Ligand_binding_sitet   Ribbonst   Bondss
   *.mgpic.pyi   i÷ÿÿÿt   ORDERR1   s	   .mgpic.pyRB   t	   GUIIGNOREi   t   1t   _t    t   :(   t   globR:   R   R   R   R   R   R   t   basenamet   isdirR   R=   R   t   removet   insertR<   R$   t	   readlinesR9   R?   t   sortRI   RY   t   sub(   R    t   stylet   treeRg   R:   t
   style_menut   style_aliast   mt   mastert	   base_listt   drt   baseR*   t   groupt   filelistt   filet   order_ft   order_linest   filelist_sortt   order_lt   flt   filequerylistt   fooRV   RR   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt   define_model_style_menu¿   sj    			%Z(($


.8.$+c         K   sx  | r$ |  j  j | ƒ r$ | |  _ n  t |  d ƒ s7 d  S|  j d |  j d d d | ƒ } |  j d |  j d d d | ƒ } | rÿ d d  l }	 |	 j d d	 | ƒ } |  j d | d d d | ƒ }
 |  j d | d d d | ƒ } t j | |
 ƒ t j | | ƒ nu| rLt j	 j
 | ƒ r't j | ƒ n  t j	 j
 | ƒ rtt j | ƒ qtn(| rt|  j j | ƒ shd  Sd
 } t j	 j
 t j	 j |  j | ƒ ƒ r­t j	 j |  j | ƒ } nM xJ |  j D]? } t j	 j
 t j	 j | | ƒ ƒ r·t j	 j | | ƒ } q·q·W| rQd d  l } |  j d |  j d d d | ƒ }
 |  j d |  j d d d | ƒ } n  | j | |
 ƒ | j | | ƒ n  d  S(   Nt   edited_picturet   indexR-   t   snapshotR#   R.   iÿÿÿÿRe   Rd   R   (   t   snapshot_listR   Rƒ   t   hasattrR/   R:   Rn   R   t   renameR   R   Rj   t
   style_dirsR   R   R   t   shutilt   copyfile(   R    t   picturet   new_nameR#   R&   t   copy_tot   keywordst   old_snapshott	   old_mgpicR:   t   new_snapshott	   new_mgpict   new_dirt   ddRŠ   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt   edit_picture  sB     !!   $!!$c         K   s4  d d  l  } |  j j | ƒ rF t ƒ  j d | d d d d d ƒd  St j j t j	 ƒ  d d	 | j
 d
 d | ƒ ƒ } t j j | ƒ r¼ t ƒ  j d | d t j j t j	 ƒ  d ƒ ƒ n  y t j | ƒ Wn t ƒ  j d | ƒ d  SX|  j j | j
 d
 d | ƒ ƒ |  j j | | j
 d
 d | ƒ g ƒ d  S(   Niÿÿÿÿs   Style name: s   already existst   helpR   t   targett   style_foldersR
   R	   Re   Rd   s   Style directory: s   already exists in s    Error creating style directory: (   R:   Rq   R   t   MGGUIt   WarningMessageR   R   R   R   R   Rn   R   t   mkdirR‰   R   (   R    t   new_style_folderR�   R:   R#   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt   create_folder1  s    $04c   
      K   sT  d d  l  } | j d d | ƒ } |  j j | ƒ rO t ƒ  j d | d ƒ d  S|  j d | d | d d	 ƒ } t ƒ  j d
 | d d d d d g d d	 ƒ } | r¸ t ƒ  j d | ƒ d  S|  j d | d | d d ƒ } t	 ƒ  j
 d
 | d d d d d d d d ƒ d } d d  l }	 x: | d k  rOt j j | ƒ rO| d } |	 j d ƒ qWd  S(   NiÿÿÿÿRe   Rd   s   Style name s    is already usedR„   R#   R-   R.   R1   t   limited_savei   t	   save_listt   displayR0   Ro   s   Error saving R…   t   screenshot_widthiÈ   t   screenshot_heightt   clear_labelsi    i
   (   R:   Rn   R†   R   Rš   R›   R/   t   PDt   save_picture_definitiont   SSt   make_screenshott   timeR   R   R   t   sleep(
   R    t	   new_styleR#   R�   R:   R�   t   filnt   statt   ntryR©   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt
   save_styleD  s$    +"
R…   c         C   sÈ  d d l  } | rf | j | d ƒ d k rf | j | d ƒ \ } } t j j |  j | t | ƒ ƒ } nB | rŠ t j j | t | ƒ ƒ } n t j j |  j t | ƒ ƒ } | d k r½ d }	 n | d k rÒ d }	 n d	 }	 d
 d d g j | ƒ r�d d l	 }
 d d l  } d d l
 } | j |
 j |
 j	 ƒ  ƒ ƒ } | d d | d d | d d | j d d | d ƒ } | d | } | d
 k rº| d | } qºn | rº| d t | ƒ } n  | |	 } | S(   sR   
    Return path for file containing status or snapshot image for given index
    iÿÿÿÿNRf   i    R…   s   .snapshot.ppmt   pngsnapshots   .snapshot.pngs	   .mgpic.pyt   newt   replacedt   editedRd   i   i   i   t   .(   R;   R>   R<   R   R   R   R   t   strR   R©   R:   t   ctimeRn   (   R    R„   R-   R#   t   versionR,   R;   t   fdirR¬   t   extR©   R:   t   t0t   t1(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyR/   `  s.    $		$= 
iÿÿÿÿc   )   	   J   s{	  d d  l  }	 d d  l }
 d d  l } d d  l } g  } | d k  rR d e ƒ  } n  | rs |  j d | d d ƒ } n  |  j | ƒ } | j | ƒ | } |  j d | d d	 ƒ } | d r» | S| d } d d  l	 } d d  l
 } d d  l } d d  l } d
 } xyd g D]n} i  } g  | d <| j | ƒ i  } y- e | j j | j d d d d ƒ | ƒ WnH e k
 r¥} | d } | j GHe ƒ  j | d d d d ƒd | g SXxç| j ƒ  D]Ù\ } } | sÎg  } n e | | j ƒ sì| g } n  x�| D]•} e d | ƒ } | ró| d } | j d d ƒ | j d k rZ| d j | j d | j ƒ ƒ n– | j d k rŒ| d j | j d | j ƒ ƒ nd | j d k r¾| d j | j d | j ƒ ƒ n2 | j d k rð| d j | j  d | j ƒ ƒ n  | d d j! d | ƒ | | d d _ g  | d d _" | d d j" j# | j" ƒ g  | d d _$ | d d j$ j# | j$ ƒ | | d <| | | <qóqóWq³W| ry | | | f d  UWq)e k
 r} | d | d } e | | j% ƒ rßd
 } d d  l } e& | d ƒ rAe | j' | j( ƒ rAx' e) d | j' ƒ D] }  | d  } q*Wn  e& | d! ƒ rƒe | j* | j( ƒ rƒ| d" e+ | j* ƒ d# } n  e& | d$ ƒ rÒe | j, | j- ƒ rÒ| |	 j. d d
 | j, ƒ d | d% } n  | d& } n" | j/ ƒ  }! | |! j0 | j ƒ } d G| G| j GHq)Xn | | | f d  U| rUe ƒ  j | d d d d ƒd | g S| j1 d' ƒ rÅ| d' rÅd( | d) } x  | d' D] }" | |" d } q‡We ƒ  j | d d d d ƒd | g S| j1 d* ƒ r.| d* r.d+ | d) } x  | d* D] }" | |" d } q÷We ƒ  j | d d d d ƒn  x@ | d, j2 D]1 } e3 | j ƒ }# |# r<|# j4 d- | j5 ƒ q<q<Wg  | d, _2 xa | d D]U } xL | j" D]A }$ e |$ | j6 ƒ r™|$ j7 | j d. e8 ƒ| j |$ j ƒ q™q™Wq‰W| d/ rg| j9 d d0 d1 d0 d2 | d/ ƒ }% |% j7 ƒ  }& |& d r9| |& d d } n  |% j: ƒ  }& |& d rg| |& d d } qgn  d d  l } x@ | d3 j2 D]1 } e3 | j ƒ }# |# r�|# j; d- | j5 ƒ q�q�Wg  | d3 _2 | d4 j2 rôe< ƒ  j= d- | d4 j2 d j5 ƒ n  | d5 j2 rµe> | d5 j2 ƒ d k rµe& | d5 j2 d d- ƒ rµx~ | d5 j2 d j5 D]e \ } } e? ƒ  j@ | d6 d ƒ}' |' d k r•e? ƒ  jA d | d7 | ƒ qIe? ƒ  jB d8 | d7 | ƒ qIWn  | d9 rf	| j9 d d: d1 d: d2 | d9 ƒ }( e d: ƒ s	|( j7 ƒ  }& |& d r2	| |& d d } q2	n |( jC e d: ƒ d ƒ |( j: d; d ƒ }& |& d rf	| |& d d } qf	n  ~ ~ d | g SWd  S(<   Niÿÿÿÿi    i   R,   R-   R.   R1   RB   R4   R   t   DataListt   CCP4MGt   pythont   uis   picture_definition_classes.pys,   Error loading picture_definition_classes.py
R—   t   picture_definitionR˜   t   errorsRL   t
   visibilityRM   t   MapDatat	   FieldDatat   VectorsDatat   dataobjt   force_recolour_bymols   Error reading s   
t   offsetRe   t   linenos   Invalid syntax in line s   :

RD   s   *

s#   (Hint: also check preceeding line)
t   ERROR_MESSAGEs   Error interpreting s   

t   WARNING_MESSAGEs   Warning interpreting t   ColourSchemeManagerR0   t   deleteEmptyt   twoDListt
   GL2dScreent   object_typet   objinstst   ParamsManagert   Viewt   Colourst   safet   newrgbt   newnamet   CrystalListt   CrystalDatat   override_visible(D   R:   R;   t   typesRÆ   t	   DEVELOPERR/   t   initialise_chosent   updateRI   R   t
   exceptionst   pprintt   picture_definition_classest   execfileR   R   R   t   StandardErrort   argsRš   R›   R   t
   isinstancet   ListTypet   get_dataobjt   set_visibilityRÐ   R   RM   RL   RÃ   RÄ   RÅ   t   saveRÑ   t   extendt   objnamest   SyntaxErrorR‡   RÈ   t   IntTypet   rangeRÉ   Rµ   RD   t
   StringTypeRn   t   PrettyPrintert   pformatRT   R   t   PMt   restore_picture_definitionR0   t   DispObjShadowt   restoret   Truet   DataObjShadowt   restore_display_objectst   update_data_statust
   MAINWINDOWt   setViewParamsR=   t   MGCOLOURR„   t   resetR±   t   set_dataobj()   R    t   trap_errorst   chosent   chosen_dataobjR   R,   t
   mgpic_fileRÇ   R�   R:   R;   RÛ   RÆ   t   createdDispobjt
   chosen_defRU   t   script_textR   Rß   Rà   Rá   t   messaget   repeatRW   RX   t   eR!   R"   t   obj_namet   obj_listt   objt   spacest   it   ppt   linet   pmt   dispt   twoDt   rvt   indxt   xtl(    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt   create_picture‡  s
   $  
 
0
-
	
####
$ $
$+


"
 
 $@! 
"
 
 c         C   s¶   i  } |  j  d | ƒ \ } } | d k r. i  Sx� | D]y } | j d ƒ r5 | j d ƒ r5 d d d d g j | d ƒ r5 | j d	 ƒ r� | d	 | | d <q® d
 | | d <q5 q5 W| S(   NR1   i    RL   RN   RM   RÃ   t
   VectorDataRÄ   t   initialR   (   RY   RT   R   (   R    R1   R   RV   RR   R*   (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyRÝ   5  s     >N(   t   __name__t
   __module__R%   R   R   R   R$   R&   R+   R2   RI   RY   RZ   R‚   R–   Rž   R¯   R/   t   FalseR  RÝ   (    (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyR      s.   
						-#I)'	­(   t   __doc__R   t   sysR   R    t   global_definitionsR   (    (    (    sE   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_wizard.pyt   <module>   s   $
