Wolfram Language

External Services

Compare Two Enantiomers

Chemical components have defining features; even the smallest change will demonstrate different properties. With the Wolfram Language, you can access PubChem data and explore these features.

First, connect to the PubChem API.

In[1]:=
Click for copyable input
pubchem = ServiceConnect["PubChem"]
Out[1]=

Compare Vicks inhaler and methamphetamine, two substances that are commonly known and surprisingly related.

In[2]:=
Click for copyable input
compounds = pubchem["CompoundProperties", "Name" -> {"Vicks Inhaler", "Meth"}, "Property" -> {"MolecularFormula", "IUPACName"}]
Out[2]=

Retrieve and compare their 3D structure.

In[3]:=
Click for copyable input
{vicksid, methid} = Normal[compounds[All, "CompoundID"]]; Row[{pubchem["CompoundSDF", "CompoundID" -> vicksid]["Graphics3D", 1], pubchem["CompoundSDF", "CompoundID" -> methid]["Graphics3D", 1]}]
Out[3]=

Although they look the same, you can corroborate that they are indeed enantiomers by plotting their bonding structure and see that one is the mirror image of the other.

show complete Wolfram Language input
In[4]:=
Click for copyable input
{edgerule1, edgetype1, vertextype1} = Flatten[Values[ Normal[pubchem["CompoundSDF", "CompoundID" -> vicksid][{"EdgeRules", "EdgeTypes", "VertexTypes"}]]], 1]; vertexcoord1 = Thread[Rule[Range[1, Length[#]], #]] &@ Flatten[Normal[ pubchem["CompoundSDF", "CompoundID" -> vicksid][ "VertexCoordinates"]], 1]; {edgerule2, edgetype2, vertextype2} = Flatten[Values[ Normal[pubchem["CompoundSDF", "CompoundID" -> methid][{"EdgeRules", "EdgeTypes", "VertexTypes"}]]], 1]; vertexcoord2 = Thread[Rule[Range[1, Length[#]], #]] &@ Flatten[Normal[ pubchem["CompoundSDF", "CompoundID" -> methid][ "VertexCoordinates"]], 1]; normal[{x_, y_}] := 2.5*{-y, x}/Norm[{x, y}]; (Block[{name = #name, edgerule = #edgerules, vertextype = #vertextype, vertexcoord = #vertexcoord, edgetype = #edgetype}, name -> GraphPlot[edgerule, VertexRenderingFunction -> (Text[ Style[vertextype[[#2]], Bold], #1, Background -> White] &), VertexCoordinateRules -> vertexcoord, EdgeRenderingFunction -> (Switch[ Extract[edgetype, Position[ edgerule, (Rule @@ #) &@#2]], {"Single"}, {Purple, Line[#1]}, {"Double"}, norm = normal[First[#1] - Last[#1]]; {Orange, Thickness[0.005], Line[{First[#1] + norm, Last[#1] + norm}], Line[{First[#1] - norm, Last[#1] - norm}]}] &), ImageSize -> 200]] & /@ {<|"name" -> "Vicks Inhaler", "edgerules" -> edgerule1, "edgetype" -> edgetype1, "vertextype" -> vertextype1, "vertexcoord" -> vertexcoord1|>, <| "name" -> "Methamphetamine", "edgerules" -> edgerule2, "edgetype" -> edgetype2, "vertextype" -> vertextype2, "vertexcoord" -> vertexcoord2|>}) // Dataset
Out[4]=

Related Examples

de es fr ja ko pt-br ru zh