B
    ž3Rc&/  ã               @   sJ   d dl Z d dlmZ d dlmZ dd„ Zdd„ Zdadd	„ Zdd
d„Z	dS )é    N)ÚChem)ÚAllChemc           &   C   s  t  dddddddg¡} | dd	d
dddƒ| dd	ddddƒ| dd	ddddƒ| dd	ddddƒ| dd	ddddƒ| dd	dd dd!ƒ| d"d	dd#d$d%ƒ| d&d	d'd(d)d*ƒ| d+d	dd,dd-ƒ| d.d	d/d0d1d2ƒ| d3d	d4d5d6d7ƒ| d8d	d9d:dd;ƒ| d<d	d=d>d?d@ƒ| dAd	dBdCddDƒ| dEdFdGdHdIdJƒ| dKdFdLdMdNdOƒ| ddFdPdddQƒ| dRdFdLdSddTƒ| dUdFdLdVddWƒ| ddFdPdddXƒ| dYdFdLdZdd[ƒ| d\dFdLd]dd^ƒ| ddFdPddd_ƒ| d`dadbdcdddƒ| dedfdgdhddiƒ| djdkdldmdndoƒ| dpdkdqdrddsƒ| dtdadbduddvƒ| dwdfdgdxddyƒ| dzdad{d|dd}ƒ| d~dfdd€ddƒ| d‚dfdƒd„dd…ƒg S )†aF  
    Return a list of the individual patterns for mutating individual
    atoms in aromatic rings to generate a new aromatic ring. The
    elements are collections.namedtuple objects with the following
    fields:

    SMARTS - the left side of the reaction SMARTS pattern, matches the atom to mutate
    CONVERT_FROM - the element type being converted: c, n, o, s
    CONVERT_TO - the right side of the reaction SMARTS pattern, there can be multiple destination types separated with a comma, these should map to multiple actual reaction objects
    EXAMPLE - an example aromatic ring system that SMARTS should match against, used in test cases
    NEGATIVE_EXAMPLE - an example aromatic ring system that SMART should NOT match against, used in test cases
    DESCRIPTION - a human readable description of the SMARTS pattern matching
    ÚHeteroAtomReactionÚSMARTSZCONVERT_FROMÚ
CONVERT_TOZEXAMPLEZNEGATIVE_EXAMPLEZDESCRIPTIONz&[c;x2;D2;r5:1]([n;x2;r5:2])[n;x2;r5:3]Úcz[n:1]([n:2])[n:3]z$c1nc[nH]c1,c1ncn([*])c1,c1nncn([*])1Ú z9aromatic carbon in 5 membered ring, bonded to 2 nitrogenszj[c;x2;D2;r5:1]([n;h1;!+;!-;x2;r5;!$(*=*);!$(*[*;r5]=*):2])[n;x2;r5;!$(*=*);!$(*[*;r5]=*);!$(*[*;r5;x3]):3]z/[o:1]([n;H0:2])[n;H0:3],[s:1]([n;H0:2])[n;H0:3]zc1nc[nH]c1,[*]c1nc[nH]c1zk[*]c1ncno1,[*]n1[nH]cnc1=O,[*]c1nc2[nH]cnn2c(=O)c1[*],c1nc2cscc2[nH]1,c1c[nH]c2c1[nH]cn2,c1ccc2c(c1)[nH]cn2z‘aromatic carbon in 5 membered ring, bonded to 1 nitrogen not bonded to another atom that is in 2 rings, bonded to 1 nitrogen with H and no chargez[c;x2;D2;r5:1]([n;h1;!+;!-;x2;r5;!$(*=*);!$(*[*;r5]=*):2])[n;x2;r5;!$(*=*);!$(*[*;r5]=*);!$(*[n;r5;x3]);$(*[c;x3;$(*[*;r6])]):3] zc1ccc2c(c1)[nH]cn2zX[*]c1ncno1,[*]n1[nH]cnc1=O,[*]c1nc2[nH]cnn2c(=O)c1[*],c1nc2cscc2[nH]1,c1c[nH]c2c1[nH]cn2z’aromatic carbon in 5 membered ring, bonded to 1 nitrogen bonded to a bridgehead carbon in 6-member ring, bonded to 1 nitrogen with H and no chargez([c;x2;D2;r5:1]([c;x2;r5:2])[o,s;x2;r5:3]z[n:1]([c:2])[*:3]z [*]c1ccoc1,c1ccoc1[*],n1ccoc1[*]zMaromatic carbon in 5 membered ring, bonded to 1 carbon and 1 oxygen or sulfurz)[c;x2;D2;r5:1]([c;r5:2])[n;r5;h0;!-;!+:3]z[n:1]([c:2])[n:3]zc1nc[nH]c1[*],n1cc[nH]c1[*],n1cc[nH][n+]1[*],[*]n1cc2c(c1)CCCC2,[*]N1Cc2cn([*])cc2C1,[*]c1c2c(cn1[*])CCCC2,[*]c1cn2c(c1[*])CCC2z`aromatic carbon in 5 membered ring, bonded to 1 carbon, bonded to 1 nitrogen with no H no chargez+[c;x2;D2;r5:1]([c;x2;r5:2])[n;x2;r5;h1;+:3]z!c1c([*])sc[nH+]1,c1csc([*])[nH+]1z^aromatic carbon in 5 membered ring, bonded to 1 carbon, bonded to 1 nitrogen with H and chargez)[c;x2;D2;r5:1]([c:2])[n;x2;r5;h1;!+;!-:3]z‹[*]n1[nH]ccc1=O,[*]n1cc[nH]c1=O,[*]c1nc2[nH]ccn2c(=O)c1[*],[*]c1ccc[nH]1,[*]c1ncc[nH]1,[*][n+]1ccc[nH]1,[*][n+]1cc[nH]c1,c1ccc2c(c1)cc[nH]2z[*]c1cn2ccnc2nc1[*]zaaromatic carbon in 5 membered ring, bonded to 1 carbon, bonded to 1 nitrogen with H and no chargezy[c;x2;D2;r5:1]([c;x2;r5;!$(*=*);!$(*[*;r5]=*);!$(*[*;r5;x3]):2])[n;x2;r5;!$(*=*);!$(*[*;r5]=*);!$(*[*;r5;x3]);h1;!+;!-:3]z)[o:1]([c:2])[n;H0:3],[s:1]([c:2])[n;H0:3]z=[*]c1ccc[nH]1,[*]c1ncc[nH]1,[*][n+]1ccc[nH]1,[*][n+]1cc[nH]c1zac1ccc2c(c1)cc[nH]2,[*]n1[nH]ccc1=O,[*]n1cc[nH]c1=O,[*]c1nc2[nH]ccn2c(=O)c1[*],[*]c1cn2ccnc2nc1[*]z‹aromatic carbon in 5 membered ring, bonded to 1 carbon, bonded to 1 nitrogen with H and no charge, no exocyclic double bonds or fused ringsz+[c;x2;D2;r5:1]([c;x2;r5:2])[n;h0;+;x2;r5:3]z+CC[n+]1ccco1,[*][n+]1ccco1,[*][n+]1ccc[nH]1zfaromatic carbon in 5 membered ring, bonded to 1 carbon, bonded to 1 nitrogen with no H and with chargez9[c;x2;D2;r5:1]([c;x2;r5:2])[n;h0;+;x2;r5:3][n;x2;r5;h1:4]z3[o:1]([c:2])[n:3][n;H0:4],[s:1]([c:2])[n:3][n;H0:4]z[*][n+]1ccc[nH]1zCC[n+]1ccco1,[*][n+]1ccco1z¢aromatic carbon in 5 membered ring, bonded to 1 carbon, bonded to 1 nitrogen with no H and with charge, that nitrogen is then bonded to a nitrogen with a hydrogenz3[c;x2;D2;r5:1]([c;x2;r5:2])[c;x2;r5:3][o,s;x2;r5:4]z[n:1]([c:2])[c:3][*:4]zs1cccn1,o1c([*])ccn1zs1cc([*])cn1zQaromatic carbon in 5 membered ring, bonded to 2 carbons, oxygen or sulfur in ringz=[!o;!s;r5:1]1~[c;r5:2]~[c;x2;D2;r5:3]~[c;r5:4]~[!o;!s;r5:5]~1z [*:1]1~[c:2]~[n:3]~[c:4]~[*:5]~1z*[*]c1cc[nH]c1,[*]n1cccc1,[*]n1ccc2nccc-2c1zTaromatic carbon in 5 membered ring, bonded to 2 carbons, no oxygen or sulfur in ringzR[n;h1;!+;!-;r5:1]1~[c;!$(*=*);r5:2]~[c;x2;D2;r5:3]~[c;!$(*=*);r5:4]~[!o;!s;r5:5]~1zF[n;H0:1]1~[c:2]~[o:3]~[c:4]~[*:5]1,[n;H0:1]1~[c:2]~[s:3]~[c:4]~[*:5]~1zc1cc[nH]c1,c1ccc2c(c1)cc[nH]2z,[*]n1cccc1,[*]n1cc([*])cc1,[*]n1ccc(=O)[nH]1z’aromatic carbon in 5 membered ring, bonded to 2 carbons without carbonyls, no oxygen or sulfur in ring, and a nitrogen with a hydrogen in the ringzæ[c;h1;D2;r6;$(a1ccc[c,n,o][c,n,o]1),$(a1cc[c,n,o][c,n,o]c1),$(a1c[c,n,o][c,n,o]cc1),$(a1[c,n,o][c,n,o]ccc1),$(a1cc[n,o]c[n,o]1),$(a1c[n,o]c[n,o]c1),$(a1[n,o]c[n,o]cc1),$(a1[n,o]ccc[n,o]1),$(a1c[n,o]cc[n,o]1),$(a1[n,o]cc[n,o]c1):1]z[n:1]z\c1ccccc1,c1cccnc1,c1nccnc1,[*]c1cc(=O)cco1,c1c([*])[nH]c(=O)[nH]c1=O,[*]c1c[nH]c(=O)[nH]c1=OzJaromatic carbon in 6 membered ring, has 1H, ring has less than 3 nitrogensz[n;x2;r5;h1;!+;!-;!$(*[o,s]):1]Únz[o:1],[s:1]zc1n[nH]nn1,c1cc[nH]c1z!c1ccn([*])c1,[*]c1o[nH]c(=O)c1[*]zQaromatic nitrogen in 5 membered ring, 1H, no charge, not next to sulfur or oxygenz([n;x2;X2;r5;h0;!+;!-;$(*[a;r5][a;r5]):1]z[c:1]z
c1cnc[nH]1zc1ccn([*])c1zNaromatic nitrogen in 5 membered ring, bonded to 2 heavy atoms, no H, no chargezNo mutationszHaromatic nitrogen in 5 membered ring, bonded to 3 heavy atoms, no chargez![n;x2;X3;r5;+;$(*[a;r5][a;r5]):1]zc1coc[n+]1CzFaromatic nitrogen in 5 membered ring, bonded to 3 heavy atoms, chargedz([n;x2;X2;r6;h0;!+;!-;$(*[a;r6][a;r6]):1]zc1cccnc1,c1nccnc1zVaromatic nitrogen in 6 membered ring, bonded to 2 heavy atoms, no hydrogens, no chargezLaromatic nitrogen in 6 membered ring, bonded to 2 heavy atoms, 1H, no chargez![n;x2;r6;h1;+;$(*[a;r6][a;r6]):1]zc1ccc2c(c1)ccc[nH+]2zJaromatic nitrogen in 6 membered ring, bonded to 2 heavy atoms, 1H, chargedz![n;x2;r6;X3;+;$(*[a;r6][a;r6]):1]z[*][n+]1cccc2c1cccc2zFaromatic nitrogen in 6 membered ring, bonded to 3 heavy atoms, chargedzHaromatic nitrogen in 6 membered ring, bonded to 3 heavy atoms, no chargez$[s;x2;r5;!+;!-;$(*([c;r5])[c;r5]):1]Úsz[n;H1:1],[o:1]zc1ccsc1,c1ncsc1z7aromatic sulfur in 5 membered ring, bonded to 2 carbonsz$[o;x2;r5;!+;!-;$(*([c;r5])[c;r5]):1]Úoz[n;H1:1],[s:1]zc1ccoc1,c1ncoc1z7aromatic oxygen in 5 membered ring, bonded to 2 carbonsz?[o,s;x2;r5;!+;!-:1]([c;x2;r5;!$(*=*):2])[n;x2;r5;h0;D2;!+;!-:3]zo,sz[c:1]([c:2])[n;H1:3]zc1cnoc1,c1csnc1,c1c([*])snc1z=[*]n1occc1=O,[*][n+]1ccco1,[*]n1c(=O)[nH]sc1=O,[*]c1nsc(=O)o1z‡aromatic oxygen or sulfur in 5 membered ring, bonded to 1 carbon, 1 nitrogen with no charge with no hydrogen and only bonded to 2 atomsz-[o,s;x2;r5;!+;!-:1]([c;x2;r5:2])[n;x2;r5;+:3]z[c:1]([c:2])[n;+0:3]z[*][n+]1ccco1zbaromatic oxygen or sulfur in 5 membered ring, bonded to 1 carbon, 1 nitrogen in ring with a chargez'[s;x2;r5;!+;!-;$(*([c;r5])[n;h1;r5]):1]z[*]c1s[nH]c(=O)c1[*]zRaromatic sulfur in 5 membered ring, bonded to 1 carbon, 1 nitrogen with a hydrogenz'[o;x2;r5;!+;!-;$(*([c;r5])[n;h1;r5]):1]z[*]c1o[nH]c(=O)c1[*]zRaromatic oxygen in 5 membered ring, bonded to 1 carbon, 1 nitrogen with a hydrogenz5[s;x2;r5;!+;!-:1]([c;x2;r5:2])[n;x2;r5;h0;D3;!+;!-:3]z&[n;H1:1]([c:2])[n:3],[o:1]([c:2])[n:3]z[*]n1sc(=O)n([*])c1=Ozdaromatic sulfur in 5 membered ring, bonded to 1 carbon, 1 nitrogen with no charge bonded to 3 atoms z5[o;x2;r5;!+;!-:1]([c;x2;r5:2])[n;x2;r5;h0;D3;!+;!-:3]z&[n;H1:1]([c:2])[n:3],[s:1]([c:2])[n:3]z[*]n1oc(=O)n([*])c1=Ozdaromatic oxygen in 5 membered ring, bonded to 1 carbon, 1 nitrogen with no charge bonded to 3 atoms z[o;r6:1]z[n;H1:1]z[*]c1cccc(=O)o1z"aromatic oxygen in 6 membered ring)ÚcollectionsÚ
namedtuple)r   © r   ú?lib/python3.7/site-packages/rdkit/Chem/EnumerateHeterocycles.pyÚGetHeterocycleReactionSmarts   sF    r   c              c   sN   xHt ƒ D ]>} | j}|sqx,| j d¡D ]}|d | }t |¡V  q&W qW d S )Nú,z>>)r   r   r   Úsplitr   ZReactionFromSmarts)ÚrowZsmartsÚproductZreactionr   r   r   Ú_ParseReactions?   s    r   c               C   s   t dkrttƒ ƒa t S )zu
    Return RDKit ChemicalReaction objects of the reaction SMARTS
    returned from GetHeterocyleReactionSmarts.
    N)ÚREACTION_CACHEÚlistr   r   r   r   r   ÚGetHeterocycleReactionsJ   s    
r   c       	      c   s²   | dfg}t ƒ }xœ|r¬| d¡\}}|dk	r8||kr8dS xptƒ D ]f}x`| |f¡D ]P}|d }t |¡ tj|dd}||kr€qR| ||d f¡ | |¡ |V  qRW q@W qW dS )aH  
    Enumerate possible relevant heterocycles on the given input
    molecule.

    >>> from rdkit.Chem.EnumerateHeterocycles import EnumerateHeterocycles
    >>> from rdkit import Chem
    >>> for smi in sorted(Chem.MolToSmiles(m) for m in EnumerateHeterocycles(Chem.MolFromSmiles('c1ccccc1'))):
    ...     print(smi)
    c1ccccc1
    c1ccncc1
    c1ccnnc1
    c1cnccn1
    c1cncnc1
    c1cnncn1
    c1cnnnc1
    c1ncncn1

    The algorithm works by mutating only one atom at a time. The depth
    parameter can be used to control the level of this recursion. For
    example, only enumerating aromatic rings that are one atom different:

    >>> for smi in sorted(Chem.MolToSmiles(m) for m in EnumerateHeterocycles(Chem.MolFromSmiles('n1ccccc1'), depth=1)):
    ...     print(smi)
    c1ccccc1
    c1ccnnc1
    c1cnccn1
    c1cncnc1
    r   NT)ZisomericSmilesé   )	ÚsetÚpopr   ZRunReactantsr   ZSanitizeMolZMolToSmilesÚappendÚadd)	ZinputmolZdepthZstarting_pointsÚseenZcurmolZcurdepthZrxnZnewmolZnewmol_smilesr   r   r   ÚEnumerateHeterocyclesU   s     


r   )N)
r   Zrdkitr   Z
rdkit.Chemr   r   r   r   r   r   r   r   r   r   Ú<module>   s   3
