ó
a#nSc           @   sU  d  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 d d l	 Z	 d d l
 Z
 d d l m Z e j ƒ  a e
 j d	 ƒ Z d
 „  Z d d „ Z d „  Z d „  Z d „  Z d d d d „ Z d e _ d „  Z d „  Z d „  Z d „  Z e j e _ d „  Z e j e _ d „  Z  e j! e  _ d „  Z" e j# e" _ d „  Z$ d e$ _ d „  Z% d e% _ d „  Z& d d „ Z' d „  Z( d „  Z) d	 d  „ Z* d! „  Z+ d" „  Z, d# „  Z- d$ „  Z. d% „  Z/ d	 d& „ Z0 d' „  Z1 d( „  Z2 d) „  Z3 d* „  Z4 e j5 e4 _ d+ „  Z6 e j7 e6 _ d, „  Z8 e j9 e8 _ d- „  Z: e j; e: _ d. „  Z< e j= e< _ d/ „  Z> e j? e> _ d0 „  Z@ e jA e@ _ d1 „  ZB e jC eB _ d2 „  ZD e jE eD _ d3 „  ZF e jG eF _ d4 „  ZH e jI eH _ d5 „  ZJ e jK eJ _ d d d6 „ ZL d eL _ d7 „  ZM d8 „  ZN d9 „  ZO d: „  ZP d; d d d< „ ZQ d= eQ _ d S(>   s9    Calculation of topological/topochemical descriptors.



iÿÿÿÿ(   t   Chem(   t   Graphs(   t   rdchem(   t   rdMolDescriptors(   t   pyPeriodicTableN(   t   entropyi   c         C   s   t  j |  ƒ t S(   N(   t   matht   logt   _log2val(   t   x(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _log2   s    i    c         C   s1   | s t  |  ƒ } n t  t j |  d ƒ ƒ } | S(   sQ     *Internal Use Only*

  this is just a row sum of the matrix... simple, neh?

  i   (   t   sumt   numpyt   equal(   t   matt   onlyOnest   res(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _VertexDegrees    s    c         C   s   |  j  ƒ  } | S(   s     *Internal Use Only*

  (   t   GetNumBonds(   t   molt   dMatR   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _NumAdjacencies,   s    c         C   s5   i  } x( |  D]  } | j  | d ƒ d | | <q W| S(   s     *Internal Use Only*

  i    i   (   t   get(   t   arrR   t   v(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _GetCountDict3   s    c   
      C   s  d } t  j d d } xð |  j ƒ  D]â } | j ƒ  } | sB q$ n  | j ƒ  } t  j j | d ƒ } | d k	 rÄ | j ƒ  d } | t	 | ƒ k  r· | | } | d k rÁ | d } qÁ qã | d } n t  j | d }	 |	 | d } | j
 ƒ  G| j ƒ  G| GH| | 7} q$ W| S(   sz    calculate the Hall-Kier alpha value for a molecule

   From equations (58) of Rev. Comp. Chem. vol 2, 367-422, (1991)

  g        t   Ci   i   iÿÿÿÿi   N(   t   PeriodicTablet	   nameTablet   GetAtomst   GetAtomicNumt	   GetSymbolt   hallKierAlphasR   t   Nonet   GetHybridizationt   lent   GetIdx(
   t   mt   alphaSumt   rCt   atomt   atNumt   symbt   alphaVt   hybt   alphat   rA(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyHallKierAlpha=   s(     
c         C   sÍ   | s | d k ru | r6 t j |  d ƒ } | |  _ qu y |  j } Wqu t k
 rq t j |  d ƒ } | |  _ qu Xn  t j | d ƒ } t t j	 |  | ƒ ƒ } | r² t
 j | ƒ St | ƒ t
 j | ƒ Sd S(   sE  This returns the information content of the coefficients of the characteristic
    polynomial of the adjacency matrix of a hydrogen-suppressed graph of a molecule.

    'avg = 1' returns the information content divided by the total population.

    From D. Bonchev & N. Trinajstic, J. Chem. Phys. vol 67, 4517-4533 (1977)

  i    i   N(   R!   R    t   GetDistanceMatrixt   _adjMatt   AttributeErrorR   R   t   absR   t   CharacteristicPolynomialR   t   InfoEntropyR   (   R   t   avgR   t	   forceDMatt   adjMatt   cPoly(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   IpcZ   s    	s   1.0.0c         C   sf   |  j  d ƒ } |  j ƒ  } t |  ƒ } | | } | r\ | | | | d d | d } n d } | S(   sj    Hall-Kier Kappa1 value

   From equations (58) and (59) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  i   i   g        (   R   t   GetNumHeavyAtomst   HallKierAlpha(   R   t   P1t   AR-   t   denomt   kappa(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt	   _pyKappa1x   s    
%c         C   ss   t  t j |  d ƒ ƒ } |  j ƒ  } t |  ƒ } | | d } | ri | | d | | d d | } n d } | S(   sk     Hall-Kier Kappa2 value

   From equations (58) and (60) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  i   i   i    (   R#   R    t   FindAllPathsOfLengthNR;   R<   (   R   t   P2R>   R-   R?   R@   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt	   _pyKappa2Š   s    %c         C   s¨   t  t j |  d ƒ ƒ } |  j ƒ  } t |  ƒ } | | d } | rž | d d k ry | | d | | d d | } q¤ | | d | | d d | } n d } | S(   sq     Hall-Kier Kappa3 value

   From equations (58), (61) and (62) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  i   i   i   i    (   R#   R    RB   R;   R<   (   R   t   P3R>   R-   R?   R@   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt	   _pyKappa3›   s    %%c         C   s   t  j |  ƒ S(   N(   R   t   CalcHallKierAlpha(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   <lambda>¯   s    c         C   s   t  j |  ƒ S(   N(   R   t
   CalcKappa1(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   ±   s    c         C   s   t  j |  ƒ S(   N(   R   t
   CalcKappa2(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   ³   s    c         C   s   t  j |  ƒ S(   N(   R   t
   CalcKappa3(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   µ   s    c         C   st   g  |  j  ƒ  D] } | j ƒ  ^ q } x d | k rD | j d ƒ q( Wt j | d ƒ } t t j d | ƒ ƒ } | S(   sR    From equations (1),(9) and (10) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  i    t   dg      ð?(   R   t	   GetDegreet   removeR   t   arrayR   t   sqrt(   R   R	   t   deltasR   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   Chi0¹   s    %c         C   sŠ   g  |  j  ƒ  D]( } | j ƒ  j ƒ  | j ƒ  j ƒ  ^ q } x d | k rZ | j d ƒ q> Wt j | d ƒ } t t j d | ƒ ƒ } | S(   sS    From equations (1),(11) and (12) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  i    RL   g      ð?(	   t   GetBondst   GetBeginAtomRM   t
   GetEndAtomRN   R   RO   R   RP   (   R   R	   t   c1sR   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   Chi1Æ   s    ;c         C   s   t  j |  j ƒ  ƒ |  j ƒ  S(   N(   t   periodicTablet   GetNOuterElecsR   t   GetTotalNumHs(   R(   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _nValÒ   s    i   c         C   s  g  } t  |  d ƒ r+ |  j d  k	 r+ |  j SxË |  j ƒ  D]½ } | j ƒ  } | d k rÃ t j | ƒ } | j ƒ  } | d k r— | j t	 | | ƒ ƒ qõ | j t	 | | ƒ t	 | | d ƒ ƒ q8 | d k rè | sõ | j d ƒ qõ q8 | j d ƒ q8 W| |  _ | S(   Nt	   _hkDeltasi   i
   g        (
   t   hasattrR\   R!   R   R   RX   RY   RZ   t   appendt   float(   R   t   skipHsR   R(   t   nt   nVt   nHs(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyR\   Õ   s"    ,	c         C   s[   t  |  ƒ } x d | k r+ | j d ƒ q Wd |  _  t t j d t j | ƒ ƒ ƒ } | S(   sS     From equations (5),(9) and (10) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  i    g      ð?N(   R\   RN   R!   R   R   RP   RO   (   R   RQ   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi0ví   s    	"c         C   s€   t  j t |  d d ƒƒ } d } xX |  j ƒ  D]J } | | j ƒ  | | j ƒ  } | d k r. | t  j d | ƒ 7} q. q. W| S(   sT     From equations (5),(11) and (12) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  R`   i    g        g      ð?(   R   RO   R\   RS   t   GetBeginAtomIdxt   GetEndAtomIdxRP   (   R   RQ   R   t   bondR   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi1vø   s    c         C   sž   t  j g  t |  d d ƒD]+ } | d k r> d t  j | ƒ n d ^ q ƒ } d } xD t j |  | d d d ƒD]& } | t  j | t  j | ƒ ƒ 7} qp W| S(   sq    From equations (5),(15) and (16) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  **NOTE**: because the current path finding code does, by design,
  detect rings as paths (e.g. in C1CC1 there is *1* atom path of
  length 3), values of ChiNv with N >= 3 may give results that differ
  from those provided by the old code in molecules that have rings of
  size 3.
  
  R`   i    g        g      ð?i   t   useBonds(   R   RO   R\   RP   R    RB   t   prod(   R   t   ordert   hkdRQ   t   accumt   path(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt	   _pyChiNv_  s
    
M#$c         C   s   t  |  d ƒ S(   sS    From equations (5),(15) and (16) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  i   (   Ro   (   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi2v  s    c         C   s   t  |  d ƒ S(   sS    From equations (5),(15) and (16) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  i   (   Ro   (   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi3v  s    c         C   s   t  |  d ƒ S(   sZ   From equations (5),(15) and (16) of Rev. Comp. Chem. vol 2, 367-422, (1991)
   
  **NOTE**: because the current path finding code does, by design,
  detect rings as paths (e.g. in C1CC1 there is *1* atom path of
  length 3), values of Chi4v may give results that differ from those
  provided by the old code in molecules that have 3 rings.
  
  i   (   Ro   (   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi4v   s    	c         C   sw   g  |  j  ƒ  D] } t | ƒ ^ q } x  | j d ƒ rG | j d ƒ q( Wt j | d ƒ } t t j d | ƒ ƒ } | S(   s†     Similar to Hall Kier Chi0v, but uses nVal instead of valence
  This makes a big difference after we get out of the first row.
   
  i    RL   g      ð?(   R   R[   t   countRN   R   RO   R   RP   (   R   R	   RQ   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi0n+  s    %c         C   s–   t  j g  |  j ƒ  D] } t | ƒ ^ q d ƒ } d } xX |  j ƒ  D]J } | | j ƒ  | | j ƒ  } | d k rD | t  j d | ƒ 7} qD qD W| S(   sE     Similar to Hall Kier Chi1v, but uses nVal instead of valence
   
  RL   g        g      ð?(   R   RO   R   R[   RS   Re   Rf   RP   (   R   R	   t   deltsR   Rg   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi1n7  s    1c         C   s±   g  |  j  ƒ  D] } t | ƒ ^ q } t j g  | D]% } | rQ d t j | ƒ n d ^ q2 ƒ } d } xD t j |  | d d d ƒD]& } | t j | t j | ƒ ƒ 7} qƒ W| S(   s£    Similar to Hall Kier ChiNv, but uses nVal instead of valence
  This makes a big difference after we get out of the first row.
   
  **NOTE**: because the current path finding code does, by design,
  detect rings as paths (e.g. in C1CC1 there is *1* atom path of
  length 3), values of ChiNn with N >= 3 may give results that differ
  from those provided by the old code in molecules that have rings of
  size 3.
  
  g      ð?g        i   Ri   i    (   R   R[   R   RO   RP   R    RB   Rj   (   R   Rk   R	   t   nvalRQ   Rm   Rn   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt	   _pyChiNn_C  s    %;#$c         C   s   t  |  d ƒ S(   s†     Similar to Hall Kier Chi2v, but uses nVal instead of valence
  This makes a big difference after we get out of the first row.
   
  i   (   Rx   (   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi2nU  s    c         C   s   t  |  d ƒ S(   s†     Similar to Hall Kier Chi3v, but uses nVal instead of valence
  This makes a big difference after we get out of the first row.
   
  i   (   Rx   (   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi3n\  s    c         C   s   t  |  d ƒ S(   sŽ    Similar to Hall Kier Chi4v, but uses nVal instead of valence
  This makes a big difference after we get out of the first row.
   

  **NOTE**: because the current path finding code does, by design,
  detect rings as paths (e.g. in C1CC1 there is *1* atom path of
  length 3), values of Chi4n may give results that differ from those
  provided by the old code in molecules that have 3 rings.
  
  i   (   Rx   (   R   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _pyChi4nc  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi0v(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   p  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi1v(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   r  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi2v(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   t  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi3v(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   v  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi4v(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   x  s    c         C   s   t  j |  | ƒ S(   N(   R   t	   CalcChiNv(   R	   t   y(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   z  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi0n(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   }  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi1n(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH     s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi2n(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   �  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi3n(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   ƒ  s    c         C   s   t  j |  ƒ S(   N(   R   t	   CalcChi4n(   R	   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   …  s    c         C   s   t  j |  | ƒ S(   N(   R   t	   CalcChiNn(   R	   R‚   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyRH   ‡  s    c      
   C   s6  | s | d k r| ru t j |  d d d d d d ƒ} | |  _ t j |  d d d d d d d d ƒ} | |  _ qAy |  j } WnA t k
 rÅ t j |  d d d d d d d d	 ƒ} | |  _ n Xy |  j } WqAt k
 rt j |  d d d d d d d d ƒ} | |  _ qAXn' t j |  d d d d d d d d ƒ} t | ƒ } t |  | ƒ } |  j	 ƒ  } | | d } d
 } t
 | ƒ }	 xp t |	 ƒ D]b }
 | |
 } xO t |
 |	 ƒ D]> } | |
 | f d k rµ| d t j | | | ƒ 7} qµqµWq•W| d d k r,t | ƒ t | d ƒ | } n d } | S(   s   Calculate Balaban's J value for a molecule

  **Arguments**

    - mol: a molecule

    - dMat: (optional) a distance/adjacency matrix for the molecule, if this
      is not provide, one will be calculated

    - forceDMat: (optional) if this is set, the distance/adjacency matrix
      will be recalculated regardless of whether or not _dMat_ is provided
      or the molecule already has one

  **Returns**

    - a float containing the J value

  We follow the notation of Balaban's paper:
    Chem. Phys. Lett. vol 89, 399-404, (1982)

  t   useBOi   t
   useAtomWtsi    t   forcet   emptyValt   prefixt   NoBOt   Balabang        g      ð?N(   R!   R    R0   t   _balabanMatt   GetAdjacencyMatrixR1   R2   R   R   t   GetNumAtomsR#   t   rangeR   RP   R_   (   R   R   R7   R8   t   st   qRa   t   muR   t   nSt   it   sit   jt   J(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   BalabanJŠ  s@    !	''''
*!c      
   C   s  | r9 t  j |  d d d d d d d d ƒ} | |  _ n  d } g  } d g | } x£ t | ƒ D]• }	 | |	 j ƒ  }
 |
 j ƒ  t g  |
 |  D] } d | ^ q� ƒ } y | j | ƒ } Wn* t k
 rå t	 | ƒ } | j
 | ƒ n X| d | |	 <q_ Wt | ƒ S(	   sx   
     Used by BertzCT

     vdList: the number of neighbors each atom has
     bdMat: "balaban" distance matrix
     
  R‰   i   RŠ   i    R‹   R�   R�   s   %.4f(   R    R0   R�   R“   t   tolistt   sortt   tuplet   indext
   ValueErrorR#   R^   (   R   t   vdListt   bdMatt
   forceBDMatt   numAtomst   cutofft   atomIdxt   keysSeent   symListR˜   t   tmpListR	   t   theKeyt   idx(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _AssignSymmetryClassesÕ  s$    	
'c         C   s\   |  | k  r |  | f } n | |  f } | | } | t  j j k rL d } n t | ƒ } | S(   s   
     Used by BertzCT
  g      ø?(   R    t   BondTypet   AROMATICR_   (   t   atom1Idt   atom2Idt   bondDicR«   t   tmp(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _LookUpBondOrderñ  s    
	c         C   su   |  j  ƒ  } t | ƒ } | t j t j | ƒ ƒ t j | ƒ t } | j  ƒ  } | t j t j | ƒ ƒ } | | S(   s   
     Used by BertzCT
  (	   t   valuesR   R   R5   R   RO   R   R   R   (   t   connectionDictt   atomTypeDictR¥   t   connectionListt   totConnectionst   connectionIEt   atomTypeListt
   atomTypeIE(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _CalculateEntropies  s    c   
      C   sŠ  i  } d g | } d g | } x|  j ƒ  D]ý } | j ƒ  } | j ƒ  } | | k rg | | } } n  | j ƒ  sŒ | j ƒ  | | | f <n t j j | | | f <| | d k rÂ | g | | <n$ | | | k ræ | | j	 | ƒ n  | | d k r| g | | <q- | | | k r- | | j	 | ƒ q- q- WxL t
 | ƒ D]> \ } }	 y |	 j ƒ  t |	 ƒ | | <Wq;d | | <q;Xq;W| | | f S(   s-    _Internal Use Only_
     Used by BertzCT

  i    N(   R!   RS   Re   Rf   t   GetIsAromatict   GetBondTypeR    R®   R¯   R^   t	   enumerateRž   R#   (
   R   R¥   t   bondDictt   nListR¢   t   aBondt   atom1t   atom2R˜   t   element(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   _CreateBondDictEtc  s4     
id   c         C   s·  i  } i  } |  j  ƒ  } | s* | d k r« | r] t j |  d d d d d d ƒ} | |  _ q« y |  j } Wq« t k
 r§ t j |  d d d d d d ƒ} | |  _ q« Xn  | d k  r» d St |  | ƒ \ } } }	 t |  |	 | | | | ƒ }
 xŠt | ƒ D]|} |  j	 | ƒ j
 ƒ  } | j | d ƒ d | | <|
 | } |	 | } x0t | ƒ D]"} | | | } |
 | } t | | | ƒ } | d k ræ| | k ræ| | d d } t | | ƒ t | | ƒ f } | j | d ƒ | | | <n  xŠ t | d | ƒ D]u } | | | } |
 | } t | | | ƒ } | | } t | | ƒ | t | | ƒ f } | j | d ƒ | | | <qúWqQWqû W| s‘i d d 6} n  | j ƒ  } | j ƒ  t | | | ƒ S(	   sÜ   A topological index meant to quantify "complexity" of molecules.

     Consists of a sum of two terms, one representing the complexity
     of the bonding, the other representing the complexity of the
     distribution of heteroatoms.

     From S. H. Bertz, J. Am. Chem. Soc., vol 103, 3599-3601 (1981)

     "cutoff" is an integer value used to limit the computational
     expense.  A cutoff value tells the program to consider vertices
     topologically identical if their distance vectors (sets of
     distances to all other vertices) are equal out to the "cutoff"th
     nearest-neighbor.

     **NOTE**  The original implementation had the following comment:
         > this implementation treats aromatic rings as the
         > corresponding Kekule structure with alternating bonds,
         > for purposes of counting "connections".
       Upon further thought, this is the WRONG thing to do.  It
        results in the possibility of a molecule giving two different
        CT values depending on the kekulization.  For example, in the
        old implementation, these two SMILES:
           CC2=CN=C1C3=C(C(C)=C(C=N3)C)C=CC1=C2C
           CC3=CN=C2C1=NC=C(C)C(C)=C1C=CC2=C3C
        which correspond to differentk kekule forms, yield different
        values.
       The new implementation uses consistent (aromatic) bond orders
        for aromatic bonds.

       THIS MEANS THAT THIS IMPLEMENTATION IS NOT BACKWARDS COMPATIBLE.

       Any molecule containing aromatic rings will yield different
       values with this implementation.  The new behavior is the correct
       one, so we're going to live with the breakage.
        
     **NOTE** this barfs if the molecule contains a second (or
       nth) fragment that is one atom.

  R‰   i    RŠ   R‹   i   i   t   aN(   R’   R!   R    R0   R1   R2   RÇ   R­   R“   t   GetAtomWithIdxR   R   R´   t   mint   maxt   keysRž   R½   (   R   R¦   R   R7   R·   R¶   R¥   RÁ   t   neighborListR¢   t   symmetryClassesR§   t   hingeAtomNumbert   hingeAtomClasst   numNeighborsR˜   t   neighbor_iIdxt   NiClasst   bond_i_ordert   numConnectionst   connectionKeyRš   t   neighbor_jIdxt   NjClasst   bond_j_ordert   ks(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   BertzCT0  sR    (!!




!&
s   2.0.0(R   t   __doc__t   rdkitR    t
   rdkit.ChemR   R   R   R   R   R   R   t   rdkit.ML.InfoTheoryR   t   GetPeriodicTableRX   R   R   R
   R   R   R   R/   R!   R:   t   versionRA   RD   RF   R<   t   _CalcHallKierAlpha_versiont   Kappa1t   _CalcKappa1_versiont   Kappa2t   _CalcKappa2_versiont   Kappa3t   _CalcKappa3_versionRR   RW   R[   R\   Rd   Rh   Ro   Rp   Rq   Rr   Rt   Rv   Rx   Ry   Rz   R{   t   Chi0vt   _CalcChi0v_versiont   Chi1vt   _CalcChi1v_versiont   Chi2vt   _CalcChi2v_versiont   Chi3vt   _CalcChi3v_versiont   Chi4vt   _CalcChi4v_versiont   ChiNv_t   _CalcChiNv_versiont   Chi0nt   _CalcChi0n_versiont   Chi1nt   _CalcChi1n_versiont   Chi2nt   _CalcChi2n_versiont   Chi3nt   _CalcChi3n_versiont   Chi4nt   _CalcChi4n_versiont   ChiNn_t   _CalcChiNn_versionRœ   R­   R´   R½   RÇ   RÛ   (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/GraphDescriptors.pyt   <module>   sœ   			
										
		
																								B						"[