unizt 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.
unizt-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dr. Sabir Makhlouf (sabir.makhlouf@gmail.com)
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.
unizt-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.4
2
+ Name: unizt
3
+ Version: 0.1.0
4
+ Summary: Unified Post-Processing Tool for True Thermoelectric Figure of Merit ZT, Lattice Thermal Conductivity, and Device Efficiency from First-Principles DFT & BoltzTraP2 Calculations
5
+ Author-email: "Dr. Sabir Makhlouf" <sabir.makhlouf@gmail.com>
6
+ License: MIT
7
+ Keywords: thermoelectrics,figure-of-merit,ZT,BoltzTraP2,DFT,lattice-thermal-conductivity,deformation-potential-theory,materials-science
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Scientific/Engineering :: Physics
17
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: numpy>=1.21
22
+ Requires-Dist: scipy>=1.8
23
+ Requires-Dist: matplotlib>=3.5
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0; extra == "dev"
26
+ Requires-Dist: build>=0.10; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # UniZT
30
+
31
+ **Unified Post-Processing Tool for True Thermoelectric Figure of Merit $ZT$, Lattice Thermal Conductivity, and Device Efficiency from First-Principles DFT & BoltzTraP2 Calculations.**
32
+
33
+ Developed by **Dr. Sabir Makhlouf** (`sabir.makhlouf@gmail.com`)
34
+
35
+ ---
36
+
37
+ ## Features
38
+
39
+ - **Elastic & Acoustic Engine (`unizt.core.elastic`, `unizt.core.validator`)**
40
+ - Born mechanical stability verification via stiffness tensor positive-definiteness.
41
+ - Voigt–Reuss–Hill (VRH) bulk ($B$), shear ($G$), Young's ($E$) moduli, and Poisson's ratio ($\nu$).
42
+ - Longitudinal ($v_l$), transverse ($v_t$), and mean ($v_m$) sound velocities, acoustic Debye temperature ($\theta_D$), and Belomestnykh–Leineweber acoustic Grüneisen parameter ($\gamma$).
43
+ - **Lattice Thermal Conductivity (`unizt.core.kappa_l`)**
44
+ - Slack's anharmonic Umklapp equation for $\kappa_L(T)$.
45
+ - Cahill–Pohl amorphous-limit minimum thermal conductivity $\kappa_{\min}(T)$.
46
+ - Custom/experimental $\kappa_L(T)$ override from CSV (`temperature_K,kappa_L_W_m_K`) with linear or log–log interpolation.
47
+ - **Carrier Relaxation Time (`unizt.core.relaxation`)**
48
+ - Bardeen–Shockley 3D Deformation Potential Theory ($\tau_{\mathrm{DPT}}(T) \propto T^{-3/2}$).
49
+ - Constant ($\tau_0$) and flexible power-law ($\tau_0 (T / T_0)^p$) sensitivity modes.
50
+ - **True $ZT(T, n)$ & Device Conversion Efficiency (`unizt.core.zt`, `unizt.core.engineering`)**
51
+ - Combines BoltzTraP2 transport coefficients with $\tau(T)$ and $\kappa_L(T)$ to compute Power Factor $\mathrm{PF} = S^2 \sigma$, $\kappa_{\mathrm{tot}}$, and $ZT(T, n)$.
52
+ - Separates $n$-type ($n < 0$) and $p$-type ($n > 0$) regimes and extracts optimal doping $n_{\mathrm{opt}}(T)$ and peak $ZT_{\max}(T)$.
53
+ - Kim et al. (PNAS 2015) engineering figure of merit $ZT_{\mathrm{eng}}$ and leg conversion efficiency $\eta_{\max}$ with automatic Carnot bound verification ($\eta_{\max} \le 1 - T_c / T_h$).
54
+ - **Lightweight Parsers & Extensible Registry (`unizt.parsers`)**
55
+ - Pure stdlib + NumPy parsers for BoltzTraP2/1 `*.trace`, arbitrary whitespace/CSV files (`--cols`), and 6×6 elastic tensors from VASP `OUTCAR`, WIEN2k `elast`/`IRelast`, Quantum ESPRESSO `thermo_pw`, and JSON.
56
+ - **Publication Outputs (`unizt.plotting`, `unizt.cli`)**
57
+ - 300 DPI journal-ready PNG figures, CSV summaries, and `booktabs` LaTeX tables (`zt_results.tex`).
58
+
59
+ ---
60
+
61
+ ## Installation
62
+
63
+ ```bash
64
+ pip install -e ".[dev]"
65
+ ```
66
+
67
+ Or standard installation:
68
+
69
+ ```bash
70
+ pip install .
71
+ ```
72
+
73
+ ---
74
+
75
+ ## CLI Quickstart
76
+
77
+ ```bash
78
+ # Print academic attribution and BibTeX citation
79
+ unizt --cite
80
+
81
+ # Full post-processing with BoltzTraP2 trace, VASP elastic tensor, DPT + Slack, and 300 DPI plots
82
+ unizt \
83
+ --trace case.trace \
84
+ --code boltztrap2 \
85
+ --elastic OUTCAR \
86
+ --elastic-format vasp \
87
+ --density 7699 \
88
+ --m-avg 89.54 \
89
+ --n-atoms 3 \
90
+ --tau-mode dpt \
91
+ --m-eff 0.45 \
92
+ --e1 14.0 \
93
+ --kappa-mode slack \
94
+ --tc 300 \
95
+ --outdir results \
96
+ --plot
97
+
98
+ # Using a generic CSV file with explicit column mapping and JSON configuration
99
+ unizt \
100
+ --trace transport.csv \
101
+ --code generic \
102
+ --cols "T,n,S,sigma_tau,kappa_e_tau" \
103
+ --config params.json \
104
+ --plot
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Paper Benchmark Pipeline
110
+
111
+ Run the automated zero-recalculation benchmark across $\mathrm{Bi_2Te_3}$, $\mathrm{PbTe}$, $\mathrm{ZrNiSn}$, $\mathrm{Mg_2Si}$, and $\mathrm{SnSe}$:
112
+
113
+ ```bash
114
+ python scripts/run_paper_benchmark.py
115
+ ```
116
+
117
+ Outputs are generated in `paper_outputs/` (`provenance.json`, `table_benchmark.csv`, `table_benchmark.tex`, and 300 DPI figures).
118
+
119
+ ---
120
+
121
+ ## License
122
+
123
+ MIT License — Copyright (c) 2026 Dr. Sabir Makhlouf (`sabir.makhlouf@gmail.com`). See [LICENSE](LICENSE).
124
+
125
+ ## Citation
126
+
127
+ If you use UniZT in your research, please cite:
128
+
129
+ ```bibtex
130
+ @software{makhlouf2026unizt,
131
+ author = {Makhlouf, Sabir},
132
+ title = {{UniZT}: A Unified Post-Processing Tool for True Thermoelectric
133
+ Figure of Merit and Device Efficiency from First-Principles Calculations},
134
+ year = {2026},
135
+ version = {0.1.0},
136
+ license = {MIT},
137
+ email = {sabir.makhlouf@gmail.com}
138
+ }
139
+ ```
unizt-0.1.0/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # UniZT
2
+
3
+ **Unified Post-Processing Tool for True Thermoelectric Figure of Merit $ZT$, Lattice Thermal Conductivity, and Device Efficiency from First-Principles DFT & BoltzTraP2 Calculations.**
4
+
5
+ Developed by **Dr. Sabir Makhlouf** (`sabir.makhlouf@gmail.com`)
6
+
7
+ ---
8
+
9
+ ## Features
10
+
11
+ - **Elastic & Acoustic Engine (`unizt.core.elastic`, `unizt.core.validator`)**
12
+ - Born mechanical stability verification via stiffness tensor positive-definiteness.
13
+ - Voigt–Reuss–Hill (VRH) bulk ($B$), shear ($G$), Young's ($E$) moduli, and Poisson's ratio ($\nu$).
14
+ - Longitudinal ($v_l$), transverse ($v_t$), and mean ($v_m$) sound velocities, acoustic Debye temperature ($\theta_D$), and Belomestnykh–Leineweber acoustic Grüneisen parameter ($\gamma$).
15
+ - **Lattice Thermal Conductivity (`unizt.core.kappa_l`)**
16
+ - Slack's anharmonic Umklapp equation for $\kappa_L(T)$.
17
+ - Cahill–Pohl amorphous-limit minimum thermal conductivity $\kappa_{\min}(T)$.
18
+ - Custom/experimental $\kappa_L(T)$ override from CSV (`temperature_K,kappa_L_W_m_K`) with linear or log–log interpolation.
19
+ - **Carrier Relaxation Time (`unizt.core.relaxation`)**
20
+ - Bardeen–Shockley 3D Deformation Potential Theory ($\tau_{\mathrm{DPT}}(T) \propto T^{-3/2}$).
21
+ - Constant ($\tau_0$) and flexible power-law ($\tau_0 (T / T_0)^p$) sensitivity modes.
22
+ - **True $ZT(T, n)$ & Device Conversion Efficiency (`unizt.core.zt`, `unizt.core.engineering`)**
23
+ - Combines BoltzTraP2 transport coefficients with $\tau(T)$ and $\kappa_L(T)$ to compute Power Factor $\mathrm{PF} = S^2 \sigma$, $\kappa_{\mathrm{tot}}$, and $ZT(T, n)$.
24
+ - Separates $n$-type ($n < 0$) and $p$-type ($n > 0$) regimes and extracts optimal doping $n_{\mathrm{opt}}(T)$ and peak $ZT_{\max}(T)$.
25
+ - Kim et al. (PNAS 2015) engineering figure of merit $ZT_{\mathrm{eng}}$ and leg conversion efficiency $\eta_{\max}$ with automatic Carnot bound verification ($\eta_{\max} \le 1 - T_c / T_h$).
26
+ - **Lightweight Parsers & Extensible Registry (`unizt.parsers`)**
27
+ - Pure stdlib + NumPy parsers for BoltzTraP2/1 `*.trace`, arbitrary whitespace/CSV files (`--cols`), and 6×6 elastic tensors from VASP `OUTCAR`, WIEN2k `elast`/`IRelast`, Quantum ESPRESSO `thermo_pw`, and JSON.
28
+ - **Publication Outputs (`unizt.plotting`, `unizt.cli`)**
29
+ - 300 DPI journal-ready PNG figures, CSV summaries, and `booktabs` LaTeX tables (`zt_results.tex`).
30
+
31
+ ---
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install -e ".[dev]"
37
+ ```
38
+
39
+ Or standard installation:
40
+
41
+ ```bash
42
+ pip install .
43
+ ```
44
+
45
+ ---
46
+
47
+ ## CLI Quickstart
48
+
49
+ ```bash
50
+ # Print academic attribution and BibTeX citation
51
+ unizt --cite
52
+
53
+ # Full post-processing with BoltzTraP2 trace, VASP elastic tensor, DPT + Slack, and 300 DPI plots
54
+ unizt \
55
+ --trace case.trace \
56
+ --code boltztrap2 \
57
+ --elastic OUTCAR \
58
+ --elastic-format vasp \
59
+ --density 7699 \
60
+ --m-avg 89.54 \
61
+ --n-atoms 3 \
62
+ --tau-mode dpt \
63
+ --m-eff 0.45 \
64
+ --e1 14.0 \
65
+ --kappa-mode slack \
66
+ --tc 300 \
67
+ --outdir results \
68
+ --plot
69
+
70
+ # Using a generic CSV file with explicit column mapping and JSON configuration
71
+ unizt \
72
+ --trace transport.csv \
73
+ --code generic \
74
+ --cols "T,n,S,sigma_tau,kappa_e_tau" \
75
+ --config params.json \
76
+ --plot
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Paper Benchmark Pipeline
82
+
83
+ Run the automated zero-recalculation benchmark across $\mathrm{Bi_2Te_3}$, $\mathrm{PbTe}$, $\mathrm{ZrNiSn}$, $\mathrm{Mg_2Si}$, and $\mathrm{SnSe}$:
84
+
85
+ ```bash
86
+ python scripts/run_paper_benchmark.py
87
+ ```
88
+
89
+ Outputs are generated in `paper_outputs/` (`provenance.json`, `table_benchmark.csv`, `table_benchmark.tex`, and 300 DPI figures).
90
+
91
+ ---
92
+
93
+ ## License
94
+
95
+ MIT License — Copyright (c) 2026 Dr. Sabir Makhlouf (`sabir.makhlouf@gmail.com`). See [LICENSE](LICENSE).
96
+
97
+ ## Citation
98
+
99
+ If you use UniZT in your research, please cite:
100
+
101
+ ```bibtex
102
+ @software{makhlouf2026unizt,
103
+ author = {Makhlouf, Sabir},
104
+ title = {{UniZT}: A Unified Post-Processing Tool for True Thermoelectric
105
+ Figure of Merit and Device Efficiency from First-Principles Calculations},
106
+ year = {2026},
107
+ version = {0.1.0},
108
+ license = {MIT},
109
+ email = {sabir.makhlouf@gmail.com}
110
+ }
111
+ ```
@@ -0,0 +1,58 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "unizt"
7
+ version = "0.1.0"
8
+ description = "Unified Post-Processing Tool for True Thermoelectric Figure of Merit ZT, Lattice Thermal Conductivity, and Device Efficiency from First-Principles DFT & BoltzTraP2 Calculations"
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ requires-python = ">=3.9"
12
+ authors = [
13
+ { name = "Dr. Sabir Makhlouf", email = "sabir.makhlouf@gmail.com" },
14
+ ]
15
+ keywords = [
16
+ "thermoelectrics",
17
+ "figure-of-merit",
18
+ "ZT",
19
+ "BoltzTraP2",
20
+ "DFT",
21
+ "lattice-thermal-conductivity",
22
+ "deformation-potential-theory",
23
+ "materials-science",
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 4 - Beta",
27
+ "Intended Audience :: Science/Research",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.9",
31
+ "Programming Language :: Python :: 3.10",
32
+ "Programming Language :: Python :: 3.11",
33
+ "Programming Language :: Python :: 3.12",
34
+ "Topic :: Scientific/Engineering :: Physics",
35
+ "Topic :: Scientific/Engineering :: Chemistry",
36
+ ]
37
+ dependencies = [
38
+ "numpy>=1.21",
39
+ "scipy>=1.8",
40
+ "matplotlib>=3.5",
41
+ ]
42
+
43
+ [project.optional-dependencies]
44
+ dev = [
45
+ "pytest>=7.0",
46
+ "build>=0.10",
47
+ ]
48
+
49
+ [project.scripts]
50
+ unizt = "unizt.cli:main"
51
+
52
+ [tool.setuptools.packages.find]
53
+ where = ["."]
54
+ include = ["unizt*"]
55
+
56
+ [tool.pytest.ini_options]
57
+ testpaths = ["tests"]
58
+ addopts = "-v"
unizt-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,355 @@
1
+ """Comprehensive unit and integration benchmark suite for UniZT."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import subprocess
7
+ import sys
8
+ from pathlib import Path
9
+
10
+ import numpy as np
11
+ import pytest
12
+
13
+ from unizt import __author__, __email__, __version__
14
+ from unizt.core.elastic import (
15
+ compute_elastic_properties,
16
+ isotropic_tensor_from_moduli,
17
+ )
18
+ from unizt.core.engineering import compute_engineering_zt
19
+ from unizt.core.kappa_l import (
20
+ cahill_pohl_kappa_min,
21
+ compute_kappa_l,
22
+ slack_kappa_l,
23
+ )
24
+ from unizt.core.relaxation import (
25
+ compute_relaxation_time,
26
+ tau_constant,
27
+ tau_dpt,
28
+ tau_power_law,
29
+ )
30
+ from unizt.core.validator import (
31
+ BornStabilityError,
32
+ ValidationError,
33
+ validate_elastic_tensor,
34
+ validate_transport_data,
35
+ )
36
+ from unizt.core.zt import compute_zt
37
+ from unizt.parsers.boltztrap2 import parse_boltztrap2_trace
38
+ from unizt.parsers.elastic_parser import parse_elastic_tensor
39
+ from unizt.parsers.generic import parse_generic_transport
40
+ from unizt.parsers.registry import PARSER_REGISTRY, get_parser, register_parser
41
+
42
+
43
+ def test_isotropic_vrh_moduli_and_acoustic_properties():
44
+ """Exact isotropic tensor must satisfy B_V=B_R=B_H, G_V=G_R=G_H, exact E & nu."""
45
+ B_true = 100.0
46
+ G_true = 45.0
47
+ rho = 5000.0
48
+ C_iso = isotropic_tensor_from_moduli(B_true, G_true)
49
+
50
+ props = compute_elastic_properties(C_iso, density=rho, m_avg=50.0)
51
+ E_true = (9.0 * B_true * G_true) / (3.0 * B_true + G_true)
52
+ nu_true = (3.0 * B_true - 2.0 * G_true) / (2.0 * (3.0 * B_true + G_true))
53
+ gamma_true = 1.5 * (1.0 + nu_true) / (2.0 - 3.0 * nu_true)
54
+
55
+ assert props.B_V == pytest.approx(B_true, rel=1e-10)
56
+ assert props.B_R == pytest.approx(B_true, rel=1e-10)
57
+ assert props.B_H == pytest.approx(B_true, rel=1e-10)
58
+ assert props.G_V == pytest.approx(G_true, rel=1e-10)
59
+ assert props.G_R == pytest.approx(G_true, rel=1e-10)
60
+ assert props.G_H == pytest.approx(G_true, rel=1e-10)
61
+ assert props.E == pytest.approx(E_true, rel=1e-10)
62
+ assert props.nu == pytest.approx(nu_true, rel=1e-10)
63
+ assert props.gamma == pytest.approx(gamma_true, rel=1e-10)
64
+ assert props.anisotropy_index == pytest.approx(0.0, abs=1e-10)
65
+ assert props.v_l > props.v_m > props.v_t > 0.0
66
+ assert props.theta_D > 0.0
67
+
68
+
69
+ def test_born_stability_and_tensor_validation():
70
+ """Stable tensors pass; unstable, asymmetric, or malformed tensors fail."""
71
+ C_stable = isotropic_tensor_from_moduli(80.0, 35.0)
72
+ validated = validate_elastic_tensor(C_stable)
73
+ assert validated.shape == (6, 6)
74
+
75
+ # Unstable cubic crystal: C11 < C12 -> negative shear eigenvalue (C11 - C12)
76
+ C_unstable = np.array(
77
+ [
78
+ [50.0, 70.0, 70.0, 0.0, 0.0, 0.0],
79
+ [70.0, 50.0, 70.0, 0.0, 0.0, 0.0],
80
+ [70.0, 70.0, 50.0, 0.0, 0.0, 0.0],
81
+ [0.0, 0.0, 0.0, 30.0, 0.0, 0.0],
82
+ [0.0, 0.0, 0.0, 0.0, 30.0, 0.0],
83
+ [0.0, 0.0, 0.0, 0.0, 0.0, 30.0],
84
+ ]
85
+ )
86
+ with pytest.raises(BornStabilityError):
87
+ validate_elastic_tensor(C_unstable)
88
+
89
+ # Asymmetric tensor
90
+ C_asym = C_stable.copy()
91
+ C_asym[0, 1] += 10.0
92
+ with pytest.raises(ValidationError):
93
+ validate_elastic_tensor(C_asym)
94
+
95
+ # Wrong shape
96
+ with pytest.raises(ValidationError):
97
+ validate_elastic_tensor(np.eye(3))
98
+
99
+
100
+ def test_validate_transport_data():
101
+ """Validator filters NaN/Inf rows, rejects T <= 0, and converts cm^-3 -> m^-3."""
102
+ raw = {
103
+ "T": [300.0, 400.0, 500.0],
104
+ "n": [-1e19, np.nan, 2e19],
105
+ "S": [-200e-6, -210e-6, np.inf],
106
+ "sigma_tau": [1e19, 1e19, 1e19],
107
+ "kappa_e_tau": [2.0, 2.0, 2.0],
108
+ "n_unit": "cm^-3",
109
+ }
110
+ with pytest.warns(UserWarning, match="Removed 2"):
111
+ cleaned = validate_transport_data(raw)
112
+ assert len(cleaned["T"]) == 1
113
+ assert cleaned["n"][0] == pytest.approx(-1e25)
114
+ assert cleaned["n_unit"] == "m^-3"
115
+
116
+ with pytest.raises(ValidationError):
117
+ validate_transport_data(
118
+ {
119
+ "T": [-50.0, 300.0],
120
+ "n": [-1e25, 1e25],
121
+ "S": [-2e-4, 2e-4],
122
+ "sigma_tau": [1e19, 1e19],
123
+ "kappa_e_tau": [2.0, 2.0],
124
+ }
125
+ )
126
+
127
+
128
+ def test_slack_scaling_cahill_positivity_and_custom_csv(tmp_path: Path):
129
+ """Slack kappa_L obeys 1/T scaling, Cahill kappa_min > 0, custom CSV works."""
130
+ T = np.array([300.0, 600.0, 900.0])
131
+ k_slack = slack_kappa_l(
132
+ T,
133
+ M_avg=90.0,
134
+ vol_atom=2.0e-29,
135
+ theta_D=350.0,
136
+ gamma=1.5,
137
+ n_atoms=3,
138
+ )
139
+ assert k_slack[0] > 0.0
140
+ assert k_slack[1] == pytest.approx(0.5 * k_slack[0], rel=1e-12)
141
+ assert k_slack[2] == pytest.approx((1.0 / 3.0) * k_slack[0], rel=1e-12)
142
+
143
+ k_min = cahill_pohl_kappa_min(T, v_l=5000.0, v_t=3000.0, vol_atom=2.0e-29)
144
+ assert np.all(k_min > 0.0)
145
+ assert k_min[2] >= k_min[0]
146
+
147
+ csv_file = tmp_path / "kappa_exp.csv"
148
+ csv_file.write_text(
149
+ "temperature_K,kappa_L_W_m_K\n300,4.0\n600,2.0\n",
150
+ encoding="utf-8",
151
+ )
152
+ k_custom = compute_kappa_l(450.0, mode="custom", custom_csv=csv_file, interpolation="linear")
153
+ assert k_custom == pytest.approx(3.0, rel=1e-12)
154
+ k_custom_log = compute_kappa_l(
155
+ np.sqrt(300.0 * 600.0), mode="custom", custom_csv=csv_file, interpolation="loglog"
156
+ )
157
+ assert k_custom_log == pytest.approx(np.sqrt(8.0), rel=1e-10)
158
+
159
+
160
+ def test_dpt_relaxation_scaling_and_modes():
161
+ """Bardeen-Shockley tau_dpt(T) follows exact T^(-3/2) scaling."""
162
+ T = np.array([300.0, 1200.0])
163
+ taus = tau_dpt(T, m_eff=0.35, E1=12.0, C_3d=150.0)
164
+ assert taus[0] > 0.0
165
+ assert taus[1] == pytest.approx(taus[0] * (4.0 ** -1.5), rel=1e-12)
166
+
167
+ assert tau_constant(300.0, tau_0=2e-14) == pytest.approx(2e-14)
168
+ assert tau_power_law(600.0, tau_0=1e-14, T_0=300.0, exponent=-1.0) == pytest.approx(0.5e-14)
169
+ assert compute_relaxation_time(300.0, mode="constant", tau_const=3e-14) == pytest.approx(3e-14)
170
+
171
+
172
+ def test_zt_identity_and_regime_extraction():
173
+ """ZT matches S^2 * sigma * T / (kappa_e + kappa_L) and extracts n/p peaks."""
174
+ T = np.array([300.0, 300.0, 300.0, 300.0, 600.0, 600.0, 600.0, 600.0])
175
+ n = np.array([-2e25, -1e25, 1e25, 3e25, -2e25, -1e25, 1e25, 3e25])
176
+ S = np.array([-220e-6, -150e-6, 180e-6, 240e-6, -260e-6, -190e-6, 210e-6, 270e-6])
177
+ sigma_tau = np.array([1.2e19, 0.8e19, 1.0e19, 1.5e19, 1.0e19, 0.7e19, 0.9e19, 1.3e19])
178
+ kappa_e_tau = np.array([0.8e14, 0.5e14, 0.6e14, 1.0e14, 1.4e14, 0.9e14, 1.1e14, 1.6e14])
179
+
180
+ tau_val = 1.5e-14
181
+ kappa_l_val = 2.0
182
+
183
+ res = compute_zt(
184
+ {"T": T, "n": n, "S": S, "sigma_tau": sigma_tau, "kappa_e_tau": kappa_e_tau},
185
+ tau=tau_val,
186
+ kappa_l=kappa_l_val,
187
+ )
188
+
189
+ sigma_exp = sigma_tau * tau_val
190
+ ke_exp = kappa_e_tau * tau_val
191
+ zt_exp = (S ** 2) * sigma_exp * T / (ke_exp + kappa_l_val)
192
+ pf_exp = (S ** 2) * sigma_exp * 1e3
193
+
194
+ np.testing.assert_allclose(res.zt, zt_exp, rtol=1e-12)
195
+ np.testing.assert_allclose(res.pf, pf_exp, rtol=1e-12)
196
+ assert res.n_type["n_opt"][0] < 0.0
197
+ assert res.p_type["n_opt"][0] > 0.0
198
+ assert res.n_type["zt_max"][1] == pytest.approx(np.max(zt_exp[4:6]))
199
+ assert res.p_type["zt_max"][1] == pytest.approx(np.max(zt_exp[6:8]))
200
+
201
+
202
+ def test_engineering_zt_and_carnot_bound():
203
+ """Kim et al. ZT_eng & eta_max match Ioffe limit for constant properties and obey Carnot."""
204
+ T = np.linspace(300.0, 900.0, 61)
205
+ S = np.full_like(T, 210e-6)
206
+ sigma = np.full_like(T, 1.1e5)
207
+ kappa = np.full_like(T, 1.8)
208
+
209
+ eng = compute_engineering_zt(T, S, sigma, kappa, T_c=300.0, T_h=900.0)
210
+ Z_const = (210e-6 ** 2) * 1.1e5 / 1.8
211
+ T_avg = 0.5 * (300.0 + 900.0)
212
+ eta_carnot = 1.0 - 300.0 / 900.0
213
+ eta_ioffe = eta_carnot * (np.sqrt(1.0 + Z_const * T_avg) - 1.0) / (
214
+ np.sqrt(1.0 + Z_const * T_avg) + 300.0 / 900.0
215
+ )
216
+
217
+ assert eng.ZT_eng == pytest.approx(Z_const * 600.0, rel=1e-6)
218
+ assert eng.eta_max == pytest.approx(eta_ioffe, rel=1e-6)
219
+ assert eng.eta_max < eng.eta_carnot
220
+
221
+
222
+ def test_parsers_and_registry(tmp_path: Path):
223
+ """Test boltztrap2, generic, elastic parsers (JSON/VASP/WIEN2k/QE), and PARSER_REGISTRY."""
224
+ bt_file = tmp_path / "case.trace"
225
+ bt_file.write_text(
226
+ "# Ef[Ry] T[K] N DOS(Ef) S[V/K] sigma/tau0[1/(Ohm*m*s)] RH[m^3/C] kappa0[W/(m*K*s)]\n"
227
+ "0.350 300.0 -0.05 1.2 -2.0e-4 1.0e19 -1.0e-8 1.5e14\n"
228
+ "0.320 300.0 0.05 1.1 1.9e-4 0.9e19 1.0e-8 1.3e14\n",
229
+ encoding="utf-8",
230
+ )
231
+ bt_data = parse_boltztrap2_trace(bt_file, vol_uc_m3=5.0e-29)
232
+ assert bt_data["T"][0] == pytest.approx(300.0)
233
+ assert bt_data["n"][0] == pytest.approx(-0.05 / 5.0e-29)
234
+ assert bt_data["S"][1] == pytest.approx(1.9e-4)
235
+
236
+ gen_file = tmp_path / "transport.csv"
237
+ gen_file.write_text(
238
+ "300.0,-1.5e25,-2.1e-4,1.1e19,1.2e14\n"
239
+ "600.0,1.2e25,2.3e-4,0.8e19,1.8e14\n",
240
+ encoding="utf-8",
241
+ )
242
+ gen_data = parse_generic_transport(gen_file, cols="T,n,S,sigma_tau,kappa_e_tau")
243
+ assert gen_data["sigma_tau"][0] == pytest.approx(1.1e19)
244
+ assert gen_data["kappa_e_tau"][1] == pytest.approx(1.8e14)
245
+
246
+ # Elastic JSON & VASP OUTCAR
247
+ C_iso = isotropic_tensor_from_moduli(90.0, 40.0)
248
+ json_file = tmp_path / "elastic.json"
249
+ json_file.write_text(json.dumps({"C_ij": C_iso.tolist()}), encoding="utf-8")
250
+ np.testing.assert_allclose(parse_elastic_tensor(json_file, fmt="json"), C_iso)
251
+
252
+ vasp_file = tmp_path / "OUTCAR"
253
+ c11, c12, c44 = (C_iso[0, 0] * 10.0, C_iso[0, 1] * 10.0, C_iso[3, 3] * 10.0)
254
+ vasp_file.write_text(
255
+ " TOTAL ELASTIC MODULI (kBar)\n"
256
+ " Direction XX YY ZZ XY YZ ZX\n"
257
+ " --------------------------------------------------------------------------------\n"
258
+ f" XX {c11:10.4f} {c12:10.4f} {c12:10.4f} 0.0 0.0 0.0\n"
259
+ f" YY {c12:10.4f} {c11:10.4f} {c12:10.4f} 0.0 0.0 0.0\n"
260
+ f" ZZ {c12:10.4f} {c12:10.4f} {c11:10.4f} 0.0 0.0 0.0\n"
261
+ f" XY 0.0 0.0 0.0 {c44:10.4f} 0.0 0.0\n"
262
+ f" YZ 0.0 0.0 0.0 0.0 {c44:10.4f} 0.0\n"
263
+ f" ZX 0.0 0.0 0.0 0.0 0.0 {c44:10.4f}\n",
264
+ encoding="utf-8",
265
+ )
266
+ np.testing.assert_allclose(parse_elastic_tensor(vasp_file, fmt="vasp"), C_iso, atol=1e-4)
267
+
268
+ # WIEN2k elast/IRelast format
269
+ wien_file = tmp_path / "elast.output"
270
+ wien_file.write_text(
271
+ f"C11 = {C_iso[0, 0]:.4f} GPa\n"
272
+ f"C12 = {C_iso[0, 1]:.4f} GPa\n"
273
+ f"C44 = {C_iso[3, 3]:.4f} GPa\n",
274
+ encoding="utf-8",
275
+ )
276
+ np.testing.assert_allclose(parse_elastic_tensor(wien_file, fmt="wien2k"), C_iso, atol=1e-4)
277
+
278
+ # Quantum ESPRESSO thermo_pw format (kbar)
279
+ qe_file = tmp_path / "thermo_pw.out"
280
+ qe_rows = "\n".join(" ".join(f"{val * 10.0:10.4f}" for val in row) for row in C_iso)
281
+ qe_file.write_text(
282
+ "Elastic constants (kbar)\n" + qe_rows + "\n",
283
+ encoding="utf-8",
284
+ )
285
+ np.testing.assert_allclose(parse_elastic_tensor(qe_file, fmt="qe"), C_iso, atol=1e-4)
286
+
287
+ # Registry checks
288
+ assert "boltztrap2" in PARSER_REGISTRY
289
+ assert "generic" in PARSER_REGISTRY
290
+ register_parser("custom_dummy", lambda p: {"T": np.array([300.0])})
291
+ assert callable(get_parser("custom_dummy"))
292
+ PARSER_REGISTRY.pop("custom_dummy", None)
293
+
294
+
295
+ def test_cli_cite_and_end_to_end(tmp_path: Path):
296
+ """Verify CLI --cite banner/BibTeX and full pipeline execution with --config & --plot."""
297
+ proc_cite = subprocess.run(
298
+ [sys.executable, "-m", "unizt.cli", "--cite"],
299
+ capture_output=True,
300
+ text=True,
301
+ check=True,
302
+ )
303
+ assert f"UniZT v{__version__}" in proc_cite.stdout
304
+ assert __author__ in proc_cite.stdout
305
+ assert __email__ in proc_cite.stdout
306
+ assert "@software{makhlouf2026unizt" in proc_cite.stdout
307
+
308
+ # End-to-end CLI run with --config and --plot
309
+ trace_file = tmp_path / "sample.trace"
310
+ rows = ["# Ef T N DOS S sigma/tau RH kappa0"]
311
+ for T in (300.0, 450.0, 600.0):
312
+ for n_val, s_val in [(-0.15, -2.1e-4), (-0.05, -2.5e-4), (0.06, 2.3e-4), (0.16, 1.9e-4)]:
313
+ rows.append(f"0.3 {T} {n_val} 1.0 {s_val} 1.2e19 0.0 1.4e14")
314
+ trace_file.write_text("\n".join(rows) + "\n", encoding="utf-8")
315
+
316
+ C_iso = isotropic_tensor_from_moduli(80.0, 40.0)
317
+ elastic_file = tmp_path / "elastic.json"
318
+ elastic_file.write_text(json.dumps({"C_ij": C_iso.tolist()}), encoding="utf-8")
319
+
320
+ outdir = tmp_path / "out"
321
+ cfg_file = tmp_path / "params.json"
322
+ cfg_file.write_text(
323
+ json.dumps(
324
+ {
325
+ "trace": str(trace_file),
326
+ "elastic": str(elastic_file),
327
+ "density": 6000.0,
328
+ "m_avg": 80.0,
329
+ "n_atoms": 3,
330
+ "m_eff": 0.4,
331
+ "e1": 12.0,
332
+ "tau_mode": "dpt",
333
+ "kappa_mode": "slack",
334
+ "tc": 300.0,
335
+ "outdir": str(outdir),
336
+ "plot": True,
337
+ }
338
+ ),
339
+ encoding="utf-8",
340
+ )
341
+
342
+ proc_run = subprocess.run(
343
+ [sys.executable, "-m", "unizt.cli", "--config", str(cfg_file)],
344
+ capture_output=True,
345
+ text=True,
346
+ check=True,
347
+ )
348
+ assert "Overall Peak ZT" in proc_run.stdout
349
+ assert __author__ in proc_run.stdout
350
+ assert (outdir / "zt_results.csv").is_file()
351
+ assert (outdir / "zt_results.tex").is_file()
352
+ assert (outdir / "kappa_l_vs_t.png").is_file()
353
+ assert (outdir / "zt_vs_t.png").is_file()
354
+ assert (outdir / "zt_heatmap.png").is_file()
355
+ assert (outdir / "efficiency_vs_th.png").is_file()