XYZ (.xyz)

Background & Context

    • MIME type: chemical/x-xyz
    • XMOL molecule model files.
    • Used in cheminformatics applications and on the web for storing and exchanging 3D molecule models.
    • Plain text tabular format.
    • Represents a single chemical compound.
    • Stores atomic coordinates and meta-information.
    • Does not store chemical bond information.
    • Developed in 1990 at the Minnesota Supercomputer Center.

Import & Export

  • Import[""] imports a molecule from an XYZ file.
  • Export["",expr] exports elements of a molecule model to an XYZ file.
  • Import[""] returns a Molecule object.
  • Import["",elem] imports the specified element from an XYZ file.
  • Import["",{elem,suba,subb,}] imports a subelement.
  • Import["",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file","XYZ"] or Import["file",{"XYZ",elem,}].
  • Export["",mol] creates an XYZ file by treating mol as a Molecule.
  • Export["",expr,elem] creates an XYZ file by treating expr as specifying element elem.
  • Export["",{expr1,expr2,},{{elem1,elem2,}}] treats each expri as specifying the corresponding elemi.
  • Export["",expr,opt1->val1, ] exports expr with the specified option elements taken to have the specified values.
  • Export["",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
    "Graphics3D"XYZ file rendered as a Graphics3D object
  • Import uses the "Molecule" element by default for the XYZ format.
  • Data representation elements:
  • "Molecule"a symbolic representation of the molecule model
    "VertexCoordinates"atomic coordinates, typically given in angstroms
    "VertexTypes"all atoms or groups constituting the molecule, typically given as a list of chemical element abbreviations
  • Export["",{vert,coord},{{"VertexTypes","VertexCoordinates"}}] creates an XYZ model from a specification of atom types and their 3D coordinates.


  • General Import options:
  • ImageSizeAutomaticspecifies the overall size of the graphics to display
    BackgroundWhitespecifies what background color to use
    ViewPointAutomaticpoint in space from which the 3D model is to be viewed
  • With the default setting "ViewPoint"Automatic, the Wolfram Language automatically calculates the optimal viewing angle for the imported molecule model.
  • An XYZ file contains no information regarding bonds between atoms. Bonds are determined by the interatomic distance, and an attempt is made to assign bond types. To disable this, use "InferBondTypes"False.
  • Selecting a 3D rendering style:
  • "Rendering""BallAndStick"specifies the visualization method
  • Possible settings for "Rendering" are:
  • "BallAndStick"displays atoms and bonds as a ball-and-stick model
    "Spacefilling"atoms shown as overlapping spheres
    "Wireframe"bonds rendered as lines


open allclose all

Basic Examples  (3)

Import an XYZ example file, rendering it as a ball-and-stick model:

Plot the molecule in 3D:

Create a molecule and export it to an XYZ file:

Import the file back in and plot in 3D:

Import a molecule as space-filling atoms:

Import Options  (1)

"InferBondTypes"  (1)

Use "InferBondTypes" to disable automatic bond-type detection:

Possible Issues  (1)

Atomic charges are not stored in an XYZ file:

Re-importing the file results in a different molecule without charge:

Ensure the molecule can be re-imported using a file format that includes charge and bond information, such as "MOL":