ó
ÉÝ{Tc           @   s    d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Td e j f d „  ƒ  YZ d f  d „  ƒ  YZ d S(   sœ  
     python/ui/model_colour.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009-2011 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   *t   model_colourc           B   s�  e  Z d  d d d d d d d d d	 d
 d d d d d d d g Z d d d d d d d d d d d d d d d  d! d" d# g Z i d$ d 6d% d 6d& d 6d' d 6d( d 6d) d 6d* d  6d+ d 6d, d 6d- d 6d. d 6d/ d 6d0 d1 6d2 d 6d3 d" 6Z i  Z i  Z e j e j	 e j
 e j e j e j e j e j e j e j e j e j e j e j e j e j e j e j g Z d4 d5 g Z e j e j g Z i	 d d6 6d7 d8 6d9 d 6d: g d; 6g  d< 6d= d> 6d? d@ 6d9 dA 6d9 dB 6Z i d4 dC 6dD dE 6dF dG 6dH g dI 6dJ dK g g dL 6dM g dN 6Z  d6 d d8 d> d; d< dO d@ dA dB g
 Z! dI dL dE dN dC dG g Z" i  e# e# dP „ Z$ dQ „  Z% dR dS „ Z& dT „  Z' dU „  Z( dV „  Z) i  d9 d9 i  d9 d9 dW „ Z* dX „  Z+ d9 d9 dY „ Z, d9 d9 g  dZ „ Z- g  d9 dR d[ „ Z. g  d9 d\ „ Z/ d] „  Z0 d^ „  Z1 d_ „  Z2 g  d` „ Z3 g  da „ Z4 dD g  g  g  d4 db dc „ Z5 d9 d7 d9 d7 dd „ Z6 d9 de „ Z7 d9 d7 d7 df „ Z8 d9 d7 dg „ Z9 dh „  Z: RS(i   s
   One colours	   Atom types   Residue types   By chains   Main/side chains   Secondary structures   Blend through models   Temperature factort	   Occupancys   Alternate locationt   Charges   User defineds   Residue solvent accesss   Atom solvent accesst	   Interfaces   Position in chains   By models   By moleculet
   one_colourt   atomtypet   restypet   bychaint   mainsidet   secstrt   blendt   bvaluet	   occupancyt   altloct   charget   rulest   res_sast   atom_sast	   interfacet
   thru_chaint   bymodelt   bymols
   byatom.svgs   blendthrough.svgs   atomsolventaccess.svgs   residuesolventaccess.svgs   bychain.svgs
   charge.svgs   interface.svgs   mainside.svgs   occupancy.svgs   residuetype.svgs
   secstr.svgs   tempfactor.svgs   electrostatic.svgt   electrostatics
   altloc.svgs   bymodel.svgt   residuet   SSEt   colour_modei    t   non_C_atomtypet    s   Edited schemet   user_schemet   colour_rulest   ATOMt   stick_colourt   RESIDUEt   interface_stylet   interface_selectiont   interface_MolData_namet   groupt   whitet   default_colourt   allt   typet   peptidet   selection_commandt   bluet   redt   colourss   anti-clockwiset	   directiont   colour_legendc         C   s|  t  j j |  ƒ d d  l } | j d ƒ d  |  _ d |  _ | |  _ | |  _ d  |  _	 d |  _
 d |  _ d |  _ d  |  _ d |  _ g  |  _ d |  _ g  |  _ i  |  _ x- t j j ƒ  D] \ } } t |  | | ƒ q· Wx* t j j ƒ  D] \ } } | |  j | <qç W|  j j j d ƒ sD|  j j j d ƒ rDd g |  j d <qDn  t j |  j j d t j ƒ  ƒ |  _ |  j d	 | ƒ d  S(
   Niÿÿÿÿt   initializeColouringPlugini    R   t   PROTEINt   NUCLEICt   nucleicR+   t	   colparams(    t   dataobjt
   Dependencyt   __init__t   loadPluginst   Nonet   atomColourVectort   ifColourContinuoust   MolDatat	   SelHandlet   legend_objectt   do_recolourR   t   colour_labelt   colour_iconR0   t   user_colour_objectst   user_colour_idt   user_selHndst   colour_blendR   t   colour_initialisationt   itemst   setattrt   colour_blend_initialisationt   molecule_typet   countt   mgappt
   CMolColourt   molHndt   servicest   getCColourSchemest
   set_colour(   t   selfR5   R=   R>   R9   t   keyt   value(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR8   T   s4    														$c   	      C   sÏ   d d  l  } d d  l } d  } | d g } x� | d D]‘ } t | d | j ƒ rº | sg | j ƒ  } n  | d | j | d ƒ d g } x | d D] } | j | ƒ q“ W| j | ƒ q6 | j | ƒ q6 W| S(   Niÿÿÿÿi    i   i   (   t   typest   model_selectionR:   t
   isinstancet   ListTypet   SelectionParsert   list_to_commandt   append(	   RS   R   RV   RW   t   parsert	   new_rulest   rulet   tmpt   item(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   commandColourRules{   s     ! i   c         C   st  i  } | rx x6 t  j D]+ } t |  | ƒ r t |  | ƒ | | <q q Wi  | d <t |  d ƒ rp| d j |  j ƒ qpnø xW t  j d D]H } t |  | ƒ } t  j j | ƒ sÁ | t  j | k r† | | | <q† q† W| rpt |  d ƒ | d <t |  d ƒ rt |  d ƒ | d <n  | d d k rAi  | d <| d j |  j ƒ n  | j d ƒ rp| d d g k rp| d =qpn  | S(   NRF   i   R   R   R   R   s   Edited scheme(   R   t   colour_initialisation_ordert   hasattrt   getattrt   updateRF   RG   t   has_key(   RS   R(   t   colRa   RU   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR5   Œ   s.     
&
c         C   s   |  j  S(   N(   RB   (   RS   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   getIcon¬   s    c         C   s   |  j  S(   N(   RA   (   RS   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   getLabel±   s    c         K   s   d |  _  d  S(   Ni   (   R@   (   RS   t   args(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   set_do_recolour·   s    c      	   K   s§  d } | r |  j  j | ƒ n  | r1 | |  _ n  | rd d g j | j d d ƒ ƒ rÒ d | d <d d g | d d k | d <t d	 | j d
 d ƒ ƒ }	 |	 rÒ |	 d j j ƒ  | d <|	 d j j	 | d <qÒ n  | j
 d ƒ r.xJ t j D]< }
 | j
 d |
 ƒ rë | d |
 |  j  |
 <| d |
 =që që Wn  | j
 d ƒ r| d j
 d ƒ ri  } | j t j ƒ | j | d ƒ g  | d <x t d t | d ƒ ƒ D]d } |  j j d | d | d | d | ƒ } | d rî| d j | d ƒ q›| d j d ƒ q›W| | d <n  | j d d ƒ rB| j d d ƒ rBd | d <n  | j
 d ƒ ry| j
 d ƒ ry| d | d <| d =n  d d g j | j d d ƒ ƒ r§d | d <n  xZ | j ƒ  D]L } | d k rÝ|  j  j | d ƒ q´| d k rìq´t |  | | | ƒ q´W| s| j d ƒ } qn  t |  j  d ƒ t |  j  d ƒ k r”xL t t |  j  d ƒ t |  j  d ƒ d ƒ D] } |  j  d j d ƒ qsWn  | d k rÜt | ƒ |  j k rÜt | ƒ |  _ t d |  j ƒ |  _ n | r÷| |  _ d |  _ n  | r]t ƒ  j | ƒ d k r*d |  _ | |  _ n d |  _ d |  _ |  j d  | ƒ |  _ d! |  _ n  |  j d" k rÕ|  j rÕd |  _ | j d t ƒ } |  j j  d# d | ƒ|  _ |  j |  j j! |  j j" d$ d ƒ|  _ n  |  j d k rd% d  l# } | j$ |  j ƒ |  _% n… |  j |  j& k rB|  j |  j' k rB|  j' |  j |  _% nK |  j d& k r]d& |  _% n0 |  j } t( j) |  j |  j* |  j+ ƒ } | |  _% | d k rÔ| j d' d ƒ } | r½| |  _, n  |  j, r—|  j, d( g k r—|  j- rt. ƒ  j/ d) |  j, d d* d+ d, |  j, d d- |  j- ƒ } q—t. ƒ  j0 d) |  j, d d* d+ d, |  j, d d. d ƒ \ } } | r‹| j
 |  j, d ƒ r‹| |  j, d |  _- q—d/ |  _ n  |  j, r³|  j, d |  _% n	 d( |  _% t d |  j ƒ |  _ n  d  |  _2 |  j d k rû|  j |  _2 n  |  j r,|  j |  j3 k r,|  j3 |  j |  _2 n  |  j2 ršt4 j5 j6 t4 j5 j7 t4 j8 d0 d1 d2 d3 |  j2 ƒ ƒ ršt4 j5 j7 t4 j8 d0 d1 d2 d3 |  j2 ƒ |  _2 qšn  d! |  _ d  S(4   NR   t
   res_buriedt   atom_buriedR   R   R   R!   R"   t   namet   contact_MolDispi    R#   t   interface_MolDatat   colour_blend_ranges_firstt   colour_blend_RF   t   ranges_firstR+   t   ranges_lasti   R(   R   t   user_colour_rulesR   t   userR   t   force_recolour_bymolR    R/   t	   clockwiset   defaults	   All atomsi   R   t   molecule_colourt   newlineiÿÿÿÿR   R   s   Edited schemet   sett   infot   user_colour_schemesRT   RU   t   firstR   t   CCP4MGt   qticonst   disptabt   colour(9   RF   Rf   R    RL   t   gett   get_dispobjR>   t
   getCommandt   parentRo   Rg   R   t   colour_blend_orderRJ   t   ranget   lenR=   t   interpretRangesR\   t   keysRI   t   intR   t   maxR@   R   R   t   MGCOLOURt   indext	   html_spanR0   t   Falset   get_attributet
   name_labelt
   mol_colourt   copyt   deepcopyRA   t   custom_colour_commands_methodst   custom_colour_commands_labelst   utilst   equivKeywordt   colour_commandst   colour_menuR   R   t	   MODELINFOt   add_infot   get_infoR:   RB   t   colour_commands_iconst   ost   patht   existst   joint   environ(   RS   R5   R   R   RF   R   R    t   keywordsRh   t   obj_listRT   t   iit   rvRa   t   iRx   R—   t   aliasR   t   statust   scheme(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyRR   ¼   sÔ    !
"
 
%
! &4!					*$		 	"				41c         C   s©   d d d d d d d g j  |  j ƒ s0 |  j r~ d g |  _ |  j d	 d
 d |  j d |  j ƒ } | r~ | \ |  _ |  _ q~ n  |  j s¥ d d g g |  _ d |  _ n  d  S(   NR   R   R   R   R	   R
   R   s   Edited schemet	   ifcommandi   t   modeR   t   greyR   (   RL   R   R   R   t   generate_colour_rulesR   R   R0   (   RS   R«   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   create_user_colour_definitionsb  s    0	c         C   sŠ   i  } t  ƒ  j d |  j j d d ƒ \ } } | rL | j ƒ  | |  j j <n  t  ƒ  j d d d d ƒ \ } } | r† | j ƒ  | t <n  | S(   NR}   R~   R   t   generic(   RŸ   R¡   R=   R•   R�   Rµ   (   RS   R}   t   labelt   parst   retvalt   defn(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   get_colour_schemesr  s    ' ! c      	   C   s@   | s |  j  j } n  t ƒ  j d | d d d | d | ƒ } | S(   NR}   R~   R   RT   RU   (   R=   R•   RŸ   R    (   RS   R}   R¶   R   R®   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   save_colour_scheme|  s
     c         C   s„   | s |  j  j d g } n  t ƒ  j d | d d d | ƒ \ } } | r€ | r€ |  j d d d i | | g d	 6| | d
 6ƒ n  d  S(   NRµ   R}   R~   R   RT   R   R   R5   R   R   (   R=   R•   RŸ   R¡   RR   (   RS   R}   R¶   t   ifapplyR¸   R¹   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   restore_colour_scheme…  s     'c         C   s=   | s |  j  j g } n  t ƒ  j d d d | d | ƒ } d  S(   NR~   R   R}   RT   (   R=   R•   RŸ   t   delete_info(   RS   R}   R¶   R®   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   remove_colour_scheme“  s     c         C   s   d d d d g j  |  j ƒ S(   NR   R   R   R
   (   RL   R   (   RS   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   colour_data_listableš  s    c   	      K   sQ  d d d d g j  |  j ƒ s. d d |  j g S|  j |  j j |  j ƒ d t j j t j j |  j	 j
 d ƒ d ƒ d	 } |  j |  j j |  j ƒ d
 |  j	 j
 d d } d d g j  |  j ƒ rë| |  j	 j j d	 ƒ } d } d } t d ƒ j d ƒ } t d ƒ j d ƒ } | rJ|  j	 j d | ƒ } | d	 sJ| d } qJn  | r|  j	 j d | ƒ } | d	 s| d } qn  | |  j	 j j d	 | | | | ƒ } | d	 k rÆ|  j	 j j | ƒ n  | d	 k rD|  j	 j j | ƒ qDnY |  j d k r|  j j ƒ  } n8 |  j d k r4| |  j	 j j ƒ  } n d d |  j g Sd	 | | g S(   NR   R   R   R
   i   s   No listing for t    i   i    s    for s   

iÿÿÿÿt   SASArea_paramt   list_selection_1t   list_selection_2t   command(   RL   R   Rž   R�   R‘   R£   R¤   t   splitextt   splitR=   t   filenamet   CSASAreat   Printt   PMR…   t   parse_selectionRO   t   DeleteSelectionR   t   list_colour_datat   PrintSecStructure(	   RS   R¨   t   titlet   textt   selHnd_1t   selHnd_2t   selection_1t   selection_2R«   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyRÎ   Ÿ  s:    N2
 
 %  c         C   sØ  |  j  s d Sd } t |  j ƒ d k r[ x$ |  j D] } |  j j j | ƒ q2 Wg  |  _ n  |  j d k rg  } t |  d ƒ r‹ |  j } nV t	 ƒ  j
 d |  j d d d d |  j d ƒ \ } } | rá | rá | |  j d } n  | r	|  j | ƒ |  j | ƒ |  _ q¨d } d	 |  _ n� |  j d
 k r¨|  j d |  j d d |  j d d |  j d d |  j d d |  j d d |  j d ƒ } | s–d |  _ q¨d	 |  _ d } n  |  j d k r]|  j rÌt j } n d } d d g j |  j ƒ rÒ|  j  d k rZ|  j j d d ƒ } | rO| d k r=t ƒ  j d |  j j ƒ n  d } d	 |  _ ne |  j j j t j d ƒ } |  j j j t j d ƒ }	 |  j j | |	 ƒ |  j |  j  j! |  j ƒ }
 |  j j" d |
 | ƒ } qZq]|  j |  j# k rr|  j# |  j |  ƒ } d |  _  t | d ƒ rW| j$ d ƒ rW| d rW| d |  _% y |  j& d ƒ Wn n Xd Sd } d	 |  _ d |  _' q]|  j d k r¡|  j  d k rZt |  d ƒ sÀt( d d  d! |  j j ƒ |  _) n  |  j) j* d" |  j+ j, ƒ  d# |  j- d$ |  j. ƒ |  j) j/ ƒ  } | d r|  j) j0 r|  j j |  j) j0 d |  j) j0 d ƒ |  j j" |  j  d t j1 t j2 g d% d& g j! |  j3 ƒ | ƒ } qžd' | d GHd } d	 |  _ qZq]d( g j |  j ƒ r	|  j j4 sä|  j j j5 d) ƒ d |  j _4 n  |  j j" |  j  d t j6 | ƒ } q]d	 d* d+ d, d- d. d/ g j |  j ƒ r…|  j7 d0 |  j d1 |  j ƒ } | sfd } d	 |  _ n  | \ } |  _ |  j | ƒ q]|  j d2 k rót8 ƒ  j! |  j9 ƒ } | d k rê|  j j: | ƒ |  j j" |  j  d t j; | ƒ } qZd } q]t< j  j |  j ƒ r]y? t< j t< j  j! |  j ƒ } |  j j" |  j  d | d ƒ } WqZd } qZXq]n  | r‘d	 |  _ d |  _' |  j j" d t j d ƒ n  |  j j= ƒ  |  j j> ƒ  |  _% d |  _  y |  j& d ƒ Wn n Xd S(3   Ni    R   R   R}   i   R~   R   RT   R   R   R+   R.   R/   R'   R)   R%   s   Blend through modeliÿÿÿÿR   R   i   t   reapplys   Error calculating SAS for t   residue_sasRg   t   successt   atom_colour_vectorR„   s	   Atom typeR   Ro   t   contactt   MolData_namet	   selectiont   contact_selectiont   contact_MolData_nameR!   R   s   ERROR calculating interface R   t   surface_potential_chargeR   R   R   R	   R
   R   R±   R   R   (?   R@   R‹   RE   R=   RO   RÍ   R   Rd   R   RŸ   R¡   R   t   apply_colour_rulest   colour_rules_legendR0   t   apply_colour_blendRF   R   RM   t
   BYATOMTYPERL   t   update_sasareat   MGGUIt   WarningMessageRo   t   GetUDDHandlet   mmdbt   UDR_ATOMt   UDR_RESIDUERN   t   SetUDDt   colour_codeR�   R‘   t   SetModeR™   Rg   R;   t   update_dependentsRA   R   R   R}   R>   R‡   R#   R$   t	   calculatet   contact_UDDt
   CONTACTRESt   CONTACTATOMR"   t   charge_loadedt
   LoadCharget   CHARGER³   R�   R   t   SetOneColourt	   ONECOLOURR   t   ReColourt   GetAtomColourVector(   RS   t   failedt   selR   R®   R   R«   t
   non_C_modet   udd_atomt   udd_rest   codet   RCt   rett   icR±   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   apply_colourÇ  sä    	  				 		(	!.'1%'	#			c   	   	   C   sÇ   d d  l  } d d  l } | j ƒ  } |  j d d d d ƒ} x„ | d D]x } t | d | j ƒ r | j | d ƒ \ } } n
 | d } | |  j | d t d t | ƒ ƒ !| d d d ƒ} qG W| S(   Niÿÿÿÿs   User colour rulesR   R|   i   i    i   (	   RV   RW   RZ   R’   RX   RY   R[   t   minR‹   (	   RS   R   RV   RW   R]   t   legendR_   R«   t   com(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyRá   g  s    
:c         C   sµ  d d l  } d d l } g  } xÅ | d D]¹ } | d r) t | d | j ƒ rq |  j j d | d ƒ \ } } n |  j j d | d ƒ \ } } | r¦ d G| d GHqâ |  j j | ƒ d d l } | j | j	 j
 | d ƒ ƒ q) q) Wt |  j ƒ }	 | j |	 ƒ }
 | j |	 ƒ } d } x% |  j D] } | d } | |
 | <q#Wd } x" | D] } | d } | | | <qNW|  j j d d d ƒ } |  j j |	 t ƒ  j | d d ƒ |
 | ƒ d S(   s.   
    Apply a selection based colour rules
    iÿÿÿÿNi   R¹   RÅ   s   ERROR parsing i    (   t
   pygl_coordRV   RX   RY   R=   RÌ   RE   R\   t   cprimt   RGBRepst   GetColourNumberR‹   t   intaRN   Rí   t	   SetSchemeR�   R‘   (   RS   R   R  RV   R.   R_   R®   Rû   R  t   nrulest   ptr_selHndst
   ptr_colourR¬   Rh   R   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyRà   v  s4    
"$

#t
   amino_acidc         C   s¡  d d l  } d d g j | ƒ rT |  j j d d | g ƒ \ } }	 | rZ d }	 qZ n d }	 t ƒ  j | ƒ g }
 d g } | j g } x¨t d t	 t
 | ƒ t
 | ƒ ƒ ƒ D]‚} d } | | r"|  j j d | | d d	 ƒ } | d r"| d	 d k r"|  j j d | | ƒ } | d	 } q"n  | d k r© |  j j | ƒ | j | ƒ |  j d
 | d k ru| j | j ƒ n | j | j ƒ |
 j t ƒ  j | | d ƒ ƒ x‚ | | d	 D]o } | rµ|
 j t ƒ  j | ƒ ƒ | j d ƒ |  j d
 | d k r| j | j ƒ q$| j | j ƒ qµqµWq© q© W|	 rK|  j j j |	 ƒ n  t
 | ƒ d	 k rad	 S|
 j t ƒ  j | ƒ ƒ | j d ƒ t
 | ƒ } d d l } | j | ƒ } | j | ƒ } d } x" | D] } | d	 } | | | <qÊWd } x" |
 D] } | d	 } | | | <qõW|  j j | ƒ rA|  j |  j j | ƒ } n	 t j } |  j j | ƒ |  j j | t ƒ  j | ƒ | | | ƒ |  j j d	 t j d ƒ } d S(   sV   
    Apply a selection based colour rules - logically part of apply_colour method
    iÿÿÿÿNR  R4   R¹   i    RÅ   t   testi   R/   Ry   (   t	   atom_utilRL   R=   RÌ   R:   R�   R‘   t   COLOUR_WHEEL_CLOCKRŠ   R  R‹   RE   R\   RF   t   COLOUR_WHEEL_ANTICLOCKRO   RÍ   R  R  t   blend_group_menut   blend_group_codeRM   t   BLEND_RESIDUERN   t   SetColourWheelDirectionR  Rí   t	   BLENDTHRU(   RS   R'   R+   R.   R/   R%   R)   R  R®   t   sel_typet   colst   selHndsR¬   Rû   R«   Rh   R  R  R  R  t
   group_codeR   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyRâ   £  sp    ! 	+
!  

	c   	      C   s*  | r d } n  | rÈ|  j  r@ |  j  | k r@ |  j d | ƒ q&|  j d k r6|  j d r6t |  j d d ƒ } xOt d t |  j d ƒ ƒ D]Ÿ } x– t d | ƒ D]… } |  j d | | | k r¦ t |  j g  i d t | d ƒ d t | d ƒ d	 6| d t | d ƒ d t | d ƒ 6ƒ q¦ q¦ Wq� Wq&|  j d
 k r&t	 |  d ƒ sXd  Sxj t d t |  j
 ƒ ƒ D]M } |  j
 | d | k rqy# |  j t | ƒ ƒ j d | ƒ Wq¾q¾XqqqqWq&n^ d |  _ d d d d d d d d d g	 j |  j ƒ r&|  j j d ƒ t d |  j ƒ |  _ n  d  S(   NR²   R   R   R.   i    R„   i   t   _t   widgetR   R   R   R   R   R   R   R   Rm   Rn   R   (   R   RR   R   RF   R‹   RŠ   t   applyt   set_colour_blendt   strRd   R   t   user_colour_instst   do_updatedisplayRL   RN   Rí   R�   R@   (	   RS   Ro   t   standardt   renamet   deletet   jmaxR¬   t   jRª   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   handle_colour_changeù  s6    		#'9 #	c         K   s   d |  _  d  S(   Ni   (   R@   (   RS   t   masterR¨   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   update_contact+  s    c   *   	   C   sS  t  j j | ƒ rG t  j t  j j | ƒ } d |  j | d d ƒ } n d } | } | ru d d i d d 6g g } n d d" d g i d d 6g g } d } | d k r|  j j }	 t	 t
 ƒ  d	 ƒ sÒ t
 ƒ  j rÛ d
 } n  t |	 ƒ d k rùxð t d t |	 ƒ ƒ D]Ù }
 t
 ƒ  j | d d d d d d g ƒ} |	 |
 } | sM| d } n  | r‰| j | d | i d d 6d |	 |
 g d 6g ƒ n9 | j | d" d | g i d d 6d |	 |
 g d 6g ƒ | |  j |	 |
 | ƒ } qW| |  j d d ƒ } n  |  j j } t | ƒ d k ryxõ t d t | ƒ ƒ D]Û }
 t
 ƒ  j | d d d d d d g ƒ} | rž| j | d | |
 d i d d 6d | |
 g d 6g ƒ nP | j | d d" d g d" d | |
 d g g i d d 6d | |
 g d 6g ƒ | |  j | |
 | ƒ } q-Wqyng	| d k r1d } |  j j } | r?| } n d } xæ t |  j j | d ƒ D]Ë } t
 ƒ  j | d d d d d g ƒ} d t | ƒ d } | r×| j | | i d d 6d t | ƒ g d 6g ƒ n7 | j | d" | g i d d 6d t | ƒ g d 6g ƒ | |  j t | ƒ | ƒ } q_W|  j j j ƒ  } | ry|  j j j ƒ  } d } xÍ | D]Â } | d } | t | ƒ k  r”| | } n d } | rÊ| j | | i d d 6| g d 6g ƒ n- | j | d" | g i d d 6| g d 6g ƒ | |  j t | ƒ | ƒ } | d } | d } qeWqynH| d  k rad! d" l } d! d" l } | j d  ƒ } | sng  S| j ƒ  \ } } } | j d# ƒ r¾| j d# ƒ } | j | ƒ | j | ƒ n  g  } g  } x€ t d t | ƒ ƒ D]i } | j | | ƒ r$| j | | ƒ } | | j | | ƒ qà| j | | ƒ | j | | g ƒ qàWx)t d t | ƒ ƒ D]÷ } | j | | d ƒ }  t | | ƒ d k rÉx0 | | d D] }! |  d$ | j |! ƒ }  q¥Wn  | r| j | | d% |  d& i d' d 6| | d' 6g ƒ n: | j | | d" d% |  d& g i d' d 6| | d' 6g ƒ | |  j |  | | ƒ } qcWn| d( k r¶	|  j j j d) ƒ rôt	 t
 ƒ  d	 ƒ rJt
 ƒ  j rJ| rÜ| j d d* i d* d 6g d+ d, i d, d 6g g ƒ n? | j d d" d* g i d* d 6g d+ d" d, g i d, d 6g g ƒ | |  j d- d ƒ } | |  j d. d+ ƒ } q³	| r†| j d/ d* i d* d 6g d0 d, i d, d 6g g ƒ n? | j d/ d" d* g i d* d 6g d0 d" d, g i d, d 6g g ƒ | |  j d- d/ ƒ } | |  j d. d0 ƒ } qy|  j j j d1 ƒ ry| rE	| j d/ d2 i d2 d 6g d0 d3 i d3 d 6g g ƒ n? | j d/ d" d2 g i d2 d 6g d0 d" d3 g i d3 d 6g g ƒ | |  j d2 d/ ƒ } | |  j d3 d0 ƒ } qynÃ| d4 k r	d! d" l } d! d" l }" | j d4 ƒ } | só	g  S| j ƒ  }# xwt |# d ƒ D]ò } | t |" j j  ƒ k  r
| t |" j j! ƒ k  r
|" j j  | }$ |" j j! | }% | r¥
| j |# d5 | d6 |$ i d d 6|$ g d4 6g g ƒ n< | j |# d5 | d" d6 |$ g i d d 6|$ g d4 6g g ƒ | |  j |% |# d5 | ƒ } q
q
Wnp| d7 k rd+ d8 d/ d9 g }& xOt d t |  j j" ƒ ƒ D]Å } | r˜| j |& | d: |  j j" | i d d 6|  j j" | g d; 6g g ƒ nL | j |& | d" d: |  j j" | g i d d 6|  j j" | g d; 6g g ƒ | |  j |  j j" | |& | ƒ } qCWnj t
 ƒ  j# | d< d ƒd k ry| rS| j | d i d d 6g ƒ qy| j | d" d g i d d 6g ƒ n  | d= k s‹| rEd! d" l } d! d" l } | j d= ƒ } | s¼g  S| j ƒ  \ } }' } |' j d# ƒ r|' j d# ƒ } |' j | ƒ | j | ƒ n  | d= k rS|' j d> ƒ rS|' j d> ƒ } |' j | ƒ | j | ƒ n  t |  j j" ƒ rnd? }( n d }( xÎ t d t |' ƒ ƒ D]´ } |' | j d@ ƒ }) | rã| j | | dA |) dB |( i dC d 6|) g dC 6g ƒ n= | j | | d" dD |) dB |( g i dC d 6|) g dC 6g ƒ | |  j |) dE | | ƒ } qŠWn  | | dF g S(G   sQ   
    Generate the rules for standard colouring schemes applied to this model
    s   <p>R   i   R²   R(   t   selectt   yellowR   t   usingOldColoursRz   i    t   excludet   blackR&   R-   R,   t   greens    /*s   //R  t   chainss   Not peptides   nucleic and //s   /*.*/*:*R4   t   strandst   andR   t   /s
   /*/*,*/*:*t
   nmr_modelsR   iÿÿÿÿNR    t   ,t   (t   )t   restypesR	   R2   t   maint   cyant   sides
   main chains
   side chaint   lemons   ice blueR3   t   backbonet   basesR
   i   s   SEC == R   t   pinkt   tans   /*/*/*.*/*:t   alt_locst   safeR   s    Cs   :*s   [] t   [t   ]t   elementtypess   /*/*/*,*/*[RÁ   s   </p>($   R   R�   RL   Rž   R‘   R’   R:   R=   t   peptidesRd   R�   R/  R‹   RŠ   t   nextR\   t   nucleicsR7  t   first_nmr_modelR"  t   model_symmetryt   get_symmetry_modelst   get_symmetry_coloursRP   t   stringt   colourschememanagert   GetColourSchemet   popt   stripRK   t   extendt   modelt   secstr_aliast   secstr_menuRD  t   colour_index(*   RS   R±   R   R°   t   legend_titleR  t   ifcomR   Rh   RI  t   nRû   RK  R7  t   n_modelst   mt   selet   symmetry_modelst   symmetry_colourst   nnR„   RP   RP  t   colobjt   ntypet   typelistt   collistRª   t   tyt   clR¬   R)  t   resRa   RV  R¯   R­   Ro   t   alt_loc_colt   elelistt   altt   ele(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR³   2  sŒ    	
 	
	
	&	$#$	 	(		% 
			
     0!("+$(+ & 	%c         C   sC   d } d } d } | | | | d | } | r? | d } n  | S(   Ns   <span style="color:s   ;">s   </span>
RÁ   s   </p><p>(    (   RS   RÑ   R„   R|   t
   open_span0t
   open_span1t
   close_span(    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR’   D  s     c         C   s   d |  j  d } d G| GH| S(   NsI  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" />
<style type="text/css">
p { white-space: pre-wrap; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;}
</style>
</head><body><p>s   </p></body></html>s   model_colour.getLegend(   R0   (   RS   R  (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt	   getLegendN  s    	(;   t   __name__t
   __module__Rž   R�   R¢   R™   Rš   RM   R÷   Rã   t	   BYRESTYPEt   BYCHAINt   MAINSIDEt   SECSTRR  t   BVALUEt	   OCCUPANCYt   ALTLOCRõ   t   USER_SCHEMEt   SASRESt   SASATOMRñ   Rò   t
   THRU_CHAINt   BYMODELRì   R  R  t   BLEND_SECSTRR  RG   RJ   Rc   R‰   R:   R8   Rb   R5   Ri   Rj   Rl   RR   R´   Rº   R»   R½   R¿   RÀ   RÎ   R  Rá   Rà   Râ   R*  R,  R³   R’   Rq  (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR      sŽ   			*


		'	 				¥	
			(	 -T2ÿ 
R   c           B   sM   e  Z d  d  d  d  d  d „ Z d „  Z d d d  d „ Z d „  Z d „  Z RS(   R   c         C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ g  |  _ d  S(   N(   Ro   RÛ   RÜ   RÞ   RÝ   Rð   (   RS   Ro   RÛ   RÜ   RÞ   RÝ   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR8   ^  s    					c         C   s   d  S(   N(    (   RS   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR'  h  s    t   XXXc         C   sF   | d k r | |  _  n  | d k r0 | |  _ n  | rB | |  _ n  d  S(   NR�  (   RÝ   RÜ   RÞ   (   RS   RÝ   RÜ   RÞ   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR}   n  s    c         K   s¬  d } d } t  d |  j ƒ } | s5 d d |  j g S| d } | d j } |  j r˜ t  d |  j ƒ } | s~ d d |  j g S| d } | d j } n | } | } | | k r�|  j rÎ |  j rÎ d d g S|  j ss| j d |  j ƒ }	 |	 d rd d |  j g S|	 d } | j ƒ  } | j | d d	 t	 j
 d	 t	 j
 d	 d	 d	 d	 d	 t	 j ƒ | j | t	 j | t	 j ƒ q-|  j s| j d |  j ƒ }	 |	 d r¬d d |  j g S|	 d } | j ƒ  } | j | d d	 t	 j
 d	 t	 j
 d	 d	 d	 d	 d	 t	 j ƒ | j | t	 j | t	 j ƒ q-| j d |  j ƒ }	 |	 d rHd d |  j g S|	 d } | j d |  j ƒ }	 |	 d r‚d d |  j g S|	 d } nž |  j s¤d
 |  _ n  | j d |  j ƒ }	 |	 d rÔd d |  j g S|	 d } |  j sód
 |  _ n  | j d |  j ƒ }	 |	 d r#d d |  j g S|	 d } | j | ƒ d k  rRd d |  j g S| j | ƒ d k  rwd d |  j g S|  j sÊ| j t	 j d |  j ƒ }
 | j t	 j d |  j ƒ } |
 | g |  _ n  t |  d ƒ s$d d  l } | j | | | | ƒ |  _ |  j j |  j d |  j d ƒ n& |  j j d | | ƒ |  j j | ƒ |  j j ƒ  }	 | d k ru| j | ƒ n  | d k r‘| j | ƒ n  |	 r¡d d g Sd g Sd  S(   NiÿÿÿÿRo   i   s   Invalid model i    s   No atom selectionRÅ   s   Invalid selection R    R(   s   No atoms selected for t   atom_contactt   residue_contactt   contact_CSASAreas   Error in calculation(   t   get_dataobjRÛ   RO   RÞ   RÜ   RÝ   RÌ   t   NewSelectiont   SelectAtomsRè   t   ANY_RESt   SKEY_NEWt   Selectt
   STYPE_ATOMt   SKEY_XORt   nAtomsRð   t   RegisterUDRealRé   Ro   Rê   Rd   t   mmutRÉ   R„  Rë   t   SetSelHandlet   Calculate_ContactRÍ   (   RS   R¨   t   selHndt   contact_selHndt   objR=   RO   t   contact_MolDatat   contact_molHndR«   Rý   Rþ   R�  (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyRï   x  sœ     
	 

	
 
!	
 
!
 

 	
 
	
 
	$  
c         C   s8   |  j  s d Sd |  j d } | |  j  j d ƒ } | S(   NR   s   
Interface to s   
i    (   R„  RÝ   RÊ   (   RS   RÑ   (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyRÎ   à  s
    	(   Rr  Rs  R8   R'  R}   Rï   RÎ   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyR   [  s
   
	
	h(   t   __doc__R£   R6   t   mmdb2Rè   RM   R�  t	   resourcesR›   RP   t   global_definitionsR7   R   R   (    (    (    sC   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/python/ui/model_colour.pyt   <module>   s   $
ÿ ÿ ÿ ÿ A