Rustb
A comprehensive Rust library for tight-binding model calculations in condensed matter physics.
Overview
Rustb computes electronic band structures, density of states, transport properties (anomalous Hall, spin Hall, nonlinear conductivities), topological invariants (Chern numbers, Wilson loops, Wannier centers), and surface states via iterative Green's functions. It supports both analytical tight-binding models and Wannier90 Hamiltonians, as well as Slater-Koster parameterized models.
Quick Start
Add to Cargo.toml:
[]
= "0.6"
= "0.17"
= "0.4"
= "0.0.39" # for plotting
Minimal Graphene Example
use *;
use *;
use *;
use Complex;
use PI;
Adding Spin-Orbit Coupling (Kane-Mele Model)
// Spinful model: each orbital is doubled (↑, ↓)
let mut model = tb_model.unwrap;
// On-site staggered potential
model.set_onsite;
// Spin-orbit coupling: i·λ_SO·ν_ij·σ_z (ν_ij = ±1 for clockwise/counterclockwise)
let soc = new;
model.add_hop; // + for A→A
model.add_hop; // - for B→B
model.add_hop;
model.add_hop;
model.add_hop;
model.add_hop;
Features
Band Structure & Density of States
// Band structure along a k-path
let = model.k_path.unwrap;
let eval = model.solve_band_all_parallel; // parallelized over k-points
model.show_band.unwrap;
// Density of states with Gaussian broadening
let kmesh = arr1;
let = model.dos.unwrap;
model.show_dos;
Topological Properties
// Chern number via Berry curvature integration
let kmesh = arr1;
let = model.chern_number.unwrap;
println!;
// Wilson loop / Wannier charge centers
let = model.wilson_loop.unwrap;
model.show_wcc;
// Berry curvature at each k-point
let berry = model.berry_curvature.unwrap;
Transport Properties
// Anomalous Hall conductivity σ_xy(μ, T)
let mu = linspace;
let sigma = model.Hall_conductivity.unwrap;
// Nonlinear Hall conductivity (Berry curvature dipole)
let dir1 = arr1;
let dir2 = arr1;
let dir3 = arr1;
let sigma_nl = model.Nonlinear_Hall_conductivity_Intrinsic.unwrap;
Surface States (Iterative Green's Function)
// Semi-infinite surface along direction 0, surface normal direction 1
let mut surf = new.unwrap;
// Surface spectral function A(k_∥, ω)
let k_para = arr1; // momentum parallel to surface
let omega = linspace;
let = surf.spectral_function.unwrap;
Magnetic Field (Peierls Substitution)
// Uniform magnetic field out-of-plane, supercell expansion [m, n], N_ϕ flux quanta
let model_b = model.add_magnetic_field.unwrap;
// Hofstadter butterfly: scan flux per primitive cell
let phi_list = linspace;
let spectrum = model.hofstadter_butterfly.unwrap;
Band Unfolding (for supercells)
// Unfold supercell band structure back to primitive cell BZ
let U = arr2;
let super_model = model.make_supercell.unwrap;
let A_unfolded = super_model.unfold.unwrap;
draw_heatmap;
Supercell & Geometry
// Create a supercell: new_lat = U · old_lat
let U = arr2;
let super_model = model.make_supercell.unwrap;
// Cut a slab/nanoribbon: remove bonds crossing the cut plane
let plane_normal = arr1; // cut along y direction
let slab = model.cut_piece.unwrap;
Slater-Koster Models
use *;
// Define SK parameters (two-center integrals)
let params = new
.with_onsite
.with_onsite
.with_hopping
.with_hopping
.with_hopping
.with_hopping;
// Build atoms
let atoms = vec!;
// Create SK model and convert to TB model
let sk = new;
let model = sk.to_tb_model.unwrap;
Wannier90 Interface
// Read a Wannier90 tight-binding model. Provide the directory path and seedname.
// The function automatically reads:
// seedname.win — lattice vectors, spin, projections, atom positions
// seedname_hr.dat — Hamiltonian matrix elements H(R)
// seedname_centres.xyz — orbital positions (recommended, set write_xyz=true)
// seedname_r.dat — position matrix elements r(R) (optional, set write_rmn=true)
// seedname_wsvec.dat — Wannier subspace vectors (recommended for better symmetry)
let model = from_hr.unwrap;
// Export a model in Wannier90 hr.dat format
model.output_hr.unwrap;
Model Construction API
Creating a Model
// Spinless model, dim=2 or 3
let model = tb_model?;
// Spinful model
let model = tb_model?;
// With custom orbital projections
let model = tb_model?;
Adding Hopping & On-site Terms
// add_hop: hermitian conjugate at -R is added automatically
model.add_hop;
// set_hop: manually set without automatic hermitian conjugate
model.set_hop;
// Bulk-set all orbitals with same value
model.add_onsite; // adds to existing
model.set_onsite; // overwrites
Where spin_dir controls the spin structure:
SpinDirection::None→ identity in spin spaceSpinDirection::x / y / z→ Pauli matrix σ_x / σ_y / σ_z
Gauge Choice
// Atomic gauge: orbital positions included in Bloch phase
let = model.gen_v;
// Lattice gauge: only R vectors in Bloch phase
let = model.gen_v;
BLAS/LAPACK Backend
For optimal performance, enable a BLAS backend:
[]
= { = "0.6", = ["intel-mkl-static"] }
# or: "intel-mkl-system", "openblas-static", "openblas-system", "netlib-static", "netlib-system"
Without features, ndarray-linalg uses system BLAS (may be slow). Intel MKL provides the best performance on x86_64.
Physical Constants
use *;
// ħ, e, k_B, μ_B, Φ_0, etc.
Constants in SI-based eV·Å units:
HBAR_EV_S= 6.582119569e-16 eV·sHBAR2_OVER_2M_EV_A2= 3.81 eV·Å²MU_B_EV_PER_T= 5.7883818060e-5 eV/TFLUX_QUANTUM_T_M2= 4.135667696e-15 T·m²K_B_EV_PER_K= 8.617333262145e-5 eV/K
Plotting
The library uses gnuplot with pdfcairo terminal. Install gnuplot:
# Ubuntu/Debian
# macOS
Built-in plotting functions:
model.show_band(&path, &label, nk, dir)— band structuremodel.show_dos(&energy, &dos, dir)— density of statesmodel.show_surf_state(&surf_green, &omega, &k_para, dir)— surface spectral functionmodel.show_wcc(&wcc, dir)— Wilson loop spectrumdraw_heatmap(&data, filename)— 2D heatmap
License
MIT OR Apache-2.0