2D Reaction Schematics from PLAMS Molecules¶
Generate compact 2D depictions of reactants and products directly from PLAMS molecule objects for reports and notebooks.
Creating 2D images of molecules¶
from IPython.display import SVG
from scm.base import ChemicalSystem
from scm.plams import ReactionEquation
from scm.plams import to_image, get_reaction_image
img_size = (150, 150)
aspirin = ChemicalSystem.from_smiles("CC(=O)OC1=CC=CC=C1C(=O)O")
text = to_image(aspirin, size=img_size)
SVG(text)
It is also possible to write the image to file. SVG is a convenient default for notebooks because it stays sharp at any display size.
text = to_image(aspirin, filename="aspirin.svg")
Creating 2D images of reactions¶
We can have aspirin react with water to form acetic acid and salicylic acid
acetic_acid = ChemicalSystem.from_smiles("CC(O)=O")
text = to_image(acetic_acid, size=img_size)
SVG(text)
salicylic_acid = ChemicalSystem.from_smiles("O=C(O)c1ccccc1O")
text = to_image(salicylic_acid, size=img_size)
SVG(text)
We can create a 2D image of the reaction as well, and optionally store it to file
reactants = [aspirin, ChemicalSystem.from_smiles("O")]
products = [acetic_acid, salicylic_acid]
text = get_reaction_image(reactants, products, filename="reaction.svg")
SVG(text)
See also¶
Python Script¶
#!/usr/bin/env python
# coding: utf-8
# ## Creating 2D images of molecules
from IPython.display import SVG
from scm.base import ChemicalSystem
from scm.plams import ReactionEquation
from scm.plams import to_image, get_reaction_image
img_size = (150, 150)
aspirin = ChemicalSystem.from_smiles("CC(=O)OC1=CC=CC=C1C(=O)O")
text = to_image(aspirin, size=img_size)
SVG(text)
# It is also possible to write the image to file. SVG is a convenient default for notebooks because it stays sharp at any display size.
text = to_image(aspirin, filename="aspirin.svg")
# ## Creating 2D images of reactions
# We can have aspirin react with water to form acetic acid and salicylic acid
acetic_acid = ChemicalSystem.from_smiles("CC(O)=O")
text = to_image(acetic_acid, size=img_size)
SVG(text)
salicylic_acid = ChemicalSystem.from_smiles("O=C(O)c1ccccc1O")
text = to_image(salicylic_acid, size=img_size)
SVG(text)
# We can create a 2D image of the reaction as well, and optionally store it to file
reactants = [aspirin, ChemicalSystem.from_smiles("O")]
products = [acetic_acid, salicylic_acid]
text = get_reaction_image(reactants, products, filename="reaction.svg")
SVG(text)