
:>"^|  ã               @   s0   d  Z  d d l m Z Gd d „  d e ƒ Z d S)z'Chain class, used in Structure objects.é    )ÚEntityc               @   s¾   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d d	 „  Z d
 d „  Z d d „  Z	 d d „  Z
 d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z d S)ÚChainz‰Define Chain class.

    Chain is an object of type Entity, stores residues and includes a method to
    access atoms from residues.
    c             C   s   d |  _  t j |  | ƒ d S)zInitialize the class.ÚCN)Úlevelr   Ú__init__)ÚselfÚid© r	   ú2/tmp/pip-build-ww9dw3qa/biopython/Bio/PDB/Chain.pyr      s    	zChain.__init__c             C   sn   t  | t ƒ rf |  j d k r1 | j d k r1 d S|  j d k rS | j d k rS d S|  j | j k Sn t Sd S)z(Validate if id is greater than other.id.ú r   é   N)Ú
isinstancer   r   ÚNotImplemented)r   Úotherr	   r	   r
   Ú__gt__   s    zChain.__gt__c             C   sn   t  | t ƒ rf |  j d k r1 | j d k r1 d S|  j d k rS | j d k rS d S|  j | j k Sn t Sd S)z1Validate if id is greater or equal than other.id.r   r   r   N)r   r   r   r   )r   r   r	   r	   r
   Ú__ge__&   s    zChain.__ge__c             C   sn   t  | t ƒ rf |  j d k r1 | j d k r1 d S|  j d k rS | j d k rS d S|  j | j k  Sn t Sd S)z%Validate if id is less than other.id.r   r   r   N)r   r   r   r   )r   r   r	   r	   r
   Ú__lt__2   s    zChain.__lt__c             C   sn   t  | t ƒ rf |  j d k r1 | j d k r1 d S|  j d k rS | j d k rS d S|  j | j k Sn t Sd S)z.Validate if id is less or equal than other id.r   r   r   N)r   r   r   r   )r   r   r	   r	   r
   Ú__le__>   s    zChain.__le__c             C   s"   t  | t ƒ r d | d f } | S)a  Translate sequence identifier to tuple form (PRIVATE).

        A residue id is normally a tuple (hetero flag, sequence identifier,
        insertion code). Since for most residues the hetero flag and the
        insertion code are blank (i.e. " "), you can just use the sequence
        identifier to index a residue in a chain. The _translate_id method
        translates the sequence identifier to the (" ", sequence identifier,
        " ") tuple.

        Arguments:
         - id - int, residue resseq

        r   )r   Úint)r   r   r	   r	   r
   Ú_translate_idJ   s    zChain._translate_idc             C   s   |  j  | ƒ } t j |  | ƒ S)a!  Return the residue with given id.

        The id of a residue is (hetero flag, sequence identifier, insertion code).
        If id is an int, it is translated to (" ", id, " ") by the _translate_id
        method.

        Arguments:
         - id - (string, int, string) or int

        )r   r   Ú__getitem__)r   r   r	   r	   r
   r   \   s    zChain.__getitem__c             C   s   |  j  | ƒ } t j |  | ƒ S)z…Check if a residue with given id is present in this chain.

        Arguments:
         - id - (string, int, string) or int

        )r   r   Ú__contains__)r   r   r	   r	   r
   r   j   s    zChain.__contains__c             C   s   |  j  | ƒ } t j |  | ƒ S)zWDelete item.

        Arguments:
         - id - (string, int, string) or int

        )r   r   Ú__delitem__)r   r   r	   r	   r
   r   t   s    zChain.__delitem__c             C   s   d |  j  ƒ  S)zReturn the chain identifier.z<Chain id=%s>)Zget_id)r   r	   r	   r
   Ú__repr__~   s    zChain.__repr__c             C   sg   g  } xZ |  j  ƒ  D]L } | j ƒ  d k rR x1 | j ƒ  D] } | j | ƒ q8 Wq | j | ƒ q W| S)zçReturn a list of undisordered residues.

        Some Residue objects hide several disordered residues
        (DisorderedResidue objects). This method unpacks them,
        ie. it returns a list of simple Residue objects.
        é   )Zget_listZis_disorderedZdisordered_get_listÚappend)r   Zunpacked_listZresidueZdresiduer	   r	   r
   Úget_unpacked_list„   s    zChain.get_unpacked_listc             C   s   |  j  | ƒ } t j |  | ƒ S)a0  Return 1 if a residue with given id is present.

        The id of a residue is (hetero flag, sequence identifier, insertion code).

        If id is an int, it is translated to (" ", id, " ") by the _translate_id
        method.

        Arguments:
         - id - (string, int, string) or int

        )r   r   Úhas_id)r   r   r	   r	   r
   r   ”   s    zChain.has_idc             c   s   x |  D] } | Vq Wd S)zReturn residues.Nr	   )r   Úrr	   r	   r
   Úget_residues¥   s    zChain.get_residuesc             c   s1   x* |  j  ƒ  D] } x | D] } | Vq Wq Wd S)zReturn atoms from residues.N)r   )r   r   Úar	   r	   r
   Ú	get_atomsª   s    zChain.get_atomsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r	   r	   r	   r
   r      s   

r   N)r%   ZBio.PDB.Entityr   r   r	   r	   r	   r
   Ú<module>   s   