B
    3Rc                 @   s  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
ejdZdd ZejZd!d	d
Zdd Zd"ddZde_d#ddZde_dd Zeje_de_ dd Zeje_de_ edkrddlZeejrg ZdZdejk rdZejd x,ejdd D ]Z e!e e"e f qW xeD ]x\Z Z#e$de   ee#edZ%e$d ee#edZ&e$de%e& e'e#Z(ee(ddZ%ee(ddZ&e$de%e& e$d  q2W dS )$z Atom-based calculation of LogP and MR using Crippen's approach


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


    N)RDConfig)Chem)rdMolDescriptorszCrippen.txtc          	   C   sL  i }g }t | d}| }W dQ R X x|D ]}|d dkr.|d}t|dkr.|d dkr.|d }|d	kr4|d
d t|}|r@t|d dkr|d d dkr|d dd }	n|d d }	t|d }
|d dkrt|d }nd}|	|kr||	 |	|	g }||||
|f |||	< q.t
d|  q.W ||fS )zH *Internal Use Only*

    parses the pattern list from the data file

  rNr   #	       ZSMARTS"ZS0123456789      g        zProblems parsing smarts: %s)open	readlinessplitlenreplacer   ZMolFromSmartsfloatappendgetprint)ZfileNamepattsorderflineslineZ	splitLinesmapchaZlogPmrl r!   1lib/python3.7/site-packages/rdkit/Chem/Crippen.py
_ReadPatts    s6    


 


r#   c          	   C   s   |st | dr| jS |dkr$t}t}|  }dg| }dg| }d}d}	x|D ]}
||
 }x|D ]z\}}}}xl| |ddD ]Z}|d }|| s|d||< ||f||< |rtd|d |||f  |d7 }||kr|d}	P q|W q`W |	rNP qNW || _|S )	a`   *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

  _crippenContribsN)g        g        r   Fr
   z	Atom %d: %s %4.4f %4.4fT)hasattrr$   _smartsPatterns_patternOrderZGetNumAtomsZGetSubstructMatchesr   )molr   r   verboseZforceZnAtomsatomContribsZ	doneAtomsZnAtomsFoundZdoner   ZpattVectr   Zpattlogpr   matchZfirstIdxr!   r!   r"   _pyGetAtomContribsI   s8    



r-   c               C   s   t i krtt\aa d S )N)r&   r#   defaultPatternFileNamer'   r!   r!   r!   r"   _Initv   s    r/   r
   c             C   st   |dk rt | d}n|dkr,t | d}n| }|dkrTti krLtt\aat}t}t||||d}t|dd S )z DEPRECATED
  r   r
   N)r)   )	r   AddHsr&   r#   r.   r'   r-   numpysum)inMolr   r   r)   addHsr(   r*   r!   r!   r"   
_pyMolLogP|   s    r5   z1.1.0c             C   st   |dk rt | d}n|dkr,t | d}n| }|dkrTti krLtt\aat}t}t||||d}t|dd S )z DEPRECATED
  r   r
   N)r)   )	r   r0   r&   r#   r.   r'   r-   r1   r2   )r3   r   r   r)   r4   r(   r*   r!   r!   r"   _pyMolMR   s    r6   c              O   s   t j| |d S )Nr   )r   CalcCrippenDescriptors)xyr!   r!   r"   <lambda>       r:   aj   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 )Nr
   )r   r7   )r8   r9   r!   r!   r"   r:      r;   ah   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.

__main__z-vzMol: %s)r)   z----zRes:)r4   r   z-*-*-*-*-*-*-*-*)NNr   r   )NNr   r
   )NNr   r
   ))__doc__osZrdkitr   r   Z
rdkit.Chemr   r1   r&   r'   pathjoinZ	RDDataDirr.   r#   Z_CalcCrippenContribsZ_GetAtomContribsr-   r/   r5   versionr6   ZMolLogPZ_CalcCrippenDescriptors_versionZMolMR__name__sysr   argvZmsr)   removeZsmir   ZMolFromSmilesmr   r+   r   r0   ZnewMr!   r!   r!   r"   <module>   sV   &
-



