Commit a36c37d
authored
Feat: Add new unifined postprocess class to handle DeePTB model. (#301)
* new_post_v0
* new post v0.2
* feat: add support for built-in polynomial checkpoints
Enhance build_model to handle 'poly2' and 'poly4' as special checkpoint names, automatically resolving them to their corresponding base model files in the dftb directory. This simplifies model initialization for common polynomial baselines.
* feat: add GUI detection and refactor calculator interface
Add is_gui_available() function to detect matplotlib GUI display availability in various environments including Jupyter notebooks and different operating systems. Refactor HamiltonianCalculator from Protocol to ABC with proper abstract methods for better type safety and inheritance. Update DeePTBAdapter to inherit from the new abstract base class.
* feat: Implement unified post-processing for band structure and DOS, including new examples and tests.
* feat: add get_hk method to HamiltonianCalculator interface
Add new abstract method get_hk() to calculate H(k) and S(k) matrices at specified k-points. Rename get_hamiltonian_blocks() to get_hr() for clarity. Implement get_hk() in DeePTBAdapter with support for custom k-point injection and proper tensor handling. Remove redundant get_hamiltonian_at_k() method from BandAccessor. Add data property to TBSystem for atomic data access.
* feat: add eigenstates calculation and DOS analysis capabilities
- Add abstract get_eigenstates method to HamiltonianCalculator interface
- Implement eigenstates calculation in DeePTBAdapter using Eigh solver
- Add DosData class for structured DOS results storage
- Add DOS plotting functionality with matplotlib integration
- Refactor solver initialization to support both Eigenvalues and Eigh solvers
- Remove unused logging imports and update error handling
* refactor: improve DOS calculation interface and configuration
Rename set_dos to set_dos_config for clarity in DOS configuration setup. Add reuse parameter to get_dos and get_bands methods to control recalculation. Improve error messages and add dos_data property for easier access to computed DOS results. Refactor DOS initialization to separate kpoints setup from configuration.
* refactor(test): replace mock tests with integration tests using real data
Replace mock-based unit tests with integration tests that use actual silicon example data. Add pytest fixtures for efficient system initialization, test band structure and DOS calculations with real model, and include plotting functionality tests. This provides more realistic validation of the unified postprocessing module.
* feat: add unified post-processing tutorial notebook
Add a comprehensive Jupyter notebook demonstrating the new TBSystem class for unified post-processing in DeePTB. The tutorial covers initialization, band structure calculation, DOS computation, and visualization using the centralized interface that manages both atomic structure and Hamiltonian model.
* feat: ignore band structure and DOS plot files in .gitignore
* fix: ensure dtype consistency in tensor product operations
Fix dtype mismatches in tensor product calculations by explicitly setting dtype to match input tensors. Updates J_full_small initialization and _Jd tensor conversion in batch_wigner_D function, and enforces double precision in test cases to prevent numerical precision issues.
* feat: add band_data initialization and simplify tensor type check
- Initialize _band_data attribute in BandAccessor.__init__ for future use
- Remove NestedTensor type check in test_postprocess_unified.py to simplify validation
- Ensure consistent tensor type handling in Hamiltonian calculations
* feat: add PythTB export tutorial notebook
Add comprehensive tutorial demonstrating how to export DeePTB models to PythTB format. The notebook covers loading pre-trained models, calculating band structures with both DeePTB and PythTB, and comparing results to ensure compatibility. This enables users to leverage external tools for post-processing trained tight-binding models.
* feat: implement Fermi level calculation and integration
Add proper Fermi level calculation functionality to replace hardcoded values. The band structure and DOS properties now use the system's Fermi level when available, falling back to 0.0 when not set. Includes a new utility function for calculating Fermi energy from eigenvalues using various smearing methods and temperature parameters. Also improves DOS plotting with inward tick direction.
* feat: add export functionality for TBSystem to third-party formats
Add ExportAccessor class to
* feat: support dict input for export interfaces
Add support for dictionary input in ToWannier90 and ToPythTB export classes. Skip data loading when input is already a dictionary to avoid redundant processing. Update ExportAccessor to use explicit parameter names for better clarity.
* feat: add PythTB-Wannier postprocessing example and rename existing notebook
- Add new_postprocess_pythtb_wannier.ipynb demonstrating PythTB and Wannier90 integration
- Rename new_postprocess.ipynb to new_postprocess_band_dos.ipynb for clarity
- New example includes band structure calculation with k-path configuration and Fermi level determination
* feat: add Wannier90 integration and export functionality
Add new cells to demonstrate Wannier90 integration with PythTB, including export functionality and model loading. Update execution counts and fix reference from tbsys.band_data to tbsys.band for consistency.
* test: update export tests to match implementation changes
Updated test assertions in test_export_unified.py to align with the actual implementation of export methods. Fixed parameter names and added missing arguments like overlap, e_fermi, and filename parameters to ensure tests accurately validate the export functionality.
* refactor: simplify HR2HK onsite block construction and SOC handling
Simplify the HR2HK class by removing redundant overlap-specific code paths and consolidating onsite block construction. The SOC handling is now restricted to Hamiltonian-only cases with clearer documentation about current limitations. This refactoring improves code readability and maintainability while preserving the same functionality.
* feat(nn): add gauge convention support to HR2HK module
Add support for two gauge conventions in HR2HK:
- Wannier90 Gauge (gauge=False) using cell shift vectors
- Physical/Periodic Gauge (gauge=True) using edge vectors
The gauge parameter controls phase factor calculation in k-space
transformation. When derivative=True, automatically enables gauge=True
mode. Added comprehensive test suite for both conventions.
* add new key for AtomicDataDict: HAMILTONIAN_DERIV_KEY = "hamiltonian_derivative" # dH(k)/dk
OVERLAP_DERIV_KEY = "overlap_derivative" # dS(k)/dk
* feat(nn): add Hamiltonian k-derivative computation to HR2HK
Add support for computing dH/dk derivatives in the HR2HK module. The implementation calculates the k-space derivatives of the Hamiltonian matrix using the analytical formula dH/dk = -i * R * H_R * exp(-i k·R), where R is the real-space hopping vector. The derivatives are computed for all three Cartesian directions and stored in the output data dictionary. This feature is controlled by the derivative parameter and uses the new out_derivative_field parameter to specify the output key. The gauge parameter default is changed to False to maintain consistency with the Wannier90 convention.
* feat: add derivative support to get_hk method in DeePTBAdapter
Enhance the get_hk method to support Hamiltonian and overlap matrix derivatives by adding a new with_derivative parameter. This allows computing derivatives of H(k) and S(k) with respect to k-points, which is useful for band structure analysis and property calculations. The implementation uses the HR2HK module for both regular and derivative computations, maintaining consistency with the existing codebase structure.
* refactor: restructure derivative handling in DeePTBAdapter
Restructured the derivative handling logic in the DeePTBAdapter class to improve code clarity and maintainability. The changes include moving derivative-related operations to a dedicated section and using .get() for safer access to optional derivative keys. This refactoring maintains the same functionality while making the code flow more logical and reducing potential errors when overlap derivatives are not present.
* correct v0
* correct v0
* jit
* v1
* feat: remove commented derivative code in HR2HK
Clean up HR2HK module by removing commented-out derivative computation code that was no longer needed. The active derivative computation logic remains intact and functional.
* refactor: rename optical to optical_conductivity and update class name
Renamed optical.py to optical_conductivity.py for clarity and updated OpticalAccessor to ACAccessor. Modified TBSystem to use accond property for accessing optical conductivity functionality, improving code organization and naming consistency.
* feat: improve optical conductivity calculation with complex Lorentzian
Enhance optical conductivity computation by implementing complex Lorentzian broadening to capture both real and imaginary parts. Update accumulation methods (loop and JIT) to use complex form 1/(E - ω + iη) for physical accuracy. Add comprehensive documentation for parameters and return values. Remove redundant vectorized method for cleaner code structure.
* feat: add spin degeneracy parameter to optical conductivity
Add g_s parameter to control spin degeneracy factor in optical conductivity calculations. Replace hardcoded spin factor of 2.0 with configurable g_s parameter (default 2.0). Update calculation to use 2πg_s/volume factor. Change default method from 'vectorized' to 'loop' for consistency.
* test: add optical conductivity test for silicon model
Add comprehensive unit test for optical conductivity calculations using a silicon tight-binding model. The test validates Fermi level calculation, optical conductivity computation with both JIT and loop methods, and consistency between different broadening functions (Lorentzian and Gaussian). Includes reference value comparisons and physical property validation.
* fix: improve broadening validation and example notebook
- Fix inconsistent indentation in optical_conductivity.py ACAccessor
- Add explicit validation for broadening type with clear error message
- Update example notebook with non-orthogonal model demonstration
- Reset execution counts and add missing import warnings
* update(example): refresh plot output in optical_cond.ipynb
The notebook's execution counts and matplotlib plot outputs have been updated. This reflects re-running the code cells to generate the latest visualization, ensuring the saved notebook state is consistent with its code.
* test: relax tolerance for optical conductivity tests
Adjusted assertion tolerances from 1e-5 to 1e-4 in optical conductivity unit tests to accommodate numerical precision differences while maintaining test validity.
* feat: add overlap override support for DeePTB calculator
Enable override of overlap matrices in DeePTB models by adding override_overlap parameter to DeePTBAdapter and TBSystem. This allows users to provide custom overlap files even when the original model includes overlap support, improving flexibility for tight-binding calculations.</think>
Based on the provided git diff, generate a concise and descriptive commit message.
The commit message should:
1. Has a short title (50-72 characters)
2. The commit message should adhere to the conventional commit format
3. Describe what was changed and why
4. De clear and informative
'git --no-pager diff --staged --diff-filter=d' Output:
diff --git a/dptb/sktb/neighbors.py b/dptb/sktb/neighbors.py
index 5128b57..689ec19 1006 Slater-Koster tight binding model module."""
+
+import numpy as np
import torch
from torch import nn
from torch.autograd import grad
from prefetch_generator import prefetch
from dptb.nn.ops.e3gnn import (
@@ -263,6 +264,11 @@ class NearestNeighborsFinder(nn.Module):
self.max_num_neighbors = max_num_neighbors
self.reference_distance = reference_distance
self.neighbor_indexing = neighbor_indexing
+ if use_efficient_format:
+ if self.max_num_neighbors is None:
+ self.max_num_neighbors = 200
+ log.info(f"use_efficient_format=True but max_num_neighbors is not specified, setting to default value 200.")
self.use_efficient_format = use_efficient_format
def forward(
@@ -525,6 +55, neighbor_list, atom_mask, positions, cell, offset_vecs = build_neighbor_list(
positions=positions,
cell=missing_masked_cell,
- neighbor_cutoff=neighbor_cutoff,
+ neighbor_cutoff=neighbor_cutoff,</think>
<think></think>
feat: add efficient neighbor format with default max neighbors
Introduce use_efficient_format option to NearestNeighborsFinder for optimized neighbor list handling. Automatically sets max_num_neighbors to 200 when not specified to improve performance with efficient format processing.
* refactor: rename TBSystems example notebooks for clarity
- Rename new_postprocess_band_dos.ipynb to tbsys_band_dos.ipynb
- Rename new_postprocess_pythtb_wannier.ipynb to tbsys_to_pythtb_wannier.ipynb
- Update kpath configuration and output filename in band DOS example1 parent 7e55619 commit a36c37d
File tree
27 files changed
+5529
-79
lines changed- dptb
- data
- nn
- postprocess
- unified
- properties
- tests
- utils
- examples
- TBSystems
- ToPythTB
27 files changed
+5529
-79
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
21 | 26 | | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
24 | 35 | | |
25 | 36 | | |
26 | 37 | | |
| |||
44 | 55 | | |
45 | 56 | | |
46 | 57 | | |
47 | | - | |
48 | | - | |
49 | | - | |
| 58 | + | |
50 | 59 | | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
54 | 63 | | |
55 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
56 | 69 | | |
57 | 70 | | |
58 | 71 | | |
| |||
67 | 80 | | |
68 | 81 | | |
69 | 82 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 83 | + | |
| 84 | + | |
74 | 85 | | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
78 | | - | |
79 | 89 | | |
80 | 90 | | |
81 | 91 | | |
| |||
92 | 102 | | |
93 | 103 | | |
94 | 104 | | |
| 105 | + | |
95 | 106 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
114 | 110 | | |
115 | 111 | | |
116 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
117 | 133 | | |
118 | 134 | | |
119 | 135 | | |
120 | 136 | | |
121 | 137 | | |
122 | | - | |
123 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
124 | 141 | | |
125 | 142 | | |
126 | 143 | | |
127 | 144 | | |
128 | 145 | | |
129 | 146 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
134 | 152 | | |
135 | 153 | | |
136 | 154 | | |
| |||
139 | 157 | | |
140 | 158 | | |
141 | 159 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
| |||
163 | 167 | | |
164 | 168 | | |
165 | 169 | | |
166 | | - | |
167 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
168 | 191 | | |
169 | 192 | | |
170 | 193 | | |
171 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
172 | 201 | | |
173 | 202 | | |
174 | 203 | | |
| |||
182 | 211 | | |
183 | 212 | | |
184 | 213 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | 214 | | |
190 | 215 | | |
191 | 216 | | |
| |||
207 | 232 | | |
208 | 233 | | |
209 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
210 | 239 | | |
211 | 240 | | |
212 | 241 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
0 commit comments