# sisl: AttributeError: 'BandStructure' object has no attribute 'eigh'

when I tried to repeat the results of tutorials https://github.com/zerothi/ts-tbt-sisl-tutorial/tree/main/S_01 , I met the following error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[34], line 22
20 # Plot band-structures
21 band.set_parent(H_fdf)
---> 22 eigs = band.eigh()
23 ax.plot(lk, eigs)
25 # You need to create the TB Hamiltonian, see e.g. example TB 1
26 #band.set_parent(<TB Hamiltonian>)
27 #eigs = band.eigh()
28 #ax.plot(lk, eigs, '--')

AttributeError: 'BandStructure' object has no attribute 'eigh'


After checking the sisl documentation, I found eigh() method do belong to class sisl.physics.Hamiltonian instead of class sisl.physics.BandStructure.

I just added the k-points path ,commented on the band structure calculation from TB Hamiltonian,set DFT Hamiltonian at band.set_parent(H_fdf) and nothing else in the original codes as shown in the below

# Calculate band-structure from DFT Hamiltonian and TB Hamiltonian
band = sisl.BandStructure(sisl.geom.graphene(),[[0, 0, 0], [0, 0.5, 0]], 200)
xtick, xtick_label = band.lineartick()
lk = band.lineark()

ax = plt.gca()
ax.xaxis.set_ticks(xtick)
ax.set_xticklabels(xtick_label)

# Define limits of the y-axis (Energy!)
# Play with this if you want! :)
ax.set_ylim(-3, 3)
ax.set_ylabel('Eigenspectrum [eV]')

# Plot x-major lines at the ticks
ymin, ymax = ax.get_ylim()
for tick in xtick:
ax.plot([tick,tick], [ymin, ymax], 'k')

# Plot band-structures
band.set_parent(H_fdf)
eigs = band.eigh()
ax.plot(lk, eigs)

# You need to create the TB Hamiltonian, see e.g. example TB 1
#band.set_parent(<TB Hamiltonian>)
#eigs = band.eigh()
#ax.plot(lk, eigs, '--')


Any suggestions will be appreciated!

The problem is solved by changing from eigs = band.eigh() in the # Plot band-structures part into eigs = band.apply.array.eigh(),which is borrowed from https://github.com/zerothi/ts-tbt-sisl-tutorial/blob/main/TB_01/run.ipynb.

help(band.apply.array.eigh) gives

Help on function eigh in module sisl.physics.sparse:

eigh(k=(0, 0, 0), gauge='R', eigvals_only=True, **kwargs)
Returns the eigenvalues of the physical quantity

Setup the system and overlap matrix with respect to
the given k-point and calculate the eigenvalues.

All subsequent arguments gets passed directly to :code:scipy.linalg.eigh

Parameters
----------
spin : int, optional
the spin-component to calculate the eigenvalue spectrum of, note that
this parameter is only valid for Spin.POLARIZED matrices.


help(band.eigh) gives

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[53], line 1
----> 1 help(band.eigh)

AttributeError: 'BandStructure' object has no attribute 'eigh'
$$$$
`
• that is correct, some changes hadn't been migrated to the tutorials Commented Aug 1 at 8:56