It seem that the correct formula is
Ω = F+(N-N0)U
F = E(DFT) + (N0 - N) FERMI_SHIFT
where N is the number of electrons of charged system, N0 is the number of electrons of neutral system. U is the work function.
However, dF/dN = E(fermi) - FERMI_SHIFT = E(fermi) + E(vac), Here E(fermi) and E(vac) are fermi energy and vacuum level, it is not -U (-U = E(fermi) - E(vac) ).
It seem that the correct formula is Ω = F+(N-N0)U F = E(DFT) + (N0 - N) FERMI_SHIFT where N is the number of electrons of charged system, N0 is the number of electrons of neutral system. U is the work function. However, dF/dN = E(fermi) - FERMI_SHIFT = E(fermi) + E(vac), Here E(fermi) and E(vac) are fermi energy and vacuum level, it is not -U (-U = E(fermi) - E(vac) ).