Function Repository Resource:

MoleculeValuePlot

Source Notebook

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

Contributed by: Jason Biggs

ResourceFunction["MoleculeValuePlot"][mol,property]

returns a molecule plot highlighted with colors corrsponding to property.

Details and Options

The property should be one of the values returned by MoleculeValue["Properties"][[{"AtomProperties","BondProperties"}]] or EntityProperties["Element"].
ResourceFunction["MoleculeValuePlot"] 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["MoleculeValuePlot"][
 Molecule["caffeine"], "GasteigerPartialCharge"]
Out[1]=

Exclude hydrogen atoms from the plot:

In[2]:=
ResourceFunction["MoleculeValuePlot"][
 Molecule["caffeine"], "GasteigerPartialCharge", IncludeHydrogens -> False]
Out[2]=

Color atoms according to their hybridization:

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

Color bonds according to their bond type:

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

Scope (2) 

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

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

Label atoms by their phase at standard temperature and pressure:

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

Options (7) 

ColorFunction (2) 

Specify an alternate color function for numeric data:

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

Specify an alternate color function for discrete data:

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

ExclusionFunction (2) 

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

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

Use MissingQ to exclude missing values:

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

IncludeHydrogens (1) 

Disable plotting explicit hydrogen atoms:

In[12]:=
ResourceFunction["MoleculeValuePlot"][
 Molecule["biphenyl"], "TopologicalStericEffectIndex", IncludeHydrogens -> False]
Out[12]=

LegendFunction (1) 

Pass options directly to the legend:

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

PlotLegends (1) 

Disable the plot legends using the PlotLegends option:

In[14]:=
ResourceFunction["MoleculeValuePlot"][
 Molecule["caffeine"], "CoordinationNumber", PlotLegends -> None]
Out[14]=

Neat Examples (1) 

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

In[15]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/e73afe57-bed9-4ac4-bbda-4b5e139db19b"]
Out[15]=

Publisher

JasonB

Version History

  • 3.0.1 – 20 May 2022
  • 3.0.0 – 07 March 2022
  • 2.0.1 – 09 November 2021

Related Resources

License Information