{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021.03.1dev1\n"
     ]
    }
   ],
   "source": [
    "from rdkit import Chem\n",
    "from rdkit.Chem import Draw\n",
    "from rdkit.Chem.Draw import IPythonConsole\n",
    "from rdkit.Chem import rdDepictor\n",
    "IPythonConsole.molSize = (350,300)\n",
    "IPythonConsole.drawOptions.centreMoleculesBeforeDrawing=True\n",
    "import rdkit\n",
    "print(rdkit.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipywidgets import interact\n",
    "import glob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cd503bbc3249487d9e5d0afc0c97e130",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='fn', options=('jm7b00306.excerpt.sdf', 'jm200186n.excerpt.sdf', 's…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_lastFn = None\n",
    "_lastMols = None\n",
    "fns = glob.glob('*.sdf')\n",
    "@interact(fn=fns,start='0',molsPerPage=range(4,24,4))\n",
    "def show_mols(fn,start,molsPerPage=12):\n",
    "    global _lastFn\n",
    "    global _lastMols\n",
    "    if fn==_lastFn:\n",
    "        mols = _lastMols\n",
    "    else:\n",
    "        mols = [x for x in Chem.SDMolSupplier(fn) if x is not None]\n",
    "        _lastMols = mols\n",
    "        _lastFn = fn\n",
    "    start = int(start)\n",
    "    return Draw.MolsToGridImage(mols[start:start+molsPerPage],molsPerRow=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
