Computational Food and Nutrition

Gay Wilson, Wolfram Research

#WolframTechConf

ABSTRACT

This talk will cover how to compute, analyze and visualize food and nutrition data in Wolfram Language.

Students, educators, researchers, developers and everyone who loves food can be creative and productive with computable, semantic representation of food.

We also will explore the molecular structures of chemical compounds in foods and introduce food physics in Wolfram|Alpha.

Topics

Food queries with Interpreter

Natural language queries

Nutrition label

Fast and easy nutrition analysis with food resource functions

NutritionLabelData

NutritionReport

NutrientComparisonBarChart

AminoAcidsBarChart

EssentialAminoAcidsChart

Food chemistry

Omega-3 and omega-6 fatty acids

Monounsaturated and saturated fats

Caffeine and theobromine

Amino acids clustering tree

Colors of turmeric, saffron and paprika

Oregano and thyme isomers

Structure of spicy mustard, wasabi and horseradish

Food physics in Wolfram|Alpha

Food queries with Interpreter

Use Interpreter to retrieve the implicit entity for a food:

Interpreter["Food"]["steamed broccoli"]

The nutrition data for each implicit food entity is a compilation of all the nutrition data stored in the explicit food entities associated with the implicit entity.

Use EntityList to view the explicit entities that compose an implicit food entity:

Natural language queries

To get a computable expression for a nutrient in a specific amount of a food, press Ctrl= to open an input box.

Type your query in natural language and press Shift+Enter:

Use the N function if you prefer the result in numerical (decimal) form, rather than scientific notation:

Nutrition label

The nutrition label is a valuable tool for assessing the nutrient composition of a food and the percent of recommended daily values that food serving provides (based on 2,000 calories per day).

Get the nutrition label for a single serving of a food:

EntityValue[Interpreter["Food"]["tofu"],"NutritionLabel"]

Fast and easy nutrition analysis

The Wolfram Function Repository hosts a collection of standalone functions for immediate use in any Wolfram Language computation.

NutrientComparisonBarChart

Create a dual bar chart comparing the calories and macronutrients in a list of foods:

ResourceFunction["NutrientComparisonBarChart"][{"braised beef","cooked lentils","boiled eggs","peanut butter","fried tofu","grilled chicken"},ChartStyle->"Pastel",BarSpacing->"None",PlotLabel->"High-Protein Foods",FontSize->10,ImageSize->300]

NutritionLabelData

Quickly retrieve the most requested nutrients and the percent daily value (%DV) provided by a quantity of a food, such as 3 oz beef:

ResourceFunction["NutritionLabelData"]["3oz beef"]

NutritionReport

Get the macronutrient values for recipes, such as this Dijon vinaigrette:

ResourceFunction["NutritionReport"][{"1 Tbsp Dijon mustard","5g shallot","2 Tbsp wine vinegar","1/3 cup olive oil"}]

Display the output as a Tabular object:

ResourceFunction["NutritionReport"][{"1 Tbsp Dijon mustard","5g shallot","2 Tbsp wine vinegar","1/3 cup olive oil"},"Tabular"]

Display the output as an ASCII table to see the total macronutrient values for the recipe:

ResourceFunction["NutritionReport"][{"1 Tbsp Dijon mustard","5g shallot","2 Tbsp wine vinegar","1/3 cup olive oil"},"ASCIITable"]

AminoAcidsBarChart

The human body needs 20 different amino acids to function properly, which combine in multiple ways to build proteins. You can create a custom bar chart of amino acid content for a list of foods.

Choose one of the 20 amino acids in the dropdown list for a 2D bar chart:

ResourceFunction["AminoAcidsBarChart"][{"beef","chicken","eggs","pork","tempeh"}]

Display the data in a 3D bar chart, and uncheck foods to remove them from the chart:

ResourceFunction["AminoAcidsBarChart"][{"beef","chicken","eggs","pork","tempeh"}]

Choose All to display a comprehensive 3D bar chart:

ResourceFunction["AminoAcidsBarChart"][{"salmon","mackerel","tuna"}]

EssentialAminoAcidsChart

There are nine amino acids that the human body cannot synthesize on its own to meet physiological needs. These “essential amino acids” must be supplied by protein foods in the diet.

Create a bar chart comparing the nine essential amino acids in a list of foods:

ResourceFunction["EssentialAminoAcidsChart"][{"chicken","turkey"},ChartStyle->"DarkBands",PlotLabel->"Essential Amino Acids in Poultry",ImageSize->400]

Food chemistry

Molecular structure is key to determining many characteristics of a food.

Nutrients and other chemicals that compose our foods lend themselves to pairs, such as omega-3 and omega-6 fatty acids.

With the MoleculeFeatureDistance function, also known as molecule fingerprint distance, you can compute the dissimilarity between two molecules.

On a scale of 0 to 1, a smaller distance indicates higher similarity; a larger distance indicates greater dissimilarity.

Omega-3 and omega-6 fatty acids

Linoleic acid and alpha-linolenic acid molecules are both 18-carbon chains and very similar in molecular structure, with a short molecule feature distance:

MoleculeFeatureDistance[(Entity["linoleic acid", Entity["Chemical","LinoleicAcid"], "Entity[\"Chemical\", \"LinoleicAcid\"]", "chemical"]),(Entity["linolenic acid", Entity["Chemical","LinolenicAcid"], "Entity[\"Chemical\", \"LinolenicAcid\"]", "chemical"])]

That small variation in their structure makes them nutritionally distinct.

Found in plant-based oils, linoleic acid is an omega-6 fatty acid, with its first double bond located six carbons from the methyl end of the chain (–(Subscript[CH, 3])). Alpha-linolenic acid (ALA) is an omega-3 fatty acid, with its first double bond three carbons from the methyl end.

MoleculePlot/@{(Entity["linoleic acid", Entity["Chemical","LinoleicAcid"], "Entity[\"Chemical\", \"LinoleicAcid\"]", "chemical"]),(Entity["linolenic acid", Entity["Chemical","LinolenicAcid"], "Entity[\"Chemical\", \"LinolenicAcid\"]", "chemical"])}

Foods high in ALA include walnuts, flax seeds and certain plant-based oils. As an omega-3 fatty acid, ALA is beneficial for cardiovascular health.

Monounsaturated and saturated fats

The long-chain fatty acids oleic acid and palmitic acid are structurally similar:

MoleculeFeatureDistance[(Entity["oleic acid", Entity["Chemical","OleicAcid"], "Entity[\"Chemical\", \"OleicAcid\"]", "chemical"]),(Entity["palmitic acid", Entity["Chemical","PalmiticAcid"], "Entity[\"Chemical\", \"PalmiticAcid\"]", "chemical"])]

However, oleic acid is monounsaturated (one double bond), and palmitic acid is saturated (no double bonds), which affects their melting point and nutritional status.

MoleculePlot/@{(Entity["oleic acid", Entity["Chemical","OleicAcid"], "Entity[\"Chemical\", \"OleicAcid\"]", "chemical"]),(Entity["palmitic acid", Entity["Chemical","PalmiticAcid"], "Entity[\"Chemical\", \"PalmiticAcid\"]", "chemical"])}

Oleic acid is abundant in olive oil and canola oil, while palmitic acid is found in animal fats and palm oil. Choose monounsaturated fats over saturated fats to reduce the risk of cardiovascular disease.

Caffeine and theobromine

Derived from the cacao plant, theobromine is found in chocolate. It has a bitter taste and, unlike caffeine, theobromine has little stimulant effect on the central nervous system. The reason lies in the structural difference of the molecules.

Caffeine has three methyl groups, and theobromine has two. That third methyl group on the caffeine molecule means it can more readily cross the blood-brain barrier and act on the central nervous system.

MoleculeFeatureDistance[(Entity["caffeine", Entity["Chemical","Caffeine"], "Entity[\"Chemical\", \"Caffeine\"]", "chemical"]),(Entity["theobromine", Entity["Chemical","Theobromine"], "Entity[\"Chemical\", \"Theobromine\"]", "chemical"])]

MoleculePlot/@{(Entity["caffeine", Entity["Chemical","Caffeine"], "Entity[\"Chemical\", \"Caffeine\"]", "chemical"]),(Entity["theobromine", Entity["Chemical","Theobromine"], "Entity[\"Chemical\", \"Theobromine\"]", "chemical"])}

Amino acids clustering tree

Quickly visualize the distances among all 20 amino acids with ClusteringTree:

ClusteringTree[EntityList[(EntityClass["amino acids", EntityClass["Chemical","AminoAcids"], "EntityClass[\"Chemical\", \"AminoAcids\"]", "chemicals"])],DistanceFunction->MoleculeFeatureDistance]

Colors of turmeric, saffron and paprika

What gives the spices turmeric, saffron and paprika their vibrant colors? It’s their molecular structure.

When a molecule has a conjugated system of alternating single and double bonds, it can absorb energy from visible light.

Curcumin primarily absorbs blue light, which causes turmeric to appear yellow. Crocin molecules absorb blue-violet light, resulting in saffron’s orange-red color. Capsanthin absorbs green-blue light, giving paprika a deep red color.

colorfulSpicesAssoc=<|{"turmeric"->(Entity["curcumin", Entity["Chemical","Curcumin"], "Entity[\"Chemical\", \"Curcumin\"]", "chemical"]),"saffron"->(Entity["crocin", Entity["Chemical","Crocin"], "Entity[\"Chemical\", \"Crocin\"]", "chemical"]),"paprika"->(Entity["capsanthin", Entity["Chemical","Capsanthin"], "Entity[\"Chemical\", \"Capsanthin\"]", "chemical"])}|>;
KeyValueMap[{MoleculePlot[#2,{{MoleculePattern["[#6]:[#6]"],MoleculePattern["[#6]-[#6]=[#6,#8]"]}}],#2}&,colorfulSpicesAssoc]//Thread//Grid

Oregano and thyme isomers

We love the smell of oregano in our pasta sauce and the earthy flavor of thyme infusing our baked chicken and glazed carrots.

The monoterpenoid compounds in oregano and thyme—carvacrol and thymol—are phenolic isomers. They have the same molecular formula, but differ in their structural arrangements.

They make a great pair in cooking and chemistry!

Labeled[MoleculePlot3D[#,ImageSize->Small],Column[{#,Molecule[#]["ChemicalFormula"]}]]&/@{(Entity["carvacrol", Entity["Chemical","Carvacrol"], "Entity[\"Chemical\", \"Carvacrol\"]", "chemical"]),(Entity["thymol", Entity["Chemical","Thymol"], "Entity[\"Chemical\", \"Thymol\"]", "chemical"])}//Row

Structure of spicy mustard, wasabi and horseradish

You know that sudden burning sensation in your nose when you eat spicy mustard, wasabi or horseradish?

That sensation is due to the highly volatile and reactive isothiocyanate group (R−N=C=S) in allyl isothiocyanate (AITC). AITC is released when we disrupt the cells of mustard seeds, wasabi and horseradish through chopping, grating or chewing.

The sensation subsides quickly—just in time for your next bite!

MoleculePlot[(Entity["allyl isothiocyanate", Entity["Chemical","AllylIsothiocyanate"], "Entity[\"Chemical\", \"AllylIsothiocyanate\"]", "chemical"])]

MoleculePlot3D[(Entity["allyl isothiocyanate", Entity["Chemical","AllylIsothiocyanate"], "Entity[\"Chemical\", \"AllylIsothiocyanate\"]", "chemical"])]

Food physics

Physics is at the heart of cooking and baking.

Consider the physical transformations that happen in the kitchen, from the melting of butter to the browning of bread.

It’s everyday applications of the principles of physics—shaping ingredients into meals by mastering heat, energy and matter.

Explore the physics of food with Wolfram|Alpha: Examples for Food Science (Food Physics)

Learn more

For more information and examples of computational food and nutrition:

Wolfram Language & System Documentation: Food

Wolfram Language & System Documentation: FoodType

Wolfram Community: Molecular structure comparisons of nutrients and food chemicals

Wolfram Community: Seasoned with science: the chemistry of spices

Wolfram|Alpha: Examples for Food Science (Food Physics)

Wolfram Blog: Creamy or Crunchy: Visualizing Food Protein Structures in Wolfram Language

Wolfram Blog: Thanksgiving Day the Wolfram Way

COMING SOON: Comprehensive, three-part “Computational Food and Nutrition” course from Wolfram U