{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 343,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from collections import namedtuple\n",
    "\n",
    "from rdkit import Chem\n",
    "from rdkit.Chem import rdDepictor\n",
    "from rdkit.Chem.Draw import rdMolDraw2D\n",
    "from rdkit.Chem.Draw import MolsToGridImage, _MolsToGridSVG\n",
    "from rdkit.Chem.Draw import IPythonConsole\n",
    "from IPython.display import SVG"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 344,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "IPythonConsole.kekulizeStructures = False # Does not propagate to MolsToGridimage\n",
    "Mol = namedtuple('Mol', ['RDK_mol', 'description'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 352,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "mols = []\n",
    "#mols.append(Mol(Chem.MolFromSmiles('C12C3C1C23'), 'tetrahedrane'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('C12-C3-C-1-C-2-3'), 'tetrahedrane expl bonds'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('*12-*3-*-1-*-2-3'), 'tetrahedrane expl bonds dummy atoms'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('*12:*3:*:1-*-2-3'), 'tetrahedrane 2 ar rings dummy atoms'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('*12:*3:*:1:*:2-3'), 'tetrahedrane 1 ar ring  dummy atoms'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('C1CC2CCCC3C2C(C1)CCC3'), 'perhydrophenalene'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('c3c1cccc2\\C=C/Cc(c12)cc3'), 'phenalene stereo'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('c3c1cccc2C=CCc(c12)cc3'), 'pheyalene no stereo'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('c3c1cccc2CCCc(c12)cc3'), 'dihydrophenalene 2 ar, 1 al ring'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('c3:c1:c:c:c:c2-C-C-C-c(:c:1:2):c:c:3'), 'dihydrophenalene w explicit bonds'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('*3:*1:*:*:*:*2-*-*-*-*(:*:1:2):*:*:3'), 'phenalene expl bonds dummy atoms, 2 ar, 1 al ring '))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('*3:*1:*:*:*:*2:*:*:*:*(:*:1:2):*:*:3'), 'phenalene  expl bonds dummy atoms, 3 ar ring'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('*3:*1-*-*-*-*2-*-*-*-*(:*:1-2):*:*:3'), 'pheyalene expl bonds dummy atoms, 1 ar, 2 al rings'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('*3:*1:*:*:*:*2:*:*:[*H]:*(:*:1:2):*:*:3'), 'phenalene expl bonds dummy atoms 3 ar ring, * and [*H]'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('c3:c1:c:c:c:c2:c:c:[nH]:c(:c:1:2):c:c:3'), 'phenalene expl bonds, c [nH], 3 ar rings'))\n",
    "mols.append(Mol(Chem.MolFromSmiles('c1c[C+]1'), 'c1c[C+]1 cyclopropenium'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('c1:c:[C+]:1'), 'cyclopropenium, explicit ar bonds'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('c1c[BH]1'), 'c1c[BH]1 borirene with [BH]'))\n",
    "#mols.append(Mol(Chem.MolFromSmiles('*1:*:*:1'), '*1:*:*:1 cyclopropane skeleton, dummy atoms, explicit ar bonds'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 353,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg baseProfile=\"full\" height=\"250px\" version=\"1.1\" width=\"700px\" xml:space=\"preserve\" xmlns:rdkit=\"http://www.rdkit.org/xml\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g transform=\"translate(0,0)\"><rect height=\"250\" style=\"opacity:1.0;fill:#FFFFFF;stroke:none\" width=\"350\" x=\"0\" y=\"0\"> </rect>\n",
       "<path d=\"M 296.467,125 99.6427,11.3636\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 244.216,147.319 106.439,67.7739\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:6,6\"/>\n",
       "<path d=\"M 296.467,125 108.772,233.365\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 245.585,101.89 114.199,177.746\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:6,6\"/>\n",
       "<path d=\"M 99.6427,11.3636 99.6427,230.386\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1\"/>\n",
       "<path d=\"M 145.097,44.217 145.097,197.533\" style=\"fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-dasharray:6,6\"/>\n",
       "<text style=\"font-size:15px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#000000\" x=\"90.513\" y=\"246.886\"><tspan>C</tspan><tspan style=\"baseline-shift:super;font-size:11.25px;\">+</tspan><tspan/></text>\n",
       "<text style=\"font-size:12px;font-style:normal;font-weight:normal;fill-opacity:1;stroke:none;font-family:sans-serif;text-anchor:start;fill:#000000\" x=\"93.9388\" y=\"241\"><tspan>c1c[C+]1 cyclopropenium</tspan></text>\n",
       "</g>\n",
       "<g transform=\"translate(350,0)\"><rect height=\"250\" style=\"opacity:1.0;fill:#FFFFFF;stroke:none\" width=\"350\" x=\"0\" y=\"0\"> </rect>\n",
       "</g></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "execution_count": 353,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_mols = [mol.RDK_mol for mol in mols]\n",
    "my_descriptions = [mol.description for mol in mols]\n",
    "type(gridImage)\n",
    "gridImage = MolsToGridImage(my_mols, molsPerRow=2, subImgSize=(350, 250), legends=my_descriptions, useSVG=True, kekulize=False)\n",
    "gridImage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda env:rdk0]",
   "language": "python",
   "name": "conda-env-rdk0-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
