Function Repository Resource:

MoleculeValuePlot3D

Source Notebook

Get a 3D molecule plot with atoms or bonds colored according to property values

Contributed by: Jason Biggs

ResourceFunction["MoleculeValuePlot3D"][mol,property]

returns a 3D molecule plot highlighted with colors corresponding to property.

Details and Options

property should be one of the values returned by MoleculeValue["Properties"][[{"AtomProperties","BondProperties"}]] or EntityProperties["Element"].
ResourceFunction["MoleculeValuePlot3D"] takes the same options as MoleculePlot, BarLegend and SwatchLegend with the following additions:
ColorFunctionAutomatichow to determine the coloring of atoms and bonds
ColorFunctionScalingTruewhether to scale numeric arguments to ColorFunction
"ExclusionFunction"(False &)function to determine which property values to exclude from the resulting plot
For numeric property values, the default color function is "StarryNightColors" and for discrete values ColorData[97] is used.

Examples

Basic Examples (3) 

Color each atom according to its partial charge:

In[1]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule["caffeine"], "GasteigerPartialCharge"]
Out[1]=

Color atoms according to their hybridization:

In[2]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule["hexa-3,4-dien-1-yne"], "OrbitalHybridization"]
Out[2]=

Color bonds according to their bond type:

In[3]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule["O=C/C=C/c1ccc(cc1)N(=O)=O"], "BondType"]
Out[3]=

Scope (2) 

The atom and bond properties can be accessed via MoleculeValue and EntityProperties:

In[4]:=
MoleculeValue["Properties"][[{"AtomProperties", "BondProperties"}]]
Out[4]=
In[5]:=
EntityProperties["Element"] // Shallow
Out[5]=

Label atoms by their phase at standard temperature and pressure:

In[6]:=
m = Molecule[
   "(5Z)-5-[(3-bromophenyl)methylidene]imidazolidine-2,4-dione"];
ResourceFunction["MoleculeValuePlot3D"][m, EntityProperty["Element", "Phase"]]
Out[7]=

Options (4) 

Disable the plot legends using the PlotLegends option:

In[8]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule[Entity["Chemical", "2Thiopheneethylamine"]], "CoordinationNumber", PlotLegends -> None]
Out[8]=

Specify an alternate color function for numeric data:

In[9]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule["O=C(CNC(=O)[C@@H](Cc1ccccc1)CSC(=O)C)OCc1ccccc1"], EntityProperty["Element", "Electronegativity"], ColorFunction -> "Rainbow"]
Out[9]=

Specify an alternate color function for discrete data:

In[10]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule["O=C(CNC(=O)[C@@H](Cc1ccccc1)CSC(=O)C)OCc1ccccc1"], EntityProperty["Element", "TermSymbol"], ColorFunction -> 98]
Out[10]=

Pass options directly to the legend:

In[11]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule["O=C(CNC(=O)[C@@H](Cc1ccccc1)CSC(=O)C)OCc1ccccc1"], EntityProperty["Element", "DiscoveryYear"], LegendLabel -> None, LegendFunction -> "Frame"]
Out[11]=

When some values are missing, the data is treated as discrete rather than numeric:

In[12]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule["Oc1ccc(cc1)O[P@](=O)(Oc1ccc(cc1)[C@H]1OC(=O)c2c1cccc2)O"], EntityProperty["Element", "SoundSpeed"]]
Out[12]=

Use MissingQ to exclude missing values:

In[13]:=
ResourceFunction["MoleculeValuePlot3D"][
 Molecule["Oc1ccc(cc1)O[P@](=O)(Oc1ccc(cc1)[C@H]1OC(=O)c2c1cccc2)O"], EntityProperty["Element", "SoundSpeed"], "ExclusionFunction" -> MissingQ]
Out[13]=

Neat Examples (1) 

Label atoms by their chirality, using the "ExclusionFunction" option to make sure achiral atoms are not labeled:

In[14]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/28329293-0be8-4d0b-bcad-a42a4ffe900f"]
Out[14]=

Publisher

JasonB

Version History

  • 1.1.1 – 20 May 2022
  • 1.1.0 – 07 March 2022
  • 1.0.1 – 09 November 2021
  • 1.0.0 – 05 August 2020

Related Resources

License Information