‹›外部服务比较两个对映体
化学成分具有定性特征,即使是最小的变化也会表现出不同的特性. 应用 Wolfram 语言,您可以访问 PubChem 数据,对这些特征一探究竟.
首先,连接到 PubChem API.
pubchem = ServiceConnect["PubChem"]
我们以维克斯鼻塞吸入剂(Vicks inhaler)和甲基苯丙胺(Metamphetamine)(即冰毒)为例,这是两种为人熟知却又令人诧异地相互关联的物质.
compounds =
pubchem["CompoundProperties", "Name" -> {"Vicks Inhaler", "Meth"},
"Property" -> {"MolecularFormula", "IUPACName"}]
检索并比较其三维结构.
{vicksid, methid} = Normal[compounds[All, "CompoundID"]];
Row[{pubchem["CompoundSDF", "CompoundID" -> vicksid]["Graphics3D", 1],
pubchem["CompoundSDF", "CompoundID" -> methid]["Graphics3D", 1]}]
虽然它们看起来是一样的,但是通过绘制它们的键合结构,我们可以看到其中一个是另一个的镜像,从而证实,他们确实是对映体.
显示完整的 Wolfram 语言输入
{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