ó
"ĪIc           @   s~  d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z d  d l m Z m Z d Z d	 d
 d d d d d d d d d d d d d d d d d d g Z d Z e Z i  Z i  Z i  Z i  Z xS e d d  D]B Z e e Z e e Z e e e <e e e <e e e <e e e <qų Wd    Z d!   Z d"   Z d#   Z d$   Z  d%   Z! d d&  Z" d' e# f d(     YZ$ d) d8 d*     YZ% d+ e% f d,     YZ& d- e% f d.     YZ' e( d/ k rzd  d0 l) Z) d  d1 l* m+ Z+ e+ d2 d3  Z, e, j- d4 e) j. d3  Z/ e'   Z0 d5 GHx" e0 j1 e/  D] Z2 e2 j3   GHqCWx& e0 j1 e/ d  D] Z2 e2 j3   GHqlWx* e0 j1 e/ d d6  D] Z2 e2 j3   GHqWx= e0 j1 e/  D], Z2 x# e2 j4   D] \ Z5 Z6 e5 Ge6 GHqŃWq¾We&   Z0 d7 GHx" e0 j1 e/  D] Z2 e2 j3   GHqWx& e0 j1 e/ d  D] Z2 e2 j3   GHq5Wx- e0 j1 e/ d d6  D] Z2 e2 j3   GHqbWn  d0 S(9   i’’’’(   t
   StringType(   t   ProteinAlphabet(   t   Seq(   t   to_one_letter_code(   t   PDBException(   t   Residuet   DisorderedResidue(   t   calc_dihedralt
   calc_anglesø   
Polypeptide related classes (construction and representation).

Example:

    >>> ppb=PPBuilder()
    >>> for pp in ppb.build_peptides(structure):
    >>>     print pp.get_sequence()
t   ALAt   CYSt   ASPt   GLUt   PHEt   GLYt   HISt   ILEt   LYSt   LEUt   METt   ASNt   PROt   GLNt   ARGt   SERt   THRt   VALt   TRPt   TYRt   ACDEFGHIKLMNPQRSTVWYi    i   c         C   s   t  |  S(   sU   
    Index to corresponding one letter amino acid name.
    For example: 0 to A.
    (   t   dindex_to_1(   t   index(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   index_to_one/   s    c         C   s   t  |  S(   s<   
    One letter code to index.
    For example: A to 0.
    (   t   d1_to_index(   t   s(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   one_to_index6   s    c         C   s   t  |  S(   sY   
    Index to corresponding three letter amino acid name.
    For example: 0 to ALA.
    (   t   dindex_to_3(   t   i(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   index_to_three=   s    c         C   s   t  |  S(   s@   
    Three letter code to index.
    For example: ALA to 0.
    (   t   d3_to_index(   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/Polypeptide.pyt   three_to_indexD   s    c         C   s   t  |  } t | S(   sJ   
    Three letter code to one letter code.
    For example: ALA to A.
    (   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/Polypeptide.pyt   three_to_oneK   s    
c         C   s   t  |  } t | S(   sJ   
    One letter code to three letter code.
    For example: A to ALA.
    (   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/Polypeptide.pyt   one_to_threeS   s    
c         C   sQ   t  |   t k s! |  j   }  n  |  j   }  | r@ t j |   St j |   Sd S(   s  
    Return 1 if residue object/string is an amino acid.

    @param residue: a L{Residue} object OR a three letter amino acid code
    @type residue: L{Residue} or string

    @param standard: flag to check for the 20 AA (default false) 
    @type standard: boolean
    N(   t   typeR    t   get_resnamet   upperR'   t   has_keyR   (   t   residuet   standard(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   is_aa[   s    
t   Polypeptidec           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s?   
    A polypeptide is simply a list of L{Residue} objects.
    c         C   s2   g  } x% |  D] } | d } | j  |  q W| S(   s\   
        @return: the list of C-alpha atoms
        @rtype: [L{Atom}, L{Atom}, ...]
        t   CA(   t   append(   t   selft   ca_listt   rest   ca(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   get_ca_listr   s
    
c         C   s  g  } t  |   } xrt d |  D]a} |  | } y4 | d j   } | d j   } | d j   } Wn1 | j d	  d | j d <d | j d <q" n X| d k rš |  | d } y) | d j   }	 t |	 | | |  }
 Wqö d }
 qö Xn d }
 | | d k  rP|  | d } y) | d j   } t | | | |  } WqVd } qVXn d } | j |
 | f  |
 | j d <| | j d <q" W| S(
   s<   
        Return the list of phi/psi dihedral angles
        i    t   NR3   t   Ct   PHIt   PSIi   N(   NN(   t   lent   ranget
   get_vectorR4   t   Nonet   xtraR   (   R5   t   pplt   lngR%   R7   t   nR8   t   ct   rpt   cpt   phit   rnt   nnt   psi(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   get_phi_psi_list}   sB    
c         C   sĻ   |  j    } g  } x¶ t d t |  d  D] } | | | | d | | d | | d g } t d   |  } | \ } } } }	 t | | | |	  }
 | j |
  | | d j   } |
 | j d <q, W| S(   s`   
        Return list of tau torsions angles for all 4 consecutive
        Calpha atoms.
        i    i   i   i   c         S   s
   |  j    S(   N(   R@   (   t   a(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   <lambda>µ   s    t   TAU(   R9   R?   R>   t   mapR   R4   t
   get_parentRB   (   R5   R6   t   tau_listR%   t	   atom_listt   vector_listt   v1t   v2t   v3t   v4t   tauR7   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   get_tau_list¬   s     .c         C   s¾   g  } |  j    } x„ t d t |  d  D] } | | | | d | | d g } t d   |  } | \ } } } t | | |  }	 | j |	  | | d j   }
 |	 |
 j d <q, W| S(   sY   
        Return list of theta angles for all 3 consecutive
        Calpha atoms.
        i    i   i   c         S   s
   |  j    S(   N(   R@   (   RN   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyRO   Ē   s    t   THETA(   R9   R?   R>   RQ   R   R4   RR   RB   (   R5   t
   theta_listR6   R%   RT   RU   RV   RW   RX   t   thetaR7   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   get_theta_list¾   s     #c         C   sb   d } xF |  D]> } | j    } t j |  r; t | } n d } | | } q Wt | t  } | S(   sh   
        Return the AA sequence.

        @return: polypeptide sequence 
        @rtype: L{Seq}
        t    t   X(   R,   R   R.   R   R   (   R5   R"   R7   t   resnamet   seq(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   get_sequenceŠ   s    c         C   s<   |  d j    d } |  d j    d } d | | f } | S(   s   
        Return <Polypeptide start=START end=END>, where START
        and END are sequence identifiers of the outer residues.
        i    i   i’’’’s   <Polypeptide start=%s end=%s>(   t   get_id(   R5   t   startt   endR"   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   __repr__ā   s    (	   t   __name__t
   __module__t   __doc__R9   RM   R[   R_   Rd   Rh   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyR2   n   s   		/			t
   _PPBuilderc           B   s,   e  Z d  Z d   Z d   Z d d  Z RS(   sÆ   
    Base class to extract polypeptides.
    It checks if two consecutive residues in a chain 
    are connected. The connectivity test is implemented by a 
    subclass.
    c         C   s   | |  _  d S(   sE   
        @param radius: distance
        @type radius: float
        N(   t   radius(   R5   Rm   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   __init__ó   s    c         C   s   t  |  r d Sd Sd S(   s&   Check if the residue is an amino acid.i   i    N(   R1   (   R5   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/Polypeptide.pyt   _acceptś   s    i   c         C   sH  |  j  } |  j } | j   } | d k rC | d } | j   } n? | d k r^ | j   } n$ | d k rv | g } n t d   g  } x¹ | D]± }	 t |	  }
 |
 j   } d } x |
 D] } | rß | |  rß | } qŗ n  | | |  r0| d k r t   } | j	 |  | j	 |  n  | j	 |  n d } | } qŗ Wq W| S(   s  
        Build and return a list of Polypeptide objects.

        @param entity: polypeptides are searched for in this object
        @type entity: L{Structure}, L{Model} or L{Chain}

        @param aa_only: if 1, the residue needs to be a standard AA
        @type aa_only: int
        t   Si    t   MR;   s+   Entity should be Structure, Model or Chain.N(
   t   _is_connectedRo   t	   get_levelt   get_listR   t   itert   nextRA   R2   R4   (   R5   t   entityt   aa_onlyt   is_connectedt   acceptt   levelt   modelt
   chain_listt   pp_listt   chaint   chain_itt   prevt   ppRv   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   build_peptides  s:    
		
	(   Ri   Rj   Rk   Rn   Ro   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/Polypeptide.pyRl   ģ   s   		t   CaPPBuilderc           B   s#   e  Z d  Z d d  Z d   Z RS(   s3   
    Use CA--CA distance to find polypeptides.
    g333333@c         C   s   t  j |  |  d  S(   N(   Rl   Rn   (   R5   Rm   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyRn   2  s    c   
      C   sĆ   x' | | g D] } | j  d  s d Sq W| d } | d } | j   rY | j   } n	 | g } | j   r} | j   } n	 | g } x6 | D]. } x% | D] }	 | |	 |  j k  r d Sq Wq Wd S(   NR3   i    i   (   t   has_idt   is_disorderedt   disordered_get_listRm   (
   R5   R   Rv   t   rRE   t   pt   nlistt   plistRK   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/Polypeptide.pyRr   5  s     

		(   Ri   Rj   Rk   Rn   Rr   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyR   .  s   t	   PPBuilderc           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s1   
    Use C--N distance to find polypeptides.
    gĶĢĢĢĢĢü?c         C   s   t  j |  |  d  S(   N(   Rl   Rn   (   R5   Rm   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyRn   O  s    c         C   s;  | j  d  s d S| j  d  s& d S|  j } | d } | d } | j   r^ | j   } n	 | g } | j   r | j   } n	 | g } x© | D]” } x | D] }	 | j   }
 |	 j   } |
 | k sį |
 d k sį | d k r | | |	  r/| j   r| j |  n  | j   r(| j |
  n  d Sq q Wq Wd S(   NR;   i    R:   t    i   (   R   t
   _test_distR   R   t
   get_altloct   disordered_select(   R5   R   Rv   t	   test_distRF   RE   t   clistR   RK   t   cct   n_altloct   c_altloc(    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyRr   R  s2    	

		$c         C   s   | | |  j  k  r d Sd Sd S(   s)   Return 1 if distance between atoms<radiusi   i    N(   Rm   (   R5   RF   RE   (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyR   u  s    (   Ri   Rj   Rk   Rn   Rr   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/Polypeptide.pyR   K  s   	#t   __main__N(   t	   PDBParsert
   PERMISSIVEi   t   scrs   C-Nt   As   CA-CA(    (7   t   typesR    t   Bio.AlphabetR   t   Bio.SeqR   t   Bio.SCOP.RafR   t   Bio.PDB.PDBExceptionsR   t   Bio.PDB.ResidueR   R   t   VectorR   R   Rk   t   standard_aa_namest   aa1t   aa3R!   R   R'   R$   R?   R%   t   n1t   n3R    R#   R&   R(   R)   R*   R1   t   listR2   Rl   R   R   Ri   t   syst   Bio.PDB.PDBParserR   R   t   get_structuret   argvR"   t   ppbR   R   Rd   RM   RI   RL   (    (    (    s   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/Polypeptide.pyt   <module>   st   





						~B2		