ó
Ñ%�Tc           @   s%  d  Z  d d l m Z m Z m Z d d l m Z d d l m Z d d l m	 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 d a e a d
 „  Z d „  Z e d d g ƒ Z e d d d d d d d g ƒ Z d „  Z e d „ Z d „  Z d „  Z  d „  Z! d S(   s(   Extend an existing chain of nucleotides.iÿÿÿÿ(   t   add_status_bar_textt   clear_pending_pickst   imol_refinement_map(   t   user_defined_click_py(   t   selectMapDialog(   t   createCitationPopup(   t   PseudoMoleculeN(   t   TraceGui(   t   reportPDB2Errort   reportInsCodeErrort   STANDARD_BASESt   reportModifiedNucErrorc           C   sŒ   t  ƒ  t j ƒ  t r= d GHt d ƒ t ƒ  t ƒ  t a nK t ƒ  d k r_ d GHt	 t
 ƒ d Sd GHt d ƒ t ƒ  t a t d t ƒ d S(	   sí   Prompt the user to pick an atoms to extend a stretch of nucleotides.  Alternatively, if
    we're already waiting for the user to pick an atom, then cancel the pending pick.
    
    ARGUMENTS:
        None
    RETURNS:
        None
    s   Rotamerize cancelleds   Extend chain cancellediÿÿÿÿs-   No refinement map set for RCrane extend chainNs   Click on a nucleotide to extends7   Pick a nucleotide [Ctrl Left-mouse rotates the view]...i   (   R   t
   rotamerizet   clearPendingRotamerizet   waitingForClicksR    R   t   __setMenuToExtendChaint   FalseR   R   t	   pickAtomst   __setMenuToCancelt   Truet   user_defined_clickt   extendChainFromAtomSpec(    (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/extendChain.pyR   "   s"    

	

c         C   s‘  t  ƒ  t a |  d \ } } } } } } | j ƒ  } y t d | d | ƒ } Wn- t k
 r} } | GHt t | ƒ d ƒ t SXt | ƒ t | ƒ }	 | j | ƒ }
 | j	 |
 ƒ } | j
 |
 ƒ } | j |
 ƒ } t } | rò | j |
 d ƒ } n  d } | r3| rd } qéd |	 d GHt d |	 d ƒ t Sn¶ | rƒ| rgd } |
 d 7}
 t } | j |
 ƒ }	 qét | |	 ƒ } | sét Snf | r²| r²d |	 d GHt d |	 d ƒ t S| rÁd	 } n( | rÐd } n t | |	 ƒ } | sét S| j |
 ƒ d d
 k rt |	 ƒ t S| rN| j |
 d ƒ d d
 k rNt | j |
 d ƒ ƒ t S| rŒ| j |
 d ƒ d d
 k rŒt | j |
 d ƒ ƒ t S| r²|
 d } | j |
 d ƒ } n |
 } |	 } | j | ƒ } | t k rêt | | ƒ t S| j | ƒ rt | ƒ t S| j | ƒ } | d k s.| d k r7d } n d } | j d | ƒ d k rxd | d GHt d | d ƒ t S| j | | ƒ d k rÃd | d | d GHt d | d | d ƒ t S| j |
 ƒ } | r| r| d k rd |	 d GHt d |	 d ƒ t S| d	 k rJ| rJd |	 d GHd GHt d |	 d ƒ t Sd t | ƒ d GH| j |
 ƒ | j ƒ  t d | d | d |
 ƒ d S(   sí   Rotamerize a stretch of nucleotides
    
    ARGUMENTS:
        atomSpec - an atom spec specifying the start of the chain extension
    RETURNS:
        False if there is a problem with the selected nucleotide
        None otherwise
    i   t   createFromMoleculet   chains   

Rotamerization canceled.i   s   Nucleotide s0    is an isolated phosphate group.  Cannot extend.s    is not at the end of a chaini   t    t   At   Gt   N9t   N1s   C1's0    does not have a C1' atom.  Cannot extend chain.s    does not have an s    atom.  Cannot extend chain.sH   is an isolated nucleotides without any phosphates.  Cannot extend chain.s   Cannot extend nucleotide s,    in the 5' direction without a 3' phosphate.sG     Please add a 3' phosphate by extending the chain in the 3' direction.s!   About to extend the chain in the s   ' directiont	   directiont   existingMoleculet   resIndexToExtendN(   R   R   R   t   stripR   t   PseudoMoleculeErrort   createRCraneErrorDialogt   strt   resIndext   connectedToNextFromIndext   connectedToPrevFromIndext   isOnlyPhosGroupFromIndext   NoneR    R   t
   resNumFullt   __decideDirectionFromAtomt   resNumR	   t   resTypeFromIndexR
   R   t   checkPDB2FromIndexR   t   getAtomCoordsFromIndext   getPhosCoordsFromIndext   setResInsertionPointt   saveMoleculeStateR   (   t   atomSpect   molR   R+   t   insCodet   atomt   altt	   pseudoMolt   errR)   R$   t   connectedToNextt   connectedToPrevt   curResIsPhosOnlyt   nextResIsPhosOnlyt	   extendDirt   resIndexToCheckt   resNumFullToCheckt   resTypet   baseTypet   glyNt   curPhosCoords(    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/extendChain.pyR   L   s¸    	
 		 
##

	
s   C3's   O3't   Pt   OP1t   OP2t   OP3s   O5's   C5's   C4'c         C   sD   |  t  k r d S|  t k r  d Sd | d GHd GHt d ƒ t Sd S(   s  Determine the direction to extend the chain based on the atom name (for use with isolated nuclotides)
    
    ARGUMENTS:
        atomName - the atom name
        resNum   - the residue number of the current nucleotide (used in reporting errors)
    RETURNS:
        False if the direction cannot be determined from the atom name
        3 or 5 otherwise
    EFFECTS:
        if the direction cannot be determined from the atom name, an error will be reported to the user
        (and False will be returned)
    i   i   s   Nucleotide s<    is an isolated nucleotide.  Please select either the O5' ors;   O3' atom to extend in the 5' or 3' direction, respectively.s6   Must select either O5' or O3' of isolated nucleotides.N(   t   ATOMS3Pt   ATOMS5PR    R   (   t   atomNameR+   (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/extendChain.pyR*   õ   s    
c         C   s'   |  a  | r# t a t ƒ  t ƒ  n  d S(   sÐ  ARGUMENTS:
        menuItem   - the gtk MenuItem to store
    OPTIONAL ARGUMENTS:
        resetLabel    - whether we should reset the menu label to "Extend chain..."
                        (and also clear all pending atom picks in Coot)
                        This is intended for use when we're reloading RCrane
                        Defaults to False
    RETURNS:
        None
    EFFECTS:
        stores menuItem in the module-level variable __menuItem
    N(   t
   __menuItemR   R   R   R   (   t   menuItemt
   resetLabel(    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/extendChain.pyt   storeMenuItem  s
    c           C   s&   t  d k	 r" t  j ƒ  j d ƒ n  d S(   sn   Set the menu entry labels to "Extend chain..."
    
    ARGUMENTS:
        None
    RETURNS:
        None
    s   Extend chain...N(   RK   R(   t	   get_childt   set_text(    (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/extendChain.pyR   (  s    	c           C   s&   t  d k	 r" t  j ƒ  j d ƒ n  d S(   st   Set the menu entry label to "Cancel extend chain..."
    
    ARGUMENTS:
        None
    RETURNS:
        None
    s   Cancel extend chain...N(   RK   R(   RO   RP   (    (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/extendChain.pyR   5  s    	c           C   s+   t  r# d GHt ƒ  t ƒ  t a  t St Sd S(   sË   Cancel any pending extend chain call (intended to be called by rotamerize)
    
    ARGUMENTS:
        None
    RETURNS:
        True if there was a pending extend chain call
        False otherwise
    s   Extend chain cancelledN(   R   R   R   R   R   (    (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/extendChain.pyt   clearPendingExtendChainB  s    ("   t   __doc__t   cootR    R   R   R   R   R   t   citationPopupR   t   pseudoMoleculeR   R   t   traceGuiR   t   reportInputErrorsR   R	   R
   R   R(   RK   R   R   R   R   t	   frozensetRH   RI   R*   RN   R   R   RQ   (    (    (    sY   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/extendChain.pyt   <module>   s&   "	*	¥!			