# Getting Molecular Weight for Stoichiometry Calculations

I love the units system in Mathematica, it's an extremely useful addition to the language. Unfortunately there are still some sharp corners that I run into on a daily basis. For example, if I want to do a stoichiometry calculation, I would like to be able to do the following:

Vol = Quantity[300,"Microliters"]
Concentration = Quantity[2,"Millimolar"]
mgCd = UnitConvert[Concentration*Vol*CdMW,"Milligrams"]


But this does not work, because "MolecularWeight" reports units of AtomicMassUnit, which Mathematica indicates is incompatible with "Grams"/"Moles", even though in practice (at least for stoichiometry calculations) they are effectively the same.

I have a workaround using the following code:

CdMW = Quantity[QuantityMagnitude[ChemicalData["CadmiumOxide","MolecularWeight]],"Grams"/"Moles"]


But I find this to be quite inelegant, and somewhat less than readable.

Is this the best way to do this, or is there a better approach?

• I've run into this problem too and each time I just write a helper function as a workaround. Very cumbersome. Oct 11, 2022 at 19:50

The "MolarMass" property has the same magnitude but the right unit dimensions for this application:

CdMW = ChemicalData["CadmiumOxide", "MolarMass"]
(* Quantity[128.413, ("Grams")/("Moles")] *)
mgCd = UnitConvert[Concentration*Vol*CdMW, "Milligrams"]
(* Quantity[0.077048, "Milligrams"] *)


As an aside, you can use WolframAlpha in your notebook for some inputs like this. Here the input string "convert 300 microliters 2mM cadmium oxide to milligrams" works:

• I was aware of the WolframAlpha technique, but it's a bit brittle, especially if I want to share the notebook with someone. It also gives some strange results occasionally. Try the following query in WolframAlpha Molar Mass Selenium Oct 11, 2022 at 19:45
• You are absolutely right, but we are trying to improve. For the selenium example I agree the "Element" entity should win over the "Chemical" entity with formula Se8. If you see something which seems wrong there you can click the "feedback" button on the bottom and it will go on someone's todo list Oct 11, 2022 at 19:56
• @JasonB. Thanks for your work on this, it's a very useful feature. Oct 11, 2022 at 20:09
• @JasonB. WolframAlpha is already quite incredible, and I definitely use it for exploratory analysis/finding the correct compound name for something. This may just be my issue, but I don't know of a way to set a variable to the output of a W|A query other than using %ans notation. The feedback button is a useful feature that I wasn't aware of, and will make use of in the future. Oct 11, 2022 at 21:33