B
    ‰°b”  ã               @   sh   d Z ddlmZ ddlmZmZ i Zded< ded< ded	< d
ed< G dd„ deƒZG dd„ deƒZdS )z)Residue class, used by Structure objects.é    )ÚPDBConstructionException)ÚEntityÚDisorderedEntityWrapperé   ÚNé   ZCAé   ÚCé   ÚOc               @   sX   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S )ÚResiduez4Represents a residue. A Residue object stores atoms.c             C   s.   d| _ d| _|| _|| _d| _t | |¡ dS )zInitialize the class.ÚRr   N)ÚlevelÚ
disorderedÚresnameÚsegidZinternal_coordr   Ú__init__)ÚselfÚidr   r   © r   ú.lib/python3.7/site-packages/Bio/PDB/Residue.pyr      s    zResidue.__init__c             C   s*   |   ¡ }|  ¡ \}}}||||f}d| S )zReturn the residue full id.z&<Residue %s het=%s resseq=%s icode=%s>)Úget_resnameÚget_id)r   r   ÚhetflagÚresseqÚicodeÚfull_idr   r   r   Ú__repr__!   s    zResidue.__repr__c             C   s2   |  ¡ }|  |¡r"td|| f ƒ‚t | |¡ dS )z}Add an Atom object.

        Checks for adding duplicate atoms, and raises a
        PDBConstructionException if so.
        z#Atom %s defined twice in residue %sN)r   Zhas_idr   r   Úadd)r   ÚatomZatom_idr   r   r   r   (   s
    
zResidue.addc             C   s
   d| _ dS )zSet the disordered flag.r   N)r   )r   r   r   r   Úflag_disordered5   s    zResidue.flag_disorderedc             C   s   | j S )z2Return 1 if the residue contains disordered atoms.)r   )r   r   r   r   Úis_disordered9   s    zResidue.is_disorderedc             C   s   | j S )zReturn the residue name.)r   )r   r   r   r   r   =   s    zResidue.get_resnamec             C   s>   |   ¡ }g }x,|D ]$}| ¡ r,|| ¡ 7 }q| |¡ qW |S )z5Return the list of all atoms, unpack DisorderedAtoms.)Zget_listr!   Údisordered_get_listÚappend)r   Z	atom_listZundisordered_atom_listr   r   r   r   Úget_unpacked_listA   s    
zResidue.get_unpacked_listc             C   s   | j S )zReturn the segment identifier.)r   )r   r   r   r   Ú	get_segidL   s    zResidue.get_segidc             c   s   | E dH  dS )zReturn atoms.Nr   )r   r   r   r   Ú	get_atomsP   s    zResidue.get_atomsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r!   r   r$   r%   r&   r   r   r   r   r      s   	r   c               @   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S )ÚDisorderedResiduezÁDisorderedResidue is a wrapper around two or more Residue objects.

    It is used to represent point mutations (e.g. there is a Ser 60 and a Cys 60
    residue, each with 50 % occupancy).
    c             C   s   t  | |¡ dS )zInitialize the class.N)r   r   )r   r   r   r   r   r   \   s    zDisorderedResidue.__init__c             C   s8   | j r0|  ¡ }|  ¡ \}}}||||f}d| S dS dS )z*Return disordered residue full identifier.z0<DisorderedResidue %s het=%s resseq=%i icode=%s>z<Empty DisorderedResidue>N)Ú
child_dictr   r   )r   r   r   r   r   r   r   r   r   r   `   s    zDisorderedResidue.__repr__c             C   sV   |   ¡ }| ¡ dksH| ¡ }| ¡ \}}}| |¡ td||||f ƒ‚| |¡ dS )zAdd atom to residue.r   z2Blank altlocs in duplicate residue %s (%s, %i, %s)N)Zdisordered_getr!   r   r   r   r   )r   r   Úresiduer   Zhetr   r   r   r   r   r   j   s    
zDisorderedResidue.addc             C   s   x|   ¡ D ]}| ¡  q
W dS )z,Sort the atoms in the child Residue objects.N)r"   Úsort)r   r-   r   r   r   r.   z   s    zDisorderedResidue.sortc             C   s>   |  ¡ }|  ¡ }| |¡ |  |¡r(t‚|| |< |  |¡ dS )zrAdd a residue object and use its resname as key.

        Arguments:
         - residue - Residue object

        N)r   Z
get_parentZ
set_parentZdisordered_has_idÚAssertionErrorÚdisordered_select)r   r-   r   Úchainr   r   r   Údisordered_add   s    
z DisorderedResidue.disordered_addc             C   sX   | j | }| j|k}| j |= | ¡  |rH| j rHtt| j ƒƒ}|  |¡ n| j sTd| _dS )z—Remove a child residue from the DisorderedResidue.

        Arguments:
         - resname - name of the child residue to remove, as a string.

        N)r,   Zselected_childZdetach_parentÚnextÚiterr0   )r   r   r-   Zis_selectedZchildr   r   r   Údisordered_removeŽ   s    


z#DisorderedResidue.disordered_removeN)
r'   r(   r)   r*   r   r   r   r.   r2   r5   r   r   r   r   r+   U   s   
r+   N)	r*   ZBio.PDB.PDBExceptionsr   ZBio.PDB.Entityr   r   Z_atom_name_dictr   r+   r   r   r   r   Ú<module>   s   @