ó
Ñ%�Tc           @   s-   d  Z  d d l m Z d d d „  ƒ  YZ d S(   s*   A class for storing chains of nucleotides.iÿÿÿÿ(   t   Suitet   Chainc           B   sƒ   e  Z d  Z d d „ Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   s`   A class for storing chains of nucleotides (which must all be instances of the nucleotide class).c         C   sp   i  |  _  | d k	 r] xK t | ƒ D]4 \ } } |  | _ | | _ | |  j  t | j ƒ <q" Wn g  } | |  _ d S(   s  Initialize a Chain object.
        
        OPTIONAL ARGUMENTS:
            nucs - a list of nucleotide objects to add to the chain
                   If not given, then an empty chain is created
        RETURNS:
            an initialized Chain object
        N(   t   _Chain__resNumDictt   Nonet	   enumeratet   chaint   seqNumt   strt   resNumt   nucleotides(   t   selft   nucst	   curSeqNumt   curNuc(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt   __init__   s    			c         C   s   |  j  S(   s   A synonym for Chain.nucleotides(   R	   (   R
   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyR   /   s    c         C   sE   |  | _  |  j ƒ  | _ |  j j | ƒ | j |  j t | j ƒ <d S(   sÜ   Add a nucleotide to the end of the chain
        
        ARGUMENTS:
            nuc - a nucleotide object to add to the chain
        RETURNS:
            None
        EFFECTS:
            Adds nuc to the chain
        N(   R   t   numNucsR   R	   t   appendR   R   R   (   R
   t   nuc(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt   addNuc5   s    	c         C   s}   |  | _  d | _ x  |  j D] } | j d 7_ q Wx. |  j j ƒ  D] \ } } | d |  j | <qE W|  j j d | ƒ d S(   sì   Add a nucleotide to the start (i.e. 5' end) of the chain
        
        ARGUMENTS:
            nuc - a nucleotide object to add to the chain
        RETURNS:
            None
        EFFECTS:
            Adds nuc to the chain
        i    i   N(   R   R   R	   R   t	   iteritemst   insert(   R
   R   R   t   curKeyt   curVal(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt   addNuc5pG   s    		c         c   sp   |  j  d j d ƒ r d } n d } xD t | t |  j  ƒ d ƒ D]& } t |  j  | |  j  | d ƒ VqB Wd S(   s‘   A generator for suites in the chain
        
        ARGUMENTS:
            None
        YIELDS:
            The next suite of the chain
        i    s   C1'i   i   N(   R	   t   hasAtomt   xranget   lenR    (   R
   t   startingNuct   i(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt   suites`   s
    
	#c         C   s   t  |  j ƒ S(   s    The length of the chain in nucleotides
        
        ARGUMENTS:
            None
        RETURNS:
            The length of the chain in nucleotides
        (   R   R	   (   R
   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyR   s   s    	c         C   s   t  |  j ƒ S(   s    The length of the chain in nucleotides
        
        ARGUMENTS:
            None
        RETURNS:
            The length of the chain in nucleotides
        (   R   R	   (   R
   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyR      s    	c         C   s   t  |  j ƒ d S(   s–   The length of the chain in suites
        
        ARGUMENTS:
            None
        RETURNS:
            The length of the chain in suites
        i   (   R   R	   (   R
   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt	   numSuites‹   s    	c         C   s   |  j  t | ƒ S(   s  Find the index (i.e. position in the chain) of a given residue number
        
        ARGUMENTS:
            resNum - the residue number to find (which may include an insertion code)
        RETURNS:
            the index of the specified residue number in this chain
        (   R   R   (   R
   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt   resIndex—   s    	c         C   s   g  |  j  D] } | j ^ q
 S(   N(   R	   R   (   R
   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt
   resNumList£   s    c         C   s   g  |  j  D] } | j ^ q
 S(   N(   R	   t   type(   R
   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt   resTypeList¦   s    c         C   s   d j  t t |  j ƒ ƒ S(   s,   Create a string representation of the objects   

(   t   joint   mapR   R	   (   R
   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt   __str__©   s    N(   t   __name__t
   __module__t   __doc__R   R   t   propertyR   R   R   R   R   R   R   R   R    R"   R%   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyR      s   									N(    (   R(   t   suiteR    R   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/chain.pyt   <module>   s   