Exemple #1
0
def depictMultipleMols(mols_list,
                       filename=None,
                       ipython=False,
                       legends=None,
                       highlightAtoms=None,
                       mols_perrow=3):
    """
        Returns the image or the ipython rendering.

        Parameters
        ----------
        mols_list: list
            The list of the rdkit molecules to depict
        filename: str
            The filename of the image
        ipython: bool
            If True, the SVG rendering for jupiter-nootebook are returned
        legends: list
            List of titles subfigure for each molecule
        highlightAtoms: list
            List of list of atom index to highlight.
        mols_perrow: int
            The number of subfigures per row

        Returns
        -------
        svg: SVG
            If ipython set as True, the SVG rendering is returned

        """
    import rdkit
    from rdkit.Chem.Draw import MolsToGridImage
    from IPython.display import SVG
    from os.path import splitext

    sel_atoms = []
    sel_colors = []
    if highlightAtoms is not None:
        if isinstance(highlightAtoms[0][0], list):
            sel_atoms = [[a for a in subset] for mol_set in highlightAtoms
                         for subset in mol_set]
            sel_colors = [{
                aIdx: _highlight_colors[n % len(_highlight_colors)]
                for aIdx in subset
            } for mol_set in highlightAtoms
                          for n, subset in enumerate(mol_set)]
        else:
            sel_atoms = highlightAtoms
            sel_colors = [{aIdx: _highlight_colors[0]
                           for aIdx in subset} for subset in highlightAtoms]

    from rdkit.Chem.Draw import IPythonConsole as CDIPythonConsole

    if MolsToGridImage == CDIPythonConsole.ShowMols:
        CDIPythonConsole.UninstallIPythonRenderer()
        from rdkit.Chem.Draw import MolsToGridImage

    svg = MolsToGridImage(mols_list,
                          highlightAtomLists=sel_atoms,
                          highlightBondLists=[],
                          highlightAtomColors=sel_colors,
                          legends=legends,
                          molsPerRow=mols_perrow,
                          useSVG=True)

    if filename:
        ext = splitext(filename)[-1]
        filename = filename if ext != '' else filename + '.svg'
        f = open(filename, 'w')
        f.write(svg)
        f.close()

    if ipython:
        _svg = SVG(svg)
        return _svg
    else:
        return None
Exemple #2
0
 def setUp(self):
     if IPythonConsole is not None and Draw.MolsToGridImage == IPythonConsole.ShowMols:
         IPythonConsole.UninstallIPythonRenderer()
     self.mol = Chem.MolFromSmiles(
         'c1c(C[15NH3+])ccnc1[C@](Cl)(Br)[C@](Cl)(Br)F')
Exemple #3
0
 def tearDown(self):
     if IPythonConsole is not None:
         IPythonConsole.UninstallIPythonRenderer()