ó
Ñ%�Tc           @   s  d  Z  d d l Z d d l Z d d l m Z d d l Z d d l m Z d d l m	 Z	 m
 Z
 m Z m Z m Z m Z d d l m Z m Z d d l m Z m Z d d l m Z m Z m Z m Z m Z d d	 l m Z d
 Z d Z e j Z d d d „  ƒ  YZ d S(   sL   A class for the graphical interface used to review the predicted conformers.iÿÿÿÿN(   t   deepcopy(   t   sleep(   t   set_rotation_centret   add_atom_labelt   remove_atom_labelt   graphics_drawt   close_generic_objectt   set_display_generic_object(   t   puckerListFullNamet
   puckerList(   t
   calcCoordst   recalcCoords(   t   buttonWithIcont   HBOX_SPACINGt   VBOX_SPACINGt   BUTTON_SPACINGt   createRCraneWindowObject(   t   determineAlternateConft   pinkt	   palegreent   ReviewSuitesGuic           B   sì   e  Z d  Z d e d e d d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   sL   A class for the graphical interface used to review the predicted conformers.c         C   sæ   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ | |  _ |
 |  _	 | |  _
 | |  _ t | ƒ |  _ d |  _ t |  j ƒ d |  _ d |  _ | j d j d ƒ rÅ d |  _ n	 d |  _ |  j ƒ  |  j ƒ  d S(   sç
  Initialize a ReviewSuitesGui object and create a GUI for reviewing the predicted suites
        
        ARGUMENTS:
            predictedProbs       - the probabilities for each rotamer calculated for each suite
                                   formatted as a list of suites, where each suite is represented as a dictionary of rotamer => probability
            bestPath             - a list of the most likely rotamers for each suite
                                   This is typically calculed by rotamerSeq using an HMM, so it may differ slightly from simply taking all the maxima from predictedProbs
            pseudoMol            - a PseudoMolecule object for the built molecule
            origCoords           - a copy of the coordinates contained in pseudoMol as a Chain object
            intermediateAtomLocs - phosphate, O3', and C3' coordinates for each nucleotide immediately before minimization of that nucleotide was started
            minimizationScores   - the minimization scores for each nucleotide
        OPTIONAL ARGUMENTS:
            window               - a window to put the GUI into
                                   If not provided, a new window will be created.
            useResNums           - whether or not to display the rotamer numbers (as opposed to just the indices) in the GUI
                                   Defaults to True
            oldCoordsObj         - a Coot generic object for drawing the coordinates we are potentially replacing when running rotamerize
                                   If not provided, then the toggle checkbox will not be displayed and the generic object will not
                                   be destroyed when closing the window.
            ignoreDensity        - ignore the density when performing the minimization
                                   defaults to False
            prevTorsions         - the pre-rotamerize torsions for the suite before the start of origCoords.  These torsions will be used
                                   as restraints when rebuilding the first suite
                                   defaults to None
            nextTorsions         - the pre-rotamerize torsions for the suite after the end of origCoords.  These torsions will be used
                                   as restraints when rebuilding the first suite
                                   defaults to None
        RETURNS:
            an initialized ReviewSuitesGui object
        EFFECTS:
            Displays an RCrane dialog box for reviewing the predicted suites
        NOTE:
            If the pseudoMol object has savedCoordinates, then an an "Accept New Coordinates" and a "Restore Original Coordinates" will be displayed.
            Otherwise, only a "Done" button will be displayed
        i   i   i    s   C1'N(   t    _ReviewSuitesGui__predictedProbst   _ReviewSuitesGui__bestPatht    _ReviewSuitesGui__pseudoMoleculet   _ReviewSuitesGui__origCoordst&   _ReviewSuitesGui__intermediateAtomLocst   _ReviewSuitesGui__windowt   _ReviewSuitesGui__useResNumst   _ReviewSuitesGui__oldCoordsObjt$   _ReviewSuitesGui__minimizationScorest   _ReviewSuitesGui__ignoreDensityt   _ReviewSuitesGui__prevTorsionst   _ReviewSuitesGui__nextTorsionsR    t   _ReviewSuitesGui__curPatht   _ReviewSuitesGui__curSuitet   lent   _ReviewSuitesGui__numNucst   Nonet*   _ReviewSuitesGui__treeViewChangedHandlerIDt   nucst   hasAtomt   _ReviewSuitesGui__skipFirstNuct   _ReviewSuitesGui__clearCachet   _ReviewSuitesGui__reviewSuites(   t   selft   predictedProbst   bestPatht	   pseudoMolt
   origCoordst   intermediateAtomLocst   minimizationScorest   windowt
   useResNumst   oldCoordsObjt   ignoreDensityt   prevTorsionst   nextTorsions(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __init__*   s*    %															
	c   #      C   sÞ  |  j  d k r t ƒ  |  _  nS |  j  d k	 rq |  j  j ƒ  } | d k	 r[ |  j  j | ƒ n  |  j  j d d ƒ n  |  j  j d |  j ƒ t d d ƒ } t d d ƒ } t d d ƒ } t d	 d
 ƒ } |  j	 j
 ƒ  ró t d d ƒ } t d d ƒ } n t d d ƒ } |  j j d |  j j } |  j rGd t | ƒ t |  j ƒ f }	 n d t |  j ƒ }	 t j |	 ƒ }
 |  j d ƒ \ } } |  j | | ƒ \ } } } t |  j ƒ d k rÃ|  j | |
 ƒ } n d } | j d |  j | ƒ |  _ |  j | | ƒ \ } } t |  j ƒ d k r/|  j | | | ƒ \ } } n  | j d |  j | ƒ | j d |  j | ƒ t |  j ƒ d k r«| j d |  j | |
 | ƒ | j d |  j  | |
 | ƒ n  | j d |  j! ƒ |  j	 j
 ƒ  rã| j d |  j" ƒ n  t j# t$ t% ƒ } t |  j ƒ d k rgt j d ƒ } t j& t' d ƒ } | j( | t' | d ƒ | j) | ƒ | j( | t$ t' t* ƒ n  t j& t$ t+ ƒ } t j# t$ t% ƒ } |
 j) | ƒ | j( | t' t' t* ƒ | j( |
 t' t' t* ƒ t j# t' t% ƒ } t j, d d d d ƒ } | j) | ƒ | j( | t$ t$ t* ƒ | j( | t' t' t* ƒ | j( | t' t' t* ƒ |  j- d k	 r³t j. d ƒ } | j/ t' ƒ | j d |  j0 ƒ t j, d d ƒ } | j) | ƒ | j( | t' t' t* ƒ n  | j( | t' t$ t* ƒ t |  j ƒ d k r|t j& t' t+ ƒ } t j, d d ƒ } | j) | ƒ | j( | t' t' t* ƒ | j( | t' t' t* ƒ |  j	 j
 ƒ  rc| j( | t$ t$ t* ƒ q|| j( | t$ t$ t* ƒ n  |  j	 j
 ƒ  rt j& t' t+ ƒ }  t j, d d ƒ }! |! j) |  ƒ | j( |! t$ t$ t* ƒ |  j( | t' t' t* ƒ |  j( | t' t' t* ƒ n5 t j, d d ƒ }! |! j) | ƒ | j( |! t$ t$ t* ƒ |  j1 d |  _2 |  j	 j3 | ƒ }" t4 |" Œ  t5 |  j	 j6 ƒ  |  j	 j7 t8 | ƒ d ƒ t9 ƒ  |  j  j) | ƒ |  j  j: ƒ  t |  j ƒ d k rÐ| j; ƒ  n
 | j; ƒ  d S(   sÒ   Create the review suites GUI
        
        ARGUMENTS:
            None
        RETURNS:
            None
        EFFECTS:
            Displays an RCrane dialog box for reviewing the predicted suites
        i   t   delete_events     Previous Conformer  s	   gtk-go-ups     Next Conformer  s   gtk-go-downs     Previous Suite  s   gtk-media-previouss     Next Suite  s   gtk-media-nexts     Accept New Coordinates  s   gtk-oks      Restore Original Coordinates  s
   gtk-cancels     Done  s   Suite %s (1 of %i)s   Suite 1 of %it   changedt   clickedt   Overviewi    t   xaligng      à?t   yaligns   Display old coordinatest   toggleds    P  N(<   R   R%   R   t	   get_childt   removet   resizet   connectt   _ReviewSuitesGui__closeWinR   R   t   hasSavedCoordinatesR   R'   R)   t   resNumR   t   strR#   R   t   gtkt   Framet%   _ReviewSuitesGui__createConfListStoret$   _ReviewSuitesGui__createConfTreeViewR   t(   _ReviewSuitesGui__createOverviewTreeViewt   _ReviewSuitesGui__changedR&   t*   _ReviewSuitesGui__createConfScrolledWindowt.   _ReviewSuitesGui__createOverviewScrolledWindowt   _ReviewSuitesGui__prevConft   _ReviewSuitesGui__nextConft   _ReviewSuitesGui__prevSuitet   _ReviewSuitesGui__nextSuitet   _ReviewSuitesGui__acceptt"   _ReviewSuitesGui__restoreOldCoordst   VBoxt   FalseR   t   HBoxt   Truet
   pack_startt   addR   R   t	   AlignmentR   t   CheckButtont
   set_activet!   _ReviewSuitesGui__toggleOldCoordsR!   t   _ReviewSuitesGui__selectedConft   getPhosCoordsR   R   t   molNumt   chaint   intR   t   show_allt
   grab_focus(#   R,   t   windowChildt   prevConfButtont   nextConfButtont   prevSuiteButtont   nextSuiteButtont
   doneButtont   cancelButtont   suiteNumt
   frameTitlet
   suiteFramet   confListStoret   initialConfNumt   confTreeViewt   confTreeSelectiont	   rowHeightt   overviewTreeViewt   treeViewScrollt   treeViewScrollWidtht   overviewScrollt   wideOverviewt	   windowBoxt   overviewFramet   overviewBoxt   suiteFrameHBoxt   suiteFrameVBoxt   prevNextConfBoxt   prevNextConfAlignmentt   oldCoordsCheckButtont   oldCoordsAlignmentt   prevNextSuiteBoxt   prevNextSuiteAlignmentt   doneBoxt   doneAlignmentt	   firstPhos(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __reviewSuitesw   sº    	"
(c         C   så  |  j  |  j d } | d k r/ d } t } n t } |  j  |  j d } |  j j | j } |  j j | j } |  j } | d k rž |  j j | d j }	 n | }	 |  j j	 | ƒ sÕ |  j
 j |	 | ƒ |  j | <n  | j ƒ  \ }
 } |
 j | d ƒ } d | GH| |  _ | rÂt | d t | d k rÂ| d k o?|  j rÂ|  j j | d j } | d k r€|  j j | d j } n  |  j j	 t | d ƒ sÁ|  j
 j | | ƒ |  j t | d <n  |  j j	 t | d ƒ r	|  j
 j | | |  j t | d ƒ t } n t | d } t |  j ƒ d k rD|  j t | d } q	|  j |  j  d |  j t | d <t |  j |  j  d d } t | t | d |  j  d |  j ƒ } | |  j t | d <nG t } |  j  d k rî|  j |  j  d } n |  j r|  j } n d } | |  j d |  j k r�t |  j t ƒ rP|  j
 j | | ƒ |  _ n |  j
 j | | |  j ƒ t } |  j r„|  j } q½d } n0t | d t | d k rö|  j j | d j } |  j j	 t | d ƒ s|  j
 j | | ƒ |  j t | d <n  |  j j	 t | d ƒ rI|  j
 j | | |  j t | d ƒ t } n t | d } t |  j ƒ d k r„|  j t | d } q½|  j |  j  |  j t | d <t |  j |  j  d } t t | d | |  j  |  j ƒ } | |  j t | d <nÇ |  j j | d j } |  j j	 t | d ƒ rO|  j
 j | | |  j t | d ƒ n$ |  j
 j | | ƒ |  j t | d <t } |  j  |  j d k  r¢|  j |  j  } n |  j r·|  j } n d } |  j j	 | ƒ rü|  j
 j |	 | |  j | ƒ |  j
 j ƒ  nh| | | g } |  j  |  j d } |  j  |  j } | r`| j d |  j |  j  d ƒ | d 8} n  | r¸| |  j d |  j k  rž| j  |  j |  j  d ƒ n | j  d ƒ | d 7} n  |  j j | j } |  j j | j } |  j
 j! | | |  j |  j" ƒ |  j
 j# ƒ  t$ | | | |  j |  j
 |  j% |  j& ƒ |  j
 j ƒ  |  j
 j' ƒ  rd|  j
 j( | | ƒ n  | d k	 rá|  j) | |  j  | ƒ t | t* ƒ r²|  j) | |  j  d | ƒ n  t | t* ƒ rá|  j) | |  j  d | ƒ qán  d S(   sJ  Respond to the user selecting a different rotamer
        
        ARGUMENTS:
            confTreeSeletion - the TreeSelection object for the conformer TreeView
        RETURNS:
            None
        EFFECTS:
            Recalculates and reminimizes coordinates using the newly selected conformer for the current suite
        i   i    i   s   Conformer %s was selectedi   N(+   R"   R)   RX   RZ   R   R'   RG   Ra   t    _ReviewSuitesGui__structureCachet   has_keyR   t   getCootNucst   get_selectedt	   get_valueR	   R   t.   _ReviewSuitesGui__startingPuckerStructureCachet   setCootNucsR#   t#   _ReviewSuitesGui__previousSuiteConfR!   R   R   R%   R$   t
   isinstancet,   _ReviewSuitesGui__endingPuckerStructureCachet   dictR    t   _ReviewSuitesGui__nextSuiteConft   drawExtraBondst   insertt   appendt	   resetNucsR   t   clearExtraBondsR   R   R   t   hasSavedBfacst   restoreSavedBfacst)   _ReviewSuitesGui__changeOverviewConformert
   basestring(   R,   Ru   Rw   t   startingNucIndext   hasPrevSuitet   endingNucIndext   startingNucNumt   endingNucNumt   previousConft   cacheStartingNucNumRr   t   selectedConfItert   selectedConft   preStartingNucNumt   changingStartingPuckert   previousSuiteConft   previousSuiteLeadingPuckert   changingEndingPuckert   nextSuiteConft   postEndingNucNumt   nextSuiteEndingPuckert   rotListt   minimizationStartingNucIndext   minimizationEndingNucIndext   minimizationStartingNucNumt   minimizationEndingNucNum(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt	   __changed  sÈ    				8'%	#'	
		'%	#($	
(c         C   su   | j  ƒ  \ } } | j | ƒ d } | d k rq | j | d ƒ } | j | ƒ | j ƒ  } | j | d ƒ n  d S(   s†  Respond to the user clicking on the previous conformer button
        
        ARGUMENTS:
            widget           - the button used to invoke this function
            confTreeSeletion - the TreeSelection object for the conformer TreeView
        RETURNS:
            None
        EFFECTS:
            Highlights the previous conformer (which will implicitly invoke __changed)
        i    i   N(   RŽ   t   get_patht   get_itert   select_itert   get_tree_viewt   scroll_to_cell(   R,   t   widgetRu   Rr   R§   t   curPost   newIterRt   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt
   __prevConf  s    c         C   sc   | j  ƒ  \ } } | j | ƒ } | d k	 r_ | j | ƒ | j ƒ  } | j | j | ƒ ƒ n  d S(   s~  Respond to the user clicking on the next conformer button
        
        ARGUMENTS:
            widget           - the button used to invoke this function
            confTreeSeletion - the TreeSelection object for the conformer TreeView
        RETURNS:
            None
        EFFECTS:
            Highlights the next conformer (which will implicitly invoke __changed)
        N(   RŽ   t	   iter_nextR%   R¹   Rº   R»   R·   (   R,   R¼   Ru   Rr   R§   R¾   Rt   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt
   __nextConf$  s    c   
   	   C   s  | d 8} t  j t t t t d d d t ƒ } |  j | j ƒ  } | j d d „  d t ƒ t |  j	 | \ } } d } x– | D]Ž \ } } | j
 | d | g t | t | d | k t | d | k | |  j	 | k | d g ƒ | |  j | k r| }	 n  | d 7} q~ W| |	 f S(   s`  Creates a ListStore containing data about the specified suite
        
        ARGUMENTS:
            curSuite - the suite to create a ListStore for
        RETURNS:
            confListStore  - a ListStore containing data about curSuite
            initialConfNum - the most likely suite (i.e. the row of confListStore to initially highlight)
        i   t   gbooleant   keyc         S   s   |  d S(   Ni   (    (   t   x(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   <lambda>H  s    t   reversei    s   %4.2f(   RI   t	   ListStoreRH   Re   R   t   itemst   sortRZ   R	   R   R™   R   R!   (
   R,   t   curSuiteRr   t   conformerListt   defaultLeadingPuckert   defaultEndingPuckert   it   conft   scoreRs   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __createConfListStore9  s    

$\ 	c         C   s(  t  j | ƒ } | j t ƒ t  j ƒ  } | j d d ƒ | j d |  j j ƒ  j t  j	 ƒ t  j
 d | d d ƒ} | j | ƒ t  j ƒ  } | j d d ƒ | j d t ƒ t  j
 d | d d	 d
 d ƒ} | j | ƒ t  j ƒ  } | j d d ƒ | j d t ƒ t  j
 d | d d d
 d ƒ}	 | j |	 ƒ t  j ƒ  }
 |
 j d d ƒ t  j
 d |
 d d ƒ} | j |
 |  j d ƒ | j | ƒ t  j ƒ  } | j d d ƒ t  j
 d | d d ƒ} | j | |  j d ƒ | j | ƒ | j ƒ  } | j | j | ƒ ƒ | j ƒ  d | j d ƒ } | | | f S(   sB  Create the TreeView object for the list of conformers
        
        ARGUMENTS:
            confListStore     - the ListStore object to attach to the TreeView
            initialConfNum    - the most likely suite (i.e. the row of confListStore to initially highlight)
        RETURNS:
            confTreeView      - the newly created TreeView object
            confTreeSelection - the TreeSelection object associated with the TreeView
            rowHeight         - the height of a single row in the TreeView (used to determine how high to size the ScrolledWindow)
        R>   g      à?s   cell-background-gdkt   Rankt   texti   s   cell-backgroundt	   Conformeri    t   cell_background_seti   t   Scorei   s   Leading Puckeri   i   s   Ending Puckeri   i   s   vertical-separator(   i   i   (   i   i   (   RI   t   TreeViewt   set_enable_searchRX   t   CellRendererTextt   set_propertyR   t	   get_stylet   bgt   STATE_NORMALt   TreeViewColumnt   append_columnt   BEST_PATH_COLORt   set_cell_data_funct   _ReviewSuitesGui__setPuckerBgt   get_selectionR¹   R¸   t   cell_get_sizet   style_get_property(   R,   Rr   Rs   Rt   t
   renderRankt
   columnRankt
   renderConft
   columnConft   renderScoret   columnScoret   renderLeadingPuckert   columnLeadingPuckert   renderEndingPuckert   columnEndingPuckerRu   Rv   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __createConfTreeViewS  s>    #c   
      C   sð   t  j ƒ  } | j t  j t  j ƒ | j t  j ƒ | j | ƒ | j ƒ  \ } } y | j	 ƒ  j ƒ  d } Wn' t
 k
 r” t  j ƒ  j ƒ  d } n X| j d ƒ } | t t ƒ | } | | | d }	 | j |	 | | d d ƒ | |	 f S(   sÚ  Create a ScrolledWindow object to display the conformer TreeView
        ARGUMENTS:
            confTreeView        - the TreeView object used to display the list of conformers
            rowHeight           - the height of a row in confTreeView
        RETURNS:
            treeViewScroll      - the newly created ScrolledWindow object
            treeViewScrollWidth - the width of treeViewScroll (used to figure out how wide to make the overview ScrolledWindow)
        i    s   scrollbar-spacingi   i   (   RI   t   ScrolledWindowt
   set_policyt   POLICY_NEVERt   POLICY_AUTOMATICt   set_shadow_typet   SHADOW_ETCHED_INR\   t   size_requestt   get_vscrollbart   AttributeErrort
   VScrollbarRå   R#   R	   t   set_size_request(
   R,   Rt   Rv   Rx   t   tableWidthReqt   tableHeightReqt   vScrollWidthReqt   scrollbarSpacingt   headerHeightRy   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __createConfScrolledWindow‹  s    
c         C   s<  t  g t |  j ƒ } t j | Œ  } |  j j ƒ  d |  j d !} | j | ƒ | j g  |  j D] } | j	 d d ƒ ^ q_ ƒ t
 g  | D] } t | ƒ ^ qˆ d g ƒ } t j | ƒ }	 |	 j t ƒ |	 j t ƒ |	 j ƒ  j t j ƒ y |	 j t j ƒ Wn t k
 rn Xt |  j ƒ }
 xüt |  j ƒ D]ë\ } } t j ƒ  } | j d d ƒ | j d | d ƒ | d	 k r‹| j d
 t ƒ n  t |  j | j ƒ  d t ƒd	 d !\ } } y | | } Wn t k
 rät d ƒ } n X| d	 k rt
 |  j d	 |  j d ƒ } n |  j | d } | d k s:| d k rM| j d d ƒ nV | d k se| d k rx| j d d ƒ n+ | d k s�| d k r£| j d d ƒ n  t j  t  | d ƒ | d | ƒ} | j! t ƒ |	 j" | ƒ | d	 k r| j# ƒ  d | j$ d ƒ } n  | j d | ƒ q0W|	 j% d |  j& | | ƒ |	 S(   sV  Create a TreeView object for the suite overview
        
        ARGUMENTS:
            confTreeView      - the TreeView object for the list of conformers
            suiteFrame        - the Frame object containing information about the current suite
        RETURNS:
            overviewTreeView  - the newly created TreeView object
        i   iÿÿÿÿt   &s   &amp;i   R>   g      à?s   width-charsi    t   weightRÆ   t   infg333333ó?i   s   cell-backgroundt   redg      ü?i   t   orangeg      @i
   t   yellowt   markupi   s   vertical-separatort   heights   button-press-event('   RH   R#   R!   RI   RÇ   R   t
   resNumListR)   R™   t   replacet   maxR×   RØ   RX   t   set_headers_visibleRã   t   set_modet   SELECTION_NONEt   set_grid_linest   TREE_VIEW_GRID_LINES_VERTICALRù   t	   enumerateRÙ   RÚ   t   BOLD_WEIGHTt   sortedR   t   valuesRZ   t   ZeroDivisionErrort   floatR   RÞ   t
   set_expandRß   Rä   Rå   RD   t   _ReviewSuitesGui__overviewClick(   R,   Rt   Rq   t   typeListt   overviewListStoreR
  RÏ   RG   t   columnWidthCharsRw   t	   setColumnt   colNumt   renderert   bestProbt   secondBestProbt   ratiot   minimizationScoret   columnt	   colHeight(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __createOverviewTreeView®  sV    /,, " c         C   s¨  t  j ƒ  } | j t  j ƒ | j | ƒ | j ƒ  \ } } | j ƒ  } t g  | j ƒ  D] } | j ƒ  d ^ qW ƒ }	 |	 d | j	 | j ƒ  d ƒ d d | j	 | j ƒ  d ƒ d 7}	 | |	 t
 d t }
 | |
 k r| j t  j t  j ƒ | j | d | d ƒ t } n‹ y | j ƒ  j ƒ  d } Wn' t k
 rVt  j ƒ  j ƒ  d } n X| j d ƒ } | j t  j t  j ƒ | j |
 | | | d ƒ t } | | f S(   s@  Create a ScrolledWindow object to display the suite overview TreeView
        
        ARGUMENTS:
            overviewTreeView    - the TreeView object used to display the suite overview
            prevConfButton      - the previous conformer button (so we can calculate its width)
            treeViewScrollWidth - the width of the TreeView used to display the conformer list
        RETURNS:
            overviewScroll      - the newly created ScrolledWindow object
            wideOverview        - whether or not the ScrolledWindow takes up the full window width
        i    i   i   i   i   s   scrollbar-spacing(   RI   Rñ   Rõ   Rö   R\   R÷   RA   t   sumt   get_childrent   query_child_packingR   R   Rò   Ró   Rû   RX   t   get_hscrollbarRù   t
   HScrollbarRå   t   POLICY_ALWAYSRZ   (   R,   Rw   Ri   Ry   Rz   t   overviewTableWidthReqt   overviewTableHeightReqt   prevConfButtonHBoxt   childt   prevConfButtonWidtht   suiteFrameWidthR{   t   hScrollHeightReqRÿ   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __createOverviewScrolledWindow  s*    /D	c   
      C   sv   | \ } } | j  | | ƒ } | r7 | j d t ƒ n; | j  | | ƒ }	 |	 rb | j d t ƒ n | j d d ƒ d S(   s4  Appropriately set the background of a cell listing sugar pucker
        
        ARGUMENTS:
            column          - the TreeViewColumn to be changed
            renderer        - the CellRenderer for the column
            confListStore   - the ListStore containing the displayed data
            iter            - a TreeIter pointing to the specified row of the TreeView
            columnList      - a list of (the number of the column to be changed, the number of the column containing the best conformer)
        RETURNS:
            None
        EFFECTS:
            Sets the background color for the specified cell to:
                DIFFERENT_PUCKER_COLOR if it's different than the pucker for the best path
                BEST_PATH_COLOR is it's the best conformer
                None otherwise
        s   cell-backgroundN(   R�   RÚ   t   DIFFERENT_PUCKER_COLORRà   R%   (
   R,   R$  R  Rr   t   itert
   columnListt   puckerColumnt   bestPathColumnt   isDifferentPuckert
   isBestPath(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __setPuckerBgD  s    c         C   s9   |  j  d k r5 |  j | | | |  j  |  j  d ƒ n  d S(   s4  Select the previous suite
        
        ARGUMENTS:
            widget           - the button used to invoke this function.  Ignored.
            confTreeView     - the TreeView used to display data about conformers for the current suite
            suiteFrame       - the GTK frame containing the "Suite X of Y" label
            overviewTreeView - the TreeView used to display the suite overview
        RETURNS:
            None
        EFFECTS:
            Recenters the screen on the previous suite and updates the RCrane GUI to reflect that suite.
        i   N(   R"   t!   _ReviewSuitesGui__prevOrNextSuite(   R,   R¼   Rt   Rq   Rw   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __prevSuiteb  s    c         C   sB   |  j  t |  j ƒ k  r> |  j | | | |  j  |  j  d ƒ n  d S(   s,  Select the next suite
        
        ARGUMENTS:
            widget           - the button used to invoke this function.  Ignored.
            confTreeView     - the TreeView used to display data about conformers for the current suite
            suiteFrame       - the GTK frame containing the "Suite X of Y" label
            overviewTreeView - the TreeView used to display the suite overview
        RETURNS:
            None
        EFFECTS:
            Recenters the screen on the next suite and updates the RCrane GUI to reflect that suite.
        i   N(   R"   R#   R   R=  (   R,   R¼   Rt   Rq   Rw   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __nextSuites  s    c         C   sà  |  j  |  j | d <t |  j ƒ d k rO |  j t |  j  d |  j | d <n  t |  j ƒ d k r† |  j t |  j  d |  j | <n  |  j j | |  j j	 } |  j j | |  j j	 } |  j
 j | ƒ } t | Œ  t |  j
 j ƒ  |  j
 j t | ƒ d ƒ t |  j
 j ƒ  |  j
 j t | ƒ d ƒ t ƒ  |  j r[d t | ƒ | t |  j ƒ f }	 n d | t |  j ƒ f }	 | j |	 ƒ |  j | ƒ \ }
 } | j ƒ  } | j |  j ƒ | j |
 ƒ | j |
 j | ƒ ƒ | j | d t d d	 ƒ| j  d
 |  j! | ƒ |  _ | j" | d ƒ j# ƒ  d j$ d t% j& ƒ | j" | d ƒ j# ƒ  d j$ d t' ƒ | j d | j" | d ƒ ƒ | j( ƒ  } | j) d | j d ƒ ƒ | j) d | j d ƒ ƒ |  j | d |  _  | |  _* |  j+ ƒ  d S(   sO  Select the specified suite
        
        ARGUMENTS:
            confTreeView     - the TreeView used to display data about conformers for the current suite
            suiteFrame       - the GTK frame containing the "Suite X of Y" label
            overviewTreeView - the TreeView used to display the suite overview
            oldSuiteIndex    - the suite we are moving from
            newSuiteIndex    - the suite we are moving to
        RETURNS:
            None
        EFFECTS:
            Recenters the screen on newSuite and updates the RCrane GUI to reflect that suite.
        i   i   i    s    P  s   Suite %s (%i of %i)s   Suite %i of %it	   use_alignt	   row_aligng      ð?R;   R  N(   i    (   i    (   i    (   i   (   i   (,   Ra   R!   R#   R’   R	   R–   R   R'   R)   RG   R   Rb   R   R   Rc   Rd   Re   R   R   R   RH   R   t	   set_labelRK   Rã   t
   disconnectR&   t	   set_modelR¹   R¸   R»   RZ   RD   RN   t
   get_columnt   get_cell_renderersRÚ   t   pangot   WEIGHT_NORMALR  t	   get_modelt   row_changedR"   R*   (   R,   Rt   Rq   Rw   t   oldSuiteIndext   newSuiteIndext   oldSuiteNumt   newSuiteNumt   newPhosRp   t   newListStoreRs   Ru   t   overviewModel(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __prevOrNextSuite„  s@    &"
((	%*'	c         C   sL   i  |  _  i  |  _ i  |  _ i  |  _ i  |  _ i  |  _ i  |  _ i  |  _ d S(   sù   Reset all data about the current suite (appropriate for when we've just switched suites)
        
        ARGUMENTS:
            None
        RETURNS:
            None
        EFFECTS:
            Resets (or initializes) all cache variables
        N(   R‹   R�   R”   R’   R–   t9   _ReviewSuitesGui__intermediateAtomLocsStartingPuckerCachet7   _ReviewSuitesGui__intermediateAtomLocsEndingPuckerCachet+   _ReviewSuitesGui__intermediateAtomLocsCache(   R,   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __clearCacheÏ  s    							c         C   s   |  j  | ƒ d S(   s   Close the RCrane window
        
        ARUGMENTS:
            window - the window to close
            widget - the widget used to close the window
        NOTES:
            This function simply calls __accept with the appropriate argument list
        N(   RU   (   R,   R3   R¼   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt
   __closeWinå  s    c         C   sD   |  j  j ƒ  |  j d k	 r, t |  j ƒ n  t ƒ  |  j j ƒ  d S(   sÍ   Close the RCrane window
        
        ARUGMENTS:
            widget - the widget used to close the window
        RETURNS:
            None
        EFFECTS:
            Closes the RCrane window
        N(   R   R›   R   R%   R   R   R   t   destroy(   R,   R¼   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __closeò  s
    c         C   s3   |  j  j d t |  j  j ƒ  ƒ ƒ |  j | ƒ d S(   s3  Accept the new molecule and close the RCrane window
        
        ARUGMENTS:
            widget - the widget used to close the window
        RETURNS:
            None
        NOTE:
            This function re-orders atoms in the pseudomolecule (that's the "accept" part) and then calls __close
        t	   fixSegidsN(   R   t   finalMoleculeCleanupt   boolRF   t   _ReviewSuitesGui__close(   R,   R¼   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __accept  s    "c         C   s    t  |  j t | j ƒ  ƒ ƒ d S(   sª   Toggle display of the old coordinates object
        
        ARGUMENTS:
            widget - the check button that was toggled
        RETURNS:
            None
        N(   R   R   Re   t
   get_active(   R,   R¼   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __toggleOldCoords  s    	c         C   s   |  j  j ƒ  |  j ƒ  d S(   sè   Set the coordinates back to the way they were before we called rotamerize
        
        ARGUMENTS:
            widget - the cancel button that was clicked to call this function.  Ignored
        RETURNS:
            None
        N(   R   t   restoreSavedCoordinatesR]  (   R,   R¼   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __restoreOldCoords!  s    	c   	      C   s¢   | j  t | j ƒ t | j ƒ ƒ d } t | j ƒ  ƒ } | |  j k r‚ |  j j | |  j j	 } |  j
 j | ƒ } t | Œ  n |  j | | | |  j | ƒ d S(   s©  Respond to the user clicking on the overview TreeView object
        
        ARGUMENTS:
            overviewTreeView - the TreeView object for the suite overview
            event            - the click event
            confTreeView     - the TreeView object for the list of conformers
            suiteFrame       - the Frame object containing information about the current suite
        RETURNS:
            None
        i   N(   t   get_path_at_posRe   RÄ   t   yt	   get_titleR"   R   R'   R)   RG   R   Rb   R   R=  (	   R,   Rw   t   eventRt   Rq   t   clickedColumnt   newSuiteRN  RO  (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __overviewClick.  s    (c         C   sˆ   | d 8} | j  ƒ  } | |  j | k rT | j | j d ƒ | | j d d ƒ ƒ n0 | j | j d ƒ | d | j d d ƒ d ƒ d S(	   sj  Change the conformer listed in the overview table for the specified suite
        
        ARGUMENTS:
            overviewTreeView - the TreeView object for the suite overview
            suiteNum         - the number of the suite to change
            newConf          - the new conformer to list in the overview table
        RETURNS:
            None
        i   R  s   &amp;s   <i>s   </i>N(   i   (   i   (   RI  R   t	   set_valueR¸   R  (   R,   Rw   Ro   t   newConfR  (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   __changeOverviewConformerM  s
    
+N(   t   __name__t
   __module__t   __doc__R%   RZ   RX   R9   R+   RN   RQ   RR   RK   RL   RO   RM   RP   Râ   RS   RT   R=  R*   RE   R]  RU   R`   RV   R  Rž   (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyR   '   s.   M	¦	ï				8	#	`	6				K					(    (    Ro  RI   RG  t   copyR    t   ost   timeR   t   cootR   R   R   R   R   R   R	   R   R
   R   t   guiUtilsR   R   R   R   R   t
   rotamerSeqR   R5  Rà   t   WEIGHT_HEAVYR  R   (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/reviewSuitesGui.pyt   <module>   s   .(	