ó
ÉÝ{Tc           @   sU   d  Z  d d l Td d l m Z d d l Z d d l Z g  Z d d d „  ƒ  YZ d S(   s¢  
     python/ui/picture_definition.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009-2010 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ÿÿÿÿ(   t   *(   t   ParamsManagerNt   picture_definitionc        
   B   sÐ   e  Z d  Z i  Z i d d 6d d 6e d <d d g e d <d e d <d „  Z d  d  d d  d	 d
 d d g d d „ Z d „  Z d  d d  d „ Z d  d  d d d d d	 d
 d d g d d  d „	 Z d d  d „ Z	 RS(   t    i   t   create_DispObji    t   keep_currentt   contentt   ordert   exportc         C   s/   |  t  _ i d d 6|  _ d |  _ d |  _ d  S(   Ni   t   COLOURi    (   R   t   instst   colour_export_objectst   pm_allt   save_visible(   t   self(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_definition.pyt   __init__%   s    		t   viewt   colourst   displayt   paramst   methodc   *      K   s
  | r{
d d  l  } d d  l }	 d d  l }
 d d  l } d d  l } t j | | ƒ } g  } d t j d t	 | j
 | j ƒ  ƒ ƒ d } d } d } | j ƒ  } t | ƒ } | rÅ t | ƒ |  _ n  xm	| D]e	} | d k rÏd } d	 } t ƒ  j ƒ  } d
 } | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | t j d | d | d | d | ƒ} | d } qÌ | d k r|  j j d ƒ r1
| t ƒ  j d | d |  j ƒ } q1
qÌ | d k rd  d! d" g } d# } i  } g  } xS t d$ d% ƒ D]B } | j ƒ  } x- | D]% } | j | ƒ sk| j | ƒ qkqkWqRW| rÌ| t ƒ  j d | d& d' d( d) d* | ƒ } n  g  } xY t d$ d% ƒ D]H } | j d( d+ ƒ } x- | D]% } | j | ƒ s| j | ƒ qqWqâW| rb| t ƒ  j d | d& d' d( d+ d* | ƒ } n  xÌ|
 j D]‘} xˆ|
 j d$ | ƒ D]t} |  j sž| j r…|
 j ƒ  } | j | d | ƒ} | rË~ qù| | j d | d | ƒ } | d% k rF| t ƒ  j d | d& | j  d( d) ƒ } | t ƒ  j d | d& | j  d( d+ ƒ } n  d } | j | ƒ r�| | d, | | <| d- k r—| | d, } q—n
 d, | | <| d% k r·| | d. d/ !} n
 | d0 } | t	 | | ƒ } | d1 | d2 d3 | d2 d4 | d2 d5 } | d6 k rd } n  xÊ | j! D]¿ }  |  j s;|  j r"| d6 k sdd7 d8 d9 g j |  j" ƒ rá| |  j d | d d d: | ƒ } t# |  d; ƒ rÞ| j$ j% j |  j& j' d< d ƒ ƒ rÛ| j |  j& j' d< d ƒ ƒ qÛqÞqáq"q"W| d. d= !d> } q…q…WqlWqÌ | d? k rÌ xE t( d ƒ D]7 }! |! j) d. k r| |! j d | d |  j ƒ } qqWxE | D]= }! t( d@ |! ƒ } | r_| | j d | d |  j ƒ } q_q_W| dA } | dB } | dC t	 t ƒ  j* j+ ƒ  ƒ dD } | dE t	 t ƒ  j* j, ƒ  ƒ dF } | dG } t ƒ  j* j- ƒ  }" d d  l. }# i  }$ d. }% xä t/ t0 t1 |" ƒ ƒ |" ƒ D]Ç \ }& }' i  }( |' rL|' j dH ƒ rL|' j d ƒ rL|' d j2 ƒ  |' d j3 ƒ  |' dH g |( dI <|' d? |# j4 |( dJ <|' d? |# j5 |( dK <|' d? |# j6 |( dL <d, |( dM <|( |$ t	 |& ƒ <|% d, }% qLqLW| dN } | dO } | t j dP |$ | d d d | ƒ} | dQ t	 |% ƒ dF } | dG } xJ |
 j7 D]? } x6 |
 j d$ | ƒ D]" } | | j d | d | ƒ } q•	Wq|	Wxo t ƒ  j8 D]^ }) t# |) dR ƒ rÌ	t9 |) j ƒ rÌ	y  | |) j d | d | ƒ } Wq*
dS G|) GdT GHq*
XqÌ	qÌ	WqÌ qÌ W| d6 k rZ
| dU | dV | } n
 | | } t j: | dW | ƒd. Sd  S(X   Niÿÿÿÿs­   # CCP4mg picture definition file
# See http://www.ysbl.york.ac.uk/~ccp4mg/ccp4mg_help/picture_definition.html
# or your local copy of CCP4mg documentation.
# CCP4mg version s   
# Created s   


s   CHOICES = [
R   R   R   i   s   view = View (t   orientationt   quatt   stylet   indentt
   centre_xyzt   post   scalet   fog_enabledt   fog_neart   fog_fart   slab_enabledt
   slab_widtht   slab_offsett   clip_capt   customClipPlaness             )

R   R	   t   pretty_printt   allR   t   secondt   thirdt   fourths   #SECTION CHOICES

CHOICES = [
t   object_typet   MolDatat   sett   generict   infot   user_selectiont   keyst   user_colour_schemesi   i   i    iüÿÿÿt   models       { 'name' : 's   ', s
   'type' : 's   'label' : 'Select s   'multi' : 0 },
t   mgpict   Crystalt   Legendt   Imaget   parentt	   colparamst   colour_modeiþÿÿÿs
   
      ]

R   t   names   ParamsManager(
s             name = 'gui_params',
s             show_axes = s   ,
s             background_colour = s   
s   )
t   deptht   positiont   ambientt   speculart   diffuset   ons   
ParamsManager(
s        name = 'light_params',
t   lightss   
     nLights = t   save_picture_definitions   call ofs   save_picture_definition faileds    #SECTION TITLE

#SECTION NOTES

s(   #SECTION SCRIPT


global ERROR_MESSAGE

t   text(;   t   pprintt   syst   dataobjt   timet   servicest   utilst   get_filenamet   versiont   ccp4mg_versiont   strt   asctimet	   localtimet   PrettyPrintert   intR   t
   MAINWINDOWt   getViewParamst   picture_defn_itemR   t   has_keyt   MGCOLOURRA   R   t   get_dataobjt   get_open_schemest   countt   appendt	   MODELINFOt   DATAOBJ_TYPESt   visiblet   DataObjShadowt   savet
   name_labelt   objinstsR)   t   hasattrt   ColourSchemeManagert   colour_pref_aliasR7   t   gett   PMR   t   glWidgett   getAxest   getBackgroundt	   getLightst   openglt   zipt   ranget   lent   xt   yt
   GL_AMBIENTt   GL_SPECULARt
   GL_DIFFUSEt   PLUGIN_DATAOBJ_TYPESt   pluginst   callablet   saveFile(*   R   t   filenamet   DIR_filenamet   limited_saveR   t	   save_listR   t   keywordsRC   RD   RE   RF   RG   t   active_colour_schemest   headert   choices_streamt   streamR$   R%   t   itemR   t   view_paramst	   label_numt   ntypet   generic_schemest   objt   scmsR)   t	   shadowobjt   rvt   labelR9   t   dispt   pmR@   Rj   t   lst   nlightst   it   lightt   lt   plug(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_definition.pyRA   .   s
   0. )))))))))))(  .  .(+ 

' 	)"$, & &

$$
($+


%
$ 
c         C   sÞ   d d  l  } d d  l } | j j | j d | j j d d ƒ ƒ } | j | j j | d ƒ ƒ } g  } | j | j | j j | j j | d ƒ ƒ ƒ ƒ x? | D]7 } | j | j | j j | j j | d ƒ ƒ ƒ ƒ qŸ W| S(   Niÿÿÿÿt   CCP4MGt   qtguiRt   R    s   *_Shadow.py(   t   ost   globt   patht   joint   environt   extendt   normpath(   R   R”   R•   t   pluginpathsRt   t   modulest
   pluginpath(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_definition.pyt   loadShadowPluginsÛ   s    +15iÿÿÿÿc         C   s  d d  l  } d d  l } d d  l } d d  l } | d k  rL d t ƒ  } n  d } i  }	 | |	 d <i  }
 yW t | j j | j d d d d	 ƒ |	 ƒ |  j	 ƒ  } x | D] } t | |	 ƒ q§ WWn% t
 k
 ræ } | d
 } | j GHn X| ræy t | |	 |
 ƒ Wqöt
 k
 râ} | d | } t | | j ƒ r­| j r­d } x$ t d | j ƒ D] } | d } qUW| d t | j ƒ d | j d d | j ƒ d | d d } n" | j ƒ  } | | j | j ƒ } d G| G| j GHqöXn t | |	 |
 ƒ | |	 |
 g S(   Niÿÿÿÿi    i   R   t   default_dirR’   t   pythont   uis   picture_definition_classes.pys+   Error loading picture_definition_classes.pys   Error reading t    s   Invalid syntax in line s   :

s   
s   *

s#   (Hint: also check preceeding line)
(   t   reR”   t
   exceptionsRC   t	   DEVELOPERt   execfileR–   R—   R˜   Rž   t   StandardErrort   argst
   isinstancet   SyntaxErrort   offsetRl   RL   t   linenot   subRB   RO   t   pformat(   R   Rw   t   trap_errorsRŸ   R£   R”   R¤   RC   t   messaget   globst   locst   plugsR‘   t   et   spacesRŽ   t   pp(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_definition.pyt   read_picture_definitionæ   s@    $ 
)
 :
c
   :      K   s  | d k  r d t  ƒ  } n  | s, d d g Sd d  l } d d  l } d d  l } d d  l } d d  l } d d  l } g  } | sË x! | j j D] } | j	 | ƒ q� W| sË x | D] } | j
 ƒ  q± WqË n  |	 d k rì | j j | ƒ }	 n  t j | | ƒ } | j j | ƒ sd d g St j } d G| GHy` t | ƒ } | j ƒ  } x7 | D]/ } | j d ƒ rN| t d ƒ j ƒ  } PqNqNW| j ƒ  Wn t j } n Xt } t t ƒ  _ t j | ƒ } d G| GH| d d k r| d d	 k r| d d
 k  rt } n  | rLg  t ƒ  _ d t ƒ  _ t ƒ  j j  ƒ  t t ƒ  _ t ƒ  j! ƒ  n5 g  t ƒ  _ d t ƒ  _ t ƒ  j j  ƒ  t ƒ  j" ƒ  t ƒ  j# ƒ  |  j$ | | d |	 ƒ\ } } } | rÛt% ƒ  j& | d d d d ƒd | g S| d r<d | d } x  | d D] } | | d } qþWt% ƒ  j& | d d d d ƒd | g S| j' d ƒ rÙ| d j( rÙx~ | d j( d j) D]e \ } } t ƒ  j* | d d ƒ} | d k r¹t ƒ  j+ d | d | ƒ qmt ƒ  j, d | d | ƒ qmWn  i d d 6}  | j- d ƒ r	|  j. | d ƒ n  x: |  j/ ƒ  D], } |
 j- | ƒ rt0 |
 | ƒ |  | <qqW| j' d ƒ rò| d r„| j1 d d d d d  | d ƒ }! n  | d! r³| j1 d d" d d" d  | d! ƒ }" n  | rßt% ƒ  j& | d d d d ƒd | g S| ròd d g Sn  g  }# d  }$ | j' d# ƒ rd d  l } xŸ | d$ j( D]� } t3 | j4 ƒ }$ |$ rX|$ j5 d# | j) ƒ q'd d  l6 }% | j4 j d% ƒ rªd d  l7 }& |& j8 d | j4 ƒ }$ |$ j9 | j) ƒ n  |# j	 | ƒ q'Wg  | d$ _( x@ | d& j( D]1 } t3 | j4 ƒ }$ |$ rÖ|$ j5 d# | j) ƒ qÖqÖWg  | d& _( n  t0 | ƒ } | j' d ƒ rÐx= | d' D]1 } | j: ƒ  }' |' d rA| |' d d } qAqAW| d' =d d  l; }( d  }) x¢ | d( D]– }* |* j< d) k rš|) sÄ|( j= ƒ  }) n  |) j> |* j? ƒ \ }+ }, |+ rú| d* |* j4 d } q0t@ ƒ  jA d+ d) d, d- d. t jB |* j4 ƒ d/ |, ƒ }' qšqšWxÞ | d0 D]Ò }* |* j< d) k r?g  }- x` |* jC D]U \ }. }, |) s…|( j= ƒ  }) n  |) j> |, ƒ \ }+ }/ |+ sd|- j	 |. |/ i  g ƒ qdqdW|- sÛ| d1 |* j4 d } qt@ ƒ  jA d+ d) d, d2 d. t jB |* j4 ƒ d/ |- ƒ }+ q?q?Wt }0 x�| d3 D]u} tD | d4 ƒ rµ	| jE j- d5 ƒ s]| | jE d5 <n  t j | jE d5 ƒ }1 |1 d d k r¬|1 d d	 k r¬|1 d d
 k  r¬t }0 n  |1 GH|0 rµ	| rµ	g  t ƒ  _ d t ƒ  _ t ƒ  j j  ƒ  t t ƒ  _ t ƒ  j! ƒ  t ƒ  j# ƒ  t } | j' d ƒ r²	| d j( r²	x~ | d j( d j) D]e \ } } t ƒ  j* | d d ƒ} | d k r�	t ƒ  j+ d | d | ƒ qC	t ƒ  j, d | d | ƒ qC	Wq²	qµ	n  d6 G| GH| jF d |	 ƒ }' |' d rï	| |' d d } n  |' d s&x– | d( D]Š }* |* j< | k r
| j j> |* j? ƒ \ }+ }, |+ rR
| d* |* j4 d } qŽ
t@ ƒ  jA d+ | j j4 d, d- d. t jB |* j4 ƒ d/ |, ƒ }+ q
q
WxÒ | d0 D]Æ }* |* j< | k r�
g  }- xN |* jC D]C \ }. }, | j j> |, ƒ \ }+ }/ |+ sÂ
|- j	 |. |/ i  g ƒ qÂ
qÂ
W|- s'| d1 |* j4 d } qct@ ƒ  jA d+ | j j4 d, d2 d. t jB |* j4 ƒ d/ |- ƒ }+ q�
q�
W| jG d7 | ƒ }' |' d r›| |' d d } q›q&q&W| d! r6| s½tH d8 ƒ rë|" jF ƒ  }' |' d r| |' d d } qn |" jI tH d8 ƒ d ƒ |" jG d7 | ƒ }' |' d r6| |' d d } q6n  | d rÐ| sTtH d ƒ r‚|! jF ƒ  }' |' d r™| |' d d } q™n |! jI tH d ƒ d ƒ |! jG d7 | ƒ }' |' d rÍ| |' d d } qÍqÐn  x/|# D]'} | j4 d9 k rtJ ƒ  jK d# | j) ƒ q×| j4 d: k rÁd d  lL }2 |2 jM | j) ƒ }3 tD |3 d; ƒ rþ|3 j- d< ƒ rþ|3 j- d= ƒ rþ|3 d< }4 |2 jM |4 ƒ }5 x" |4 D] } |5 | |5 t0 | ƒ <qW|3 d= |5 d= <tJ ƒ  jN |5 ƒ qþq×t3 | j4 ƒ }$ |$ ré|$ j9 | j) ƒ q×| d> | j4 d } q×W~# | j' d? ƒ rE| d@ j( rEtJ ƒ  jO d# | d@ j( d j) ƒ n  x9 tP D]1 }6 tD |6 dA ƒ rLtQ |6 jR ƒ rL|6 jR ƒ  qLqLW| r×d d  lS }7 d d  lT }8 |7 jU ƒ  |8 jV dB ƒ x | D] }9 |9 j
 ƒ  q½W~ n  | GH| rt% ƒ  j& | d d d d ƒd | g S~ ~ d d g S(C   Ni    i   R   iÿÿÿÿt   restore_picture_definitions   # CCP4mg version s    Reading status file from versioni   i   i   RŸ   t   helpR   t   targett   errorst   ERROR_MESSAGEs   Error interpreting s   

s   
R   t   Colourst   safeR9   t   newrgbt   newnameR   t   preferencesR   t   CrystalListt   CrystalDataR)   R`   t   twoDListt
   GL2dScreenR   R   t   HBond_drawing_styleRb   t
   InlineListt   SelectionSchemeListR,   s"   Can not interpret SelectionScheme R+   R-   R.   t   keyt   valuet   ColourSchemeLists   Can not interpret ColourScheme R0   t   DataListt
   dataparamst   ccp4mg_creator_versions   restoring fromt   override_visibles   Legends&Imagest
   gui_paramst   light_paramsRT   R@   t   nLightss#   Can not restore the ParamsManager: R   t   Viewt   runAfterModelLoadg      ð?(W   R¥   RE   R”   R¤   R£   RC   t   picture_definition_classest   DataObjt   dataobj_instsRY   t   deleteR–   t   dirnameRH   RI   t   existsRJ   RK   t   opent	   readlinest
   startswithRm   t   rstript   closet   FalseRU   t   usingOldColourst   parseVersiont   Truet   rgbrepst   n_standard_rgbrepst   RGBRepst   cleart   load_old_defaultt   load_defaultt   initialiseRGBRepsR·   t   MGGUIt   WarningMessageRX   R
   R   t   indext   resett   newRT   t   updateR/   RP   R]   t   NoneRe   R9   R¸   RG   t   HBondst   createDrawingStylePMt	   setparamst   unpackt   model_selectiont
   parent_objt   SelectionParsert   command_to_listt	   selectionRZ   t   add_infot   oneWordR   Ra   RÍ   t   restoret   restore_display_objectsRV   t   set_dataobjRQ   t	   setParamst   copyt   deepcopyt   setLightParamst   setViewParamst   reqRunAfterModelLoadRu   RÔ   t   rebuildRF   t   UpdateDisplayt   sleep(:   R   Rw   Rx   R¯   t   testR   RÏ   t   restore_listt   delay_deleteRŸ   R{   RE   R”   R¤   R£   RC   RÕ   t   delete_listR…   t   ccp4mg_version_strt   ft   linesR�   t   old_coloursRK   R°   R±   R²   t   lineRÉ   RÊ   t   indxRÁ   t   xtlt   twoDt   PM_remainingR‹   RG   Rò   Rˆ   Rö   t	   SelParsert   schemet   statt   selt   com2listt   colt   listselt   data_old_coloursRÎ   R  t   pst   ps2t   ps3t   pR  RF   R€   (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_definition.pyR¸     sÚ     
H   
			0	!


! 
  
%
%
 
  "  "0	!&	
 
" "
 

 
 

 
 -
 $
 
t   mmanc         C   s¸  |  j  | ƒ \ } } } | r, d d | g S| d sD d d | g Sd d  l } | j j | ƒ d d } | d d j | ƒ }	 |	 d r™ d d | g S| d	 k rd d  l }
 |
 j d
 | d | ƒ } | j d d ƒ }	 |	 d d k r| j ƒ  d d | d |	 d g Sd | g Sd d  l	 } d d  l
 } | d k r^| j t ƒ  j t ƒ  j ƒ } n | j ƒ  } | j | j ƒ | j | j ƒ | j | j ƒ t j | | ƒ d | g Sd  S(   Ni   s    Error extracting data from file
RÇ   s   No inline data in file
iÿÿÿÿi    s   .pdbs$   No extracting inline data from file
R*   Rw   R9   t   warningss   Error loading file: s   
R"  (   R·   R”   R–   t   splitextRõ   R1   R*   t   loaddataRØ   t   mmutt   mmdb2t   CMMANManagert	   RESOURCESt   SRSt   CMolBondParamst   Managert   SetFlagt   MMDBF_IgnoreRemarkst   MMDBF_IgnoreBlankLinest   MMDBF_IgnoreHashRH   t   ReadCoorFile(   R   Rw   t   modeR9   R°   R±   R²   R”   t   pdbfileRˆ   R1   t   mR&  t   mmdbt   molHnd(    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_definition.pyt   loadInlinePDBA  s8    



!(
   t   __name__t
   __module__R
   RÁ   R   RA   Rž   R·   R¸   R7  (    (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_definition.pyR      s"   
		ª	-0ÿ /(    (   t   __doc__t   global_definitionsRÕ   R   RH   RJ   R  R   (    (    (    sI   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/picture_definition.pyt   <module>   s   
