From v2.8.0, pymatgen comes with a fairly robust system of managing units. In essence, subclasses of float and numpy array is provided to attach units to any quantity, as well as provide for conversions. These are loaded at the root level of pymatgen and some properties (e.g., atomic masses, final energies) are returned with attached units. This demo provides an outline of some of the capabilities.

Let's start with some common units, like Energy.

Units support all functionality that is supported by floats. Unit combinations are automatically taken care of.

Note that complex units are specified as space-separated powers of units. Powers are specified using "^". E.g., "kg m s^-1". Only integer powers are supported.

Now, let's do some basic science.

Some highly complex conversions are possible with this system. Let's do some made up units. We will also demonstrate pymatgen's internal unit consistency checks.

For arrays, we have the equivalent EnergyArray, ... and ArrayWithUnit classes. All other functionality remain the same.

This concludes the tutorial on units in pymatgen.