ó
a#nSc           @   s   d  d l  m Z d  d l m Z d  d l  m Z d e d  d  Z d   Z e	 d k r d  d l
 Z
 e   \ Z Z e
 j e  n  d S(   i˙˙˙˙(   t   Chem(   t
   rdDepictor(   t   Geometryc         C   sŚ   | s |  j  |  } n  | s* t d  n  i  } | j |  } xE t |  D]7 \ } } | j |  }	 t j |	 j |	 j  | | <qL Wt	 j
 |  d | d | }
 |
 S(   sš  
   Arguments:

     - mol:      the molecule to be aligned
     - template: the template to align to
     - match:    If provided, this should be a sequence of integers
                 containing the indices of the atoms in mol that match
                 those in template. This is the result of calling:
                   mol.GetSubstructMatch(template)
     - clearConfs: toggles removing any existing conformers on mol

    Returns the confId of the conformer containing the depiction

    >>> patt = Chem.MolFromSmiles('C1CC1')
    >>> rdDepictor.Compute2DCoords(patt)
    0
    >>> mol = Chem.MolFromSmiles('OC1CC1CC1CCC1')
    >>> rdDepictor.Compute2DCoords(mol)
    0
    >>> pc = patt.GetConformer(0)
    >>> mc = mol.GetConformer(0)

    We start out with the molecules not aligned:
    >>> vs = [abs(pc.GetAtomPosition(i).x-mc.GetAtomPosition(i+1).x) for i in range(pc.GetNumAtoms())]
    >>> [x<1e-4 for x in vs]
    [False, False, False]

    But then we can replace the conformer of mol:
    >>> AlignMolToTemplate2D(mol,patt,clearConfs=True)
    0
    >>> mol.GetNumConformers()
    1
    >>> pc = patt.GetConformer(0)
    >>> mc = mol.GetConformer(0)
    >>> vs = [abs(pc.GetAtomPosition(i).x-mc.GetAtomPosition(i+1).x) for i in range(pc.GetNumAtoms())]
    >>> [x<1e-4 for x in vs]
    [True, True, True]

    If we like, we can specify the atom map explicitly in order to align to the second
    matching ring in the probe molecule:
    >>> match = (5,6,7)
    >>> AlignMolToTemplate2D(mol,patt,clearConfs=True,match=match)
    0
    >>> mol.GetNumConformers()
    1
    >>> pc = patt.GetConformer(0)
    >>> mc = mol.GetConformer(0)
    >>> vs = [abs(pc.GetAtomPosition(i).x-mc.GetAtomPosition(i+1).x) for i in range(pc.GetNumAtoms())]
    >>> [x<1e-4 for x in vs]
    [False, False, False]
    >>> vs = [abs(pc.GetAtomPosition(i).x-mc.GetAtomPosition(i+5).x) for i in range(pc.GetNumAtoms())]
    >>> [x<1e-4 for x in vs]
    [True, True, True]


    
  s!   no match between mol and templatet
   clearConfst   coordMap(   t   GetSubstructMatcht
   ValueErrort   GetConformert	   enumeratet   GetAtomPositionR   t   Point2Dt   xt   yR   t   Compute2DCoords(   t   molt   templatet   matchR   t   templateConfIdt   atomMapt   templateConft   it   idxt   pt	   molConfId(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/TemplateAlign.pyt   AlignMolToTemplate2D   s    ; c          C   s,   d d  l  }  d d  l } |  j | j d  S(   Ni˙˙˙˙t   __main__(   t   doctestt   syst   testmodt   modules(   R   R   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/TemplateAlign.pyt   _test\   s    R   N(   t   rdkitR    t
   rdkit.ChemR   R   t   Nonet   FalseR   R   t   __name__R   t   failedt   triedt   exit(    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/rdkit/Chem/TemplateAlign.pyt   <module>   s   L	