
    Ri                     p    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	ed
         Zy)z'Chain class, used in Structure objects.    )Optional)TYPE_CHECKING)Entity)IC_Chain)Model)Residuec                       e 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deddfdZ	 	 	 ddededz  dedz  fdZy)ChainzDefine Chain class.

    Chain is an object of type Entity, stores residues and includes a method to
    access atoms from residues.
    c                 L    d| _         d| _        t        j                  | |       y)zInitialize the class.CN)levelinternal_coordr   __init__selfids     E/home/agent/.friday_env/lib/python3.12/site-packages/Bio/PDB/Chain.pyr   zChain.__init__   s    
"b!    c                     t        |t              rW| j                  dk(  r|j                  dk7  ry| j                  dk7  r|j                  dk(  ry| j                  |j                  kD  S t        S )z(Validate if id is greater than other.id. r      
isinstancer
   r   NotImplementedr   others     r   __gt__zChain.__gt__#   U    eU#ww#~%((c/CEHHOww))!!r   c                     t        |t              rW| j                  dk(  r|j                  dk7  ry| j                  dk7  r|j                  dk(  ry| j                  |j                  k\  S t        S )z1Validate if id is greater or equal than other.id.r   r   r   r   r   s     r   __ge__zChain.__ge__/   U    eU#ww#~%((c/CEHHOww%((**!!r   c                     t        |t              rW| j                  dk(  r|j                  dk7  ry| j                  dk7  r|j                  dk(  ry| j                  |j                  k  S t        S )z%Validate if id is less than other.id.r   r   r   r   r   s     r   __lt__zChain.__lt__;   r   r   c                     t        |t              rW| j                  dk(  r|j                  dk7  ry| j                  dk7  r|j                  dk(  ry| j                  |j                  k  S t        S )z.Validate if id is less or equal than other id.r   r   r   r   r   s     r   __le__zChain.__le__G   r!   r   c                 z    	 t        |      }t        |t               rd|df}|S # t        $ r Y "t        $ r Y ,w xY w)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   )int
ValueError	TypeErrorr   r   s     r   _translate_idzChain._translate_idS   sK    	RB
 b#r3B	  	 		s   $ 	:::c                 P    | 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   s     r   r,   zChain.__getitem__k   s'     #!!$++r   c                 P    | j                  |      }t        j                  | |      S )zCheck if a residue with given id is present in this chain.

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

        )r*   r   __contains__r   s     r   r.   zChain.__contains__y   s'     #""4,,r   c                 P    | j                  |      }t        j                  | |      S )zWDelete item.

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

        )r*   r   __delitem__r   s     r   r0   zChain.__delitem__   s'     #!!$++r   c                 *    d| j                          dS )zReturn the chain identifier.z
<Chain id=>)get_idr   s    r   __repr__zChain.__repr__   s    DKKM?!,,r   c                     g }| j                         D ]M  }|j                         dk(  r'|j                         D ]  }|j                  |        =|j                  |       O |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dresidues       r   get_unpacked_listzChain.get_unpacked_list   sm     }} 	.G$$&!+ ' ; ; = 3H!((23 $$W-	. r   c                 P    | 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_idr   s     r   rA   zChain.has_id   s%     #}}T2&&r   c              #   $   K   | E d{    y7 w)zReturn residues.N r4   s    r   get_residueszChain.get_residues   s     s   c              #   N   K   | j                         D ]  }|E d{     y7 w)zReturn atoms from residues.N)rD   )r   rs     r   	get_atomszChain.get_atoms   s(     ""$ 	ALL	s   %#%verbosereturnNc                 v    | j                   st        | |      | _         | j                   j                  |       y)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
        )rH   N)r   r   atom_to_internal_coordinates)r   rH   s     r   rK   z"Chain.atom_to_internal_coordinates   s3     """*4"9D888Ir   startfinc                     | j                   r| j                   j                  |||       y| j                  dn| j                  j                  }t        d|d| d      )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
        )rH   rL   rM   Nz
Structure z Chain z' does not have internal coordinates set)r   internal_to_atom_coordinatesparent	Exception)r   rH   rL   rM   	structures        r   rO   z"Chain.internal_to_atom_coordinates   s`      <<u# =  !% 39K9KId$ r   )F)FNN)__name__
__module____qualname____doc__r   r   r    r#   r%   r*   r,   r.   r0   r5   r?   rA   rD   rG   boolrK   r'   rO   rC   r   r   r
   r
      s    "
"
"
"
"0,-,- '"

JD 
JT 
J  	 Tz 4Z	r   r
   )r   r   N)rV   typingr   r   Bio.PDB.Entityr   Bio.PDB.internal_coordsr   Bio.PDB.Modelr   Bio.PDB.Residuer   r
   rC   r   r   <module>r]      s3    .    ! ,#'MF%& Mr   