# XYZ file format: what it stores, how to open it and how to convert it

> An XYZ file lists an atom count, a comment line and one line per atom with its element and x, y and z coordinates in ångström. Nothing else: no bonds, charges, residues or chains. See how viewers and converters rebuild the rest, what is lost going from PDB to XYZ and back, and how to open and convert XYZ files.

## What is an XYZ file?

An XYZ file (`.xyz`) is a plain-text list of atoms and their positions. The first line gives the number of atoms, the second is a free comment, and each line after that holds an element symbol and x, y and z coordinates in ångström. There is no formal specification, so programs read it loosely, but the layout above is what every one of them expects. It is the usual input and output of quantum chemistry programs, semi-empirical methods and machine-learned potentials, because their calculations need nothing more than atoms and positions, plus a charge and multiplicity given separately.

The catch is what the file leaves out: bonds, bond orders, formal charge, residues, chains and everything else that makes a list of atoms into a molecule. The [PDB viewer by ProteinIQ](/app/pdb-viewer) shows what that costs. Crambin from [PDB entry 1CRN](/app/pdb-viewer#session=7Vhbc-I6Ev4vejYcyVdM1XnIPUwyCZOEySRTKUqWBSjIkiPJEDLFf9-SDASTw5mc3Zet2n0CtaRWd6v7-1r-BVgOumCR3xy2joLn5x5vTZ_h9c33bHY1Bx7IscGg-wsYRWn9i4UeSVVo0P35C5RYUWFAF7T-VFKaP1vAe19CFeiCrGI8bzHRtvPAszuw3fxr6QFFR82tM6o0kwJ0QfDleTyN5vPsbf4yS8sDfRidxmOw9D5zZqFbJa_GTLRzORdc4nz7YFApDrpgYkypu3_8Ucicct1WRGdtqcZ_IKJEOyNsBDzAcUbtWnR0cwU8wPQhE1gtQNeoim4cIPf0kpzmD-fMnE2qwf1ioWF80HCnOh8y1J899nrTk45_sni5VZOrb0139qrZ51yJlaat2tLtsGqDjbssps8mUpsdc6cyF9mNTofTi1tC1eMdFAMybpj7I6WLkqiT4d3j_SFMiq8_BhLtRH-vmn3mGoWfKTFSLVojJYtWUXw0vbZw8Brq4Ut-dzOYnpk0CU-Db_q-aeFpC7ZQUPQui5v-wSGUx_K0JPOmhXvV7LPQpUJt3LuxjdRxK3oip6-gCzf2cm7048X12xQffb_owdbtl_PLwbeG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7u6aHyweeq-8N3xZLKqLsgOzaX7dSq4PwLJGZFxQ5V77pFJ10dZfx2wMqXJUY9PeAyM5s84lnSiwWBcEaRKGncB7D3X3J4JtP4nDCMI0CZMYxqmXtuM0StIgQVGcBBEMvChux2GI_E6EOlHkx9GTB6rSVQlyVWLs-8R8Vl3cTjrIYrrvo8AP0vipptPKJlJiJ5M49mEQpBFM4vVc_VK3e8MkCH0Yp36QBrF1cwy6KKqR4RRvSLJg4orimoULJtyMzUxXQM7_W7NwlF_jgalvb9Wxn0pSrT6N5pVyKdsTX62FEYTLfwE) opens as one chain of 46 residues; the same 327 atoms written as XYZ open as `C202N55O64S6 · 327 atoms`, with no chain, no residue and no cartoon. Acetate goes in as an anion and comes back out of the same viewer, saved as SDF, as neutral acetic acid.

So reading an XYZ file always means rebuilding the rest. A program decides which atoms are bonded from their distances, then infers bond orders from valence rules, and that second step needs a total charge the file never states. How well a conversion goes depends on which of those guesses it makes and whether you give it the missing facts.

## Anatomy of an XYZ file

Here is caffeine, PubChem CID 2519, written as XYZ from PubChem's 3D record by RDKit. The comment line holds the CID, because that was the molecule's name in the source file:
```text
24
2519
O      0.470000    2.568800    0.000600
O     -3.127100   -0.443600   -0.000300
N     -0.968600   -1.312500    0.000000
N      2.218200    0.141200   -0.000300
N     -1.347700    1.079700   -0.000100
N      1.411900   -1.937200    0.000200
C      0.857900    0.259200   -0.000800
C      0.389700   -1.026400   -0.000400
C      0.030700    1.422000   -0.000600
C     -1.906100   -0.249500   -0.000400
C      2.503200   -1.199800    0.000300
C     -1.427600   -2.696000    0.000800
C      3.192600    1.206100    0.000300
C     -2.296900    2.188100    0.000700
H      3.516300   -1.578700    0.000800
H     -1.045100   -3.197300   -0.893700
H     -2.518600   -2.759600    0.001100
H     -1.044700   -3.196300    0.895700
H      4.199200    0.780100    0.000200
H      3.046800    1.809200   -0.899200
H      3.046600    1.808300    0.900400
H     -1.808700    3.165100   -0.000300
H     -2.932200    2.102700    0.888100
H     -2.934600    2.102100   -0.884900
```
Line 1 is the atom count, 24. Line 2 is free text: a title, a file name, an energy or nothing at all, but it cannot be skipped, so an empty comment is still an empty line. Each of the next 24 lines is an element followed by three coordinates separated by whitespace.

Because the columns are separated by whitespace rather than fixed widths, the number of decimals is up to the writer. RDKit wrote six; Open Babel writes coordinates in a `10.5` format, five decimals. Some programs put an atomic number in place of the element symbol, and Open Babel accepts that: its reader falls back to reading the first column as a number when it is not a symbol. Coordinates are Cartesian and in ångström; there is no field for units, so a file written in bohr by mistake looks the same and simply describes a molecule 1.89 times too large.

Compare the caffeine record with the [SDF file](/guides/sdf-file) it came from. The SDF has the same 24 coordinates plus 25 bond lines and 33 data fields. The XYZ kept the coordinates and the order of the atoms. That order matters later: it is the only thing that ties an atom in an XYZ file to the same atom anywhere else.

## Extended XYZ adds a cell and properties

Simulations of crystals, surfaces and liquids need a unit cell, and machine-learned potentials need energies and forces stored next to each structure. Extended XYZ, specified by the libAtoms project, fits both into the comment line without changing the rest of the layout. Line 2 becomes a set of `key=value` pairs:
```text
24
Lattice="20.0 0.0 0.0 0.0 20.0 0.0 0.0 0.0 20.0" Properties=species:S:1:pos:R:3 pbc="T T T"
O      0.470000    2.568800    0.000600
...
```
`Lattice` holds the three cell vectors as a 3 × 3 matrix and `pbc` says along which of them the system is periodic. `Properties` describes the atom columns as triplets of name, type and count: `species:S:1` is one string column for the element and `pos:R:3` three real columns for the position. A file with forces adds `forces:R:3`, and any other key, such as an energy, can be added to line 2.

A reader that knows nothing about extended XYZ sees an ordinary comment and still gets the atoms right, which is the point of the design. The PDB viewer by ProteinIQ opened our test file with the comment line above and drew all 24 atoms; nothing in the viewer shows the cell, so treat it as a viewer for the coordinates only. The machine-learned potentials [AIMNet2](/app/aimnet2) and [ORB v3](/app/orb-v3) on ProteinIQ read plain and extended XYZ. ORB v3 writes its optimized structures and trajectories as `.extxyz`, and AIMNet2 writes its optimization trajectory the same way.

## Multi-frame XYZ files

An XYZ file can hold several structures one after another, each with its own count and comment line. Computational chemistry programs use this for anything that produces a series of geometries. The semi-empirical program xtb writes its optimized structure to `xtbopt.xyz` and the whole optimization path to `xtbopt.log`, a multi-frame XYZ. ORCA writes the final geometry of an optimization to `basename.xyz` and the path to `basename_trj.xyz`. The conformer search program CREST writes its final ensemble to `crest_conformers.xyz`, one conformer per frame.

The PDB viewer by ProteinIQ opens such a file as a trajectory. We wrote caffeine three times, shifting it 0.5 Å along x in each frame, and the viewer loaded one structure with a player under the canvas reading `1 / 3` (Figure 4). The player has play, step and loop controls, so an optimization log or a conformer ensemble can be watched from first frame to last.

## What an XYZ file leaves out

Everything the [richer structure formats](/guides/chemical-file-formats) say about chemistry beyond the element and position is gone:

- Bonds and bond orders. There is no connection table, so a single and a double bond look the same, and so does a bond and two atoms that happen to sit close together.
- Charge and spin. The file does not say whether the molecule is neutral, an anion or a radical.
- Biological identity. There are no residue names or numbers, chains, alternate locations, occupancies or B-factors, so a protein is just a list of atoms.

Programs that read XYZ fill the first gap themselves. Open Babel connects atoms whose distance fits their covalent radii, then perceives bond orders, unless told not to: the read option `-as` keeps every bond single and `-ab` turns bonding off. RDKit splits the same job into `DetermineConnectivity`, which assigns bonds from distances, and `DetermineBondOrders`, a port of Jan Jensen's group's xyz2mol. The method behind it comes from Kim and Kim, who chose bond orders from valence rules alone, without fitted parameters, and reported near-complete success in rebuilding 10,000 PubChem molecules.

The second gap is filled by asking. RDKit's bond-order step needs the molecule's total charge, which defaults to 0. Quantum chemistry programs take charge and multiplicity on a separate line: ORCA reads coordinates with `* xyzfile 0 1 caffeine.xyz`, where 0 is the charge and 1 the multiplicity. AIMNet2 on ProteinIQ has `Charge` and `Multiplicity` settings for the same reason. The third gap cannot be filled from the file at all.

## One protein and two molecules through XYZ

To see what survives, we took three structures through XYZ and back: crambin from PDB entry 1CRN, a 46-residue protein of 327 atoms with no hydrogens, and the PubChem 3D records of caffeine and acetate. Each was written as XYZ with RDKit 2025.03.5, opened in the PDB viewer by ProteinIQ, exported from the viewer with `Export` > `Structure`, and rebuilt with RDKit's `rdDetermineBonds` for comparison. Table 1 has the results.

  <caption><strong>Table 1. Three structures taken through XYZ.</strong> Our test on 2026-11-16. Viewer columns describe the PDB viewer by ProteinIQ; RDKit is version 2025.03.5. Bond-order checks compare canonical SMILES and InChIKeys with the source records.</caption>
  <thead>
    <tr>
      <th scope="col">Structure</th>
      <th scope="col">Viewer canvas</th>
      <th scope="col">Viewer export</th>
      <th scope="col">RDKit rebuild</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Crambin, 1CRN</td>
      <td>327 atoms in ball and stick, no chain, residues or cartoon</td>
      <td>PDB: 327 `ATOM` lines, every one in residue `MOL`, chain A, number 1, no `CONECT` records</td>
      <td>337 bonds, as many as RDKit reads from the PDB file; written as PDB, one residue `UNL 1` with no chain</td>
    </tr>
    <tr>
      <td>Caffeine, CID 2519</td>
      <td>Rings drawn aromatic, both C=O drawn as single bonds</td>
      <td>SDF: both C=O double; same InChIKey as PubChem's record</td>
      <td>Same SMILES as the source with charge 0</td>
    </tr>
    <tr>
      <td>Acetate, CID 175</td>
      <td>Not checked</td>
      <td>SDF: neutral acetic acid, `CC(=O)O`</td>
      <td>Fails with charge 0; correct acetate with charge −1</td>
    </tr>
  </tbody>

Crambin shows the limit no algorithm can cross. The viewer drew bonds from the distances between atoms, disulfide bonds included, and drew the aromatic side-chain rings, but with no residues it could not draw a cartoon (Figure 1). Opened from the database, the same protein is a cartoon with one chain of 46 residues (Figure 2). The exported PDB file keeps the coordinates and loses the rest (Table 1), and programs that need residue names, such as the preparation of a [PDBQT file](/guides/pdbqt-file) for docking or a validation tool, cannot use it.

![The PDB viewer by ProteinIQ showing crambin opened from an XYZ file: 327 atoms in ball and stick with no cartoon, and a details panel that lists only the file name, formula and atom count.](/images/guides/xyz-file/crambin-xyz-in-pdb-viewer.webp "**Figure 1. Crambin opened from an XYZ file.** The details panel lists `1crn.xyz`, `C202N55O64S6 · 327 atoms` and nothing about chains or residues. Bonds are drawn from distances, including the yellow disulfide bonds, but without residues there is no cartoon.")

![The PDB viewer by ProteinIQ showing PDB entry 1CRN as a green cartoon with helices and a beta sheet, and a details panel listing chain A, crambin, 46 residues.](/images/guides/xyz-file/crambin-1crn-pdb-viewer.webp "**Figure 2. The same protein opened as PDB entry 1CRN.** The PDB file carries residue names and a chain, so the viewer draws the cartoon and lists chain A, crambin, with 46 residues.")

Caffeine shows a display and a file disagreeing. On the canvas, the XYZ copy has both carbonyl groups drawn as single bonds, while the SDF copy beside it shows them double (Figure 3). Yet the SDF the viewer exported from the XYZ copy has every bond order right, with the same InChIKey as PubChem's record, because the exporter perceives bond orders when it writes a molfile. Judge a conversion by the file it writes, not by the sticks on screen. [Caffeine opened from PubChem](/app/pdb-viewer#session=nVhrU9s6E_4v-uwEKb5npnMmTYFSboVAKe0wGVlWYhVZciU5IXTy39-RnJgYmtOely9YK-1qr8-u8guwHAzB7eWXm4vE3FYJ-5SLL-9n4YjzEfBAjg0Gw1_AKEqb_1jomVSlBsPvv0CFFRUGDEHvnZLSvOsB7-UIVWAIsprxvMdE3-4Dz3Jgy_xr7QFFZ13WBVWaSQGG4DCf4c_pM_tE759OLoJR_u3pRI3A2vubO0vdq3g9Z6Kfy6XgEue7F4NacTAEhTGVHh4cVHVGClr2BclYX_CyL1jRn8vFgaLaHFT1_IDIspK1yA8Iyw8GIUoPFCVS5QeTD0f_NJ9Ts6roO9_ew3FGrfwxns0oExR4gOn3TGC1AsMZ5pq2lufX-PTqePkt_pD_vOjJwdk9OgqvOn4oR3flgjwvnukqMcnx_Og2VuW864e9YvZ5xSj8gxIj1ao3U7Ls6Xz228hcpu_v40-TARofLsfjMKu_pvffRh394HG8PP46pox_FNkhurlTsZ-9itNeMfv0K2VOeaPai6qdELoTJyKnT2AIW33TAMc_Ti7zSbGsnurH5Lb-QW6WHX3ri_NgcXH6hY3Qh0VWxbHG8-urrr57xezTl9TayLLXqF0pWVFlGNUdjXFt5MgYTAow_P7ggZ1jdlevyinLp3I209RYygLzmm4YCzCEbWLB9doDr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3kfD9NA6CxPdeusnwO-wjPwzCAfTD2A_S1IeRZzE7CVCQBIEfJH4YhYGHon4A4yCJYIxQhNLgwQN15WYB5GYBY6dZ8x8k9mAf-n4M4zRMBmmKogSmDw3Y1No-EZPIR36YJmmMAhig7dbmAflmdyYtAoZNXznCLWCXTFxQu0Tu2-3YHuxGBeeGiVnZmG0mH2Nn0nbWO5Kk3vyAlm9S6UScWxAMIVz_Dw) instead of from a file carries its bond orders on the canvas too, and that view can be shared as a link.

![The PDB viewer by ProteinIQ in side-by-side mode: caffeine from an SDF file on the left in green with double bonds on both carbonyl groups, and the same caffeine from an XYZ file on the right in orange with single bonds to both oxygens.](/images/guides/xyz-file/caffeine-sdf-vs-xyz.webp "**Figure 3. Caffeine from SDF (left) and XYZ (right) with the same coordinates.** The SDF stores both C=O bonds as double. The XYZ file has no bond orders, so the viewer draws those bonds single while still drawing the rings as aromatic.")

Acetate shows the guess that can be wrong without any warning. Assuming a neutral molecule, the viewer exported acetic acid, and any program that reads that SDF adds a hydrogen to the bare oxygen. RDKit refused the same assumption, reporting that it could not find a valid bond ordering, until it was given the charge. Protonation states matter in docking and in quantum chemistry, so for any ion or zwitterion, pass the charge to the converter and check the result.

## How to open an XYZ file

Any text editor shows the contents, since the format is plain text. To see the structure, drop the `.xyz` file, or a gzipped `.xyz.gz`, onto the PDB viewer by ProteinIQ. It reads the file in your browser without uploading it, lists the formula and atom count, draws bonds from distances and plays multi-frame files as trajectories. Several files can be opened at once, as with the caffeine pair in Figure 3, and the side-by-side button puts them in two panes.

![The PDB viewer by ProteinIQ showing caffeine from a three-frame XYZ file, with a trajectory player under the canvas reading 1 of 3 and play, step and loop controls.](/images/guides/xyz-file/multi-frame-xyz-player.webp "**Figure 4. A multi-frame XYZ file opens as a trajectory.** Our three-frame caffeine file loads as one structure with a player under the canvas; the counter reads `1 / 3`. Optimization logs from xtb or ORCA and CREST conformer ensembles are multi-frame XYZ files of the same kind.")

One limit matters when you want to share the view. A file opened from your computer stays in your browser, so `Export` > `Link` leaves it out, and a scene made only of your own files cannot be linked. Link the database entry instead, as in the 1CRN link above.

On the desktop, Avogadro reads XYZ through Open Babel. In Python, RDKit reads it with `Chem.MolFromXYZFile` and Open Babel's `obabel` reads it from the command line.

## How to convert XYZ to PDB, SDF or mmCIF

The PDB viewer by ProteinIQ converts an open XYZ file with `Export` > `Structure`, which writes PDB, mmCIF or SDF. Pick the format by what the structure is:

- For a small molecule, write SDF. The exporter assigns bond orders, as it did for caffeine. Then check the charge, because it assumes a neutral molecule, as it did for acetate. A wrong protonation state can be fixed with [Open Babel](/app/open-babel), which adds hydrogens for a chosen pH.
- For a protein or nucleic acid, the file you get from XYZ to PDB is one residue called `MOL` with no bonds written. If the XYZ came from a PDB entry, go back to that entry: [PDB download](/app/pdb-download) fetches it by ID. If it came from a calculation on a PDB structure and the calculation kept the same atoms in the same order, the atom order is the link: copy the new coordinates into the original PDB file atom by atom.
- For [mmCIF](/guides/cif-file), the same applies as for PDB, since the residue information is not there to write.

In Python, RDKit does the small-molecule conversion with an explicit charge:
```python
from rdkit import Chem
from rdkit.Chem import rdDetermineBonds

mol = Chem.MolFromXYZFile("acetate.xyz")
rdDetermineBonds.DetermineBonds(mol, charge=-1)
Chem.MolToMolFile(mol, "acetate.sdf")
```
`DetermineBonds` runs connectivity and bond orders in one call. On the command line, `obabel caffeine.xyz -O caffeine.sdf` does the same with Open Babel's bond perception, which is given no charge, so check ions by hand.

## How to convert PDB or SDF to XYZ

This direction is easy, because it only throws information away. [Open Babel](/app/open-babel) on ProteinIQ runs in your browser: upload a PDB or SDF file and choose `xyz` as the output format. Crambin's PDB file came back as a 327-atom XYZ in our test. With RDKit, `Chem.MolToXYZBlock(mol)` returns the text, and `obabel 1crn.pdb -O 1crn.xyz` does it on the command line.

Two checks before handing the file to a calculation. First, hydrogens: crystal structures such as 1CRN have none, and quantum chemistry methods and machine-learned potentials need every one of them, so add hydrogens before converting. Second, the charge and multiplicity you will have to supply separately, since the XYZ file will not carry them. Write them down while the SDF or PDB file still shows the formal charges.

## XYZ tools on ProteinIQ

A typical path is to fetch or build a structure, convert it to XYZ for a calculation, then look at the results:

- [PubChem download](/app/pubchem-download) and [SMILES to SDF](/app/smiles-to-sdf): get a 3D small molecule with hydrogens
- [Open Babel](/app/open-babel): convert PDB or SDF to XYZ, adding hydrogens on the way
- [AIMNet2](/app/aimnet2): energies, forces, charges and geometry optimization from an XYZ file, with charge and multiplicity as settings
- [ORB v3](/app/orb-v3): energies, optimization and short molecular dynamics, written out as extended XYZ
- [PDB viewer](/app/pdb-viewer): open single or multi-frame XYZ files and export them as PDB, mmCIF or SDF

## Frequently asked questions

### What is the difference between an XYZ file and a PDB file?

Both store Cartesian coordinates in ångström, but a [PDB file](/guides/open-pdb-file) also names every atom, residue and chain and can list bonds in `CONECT` records. An XYZ file has only the element and position of each atom, so a protein written as XYZ loses its residues and chains.

### Can an XYZ file hold more than one molecule?

Yes. Structures follow one another, each with its own atom count and comment line. Programs use this for optimization paths and conformer ensembles, and the PDB viewer by ProteinIQ opens such a file as a trajectory with one frame per structure.

### What units are XYZ coordinates in?

Ångström, by convention, and Open Babel reads and writes them in ångström. The file has no units field, so a file written in bohr is not marked as such and describes a structure 1.89 times too large.

### Why does my XYZ molecule have the wrong bonds or charge?

Because the file stores neither. Readers bond atoms by distance and then guess bond orders for a neutral molecule unless told otherwise. Give the converter the real charge, as with RDKit's `charge` argument, and check ions and stretched geometries such as transition states by eye.
