hamop
hamop is a Python package for computing what electrons do in a
material or molecule described by a tight-binding model: a short
list of orbitals and the energies that let an electron hop between
them. You build the model once. From that one model the package
computes:
- the allowed electron energies (the band structure) and how many states sit at each energy (the density of states);
- how strongly the material absorbs light at each photon energy (the optical conductivity);
- how easily electrons pass through a small device placed between two wires (the transmission), and from it the conductance, current and thermovoltage a measurement at a given temperature would report;
- topological numbers such as the Chern number and, for crystals with time-reversal symmetry, the Z2 index (in 2D, and the strong and weak indices in 3D), and related geometric quantities of the electron states;
- for your own measurements: model parameters fitted to measured band energies with error bars, error bars for anything computed from them, a test of whether the data need a richer model, the chemical potential and quantum capacitance that a measured carrier density implies, and the transmittance of a 2D sample that an optical measurement would see;
- the conductivity, the thermopower (Seebeck coefficient) and the electronic heat conductivity of a bulk crystal or a gated 2D sheet, in the relaxation-time (Boltzmann) picture;
- (new in 0.17.0) the absorption of 2D semiconductors with excitons, the bound electron-hole pairs that dominate it, and the sub-gap absorption of point defects in supercells: their levels, how the result depends on the cell size, and which transitions absorb.
The point of the package is that all of these come from the same
matrices. When the optics and the energy levels of one model are
computed by different codes, small differences in conventions (how
the velocity is defined, how overlapping orbitals are treated, how
peaks are broadened) can make the results disagree, for example an
absorption edge that no longer sits at the band gap. Here the
spectrum and the optics are computed from the same Bloch matrices
through the same eigensolver, the topology functions work from the
same hopping blocks, and principal_layers cuts the same model into
the layer blocks that the transport functions take.
The package also works when neighboring orbitals overlap (a nonorthogonal basis, as in LCAO calculations, which build electron states from atomic orbitals), and it can read Hamiltonians exported by Wannier90, a widely used program that turns first-principles (quantum-mechanical, parameter-free) calculations into tight-binding models. Since 0.17.0 it also takes the Bloch matrices H(k) and S(k) straight from any code that can give them at a chosen wave vector, so the optics of a first-principles calculation need no real-space reconstruction, which goes wrong in small cells. It ships no material data: the numbers of a real material come from your own calculation or measurement.
Install
pip install hamop
It needs Python 3.9 or newer, NumPy 1.22 or newer and SciPy 1.8 or newer, and nothing else.
A first look
Graphene: bands and the absorption plateau
import numpy as np
from hamop import graphene, bands, sigma_optical
g = graphene(t=-2.7, a=2.46) # hopping t in eV, lattice constant a in Angstrom
b = 2 * np.pi * np.linalg.inv(g.cell).T # reciprocal lattice vectors (rows)
K = (2 * b[0] + b[1]) / 3 # a corner of the Brillouin zone
e_gamma = bands(g, [np.zeros(2)])[0]
e_K = bands(g, [K])[0]
print(f"band energies at the zone center: {e_gamma[0]:+.4f} {e_gamma[1]:+.4f} eV")
print("gap at the zone corner K below 1e-9 eV:", abs(e_K[1] - e_K[0]) < 1e-9)
omega = np.array([1.0, 1.3]) # photon energies, eV
sigma = sigma_optical(g, omega, mu=0.0, mesh=120, eta=0.12, T=10.0)
for w, s in zip(omega, sigma):
print(f"photon {w:.1f} eV: sigma = {s:.3f} x e^2/(4 hbar)")
band energies at the zone center: -8.1000 +8.1000 eV
gap at the zone corner K below 1e-9 eV: True
photon 1.0 eV: sigma = 1.020 x e^2/(4 hbar)
photon 1.3 eV: sigma = 1.032 x e^2/(4 hbar)
The two bands sit at -/+ 3|t| at the zone center and touch at the
corner K (the "Dirac point"). The absorption is close to 1 in units of
e^2/(4 hbar), the universal optical conductivity of graphene
(Kuzmenko et al., Phys. Rev. Lett. 100, 117401 (2008)). The test suite
checks these two photon energies to within 5 %. The script
examples/graphene_universal_conductivity.py prints the same quantity
from 0.6 to 1.8 eV.
How strongly an exciton is bound in a layer of MoS2
from hamop import wannier_exciton
# MoS2 with the reduced mass 0.271 of relaxed PBE bands at K
hbn = wannier_exciton(0.271, eps=4.45, r0=34.0) # in hBN
free = wannier_exciton(0.271, eps=1.0, r0=2 * 3.14159265 * 6.6)
print(f"in hBN: 1s bound by {hbn.binding_energy:.3f} eV, "
f"rms radius {hbn.radii[0]:.1f} A")
print(f"free standing: 1s bound by {free.binding_energy:.3f} eV, "
f"rms radius {free.radii[0]:.1f} A")
print("in hBN, 1s 2s 3s (eV):", " ".join(f"{e:.3f}" for e in hbn.energies))
in hBN: 1s bound by 0.219 eV, rms radius 12.5 A
free standing: 1s bound by 0.567 eV, rms radius 10.3 A
in hBN, 1s 2s 3s (eV): -0.219 -0.051 -0.022
The same numbers as the MoS2 vacancy study this release follows; the tests also reproduce published binding energies of four materials and the exact 2D hydrogen series.
Where to read on
- Examples: 23 short examples, each with the output it prints. Examples 19 to 23 are new in 0.17.0: optics from any code's H(k) and S(k), exciton binding, absorption with excitons, a vacancy in supercells of growing size, and mirror parity.
- Tutorials: three complete analyses, from data to a result with error bars.
- Words, units and conventions: the terms used here, explained, and every unit and sign convention.
- What is in the package: every function, grouped by task.
- How the results are checked: what each test compares with, and to what accuracy.
- Limits: when the package refuses an input and why, and the approximations it makes on purpose.
- CHANGELOG: what changed in each version.
Relation to existing tools
Excellent tools cover parts of this space: PythTB and pybinding build tight-binding models and their spectra, Kwant is the standard for quantum transport, and Xatu is a dedicated code for excitons from tight-binding and localized-orbital Hamiltonians. hamop does not replace any of them, and for their core use cases they are more capable. Its niche is the combination they leave open: overlap matrices handled across all the observables above, optics computed from the same Bloch matrices as the spectrum (also Bloch matrices taken directly from a first-principles code), excitons and defect analysis on the same footing, and a small NumPy/SciPy-only core checked against closed forms and published numbers.
Where it comes from
The package started as the general-purpose engine of a study of sulfur vacancies in monolayer MoS2, whose code is at https://github.com/Tanvir-Mahmud-Mahim/mos2-vacancy-optics. The revised version of that study is
T. M. Mahim, M. M. Rahman and A. S. M. Mohsin, "Sub-gap optical absorption of sulfur vacancies in monolayer MoS2: supercell size effects, vacancy arrangement, and a machine-learning Hamiltonian model", manuscript (2026).
It computes the optical conductivity from the Hamiltonian and overlap
matrices with exact k-derivatives, measures and removes the effect of
the supercell size, splits the absorption by transition, and adds the
electron-hole interaction with a model Bethe-Salpeter equation. Version
0.17.0 brings those methods into the package (KSpaceModel,
exciton_spectrum, wannier_exciton, supercell,
sigma_by_transition, absorption_per_defect and the mirror labels).
The first version of the study took the k-derivatives from real-space
blocks rebuilt on a coarse k-mesh; the revised version shows that this
overestimates the absorption of distorted supercells, and the
KSpaceModel exists so that the shortcut is not needed. The
material-specific parts (DFT extraction, the machine-learned
Hamiltonians, the MoS2 structures) stay in the study's repository.
Citing, support and license
If hamop helps your work, please cite it with the concept DOI
10.5281/zenodo.22311381,
which always resolves to the latest release; every release is
archived on Zenodo. Citation metadata is in
CITATION.cff.
The package is written and maintained by Tanvir Mahmud Mahim (Department of Electrical and Electronic Engineering, BRAC University), who reviews every change and takes the final decision on scope and releases. There is no separate governance body; design questions are discussed in the open in issues and pull requests, and the standing rule of CONTRIBUTING.md binds the maintainer exactly as it binds contributors: a change that touches physics arrives with a test, and a constant arrives with its source.
Support runs through the issue tracker at https://github.com/TaN-MM-Org/hamop/issues. Usage questions are welcome there alongside bug reports; a docstring that left a unit or a sign convention unclear is treated as a documentation bug, not as user error. The maintainer aims to respond within a week.
While the version is below 1.0 the API may still move between minor versions; such changes are called out in the release notes.
Licensed under Apache-2.0 (see LICENSE).
Metadata
Release files for hamop 0.17.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hamop-0.17.0.tar.gz | 280.2 kB | With provenance | Details for hamop-0.17.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hamop-0.17.0-py3-none-any.whl | Python 3 | none | any | Details for hamop-0.17.0-py3-none-any.whl |
Total release size: 418.0 kB
Release files / hamop-0.17.0.tar.gz
| Download URL | hamop-0.17.0.tar.gz |
|---|---|
| Size | 280.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d6f0bbb8de7dba785b4474295f2f58bc1fd52054514b2637e18586b3b4972ba
|
|
BLAKE2b-256 checksum How to use checksums |
382b56b2acdfa03ff311346e02c771cfcebdcdee42f45e94d6e667f337e0360a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logRelease files / hamop-0.17.0-py3-none-any.whl
| Download URL | hamop-0.17.0-py3-none-any.whl |
|---|---|
| Size | 137.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba62b6752482e4a4867384a694e3ed1cf5aa7043d15fc2279345c45e1d9915b8
|
|
BLAKE2b-256 checksum How to use checksums |
744bd5d6ec2130c3fcd667b8fd948080513dea63da176f58cf102baa3a83d412
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logSecurity for hamop 0.17.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for hamop-0.17.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.