B
    3Rc                 @   s^   d dl mZ d dlmZ d dl mZ dddZd	d
 ZedkrZd dlZe \Z	Z
ee	 dS )    )Chem)
rdDepictor)GeometryNFc             C   sp   |s|  |}|stdi }||}x2t|D ]&\}}||}	t|	j|	j||< q2W t	j
| ||d}
|
S )a  
   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]



  z!no match between mol and template)
clearConfsZcoordMap)ZGetSubstructMatch
ValueErrorZGetConformer	enumerateZGetAtomPositionr   ZPoint2Dxyr   ZCompute2DCoords)Zmoltemplatematchr   ZtemplateConfIdZatomMapZtemplateConfiidxpZ	molConfId r   7lib/python3.7/site-packages/rdkit/Chem/TemplateAlign.pyAlignMolToTemplate2D   s    A


r   c              C   s6   dd l } dd l}ddlm} |d | |jd S )Nr   )r   F__main__)doctestsys
rdkit.Chemr   ZSetPreferCoordGenZtestmodmodules)r   r   r   r   r   r   _testc   s    
r   r   )NFr   )Zrdkitr   r   r   r   r   r   __name__r   ZfailedZtriedexitr   r   r   r   <module>   s     
O
