ElectronBands.from_mpid fails with spin-polarized system
savya10 opened this issue · comments
Code to reproduce this error:
import abipy.electrons as abielectrons
abielectrons.ebands.ElectronBands.from_mpid('mp-565814',line_mode = True)
Produces the error:
ValueError Traceback (most recent call last)
/var/folders/pr/lgdp8dd12l5gbq5jhlzwtjlm0000gn/T/ipykernel_1625/626718764.py in <module>
1 import abipy.electrons as abielectrons
----> 2 abielectrons.ebands.ElectronBands.from_mpid('mp-565814',line_mode = True)
~/.local/lib/python3.8/site-packages/abipy/electrons/ebands.py in from_mpid(cls, material_id, api_key, endpoint, nelect, has_timerev, nspinor, nspden, line_mode)
481 #print("iv_up", iv_up, "nelect: ", nelect)
482 if pmgb.is_spin_polarized:
--> 483 iv_down = max(d["band_index"][PmgSpin.down])
484 assert iv_down == iv_up
485
ValueError: max() arg is an empty sequence
Any help would be greatly appreciated!
This is a tricky case for the pymatgen --> abipy converter as it's a magnetic semiconductor.
In this case one has to specify the number of electrons per unit cell with:
from abipy.electrons import ElectronBands
ebands = ElectronBands.from_mpid('mp-565814', line_mode=True, nelect=???)
print(ebands)
ebands.plot()
where nelect depends on the structure and the pseudopotentials used in the Vasp calculation
Please consult the MP database.
Specifying nelect will allow you to construct an AbiPy band structure and plot the results.
Note however that the values of the fundamental/direct gaps reported by AbiPy are wrong because the
Fermi level reported by the MP database is inside the bands. Very likely because this is the Fermi level computed
at the SCF level using a shifted k-mesh.
Perhaps the AbipY converter should use the band_index entry to compute the HOMO energy
{'band_index': defaultdict(<class 'list'>,
{<Spin.up: 1>: [221, 222, 223],
<Spin.down: -1>: []}),
)
but this requires some refactoring of the implementation
Fixed in 2e1ed12