# Wolfram Language™

## Prepare Aspirin

Aspirin is one of the most commonly used medications for treating pain, fever, and inflammation. It can be synthesized by combining equimolar amounts of salicylic acid and acetic anhydride. Here, chemical data from the Wolfram Knowledgebase is used together with the quantity framework and entity groups, copies, and instances to study the chemical preparation of aspirin.

Represent a typical laboratory batch for a 100-millimolar preparation of aspirin using EntityGroup.

In:= ```reactants = EntityGroup[{EntityInstance[Entity["Chemical", "SalicylicAcid"], Quantity[0.1, "Moles"]], EntityInstance[Entity["Chemical", "AceticAnhydride"], Quantity[0.1, "Moles"]]}]```
Out= Compute the total mass of this batch using a "curried" form of an entity-property query.

In:= `mass = reactants["AbsoluteMass"]`
Out= Because acetic anhydride is a liquid, it would be convenient to know exactly how much is needed.

In:= ```UnitConvert[ EntityInstance[Entity["Chemical", "AceticAnhydride"], Quantity[0.1, "Moles"]]["AbsoluteVolume"], "Milliliter"]```
Out= Assuming a stoichiometric, i.e. a (theoretical) quantitative reaction, this yields 100 millimoles of aspirin. However, in practice, yields of about 90% will be achieved.

In:= ```EntityInstance[Entity["Chemical", "Aspirin"], 0.9*Quantity[0.1, "Moles"]]["AbsoluteMass"]```
Out= Count constituent atoms of the aspirin molecule.

In:= `elem = Entity["Chemical", "Aspirin"]["ElementCounts"]`
Out= Assemble the proper numbers of these atoms into a grouped entity expression.

In:= ```atomAssemble = EntityGroup[ MapThread[EntityCopies[#1, #2] &, {Keys[elem], Values[elem]}]]```
Out= In:= `atomicmass = atomAssemble["AtomicMass"]`
Out= As expected, the overall atomic mass of this entity group coincides with the molar mass of the whole molecule.

In:= ```molarmass = Entity["Chemical", "Aspirin"][ EntityProperty["Chemical", "MolarMass"]]```
Out= In:= `Equal @@ QuantityMagnitude /@ {atomicmass, molarmass}`
Out= However, there are other possible isotopic combinations, each of them with a slightly different total mass.

In:= ```stableIsotopes = #[EntityProperty["Element", "StableIsotopes"]] & /@ Keys[elem]```
Out= This group consists of the standard isotopes only (the so-called "principal ion").

In:= ```EntityGroup[{EntityCopies[Entity["Isotope", "C12"], 9], EntityCopies[Entity["Isotope", "H1"], 8], EntityCopies[Entity["Isotope", "O16"], 4]}]["AtomicMass"]```
Out= The probability of the occurrence of a molecule with such a composition is less than 90%. Nevertheless, in a mass spectrum it would be the most prominent molecular peak.

In:= ```Times @@ MapThread[(QuantityMagnitude[#1[ EntityProperty["Isotope", "IsotopeAbundance"]], "PureUnities"])^#2 &, {stableIsotopes[[All, 1]], Values[elem]}]```
Out= 