Viewing a reaction path diagram#

This script uses Graphviz to generate an image. You must have Graphviz installed and the program ‘dot’ must be on your path for this example to work. Graphviz can be obtained from https://www.graphviz.org/ or (possibly) installed using your operating system’s package manager.

Requires: cantera >= 2.5.0, graphviz

Tags: Python kinetics reaction path analysis pollutant formation

from subprocess import run
from pathlib import Path
import graphviz

import cantera as ct

Generate a Solution with a state where reactions are occurring#

these lines can be replaced by any commands that generate an object of a class derived from class Kinetics in some state.

gas = ct.Solution('gri30.yaml')
gas.TPX = 1300.0, ct.one_atm, 'CH4:0.4, O2:1, N2:3.76'
r = ct.IdealGasReactor(gas)
net = ct.ReactorNet([r])
T = r.T
while T < 1900:
    net.step()
    T = r.T

Create a reaction path diagram following nitrogen#

element = 'N'

diagram = ct.ReactionPathDiagram(gas, element)
diagram.title = 'Reaction path diagram following {0}'.format(element)
diagram.label_threshold = 0.01

Save the reaction path diagram#

dot_file = 'rxnpath.dot'
img_file = 'rxnpath.png'
img_path = Path.cwd().joinpath(img_file)

diagram.write_dot(dot_file)
print(diagram.get_data())

print(f"Wrote graphviz input file to '{Path.cwd().joinpath(dot_file)}'.")

run(f"dot {dot_file} -Tpng -o{img_file} -Gdpi=200".split())
print(f"Wrote graphviz output file to '{img_path}'.")
Reaction path diagram following N
N N2 NO N2O NO2 NH HNO NH2 NNH CN NCO HCN HOCN HNCO H2CN HCNN HCNO NH3
N N2 1.0608e-09 -0.000510821
N NO 0.000287478 -9.69824e-08
N N2O 0 -0
N NO2 0 -0
N NH 3.87974e-06 -4.19395e-06
N HNO 0 -0
N NH2 0 -0
N NNH 0 -0
N CN 1.12045e-11 -1.45842e-07
N NCO 1.05966e-08 -1.93057e-08
N HCN 3.10171e-05 -4.7182e-16
N HOCN 0 -0
N HNCO 0 -0
N H2CN 0.00014347 -3.31889e-10
N HCNN 0 -0
N HCNO 0 -0
N NH3 0 -0
N2 NO 5.4673e-06 -1.03236e-09
N2 N2O 0.000143109 -3.6284e-05
N2 NO2 0 -0
N2 NH 9.00346e-08 -2.86085e-11
N2 HNO 0 -0
N2 NH2 0 -0
N2 NNH 0.0271338 -0.0271053
N2 CN 3.71158e-07 -1.24508e-12
N2 NCO 2.76803e-13 -1.41513e-11
N2 HCN 0.000505007 -9.6134e-12
N2 HOCN 0 -0
N2 HNCO 0 -0
N2 H2CN 6.49841e-08 -2.09491e-11
N2 HCNN 0.000446281 -0.000439455
N2 HCNO 0 -0
N2 NH3 0 -0
NO N2O 6.92217e-11 -2.84723e-06
NO NO2 4.37729e-06 -3.78307e-06
NO NH 1.12592e-11 -2.31178e-06
NO HNO 2.40006e-07 -6.29759e-06
NO NH2 0 -0
NO NNH 7.81587e-12 -5.95793e-06
NO CN 1.87268e-09 -3.39502e-11
NO NCO 6.01736e-08 -8.78664e-07
NO HCN 1.48477e-06 -1.60288e-11
NO HOCN 0 -0
NO HNCO 1.58603e-06 -3.10615e-15
NO H2CN 6.88375e-08 -2.09993e-09
NO HCNN 1.04513e-22 -4.41931e-08
NO HCNO 2.21875e-06 -1.74634e-08
NO NH3 0 -0
N2O NO2 5.52481e-16 -8.46407e-14
N2O NH 2.58459e-06 -6.22013e-11
N2O HNO 0 -0
N2O NH2 0 -0
N2O NNH 0 -0
N2O CN 0 -0
N2O NCO 1.12701e-09 -7.10496e-12
N2O HCN 0 -0
N2O HOCN 0 -0
N2O HNCO 0 -0
N2O H2CN 0 -0
N2O HCNN 0 -0
N2O HCNO 0 -0
N2O NH3 0 -0
NO2 NH 0 -0
NO2 HNO 0 -0
NO2 NH2 0 -0
NO2 NNH 0 -0
NO2 CN 0 -0
NO2 NCO 0 -0
NO2 HCN 0 -0
NO2 HOCN 0 -0
NO2 HNCO 0 -0
NO2 H2CN 0 -0
NO2 HCNN 0 -0
NO2 HCNO 0 -0
NO2 NH3 0 -0
NH HNO 8.09138e-06 -1.18708e-06
NH NH2 9.2279e-07 -2.58356e-07
NH NNH 7.81587e-12 -5.95793e-06
NH CN 0 -0
NH NCO 1.61899e-08 -4.19046e-06
NH HCN 1.03057e-10 -2.50073e-06
NH HOCN 0 -0
NH HNCO 7.47656e-09 -1.56961e-08
NH H2CN 0 -0
NH HCNN 0 -0
NH HCNO 0 -0
NH NH3 0 -0
HNO NH2 4.72037e-09 -1.36038e-07
HNO NNH 0 -0
HNO CN 0 -0
HNO NCO 0 -0
HNO HCN 0 -0
HNO HOCN 0 -0
HNO HNCO 9.90946e-15 -6.5204e-12
HNO H2CN 0 -0
HNO HCNN 0 -0
HNO HCNO 0 -0
HNO NH3 0 -0
NH2 NNH 0 -0
NH2 CN 0 -0
NH2 NCO 0 -0
NH2 HCN 3.74139e-12 -4.37605e-08
NH2 HOCN 0 -0
NH2 HNCO 1.4613e-08 -3.44328e-07
NH2 H2CN 0 -0
NH2 HCNN 0 -0
NH2 HCNO 2.306e-17 -9.01273e-09
NH2 NH3 4.00922e-07 -7.77888e-08
NNH CN 0 -0
NNH NCO 0 -0
NNH HCN 0 -0
NNH HOCN 0 -0
NNH HNCO 0 -0
NNH H2CN 0 -0
NNH HCNN 0 -0
NNH HCNO 0 -0
NNH NH3 0 -0
CN NCO 4.91314e-06 -4.72254e-08
CN HCN 2.8998e-06 -8.05959e-06
CN HOCN 0 -0
CN HNCO 0 -0
CN H2CN 0 -0
CN HCNN 0 -0
CN HCNO 0 -0
CN NH3 0 -0
NCO HCN 1.06804e-07 -1.00128e-05
NCO HOCN 0 -0
NCO HNCO 4.70286e-06 -1.94489e-07
NCO H2CN 0 -0
NCO HCNN 0 -0
NCO HCNO 0 -0
NCO NH3 0 -0
HCN HOCN 1.72989e-06 -3.52964e-07
HCN HNCO 2.48749e-07 -4.85572e-10
HCN H2CN 1.02684e-07 -0.000140116
HCN HCNN 1.04513e-22 -4.41931e-08
HCN HCNO 5.88435e-13 -1.96628e-08
HCN NH3 0 -0
HOCN HNCO 5.49737e-07 -5.25937e-09
HOCN H2CN 0 -0
HOCN HCNN 0 -0
HOCN HCNO 0 -0
HOCN NH3 0 -0
HNCO H2CN 0 -0
HNCO HCNN 0 -0
HNCO HCNO 1.03396e-14 -1.76994e-07
HNCO NH3 0 -0
H2CN HCNN 0 -0
H2CN HCNO 0 -0
H2CN NH3 0 -0
HCNN HCNO 0 -0
HCNN NH3 0 -0
HCNO NH3 0 -0

Wrote graphviz input file to '/home/runner/work/cantera/cantera/build/doc/samples/python/kinetics/rxnpath.dot'.
Wrote graphviz output file to '/home/runner/work/cantera/cantera/build/doc/samples/python/kinetics/rxnpath.png'.

View the reaction path diagram#

graphviz.Source(diagram.get_dot())
reaction path

Total running time of the script: (0 minutes 0.248 seconds)

Gallery generated by Sphinx-Gallery