ó
"˜ÎIc           @   sV   d  d l  m  Z  d  d l m Z m Z d Z d d	 d „  ƒ  YZ d d
 d „  ƒ  YZ d S(   iÿÿÿÿ(   t   copy(   t   PDBConstructionExceptiont   PDBExceptionsˆ   
Base class for Residue, Chain, Model and Structure classes. 
It is a simple container class, with list and dictionary like properties.
t   Entityc           B   s•   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 RS(   s…   
    Basic container object. Structure, Model, Chain and Residue
    are subclasses of Entity. It deals with storage and lookup.
    c         C   s:   | |  _  d  |  _ d  |  _ g  |  _ i  |  _ i  |  _ d  S(   N(   t   idt   Nonet   full_idt   parentt
   child_listt
   child_dictt   xtra(   t   selfR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   __init__   s    					c         C   s   t  |  j ƒ S(   s   Return the number of children.(   t   lenR   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   __len__    s    c         C   s   |  j  | S(   s   Return the child with given id.(   R	   (   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   __getitem__$   s    c         c   s   x |  j  D] } | Vq
 Wd S(   s   Iterate over children.N(   R   (   R   t   child(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   __iter__(   s    c         C   s   |  j  S(   sƒ   Return level in hierarchy.

        A - atom
        R - residue
        C - chain
        M - model
        S - structure
        (   t   level(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt	   get_level/   s    	c         C   s   | |  _  d S(   s   Set the parent Entity object.N(   R   (   R   t   entity(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt
   set_parent:   s    c         C   s   d |  _ d S(   s   Detach the parent.N(   R   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   detach_parent>   s    c         C   s5   |  j  | } | j ƒ  |  j  | =|  j j | ƒ d S(   s   Remove a child.N(   R	   R   R   t   remove(   R   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   detach_childB   s    

c         C   sb   | j  ƒ  } |  j | ƒ r4 t d t | ƒ ƒ ‚ n  | j |  ƒ |  j j | ƒ | |  j | <d S(   s   Add a child to the Entity.s   %s defined twiceN(   t   get_idt   has_idR   t   strR   R   t   appendR	   (   R   R   t	   entity_id(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   addI   s    c         c   s   x |  j  D] } | Vq
 Wd S(   s   Return iterator over children.N(   R   (   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   get_iteratorS   s    c         C   s   t  |  j ƒ S(   s&   Return a copy of the list of children.(   R    R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   get_listX   s    c         C   s   |  j  j | ƒ S(   s6   Return 1 if a child with given id exists, otherwise 0.(   R	   t   has_key(   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR   \   s    c         C   s   |  j  S(   s    Return the parent Entity object.(   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt
   get_parent`   s    c         C   s   |  j  S(   s   Return the id.(   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR   d   s    c         C   s‹   |  j  d k r„ |  j ƒ  } | g } |  j ƒ  } x5 | d k	 rg | j ƒ  } | j | ƒ | j ƒ  } q3 W| j ƒ  t | ƒ |  _  n  |  j  S(   sm  Return the full id.

        The full id is a tuple containing all id's starting from
        the top object (Structure) down to the current object. A full id for
        a Residue object e.g. is something like:

        ("1abc", 0, "A", (" ", 10, "A"))

        This corresponds to:

        Structure with id "1abc"
        Model with id 0
        Chain with id "A"
        Residue with id (" ", 10, "A")

        The Residue id indicates that the residue is not a hetero-residue 
        (or a water) beacuse it has a blank hetero field, that its sequence 
        identifier is 10 and its insertion code "A".
        N(   R   R   R   R"   R   t   reverset   tuple(   R   R   t   lR   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   get_full_idh   s    	
(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   R   R    R   R"   R   R&   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR      s    									
					t   DisorderedEntityWrapperc           B   s   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 d „ Z d „  Z RS(   s£  
    This class is a simple wrapper class that groups a number of equivalent
    Entities and forwards all method calls to one of them (the currently selected 
    object). DisorderedResidue and DisorderedAtom are subclasses of this class.
    
    E.g.: A DisorderedAtom object contains a number of Atom objects,
    where each Atom object represents a specific position of a disordered
    atom in the structure.
    c         C   s(   | |  _  i  |  _ d  |  _ d  |  _ d  S(   N(   R   R	   R   t   selected_childR   (   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR   ”   s    			c         C   s(   t  |  d ƒ s t ‚ n  t |  j | ƒ S(   s.   Forward the method call to the selected child.R+   (   t   hasattrt   AttributeErrort   getattrR+   (   R   t   method(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   __getattr__œ   s    	c         C   s   | |  j  | <d S(   s*   Add a child, associated with a certain id.N(   R	   (   R   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   __setitem__¤   s    c         C   s   |  j  S(   s   Return the id.(   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR   ª   s    c         C   s   |  j  j | ƒ S(   s?   Return 1 if there is an object present associated with this id.(   R	   R!   (   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   disordered_has_id®   s    c         C   s.   d |  _ x |  j ƒ  D] } | j ƒ  q Wd S(   s   Detach the parentN(   R   R   t   disordered_get_listR   (   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR   ²   s    	c         C   s   |  j  S(   s   Return parent.(   R   (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR"   ¸   s    c         C   s1   | |  _  x! |  j ƒ  D] } | j | ƒ q Wd S(   s/   Set the parent for the object and its children.N(   R   R3   R   (   R   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR   ¼   s    	c         C   s   |  j  | |  _ d S(   s“   Select the object with given id as the currently active object.

        Uncaught method calls are forwarded to the selected child object.
        N(   R	   R+   (   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   disordered_selectÂ   s    c         C   s
   t  ‚ d S(   s<   This is implemented by DisorderedAtom and DisorderedResidue.N(   t   NotImplementedError(   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   disordered_addÉ   s    c         C   s   d S(   sT   
        Return 2, indicating that this Entity is a collection of Entities.
        i   (    (   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   is_disorderedÍ   s    c         C   s   |  j  j ƒ  } | j ƒ  | S(   s   Return a list of id's.(   R	   t   keyst   sort(   R   R%   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   disordered_get_id_listÓ   s    
c         C   s   | d k r |  j S|  j | S(   ss   Get the child object associated with id.

        If id is None, the currently selected child is returned.
        N(   R   R+   R	   (   R   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   disordered_getÚ   s    c         C   s   |  j  j ƒ  S(   s   Return list of children.(   R	   t   values(   R   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR3   ã   s    N(   R'   R(   R)   R   R0   R1   R   R2   R   R"   R   R4   R6   R7   R:   R   R;   R3   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyR*   Š   s   														N(    (    (   R    t   PDBExceptionsR   R   R)   R   R*   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Entity.pyt   <module>   s   z