2.12 — Wavefunction Density (stb-wfdensity)¶
Note. The stored runs use the nc-sr-05 sulfur pseudopotential, which 2.1.0 refuses, and have not been regenerated yet. A new run uses nc-sr-04, so its numbers can differ from this page.
What this tool does¶
stb-wfdensity computes the real-space probability density |psi(r)|^2
of one chosen electronic eigenstate — band N at k-point K — from a
SIESTA .WFSX file, and writes it as a Gaussian .cube file (the primary
output, for VESTA/VMD/Avogadro) plus an optional 2D-slice or 1D-profile
gnuplot/matplotlib preview. Useful as a diagnostic: "what does the CBM
look like at this k-point", "is this defect state localized on one atom
or spread across the lattice" — not a physical ground-state observable
by itself (see the theory section below for why).
Why this matters (a bit of theory)¶
From LCAO coefficients to a real-space value¶
SIESTA is an LCAO code: every state is a linear combination of localized atomic orbitals,
psi_n(k, r) = sum_mu c_mu,n(k) * phi_mu(r)
stb-fatbands uses this same expansion to compute how much weight each
orbital contributes (a projection). stb-wfdensity instead evaluates the
actual value of psi at every point of a real-space grid — summing every
orbital's own numerical radial function, phase and all, at each grid
point — then takes |psi(r)|^2 to get a real, plottable 3D density for
that one state.
Why only a real .fdf (+ .ion/.ion.xml) works — never .XV/.HSX¶
Evaluating phi_mu(r) at a real-space point needs the orbital's actual
radial shape (a numerical function with a finite cutoff radius) — not
just bookkeeping about how many orbitals exist. Verified live on this
example's own structure:
Geometry from siesta.XV : 4 orbitals total (1 per atom), cutoff radius = -1 (no shape at all)
Geometry from calc.fdf : 64 real orbitals, cutoff radius = 3.61 Ang
A bare .XV (or .HSX) carries no radial-function information at all —
sisl fills in one placeholder "orbital" per atom just so the bookkeeping
doesn't crash, with a cutoff radius of -1 (not "small", literally
undefined). Only a .fdf, read together with the .ion/.ion.xml
files SIESTA itself wrote for that basis, carries the real numerical
radial functions phi_mu(r) needs. This is a hard physical/data
limitation, not an arbitrary restriction — --geometry-file (or
--label's auto-detected <label>.fdf) is not optional.
The normalization check: a built-in quality control¶
A single-particle wavefunction is normalized to exactly one electron:
integral |psi(r)|^2 dV = 1
stb-wfdensity computes this directly from the evaluated grid and reports
it in [3] WAVEFUNCTION DENSITY, warning if it deviates from 1 by more
than 5%. This is a genuinely useful diagnostic, not decoration — verified
live on this example's own VBM state:
--spacing 0.3 (default) : integral = 0.939287 -- [WARNING] more than 5% off
--spacing 0.2 : integral = 1.009170 -- [OK]
The coarser grid was clipping the tails of the real orbitals (each with a
genuine several-Angstrom cutoff radius) badly enough to lose ~6% of the
normalization — the exact failure mode the warning exists to catch,
demonstrated live in grid-resolution/ below.
Not a physical observable by itself¶
|psi_n(k, r)|^2 for one single band at one single k-point is not,
by itself, a measurable ground-state quantity — the real physical charge
density sums |psi_n(k, r)|^2 over every occupied band and k-point,
weighted by the Brillouin-zone integration weights (that's exactly what
stb-density's .RHO-based total charge density already is). This tool
is a diagnostic/visualization aid for one state at a time — e.g. "is
this defect level localized", "what does the band edge look like at
Gamma" — never a substitute for the real total density.
Selecting the state: --band N, or vbm/cbm with a Fermi energy¶
--band vbm/cbm searches the entire k-mesh in the .WFSX for the
global valence-band-maximum/conduction-band-minimum state, exactly the
same search stb-fatbands/stb-bands use. This needs a Fermi energy,
resolved in priority order: --fermi (explicit value) > --bands-file (a
real .bands file) > --fermi-file (an explicit .out log) > an
auto-detected .out in the current directory — not assumed to be
named after the label (see the next section for exactly why that
decoupling matters in practice).
A real bug this example's own fixture caught: --label + --geometry-file¶
This folder's calc.fdf/structure.fdf/siesta.bands.WFSX/calc.out
are a real SIESTA run with SystemLabel siesta -- but the actual input
file is named calc.fdf, and there is no siesta.fdf anywhere (a
completely ordinary, common mismatch for anything generated by this
suite's own workflow tools). --label siesta alone used to fail outright
("No usable geometry found") because --label and --geometry-file
together were rejected as mutually exclusive — forcing --wfsx to be
given explicitly too, just to change the geometry source. Fixed: --label
now auto-detects the .WFSX as before, and --geometry-file (given
alongside it) simply overrides the geometry source instead of being
rejected. There are actually three .fdf files in this exact folder
(calc.fdf, structure.fdf, and kpath_bs.fdf, a k-path-only fragment
kept here specifically to show this) -- none named siesta.fdf -- so
--geometry-file still has to be given explicitly; only the "can't
combine with --label" restriction was the actual bug.
Another real bug this example's own fixture caught: where the slice cuts¶
--mode-equivalent slice output (--save-gnuplot/--view without
--profile) used to always cut at the geometric center of the cell
along --axis — with no way to change it. This structure's 4 atoms sit
at fractional z = 0, 0, 0.066, 0.934 (clustered near the cell
boundary), with the real vacuum in the middle of the cell — so the
old geometric-center default landed squarely in that vacuum, showing
essentially nothing. Fixed: the default is now the plane where the
planar-averaged |psi|^2 is largest (verified live: index 0, right at
the atoms, versus the old geometric center at roughly the halfway point
which sits deep in the vacuum) — --pos (Angstrom along --axis, same
name/semantics as stb-density's own flag) overrides it manually. See
slice-position/ below for both, side by side, on the same real grid.
Grid resolution: --spacing vs. --shape¶
--spacing (Angstrom per voxel, default 0.3) is the usual control;
--shape NX NY NZ sets exact voxel counts instead, mutually exclusive
with --spacing. A coarser grid is faster but risks the normalization
warning above; there's no universal "correct" value, only "checked, via
the normalization warning, and tightened if it fires."
Spin channels and what's not modeled¶
--spin selects which channel to evaluate (0/1, must be 0 for a
non-spin-polarized calculation) — this example's own calculation is
genuinely spin-polarized (Spin polarized in calc.fdf, nspin=2 in
the .WFSX). Only the first spinor component is evaluated at all times;
non-collinear/SOC wavefunctions are not fully represented.
The report: console output, --save-gnuplot, --view¶
Every run prints a numbered report, the same [0]...[6] style every
newer tool in this suite uses:
| Section | Content |
|---|---|
[0] RUN METADATA |
input files, band/Fermi selection, grid spec, slice/profile mode + position, output dir, active options |
[1] INPUT DATA |
orbital count, k-points in the .WFSX, spin channels |
[2] STATE SELECTION |
k-index/vector, spin, band, eigenvalue -- and the VBM/CBM search details if used |
[3] WAVEFUNCTION DENSITY |
grid shape, the normalization check (and its [OK]/[WARNING]) |
[4] OUTPUT DATA & PLOTS |
the .cube file (always), and whether the slice/profile .dat/.gplot were written |
[5] REFERENCES |
writes stb_wfdensity_references.bib (SIESTA) |
[6] SUMMARY & FILES |
status and a recap of every file written |
- Report — always saved to
stb_wfdensity_report.txtin the current folder (_1,_2, ... when that name is taken); there is no option for it. --save-gnuplot— write the slice/profile.dat+ a real.gplotscript together. Off by default — this tool used to write the.datfile unconditionally (opted out via a now-removed--cube-only) but never actually wrote a.gplotscript at all, despite its own docstring calling this "gnuplot output". The.cubefile itself is always written regardless (the tool's primary output).--view— an interactive matplotlib preview (2D slice or 1D profile, matching--profile). Off by default — this tool previously had no matplotlib option at all.
When you'd reach for it¶
- Checking whether a defect/impurity state is localized on one site or delocalized across the lattice.
- Visualizing what the VBM or CBM actually looks like at a specific k-point (Gamma, or the true band-edge k-point from a VBM/CBM search).
- A quick, real-space sanity check on one state before trusting a more
abstract projection (
stb-fatbands) or a derived quantity.
Two ways to run it¶
A — direct CLI:
stb-wfdensity --label siesta --geometry-file calc.fdf --band vbm --fermi-file calc.out --spacing 0.2
B — interactive stb-suite menu:
$ stb-suite
Select an option (0-7, or a tool code like 5.1.2): 2.12
example_2.12.sh proves this directly at the end. The menu asks
for the label and the .fdf structure path separately (a real fix —
it used to only ask for one label and assume <label>.fdf named
everything), and for VBM/CBM offers a small Fermi-source submenu (a
direct value, a .bands file, an explicit .out log, or auto-detect —
matching the CLI's own priority order).
Files in this folder¶
siesta.bands.WFSX/siesta.XV/calc.fdf/structure.fdf/calc.out— a real, spin-polarized SIESTA band-structure calculation of a CrS monolayer (fetched viastb-fetchfrom the twodmatpedia OPTIMADE database, id2dm-2617— the same structure already used inexamples/2.7-stb-workfunction/,examples/2.9-stb-xrd/andexamples/2.11-stm/).SystemLabel siesta, but nosiesta.fdf— this exact mismatch is what caught the--label+--geometry-filebug above.kpath_bs.fdf— a genuine k-path-only fdf fragment from the same real run, kept here specifically to show that this directory really does have multiple.fdffiles, none matching the label — it doesn't even parse as a geometry at all (noLatticeConstantblock), which is fine: it's never touched unless you explicitly pointed--geometry-fileat it by mistake.Cr.ion/Cr.ion.xml,S.ion/S.ion.xml— the real numerical basis orbitals for this calculation, needed alongsidecalc.fdf/structure.fdffor real-space wavefunction evaluation (see the theory section above).example_2.12.sh— the guided walkthrough (not an automated test — seetest/2-analysis/12-wfdensity/test.shfor that, which uses a separate, non-spin-polarized bulk Sn3O4 fixture)..gitignore— excludesoutput/and every file this tool itself generates on a run.
Running the walkthrough¶
cd examples/2.12-wfdensity
./example_2.12.sh
It pauses between sections ([Press Enter to continue]) and always starts
by wiping its own output/. Self-contained cases are generated:
| Folder | What it shows |
|---|---|
basic-run/ |
A plain --k-index/--band run, the .cube file, and the normalization check |
vbm-cbm/ |
--band vbm/cbm searching the whole k-mesh, Fermi energy from --fermi-file |
slice-position/ |
The real bug: default (auto-detected |psi|^2 peak, right at the atoms) vs. --pos at the old geometric center (near-empty vacuum) |
grid-resolution/ |
--spacing 0.3 (normalization warning fires) vs. 0.2 (passes) -- the same real state |
full-report/ |
--save-gnuplot, the report, stb_wfdensity_references.bib, a real gnuplot render |
Try it yourself¶
# Your own finished SIESTA calculation (needs a real .fdf + .ion/.ion.xml files)
stb-wfdensity --label my_calc --k-index 0 --band 1 --save-gnuplot
# The VBM at whatever k-point it actually sits at, reading Fermi from the .out log
stb-wfdensity --label my_calc --band vbm --fermi-file my_calc.out --view
# A specific k-point by vector instead of index, at a finer grid
stb-wfdensity --label my_calc --k-point 0.0 0.0 0.0 --band 5 --spacing 0.2
Flag reference¶
| Flag | Meaning |
|---|---|
--label |
SIESTA label; auto-detects .WFSX + (unless --geometry-file overrides it) <label>.fdf. |
--wfsx/--geometry-file |
Explicit .WFSX/.fdf paths. |
--k-index/--k-point |
Select k by index (default 0) or by vector. |
--spin |
Spin channel (0/1, default 0). |
--band |
Band number (1-based), or vbm/cbm. |
--fermi/--bands-file/--fermi-file |
Fermi energy sources for --band vbm/cbm, in priority order (plus auto-detected .out). |
--gap-tol |
VBM/CBM classification tolerance, eV (default 0.01). |
--spacing/--shape |
Grid resolution (Ang/voxel) or exact voxel counts. |
--axis |
Axis for the optional slice/profile (default 2). |
--profile |
1D planar-averaged profile instead of a 2D slice. |
--pos |
Slice position, Ang along --axis (default: auto-detected |psi|^2 peak). |
-o/--output-dir |
Where all generated files (and stb_wfdensity_references.bib) land. |
--save-gnuplot |
Also write the slice/profile .dat/.gplot. |
--view |
Show an interactive matplotlib preview. |
What's next¶
core/siesta_wfsx.py's .WFSX/geometry loading (load_parent, mode
"orbitals_required") is the same machinery stb-sts/stb-coop use for
a full-BZ-mesh .WFSX, and shares its overall shape with
stb-fatbands's own "hamiltonian_preferred" mode (which additionally
needs a .HSX for overlap-weighted orbital projections — this tool never
touches .HSX at all). stb-density covers the real, physical ground
-state charge density (.RHO, summed over every occupied state/k) that
this tool's own single-eigenstate density is explicitly not a substitute
for.
Example folder (input fixtures and guided script) on GitHub: examples/2.12-wfdensity/ · guided script example_2.12.sh
Command reference: stb-wfdensity