ó
Ñ%�Tc           @   s?   d  Z  d d l m Z m Z m Z d Z d d d „  ƒ  YZ d S(   s=   A class for storing information about individual nucleotides.iÿÿÿÿ(   t   torsiont   distt
   distToLines   C1't
   Nucleotidec           B   s¼   e  Z d  Z 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 „  Z d „  Z d „  Z RS(   sc   A class for storing information about individual nucleotides (which may be part of a Chain object).c         C   s1   | |  _  | |  _ | |  _ d |  _ d |  _ d S(   sz  Initialize a Nucleotide object
        
        ARGUMENTS:
            type  - the nucleotide type (i.e. A, C, G, or U)
            atoms - a hash of atom coordinates (in the form atomName: [x, y, z])
        OPTIONAL ARGUMENTS:
            resNum - the residue number (possibly including an insertion code)
        RETURNS:
            an initialized Nucleotide object
        N(   t   typet   atomst   resNumt   Nonet   chaint   seqNum(   t   selfR   R   R   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   __init__   s
    				c         C   s,   |  j  d k r$ |  j j |  j  d Sd Sd S(   sR  If this nucleotide is part of a chain, return the previous nucleotide in the chain
        
        ARGUMENTS:
            None
        RETURNS:
            The Nucleotide object of the previous nucleotide if there is one
            None if this is the first nucleotide of the chain,or if this nucleotide is not part of a chain.
        i    i   N(   R	   R   t   nucleotidesR   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   prevNuc,   s    
c         C   s5   |  j  |  j j ƒ  k  r- |  j j |  j  d Sd Sd S(   sI  If this nucleotide is part of a chain, return the next nucleotide in the chain
        
        ARGUMENTS:
            None
        RETURNS:
            The Nucleotide object of the next nucleotide if there is one
            None if this is the last nucleotide of the chain or if this nucleotide is not part of a chain.
        i   N(   R	   R   t   lenR   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   nextNuc<   s    
c         C   s   |  j  d k S(   sö  Is this nucleotide connected to the previous nucleotide of the chain?
        
        ARGUMENTS:
            None
        RETURNS:
            True if this nucleotide is connected to the previous nucleotide of the chain
            False if it isn't or if this nucleotide is not part of a chain.
        NOTE:
            Because the chain module does not currently support unconnected nucleotides, this function only
            tells you if this is the first nucleotide of the chain or not.
        i    (   R	   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   connectedToPrevL   s    c         C   s   |  j  |  j j ƒ  d k  S(   s†  Is this nucleotide connected to the next nucleotide of the chain?
        
        ARGUMENTS:
            None
        RETURNS:
            True if this nucleotide is connected to the previous nucleotide of the chain
            False if it isn't
            Note that the behavior of this function (unlike that of connectedToPrev()) is not defined
                if this nucleotide is not part of a chain.  (Currently, it raises an error.)
        NOTE:
            Because the chain module does not currently support unconnected nucleotides, this function only
            tells you if this is the last nucleotide of the chain or not.
        i   (   R	   R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   connectedToNext\   s    c         C   s   |  j  j | ƒ S(   sæ   Does this nucleotide contain the specified atom?
        
        ARGUMENTS:
            atomName - the name of the atom to check for
        RETURNS:
            True if this nucleotide contains atomName, False otherwise
        (   R   t   has_key(   R
   t   atomName(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   hasAtomn   s    	c         C   s£   |  j  ƒ  r› |  j ƒ  r› |  j ƒ  j t ƒ r› |  j d ƒ r› |  j t ƒ r› |  j ƒ  j d ƒ r› t |  j ƒ  j t |  j d |  j t |  j ƒ  j d ƒ Sd Sd S(   sç  Calculate the eta pseudotorsion for the current nucleotide
        
        ARGUMENTS:
            None
        RETURNS:
            The value of eta if it is defined, None otherwise.
        NOTE:
            Calculating eta requires the sugar atom of the previous nucleotide and the phosphate atom
            of the next nucleotide.  As a result, behaviour of this function is undefined if this nucleotide
            is not part of a chain.  (Currently, it raises an error.)
        t   PN(	   R   R   R   R   t	   SUGARATOMR   R    R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   etay   s    

c         C   s—   |  j  ƒ  r� |  j d ƒ r� |  j t ƒ r� |  j ƒ  j d ƒ r� |  j ƒ  j t ƒ r� t |  j d |  j t |  j ƒ  j d |  j ƒ  j t ƒ Sd Sd S(   sÈ  Calculate the theta pseudotorsion for the current nucleotide
        
        ARGUMENTS:
            None
        RETURNS:
            The value of theta if it is defined, None otherwise.
        NOTE:
            Calculating theta requires the phosphate and sugar atom of the next nucleotide.
            As a result, behaviour of this function is undefined if this nucleotide
            is not part of a chain.  (Currently, it raises an error.)
        R   N(   R   R   R   R   R    R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   theta”   s    
c         C   s¬   |  j  d ƒ r |  j d } n% |  j  d ƒ r> |  j d } n d } | d k	 r¤ |  j  t ƒ r¤ |  j ƒ  r¤ |  j ƒ  j  d ƒ r¤ t |  j ƒ  j d |  j t | ƒ Sd Sd S(   sÓ  Calculate the base-phosphate perpendicular distance (P-perp distance) for the current nucleotide
        
        ARGUMENTS:
            None
        RETURNS:
            The P-perp distance if it is defined, None otherwise
        NOTE:
            Calculating P-perp requires the phosphate of the next nucleotide.  As a result, behaviour of this
            function is undefined if this nucleotide is not part of a chain.  (Currently, it raises an error.)
        t   N9t   N1R   N(   R   R   R   R   R   R   R   (   R
   t   baseN(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   pperp¯   s    <
c         C   sY   |  j  ƒ  rQ |  j d ƒ rQ |  j ƒ  j d ƒ rQ t |  j d |  j ƒ  j d ƒ Sd Sd S(   s¢  Calculate the phosphate-phosphate distance
        
        ARGUMENTS:
            None
        RETURNS:
            The distance from the phosphate of this nucleotide to the phosphate of the next nucleotide
            None if no next phosphate if present
        NOTE:
            Behavior of this function is undefined if this nucleotide is not part of a chain.
            (Currently, it raises an error.)
        R   N(   R   R   R   R   R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   phosDistÌ   s    0!c         C   sY   |  j  ƒ  rQ |  j t ƒ rQ |  j ƒ  j t ƒ rQ t |  j t |  j ƒ  j t ƒ Sd Sd S(   sÛ  Calculate the sugar-sugar distance for the starting suite of this nucleotide
        
        ARGUMENTS:
            None
        RETURNS:
            the distance from the sugar atom (i.e. C1') of the previous nucleotide to the sugar atom (C1') of this nucleotide
            None if there is no previous nucleotide
        NOTE:
            Behavior of this function is undefined if this nucleotide is not part of a chain.
            (Currently, it returns None.)
        N(   R   R   R   R   R   R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   startingSugarDistß   s    0!c         C   s$   |  j  ƒ  r |  j ƒ  j ƒ  Sd Sd S(   sØ  Calculate the sugar-sugar distance for the ending suite of this nucleotide
        
        ARGUMENTS:
            None
        RETURNS:
            the distance from the sugar atom (i.e. C1') of this nucleotide to the sugar atom (C1') of the next nucleotide
            None if there is no previous nucleotide
        NOTE:
            Behavior of this function is undefined if this nucleotide is not part of a chain.
            (Currently, it raises an error.)
        N(   R   R   R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   endingSugarDistò   s    c         C   s›   d t  |  j ƒ d } | d t  |  j ƒ d 7} | d t  |  j ƒ d 7} | d 7} x= |  j j ƒ  D], \ } } | d | d t  | ƒ d 7} qg W| S(   s,   Create a string representation of the objects
   Nuc Num:  s   
s
   Seq Num:  s
   Nuc type: s   Atoms: 
s   	s   :  (   t   strR   R	   R   R   t	   iteritems(   R
   t   retValt   namet   coords(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   __str__  s    
$c         C   s‹   |  j  ƒ  rƒ |  j ƒ  j d ƒ rƒ |  j d ƒ rƒ |  j d ƒ rƒ |  j d ƒ rƒ t |  j d |  j d |  j d |  j ƒ  j d ƒ Sd Sd S(   s£   Calculate the alpha torsion
        
        ARGUMENTS:
            None
        RETURNS:
            The value of alpha if it is defined, None otherwise.
        s   O3'R   s   O5's   C5'N(   R   R   R   R    R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   alpha  s    	

c         C   ss   |  j  d ƒ rk |  j  d ƒ rk |  j  d ƒ rk |  j  d ƒ rk t |  j d |  j d |  j d |  j d ƒ Sd Sd S(   s¡   Calculate the beta torsion
        
        ARGUMENTS:
            None
        RETURNS:
            The value of beta if it is defined, None otherwise.
        R   s   O5's   C5's   C4'N(   R   R    R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   beta'  s    	

c         C   ss   |  j  d ƒ rk |  j  d ƒ rk |  j  d ƒ rk |  j  d ƒ rk t |  j d |  j d |  j d |  j d ƒ Sd Sd S(   s£   Calculate the gamma torsion
        
        ARGUMENTS:
            None
        RETURNS:
            The value of gamma if it is defined, None otherwise.
        s   O5's   C5's   C4's   C3'N(   R   R    R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   gamma=  s    	

c         C   ss   |  j  d ƒ rk |  j  d ƒ rk |  j  d ƒ rk |  j  d ƒ rk t |  j d |  j d |  j d |  j d ƒ Sd Sd S(   s£   Calculate the delta torsion
        
        ARGUMENTS:
            None
        RETURNS:
            The value of delta if it is defined, None otherwise.
        s   C5's   C4's   C3's   O3'N(   R   R    R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   deltaS  s    	

c         C   s‹   |  j  ƒ  rƒ |  j d ƒ rƒ |  j d ƒ rƒ |  j d ƒ rƒ |  j ƒ  j d ƒ rƒ t |  j d |  j d |  j d |  j ƒ  j d ƒ Sd Sd S(   s§   Calculate the epsilon torsion
        
        ARGUMENTS:
            None
        RETURNS:
            The value of epsilon if it is defined, None otherwise.
        s   C4's   C3's   O3'R   N(   R   R   R   R    R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   epsiloni  s    	

c         C   s—   |  j  ƒ  r� |  j d ƒ r� |  j d ƒ r� |  j ƒ  j d ƒ r� |  j ƒ  j d ƒ r� t |  j d |  j d |  j ƒ  j d |  j ƒ  j d ƒ Sd Sd S(   s¡   Calculate the zeta torsion
        
        ARGUMENTS:
            None
        RETURNS:
            The value of zeta if it is defined, None otherwise.
        s   C3's   O3'R   s   O5'N(   R   R   R   R    R   R   (   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   zeta�  s    	
N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   R   R   R   R   R%   R&   R'   R(   R)   R*   R+   (    (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyR      s(   																	N(    (   R.   t	   strucCalcR    R   R   R   R   (    (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/nucleotide.pyt   <module>   s   