B
    3Rc                 @   sP   d Z ddlmZ G dd deZdd ZedkrLddlZe \ZZ	e
e dS )	a  Exposes a class for matching fragments of molecules.

The class exposes a simple API:

If you want a matcher that hits C=O, you'd do:

>>> p = FragmentMatcher()
>>> p.Init('C=O')

you can then match with:

>>> mol = Chem.MolFromSmiles('CC(=O)O')
>>> p.HasMatch(mol)
1
>>> p.HasMatch(Chem.MolFromSmiles('CC(C)C'))
0

information about the matches:

>>> len(p.GetMatches(Chem.MolFromSmiles('CC=O')))
1
>>> len(p.GetMatches(Chem.MolFromSmiles('O=CC=O')))
2

or, you can add exclusion fragments (defined as smarts) with:

>>> p.AddExclusion('c1ccccc1')

now the matcher will not hit anything that has a benzene ring.

>>> p.HasMatch(Chem.MolFromSmiles('CC=O'))
1
>>> p.HasMatch(Chem.MolFromSmiles('c1ccccc1CC=O'))
0


    )Chemc               @   sV   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dddZ
dd ZdS )FragmentMatcherc             C   s   d | _ g | _d S )N)_onPatt	_offPatts)self r   9lib/python3.7/site-packages/rdkit/Chem/FragmentMatcher.py__init__4   s    zFragmentMatcher.__init__c             C   s   | j t| d S )N)r   appendr   MolFromSmarts)r   smar   r   r   AddExclusion8   s    zFragmentMatcher.AddExclusionc             C   s   t || _d S )N)r   r   r   )r   r   r   r   r   Init;   s    zFragmentMatcher.Initc             C   s   d S )Nr   )r   r   r   r   	GetSMARTS>   s    zFragmentMatcher.GetSMARTSc             C   s   d S )Nr   )r   r   r   r   GetExclusionSMARTSA   s    z"FragmentMatcher.GetExclusionSMARTSc             C   sD   | j d krdS || j }|s"dS x| jD ]}||r*dS q*W dS )Nr      )r   ZHasSubstructMatchr   )r   moltZpattr   r   r   HasMatchD   s    

zFragmentMatcher.HasMatchc             C   s   | j d krd S || j S )N)r   ZGetSubstructMatch)r   r   r   r   r   GetMatchP   s    
zFragmentMatcher.GetMatchr   c             C   s   | j d krd S |j| j |dS )N)uniquify)r   ZGetSubstructMatches)r   r   r   r   r   r   
GetMatchesU   s    
zFragmentMatcher.GetMatchesc             C   s   | j d krd S | j |S )N)r   ZGetBondWithIdx)r   idxr   r   r   GetBondZ   s    
zFragmentMatcher.GetBondN)r   )__name__
__module____qualname__r	   r   r   r   r   r   r   r   r   r   r   r   r   r   2   s   
r   c              C   s    dd l } dd l}| |jd S )Nr   __main__)doctestsysZtestmodmodules)r   r   r   r   r   _testd   s    r!   r   N)__doc__Zrdkitr   objectr   r!   r   r   ZfailedZtriedexitr   r   r   r   <module>.   s   2
