Thanks for the suggestion, Daniel! How exactly would that work, though? Here's the situation so far:
Get a molecule:
pos = QuantityMagnitude[ChemicalData["Benzene", "AtomPositions"]]
types = ChemicalData["Benzene", "VertexTypes"]
The output is:
{{-119.07, -1.5997, -75.474}, {-13.956,
84.677, -110.68}, {-105.11, -86.277, 35.210}, {105.11,
86.277, -35.210}, {13.956, -84.677, 110.68}, {119.07, 1.5997,
75.474}, {-209.33, -2.6239, -132.92}, {-24.311,
149.49, -195.19}, {-184.85, -152.21, 62.495}, {184.85,
152.21, -62.495}, {24.311, -149.49, 195.19}, {209.33, 2.6239,
132.92}}
{"C", "C", "C", "C", "C", "C", "H", "H", "H", "H", "H", "H"}
Here's the original problem:
ExportString[{types,pos}, {"XYZ", {"VertexTypes", "VertexCoordinates"}}]
Output:
"12
Created with the Wolfram Language : www.wolfram.com
C -1.19070 -1.59970E-2 -7.54740E-1
C -1.39560E-1 8.46770E-1 -1.10680
C -1.05110 -8.62770E-1 3.52100E-1
C 1.05110 8.62770E-1 -3.52100E-1
C 1.39560E-1 -8.46770E-1 1.10680
C 1.19070 1.59970E-2 7.54740E-1
H -2.09330 -2.62390E-2 -1.32920
H -2.43110E-1 1.49490 -1.95190
H -1.84850 -1.52210 6.24950E-1
H 1.84850 1.52210 -6.24950E-1
H 2.43110E-1 -1.49490 1.95190
H 2.09330 2.62390E-2 1.32920"
Using InputForm
like this:
ExportString[{types,InputForm[pos]}, {"XYZ", {"VertexTypes", "VertexCoordinates"}}]
... results in this error:
Export::uneqlen: Elements VertexCoordinates and VertexTypes must have the same length. >>
$Failed
Applying InputForm
to each number separately like this:
ExportString[{types,Map[InputForm, pos, {2}]}, {"XYZ", {"VertexTypes","VertexCoordinates"}}]
... results in the following error:
Export::errelem: The Export element VertexCoordinates contains a malformed data structure and could not be exported to XYZ format. >>
$Failed
This behaviour makes sense to me since InputForm
and other functions like it are just display functions that don't actually return their input in an altered form, or as a formatted string or anything like that. (Speaking of strings, ToString
doesn't help either, Export
still considers that a malformed data structure because "VertexCoordinates"
are supposed to be numbers.)
All in all, I still basically vote for writing a new customized export based on generic table format, but I'm also still curious about the atom type problem.
Anyway, here's a suggestion for the export that eliminates the exponential notation:
Export["benzene.xyz",
Join[
{{Length[types]}, StringSplit["This is a benzene molecule!"]},
Join[{types[[#]]}, pos[[#]]/100] & /@ Range[Length[types]]
],
"Table", "FieldSeparators" -> " "]