C++ C CMake Shell Python PowerShell
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Chemfiles: a library for reading and writing chemistry files

Documentation Build Status -- Linux & OSX Build Status -- Windows Code Coverage Gitter DOI

Chemfiles is a modern and high-quality library for reading and writing trajectory files created by computational chemistry simulations programs. To help you access information (atomic positions, velocities, names, topology, etc.) about these files, Chemfiles provides an interface that is

  • unified: the same code will work with all supported formats;
  • simple: the interface is easy to use and extensively documented.

You can use Chemfiles to conduct post-processing analysis and extract physical information about the systems you're simulating, to convert files from one format to another, or to write trajectories with your own simulation software.

This repository contains the core of the Chemfiles library — a programmer interface written in C++11, with a C99 interface. If you want a ready-to-use programs for trajectory analysis, use cfiles. You can also use Chemfiles from other languages: Python 2&3, Fortran, Rust, and Julia.

Is Chemfiles for You?

We created Chemfiles to be able to write analysis algorithms once and use them with all the existing trajectory formats in cfiles; and to provide input/output capacities in two molecular simulation engines. You might want to use it too, if any of these apply to your use case:

  • you don't want to spend time writing and debugging a file parser;
  • you use binary formats because they are faster and take up less disk space;
  • you write analysis algorithms and want to read more than one trajectory format;
  • you write simulation software and want to use more than one format for input or output.

There are other libraries doing the roughly the same job as Chemfiles, have a look at them if Chemfiles is not for you. Here we also say why we could not use them instead of creating a new library.

  • OpenBabel is a C++ library providing convertions between more than 110 formats. It is more complex than chemfiles, and distributed under the GPL license.
  • VMD molfile plugins are a collection of plugins witten in C and C++ used by VMD to read/write trajectory files. It does not support non-constant number of atoms in a trajectory, and do not provide a lot of documentation.
  • MDTraj, MDAnalyis, cclib are Python libraries providing analysis and read capacities for trajectories. Unfortunely, they are only usable from Python.


Chemfiles is free and open source. Your contributions are always welcome!

If you have questions or suggestions, or need help, please open an issue or join us on our Gitter chat room.

If you are using Chemfiles in a published scientific study, please cite us using the following DOI: https://doi.org/10.5281/zenodo.800663.

Quick Links

Chemfiles Features

  • Reads both text (XYZ, PDB, ...) and binary (NetCDF, TNG, ...) file formats;
  • Transparently read and write compressed files (.gz and .xz compressions);
  • Filters atoms with a rich selection language;
  • Supports non-constant numbers of atoms in trajectories;
  • Easy-to-use programming interface in Python, C++, C, Fortran 95, Julia and Rust;
  • Cross-platform and usable from Linux, OS X and Windows;
  • Open source and freely available (3-clauses BSD license);

Supported File Formats

Chemfiles can read and write files in the following formats:

  • XYZ;
  • PDB;
  • Amber NetCDF
  • LAMMPS data files;
  • Tinker XYZ files (.arc files);
  • BIOVIA SDF files;
  • SERC Daresbury Laboratory CSSR files;
  • GROMACS formats: .gro;
  • TRIPOS mol2 files;

For text-based formats (XYZ, PDB, LAMMPS Data, Tinker, ...) Chemfiles will transparently read compressed files if the file extension matches the expected one (file.arc.gz, trajectory.pdb.xz).

Chemfiles can also read but not (yet) write files in the following formats:

  • TNG;
  • LAMMPS trajectory;
  • GROMACS formats: .xtc; .trj; .trr;
  • CHARMM DCD files;
  • Molden files;
  • MacroMolecular Transmission Format (MMTF) files;

See the issue list for planned formats. If you need another format, open a new issue with a link to the format definition, or — even better — write the code and contribute it!

Getting Started

Here, we'll help you get started with the C++ and C interface. If you want to use Chemfiles with another language, please refer to the corresponding documentation.

Installing Compiled Packages

We provide compiled packages of the latest Chemfiles release for Linux distributions. You can use your package manager to download them here.

We also provide conda packages in the conda-forge community channel for Linux and OS X. This package provides the C++, C and Python interfaces. Install the conda package by running:

conda install -c conda-forge chemfiles

Find more information about packages in the documentation.

Building from Source

You will need cmake and a C++11 compiler.

git clone https://github.com/chemfiles/chemfiles
cd chemfiles
mkdir build
cd build
cmake ..
make install

Usage Examples

This is what the interface looks like in C++:

// C++ version
#include <iostream>
#include "chemfiles.hpp"

int main() {
    chemfiles::Trajectory trajectory("filename.xyz");

    auto frame = trajectory.read();
    std::cout << "There are " << frame.natoms() << " atoms in the frame" << std::endl;

    auto positions = frame.positions();
    // Do awesome science with the positions here !


Guillaume Fraux created and maintains Chemfiles, which is distributed under the 3 clauses BSD license. By contributing to Chemfiles, you agree to distribute your contributions under the same license.

The AUTHORS file lists all contributors to Chemfiles. Many thanks to all of them!