2D Reaction Schematics from PLAMS Molecules
*******************************************

Technical Visualization Reaction equations

Generate compact 2D depictions of reactants and products directly from
PLAMS molecule objects for reports and notebooks.

**Requires:** AMS2026 or later

-[ Related examples ]-

* Balancing Reaction Equations from Formulas and Structures

-[ Related tutorials ]-

* Building molecules tutorial

* Python Getting Started tutorial

-[ Related documentation ]-

* PLAMS RDKit interface

* PLAMS Molecule class

[image]


Creating 2D images of molecules
===============================

   from IPython.display import SVG
   from scm.plams import ReactionEquation
   from scm.plams import from_smiles, to_image, get_reaction_image

   img_size=(150, 150)
   aspirin = from_smiles("CC(=O)OC1=CC=CC=C1C(=O)O")
   text = to_image(aspirin, size=img_size)
   SVG(text)

   [image: image generated from notebook][image]

It is also possible to write the image to file in a range of different
formats (SVG, PNG, EPS, PDF, JPEG)

   text = to_image(aspirin, filename="aspirin.svg")
   text = to_image(aspirin, filename="aspiring.png")


Creating 2D images of reactions
===============================

We can have aspirin react with water to form acetic acid and salicylic
acid

   acetic_acid = from_smiles("CC(O)=O")
   text = to_image(acetic_acid, size=img_size)
   SVG(text)

   [image: image generated from notebook][image]

   salicylic_acid = from_smiles("O=C(O)c1ccccc1O")
   text = to_image(salicylic_acid, size=img_size)
   SVG(text)

   [image: image generated from notebook][image]

We can create a 2D image of the reaction as well, and optionally store
it to file

   reactants = [aspirin, from_smiles("O")]
   products = [acetic_acid, salicylic_acid]
   text = get_reaction_image(reactants, products, filename="reaction.svg")
   SVG(text)

   [image: image generated from notebook][image]


See also
========


Related examples
----------------

* Balancing Reaction Equations from Formulas and Structures


Related tutorials
-----------------

* Building molecules tutorial

* Python Getting Started tutorial


Related documentation
---------------------

* PLAMS RDKit interface

* PLAMS Molecule class


Python Script
=============

   #!/usr/bin/env python
   # coding: utf-8

   # ## Creating 2D images of molecules

   from IPython.display import SVG
   from scm.plams import ReactionEquation
   from scm.plams import from_smiles, to_image, get_reaction_image

   img_size = (150, 150)
   aspirin = 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 in a range of different formats (SVG, PNG, EPS, PDF, JPEG)

   text = to_image(aspirin, filename="aspirin.svg")
   text = to_image(aspirin, filename="aspiring.png")


   # ## Creating 2D images of reactions

   # We can have aspirin react with water to form acetic acid and salicylic acid

   acetic_acid = from_smiles("CC(O)=O")
   text = to_image(acetic_acid, size=img_size)
   SVG(text)


   salicylic_acid = 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, from_smiles("O")]
   products = [acetic_acid, salicylic_acid]
   text = get_reaction_image(reactants, products, filename="reaction.svg")
   SVG(text)
