ó
°™xTc           @   s  d  d l  m Z d  d l Z d  d l Z d  d l Z e j j d ƒ Z	 d  d l
 Td  d l m Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d d „ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z e e d d d „ Z d S(   iÿÿÿÿ(   t   divisionNt   mmtbx_geometry_asa_ext(   t   *(   t   altlocc      	   C   sZ   t  j d t d | j d | | j j ƒ  j ƒ  | d |  ƒ d | j d t  j d | ƒ ƒ S(   Nt   datat   centret   radiust   indext   coordinatest   altidt   atom(   R   t   Descriptiont   spheret   xyzt   elementt   stript
   capitalizet	   altid_for(   R   R
   t
   radius_fort   probe(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   create_description   s    				c         C   sI   t  j d |  ƒ } t  j d | ƒ } x | D] } | j d | ƒ q+ W| S(   Nt   factoryt   indexert	   processor(   R   t   Indexert   Insertert   accept(   R   t   descriptionsR   t   insertert   d(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   create_and_populate_indexer   s
    c         C   s   t  d t j d |  ƒ S(   NR   R   (   R   t   indexingt   linear_spheres(   R   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   get_linear_indexer_for%   s    	c            s+   t  d |  ƒ ‰  t d ‡  f d †  d |  ƒ S(   NR   R   c              s   t  j d ˆ  d d ƒ S(   Nt	   voxelizert   margini   (   R   t   hash_spheres(    (   R"   (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   <lambda>1   s    (   t   get_voxelizer_forR   (   R   (    (   R"   s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   get_hash_indexer_for-   s    c         C   s   t  d |  ƒ S(   NR   (   R!   (   R   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   get_optimal_indexer_for6   s    i   c         C   sz   g  |  D] } | j  j ^ q } t | Œ  \ } } } t | ƒ t | ƒ t | ƒ f } t j j j d | d | | | f ƒ S(   Nt   baset   step(   R   t   lowt   zipt   mint   mmtbxt   geometryt   shared_typesR"   (   R   R*   R   t   lowst   low_xst   low_yst   low_zsR+   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyR&   ;   s    !t   CompositeCheckerBuilderc           B   s   e  Z d  Z d „  Z RS(   s#   
  Finds neighbours for a sphere
  c         C   sƒ   t  j d | ƒ } | j d | ƒ t j ƒ  |  _ t j d | j ƒ } x6 | j D]+ } |  j j	 d t j
 d | d | ƒ ƒ qP Wd  S(   NR   R   t   objectt
   neighbourst   ranget	   predicate(   R   t
   AggregatorR   t   accessibilityt   pythagorean_checkert   checkert   overlap_equality_predicateR   t   rangest   addt   filter(   t   selfR   t   descriptionR   t   predt   r(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   __init__M   s    (   t   __name__t
   __module__t   __doc__RF   (    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyR5   H   s   t   SeparateCheckerBuilderc           B   s8   e  Z d  Z d „  Z d „  Z d „  Z e d „  ƒ Z RS(   s#   
  Finds neighbours for a sphere
  c         C   s5   | |  _  t j ƒ  |  _ i  |  _ | j d |  ƒ d  S(   NR   (   R   R;   R<   t   regulart   altlocsR   (   RB   R   RC   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyRF   `   s    		c      
   C   sœ   |  j  d |  j j d | d | d |  j ƒ xj |  j j j ƒ  D]V \ } } t j ƒ  } |  j  d | d | d | d | ƒ | j ƒ  r> | |  j | <q> q> Wd  S(   NR   R   R   R=   (   t   append_neighboursR   RK   RL   t   itemsR;   R<   R7   (   RB   R   R   t
   identifierR   R=   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   process_regularh   s    	
	c      
   C   su   |  j  d |  j j d | d | d |  j ƒ t j ƒ  |  j | <|  j  d |  j j | d | d | d |  j | ƒ d  S(   NR   R   R   R=   (   RM   R   RK   R;   R<   RL   (   RB   R   R   RO   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   process_altloc~   s    	
	c      	   C   s>   | j  d t j d |  j d | ƒ d t j d | ƒ ƒ ƒ d  S(   NR7   R8   R   R9   R6   (   R@   R;   RA   t   close_toR>   (   R   R   R   R=   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyRM   �   s    		(   RG   RH   RI   RF   RP   RQ   t   staticmethodRM   (    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyRJ   [   s
   			t   AccessibleSurfaceResultc           B   s&   e  Z d  Z d „  Z e d „  ƒ Z RS(   s   
  Result of the calculation
  c         C   s   | |  _  | |  _ d  S(   N(   t   countt	   radius_sq(   RB   RU   RV   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyRF       s    	c         C   s   |  j  |  j S(   N(   RU   RV   (   RB   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   surface¦   s    (   RG   RH   RI   RF   t   propertyRW   (    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyRT   ›   s   	t   AccessibleSurfaceAreasc           B   s5   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z RS(   s(   
  Result of a series of calculations
  c         C   s   | |  _  | |  _ d  S(   N(   t   valuest   unit(   RB   RZ   R[   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyRF   ±   s    	c         C   s   g  |  j  D] } | j ^ q
 S(   N(   RZ   RU   (   RB   t   v(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   points·   s    c         C   s1   d d l  m } |  j | j d „  |  j Dƒ ƒ S(   Niÿÿÿÿ(   t   flexc         s   s   |  ] } | j  Vq d  S(   N(   RW   (   t   .0R\   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pys	   <genexpr>Á   s    (   t   scitbx.array_familyR^   R[   t   doubleRZ   (   RB   R^   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   areas½   s    (   RG   RH   RI   RF   RX   R]   Rb   (    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyRY   ¬   s   	c         C   s‚   t  d |  d | ƒ } t j d t j d | j d t j d | j j d | j j ƒ ƒ d | j	 ƒ } t
 d t | ƒ d	 | j j ƒ S(
   s2   
  Calculates ASA by not worrying about altlocs
  R   RC   R8   t   transformationR   R   R9   RU   RV   (   R5   R;   RA   t	   transformR]   Rc   R   R   R   R=   RT   t   lenRV   (   R   t   samplingRC   t   buildert
   overlapped(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   simple_surface_calculationÅ   s    				c   	      C   sÿ   t  d |  d | ƒ } t j d t j d | j d t j d | j j d | j j ƒ ƒ d | j	 ƒ } | j
 s{ t | ƒ } nk g  } xL | j
 j ƒ  D]; } | j t g  | D] } | d | ƒ r§ | ^ q§ ƒ ƒ q‘ Wt | ƒ t | ƒ } t d	 | d
 | j j ƒ S(   s²   
  For atoms with altloc identifier, use empty altloc + atom with same altloc.
  For atoms with empty altloc, run a calculation for each know altloc and
  average the results.
  R   RC   R8   Rc   R   R   R9   t   pointRU   RV   (   RJ   R;   RA   Rd   R]   Rc   R   R   R   RK   RL   Re   RZ   t   appendt   sumRT   RV   (	   R   Rf   RC   Rg   t   nonoverlappedRU   RZ   R=   t   p(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   altloc_averaged_calculationÜ   s"    					9gffffffö?iÀ  c         C   sÑ   d d l  m } | j j } g  t |  ƒ D]- \ } } t d | d | d | d | ƒ ^ q) }	 | d |	 ƒ }
 d d l m } | j d	 | ƒ } g  |	 D]! } | d
 |
 d | d | ƒ ^ q” } t	 d | d | j
 ƒ S(   Niÿÿÿÿ(   t   van_der_waals_radiiR   R
   R   R   R   (   t   sphere_surface_samplingRU   R   Rf   RC   RZ   R[   (   t   cctbx.eltbxRp   t   vdwt   tablet	   enumerateR   t   mmtbx.geometryRq   t   golden_spiralRY   t	   unit_area(   t   atomst   calculationt   indexer_selectorR   t	   precisionRp   R   t   it   aR   R   Rq   Rf   R   RZ   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt	   calculate  s    =+(   t
   __future__R    t   mmtbx.geometry.primitiveR.   t   mmtbx.geometry.shared_typest   boost.pythont   boostt   pythont
   import_extt   extR   Rv   R   R   R   R!   R'   R(   R&   R6   R5   RJ   RT   RY   Ri   Ro   R   (    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/geometry/asa.pyt   <module>   s,   
						@		(