3
$\begingroup$

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
.......
$\endgroup$
0
6
$\begingroup$

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"]

Mathematica graphics

And here is what it looks like when imported

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

Mathematica graphics

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]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – thils
    Sep 12 '14 at 2:19
  • $\begingroup$ @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? $\endgroup$
    – RunnyKine
    Sep 12 '14 at 2:25
3
$\begingroup$
pos = ChemicalData["DFructose", "AtomPositions"]/100;
elems = ChemicalData["DFructose", "VertexTypes"];
positions = Transpose[{elems, pos}];
Grid[positions, Frame -> All]

Mathematica graphics

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

Mathematica graphics

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.