mols2grid


Pat gave a talk (slides: https://github.com/PatWalters/chem_tutorial/blob/main/2021_08_19_Chem_Tutorial.pdf; code: https://github.com/PatWalters/chem_tutorial) as part of the RSC CICAG Open Chemical Sciences workshop series.

As an interesting matter of fact Pat is using binder (www.mybinder.org) for direct access and execution of his notebooks (https://mybinder.org/v2/gh/PatWalters/chem_tutorial/HEAD): this is awesome!

In [2]:
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole 
from rdkit.Chem import Draw
from rdkit.Chem import rdDepictor
IPythonConsole.ipython_useSVG = True
rdDepictor.SetPreferCoordGen(True)
import mols2grid
In [3]:
mols = [x for x in Chem.SDMolSupplier("example_compounds.sdf")]

Here comes the cool thing: mols2grid for a neat display of a list of molecules

mols2grid (https://github.com/cbouy/mols2grid) is developed by Cédric Bouysset (https://twitter.com/cedricbouysset, https://cedric.bouysset.net/) and can be simply installed via conda

In [4]:
mols2grid.display(mols)
Out[4]:
In [5]:
mols2grid.selection
Out[5]:
{0: 'COc1cc2c(Nc3ccc(Sc4nccn4C)c(Cl)c3)c(C#N)cnc2cc1OCCCN1CCOCC1',
 2: 'Cc1cnc(Nc2cccc3c2OC(F)(F)O3)nc1-c1c[nH]c(C(=O)N[C@H](CO)c2cccc(Cl)c2)c1',
 4: 'Cc1cnc(Nc2cccc3c2CCC3)nc1-c1c[nH]c(C(=O)N[C@H](CO)c2cccc(Cl)c2)c1'}

Now a few more tricks I found on Cedric'c Colab notebook (https://colab.research.google.com/github/cbouy/mols2grid/blob/master/demo.ipynb):

In [6]:
# example dataframe
import pandas as pd

smiles = ["CCO", "c1ccccc1", "N", "CO", "O=S(=O)(-O)(-O)", "CCC", "CCC=O"]
df = pd.DataFrame({"smi": smiles,
                   "id": range(1, len(smiles) + 1)})
# setup the grid
mg = mols2grid.MolGrid(df, smiles_col="smi", size=(110, 90))
mg.display(subset=["id", "img"], n_cols=7)
Out[6]:
In [ ]: