# Visualizing .xyz file in Mathematica

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. 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[#[]/1000], Line[coord[[#[]]][[All, 1 ;; 2]]]} & /@ sticks,
{Disk[coord[[#[]]][[1 ;; 2]], #[]]} & /@ balls,
Text[Style[atm[[#]], 20, Bold], coord[[#, 1 ;; 2]]] & /@ Range[Length[atm]]}] 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 @@@ GraphicsMoleculePlotDumpInferBonds[elem, coords, 40, 25];


From here, you can use Graph[] for visualization:

Graph[Range[Length[elem]], bonds,
EdgeShapeFunction -> ({{Directive[AbsoluteThickness, Black], Line[#1]},
{Directive[AbsoluteThickness, 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"]: 