4
$\begingroup$

v13 added some interesting-sounding chemical species functions like ChemicalReaction. But they don't seem to have any operations.

For example the most common operation would be adding / composing reactions and cancelling intermediates, like:

ChemicalReaction["methane + water -> CO + 3 dihydrogen"]
ChemicalReaction["CO + water -> carbon dioxide + dihydrogen"]
% + %%

But this produces nothing. ApplyReaction doesn't accept a ChemicalReaction either. So do you add/compose reactions?

$\endgroup$
2
  • $\begingroup$ There isn't anything built in but you should be able to write a function to do what you are looking for. Can you describe what you would expect back from adding the two reactions? $\endgroup$
    – Jason B.
    Commented Oct 3, 2022 at 17:32
  • $\begingroup$ r1=ChemicalReaction["methane + water -> CO + 3 dihydrogen"]; r2=ChemicalReaction["CO + water -> carbon dioxide + dihydrogen"]; addReactions[r1_,r2_]:=ChemicalReaction[Merge[{r1["ReactantCounts"],r2["ReactantCounts"]},Total]->Merge[{r1["ProductCounts"],r2["ProductCounts"]},Total]]; addReactions[r1,r2] However, there seems to be no "ReactionSimplify" yet which would cancel the reactants and products, and ReactionBalance doesn't do it either. $\endgroup$
    – Domen
    Commented Oct 3, 2022 at 17:51

2 Answers 2

5
$\begingroup$
CirclePlus[r1_ChemicalReaction, r2_ChemicalReaction] := 
  Module[{r1b, r2b, reactants, products, reactantsMerged, total},
   r1b = ReactionBalance[r1];
   r2b = ReactionBalance[r2];

   reactants = Merge[{r1b["ReactantCounts"], r2b["ReactantCounts"]}, Total];
   products = Merge[{r1b["ProductCounts"], r2b["ProductCounts"]}, Total];
   total = Merge[{reactants, -products}, Total];

   reactants = KeyTake[reactants, Keys@Select[total, Positive]];
   products = KeyTake[products, Keys@Select[total, Negative]];

   ChemicalReaction[reactants -> products]
  ];

r1 = ChemicalReaction["methane + water -> CO + 3 dihydrogen"];
r2 = ChemicalReaction["CO + water -> carbon dioxide + dihydrogen"];

r1 ⊕ r2

Reaction

$\endgroup$
2
$\begingroup$

This is an added type of Interpreter. The name is ChemicalReaction. The is a concept of knowledge base use. There is the built-in ReactionBalance for the more advanced users with a reactions balance included.

The "one arrow" is the stereotype of the built-in. There is no adding as long as You do it by hand and type it in. Or enter a textual-based program that is doing this for You with the added.

This might be a question of similar intent: modeling chemical reactions can mathematica tell the end result of a reaction. So definitely Your given idea fails.

You are allowed to enter either a list or an association for what is right and what is left of the to-the-arrow. That is all and conforms with standards and norms. There is no standard for the reaction room or time. This has only the concept of equilibrium or quasi-equilibrium behind as background chemistry. Left are called reagents or reactants, right are products. These can be found in good encyclopedia-like: Chemical_reaction.

For chaining make a graphics output and image and composed it with built-in primitives like $Arrow$.

Kind of good insight into the theory beneath is Knowledge-based_systems. So let Yourself be inspired by my reference and enhance them or follow my first principle advise, add-up Yourself. Have fun.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.