Changelog#
All notable changes to this project will be documented in this file. The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[2.0.1] - 2026-01-29#
Fixed#
Fixed bug in
Wannier.projectwhere the projection procedure improperly reshaped spinful wavefunctions leading to an error when projecting onto trial orbitals.Fixed bug in
models.sshwhere the intercell hopping was not set between neighboring unit cells as intended.
[2.0.0] - 2025-11-11#
Fixed#
Fixed bug in
TBModel._shift_to_home()where only the last orbital was shifted. This affected theto_homeflag inchange_nonperiodic_vector()andmake_supercell().
Improved#
Vectorized code throughout using NumPy for substantial speed improvements
TBModelinitialization, Hamiltonian construction, and diagonalization orders of magnitude faster for large modelsWFArraystate storage and manipulation significantly accelerated for large k-meshesW90.model()construction from Wannier90 data significantly faster, allowing practical use with large first-principles models
Type hints added throughout the codebase for improved developer experience and IDE support
Modernized Sphinx-based documentation website, copying over the previous tutorials, and adding some new ones to cover new features
TBModel.visualize(): Enhanced 2D Visualization
Changed#
Restructured from single
pythtb.pyfile to organizedpythtb/package with separate purpose-specific modules:tbmodel.py: Tight-binding model class and methodswfarray.py: Wavefunction array class for storing and manipulating quantum statesw90.py: Wannier90 interfaceetc.
Migrated from
setup.pyto modernpyproject.tomlconfiguration as per PEP 518
Breaking Changes
Updated class and method names to follow PEP 8 conventions:
tb_model->TBModelwf_array->WFArrayw90->W90
TBModelInitialization ChangesReplaced
dim_r,dim_k,lat,orb, andperparameters with a singleLatticeinstanceReplaced
nspinparameter withspinfulboolean flag
WFArrayInitialization Changes:Replaced
mesh_arrparameter with aMeshinstanceReplaced
modelparameter with aLatticeinstanceRenamed
nsta_arrparameter to integernstatesfor clarity
TBModel.solve_ham()(replacessolve_one()andsolve_all())Changed eigenvalue/eigenvector indexing for vectorized workflows
Eigenvalues: shape
(nk, ..., nstate)(matrix elements last for NumPy compatibility)Eigenvectors for spinless (
nspin=1): shape(nk, ..., nstate, nstate)Eigenvectors for spinful (
nspin=2): shape(nk, ..., nstate, norb, 2)
W90.w90_bands_consistency()(deprecated and renamed tobands_w90())Returned energy array shape changed from
(band, kpts)to(kpts, band)Now consistent with eigenvalue shape from
TBModel.solve_ham()Aligns with NumPy convention of putting k-points in first axis
Renaming
TBModel.position_expectation()parameter renamingRenamed parameter
evectoevecsfor clarityRenamed parameter
dirtopos_dirto avoid conflict with built-in Python functiondir()
TBModel.position_matrix()parameter renamingRenamed parameter
evectoevecsfor clarityRenamed parameter
dirtopos_dirto avoid conflict with built-in Python functiondir()
TBModel.position_hwf()parameter renamingRenamed parameter
evectoevecsfor clarityRenamed parameter
dirtopos_dirto avoid conflict with built-in Python functiondir()
WFArray.berry_phase()parameter renamingdirrenamed toaxis_idxto avoid conflict with Python built-indir()occrenamed tostate_idxto emphasize that band indices need not be occupiedRemoved
"all"option; useNone(default) to include all states
WFArray.berry_flux()parameter renamingdirsrenamed toplanenow only accepts 2-element tuples defining planesoccrenamed tostate_idxto emphasize that band indices need not be occupied
WFArray.position_matrix()parameter renamingdirrenamed topos_dirto avoid conflict with built-in Python functiondir()occrenamed tostate_idxto emphasize that states need not be occupiedRemoved
"all"option; useNone(default) to include all states
WFArray.position_expectation()parameter renamingdirrenamed topos_dirto avoid conflict with built-in Python functiondir()occrenamed tostate_idxto emphasize that states need not be occupiedRemoved
"all"option; useNone(default) to include all states
WFArray.position_hwf()parameter renames:dirrenamed topos_dirto avoid conflict with built-in Python functiondir()occrenamed tostate_idxto emphasize that states need not be occupiedRemoved
"all"option; useNone(default) to include all states
WFArray.choose_states()parameter rename:subsetrenamed tostate_idxsfor clarity and consistency
WFArray.empty_like()parameter rename:nsta_arrrenamed tonstatesfor clarity and consistency
Added#
Published
pythtbpackage to conda-forge for easy installation viaconda install -c conda-forge pythtbOptional TensorFlow backend for linear algebra acceleration on compatible hardware (GPUs/TPUs) in
TBModelandWFArrayEnable by passing
use_tensorflow=Trueon compatible methods
Comprehensive unit tests added using
pytestto cover core functionalityNew examples and tutorials added to documentation website covering new features and workflows
New classes
Latticeclass that handles lattice geometry and reciprocal operations.Encapsulates lattice manipulation methods previously embedded in
TBModelUsed by
TBModelandWFArray
Meshclass that defines structured grids in k-space or parameter space.Supports arbitrary dimensions and mixed \((k, \lambda)\) meshes
Includes
Axishelper class for labeled mesh axesUsed by
WFArrayfor consistent data mapping
Wannierclass for constructing and analyzing Wannier functions fromWFArrayProjection onto trial orbitals
Iterative maximal localization/disentanglement
Visualization of centers, decay profiles, and spreads
New modules
pythtb.models: collection of common tight-binding modelsthat are importable using, e.g.,pythtb.io.w90: Wannier90 file parsing utilitiesread_hr(),read_centres()etc. for standalone Wannier90 file parsingSupports loading a full Wannier90 dataset for downstream
W90->TBModelprocessing
pythtb.io.qe: Quantum ESPRESSO file parsing utilitiesread_bands_qe()for readingprefix_bands.outbands.xoutput files
New functionality in TBModel
Added support for specifying symbolic strings and callables for parameter-dependent onsite energies and hoppings in parameterized tight-binding models in
TBModel.set_onsite()andTBModel.set_hop()This enables passing kwargs specifying parameter values as scalars or arrays to methods like
TBModel.hamiltonian()or any other method that uses the tight-binding Hamiltonian (e.g.,TBModel.velocity(),TBModel.berry_curvature(), etc.)
New methods in TBModel
Added
TBModel.__str__: Allows printing aTBModelinstance usingprint(TBModel), which printsTBModel.info()Added
TBModel.info(): Replacesdisplay()for printing model summaryAdded
TBModel.copy(): Creates a deep copy of theTBModelinstanceAdded
TBModel.get_lat_vecs(): Replacesget_lat()for clarityAdded
TBModel.get_orb_vecs(): Replacesget_orb()for clarityAdded boolean flag
cartesianto return orbital vectors in Cartesian coordinates (defaultFalse)
Added
TBModel.get_recip_lat(): Returns reciprocal lattice vectorsAdded
TBModel.add_orb(): Adds a single orbital to the modelAdded
TBModel.make_finite(): Convenience function for chainingcut_piece()along different directionsAdded
TBModel.solve_ham(): Replacessolve_one()andsolve_all()for a unified, vectorized diagonalization of Hamiltonians at multiple k-points and parameter valuesAdded
flatten_spin_axisflag to return spinful eigenvectors in flattened shape for easier processingAdded
use_tensorflowflag to enable optional TensorFlow backend accelerationAdded
paramskwargs to pass parameter values for parameterized models
Added
TBModel.clear_hoppings(): Removes all hopping terms from the modelAdded
TBModel.clear_onsite(): Resets all on-site energies to zeroAdded
TBModel.with_parameters(): Returns model at specific parameter values for parameterized modelsAdded
TBModel.set_parameters(): Resolves parameterized terms with scalar valuesAdded
TBModel.set_shell_hops(): Bulk setting of n’th nearest-neighbor hoppings for faster model constructionAdded
TBModel.nn_bonds(): Returns information about nearest-neighbor bonds in the model, useful for manually setting hoppings on shellsAdded
TBModel.hamiltonian(): constructs Hamiltonians for finite and periodic systemsAdded
TBModel.velocity(): computes velocity operator \(dH/dk\) in orbital basisAdded
TBModel.quantum_geometric_tensor(): quantum geometric tensor using Kubo formulaAdded
TBModel.quantum_metric(): quantum metric tensor from quantum geometric tensorAdded
TBModel.berry_curvature(): berry curvature from quantum geometric tensorAdded
TBModel.chern_number(): computes Chern number using Berry curvatureAdded
TBModel.axion_angle(): computes axion angle using 4-curvature integrationAdded
TBModel.local_chern_marker(): Bianco-Resta formula for real-space Chern markerAdded
TBModel.plot_bands(): built-in band structure plotting utility usingmatplotlibAdded
TBModel.visualize3d(): interactive 3D visualization for 3D models usingplotly
New attributes in TBModel
Added
TBModel.assume_position_operator_diagonal: attribute setter to control diagonal approximation for position operatorReplaces deprecated
ignore_position_operator_offdiagonal()method
Added
TBModel.lattice: read-only property returning associatedLatticeinstanceAdded
TBModel.nspin: read-only property returning spinful/spinless statusAdded
TBModel.periodic_dirs: read-only property returning list of periodic directionsAdded
TBModel.norb: read-only property returning number of orbitalsAdded
TBModel.nstate: read-only property returning number of statesAdded
TBModel.dim_r: read-only property returning real-space dimensionAdded
TBModel.dim_k: read-only property returning k-space dimensionAdded
TBModel.onsite: read-only property returning on-site energies as NumPy arrayAdded
TBModel.hoppings: read-only property returning hoppings as list of dictionariesAdded
TBModel.nhops: read-only property returning number of hopping termsAdded
TBModel.spinful: read-only property returning spinful/spinless statusAdded
TBModel.parameters: read-only property returning current parameter values for parameterized modelsAdded
TBModel.from_w90: read-only property returning whether model was constructed from Wannier90 dataAdded
TBModel.lat_vecs: read-only property returning lattice vectorsAdded
TBModel.orb_vecs: read-only property returning orbital position vectors in reduced coordinatesAdded
TBModel.cell_volume: read-only property returning unit cell volumeAdded
TBModel.recip_lat_vecs: read-only property returning reciprocal lattice vectorsAdded
TBModel.recip_volume: read-only property returning reciprocal unit cell volume
New methods in WFArray
Added
WFArray.set_states(): Sets wavefunction data from NumPy arrayAdded
WFArray.remove_states(): Removes specified states from theWFArrayAdded
WFArray.overlap_matrix(): Computes overlap matrix of the states in theWFArraywith their nearest neighbors on aMesh.Added
WFArray.links(): Computes the unitary part of the overlap between states and their nearest neighbors in each mesh directionAdded
WFArray.berry_connection(): Computes Berry connection from the links between nearest neighbor states in the meshAdded
WFArray.wilson_loop(): Static method that computes the Wilson loop unitary matrix for a loop of statesAdded
WFArray.berry_curvature(): Computes dimensionful Berry curvature by divinding Berry flux by mesh cell area/volumeAdded
WFArray.chern_number(): Returns the Chern number for a given plane in the parameter meshAdded
WFArray.solve_model(): PopulatesWFArraywith energy eigenstates from a givenTBModelalong theMeshReplaces deprecated
solve_on_grid()andsolve_on_one_point()methods
Added
WFArray.projectors(): Returns band projectors and optionally their complements as NumPy arraysAdded
WFArray.states(): Returns states as a NumPy array, optionally the full Bloch states including phase factorsAdded
WFArray.roll_states_with_pbc(): Rolls states along a given mesh axis with periodic boundary conditions.Added
WFArray.copy(): Creates a deep copy of theWFArrayinstanceAdded parameter
non_abeliantoWFArray.berry_flux()to compute non-Abelian Berry flux for a manifold of states
New attributes in WFArray
Added
WFArray.model: read-only property returning associatedTBModelinstance (if provided withsolve_model())Added
WFArray.mesh: read-only property returning associatedMeshinstanceAdded
WFArray.lattice: read-only property returning associatedLatticeinstanceAdded
WFArray.filled: read-only property returning whether states have been populatedAdded
WFArray.wfs: read-only property returning wavefunction data as NumPy arrayAdded
WFArray.energies: read-only property returning energies as NumPy array (if populated viasolve_model())Added
WFArray.u_nk: read-only property returning cell-periodic parts of Bloch states as NumPy array (if populated viaset_states()orsolve_model()and system is periodic)Added
WFArray.psi_nk: read-only property returning full Bloch states including phase factors as NumPy array (if populated viaset_states()orsolve_model()and system is periodic)Added
WFArray.Mmn: read-only property returning overlap matrices between states and their nearest neighbors on the mesh (if computed viaoverlap_matrix())Added
WFArray.hamiltonian: read-only property returning Hamiltonian matrices at each mesh point (if populated viasolve_model())Added
WFArray.shape: read-only property returning shape of the stored wavefunction arrayAdded
WFArray.nstates: read-only property returning number of states storedAdded
WFArray.spinful: read-only property returning spinful/spinless statusAdded
WFArray.nspins: read-only property returning number of spin components (1 or 2)Added
WFArray.norb: read-only property returning number of orbitals in the underlyingLatticeAdded
WFArray.shape_mesh: number of points along each mesh axisAdded
WFArray.dim_k: read-only property returning k-space dimension of the underlyingLatticeAdded
WFArray.dim_lambda: read-only property returning number of swept parameters in theMeshAdded
WFArray.naxes: read-only property returning total number of mesh axesAdded
WFArray.k_points: read-only property returning k-points stored in theMeshein reduced coordinates as NumPy arrayAdded
WFArray.param_points: read-only property returning parameter points stored in theMeshas NumPy array
New methods in W90
Added
W90.bands_w90(): Renaming ofw90_bands_consistency()for consistencyReturns energy array with shape
(kpts, band)consistent withTBModel.solve_ham()
Added
W90.bands_qe(): Reads band structure from Quantum ESPRESSOprefix_bands.outoutput files
Deprecated#
The following methods are deprecated but still functional with backward compatibility wrappers. These will be removed in a future release.
tb_modelclass name remains available as alias forTBModelTBModel.display()(deprecated) renamed toTBModel.info()to prevent confusion with visualization. UseTBModel.info()orprint(my_model)insteadTBModel.get_lat()(deprecated) renamed toTBModel.get_lat_vecs()for clarityTBModel.get_orb()(deprecated) renamed toTBModel.get_orb_vecs()for clarityTBModel.set_onsite()andTBModel.set_hop()"reset"mode (deprecated): use"set"insteadTBModel.solve_one()(deprecated) replaced byTBModel.solve_ham()TBModel.solve_all()(deprecated) replaced byTBModel.solve_ham()WFArray.impose_pbc()(deprecated). Periodic boundary conditions are handled automatically byMesh. Will raiseNotImplementedErrorif called.WFArray.impose_loop()(deprecated). Periodic boundary conditions are handled automatically byMesh. Will raiseNotImplementedErrorif called.WFArray.solve_on_grid()(deprecated). UseWFArray.solve_model()instead. Will raiseNotImplementedErrorif called.WFArray.solve_on_one_point()(deprecated). UseWFArray.solve_model()instead. Will raiseNotImplementedErrorif called.W90.w90_bands_consistency()(deprecated) renamed toW90.bands_w90()for clarity
Removed#
Following SPEC-0 (Scientific Python Ecosystem Coordination)
Dropped support for Python < 3.12
Dropped support for NumPy < 2.0
Dropped support for Matplotlib < 3.9
Expired deprecations
Removed parameter
to_home_supress_warninginTBModel.change_nonperiodic_vector()andTBModel.make_supercell()(deprecated since v1.8.0). Default behavior is to only shift orbitals along periodic directions, with a warning sent to the logger if an orbital is outside the home unit cell in a non-periodic direction.
The following functionality has been removed. Users should update their code accordingly.
Removed
TBModel.reduce_dim(). This was used fix a particular k-component.TBModelis not intended to handle such constraints directly. This should be handled externally.Removed
TBModel.ignore_position_operator_offdiagonal(). Functionality replaced byTBModel.assume_position_operator_diagonalattribute setter.Removed flag
individual_phasesinWFArray.berry_flux(). The returned Berry fluxes are always computed with individual phases now.
[1.8.0] - 2022-09-20#
Changed#
Updated class
wf_arrayto make it easier to store states which are not Bloch-like eigenstates.Fixed various small issues.
Added#
Added new functionality to
wf_arraysolve_on_one_pointchoose_statesempty_like
Added function change_nonperiodic_vector and changed the way
to_homeparameter works.
Removed#
Removed some functions that were kept for backwards compatibility
berry_curvk_pathtbmodelset_sitesadd_hop.
[1.7.2] - 2017-08-01#
Changed#
Display function now prints hopping distances
Added#
Added support for deleting orbitals
[1.7.1] - 2016-12-22#
Added#
Added support for python 3.x in addition to 2.x
[1.7.0] - 2016-06-07#
Changed#
Cleaned up period boundary condition in the
wf_arrayclass
Fixed#
Fixed bug with reduce_dim. Some hopping terms were not correctly cast as onsite terms.
Fixed bug in
impose_pbcwhendim_kis less thandim_r.
Added#
Added interface with Wannier90 package
Added support for making bandstructure plots along multi-segment paths in the Brillouin zone
Added support for hybrid Wannier functions.
Berry curvature in dimensions higher than 2.
[1.6.2] - 2013-02-25#
Added#
Added support for spinors.
Added make_supercell method with which one can make arbitrary super-cells of the model and also generate slabs with arbitrary orientation.
[1.6.1] - 2012-11-15#
For the most part, the code should be backward-compatible with version 1.5.
Changed#
Renamed the code package (previously PyTB) to avoid confusion with other acronyms.
Streamlined the code to be more consistent in naming conventions.
Made some improvements and extensions to the calculation of Berry phases and curvatures.
Changed the way in which the
impose_pbcfunction is used.tb_mode,set_onsite,set_hopare named differently but have aliases to names from version 1.5
Added#
Built a proper python distribution including documentation and an improved website.
Added a more powerful method of setting onsite and hopping parameters.
Added some additional examples.
Removed#
Removed
add_wffunction fromwf_arrayobject and replaced it with[]operator, and