ó
a#nSc           @   s—   d  d l  Z  d e f d „  ƒ  YZ d  d l m Z e j Z e e d „ Z d „  Z	 d „  Z
 e d k r“ d  d l Z e
 ƒ  \ Z Z e j e ƒ n  d S(	   iÿÿÿÿNt   pySparseIntVectc           B   sÔ   e  Z d  Z d Z i  Z d „  Z d „  Z d „  Z e d „ Z	 e 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(   s6    this class is pretty much obsolete (it's in C++ now) i    c         C   s   | |  _  i  |  _ d  S(   N(   t   sizet	   container(   t   selfR   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __init__   s    	c         C   s%   x | D] } |  | c d 7<q Wd S(   så   
    >>> c1=pySparseIntVect(10)
    >>> c1.UpdateFromSequence((0,1,1,5))
    >>> [x for x in c1]
    [(0, 1), (1, 2), (5, 1)]
    >>> c1.UpdateFromSequence((0,3))
    >>> [x for x in c1]
    [(0, 2), (1, 2), (3, 1), (5, 1)]

    i   N(    (   R   t   seqt   v(    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   UpdateFromSequence   s    c         C   s   i  |  _  |  j | ƒ d S(   s�   
    >>> c1=pySparseIntVect(10)
    >>> c1.InitFromSequence((0,1,1,5))
    >>> [x for x in c1]
    [(0, 1), (1, 2), (5, 1)]

    N(   R   R   (   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   InitFromSequence   s    	c         C   sG   d } x: |  j  j ƒ  D]) } | s/ | | 7} q | t | ƒ 7} q W| S(   sÀ   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c1.Sum()
    10

    >>> c1[2] = -2
    >>> c1.Sum()
    6
    >>> c1.Sum(useAbs=True)
    10
    i    (   R   t   valuest   abs(   R   t   useAbst   resR   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   Sum(   s    c         C   s   |  j  d | ƒ S(   NR   (   R   (   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   GetTotalVal>   s    c         C   s>   t  | t ƒ s t ‚ n  |  j | j k r. d S|  j | j k S(   sÒ   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 3
    >>> c2[2] = 2
    >>> c1 == c2
    False
    >>> c1 == c1
    True
    i    (   t
   isinstanceR    t	   TypeErrorR   R   (   R   t   other(    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __eq__B   s
    	c         C   s§   t  | t ƒ s t ‚ n  |  j | j k r3 t ‚ n  i  } x^ |  j j ƒ  D]M \ } } | j j | d ƒ } | rI | | k  r‰ | | | <q– | | | <qI qI W| |  _ |  S(   sð   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[2] = -2
    >>> c2[5] = 6
    >>> c1 &= c2
    >>> [x for x in c1]
    [(0, 2), (2, -2)]

    i    (   R   R    R   R   t
   ValueErrorR   t	   iteritemst   get(   R   R   t   newCt   idxR   t   ov(    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __iand__W   s    			c         C   sÚ   t  | t ƒ s t ‚ n  |  j | j k r3 t ‚ n  i  } xU |  j j ƒ  D]D \ } } | j j | d ƒ } | | k  rƒ | | | <qI | | | <qI Wx9 | j j ƒ  D]( \ } } | j | ƒ s¡ | | | <q¡ q¡ W| |  _ |  S(   sÿ   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[2] = -2
    >>> c2[5] = 6
    >>> c1 |= c2
    >>> [x for x in c1]
    [(0, 3), (2, 2), (4, 5), (5, 6)]

    i    (	   R   R    R   R   R   R   R   R   t   has_key(   R   R   R   R   R   R   t   k(    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __ior__u   s    			c         C   sÌ   t  | t ƒ s t ‚ n  |  j | j k r3 t ‚ n  i  } xV |  j j ƒ  D]E } d | | <|  j | | | } | r„ | |  j | <qI |  j | =qI Wx3 | D]+ \ } } | j | ƒ s™ | |  j | <q™ q™ W|  S(   s÷   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[2] = -2
    >>> c2[5] = 6
    >>> c1 += c2
    >>> [x for x in c1]
    [(0, 5), (4, 5), (5, 6)]

    i   (   R   R    R   R   R   R   t   keysR   (   R   R   t   seenR   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __iadd__–   s    		
c         C   sÍ   t  | t ƒ s t ‚ n  |  j | j k r3 t ‚ n  i  } xV |  j j ƒ  D]E } d | | <|  j | | | } | r„ | |  j | <qI |  j | =qI Wx4 | D], \ } } | j | ƒ s™ | |  j | <q™ q™ W|  S(   s÷   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[2] = 2
    >>> c2[5] = 6
    >>> c1 -= c2
    >>> [x for x in c1]
    [(0, 1), (4, 5), (5, -6)]

    i   (   R   R    R   R   R   R   R   R   (   R   R   R   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __isub__¶   s    		
c         C   s†   t  | t ƒ s t ‚ n  |  j | j k r3 t ‚ n  xL |  j j ƒ  D]; } |  j | | | } | rt | |  j | <qC |  j | =qC W|  S(   sÂ   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[5] = 6
    >>> c1 *= c2
    >>> [x for x in c1]
    [(0, 6)]

    (   R   R    R   R   R   R   R   (   R   R   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __imul__Ö   s    		c         C   s2   t  |  j ƒ } t j |  j ƒ | _ | | 7} | S(   sÔ   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[5] = 6
    >>> c3 = c2+c1
    >>> [x for x in c3]
    [(0, 5), (4, 5), (5, 6)]

    (   R    R   t   copyt   deepcopyR   (   R   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __add__ï   s    
c         C   s2   t  |  j ƒ } t j |  j ƒ | _ | | 8} | S(   s.  
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[2] = 2
    >>> c2[5] = 6
    >>> c3 = c1-c2
    >>> [x for x in c3]
    [(0, 1), (4, 5), (5, -6)]
    >>> [x for x in c1]
    [(0, 3), (2, 2), (4, 5)]

    (   R    R   R"   R#   R   (   R   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __sub__   s    
c         C   s2   t  |  j ƒ } t j |  j ƒ | _ | | 9} | S(   sñ   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[5] = 6
    >>> c3 = c1*c2
    >>> [x for x in c3]
    [(0, 6)]
    >>> [x for x in c1]
    [(0, 3), (4, 5)]

    (   R    R   R"   R#   R   (   R   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __mul__  s    
c         C   s2   t  |  j ƒ } t j |  j ƒ | _ | | M} | S(   s)  
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[2] = -2
    >>> c2[5] = 6
    >>> c3 = c1 & c2
    >>> [x for x in c3]
    [(0, 2), (2, -2)]
    >>> [x for x in c1]
    [(0, 3), (2, 2), (4, 5)]

    (   R    R   R"   R#   R   (   R   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __and__(  s    
c         C   s2   t  |  j ƒ } t j |  j ƒ | _ | | O} | S(   s8  
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[2] = 2
    >>> c1[4] = 5
    >>> c2=pySparseIntVect(10)
    >>> c2[0] = 2
    >>> c2[2] = -2
    >>> c2[5] = 6
    >>> c3 = c1 | c2
    >>> [x for x in c3]
    [(0, 3), (2, 2), (4, 5), (5, 6)]
    >>> [x for x in c1]
    [(0, 3), (2, 2), (4, 5)]

    (   R    R   R"   R#   R   (   R   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __or__=  s    
c         C   s   |  j  S(   N(   R   (   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __len__S  s    c         C   sP   t  | ƒ |  j k r! t | ‚ n  | d k  r= |  j | } n  |  j j | d ƒ S(   su   
    >>> c1=pySparseIntVect(10)
    >>> c1[0] = 3
    >>> c1[4] = 5
    >>> c1[0]
    3
    >>> c1[1]
    0
    
    i    (   R
   R   t
   IndexErrorR   R   (   R   t   which(    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __getitem__U  s
    c         C   sZ   t  | ƒ |  j k r! t | ‚ n  t | ƒ } | d k  rI |  j | } n  | |  j | <d  S(   Ni    (   R
   R   R*   t   intR   (   R   R+   t   val(    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __setitem__e  s    c         C   s   |  j  j ƒ  S(   sž   
    >>> c=pySparseIntVect(10)
    >>> c[0] = 3
    >>> c[4] = 5
    >>> c[7] = -1
    >>> for idx,v in c:
    ...  print idx,v
    0 3
    4 5
    7 -1

    (   R   R   (   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   __iter__l  s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   t   FalseR   R   R   R   R   R   R    R!   R$   R%   R&   R'   R(   R)   R,   R/   R0   (    (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyR       s.   						!	 	 									(   t   DataStructsc         C   s�   d |  j  d | ƒ | j  d | ƒ } | s5 d } nd | ri t t |  ƒ t | ƒ ƒ | | k  ri d } n" d } |  | @} | j  d | ƒ } d | | } | S(   sô   Implements the DICE similarity metric.

  >>> v1 = DataStructs.IntSparseIntVect(10)
  >>> v2 = DataStructs.IntSparseIntVect(10)
  >>> v1.UpdateFromSequence((1,2,3))
  >>> v2.UpdateFromSequence((1,2,3))
  >>> DiceSimilarity(v1,v2)
  1.0

  >>> v2 = DataStructs.IntSparseIntVect(10)
  >>> v2.UpdateFromSequence((5,6))
  >>> DiceSimilarity(v1,v2)
  0.0

  >>> v1 = DataStructs.IntSparseIntVect(10)
  >>> v2 = DataStructs.IntSparseIntVect(10)
  >>> v1.UpdateFromSequence((1,2,3,4))
  >>> v2.UpdateFromSequence((1,3,5,7))
  >>> DiceSimilarity(v1,v2)
  0.5

  >>> v1 = DataStructs.IntSparseIntVect(10)
  >>> v2 = DataStructs.IntSparseIntVect(10)
  >>> v1.UpdateFromSequence((1,2,3,4,5,6))
  >>> v2.UpdateFromSequence((1,3))
  >>> DiceSimilarity(v1,v2)
  0.5

  g      ð?R   g        g       @(   R   t   mint   len(   t   v1t   v2t   boundsR   t   denomR   t   numert   v3(    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   pyDiceSimilarity~  s    &	+	
c         C   s?   d } x2 |  j  ƒ  j ƒ  D] \ } } | | | | 7} q W| S(   Ng        (   t   GetNonzeroElementsR   (   t   bv1t   bv2R   R   R   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt
   DotProductª  s    c          C   s,   d d  l  }  d d  l } |  j | j d ƒ S(   Niÿÿÿÿt   __main__(   t   doctestt   syst   testmodt   modules(   RD   RE   (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   _test´  s    RC   (   R"   t   objectR    t   rdkitR5   t   DiceSimilarityt   NoneR4   R>   RB   RH   R1   RE   t   failedt   triedt   exit(    (    (    sa   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/DataStructs/SparseIntVect.pyt   <module>   s   ÿ u	,	
	