
:>"^  ã               @   s¦   d  Z  d d l Z d d l m 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 <Gd d „  d e ƒ Z
 Gd d „  d e ƒ Z d S)z)Residue class, used by Structure objects.é    N)ÚBiopythonDeprecationWarning)ÚPDBConstructionException)ÚEntityÚDisorderedEntityWrapperé   ÚNé   ÚCAé   ÚCé   ÚOc               @   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 S)ÚResiduez4Represents a residue. A Residue object stores atoms.c             C   s8   d |  _  d |  _ | |  _ | |  _ t j |  | ƒ d S)zInitialize the class.ÚRr   N)ÚlevelÚ
disorderedÚresnameÚsegidr   Ú__init__)ÚselfÚidr   r   © r   ú4/tmp/pip-build-ww9dw3qa/biopython/Bio/PDB/Residue.pyr      s
    				zResidue.__init__c             C   s;   |  j  ƒ  } |  j ƒ  \ } } } | | | | 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   sE   | j  ƒ  } |  j | ƒ r1 t d | |  f ƒ ‚ t j |  | ƒ 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!   t  j d t ƒ |  j j ƒ  d S)zÓSort child atoms.

        Atoms N, CA, C, O always come first, thereafter alphabetically
        by name, with any alternative location specifier for disordered
        atoms (altloc) as a tie-breaker.
        zˆThe custom sort() method will be removed in the future in favour of rich comparison methods. Use the built-in sorted() function instead.N)ÚwarningsÚwarnr   Z
child_listÚsort)r   r   r   r   r$   7   s    zResidue.sortc             C   s   d |  _  d S)zSet the disordered flag.r   N)r   )r   r   r   r   Úflag_disorderedE   s    zResidue.flag_disorderedc             C   s   |  j  S)z2Return 1 if the residue contains disordered atoms.)r   )r   r   r   r   Úis_disorderedI   s    zResidue.is_disorderedc             C   s   |  j  S)zReturn the residue name.)r   )r   r   r   r   r   M   s    zResidue.get_resnamec             C   sS   |  j  ƒ  } g  } x: | D]2 } | j ƒ  r> | | j ƒ  7} q | j | ƒ 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_listQ   s    zResidue.get_unpacked_listc             C   s   |  j  S)zReturn the segment identifier.)r   )r   r   r   r   Ú	get_segid\   s    zResidue.get_segidc             c   s   x |  D] } | Vq Wd S)zReturn atoms.Nr   )r   Úar   r   r   Ú	get_atoms`   s    zResidue.get_atomsc             c   s*   t  j d t ƒ x |  D] } | Vq Wd S)zReturn atom.z{`get_atom` has been deprecated and we intend to remove it in a future release of Biopython. Please use `get_atoms` instead.N)r"   r#   r   )r   r+   r   r   r   Úget_atome   s
    zResidue.get_atomN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r$   r%   r&   r   r)   r*   r,   r-   r   r   r   r   r      s   r   c               @   sR   e  Z d  Z 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  j |  | ƒ d S)zInitialize the class.N)r   r   )r   r   r   r   r   r   w   s    zDisorderedResidue.__init__c             C   s;   |  j  ƒ  } |  j ƒ  \ } } } | | | | f } d | S)z*Return disordered residue full identifier.z0<DisorderedResidue %s het=%s resseq=%i icode=%s>)r   r   )r   r   r   r   r   r   r   r   r   r   {   s    zDisorderedResidue.__repr__c             C   sy   |  j  ƒ  } | j ƒ  d k sh | j ƒ  } | j ƒ  \ } } } | j | ƒ t d | | | | f ƒ ‚ | j | ƒ 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    ‚   s    zDisorderedResidue.addc             C   s%   x |  j  ƒ  D] } | j ƒ  q Wd S)z,Sort the atoms in the child Residue objects.N)r'   r$   )r   r3   r   r   r   r$   ’   s    zDisorderedResidue.sortc             C   sV   | j  ƒ  } |  j ƒ  } | j | ƒ |  j | ƒ s; t ‚ | |  | <|  j | ƒ 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ÚAssertionErrorZdisordered_select)r   r3   r   Úchainr   r   r   Údisordered_add—   s    
z DisorderedResidue.disordered_addN)	r.   r/   r0   r1   r   r   r    r$   r6   r   r   r   r   r2   p   s   r2   )r1   r"   ZBior   ZBio.PDB.PDBExceptionsr   ZBio.PDB.Entityr   r   Z_atom_name_dictr   r2   r   r   r   r   Ú<module>   s   



X