ó
a#nSc           @   sp   d  Z  d d l m Z d e f d „  ƒ  YZ d „  Z e d k rl d d l Z e ƒ  \ Z Z	 e j
 e ƒ n  d S(   sÆ   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


iÿÿÿÿ(   t   Chemt   FragmentMatcherc           B   s\   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z	 d	 „  Z
 RS(
   c         C   s   d  |  _ g  |  _ d  S(   N(   t   Nonet   _onPattt	   _offPatts(   t   self(    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   __init__/   s    	c         C   s   |  j  j t j | ƒ ƒ d  S(   N(   R   t   appendR    t   MolFromSmarts(   R   t   sma(    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   AddExclusion3   s    c         C   s   t  j | ƒ |  _ d  S(   N(   R    R   R   (   R   R	   (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   Init5   s    c         C   s   d  S(   N(    (   R   (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt	   GetSMARTS8   s    c         C   s   d  S(   N(    (   R   (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   GetExclusionSMARTS:   s    c         C   sZ   |  j  d  k r d S| j |  j  ƒ } | s/ d Sx$ |  j D] } | j | ƒ r9 d Sq9 Wd S(   Ni    i   (   R   R   t   HasSubstructMatchR   (   R   t   molt   tt   patt(    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   HasMatch>   s    c         C   s#   |  j  d  k r d  S| j |  j  ƒ S(   N(   R   R   t   GetSubstructMatch(   R   R   (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   GetMatchJ   s    i   c         C   s&   |  j  d  k r d  S| j |  j  | ƒ S(   N(   R   R   t   GetSubstructMatches(   R   R   t   uniquify(    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt
   GetMatchesO   s    c         C   s#   |  j  d  k r d  S|  j  j | ƒ S(   N(   R   R   t   GetBondWithIdx(   R   t   idx(    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   GetBondT   s    (   t   __name__t
   __module__R   R
   R   R   R   R   R   R   R   (    (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyR   .   s   							c          C   s,   d d  l  }  d d  l } |  j | j d ƒ S(   Niÿÿÿÿt   __main__(   t   doctestt   syst   testmodt   modules(   R   R   (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   _test^   s    R   N(   t   __doc__t   rdkitR    t   objectR   R"   R   R   t   failedt   triedt   exit(    (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/FragmentMatcher.pyt   <module>*   s   0	