‹›External ServicesCompare 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.
pubchem = ServiceConnect["PubChem"]
Compare Vicks inhaler and methamphetamine, two substances that are commonly known and surprisingly related.
compounds =
pubchem["CompoundProperties", "Name" -> {"Vicks Inhaler", "Meth"},
"Property" -> {"MolecularFormula", "IUPACName"}]
Retrieve and compare their 3D structure.
{vicksid, methid} = Normal[compounds[All, "CompoundID"]];
Row[{pubchem["CompoundSDF", "CompoundID" -> vicksid]["Graphics3D", 1],
pubchem["CompoundSDF", "CompoundID" -> methid]["Graphics3D", 1]}]
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
{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