{
"cells": [
{
"cell_type": "markdown",
"id": "a5f85e1f",
"metadata": {},
"source": [
"# Finding Stereoisomers of Molecules #"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "aff3d8fe",
"metadata": {},
"outputs": [],
"source": [
"from rdkit import Chem\n",
"\n",
"from stereomolgraph import StereoMolGraph\n",
"from stereomolgraph.experimental import generate_stereoisomers\n",
"from stereomolgraph.ipython import View2D\n",
"\n",
"from IPython.core.interactiveshell import InteractiveShell\n",
"\n",
"InteractiveShell.ast_node_interactivity = \"all\"\n",
"\n",
"View2D.show_atom_numbers = True\n",
"View2D.show_h = False\n",
"View2D.generate_bond_orders = True # bond orders are not used internally"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "4bb173bc",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rdmol = Chem.AddHs(\n",
" Chem.MolFromSmiles(\"[CH]1([CH](C1C2[CH]([CH]2C(=O)O)C(=O)O)C(=O)O)C(=O)O\")\n",
")\n",
"smg = StereoMolGraph.from_rdmol(rdmol, stereo_complete=False)\n",
"smg"
]
},
{
"cell_type": "markdown",
"id": "079c8f53",
"metadata": {},
"source": [
"### Construction from `rdkit.Mol`\n",
"\n",
"When constructing from an `rdkit.Mol` with `stereo_complete=False`, any atom without explicitly defined stereochemistry is treated as **undefined**.\n",
"\n",
"Using `generate_stereoisomers` will enumerate all **distinct stereoisomers** without producing duplicates."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "7d4a3631",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"isomers = list(generate_stereoisomers(smg, enantiomers=True))\n",
"# enantiomes are removed\n",
"len(isomers)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "fbb9673b",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"for isomer in isomers:\n",
" isomer"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "dcca7323",
"metadata": {
"tags": [
"hide-cell"
]
},
"outputs": [
{
"data": {
"text/plain": [
"[[(0, 'R'), (1, 'R'), (4, 'R'), (5, 'R')],\n",
" [(0, 'R'), (1, 'R'), (4, 'S'), (5, 'S')],\n",
" [(0, 'R'), (1, 'S'), (2, 'R'), (3, 'R'), (4, 'S'), (5, 'R')],\n",
" [(0, 'R'), (1, 'S'), (2, 'R'), (3, 'S'), (4, 'R'), (5, 'S')],\n",
" [(0, 'R'), (1, 'S'), (2, 'R'), (4, 'R'), (5, 'R')],\n",
" [(0, 'R'), (1, 'S'), (2, 'R'), (4, 'S'), (5, 'S')],\n",
" [(0, 'R'), (1, 'S'), (2, 'S'), (3, 'S'), (4, 'R'), (5, 'S')],\n",
" [(0, 'R'), (1, 'S'), (2, 'S'), (4, 'R'), (5, 'R')],\n",
" [(0, 'R'), (1, 'S'), (2, 'S'), (4, 'S'), (5, 'S')],\n",
" [(0, 'S'), (1, 'S'), (4, 'S'), (5, 'S')]]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"all_isomers_stereo = []\n",
"\n",
"for i in isomers:\n",
" rdmol = i.to_rdmol(generate_bond_orders=True)\n",
"\n",
" stereocenters = Chem.FindMolChiralCenters(\n",
" rdmol, includeUnassigned=False, force=True\n",
" )\n",
"\n",
" isomer_stereo = []\n",
" for atom_idx, stereo in stereocenters:\n",
" atom = rdmol.GetAtomWithIdx(atom_idx)\n",
" atom_idx = atom.GetIdx()\n",
" isomer_stereo.append((atom_idx, stereo))\n",
"\n",
" isomer_stereo.sort()\n",
" all_isomers_stereo.append(isomer_stereo)\n",
"\n",
"all_isomers_stereo.sort()\n",
"all_isomers_stereo"
]
}
],
"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.14.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}