B
    ‰°b  ã               @   s<   d Z ddlmZ ddlmZ ddlmZ G dd„ deƒZdS )z'Chain class, used in Structure objects.é    )ÚEntity)ÚIC_Chain)ÚOptionalc               @   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&edd œd!d"„Zd'eee ee d#œ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| _ d| _t | |¡ dS )zInitialize the class.ÚCN)ÚlevelÚinternal_coordr   Ú__init__)ÚselfÚid© r   ú,lib/python3.7/site-packages/Bio/PDB/Chain.pyr	      s    zChain.__init__c             C   sP   t |tƒrH| jdkr"|jdkr"dS | jdkr:|jdkr:dS | j|jkS ntS d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   sP   t |tƒrH| jdkr"|jdkr"dS | jdkr:|jdkr:dS | j|jkS ntS d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   sP   t |tƒrH| jdkr"|jdkr"dS | jdkr:|jdkr:dS | j|jk S ntS dS )z%Validate if id is less than other.id.r   r   r   N)r   r   r   r   )r
   r   r   r   r   Ú__lt__6   s    
zChain.__lt__c             C   sP   t |tƒrH| jdkr"|jdkr"dS | jdkr:|jdkr:dS | j|jkS ntS d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__B   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_idN   s    

zChain._translate_idc             C   s   |   |¡}t | |¡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   |   |¡}t | |¡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   n   s    
zChain.__contains__c             C   s   |   |¡}t | |¡S )zWDelete item.

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

        )r   r   Ú__delitem__)r
   r   r   r   r   r   x   s    
zChain.__delitem__c             C   s   d|   ¡  S )zReturn the chain identifier.z<Chain id=%s>)Zget_id)r
   r   r   r   Ú__repr__‚   s    zChain.__repr__c             C   sN   g }xD|   ¡ D ]8}| ¡ dkr<x&| ¡ D ]}| |¡ q(W q| |¡ 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   |   |¡}t | |¡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   | E dH  dS )zReturn residues.Nr   )r
   r   r   r   Úget_residues©   s    zChain.get_residuesc             c   s    x|   ¡ D ]}|E dH  q
W dS )zReturn atoms from residues.N)r!   )r
   Úrr   r   r   Ú	get_atoms­   s    zChain.get_atomsFN)ÚverboseÚreturnc             C   s$   | j st| |ƒ| _ | j j|d dS )zäCreate/update internal coordinates from Atom X,Y,Z coordinates.

        Internal coordinates are bond length, angle and dihedral angles.

        :param verbose bool: default False
            describe runtime problems
        )r$   N)r   r   Úatom_to_internal_coordinates)r
   r$   r   r   r   r&   ²   s    z"Chain.atom_to_internal_coordinates)r$   ÚstartÚfinc             C   s2   | j r| j j|||d ntd| jj| f ƒ‚dS )aX  Create/update atom coordinates from internal coordinates.

        :param verbose bool: default False
            describe runtime problems
        :param: start, fin lists
            sequence position, insert code for begin, end of subregion to
            process
        :raises Exception: if any chain does not have .pic attribute
        )r$   r'   r(   z<Structure %s Chain %s does not have internal coordinates setN)r   Úinternal_to_atom_coordinatesÚ	ExceptionÚparent)r
   r$   r'   r(   r   r   r   r)   ¾   s    z"Chain.internal_to_atom_coordinates)F)FNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   r   r   r   r   r    r!   r#   Úboolr&   r   r   r)   r   r   r   r   r      s&   

  r   N)r/   ZBio.PDB.Entityr   ZBio.PDB.internal_coordsr   Útypingr   r   r   r   r   r   Ú<module>   s   