ó
a#nSc           @   sN  d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l Z i  a g  a	 e j
 j e j d ƒ Z d „  Z e j Z d d d d d	 „ Z d
 „  Z d d d d d „ Z d e _ d d d d d „ Z d e _ d „  Z e j e _ d e _  d „  Z e j e _ d e _  e d k rJd d l Z e e j ƒ rJg  Z d Z d e j k rud Z e j j  d ƒ n  x1 e j d D]" Z! e j" e! e j# e! ƒ f ƒ qƒWx› e D]� \ Z! Z$ d e! GHe e$ d e ƒZ% d GHe e$ d e ƒZ& d Ge% Ge& GHe j' e$ ƒ Z( e e( d d ƒZ% e e( d d ƒZ& d Ge% Ge& GHd GHq°WqJn  d S(   s•    Atom-based calculation of LogP and MR using Crippen's approach


    Reference:
      S. A. Wildman and G. M. Crippen *JCICS* _39_ 868-873 (1999)


iÿÿÿÿN(   t   RDConfig(   t   Chem(   t   rdMolDescriptorss   Crippen.txtc         C   s¨  i  } g  } x�t  |  d ƒ j ƒ  D]x} | d d k r" | j d ƒ } t | ƒ d k rš| d d k rš| d } | d k r—| j d	 d ƒ y t j | ƒ } Wn q”X| rˆt | d ƒ d k rí | d d d
 k rí | d d  } n | d d } t | d ƒ } | d d k r.t | d ƒ }	 n d }	 | | k rP| j | ƒ n  | j	 | g  ƒ }
 |
 j | | | |	 f ƒ |
 | | <q”d | GHq—qšq" q" W| | f S(   sH    *Internal Use Only*

    parses the pattern list from the data file

  t   ri    t   #s   	i   t    i   t   SMARTSt   "t   S0123456789i   i   g        s   Problems parsing smarts: %s(
   t   opent
   xreadlinest   splitt   lent   replaceR   t   MolFromSmartst   floatt   appendt   get(   t   fileNamet   pattst   ordert   linet	   splitLinet   smat   pt   chat   logPt   mrt   l(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/Crippen.pyt
   _ReadPatts   s8    "
*i    c         C   sL  | r t  |  d ƒ r |  j S| d k r8 t } t } n  |  j ƒ  } d g | } d g | } d } t }	 xÒ | D]Ê }
 | |
 } x­ | D]¥ \ } } } } x� |  j | t t ƒ D]y } | d } | | s° d | | <| | f | | <| rd | d | | | f GHn  | d 7} | | k r)t }	 Pq)q° q° Wqˆ W|	 rq Pqq qq W| |  _ | S(   s`   *Internal Use Only*

    calculates atomic contributions to the LogP and MR values

    if the argument *force* is not set, we'll use the molecules stored
    _crippenContribs value when possible instead of re-calculating.

  **Note:** Changes here affect the version numbers of MolLogP and MolMR
    as well as the VSA descriptors in Chem.MolSurf

  t   _crippenContribsg        i    i   s   	Atom %d: %s %4.4f %4.4fN(   g        g        (	   t   hasattrR   t   Nonet   _smartsPatternst   _patternOrdert   GetNumAtomst   Falset   GetSubstructMatchest   True(   t   molR   R   t   verboset   forcet   nAtomst   atomContribst	   doneAtomst   nAtomsFoundt   doneR   t   pattVectR   t   pattt   logpR   t   matcht   firstIdx(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/Crippen.pyt   _pyGetAtomContribsF   s8    	




 	c           C   s%   t  i  k r! t t ƒ \ a a  n  d  S(   N(   R!   R   t   defaultPatternFileNameR"   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/Crippen.pyt   _Initq   s    i   c         C   s°   | d k  r! t  j |  d ƒ } n' | d k rB t  j |  d ƒ } n |  } | d k r„ t i  k ru t t ƒ \ a a n  t } t } n  t | | | d | ƒ} t j	 | d ƒ d S(   s    DEPRECATED
  i    i   R(   N(
   R   t   AddHsR    R!   R   R5   R"   R4   t   numpyt   sum(   t   inMolR   R   R(   t   addHsR'   R+   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/Crippen.pyt
   _pyMolLogPv   s    	s   1.1.0c         C   s°   | d k  r! t  j |  d ƒ } n' | d k rB t  j |  d ƒ } n |  } | d k r„ t i  k ru t t ƒ \ a a n  t } t } n  t | | | d | ƒ} t j	 | d ƒ d S(   s    DEPRECATED
  i    i   R(   N(
   R   R7   R    R!   R   R5   R"   R4   R8   R9   (   R:   R   R   R(   R;   R'   R+   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/Crippen.pyt   _pyMolMRŠ   s    	c          O   s   t  j |  | Ž  d S(   Ni    (   R   t   CalcCrippenDescriptors(   t   xt   y(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/Crippen.pyt   <lambda>Ÿ   s    sj   Wildman-Crippen LogP value

  Uses an atom-based scheme based on the values in the paper:
     S. A. Wildman and G. M. Crippen JCICS 39 868-873 (1999)

  **Arguments**

    - inMol: a molecule

    - addHs: (optional) toggles adding of Hs to the molecule for the calculation.
      If true, hydrogens will be added to the molecule and used in the calculation.

c          O   s   t  j |  | Ž  d S(   Ni   (   R   R>   (   R?   R@   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/Crippen.pyRA   ¯   s    sh   Wildman-Crippen MR value

  Uses an atom-based scheme based on the values in the paper:
     S. A. Wildman and G. M. Crippen JCICS 39 868-873 (1999)

  **Arguments**

    - inMol: a molecule

    - addHs: (optional) toggles adding of Hs to the molecule for the calculation.
      If true, hydrogens will be added to the molecule and used in the calculation.

t   __main__s   -vs   Mol: %sR(   s   ----s   Res:R;   s   	s   -*-*-*-*-*-*-*-*()   t   __doc__t   ost   rdkitR    R   t
   rdkit.ChemR   R8   R!   R"   t   patht   joint	   RDDataDirR5   R   t   _CalcCrippenContribst   _GetAtomContribsR    R4   R6   R<   t   versionR=   t   MolLogPt   _CalcCrippenDescriptors_versiont   MolMRt   __name__t   sysR   t   argvt   msR(   t   removet   smiR   t   MolFromSmilest   mR1   R   R7   t   newM(    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/Crippen.pyt   <module>   sV   	'	+							 	