Python interface reference

The Python interface is exposed in the chemfiles module, and this page list all the classes and methods in this module.

Error handling

Chemfiles uses exceptions for error handling, throwing ChemfilesError when an error occurs.

exception chemfiles.misc.ChemfilesError

Exception class for errors in chemfiles

exception chemfiles.misc.ChemfilesWarning

Warnings from the Chemfiles runtime.

class chemfiles.misc.FormatMetadata

FormatMetadata contains metadata associated with one format. The following fields are directly accessible:

  • name (str) – name of the format

  • extension (str) – extension associated with the format, or None if there is no extension associated with this format

  • description (str) – extended user-facing description of the format

  • reference (str) – extended user-facing description of the format

  • read (bool) – is reading files in this format implemented?

  • write (bool) – is writing files in this format implemented?

  • memory (bool) – does this format support in-memory IO?

  • positions (bool) – does this format support storing atomic positions?

  • velocities (bool) – does this format support storing atomic velocities?

  • unit_cell (bool) – does this format support storing unit cell information?

  • atoms (bool) – does this format support storing atom names or types?

  • bonds (bool) – does this format support storing bonds between atoms?

  • residues (bool) – does this format support storing residues?


Read configuration data from the file at path.

By default, chemfiles reads configuration from any file named .chemfilesrc in the current directory or any parent directory. This function can be used to add data from another configuration file.

This function will fail if there is no file at path, or if the file is incorrectly formatted. Data from the new configuration file will overwrite any existing data.


Get the list of formats known by chemfiles, as well as all associated metadata.

Return type



Get the format that chemfiles would use to read a file at the given path.

The format is mostly guessed from the path extension, chemfiles only tries to read the file to distinguish between CIF and mmCIF files. Opening the file using the returned format string might still fail. For example, it will fail if the file is not actually formatted according to the guessed format; or the format/compression combination is not supported (e.g. XTC / GZ will not work since the XTC reader does not support compressed files).

The returned format is represented in a way compatible with the various Trajectory constructors, i.e. "<format name> [/ <compression>]", where compression is optional.


Call function on every warning event. The callback should take a string message and return nothing.

By default, warnings are send to python warnings module.