If i import a .xyz file in Mathematica that will show me the moelcule in the default way. But i want to visualise the .xyz file in the following manner.
$\begingroup$
$\endgroup$
3
-
$\begingroup$ Do you have the .xyz file? $\endgroup$– SumitCommented Nov 21, 2017 at 12:36
-
$\begingroup$ dropbox.com/s/q3rwpedngv5wbqi/ben.xyz?dl=012 $\endgroup$– sravankumar perumallaCommented Nov 21, 2017 at 12:49
-
1$\begingroup$ (Editorializing here) Unless you were a speaker here, I'm wondering what the motivation for this type of presentation is. $\endgroup$– bobthechemistCommented Nov 21, 2017 at 13:59
Add a comment
|
2 Answers
$\begingroup$
$\endgroup$
Sticks and balls
file = "ben.xyz";
atm = Import[file, "VertexTypes"];
xyz = Import[file];
coord = xyz[[1, 4, 1]];
balls = Cases[xyz[[1, 4, 2]], Sphere[x_, y_] -> {x, y}];
sticks= Cases[xyz[[1, 4, 2]], Cylinder[x_, y_] -> {x, y}];
Graphics[{EdgeForm[Black], FaceForm[White],
{Thickness[#[[2]]/1000], Line[coord[[#[[1]]]][[All, 1 ;; 2]]]} & /@ sticks,
{Disk[coord[[#[[1]]]][[1 ;; 2]], #[[2]]]} & /@ balls,
Text[Style[atm[[#]], 20, Bold], coord[[#, 1 ;; 2]]] & /@ Range[Length[atm]]}]
$\begingroup$
$\endgroup$
Here's a starting point, whose finessing/generalization I will leave to somebody else. First, import the elements and coordinates separately:
elem = Import["https://pastebin.com/raw/QqrhhvMj", {"XYZ", "VertexTypes"}];
coords = Import["https://pastebin.com/raw/QqrhhvMj", {"XYZ", "VertexCoordinates"}];
Use an undocumented internal function to get bonding information:
bonds = UndirectedEdge @@@ Graphics`MoleculePlotDump`InferBonds[elem, coords, 40, 25];
From here, you can use Graph[]
for visualization:
Graph[Range[Length[elem]], bonds,
EdgeShapeFunction -> ({{Directive[AbsoluteThickness[4], Black], Line[#1]},
{Directive[AbsoluteThickness[2], White], Line[#1]}} &),
GraphLayout -> "SpringEmbedding",
VertexLabels -> MapIndexed[First[#2] -> Placed[#1, Center] &, elem],
VertexSize -> 0.5, VertexStyle -> GrayLevel[9/10]]
Here is the corresponding diagram for Import["ExampleData/caffeine.xyz"]
: