Despite the fact that Mathematica (V13.2) is able to import an SD file with corresponding metadata for each structure, e.g.

Import["ExampleData/alkanes.sdf", {{"Molecule", "Metadata"}}]

I was not successful when exporting a set of Molecules[] together with some data. Attempts like this one

Export["test.sdf", {Molecule["methane"], Molecule["propane"]}, "SDF", "MetaData" -> {<|"name" -> "Methan"|>, <|"name" -> "Propan"|>}]

seem to work, but the the resulting file (or string) doesn't include any metadata. I've tried several variants, such as

ExportString[{{Molecule["methane"], Molecule["propane"]}, "MetaData" -> {<|"name" -> "Methan"|>, <|"name" -> "Propan"|>}}, "SDF"]
(* $Failed *)


ExportString[{{Molecule["methane"], Molecule["propane"]}, {<|"name" -> "Methan"|>, <|"name" -> "Propan"|>}}, "SDF"]
(* $Failed *)

Unfortunately, the documentation is silent on this point.

Any comments?

  • $\begingroup$ In exporting jpg and other file formats I encountered the same problem. t first I simply used exiftool to add metadata. Trying Mathematica it was not possible to add metadata, perhaps because some entries are not editable. Then I found out, that the import with metadata allows to edit the metadata and to export them. Its all very nebulous around Export filters. $\endgroup$
    – Roland F
    May 27, 2023 at 12:05

1 Answer 1


When exporting multiple elements for a file, you want to include them all together in the first argument and not place some of them at the end like options. That's why your first Export doesn't work.

Something like this does the trick

ExportString[{mols, meta}, {"SDF", {"Molecule", "Metadata"}}]

You could also specify the export elements using a list of rules:

mols = {Molecule["methane"], Molecule["propane"]};
meta = {<|"name" -> "Methan"|>, <|"name" -> "Propan"|>};

ExportString[{"Molecule" -> mols, "Metadata" -> meta}, {"SDF", "Rules"}]

Or put the information inside the molecules:

   MetaInformation -> <|"name" -> "Methan"|>], 
   MetaInformation -> <|"name" -> "Propan"|>]}, "SDF"]
  • $\begingroup$ Marvelous! Thank you very much Jason! $\endgroup$ May 27, 2023 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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