# Chemical potential tutorial {#chemical_potential_tutorial}

## Introduction

In this tutorial, you will see how to compute the chemical potential of
carbon in the diamond phase. In DFT, this is simple the total energy per
atom. In general, the chemical potential depends on thermodynamic
variables likes pressure and temperature. Here we'll simply get the
chemical potential of the zero temperature ground state. We thus use the
equilibrium lattice constant which may be found using an equation of
states fit (see `sec:eos`{.interpreted-text role="ref"}). We simply
perform the calculation defined in
`scf.input <scf.input>`{.interpreted-text role="download"} as follows

``` shell
mpiexec -n 16 rescu --smi -i scf.input
```

Then load the results and get the total energy per atom.

``` matlab
HA2EV = 27.21138602;
mrc = load('results/scf.mat');
etot = mrc.energy.Etot * HA2EV;
etot = etot / numel(mrc.atom.element);
fprintf('mu = %f eV\n', etot)
```

The last line will print

``` shell
mu = -163.887300 eV
```
