Summary
In this post I will show how to create a function called VitaminData[ ] using information available in the Wolfram Knowledgebase. This custom function will provide chemical and physical data, molecule visualizations, lists of food sources rich on a specific vitamin and other nutritional data.
Function, data, uses:
- List
By way of comparison, the vitamins in the list of entities:
EntityList@EntityClass["Chemical", "Vitamins"]

The function I created has an extended list of vitamins, of course some are questionable and/or old definitions, but I found it interesting to add to the function for didactic reasons and to make the study more complete.
VitaminData["List"]
- Show
Using the function more simply we get the vitamin in the form of entity:
VitaminData["A"]
![]()
With the optional Show we have several options, one of them is the 2D model:
VitaminData["B12", "Show" -> "Model2D"]
Using Show for the 3D model:
VitaminData["B12", "Show" -> "Model3D"]
We can visualize each bond in the molecule with “Show” and “Bonds”:
VitaminData["B5", "Show" -> "Bonds"]
We can count atoms and show their respective charges with “Show” and “Atoms”:
VitaminData["B12", "Show" -> "Atoms"]
![]()
To have the complete list of properties available in the optional Show, use Properties:
VitaminData["A", "Show" -> "Properties"]
For example, the molecular mass:
VitaminData["H", "Show" -> "MolecularMass"]
![]()
Another example of one of the properties from the list above is NFPALabel:
VitaminData["K1", "Show" -> "NFPALabel"]
With the optional Show and Data, all properties of the above list are shown at once, interactively:
VitaminData["C", "Show" -> "Data"]
- Food
Another function option is Food, where the relative amount of each vitamin in a specific food is determined:
VitaminData["C", "Food" -> "Banana"]
![]()
If we use the function only with Food, without naming the vitamin, the full list of vitamins for a specific food is shown:
VitaminData["Food" -> "Apple"]
- Nutritional Information
Another option for the function is Nutri, which is the nutritional information of foods in label form. Below is the example for four types of foods:
Table[VitaminData[
"Nutri" -> n], {n, {"Banana", "Carrot", "Shrimp", "Salmon"}}]
Code
-
Code of the function VitaminData[]:
VitaminData["List"] := VitaminData["A", "Show" -> "List"]; VitaminData[vita_, OptionsPattern[]] := Module[{Vitamin, vitamins, ss, cc, a0, a1, a2, a3, a4, a5, a6, a7, ai}, Options[VitaminData] = {"Show" -> "Entity"}; ss = {"A", "B1", "B2", "B3", "B4", "B5", "B6", "B12", "C", "D2", "D3", "H", "H1", "K1", "K3", "K5", "M", "P", "AlphaTocopherol", "DAlphaTocopherol", "Niacin", "Choline"}; Vitamin[vit_] := (vitamins = Join[Table[ Entity["Chemical", StringJoin["Vitamin", i]], {i, {"A", "B1", "B2", "B3", "B4", "B5", "B6", "B12", "C", "D2", "D3", "H", "H1", "K1", "K3", "K5", "M", "P"}}], Table[Entity["Chemical", j], {j, {"AlphaTocopherol", "DAlphaTocopherol", "Niacin", "Choline"}}]]; cc = vit /. AssociationThread[ss, Range@22]; vitamins[[cc]]); a0 = Thread[{ss, Vitamin[All]}]; a1 = Vitamin[vita]; a2 = Dataset[ EntityValue[Vitamin[vita], EntityValue[Vitamin[vita], "Properties"], "PropertyAssociation"]]; a3 = MoleculePlot[Vitamin[vita], ImageSize -> Large]; a4 = MoleculePlot3D[Vitamin[vita], ImageSize -> Large]; a5 = BondList@Vitamin[vita]; a6 = Counts@AtomList@Vitamin[vita]; a7 = Thread[{Map[Text[Style[#, Small]] &, DeleteCases[ StringReplace[ StringDelete[ EntityValue[Entity["Chemical", "VitaminA"], "Properties"] // InputForm // ToString, {"EntityProperty[", "Chemical", "]"}], {FromCharacterCode[32] -> ""}] // ToExpression, ""]], EntityValue[Entity["Chemical", "VitaminA"], "Properties"]}]; ai = EntityValue[Vitamin[vita], OptionValue["Show"]]; If[MemberQ[{"List", "Entity", "Data", "Model2D", "Model3D", "Bonds", "Atoms", "Mass", "Properties"}, OptionValue["Show"]] == True, OptionValue["Show"] /. {"List" -> a0, "Entity" -> a1, "Data" -> a2, "Model2D" -> a3, "Model3D" -> a4, "Bonds" -> a5, "Atoms" -> a6, "Properties" -> a7}, ai]] VitaminData["Nutri" -> al_] := {Entity["FoodType", al], Entity[ "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{Entity["FoodType", al]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}][ EntityProperty["Food", "NutritionLabel"]]}; VitaminData[x_, "Food" -> y_] := Module[{bb}, bb = Entity[ "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{Entity["FoodType", y]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}][ EntityProperty["Food", x /. AssociationThread[{"A", "B1", "B2", "B3", "B4", "B5", "B6", "B12", "C", "D2", "D3", "H", "H1", "K1", "K3", "K5", "M", "P", "AlphaTocopherol", "DAlphaTocopherol", "Niacin", "Choline"}, {"RelativeVitaminAContent", "RelativeThiaminContent", "RelativeRiboflavinContent", "NoData", "NoData", "RelativePantothenicAcidContent", "RelativeVitaminB6Content", "RelativeVitaminB12Content", "RelativeVitaminCContent", "RelativeVitaminD2Content", "RelativeVitaminD3Content", "RelativeBiotinContent", "NoData", "RelativeVitaminKContent", "RelativeVitaminKContent", "RelativeVitaminKContent", "RelativeFolicAcidContent", "NoData", "RelativeVitaminEContent", "RelativeVitaminEContent", "RelativeNiacinContent", "RelativeCholineContent"}]]]; If[QuantityQ[bb] == True, {x, bb}, {x, "NoData"}]]; VitaminData["Food" -> an_] := Map[VitaminData[#, "Food" -> an] &, {"A", "B1", "B2", "B3", "B4", "B5", "B6", "B12", "C", "D2", "D3", "H", "H1", "K1", "K3", "K5", "M", "P", "AlphaTocopherol", "DAlphaTocopherol", "Niacin", "Choline"}]
Food Ranking
Below we can see that there are 1816 foods in the Mathematica database as FoodType entities. I decided to leave this option out of the VitaminData[] function because each evaluation takes a long time to perform.
SparseArray@EntityList@Entity["FoodType"]

Below are some examples of vitamin ranking lists (top 10 foods) for all foods in the database. In this case I could specify some very specific types as well, such as Beta-Tocopherol (instead of Alpha-Tocopherol, for example) and vitamin D3:
-
Vitamin C
MaximalBy[ Thread[{EntityList@Entity["FoodType"], Map[Entity[ "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{#}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}][ EntityProperty["Food", "RelativeVitaminCContent"]] &, EntityList@Entity["FoodType"]]}], Last, UpTo[10]]
-
Vitamin A
MaximalBy[ Thread[{EntityList@Entity["FoodType"], Map[Entity[ "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{#}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}][ EntityProperty["Food", "RelativeVitaminAContent"]] &, EntityList@Entity["FoodType"]]}], Last, UpTo[10]]
-
Vitamin B6
MaximalBy[ Thread[{EntityList@Entity["FoodType"], Map[Entity[ "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{#}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}][ EntityProperty["Food", "RelativeVitaminB6Content"]] &, EntityList@Entity["FoodType"]]}], Last, UpTo[10]]
-
Beta-Tocopherol
MaximalBy[ Thread[{EntityList@Entity["FoodType"], Map[Entity[ "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{#}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}][ EntityProperty["Food", "RelativeBetaTocopherolContent"]] &, EntityList@Entity["FoodType"]]}], Last, UpTo[10]]
-
Vitamin D3
MaximalBy[ Thread[{EntityList@Entity["FoodType"], Map[Entity[ "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{#}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}][ EntityProperty["Food", "RelativeVitaminD3Content"]] &, EntityList@Entity["FoodType"]]}], Last, UpTo[10]]
These lists above were just a few examples of vitamin ranking using all foods in the database and could be extended to various other substances.
Thanks.














