ó
ŽïIc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Td  d l m Z d Z d „  Z d d d „ Z d	 „  Z	 d
 „  Z
 d „  Z d e f d „  ƒ  YZ e d k rd  d l Z e ƒ  Z e j d e j d ƒ Z e d Z e e e j d ƒ Z x e D] Z e GHqú Wn  d S(   iÿÿÿÿN(   t   *(   t   AbstractPropertyMapsß  
Calculation of residue depth (using Michel Sanner's MSMS program for the
surface calculation).

Residue depth is the average distance of the atoms of a residue from 
the solvent accessible surface.

Residue Depth:

    rd=ResidueDepth(model, pdb_file)

    print rd[(chain_id, res_id)]

Direct MSMS interface:

    Typical use:

        surface=get_surface("1FAT.pdb")

    Surface is a Numeric array with all the surface 
    vertices.  

    Distance to surface:

        dist=min_dist(coord, surface)

    where coord is the coord of an atom within the volume
    bound by the surface (ie. atom depth).

    To calculate the residue depth (average atom depth
    of the atoms in a residue):

    rd=residue_depth(residue, surface)
c         C   sŠ   t  |  d ƒ } g  } x[ | j ƒ  D]M } | j ƒ  } t | ƒ d k sL q" n  t t | d d !ƒ } | j | ƒ q" W| j ƒ  t j	 | ƒ S(   s4   
    Read the vertex list into a Numeric array.
    t   ri	   i    i   (
   t   opent	   readlinest   splitt   lent   mapt   floatt   appendt   closet   numpyt   array(   t   filenamet   fpt   vertex_listt   lt   slt   vl(    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/ResidueDepth.pyt   _read_vertex_array1   s    
t   pdb_to_xyzrt   msmsc   	      C   sŠ   t  j ƒ  } | d } | |  | f } t j | ƒ t  j ƒ  } | d t  j ƒ  } | | | f } t j | ƒ | d } t | ƒ } | S(   sÐ   
    Return a Numeric array that represents 
    the vertex list of the molecular surface.

    PDB_TO_XYZR --- pdb_to_xyzr executable (arg. to os.system)
    MSMS --- msms executable (arg. to os.system)
    s    %s > %ss#    -probe_radius 1.5 -if %s -of %s > s   .vert(   t   tempfilet   mktempt   ost   systemR   (	   t   pdb_filet   PDB_TO_XYZRt   MSMSt   xyz_tmpt   make_xyzt   surface_tmpt   make_surfacet   surface_filet   surface(    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/ResidueDepth.pyt   get_surfaceA   s    	

c         C   s0   | |  } t  | | d ƒ } t j t | ƒ ƒ S(   s@   
    Return minimum distance between coord
    and surface.
    i   (   t   sumR   t   sqrtt   min(   t   coordR"   t   dt   d2(    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/ResidueDepth.pyt   min_dist^   s    
c         C   sV   |  j  ƒ  } t | ƒ } d } x- | D]% } | j ƒ  } | t | | ƒ } q% W| | S(   sc   
    Return average distance to surface for all
    atoms in a residue, ie. the residue depth.
    i    (   t   get_unpacked_listR   t	   get_coordR*   (   t   residueR"   t	   atom_listt   lengthR(   t   atomR'   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/ResidueDepth.pyt   residue_depthg   s    c         C   s6   |  j  d ƒ s d  S|  d } | j ƒ  } t | | ƒ S(   Nt   CA(   t   has_idt   NoneR,   R*   (   R-   R"   t   caR'   (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/ResidueDepth.pyt   ca_deptht   s
    
t   ResidueDepthc           B   s   e  Z d  Z d „  Z RS(   s:   
    Calculate residue and CA depth for all residues.
    c         C   s  i  } g  } g  } t  j | d ƒ } t | ƒ } x¸ | D]° } t | ƒ sO q7 n  t | | ƒ }	 t | | ƒ }
 | j ƒ  } | j ƒ  j ƒ  } |	 |
 f | | | f <| j | |	 |
 f f ƒ | j | | f ƒ |	 | j	 d <|
 | j	 d <q7 Wt
 j |  | | | ƒ d  S(   Nt   Rt   EXP_RDt	   EXP_RD_CA(   t	   Selectiont   unfold_entitiesR#   t   is_aaR1   R6   t   get_idt
   get_parentR	   t   xtraR   t   __init__(   t   selft   modelR   t
   depth_dictt
   depth_listt
   depth_keyst   residue_listR"   R-   t   rdt   ca_rdt   res_idt   chain_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/ResidueDepth.pyRA      s$    (   t   __name__t
   __module__t   __doc__RA   (    (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/ResidueDepth.pyR7   {   s   t   __main__t   Xi   i    (   R   R   R   t   syst   Bio.PDBR   RN   R   R#   R*   R1   R6   R7   RL   t	   PDBParsert   pt   get_structuret   argvt   sRC   RH   t   item(    (    (    s‡   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/PDB/ResidueDepth.pyt   <module>   s(   
#						
