Fix compute_fermi_level for FermiZeroTemperature and collinear spins
This PR changes compute_fermi_level to have the two spin components of a same kpoint be treated together in the case of collinear spins. The eigenvalues of the two spin components are merged before searching for the HOMO and LUMO.
I think you can just brutally concatenate everything and get rid of n_spin, no? Also should be able to get rid of some of the rest of that function? I think that function should just look like the bisection in FermiBisection but doing the bisection on the index of the eigenvalues rather than on the eigenvalues themselves, ie find the index i such that excess(all_eigs[i]) == 0 and set the fermi level to all_eigs[i] + all_eigs[i+1]. Doesn't look like there's a integer bisection already coded, so just do it by hand I guess.
@gkemlin this came up because we had trouble with SCF for magnetic systems (without temperature), there's no reason to want to have the same number of occupied states in every kpoint, is there?
The krange_spin function with loop over model.n_spin_components might also be helpful.
For zero temperature there might be hidden assumptions about how many bands are actually converged in the diagonalisation or sth. like that.
We discussed the semantics here, and it seems reasonable to allow a variable number of occupied states per kpoint, but emit a warning. It's helpful when eg something is an insulator but the SCF goes through a phase where it thinks it's a metal. Also doing a metal at zero temperature is relatively sensible too. I'm not sure what the other codes do here.
Abinit says by default All k points have the same occupancies of bands for a given spin (but these occupancies may differ for spin up and spin down - typical for ferromagnetic insulators) and also has an option to allow for manual occupations (which can be different for each kpoint)
I agree, sounds reasonable and useful to have (referring to the different number of occupied bands per k-Point and spin)
Hi, that's a good question. From my very sparse experience with spins (I think it only concerns what we did with Fe2MnAl), I remember that
- for a fixed spin channel, there is no reason to assume that all kpts have the same number of occupied states
- for a fixed kpt, there is no reason to assume that both spin channels have the same number of occupied states
However, this is was with positive temperature but I guess that at zero temperature there is still no reason to enforce same occupancy for every kpt and spin so that's something reasonable to have, yes.
Still, just to make sure I get it, at zero temperature (e.g. for ferromagnetic insulators), if you look at every kpts with both spin channels taken together, the number of occupied states should be the same everywhere right ? Otherwise I can't see how the Fermi level can en up in a spectral gap.
Still, just to make sure I get it, at zero temperature (e.g. for ferromagnetic insulators), if you look at every kpts with both spin channels taken together, the number of occupied states should be the same everywhere right ? Otherwise I can't see how the Fermi level can en up in a spectral gap.
Yes, if the thing is an insulator. However, it can possibly happen that during SCF iterations the system gets lost and temporarily believes it's a metal (I think I encountered this issue before). Also, there's no particular reason we shouldn't be able to do metals at zero temperature (it might blow up, but it might not, and we should be able to try).