ó
dIc           @   su  d  d l  Z  d  d l Z d  d l m Z d  d l m Z d  d l m Z d Z d d d „  ƒ  YZ e	 d k rqd  d l  Z  e d	 d
 ƒ Z
 e  j d
 Z e
 j d e ƒ Z xÇ e D]¼ Z e j ƒ  Z
 e
 e k sÒ t ‚ x• e D] Z e j ƒ  Z
 e
 e k sý t ‚ xf e D]^ Z e GHe j ƒ  Z
 e
 e k s-t ‚ x2 e D]* Z e j ƒ  Z
 e
 e k	 r4e
 Ge GHq4q4WqWqÙ Wq® Wn  d S(   iÿÿÿÿN(   t   StructureBuilder(   t   PDBConstructionException(   t   _parse_pdb_header_lists   Parser for PDB files.t	   PDBParserc           B   s_   e  Z d  Z d d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z RS(   s9   
    Parse a PDB file and return a Structure object.
    i   i    c         C   sL   | d k r | |  _ n t ƒ  |  _ d |  _ d |  _ d |  _ | |  _ d S(   s—  
        The PDB parser call a number of standard methods in an aggregated
        StructureBuilder object. Normally this object is instanciated by the
        PDBParser object itself, but if the user provides his own StructureBuilder
        object, the latter is used instead.

        Arguments:
        o PERMISSIVE - int, if this is 0 exceptions in constructing the
        SMCRA data structure are fatal. If 1 (DEFAULT), the exceptions are 
        caught, but some residues or atoms will be missing. THESE EXCEPTIONS 
        ARE DUE TO PROBLEMS IN THE PDB FILE!.
        o structure_builder - an optional user implemented StructureBuilder class. 
        i    N(   t   Nonet   structure_builderR    t   headert   trailert   line_countert
   PERMISSIVE(   t   selfR	   t
   get_headerR   (    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/PDBParser.pyt   __init__   s    			c         C   ss   d |  _ d |  _ |  j j | ƒ t | t ƒ r@ t | ƒ } n  |  j | j	 ƒ  ƒ |  j j
 |  j ƒ |  j j ƒ  S(   s°   Return the structure.

        Arguments:
        o id - string, the id that will be used for the structure
        o file - name of the PDB file OR an open filehandle
        N(   R   R   R   R   t   init_structuret
   isinstancet
   basestringt   opent   _parset	   readlinest
   set_headert   get_structure(   R
   t   idt   file(    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/PDBParser.pyR   4   s    		c         C   s   |  j  S(   s   Return the header.(   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/PDBParser.pyR   F   s    c         C   s   |  j  S(   s   Return the trailer.(   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/PDBParser.pyt   get_trailerJ   s    c         C   s.   |  j  | ƒ \ |  _ } |  j | ƒ |  _ d S(   s   Parse the PDB file.N(   t   _get_headerR   t   _parse_coordinatesR   (   R
   t   header_coords_trailert   coords_trailer(    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/PDBParser.pyR   P   s    c   	      C   s¯   |  j  } xm t d t | ƒ ƒ D]V } | j | d ƒ | | } | d d !} | d k sq | d k sq | d k r Pq q W| d | !} | |  _ | | } t | ƒ } | | f S(   s0   Get the header of the PDB file, return the rest.i    i   i   s   ATOM  t   HETATMs   MODEL (   R   t   ranget   lent   set_line_counterR   R   (	   R
   R   R   t   it   linet   record_typeR   R   t   header_dict(    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/PDBParser.pyR   W   s    	
$	
c   '      C   s  d } |  j  } d } d } d2 } d2 } d2 } d2 }	 xÏt d t | ƒ ƒ D]¸}
 | |
 } | d d !} |  j | d } | j | ƒ | d k sœ | d k ró| sÂ | j | ƒ | d 7} d } n  | d d !} | j ƒ  } t | ƒ d k rö | } n
 | d } | d d !} | d d	 !} | d
 d !} y t | d d !ƒ } Wn d } n Xt | d d !j ƒ  d ƒ } | d d !} | d k r®| d k sœ| d k r¥d } q´d } n d } | | | f } y= t	 | d d !ƒ } t	 | d d !ƒ } t	 | d d !ƒ } Wn t
 d | ƒ ‚ n Xt j | | | f d ƒ } y t	 | d d !ƒ } Wn |  j d | ƒ d } n Xy t	 | d d !ƒ } Wn |  j d | ƒ d } n X| d d  !} | | k rÒ| } | j | ƒ n  | | k r@| } | j | ƒ | } | }	 y | j | | | | ƒ Wq§t k
 r<}  |  j |  | ƒ q§Xng | | k sX|	 | k r§| } | }	 y | j | | | | ƒ Wq§t k
 r£}  |  j |  | ƒ q§Xn  y# | j | | | | | | | ƒ Wq÷t k
 rï}  |  j |  | ƒ q÷Xn| d! k ryt t	 | d" d# !| d# d$ !| d% d& !| d& d' !| d' d( !| d( d) !f ƒ }! t j |! d ƒ d* j d ƒ }" | j |" ƒ n~| d+ k r±| j | ƒ | d 7} d } d2 } d2 } nF| d, k sÉ| d- k rá|  j | |  _ | | S| d. k rd } d2 } d2 } nõ | d/ k rˆt t	 | d" d# !| d# d$ !| d$ d& !| d& d' !| d' d( !| d( d) !f ƒ }# t j |# d ƒ d* j d ƒ }$ | j |$ ƒ no | d0 k r÷t t	 | d d !| d d1 !| d d !| d d !| d d !f ƒ }% t j |% d ƒ }& | j |& ƒ n  | d } qI W|  j | |  _ g  S(3   s&   Parse the atomic data in the PDB file.i    i   i   s   ATOM  R   i   i   i   i   i   i   i   i   i   t   HOHt   WATt   Wt   Ht    i   i&   i.   i6   s,   Invalid or missing coordinate(s) at line %i.t   fi<   s   Invalid or missing occupancyg        iB   s   Invalid or missing B factoriH   iL   t   ANISOUi   i#   i*   i+   i1   i8   i?   iF   g     ˆÃ@s   MODEL s   END   t   CONECTt   ENDMDLt   SIGUIJt   SIGATMi-   N(   R   R   R   R   R   R   t
   init_modelt   splitt   intt   floatt   PDBContructionErrort   numpyt   arrayt   _handle_PDB_exceptiont   init_segt
   init_chaint   init_residueR   t	   init_atomt   mapt   astypet
   set_anisout
   set_siguijt
   set_sigatm('   R
   R   t   local_line_counterR   t   current_model_idt
   model_opent   current_chain_idt   current_segidt   current_residue_idt   current_resnameR    R!   R"   t   global_line_countert   fullnamet
   split_listt   namet   altloct   resnamet   chainidt   serial_numbert   resseqt   icodet   hetero_flagt
   residue_idt   xt   yt   zt   coordt	   occupancyt   bfactort   segidt   messaget   anisout   anisou_arrayt   siguijt   siguij_arrayt   sigatmt   sigatm_array(    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/PDBParser.pyR   g   sÜ    	

		

			
	
#K
		KAc         C   s:   d | | f } |  j  r* d | GHd GHn t | ƒ ‚ d S(   sÑ   
        This method catches an exception that occurs in the StructureBuilder
        object (if PERMISSIVE==1), or raises it again, this time adding the 
        PDB line number to the error message.
        s   %s at line %i.s   PDBConstructionException: %ssO   Exception ignored.
Some atoms or residues may be missing in the data structure.N(   R	   R   (   R
   RZ   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/PDBParser.pyR6   ì   s
    		N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R6   (    (    (    s„   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/PDBParser.pyR      s   						…t   __main__R	   i   t   scr(    (   t   sysR4   R    t   PDBExceptionsR   t   parse_pdb_headerR   Rc   R   Ra   t   pt   argvt   filenameR   t   st   mt
   get_parentt   AssertionErrort   ct   rt   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/PDBParser.pyt   <module>   s2   æ