This is a Python library to compute quantum-lattice tight-binding models in different dimensionalities.
pip install --upgrade pyqulaClone the Github repository with
git clone https://github.com/joselado/pyqulaand add the "pyqula/src" path to your Python script with
import sys
sys.path.append(PATH_TO_PYQULA+"/src")A few features depend on heavier, optional backends that are not installed by default. Install them with the relevant extra:
pip install pyqula[mpi] # MPI-parallel routines (mpi4py)
pip install pyqula[dataframe] # pandas-based data export
pip install pyqula[images] # Pillow-based image export
pip install pyqula[all] # all of the aboveThese are the minimum/recommended versions of several required libraries
(also enforced in pyproject.toml)
- numpy >= 2.1
- scipy >= 1.13.1
- matplotlib >= 3.10.0
- numba >= 0.60.0
- multiprocess >= 0.70.19
- dill >= 0.4.1
- threadpoolctl >= 3.5.0
- jax >= 0.8.1
The user guide is the main reference: a chapter
per topic (Hamiltonians, observables, operators, superconductivity, mean field,
topology, response functions, transport, Wannierization, KPM, classical spin and
lattice-gas models), each with the physics and runnable snippets, followed by a
reference of every Geometry/Hamiltonian method and its arguments. A PDF
build is at documentation/user_guide.pdf.
examples/ holds several hundred runnable scripts organized by dimensionality
(0d/ 1d/ 2d/ 3d/, plus transport/, embedding/, wannier/,
classicalspin/, latticegas/).
Jupyter notebooks with tutorials can be found in the links below
In this repository:
jupyter-notebooks/: eleven step-by-step notebooks, building up from lattice structure and band structure through self-consistency, Chern insulators, Jackiw-Rebbi solitons and quantum-dot modesjupyter-notebooks/functionalities/: one executed notebook for each entry of the FUNCTIONALITIES list below
From the "Advanced Quantum Materials course at Aalto University 2025"
- Electronic structure theory
- Topological band structure theory
- The Quantum Hall state
- Superconductivity and Majorana physics
- Interactions and magnetism
- Excitations and defects in quantum materials
From the Jyvaskyla Summer School 2022
- Spinless, spinful and Nambu basis for orbitals [notebook]
- Full non-collinear electron and Nambu formalism [notebook]
- Include magnetism, spin-orbit coupling and superconductivity [notebook]
- Band structures with state-resolved expectation values [notebook]
- Momentum-resolved spectral functions [notebook]
- Local and full operator-resolved density of states [notebook]
- 0d, 1d, 2d and 3d tight binding models [notebook]
- Electronic structure unfolding in supercells [notebook]
- Non-Hermitian Hamiltonians [notebook]
- Structural relaxation of twisted bilayer graphene [notebook]
- Spin splitting of collinear magnets and altermagnets [notebook]
- Nonlinear spin conductivity and the X-wave index of altermagnets [notebook]
- Selfconsistent mean-field calculations with local/non-local interactions [notebook]
- Both collinear and non-collinear formalism [notebook]
- Spin-spin exchange mean field, including anisotropic exchange [notebook]
- Anomalous mean-field for non-collinear superconductors [notebook]
- Full selfconsistency with all Wick terms for non-collinear superconductors [notebook]
- Constrained and unconstrained mean-field calculations [notebook]
- Automatic identification of order parameters for symmetry broken states [notebook]
- Hermitian and non-Hermitian mean-field calculations [notebook]
- Random phase approximation many-body response functions [notebook]
- RPA collective modes and instability detection [notebook]
- Chebyshev-based mean-field calculations for large systems [notebook]
- Mean-field solvers with automatic differentiation [notebook]
- Spinon mean-field theory of quantum spin models [notebook]
- Mean-field theory of Kondo lattices and heavy fermions [notebook]
- Superfluid weight of superconductors and its quantum geometry [notebook]
- Non-unitarity of spin-triplet superconductors [notebook]
- Excitons from the Bethe-Salpeter equation [notebook]
- Magnons from time-dependent Hartree-Fock [notebook]
- Magnons from a pair-basis ladder [notebook]
- Matrix-free and tensor-network Bethe-Salpeter solvers [notebook]
- Static RPA screened interaction [notebook]
- GPU execution of the heavy kernels [notebook]
- Berry phases, Berry curvatures, Chern numbers and Z2 invariants [notebook]
- Operator-resolved Chern numbers and Berry density [notebook]
- Frequency resolved topological density [notebook]
- Spatially resolved topological flux [notebook]
- Real-space Chern density for amorphous systems [notebook]
- Non-Abelian quantum geometric tensor and quantum metric [notebook]
- Wilson loop and Green's function formalism [notebook]
- Spin Chern and mirror Chern numbers [notebook]
- Quadrupole moment of higher-order topological insulators [notebook]
- Strong and weak Z2 indices in three dimensions [notebook]
- Winding numbers and Z2 invariants in one dimension [notebook]
- Entanglement entropy and entanglement spectrum [notebook]
- Optical conductivity from the Kubo-Greenwood formula [notebook]
- Drude weight and the optical f-sum rule [notebook]
- Charge-charge response function and its RPA form [notebook]
- Response functions between arbitrary operators [notebook]
- RKKY interaction between magnetic impurities [notebook]
- Spectral functions in infinite geometries [notebook]
- Surface spectral functions for semi-infinite systems [notebook]
- Interfacial spectral function in semi-infinite junctions [notebook]
- Single impurities in infinite systems [notebook]
- Quasiparticle interference maps [notebook]
- Green's function renormalization algorithm [notebook]
- Operator and momentum resolved spectral functions [notebook]
- Local and full spectral functions [notebook]
- Non-local correlators and Green's functions [notebook]
- Locally resolved expectation values [notebook]
- Operator resolved spectral functions [notebook]
- Reaching system sizes up to 10000000 atoms on a single-core laptop [notebook]
- Maximally-localized Wannier functions for a selected range of bands [notebook]
- Exact reproduction of the selected bands on the Wannier mesh [notebook]
- Band disentanglement with outer and frozen energy windows [notebook]
- Point-group symmetry-enforced Wannierization [notebook]
- Works for 0d, 1d, 2d and 3d periodic Hamiltonians, including Nambu/BdG [notebook]
- Metal-metal transport [notebook]
- Metal-superconductor transport [notebook]
- Transport through a finite central region between two leads [notebook]
- Fully non-collinear Nambu basis [notebook]
- Non-equilibrium Green's function formalism [notebook]
- Operator-resolved transport [notebook]
- Differential decay rate [notebook]
- Tunneling and contact scanning probe spectroscopy [notebook]
- Multiple Andreev reflection and the AC Josephson effect [notebook]
- Classical Heisenberg spin models with arbitrary exchange couplings [notebook]
- Local energy minimization and magnetization textures [notebook]
- Lattice-gas Monte Carlo with configurable interactions [notebook]
- Ising model Monte Carlo [notebook]
- Correlators, structure factors and thermodynamics from sampling [notebook]
A variety of examples can be found in pyqula/examples. Short examples are shown below
from pyqula import geometry
g = geometry.kagome_lattice() # get the geometry object
h = g.get_hamiltonian() # get the Hamiltonian object
(k,e) = h.get_bands() # compute the band structurefrom pyqula import geometry
g = geometry.honeycomb_lattice() # get the geometry object
g = g.get_supercell(7) # create a supercell
h = g.get_hamiltonian() # get the Hamiltonian object
(k,e,v) = h.get_bands(operator="valley") # compute the band structurefrom pyqula import geometry
import numpy as np
g = geometry.triangular_lattice() # geometry of a triangular lattice
h = g.get_hamiltonian() # get the Hamiltonian
h.setup_nambu_spinor() # setup the Nambu form of the Hamiltonian
# perform SCF, on a k-mesh that resolves the superconducting gap
h = h.get_mean_field_hamiltonian(U=-2.0,filling=0.45,mf="swave",nk=40)
# electron spectral-function
h.get_kdos_bands(operator="electron",nk=400,energies=np.linspace(-2.0,2.0,200),delta=0.03)import numpy as np
from pyqula import geometry
g = geometry.triangular_lattice() # generate the geometry
h = g.get_hamiltonian() # create Hamiltonian of the system
h.add_exchange([0.,0.,1.]) # add exchange field
h.setup_nambu_spinor() # initialize the Nambu basis
# perform a superconducting non-collinear mean-field calculation,
# on a k-mesh that resolves the superconducting gap
h = h.get_mean_field_hamiltonian(V1=-1.5,filling=0.3,mf="random",nk=40)
# compute the non-unitarity of the spin-triplet superconducting d-vector
d = h.get_dvector_non_unitarity(nk=40) # non-unitarity of spin-triplet
# electron spectral-function
h.get_kdos_bands(operator="electron",nk=400,energies=np.linspace(-2.0,2.0,200),delta=0.03)from pyqula import geometry
g = geometry.honeycomb_zigzag_ribbon(10) # create geometry of a zigzag ribbon
h = g.get_hamiltonian() # create hamiltonian of the system
h = h.get_mean_field_hamiltonian(U=1.0,filling=0.5,mf="ferro")
(k,e,sz) = h.get_bands(operator="sz") # calculate band structurefrom pyqula import geometry
g = geometry.square_lattice() # geometry of a square lattice
g = g.get_supercell([2,2]) # generate a 2x2 supercell
h = g.get_hamiltonian() # create hamiltonian of the system
h.add_zeeman([0.,0.,0.1]) # add out-of-plane Zeeman field
h = h.get_mean_field_hamiltonian(U=2.0,filling=0.5,mf="random") # perform SCF
(k,e,c) = h.get_bands(operator="sz") # calculate band structure
m = h.get_magnetization() # get the magnetizationfrom pyqula import geometry
g = geometry.square_lattice() # geometry of a square lattice
g = g.get_supercell([7,7]) # generate a 7x7 supercell
g = g.remove(i=g.get_central()[0]) # remove the central site
h = g.get_hamiltonian() # create hamiltonian of the system
h.add_rashba(.4) # add Rashba spin-orbit coupling
h = h.get_mean_field_hamiltonian(U=2.0,filling=0.5,mf="random") # perform SCF
(k,e,c) = h.get_bands(operator="sz") # calculate band structure
m = h.get_magnetization() # get the magnetizationfrom pyqula import geometry
import numpy as np
g = geometry.bisquare_ribbon(2) # square bipartite ribbon
h = g.get_hamiltonian() # generate Hamiltonian
h = h.get_mean_field_hamiltonian(U=3.,nk=10,mf="antiferro",filling=0.5) # SCF
energies=np.linspace(.0,1.6,400) # energies
# RPA many-body spin spectral function
(qs,es,chis) = h.get_qdos_iets(energies = energies,nq=100,nk=10,
delta=1e-2,qpath=["G","X"])from pyqula import geometry ; import numpy as np
g = geometry.lieb_ribbon(2) # Lieb lattice ribbon
h = g.get_hamiltonian() # generate Hamiltonian
h = h.get_mean_field_hamiltonian(U=3.,mf="antiferro",filling=0.5) # perform SCF
energies=np.linspace(.0,1.,400) # energies
# RPA many-body spin spectral function
(qs,es,chis) = h.get_qdos_iets(energies = energies,nq=100,nk=10,
delta=1e-2,qpath=["G","X"])from pyqula import specialhamiltonian # special Hamiltonians library
h = specialhamiltonian.twisted_bilayer_graphene() # TBG Hamiltonian
(k,e) = h.get_bands() # compute band structurefrom pyqula import specialhamiltonian # special Hamiltonians library
h = specialhamiltonian.NbSe2(soc=0.5) # NbSe2 Hamiltonian
(k,e,c) = h.get_bands(operator="sz",kpath=["G","K","M","G"]) # compute bandsfrom pyqula import geometry
g = geometry.honeycomb_lattice()
h = g.get_hamiltonian()
h.add_rashba(0.2) # Rashba spin-orbit coupling
h.add_zeeman([0.,0.,0.6]) # Zeeman field
from pyqula import topology
(kx,ky,omega) = h.get_berry_curvature() # compute Berry curvature
c = h.get_chern() # compute the Chern numberimport numpy as np
from pyqula import geometry
g = geometry.chain() # create a chain
g = g.supercell(100) # create a large supercell
g.dimensionality = 0 # make it finite
for J in np.linspace(0.,0.2,50): # loop over exchange couplings
h = g.get_hamiltonian() # create a new hamiltonian
h.add_onsite(2.0) # shift the chemical potential
h.add_rashba(.3) # add rashba spin-orbit coupling
h.add_exchange([0.,0.,J]) # add exchange coupling
h.add_swave(.1) # add s-wave superconductivity
edge = h.get_operator("location",r=g.r[0]) # projector on the edge
energies = np.linspace(-.2,.2,200) # set of energies
(e0,d0) = h.get_dos(operator=edge,energies=energies,delta=2e-3) # edge DOSimport numpy as np
from pyqula import geometry
g = geometry.chain() # create a chain
g = g.supercell(100) # create a large supercell
g.dimensionality = 0 # make it finite
h = g.get_hamiltonian() # create a new hamiltonian
h.add_onsite(2.0) # shift the chemical potential
h.add_rashba(.3) # add rashba spin-orbit coupling
h.add_exchange([0.,0.,0.15]) # add exchange coupling
h.add_swave(.1) # add s-wave superconductivity
energies = np.linspace(-.15,.15,200) # set of energies
for ri in g.r: # loop over sites
edge = h.get_operator("location",r=ri) # projector on that site
(e0,d0) = h.get_dos(operator=edge,energies=energies,delta=2e-3) # local DOSfrom pyqula import geometry
import numpy as np
g = geometry.honeycomb_lattice() # create a honeycomb lattice
n = 3 # size of the supercell
g = g.get_supercell(n,store_primal=True) # create a supercell
h = g.get_hamiltonian() # get the Hamiltonian
fons = lambda r: (np.sum((r - g.r[0])**2)<1e-2)*100 # onsite in the impurity
h.add_onsite(fons) # add onsite energy
kpath = np.array(g.get_kpath(nk=200))*n # enlarged k-path
h.get_kdos_bands(operator="unfold",delta=1e-1,kpath=kpath) # unfolded bandsfrom pyqula import geometry
from pyqula import potentials
g = geometry.triangular_lattice() # create geometry
g = g.get_supercell([7,7]) # create a supercell
h = g.get_hamiltonian() # get the Hamiltonian
fmoire = potentials.commensurate_potential(g,n=3,minmax=[0,1]) # moire potential
h.add_onsite(fmoire) # add onsite energy following the moire
h.get_bands(operator=fmoire) # project on the moirefrom pyqula import geometry
from pyqula import potentials
import numpy as np
g0 = geometry.triangular_lattice() # create geometry
n = 5 # supercell
g = g0.get_supercell(n,store_primal=True) # create a supercell
h = g.get_hamiltonian() # get the Hamiltonian
fmoire = potentials.commensurate_potential(g,n=3,minmax=[0,1]) # moire potential
h.add_onsite(fmoire) # add onsite energy following the moire
kpath = np.array(g.get_kpath(nk=400))*n # enlarged k-path
h.get_kdos_bands(operator="unfold",delta=2e-2,kpath=kpath,
energies=np.linspace(-3,-1,300)) # unfolded bandsfrom pyqula import geometry
from pyqula import films
g = geometry.diamond_lattice()
g = films.geometry_film(g,nz=20)
h = g.get_hamiltonian()
(k,e) = h.get_bands()from pyqula import geometry
from pyqula import films
import numpy as np
g = geometry.diamond_lattice() # create a diamond lattice
g = films.geometry_film(g,nz=60) # create a thin film
h = g.get_hamiltonian() # generate Hamiltonian
h.add_strain(lambda r: 1.+abs(r[2])*0.8,mode="directional") # add axial strain
h.add_kane_mele(0.1) # add intrinsic spin-orbit coupling
(k,e,c)= h.get_bands(operator="surface") # compute band structurefrom pyqula import geometry
g = geometry.honeycomb_lattice() # create a honeycomb lattice
h = g.get_hamiltonian() # generate Hamiltonian
h.add_soc(0.15) # add intrinsic spin-orbit coupling
h.add_rashba(0.1) # add Rashba spin-orbit coupling
(es,ks,ds,db) = h.get_surface_kdos(delta=1e-2) # compute surface spectral functionfrom pyqula import islands
g = islands.get_geometry(name="honeycomb",n=3,nedges=3) # get an island
h = g.get_hamiltonian() # get the Hamiltonian
h.get_multildos(projection="atomic") # get the LDOSfrom pyqula import islands
g = islands.get_geometry(name="honeycomb",n=3,nedges=3) # get an island
h = g.get_hamiltonian() # get the Hamiltonian
h = h.get_mean_field_hamiltonian(U=1.0,filling=0.5,mf="ferro") # perform SCF
m = h.get_magnetization() # get the magnetization in each siteimport numpy as np
from pyqula import geometry
g = geometry.square_ribbon(40) # create square ribbon geometry
for B in np.linspace(0.,1.0,300): # loop over magnetic field
h = g.get_hamiltonian() # create a new hamiltonian
h.add_orbital_magnetic_field(B) # add an orbital magnetic field
# calculate DOS projected on the bulk
(e,d) = h.get_dos(operator="bulk",energies=np.linspace(-4.5,4.5,200))import numpy as np
from pyqula import geometry
g = geometry.honeycomb_ribbon(30) # create a honeycomb ribbon
for B in np.linspace(0.,0.02,100): # loop over magnetic field
h = g.get_hamiltonian() # create a new hamiltonian
h.add_orbital_magnetic_field(B) # add an orbital magnetic field
# calculate DOS projected on the bulk
(e,d) = h.get_dos(operator="bulk",energies=np.linspace(-1.0,1.0,200),
delta=1e-2)from pyqula import geometry
from pyqula import kdos
g = geometry.honeycomb_lattice() # create honeycomb lattice
h = g.get_hamiltonian() # create hamiltonian of the system
h.add_haldane(0.05) # Add Haldane coupling
kdos.surface(h) # surface spectral functionfrom pyqula import geometry
import numpy as np
g = geometry.triangular_lattice() # get the geometry
h = g.get_hamiltonian() # get the Hamiltonian
h.add_onsite(2.0) # shift chemical potential
h.add_rashba(1.0) # Rashba spin-orbit coupling
h.add_zeeman([0.,0.,0.6]) # Zeeman field
h.add_swave(.3) # add superconductivity
(kx,ky,omega) = h.get_berry_curvature() # compute Berry curvature
(es,ks,ds,db) = h.get_surface_kdos(energies=np.linspace(-.4,.4,300)) # surface spectral functionfrom pyqula import islands
g = islands.get_geometry(name="triangular",shape="flower",
r=14.2,dr=2.0,nedges=6) # get a flower-shaped island
h = g.get_hamiltonian() # get the Hamiltonian
h.add_onsite(3.0) # shift chemical potential
h.add_rashba(1.0) # Rashba spin-orbit coupling
h.add_zeeman([0.,0.,0.6]) # Zeeman field
h.add_swave(.3) # add superconductivity
h.get_ldos() # Spatially resolved DOSfrom pyqula import geometry
g = geometry.honeycomb_zigzag_ribbon(20) # create geometry of a zigzag ribbon
h = g.get_hamiltonian(has_spin=True) # create hamiltonian of the system
h.add_antiferromagnetism(lambda r: (r[1]>0)*0.5) # add antiferromagnetism
h.add_onsite(lambda r: (r[1]>0)*0.3) # add chemical potential
h.add_swave(lambda r: (r[1]<0)*0.3) # add superconductivity
(k,e,sz) = h.get_bands(operator="sz") # calculate band structurefrom pyqula import geometry
import numpy as np
g = geometry.triangular_lattice() # create geometry of the system
g = g.get_supercell(2) # create a supercell
h = g.get_hamiltonian() # create hamiltonian of the system
h.get_multi_fermi_surface(energies=np.linspace(-4,4,100),delta=1e-1)from pyqula import geometry
import numpy as np
g0 = geometry.triangular_lattice()
n = 3 # size of the supercell
g = g0.get_supercell(n,store_primal=True) # create a supercell
h = g.get_hamiltonian() # get the Hamiltonian
fons = lambda r: (np.sum((r - g.r[0])**2)<1e-2)*100 # onsite in the impurity
h.add_onsite(fons) # add onsite energy
kpath = np.array(g.get_kpath(nk=200))*n # enlarged k-path
h.get_multi_fermi_surface(nk=50,energies=np.linspace(-4,4,100),
delta=0.1,nsuper=n,operator="unfold")from pyqula import geometry
from pyqula import heterostructures
import numpy as np
g = geometry.chain() # create the geometry
h = g.get_hamiltonian() # create the Hamiltonian
h1 = h.copy() # first lead
h2 = h.copy() # second lead
h2.add_swave(.01) # the second lead is superconducting
es = np.linspace(-.03,.03,100) # set of energies for dIdV
for T in np.linspace(1e-3,1.0,6): # loop over transparencies
HT = heterostructures.build(h1,h2) # create the junction
HT.set_coupling(T) # set the coupling between the leads
Gs = [HT.didv(energy=e) for e in es] # calculate conductancefrom pyqula import geometry
from pyqula import heterostructures
import numpy as np
g = geometry.chain() # create the geometry
h = g.get_hamiltonian() # create teh Hamiltonian
h1 = h.copy() # first lead
h2 = h.copy() # second lead
h2.add_onsite(2.0) # shift chemical potential in the second lead
h2.add_exchange([0.,0.,.3]) # add exchange in the second lead
h2.add_rashba(.3) # add Rashba SOC in the second lead
h2.add_swave(.05) # add s-wave SC in the second lead
es = np.linspace(-.1,.1,100) # grid of energies
for T in np.linspace(1e-3,0.5,10): # loop over transparencies
HT = heterostructures.build(h1,h2) # create the junction
HT.set_coupling(T) # set the coupling between the leads
Gs = [HT.didv(energy=e) for e in es] # calculate transmissionfrom pyqula import geometry
import numpy as np
from pyqula import embedding
g = geometry.honeycomb_lattice() # create geometry
h = g.get_hamiltonian() # get the Hamiltonian
hv = h.copy() # copy Hamiltonian to create a defective one
hv.add_onsite(lambda r: (np.sum((r - g.r[0])**2)<1e-2)*100) # add a defect
eb = embedding.Embedding(h,m=hv) # create an embedding object
(x,y,d) = eb.ldos(nsuper=19,energy=0.,delta=1e-2) # compute LDOSfrom pyqula import geometry
import numpy as np
from pyqula import embedding
g = geometry.square_lattice() # create geometry
h = g.get_hamiltonian() # get the Hamiltonian
h.add_swave(0.1) # add s-wave superconductivity
h.add_onsite(3.0) # shift chemical potential
hv = h.copy() # copy Hamiltonian to create a defective one
hv.add_exchange(lambda r: [0.,0.,(np.sum((r - g.r[0])**2)<1e-2)*6.]) # add magnetic site
eb = embedding.Embedding(h,m=hv) # create an embedding object
ei = eb.get_energy_ingap_state() # get energy of the impurity state
(x,y,d) = eb.ldos(nsuper=19,energy=ei,delta=1e-3) # compute LDOSfrom pyqula import geometry
from pyqula import embedding
import numpy as np
g = geometry.square_lattice() # create geometry
for J in np.linspace(0.,4.0,100): # loop over exchange
h = g.get_hamiltonian() # get the Hamiltonian,spinless
h.add_onsite(3.0) # shift chemical potential
h.add_swave(0.2) # add s-wave superconductivity
hv = h.copy() # copy Hamiltonian to create a defective one
# add magnetic site
hv.add_exchange(lambda r: [0.,0.,(np.sum((r - g.r[0])**2)<1e-2)*J])
eb = embedding.Embedding(h,m=hv) # create an embedding object
energies = np.linspace(-0.4,0.4,100) # energies
d = [eb.dos(nsuper=2,delta=1e-2,energy=ei) for ei in energies] # compute DOS

































