Chemfiles: dealing with computational chemistry files


My C++ library chemfiles just hit 0.4.0, and won a Rust interface!

Chemfiles is a library providing a consistent interface on the top of computational chemistry file formats. These format are the way we store data about a molecular simulation (positions, velocities, forces on the atoms, …), and a lot of different formats have been invented to store these data. Some are simple text-based formats, other are more complexe, or binary format. Chemfiles provide an unique API to deal with all the complexity in the chemistry file formats landscape.

Chemfiles is written in C++, and exposes a stable C interface. On the top of this C interface are built the Python, Fortran, Julia and now Rust interfaces to chemfiles.

While writing this, I found that the C FFI of Rust is really wonderful compared to the Fortran, Python or even Julia FFI, thank to a combination of factors:

  • The bindgen crate make it easy to wrap declarations to Rust;
  • Usage of these declarations is typechecked by the compiler, and that save lot of testing time;
  • Dealing with C FFI string is part of the standard library (CStr and CString types). Python and Julia or OK with respect to this, but Fortran is a nightmare …

If you want to try it, it is on I’d like to have some feedback on the API: is it rusty enough? The documentation is here.