o
    RŀgF                     @   sh   d Z ddlmZ ddlmZ ddlmZ ddlmZ er(ddlm	Z	 ddl
mZ G dd	 d	ed
 ZdS )z'Chain class, used in Structure objects.    )Optional)TYPE_CHECKING)Entity)IC_Chain)Model)Residuec                   @   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(ded d!fd"d#Z		!	!d)ded$ee d%ee fd&d'Zd!S )*ChainzDefine 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   A/var/www/html/myenv/lib/python3.10/site-packages/Bio/PDB/Chain.pyr      s   zChain.__init__c                 C   sJ   t |tr#| jdkr|jdkrdS | jdkr|jdkrdS | j|jkS tS )z(Validate if id is greater than other.id. r      
isinstancer   r   NotImplementedr   otherr   r   r   __gt__#      
zChain.__gt__c                 C   sJ   t |tr#| jdkr|jdkrdS | jdkr|jdkrdS | j|jkS tS )z1Validate if id is greater or equal than other.id.r   r   r   r   r   r   r   r   __ge__/   r   zChain.__ge__c                 C   sJ   t |tr#| jdkr|jdkrdS | jdkr|jdkrdS | j|jk S tS )z%Validate if id is less than other.id.r   r   r   r   r   r   r   r   __lt__;   r   zChain.__lt__c                 C   sJ   t |tr#| jdkr|jdkrdS | jdkr|jdkrdS | j|jkS tS )z.Validate if id is less or equal than other id.r   r   r   r   r   r   r   r   __le__G   r   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   intr   r   r   r   _translate_idS   s   

zChain._translate_idc                 C      |  |}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!   e   s   
zChain.__getitem__c                 C   r    )zCheck 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"   s      
zChain.__contains__c                 C   r    )zWDelete item.

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

        )r   r   __delitem__r   r   r   r   r$   }   r#   zChain.__delitem__c                 C   s   d|    dS )zReturn the chain identifier.z
<Chain id=>)get_idr   r   r   r   __repr__   s   zChain.__repr__c                 C   sF   g }|   D ]}| dkr| D ]}|| qq|| q|S )zReturn 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.
           )get_listis_disordereddisordered_get_listappend)r   unpacked_listresiduedresiduer   r   r   get_unpacked_list   s   zChain.get_unpacked_listc                 C   r    )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_idr   r   r   r   r2      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    |   D ]}|E dH  qdS )zReturn atoms from residues.N)r3   )r   rr   r   r   	get_atoms   s   zChain.get_atomsFverbosereturnNc                 C   s$   | j s	t| || _ | j j|d dS )zCreate/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
        )r6   N)r   r   atom_to_internal_coordinates)r   r6   r   r   r   r8      s   z"Chain.atom_to_internal_coordinatesstartfinc                 C   sB   | j r| j j|||d dS | jdu rdn| jj}td|| f )a  Create/update atom coordinates from internal coordinates.

        :param verbose bool: default False
            describe runtime problems
        :param: start, fin integers
            optional sequence positions for begin, end of subregion to process.
            N.B. this activates serial residue assembly, <start> residue CA will
            be at origin
        :raises Exception: if any chain does not have .internal_coord attribute
        )r6   r9   r:   Nz<Structure %s Chain %s does not have internal coordinates set)r   internal_to_atom_coordinatesparent	Exception)r   r6   r9   r:   	structurer   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(   r1   r2   r3   r5   boolr8   r   r   r;   r   r   r   r   r      s6    

r   )r   r   N)rB   typingr   r   Bio.PDB.Entityr   Bio.PDB.internal_coordsr   Bio.PDB.Modelr   Bio.PDB.Residuer   r   r   r   r   r   <module>   s   