# Retrieving coordinate positions using ChemicalData for input to quanutm modelling software

I am trying to set up an input file for a quantum chemical modelling software. How do I obtain the (XYZ) coordinate positions in Angstroms using information obtained using ChemicalData. Have some initial input for fructose below:

ChemicalData["Fructose", "AtomPositions"]


What I expect in the output (just an example not the actual positions)

                 Coordinates (Angstroms)
ATOM                X               Y               Z
1  C        2.5130891440   -0.0345557109   -0.2500995821
2  O         0.0459435630    3.3652982874    1.6477735205
3  H        0.0347565292    2.5110247340    0.2498797086
.......


Let's first pre-process the data you need for the output file to be used in your quantum simulation software:

pos = ChemicalData["Fructose", "AtomPositions"][[1]]/100.;
atype = ChemicalData["Fructose", "VertexTypes"][[1]];
data = Transpose[{atype, pos}];


Here's a function to give you the output file the way you specified in your question:

writeXYZ[file_String, data_] :=
Module[{str = OpenWrite[file, FormatType -> OutputForm], len = Length @ data},
Scan[WriteLine[str, #] &, {ToString @ len, " Coordinates (Angstroms)"}];
Scan[Write[str, " ", data[[#, 1]], PaddedForm[data[[#, 2, 1]], {14, 6}],
PaddedForm[data[[#, 2, 2]], {10, 6}],
PaddedForm[data[[#, 2, 3]], {10, 6}]] &, Range @ len];
Close[str]
]


Now, let's use it:

writeXYZ["test.xyz", data]


We can view the file to see what it looks like:

FilePrint["test.xyz"]


And here is what it looks like when imported

Import["test.xyz", "XYZ"]


Plot with Mathematica

radii = QuantityMagnitude @ Map[ElementData[#, "VanDerWaalsRadius"] &, atype] / 100.;
color = Map[ColorData["Atoms", #] &, atype];


Then:

Graphics3D[{Specularity[White, 40], MapThread[{#1, Sphere[#2, #3 / 1.2]} &, {color, pos, radii}]},
Boxed -> False]


• The VMD viewer is OK, but is it possible to use the higher resolution Graphics capability of Ver 10, and have a nicer output. This will allow further processing such as attachment of a fructose to a sucrose and other related manipulations. Sep 12 '14 at 2:19
• @thils, Yes it should be possible. I answered exactly your question since I thought you just wanted to use the .xyz file in a quantum simulation program. Do you want to plot it with the bonds included? Sep 12 '14 at 2:25
pos = ChemicalData["DFructose", "AtomPositions"]/100;
elems = ChemicalData["DFructose", "VertexTypes"];
positions = Transpose[{elems, pos}];
Grid[positions, Frame -> All]


Graphics3D[{ColorData["Atoms", #[[1]]], Sphere[#[[2]], .2]} & /@
positions, Axes -> True, Lighting -> "Neutral"]


• The ans. is appropriate but what is "nums"...I can't generate the same output because this info. is missing. Sep 11 '14 at 23:35
• @thils Sorry, it was an old name for lens. Typo corrected. Thanks! Sep 12 '14 at 0:49
• Graphics3D does not work in Ver 10 Sep 12 '14 at 0:54
• Sep 12 '14 at 0:57
• It looks like you've got the positions of the atoms mixed up. This looks nothing like D-Fructose. Sep 12 '14 at 2:12