互動式查詢化學鍵信息
█ 本文譯自 WolframAlpha 化學組開發人員 Jason.Biggs 在 Wolfram 社區發表的文章:Interactively query bond information
最近在Stack Exchange問答網站上有一個關於如何從 XYZ 文件求二面角的問題,文件中含有分子或分子群的原子類型及三維坐標。二面角是兩個相交平面之間的夾角。在化學中, 我們將四原子的二面角定義為含有前三個原子的平面和含有後三原子的平面之間的夾角。希望這裡我能像你們用其他化學專業軟體一樣互動式地來求二面角。
這是我嘗試開發的一個工具,代碼如下。您可以查詢鍵長、鍵角和二面角。還可以查看三維布洛芬模型中的角。
GIF/2K
或者比較巴克敏斯特富勒烯的五元環和六元環。
GIF/2K
下面是生成上述圖形的代碼。我們使用 EventHandler 和 MousePosition["Graphics3DBoxIntercepts"] 使滑鼠點擊與原子選擇關聯。
interactiveBondTool[chemical_String]:=Module[{plot,coords,atomLabels,bonds},{plot,coords,atomLabels,bonds}=EntityValue[Entity["Chemical",chemical],{"MoleculePlot","AtomPositions","VertexTypes","EdgeRules"}];If[Head/@{plot,coords,atomLabels,bonds}===,interactiveBondTool[{plot,coords,atomLabels,bonds}],Missing["NotAvailable"]]];interactiveBondTool[{plot_,coords_,atomLabels_,bonds_}]:=Module[{dihedralFromVectors,dihedralFromAtomNumbers,bondLength,bondAngle,findAtomNearestToLine,bondInfoBox},dihedralFromVectors[{b1_,b2_,b3_}]:=Module[{n1,n2},(*http://math.stackexchange.com/a/47084/210969*)n1=Normalize@Cross[b1,b2];n2=Normalize@Cross[b2,b3];ArcTan[n1.n2,Cross[n1,Normalize@b2].n2]];dihedralFromAtomNumbers[{a1_,a2_,a3_,a4_}]:=dihedralFromVectors[(Subtract@@coords[[#]])&/@{{a1,a2},{a2,a3},{a3,a4}}];bondLength[{a1_,a2_}]:=EuclideanDistance@@coords[[{a1,a2}]];bondAngle[{a1_,a2_,a3_}]:=VectorAngle@@((Subtract@@coords[[#]])&/@{{a2,a1},{a2,a3}});findAtomNearestToLine[{v1_,v2_},pts_]:=Module[{nearestFunc},(* adapted from this answer: http://mathematica.stackexchange.com/a/28004/9490 *)nearestFunc=Function[{u},Norm/@({#/10,u-v1-#}&@Projection[u-v1,v2-v1])];First@Nearest[(nearestFunc/@pts)->pts,{,}]];findAtomNearestToLine[None,pts_]:=Nothing;bondInfoBox[pts_]:=Grid[{{"atom (atom number)",Grid@Thread[{atomLabels[[pts]],pts,[[;;(Length@pts)]]}]},{"bond length",If[Length@Union@pts>1,(bondLength@pts[[;;2]])/100,""]},{"bond angle",If[Length@Union@pts>2,(bondAngle@pts[[;;3]])/Degree,""]},{"dihedral angle",If[Length@Union@pts>3,(dihedralFromAtomNumbers@pts[[;;4]])/Degree,""]}},Frame->All];DynamicModule[{clicked={},atoms={},spheres={},atomlabels={}},atoms=Dynamic[Flatten[Position[coords,#]&/@clicked]];atomlabels:=With[{pos=atoms},If[pos==={},{},atomLabels[[#]]&/@pos]];spheres=Dynamic[Transpose[{[[;;Length@clicked]],Sphere[#,40]&/@clicked}]];EventHandler[Row[{MouseAppearance[Show[plot,Graphics3D[spheres],ImageSize->500],"Arrow"],Dynamic@bondInfoBox[Setting[atoms]]}],{"MouseClicked":>If[Length@clicked===4,clicked={},AppendTo[clicked,findAtomNearestToLine[MousePosition["Graphics3DBoxIntercepts"],coords]]]},PassEventsDown->True]]];


TAG:WolframMathematica |
※建設銀行龍卡信用卡查詢
※海南建成文物信息管理系統 文物「家底」可隨時查詢
※留學自助查詢寶典!語言學校信息全搜集,不用再求人!
※北京銀行信用卡查詢
※北京銀行信用卡申請辦理進度查詢
※簡單幾步,教你查詢藥品信息、適應症、用法用量及不良反應
※中國銀行信用卡申請辦理進度查詢
※谷歌地圖測試新功能:導航狀態可查詢另一行程
※光大銀行信用卡查詢
※平安銀行信用卡申請進度查詢
※中國互金協會:全國互聯網金融登記披露服務平台向公眾開放項目信息查詢功能
※如何查詢加密貨幣錢包地址的交易信息
※【精選】進銷存管理系統(財務匯總,智能查詢,庫存自動更新)模板
※加入互聯網金融科技委員會 銀行存管可查詢 銀湖網合規再進階
※阿里的程序員們如何解決複雜數據的查詢優化問題?
※國家互聯網應急中心開通勒索病毒免費查詢服務
※光大信用卡賬單查詢
※7小妙方教你供應商信息查詢、資質審查的正確打開方式——華東小招開課啦!
※網商銀行賬號怎麼查詢 詳細操作步驟分享
※國家互金專委會上線網貸查詢APP,提供出借端查驗服務