bztetra 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ libtetra_original/
2
+ .internal/
3
+
4
+ # Python
5
+ __pycache__/
6
+ *.py[cod]
7
+ *.so
8
+ .python-version
9
+ .pkg-venv/
10
+ .venv/
11
+ venv/
12
+
13
+ # Packaging
14
+ build/
15
+ dist/
16
+ *.egg-info/
17
+ site/
18
+
19
+ # Tool caches
20
+ .coverage
21
+ .hypothesis/
22
+ .mypy_cache/
23
+ .nox/
24
+ .pytest_cache/
25
+ .ruff_cache/
26
+ htmlcov/
bztetra-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bztetra contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
bztetra-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,94 @@
1
+ Metadata-Version: 2.4
2
+ Name: bztetra
3
+ Version: 0.1.0
4
+ Summary: Python and Numba port of libtetrabz-style tetrahedron integration routines.
5
+ Project-URL: Homepage, https://github.com/skilledwolf/bztetra
6
+ Project-URL: Documentation, https://skilledwolf.github.io/bztetra/
7
+ Project-URL: Repository, https://github.com/skilledwolf/bztetra
8
+ Project-URL: Issues, https://github.com/skilledwolf/bztetra/issues
9
+ Author: bztetra contributors
10
+ License: MIT License
11
+
12
+ Copyright (c) 2026 bztetra contributors
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Keywords: brillouin-zone,density-of-states,electronic-structure,numba,tetrahedron-method
33
+ Classifier: Development Status :: 3 - Alpha
34
+ Classifier: Intended Audience :: Science/Research
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: OS Independent
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Topic :: Scientific/Engineering :: Physics
41
+ Requires-Python: >=3.11
42
+ Requires-Dist: numba>=0.61
43
+ Requires-Dist: numpy>=2.0
44
+ Provides-Extra: dev
45
+ Requires-Dist: matplotlib>=3.9; extra == 'dev'
46
+ Requires-Dist: pytest>=8.0; extra == 'dev'
47
+ Requires-Dist: ruff>=0.11; extra == 'dev'
48
+ Provides-Extra: docs
49
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
50
+ Requires-Dist: mkdocs>=1.6; extra == 'docs'
51
+ Requires-Dist: mkdocstrings[python]>=0.28; extra == 'docs'
52
+ Provides-Extra: plot
53
+ Requires-Dist: matplotlib>=3.9; extra == 'plot'
54
+ Description-Content-Type: text/markdown
55
+
56
+ # bztetra
57
+
58
+ `bztetra` is a Python + Numba package for tetrahedron integration on regular
59
+ k-grids.
60
+
61
+ This is the public `0.x` preview series. Validate important production results
62
+ against the original
63
+ [`libtetrabz`](https://github.com/mitsuaki1987/libtetrabz) implementation or
64
+ the parity guidance in the
65
+ [validation docs](https://skilledwolf.github.io/bztetra/validation/).
66
+
67
+ ## Install
68
+
69
+ ```bash
70
+ pip install bztetra
71
+ ```
72
+
73
+ Plot-backed examples use Matplotlib:
74
+
75
+ ```bash
76
+ pip install "bztetra[plot]"
77
+ ```
78
+
79
+ ## What It Provides
80
+
81
+ - Occupation, DOS, and integrated DOS weights on regular 3D k-grids.
82
+ - Static overlap, nesting, and polarization weights.
83
+ - Real- and complex-frequency Lindhard-style response functions.
84
+ - A separate `bztetra.twod` namespace for genuine 2D triangle-method problems.
85
+
86
+ ## Documentation
87
+
88
+ - Documentation: <https://skilledwolf.github.io/bztetra/>
89
+ - Quickstart: <https://skilledwolf.github.io/bztetra/quickstart/>
90
+ - Physics guide: <https://skilledwolf.github.io/bztetra/physics/>
91
+ - Examples: <https://skilledwolf.github.io/bztetra/examples/>
92
+ - Validation: <https://skilledwolf.github.io/bztetra/validation/>
93
+ - Repository: <https://github.com/skilledwolf/bztetra>
94
+ - Issues: <https://github.com/skilledwolf/bztetra/issues>
@@ -0,0 +1,176 @@
1
+ # bztetra
2
+
3
+ `bztetra` is a Python + Numba package for single-process tetrahedron
4
+ integration on regular k-grids.
5
+
6
+ It is aimed at users who already have band energies on a regular mesh and want
7
+ k-resolved weights for occupations, DOS, and Lindhard-style response functions
8
+ without going through the legacy `libtetrabz` wrapper.
9
+
10
+ The top-level `bztetra` API remains strictly 3D. A parallel 2D linear
11
+ triangle-method implementation now lives under `bztetra.twod` for the
12
+ occupation, DOS, and response families. Do not fake a flat third axis with
13
+ `nz=1`; see
14
+ [docs/two_dimensional_plan.md](docs/two_dimensional_plan.md).
15
+
16
+ > [!IMPORTANT]
17
+ > `bztetra` is a public preview in the `0.x` series. The package is usable, but
18
+ > the API and validation envelope may still evolve before `1.0`. Validate
19
+ > important production results against the original
20
+ > [`libtetrabz`](https://github.com/mitsuaki1987/libtetrabz) implementation or
21
+ > run the parity checks described in [docs/validation.md](docs/validation.md).
22
+
23
+ - NumPy arrays in, NumPy arrays out.
24
+ - Optimized and legacy-linear tetrahedron schemes.
25
+ - Validation against legacy shell outputs, the legacy Python wrapper, and
26
+ analytic free-electron reference cases.
27
+
28
+ ## Install
29
+
30
+ Requires Python 3.11+.
31
+
32
+ ```bash
33
+ pip install bztetra
34
+ ```
35
+
36
+ Project docs live at [skilledwolf.github.io/bztetra](https://skilledwolf.github.io/bztetra/).
37
+
38
+ Plotting examples use Matplotlib:
39
+
40
+ ```bash
41
+ pip install "bztetra[plot]"
42
+ ```
43
+
44
+ From a source checkout:
45
+
46
+ ```bash
47
+ pip install .
48
+ ```
49
+
50
+ ## First Calculation
51
+
52
+ ```python
53
+ import numpy as np
54
+ from bztetra import density_of_states_weights
55
+
56
+ bvec = 2.0 * np.pi * np.eye(3)
57
+ nx = ny = nz = 16
58
+ energies = np.linspace(-1.0, 1.0, 200, dtype=np.float64)
59
+
60
+ eigenvalues = np.empty((nx, ny, nz, 1), dtype=np.float64)
61
+ for ix in range(nx):
62
+ for iy in range(ny):
63
+ for iz in range(nz):
64
+ kfrac = np.array([ix / nx, iy / ny, iz / nz], dtype=np.float64) - 0.5
65
+ kcart = bvec @ kfrac
66
+ eigenvalues[ix, iy, iz, 0] = 0.5 * np.dot(kcart, kcart)
67
+
68
+ weights = density_of_states_weights(bvec, eigenvalues, energies)
69
+ total_dos = weights.sum(axis=(1, 2, 3, 4)) * np.linalg.det(bvec)
70
+ ```
71
+
72
+ `weights` has shape `(nenergy, nx, ny, nz, nbands)`. For band-resolved DOS,
73
+ sum only over the k-grid axes.
74
+
75
+ ## Core Conventions
76
+
77
+ - `reciprocal_vectors` is a `(3, 3)` matrix with reciprocal basis vectors in
78
+ columns.
79
+ - `eigenvalues` always has shape `(nx, ny, nz, nbands)`.
80
+ - `weight_grid_shape` is optional. Leave it unset unless you intentionally want
81
+ weights interpolated onto another regular grid.
82
+ - Response outputs use the last axes `(target_band, source_band)`.
83
+ - To integrate over the Brillouin zone, sum over the explicit k-grid axes and
84
+ multiply by `np.linalg.det(bvec)` for a right-handed basis.
85
+
86
+ ## Choose The Right Routine
87
+
88
+ | Need | Call |
89
+ | --- | --- |
90
+ | Occupations at a known Fermi level | `occupation_weights` |
91
+ | Fermi level search plus occupations | `solve_fermi_energy` |
92
+ | DOS or integrated DOS on a sampled energy grid | `density_of_states_weights`, `integrated_density_of_states_weights` |
93
+ | Static overlap, nesting, or polarization between two band manifolds | `phase_space_overlap_weights`, `nesting_function_weights`, `static_polarization_weights` |
94
+ | Repeated real- or complex-frequency response sweeps | `prepare_response_evaluator`, then `fermi_golden_rule_weights` or `complex_frequency_polarization_weights` |
95
+
96
+ See [docs/physics.md](docs/physics.md) for the key formulas and
97
+ [docs/examples.md](docs/examples.md) for worked examples with output plots.
98
+
99
+ ## 2D Triangle Method
100
+
101
+ For genuinely 2D problems, switch namespaces and use `bztetra.twod`.
102
+ `bztetra.twod` keeps the same physics-facing routine names for occupations,
103
+ DOS, overlap, Lindhard-style polarization, and real- or complex-frequency
104
+ response, but on `(nx, ny, nbands)` arrays with Brillouin-zone **area**
105
+ normalization and the linear triangle method.
106
+
107
+ Start with [docs/two_dimensional_plan.md](docs/two_dimensional_plan.md) for
108
+ the current 2D surface, then run one of the plot-backed example scripts:
109
+
110
+ - [examples/plot_twod_square_lattice_dos.py](examples/plot_twod_square_lattice_dos.py)
111
+ - [examples/plot_twod_phase_space_overlap.py](examples/plot_twod_phase_space_overlap.py)
112
+ - [examples/plot_twod_lindhard.py](examples/plot_twod_lindhard.py)
113
+
114
+ ## Examples
115
+
116
+ - [docs/quickstart.md](docs/quickstart.md): the shortest path from eigenvalues
117
+ on a regular grid to a correct `bztetra` call.
118
+ - [examples/plot_tight_binding_dos.py](examples/plot_tight_binding_dos.py):
119
+ cubic tight-binding DOS figure.
120
+ - [examples/review_occupancy.py](examples/review_occupancy.py): occupation
121
+ weights and Fermi-level search on a small reference problem.
122
+ - [examples/plot_lindhard.py](examples/plot_lindhard.py): static Lindhard
123
+ response figure.
124
+ - [examples/plot_twod_square_lattice_dos.py](examples/plot_twod_square_lattice_dos.py):
125
+ 2D square-lattice DOS and integrated DOS via `bztetra.twod`.
126
+ - [examples/plot_twod_phase_space_overlap.py](examples/plot_twod_phase_space_overlap.py):
127
+ 2D free-electron `dblstep` phase-space overlap with the exact circular-segment curve.
128
+ - [examples/plot_twod_lindhard.py](examples/plot_twod_lindhard.py):
129
+ 2D free-electron static Lindhard plateau and Kohn cusp.
130
+
131
+ ## Validation
132
+
133
+ `bztetra` is checked against tracked legacy shell/example fixtures, optional
134
+ direct parity with the legacy `libtetrabz` Python wrapper, and analytic
135
+ reference cases. See
136
+ [docs/validation.md](docs/validation.md) for the exact coverage and
137
+ reproduction commands.
138
+
139
+ ## Acknowledgement
140
+
141
+ `bztetra` is a clean-room Python + Numba port informed by the original
142
+ [`libtetrabz`](https://github.com/mitsuaki1987/libtetrabz) project by Mitsuaki
143
+ Kawamura and collaborators. If `bztetra` is useful in research, users should
144
+ also acknowledge the original method and implementation:
145
+
146
+ - M. Kawamura, Y. Gohda, and S. Tsuneyuki, "Improved tetrahedron method for the
147
+ Brillouin-zone integration applicable to response functions,"
148
+ [Phys. Rev. B 89, 094515 (2014)](https://journals.aps.org/prb/abstract/10.1103/PhysRevB.89.094515)
149
+ - Original repository:
150
+ [github.com/mitsuaki1987/libtetrabz](https://github.com/mitsuaki1987/libtetrabz)
151
+
152
+ ## Development
153
+
154
+ ```bash
155
+ python3 -m venv .venv
156
+ . .venv/bin/activate
157
+ pip install -e '.[dev]'
158
+ python -m pytest -q
159
+ ```
160
+
161
+ For local docs work:
162
+
163
+ ```bash
164
+ pip install -e '.[dev,docs]'
165
+ mkdocs serve
166
+ ```
167
+
168
+ Benchmark entry points live under `benchmarks/`:
169
+
170
+ ```bash
171
+ PYTHONPATH=src python benchmarks/benchmark_hotpaths.py
172
+ PYTHONPATH=src python benchmarks/benchmark_twod_hotpaths.py --profile --profile-task complex_frequency_polarization_weights
173
+ PYTHONPATH=src python benchmarks/benchmark_twod_response_multiband.py --profile --profile-task all
174
+ ```
175
+
176
+ Package versions are derived from git tags at build and install time.
@@ -0,0 +1,39 @@
1
+ # bztetra
2
+
3
+ `bztetra` is a Python + Numba package for tetrahedron integration on regular
4
+ k-grids.
5
+
6
+ This is the public `0.x` preview series. Validate important production results
7
+ against the original
8
+ [`libtetrabz`](https://github.com/mitsuaki1987/libtetrabz) implementation or
9
+ the parity guidance in the
10
+ [validation docs](https://skilledwolf.github.io/bztetra/validation/).
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pip install bztetra
16
+ ```
17
+
18
+ Plot-backed examples use Matplotlib:
19
+
20
+ ```bash
21
+ pip install "bztetra[plot]"
22
+ ```
23
+
24
+ ## What It Provides
25
+
26
+ - Occupation, DOS, and integrated DOS weights on regular 3D k-grids.
27
+ - Static overlap, nesting, and polarization weights.
28
+ - Real- and complex-frequency Lindhard-style response functions.
29
+ - A separate `bztetra.twod` namespace for genuine 2D triangle-method problems.
30
+
31
+ ## Documentation
32
+
33
+ - Documentation: <https://skilledwolf.github.io/bztetra/>
34
+ - Quickstart: <https://skilledwolf.github.io/bztetra/quickstart/>
35
+ - Physics guide: <https://skilledwolf.github.io/bztetra/physics/>
36
+ - Examples: <https://skilledwolf.github.io/bztetra/examples/>
37
+ - Validation: <https://skilledwolf.github.io/bztetra/validation/>
38
+ - Repository: <https://github.com/skilledwolf/bztetra>
39
+ - Issues: <https://github.com/skilledwolf/bztetra/issues>
@@ -0,0 +1,82 @@
1
+ [build-system]
2
+ requires = ["hatch-vcs>=0.4", "hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "bztetra"
7
+ dynamic = ["version"]
8
+ description = "Python and Numba port of libtetrabz-style tetrahedron integration routines."
9
+ readme = {file = "README.pypi.md", content-type = "text/markdown"}
10
+ requires-python = ">=3.11"
11
+ license = {file = "LICENSE"}
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ {name = "bztetra contributors"},
15
+ ]
16
+ keywords = [
17
+ "brillouin-zone",
18
+ "density-of-states",
19
+ "electronic-structure",
20
+ "numba",
21
+ "tetrahedron-method",
22
+ ]
23
+ classifiers = [
24
+ "Development Status :: 3 - Alpha",
25
+ "Intended Audience :: Science/Research",
26
+ "License :: OSI Approved :: MIT License",
27
+ "Operating System :: OS Independent",
28
+ "Programming Language :: Python :: 3",
29
+ "Programming Language :: Python :: 3.11",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Topic :: Scientific/Engineering :: Physics",
32
+ ]
33
+ dependencies = [
34
+ "numba>=0.61",
35
+ "numpy>=2.0",
36
+ ]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/skilledwolf/bztetra"
40
+ Documentation = "https://skilledwolf.github.io/bztetra/"
41
+ Repository = "https://github.com/skilledwolf/bztetra"
42
+ Issues = "https://github.com/skilledwolf/bztetra/issues"
43
+
44
+ [project.optional-dependencies]
45
+ plot = [
46
+ "matplotlib>=3.9",
47
+ ]
48
+ docs = [
49
+ "mkdocs>=1.6",
50
+ "mkdocs-material>=9.5",
51
+ "mkdocstrings[python]>=0.28",
52
+ ]
53
+ dev = [
54
+ "matplotlib>=3.9",
55
+ "pytest>=8.0",
56
+ "ruff>=0.11",
57
+ ]
58
+
59
+ [tool.hatch.build.targets.wheel]
60
+ packages = ["src/bztetra"]
61
+
62
+ [tool.hatch.build.targets.sdist]
63
+ include = [
64
+ "/LICENSE",
65
+ "/README.md",
66
+ "/README.pypi.md",
67
+ "/pyproject.toml",
68
+ "/src",
69
+ ]
70
+
71
+ [tool.hatch.version]
72
+ source = "vcs"
73
+
74
+ [tool.hatch.version.raw-options]
75
+ fallback_version = "0.0.0"
76
+
77
+ [tool.pytest.ini_options]
78
+ testpaths = ["tests"]
79
+
80
+ [tool.ruff]
81
+ line-length = 100
82
+ target-version = "py311"
@@ -0,0 +1,56 @@
1
+ """Modern 3D Python port of the legacy libtetrabz tetrahedron routines."""
2
+
3
+ from importlib.metadata import PackageNotFoundError
4
+ from importlib.metadata import version as package_version
5
+
6
+ from .dos import density_of_states_weights
7
+ from .dos import integrated_density_of_states_weights
8
+ from .occupancy import FermiEnergySolution
9
+ from .response import complex_frequency_polarization_weights
10
+ from .response import fermi_golden_rule_weights
11
+ from .response import nesting_function_weights
12
+ from .response import phase_space_overlap_weights
13
+ from .response import prepare_response_evaluator
14
+ from .response import PreparedResponseEvaluator
15
+ from .response import static_polarization_weights
16
+ from .formulas import SimplexCut
17
+ from .geometry import IntegrationMesh
18
+ from .geometry import build_integration_mesh
19
+ from .occupancy import occupation_weights
20
+ from .occupancy import solve_fermi_energy
21
+ from .formulas import simplex_affine_coefficients
22
+ from .formulas import small_tetrahedron_cut
23
+ from .geometry import tetrahedron_offsets
24
+ from .geometry import tetrahedron_weight_matrix
25
+ from .formulas import triangle_cut
26
+ from .geometry import trilinear_interpolation_indices
27
+
28
+ try:
29
+ __version__ = package_version("bztetra")
30
+ except PackageNotFoundError:
31
+ __version__ = "0+unknown"
32
+
33
+ __all__ = [
34
+ "complex_frequency_polarization_weights",
35
+ "density_of_states_weights",
36
+ "FermiEnergySolution",
37
+ "fermi_golden_rule_weights",
38
+ "integrated_density_of_states_weights",
39
+ "IntegrationMesh",
40
+ "nesting_function_weights",
41
+ "occupation_weights",
42
+ "phase_space_overlap_weights",
43
+ "PreparedResponseEvaluator",
44
+ "prepare_response_evaluator",
45
+ "SimplexCut",
46
+ "solve_fermi_energy",
47
+ "static_polarization_weights",
48
+ "__version__",
49
+ "build_integration_mesh",
50
+ "simplex_affine_coefficients",
51
+ "small_tetrahedron_cut",
52
+ "tetrahedron_offsets",
53
+ "tetrahedron_weight_matrix",
54
+ "triangle_cut",
55
+ "trilinear_interpolation_indices",
56
+ ]