Function Repository Resource:

ReactionGrid

Source Notebook

Format a two-dimensional grid with a chemical reaction as the column headings

Contributed by: Wolfram Chemistry

ResourceFunction["ReactionGrid"][reaction,data]

builds a two-dimensional grid from data with the chemicals in reaction as column headings.

Details and Options

A balanced ChemicalReaction is not required for reaction.
ResourceFunction["ReactionGrid"] will automatically fill in missing values using PadRight.
ResourceFunction["ReactionGrid"] has the same options as Grid, with the following additions:
"DefaultValue"Nullvalue used by PadRight to fill in missing data
"FormulaStyle"Automaticadditional Style options for formatting chemical formulas
"IncludeCoefficients"Falseinclude existing stochiometric coefficients in column headings
"Labels"{Text["Reactants:"],Text["\nProducts:"]}labels used when "SplitReaction" is True
"Offset"AutomaticInteger number of columns preceeding the chemical data
"SplitReaction"Falsereturn the reactant and product data as separate grids in a Column
"ReactionArrow"arrow to use when "SplitReaction" is False

Examples

Basic Examples (3) 

Display names and stoichiometric coefficients in a Grid:

In[1]:=
ResourceFunction["ReactionGrid"][
 ChemicalReaction[<|ChemicalFormula[{"O" -> 3}, <|"Phase" -> "Gas"|>] -> 1|> -> <|ChemicalFormula[{"O" -> 2}, <|"Phase" -> "Gas"|>] -> 1|>],
 {{"ozone", "oxygen"}, {2, 3}}
 ]
Out[1]=

Include row labels and use Text to format grid elements as text:

In[2]:=
Text[ResourceFunction["ReactionGrid"][
  ChemicalReaction[<|ChemicalFormula[{"O" -> 3}, <|"Phase" -> "Gas"|>] -> 1|> -> <|ChemicalFormula[{"O" -> 2}, <|"Phase" -> "Gas"|>] -> 1|>],
  {{"Name", "ozone", "oxygen"}, {"Coefficient", 2, 3}}
  ]]
Out[2]=

Return the reactants and products as separate grids:

In[3]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/3bc142f9-613d-4349-80f2-798881caf2b0"]
Out[3]=

Scope (2) 

Build an empty table for the reaction between zinc hydroxide and hydrogen chloride:

In[4]:=
ResourceFunction["ReactionGrid"][
 ChemicalReaction[
  <|Entity["Chemical", "ZincHydroxide"] -> 1, Entity["Chemical", "HydrogenChloride"] -> 1|> ->
   <|Entity["Chemical", "ZincChloride"] -> 1, Entity["Chemical", "Water"] -> 2|>
  ],
 {{}, {}}
 ]
Out[4]=

An equivalent specification:

In[5]:=
ResourceFunction["ReactionGrid"][
 ChemicalReaction["Zn(OH)2+HCl->ZnCl2+2H2O"],
 {{}, {}}
 ]
Out[5]=

Options (7) 

DefaultValue (1) 

Change the value used by PadRight fill in missing values:

In[6]:=
ResourceFunction["ReactionGrid"][
 ChemicalReaction[<|ChemicalFormula[{"Br" -> 2}, <|"Phase" -> "Liquid"|>] -> 1|> -> <|ChemicalFormula[{"Br" -> 2}, <|"Phase" -> "Gas"|>] -> 1|>],
 {{}},
 "DefaultValue" -> x
 ]
Out[6]=

FormulaStyle (1) 

Change chemical formula formatting using Style options:

In[7]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/e2e8269b-d5de-44c4-b444-07644f8dbda0"]
Out[7]=

IncludeCoefficients (1) 

Include stoichiometric coefficients when "IncludeCoefficients" is True:

In[8]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/3a082d7f-1f1a-4710-aab8-fff15066ba16"]
Out[8]=

Labels (1) 

Change reactant and product labels when "SplitReaction" is True:

In[9]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/06d46248-660e-49db-aeee-99f18057a0c6"]
Out[9]=

Offset (1) 

Account for the presence of other columns of information in data by passing in an offset when the length of each row is less than the number of reactants and products:

In[10]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/505b08f8-607f-49bf-96d2-802da431f200"]
Out[10]=

SplitReaction (1) 

Return the reactant and product data as separate grids in a Column:

In[11]:=
ResourceFunction["ReactionGrid"][
 ChemicalReaction[<|Entity["Chemical", "Ethylene"] -> 1, Entity["Chemical", "MolecularChlorine"] -> 1|> -> <|Entity[
     "Chemical", "1,2Dichloroethane"] -> 1|>],
 {{"Volume", Quantity[2, "Milliliters"], Quantity[1.85`, "Milliliters"], Quantity[0.00662`, "Milliliters"]}},
 "SplitReaction" -> True
 ]
Out[11]=

ReactionArrow (1) 

Change the reaction arrow used in the grid header:

In[12]:=
ResourceFunction["ReactionGrid"][
 ChemicalReaction[<|ChemicalFormula[{"N" -> 2, "O" -> 2}] -> 1|> -> <|ChemicalFormula[{"N" -> 1, "O" -> 1}] -> 2|>],
 {{}},
 "ReactionArrow" -> "\[ReverseEquilibrium]"
 ]
Out[12]=

Properties and Relations (1) 

The reactant and product grids can be extracted with Part:

In[13]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/3e96bb85-3334-4b13-81fe-94a5429fc2d2"]
Out[13]=
In[14]:=
result[[1, {2, -1}]]
Out[14]=

Possible Issues (3) 

Duplicate chemicals are automatically combined by ChemicalReaction:

In[15]:=
ResourceFunction["ReactionGrid"][
 ChemicalReaction["NO+NO->N2O2"], {{}}]
Out[15]=

Use an alternative specification for ChemicalReaction employing an Entity and a ChemicalFormula to prevent such behavior:

In[16]:=
ResourceFunction["ReactionGrid"][
 ChemicalReaction[{Entity["Chemical", "NitricOxide"], ChemicalFormula["NO"]} -> {ChemicalFormula["N2O2"]}],
 {{}}
 ]
Out[16]=

Heterogeneous data may skew alignment of + and → with the Frame lines:

In[17]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/2ac10a0e-7730-4e0b-b519-be932fb76a6c"]
Out[17]=

Use ItemSize to fix that:

In[18]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/c771de9b-718a-4c6b-bdba-65e9d0891a95"]
Out[18]=

Invalid ChemicalReaction objects fail:

In[19]:=
ResourceFunction["ReactionGrid"][ChemicalReaction["H2O->"], {{}}]
Out[19]=

Neat Examples (1) 

Build an ICE table to solve chemical equilibrium problems:

In[20]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/638ce5c9-8e9e-4cac-a2cf-a097bb806330"]
Out[20]=

Publisher

WolframChemistry

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.1.0 – 15 October 2024
  • 1.0.0 – 04 October 2024

Related Resources

License Information