ó
ÉÝ{Tc           @   s`   d  Z  d d l Z d d l Z d d l Td d l Z d d l Z d f  d „  ƒ  YZ d „  Z d S(   s|  
     python/ui/Animation.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009-2010 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.
iÿÿÿÿN(   t   *t	   Animationc           B   sé   e  Z d Z d  i  d d „ Z i  d „ Z d „  Z d „  Z d  d  d  d „ Z d  d d  d „ Z	 d  d  d	 „ Z
 d
 d „ Z d d  d „ Z d „  Z d „  Z d „  Z d „  Z d  d „ Z d „  Z d  d  d  d „ Z d  d  d d „ Z RS(   t    i   c         K   sÊ   | j  | ƒ | |  _ d d g |  _ d d g |  _ d  |  _ d |  _ t |  d | j d g  ƒ ƒ t |  d | j d d ƒ ƒ | rÆ |  j	 rÆ |  j
 ƒ  } | r¬ |  j ƒ  n  t ƒ  |  j d | ƒ n  d  S(	   Niüÿÿi   i'  i    t   filenamet   file_formatt   multiple_PDBst   params(   t   updatet   parentt   current_framet   frame_ranget   Nonet
   legend_objt
   nowRunningt   setattrt   getR   t   loaddatat   deletet   AnimationParamsManagert   update_data_status(   t   selfR   R   t   loadt   kwt   rv(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   __init__   s    			 c         C   sÛ   d } | j  d ƒ rk | d |  j k rk | d d d k rk d } |  j d | d d d | d d ƒ n  | j  d ƒ r× | d r¡ |  j r¡ d } |  j ƒ  q× | d r× |  j r× d } |  j j ƒ  d  |  _ q× n  | S(   Ni    R	   iüÿÿi   t   framet	   directiont   legend_name(   t   has_keyR	   t	   set_frameR   t
   add_legendR   R   (   R   R   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR   5   s     c         C   sS   |  j  r |  j  j ƒ  n  t d d ƒ r1 |  ` n  t |  j d ƒ rO |  j ` n  d  S(   NR   t   NMR_models_molHndt	   animation(   R   R   t   hasattrR   R   R    (   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR   K   s    	  	 c         C   s`   i  } x- d d d d g D] } t  |  | ƒ | | <q W|  j rR |  j j | d <n
 d | d <| S(   NR   R   R	   R
   R   R   (   t   getattrR   t   name(   R   t   parst   item(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR   Q   s    	
c         K   s2  | s |  j  d } n  | s, |  j  d } n  | r] |  j d k r] |  j d | d | d | ƒ S| r.|  j d k r.t j | | ƒ } t j j | ƒ sš d St j	 ƒ  } t j
 | | ƒ } | rÕ ~ t ƒ  j d ƒ d Sd | j ƒ  g |  _ | | | g |  _  | |  _ |  j j d k r.t ƒ  j d	 ƒ d Sn  d  S(
   Ni   i    R   t   pdbfilet   DIR_pdbfilet
   last_framet
   NMR_modelss)   Error attempting to read 'NMR' model files†   Animation successfully loaded. The first model in the structure will be updated with trajectory coordinates when you run the animation(   R   R   t   set_filebaset   utilst   get_filenamet   ost   patht   existst   mmdbt   Managert   ReadCoorFilet   MGGUIt   WarningMessaget   GetNumberOfModelsR
   R   R   t
   nmr_models(   R   R&   R'   R(   t   keywordsR.   t   molHndR   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR   ]   s,       	t   FULLPATHc      	   C   sÐ  d d  l  } d d d d d d d d	 d
 g	 } t j | | ƒ } t j j | ƒ sU d St j j | ƒ } x5 t d d d ƒ D]! } | j | d | ƒ sz Pqz qz W| d k r¿ t	 ƒ  j
 d ƒ d S| d } | d d | !| d g |  _ | | | g |  _ t | d | ƒ }	 d }
 xO |
 rdt j j |  j d t |	 d ƒ |  j d ƒ r[|	 d }	 qd }
 qW| r¯t j | d ƒ |	 k  r¯t | d | ƒ t j | d ƒ g |  _ n t | d | ƒ |	 g |  _ d S(   Niÿÿÿÿt   0t   1t   2t   3t   4t   5t   6t   78t   9i   iûÿÿÿi    s1   Animation file name does not have expected formati'  (   t   GUIR+   R,   R-   R.   R/   t   splitextt   ranget   countR3   R4   t   filebaseR   t   intt   strt   safeIntR
   (   R   R&   R'   R(   RC   t   digitsR.   t   splitt   nnumt   iframet   continu(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR*   y   s2    !  
	2
,c      	   C   sN  d d d d d d d d d	 g	 } t  j | | ƒ } t j j | ƒ sI g  St j j | ƒ } x5 t d
 d d
 ƒ D]! } | j | d | ƒ sn Pqn qn W| d
 k r£ g  S| d } | d d | !| d g } | g } t | d | ƒ }	 d }
 x\ |
 rI| d t	 |	 d ƒ | d } t j j | ƒ r@| j
 | ƒ |	 d }	 qî d }
 qî W| S(   NR:   R;   R<   R=   R>   R?   R@   RA   RB   iÿÿÿÿiûÿÿÿi    i   (   R+   R,   R-   R.   R/   RD   RE   RF   RH   RI   t   append(   R   R&   R'   RK   R.   RL   RM   RG   t   filename_listRN   RO   t   file(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   get_filelist§   s,    !  
		 
iÿÿÿÿc         C   s™   | d k s! | d k  rG |  j  rG d |  _  t ƒ  j d |  j j ƒ nN | d k si | d k  r• |  j  r• d |  _  t ƒ  j d |  j j |  j ƒ n  d  S(   Ni    s   Animation of i   (   R   t
   MAINWINDOWt   removeAnimationHandlerR   t
   name_labelt   addAnimationHandlert
   next_frame(   R   t   mode(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   toggle_animationÎ   s    !	"	i    c         K   sr   | rR | |  j  d k rR |  j d | ƒ } | d rO t ƒ  j | d ƒ qO qR n  | rn t | ƒ |  j  d <n  d  S(   Ni    RN   i   (   R	   t
   load_frameR3   R4   RH   (   R   R   R   R7   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR   Ú   s    
 c         C   s   |  j  d S(   Ni    (   R	   (   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   getFrameå   s    c         C   s   | |  j  d <d  S(   Ni   (   R	   (   R   t   inc(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   setIncrementè   s    c         C   s   |  j  d S(   Ni   (   R	   (   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   getIncrementë   s    c         C   s×   d d  l  } d d  l } |  j d |  j d } | |  j d k  rr | j |  j d ƒ } |  j d d g |  _ nO | |  j d k r´ | j |  j d ƒ } |  j d d g |  _ n | |  j d <|  j d | ƒ } | S(   Niÿÿÿÿi    i   RN   (   t   copyt   rebuildR	   R
   t   deepcopyR[   (   R   R`   Ra   RN   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyRX   ï   s    c         C   sA  d d  l  } | d k rŒ | j ƒ  } |  j j d } t j | | ƒ } | r] ~ d d | g S|  j j j | ƒ } ~ | r¦d d | g Sn|  j d k r_|  j	 d t
 | ƒ |  j	 d } t j j | ƒ së d d | d	 t
 | ƒ g S| j ƒ  } t j | | ƒ } | r ~ d d | g S|  j j j | ƒ } |  j j j ƒ  ~ | r¦d d | g SnG |  j d
 k r¦|  j j j |  j | ƒ } | r¦d d t
 | ƒ g Sn  | |  j d <|  j d d k rÏd } n d } |  j r|  j j d t
 |  j d d ƒ ƒ n  t ƒ  j d ƒ r*|  j j d ƒ n |  j j d ƒ d g S(   Niÿÿÿÿi   i   s   Error loading PDB file s   Error setting coordinates from R   i    s   Error PDB file s    does not exist for frame R)   s$   Error setting coordinates for frame R;   t   forwardst	   backwardst   textt   update_propertiest   reconfiguret	   transform(   t   mmdb2R1   R   R   R+   R2   R8   t   CopyCoordinatesR   RG   RI   R-   R.   R/   t   ReApplyTransformR   R	   R   t   set_selectionR   R   t   update_dependents(   R   RN   R0   R8   R.   R   t   dirn(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR[      sP    "		'c         C   s   |  j  d |  j  d d S(   Ni   i    (   R
   (   R   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   get_number_of_framesB  s    c         C   s²   | d k r d  |  _ n– |  j r% d  Sd d  l } | j d t ƒ  j d d |  j j d |  j j ƒ |  _ |  j j d t |  j d d	 ƒ ƒ |  j j	 |  j d g |  j
 g ƒ d  S(
   NR   iÿÿÿÿR   R#   t   animation_legendt   masterRe   i    i   (   R   R   t   Legendt   GL2DMANAGERR#   R   Rl   RI   R	   t   add_dependencyR   (   R   t   legendRq   t	   attributeRr   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR   H  s    	 $c         C   sJ  d d l  } d d l } g  } g  } |  j s@ t | ƒ | | g S|  j d k r´ |  j d |  j d d |  j d ƒ |  j sŒ d d g g  g S| j |  j d	 d
 |  j d ƒ } n |  j g } xN | D]F }	 t j d |	 d | d | ƒ }
 | j	 |
 d ƒ | j	 |
 d ƒ qÇ W| r7| |  j d |
 d g |  _ n  t | ƒ | | g S(   s4   
    Copy the data file(s) to another directory
    iÿÿÿÿNR   R&   i   R'   i   s   No animation files definedi    R    R   t   dirt	   overwrite(
   t   shutilt   globR   t   lenR   R*   RG   R+   t   copy_data_fileRP   (   R   t   projectRw   Rx   Ry   Rz   t   copiedt   errorst   filnlistt   filnt   ret(    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   copy_data_filesX  s$    	 $	 (  N(   t   __name__t
   __module__R   t   ParamsManagerR   R   R   R   R   R*   RS   RZ   R   R\   R^   R_   RX   R[   Ro   R   Rƒ   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR      s$   		.'				B	c          C   sè   d d  l  }  t j sá |  j d d d d d d d d	 d
 d g d i d d	 6d d
 6d d 6d i t d d d d ƒ d	 6t d t d d d d d d d d d d ƒ d
 6t d t d d d d d d d d d d ƒ d 6d d ƒ t _ n  t j S(   NiÿÿÿÿR#   t   Animation_paramt   titles   Animation and flashingt   picture_definitioni   t   guiRf   t   delayt   flash_delayt   defaultgš™™™™™¹?g      à?t
   definitiont   typet   boolt   labels1   Update properties (e.g. secondary str.) each steps"   Minimum time delay between updatest   stylet   spinboxt   maxg      $@t   mint   steps   Minimum delay in flashingt   helpR    (   t   servicesR   R†   t   dictt   float(   R˜   (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyR   v  s     	

(	   t   __doc__t   mmutRi   R0   t   global_definitionsR+   R-   R   R   (    (    (    s@   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/Animation.pyt   <module>   s   
ÿ ]