{
"cells": [
{
"cell_type": "markdown",
"id": "97297c43",
"metadata": {},
"source": [
"## Creating 2D images of molecules"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "5492c24c",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import SVG\n",
"from scm.plams import ReactionEquation\n",
"from scm.plams import from_smiles, to_image, get_reaction_image\n",
"\n",
"img_size = (150, 150)\n",
"aspirin = from_smiles(\"CC(=O)OC1=CC=CC=C1C(=O)O\")\n",
"text = to_image(aspirin, size=img_size)\n",
"SVG(text)"
]
},
{
"cell_type": "markdown",
"id": "1197ae3d",
"metadata": {},
"source": [
"It is also possible to write the image to file in a range of different formats (SVG, PNG, EPS, PDF, JPEG)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c8ea1fc3",
"metadata": {},
"outputs": [],
"source": [
"text = to_image(aspirin, filename=\"aspirin.svg\")\n",
"text = to_image(aspirin, filename=\"aspiring.png\")"
]
},
{
"cell_type": "markdown",
"id": "c4c0c08a",
"metadata": {},
"source": [
"## Creating 2D images of reactions"
]
},
{
"cell_type": "markdown",
"id": "96d8ae00",
"metadata": {},
"source": [
"We can have aspirin react with water to form acetic acid and salicylic acid"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "cb96c8e4",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"acetic_acid = from_smiles(\"CC(O)=O\")\n",
"text = to_image(acetic_acid, size=img_size)\n",
"SVG(text)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6491b163",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"salicylic_acid = from_smiles(\"O=C(O)c1ccccc1O\")\n",
"text = to_image(salicylic_acid, size=img_size)\n",
"SVG(text)"
]
},
{
"cell_type": "markdown",
"id": "ced4b84e",
"metadata": {},
"source": [
"We can create a 2D image of the reaction as well, and optionally store it to file"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8fb3d7e0",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reactants = [aspirin, from_smiles(\"O\")]\n",
"products = [acetic_acid, salicylic_acid]\n",
"text = get_reaction_image(reactants, products, filename=\"reaction.svg\")\n",
"SVG(text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "94ce3a02-b7d4-4dcc-aab3-6770b0402e6d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}