{
"cells": [
{
"cell_type": "markdown",
"id": "6223ccee-4f30-47da-9796-3f08b3387fae",
"metadata": {},
"source": [
"## Creating 2D images of molecules"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "d8479d8e-8f2b-4882-94a9-0914e838ffc8",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 46,
"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",
"aspirin = from_smiles(\"CC(=O)OC1=CC=CC=C1C(=O)O\")\n",
"text = to_image(aspirin)\n",
"SVG(text)"
]
},
{
"cell_type": "markdown",
"id": "530d601b-eac3-4849-b5a3-1f7418c3edd0",
"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": 49,
"id": "7b452b79-2c62-4bdd-b129-268ff0c0117c",
"metadata": {},
"outputs": [],
"source": [
"text = to_image(aspirin, filename=\"aspirin.svg\")\n",
"text = to_image(aspirin, filename=\"aspiring.png\")"
]
},
{
"cell_type": "markdown",
"id": "79095131-3e8b-4abb-8dfd-5fa7ea11ca49",
"metadata": {},
"source": [
"## Creating 2D images of reactions"
]
},
{
"cell_type": "markdown",
"id": "a2c93688-af57-416d-ba52-389b69314435",
"metadata": {},
"source": [
"We can have aspirin react with water to form acetic acid and salicylic acid"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "5366f0ff-6435-4b6c-802f-f521ced86d4c",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"acetic_acid = from_smiles(\"CC(O)=O\")\n",
"text = to_image(acetic_acid)\n",
"SVG(text)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "5316bb6a-c850-41ac-b3dd-9a33eec653a5",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"salicylic_acid = from_smiles(\"O=C(O)c1ccccc1O\")\n",
"text = to_image(salicylic_acid)\n",
"SVG(text)"
]
},
{
"cell_type": "markdown",
"id": "ed975357-5d66-4090-ac85-a13cad4cc95c",
"metadata": {},
"source": [
"We can create a 2D image of the reaction as well, and optionally store it to file"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "2169688f-97ff-4777-b01b-747c643f06d6",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 52,
"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)"
]
}
],
"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
}