Rewrote the calculation of the number of DOFs.

It was broken for the combination of PIMD, centroid freezing and ghost
atoms present in the system. This fixes it.

The new code is on lines 222-255.

There is also some style cleanup, with no semantic changes.