tbkit 0.2.0__py3-none-any.whl

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,260 @@
1
+ Metadata-Version: 2.4
2
+ Name: tbkit
3
+ Version: 0.2.0
4
+ Summary: A Python package to build and solve Tight-Binding models, for research and education.
5
+ Author-email: Charles Poli <cpoli374@gmail.com>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/cpoli/tbkit
8
+ Classifier: Intended Audience :: Education
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Topic :: Scientific/Engineering :: Physics
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: numpy>=1.24
16
+ Requires-Dist: scipy>=1.10
17
+ Requires-Dist: matplotlib>=3.7
18
+ Provides-Extra: test
19
+ Requires-Dist: pytest>=7; extra == "test"
20
+ Requires-Dist: pytest-cov>=4; extra == "test"
21
+ Provides-Extra: docs
22
+ Requires-Dist: sphinx>=7; extra == "docs"
23
+ Requires-Dist: pydata-sphinx-theme>=0.15; extra == "docs"
24
+ Requires-Dist: sphinx-gallery>=0.15; extra == "docs"
25
+ Dynamic: license-file
26
+
27
+ # tbkit — a Tight-Binding package for research and education
28
+
29
+ [![tests](https://github.com/cpoli/tbkit/actions/workflows/tests.yml/badge.svg)](https://github.com/cpoli/tbkit/actions/workflows/tests.yml)
30
+ [![docs](https://img.shields.io/badge/docs-cpoli.github.io%2Ftbkit-blue.svg)](https://cpoli.github.io/tbkit/)
31
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)
32
+ [![License: BSD 3-Clause](https://img.shields.io/badge/License-BSD--3--Clause-blue.svg)](LICENSE)
33
+
34
+ ![tbkit logo](docs/source/_static/image/tbkit_logo.png)
35
+
36
+ **tbkit** is a Python package to build and solve Tight-Binding models, written
37
+ in vectorized NumPy/SciPy. It aims to make the mechanics of Tight-Binding
38
+ models — lattices, hoppings, Hamiltonians, spectra, band structures —
39
+ explicit and easy to inspect, so it works as well for teaching as for
40
+ research prototyping.
41
+
42
+ ## Features
43
+
44
+ * **Real space**: build arbitrarily complex finite lattices (flakes,
45
+ ribbons, disordered structures, defects) site by site or via boolean
46
+ selections (ellipses, half-planes, unions/differences of lattices), then
47
+ diagonalize the resulting Hamiltonian directly.
48
+ * **Reciprocal space**: build the Bloch Hamiltonian `H(k)` of the infinite
49
+ periodic lattice from a small set of intra-unit-cell hoppings, and compute
50
+ band structures along a k-path through high-symmetry points.
51
+ * **Topology**: Berry curvature and Chern numbers of a group of bands, by
52
+ the gauge-invariant Fukui-Hatsugai-Suzuki lattice method.
53
+ * **Spin**: optional spin-1/2 degree of freedom on every site, with 2x2
54
+ (Pauli-matrix) hoppings/onsite terms, for spin-orbit coupling (Rashba,
55
+ Kane-Mele) and Zeeman splitting.
56
+ * **Edge states**: cut a ribbon (periodic in one direction, finite in the
57
+ other) out of any periodic model, to see edge/surface physics.
58
+ * **Density of states**, Gaussian- or Lorentzian-broadened, from either a
59
+ real-space spectrum or a Brillouin-zone mesh.
60
+ * A small library of ready-made lattices (chain, square, triangular,
61
+ honeycomb, kagome, Lieb).
62
+ * Complex-valued onsite energies and hoppings; **Hermitian and non-Hermitian**
63
+ Tight-Binding Hamiltonians.
64
+ * Multiple sublattices, with hoppings addressed by neighbor order (1st,
65
+ 2nd, 3rd-nearest neighbor, ...), by angle, or by sublattice-pair tag.
66
+ * Built-in patterns for onsite disorder, hopping disorder, dimerization,
67
+ strain, and an orbital magnetic field (Peierls substitution).
68
+ * Time propagation of a wavepacket under the Tight-Binding Hamiltonian
69
+ (Crank-Nicolson).
70
+
71
+ **tbkit** is organized as a small set of composable classes and modules:
72
+
73
+ | Class / module | Purpose |
74
+ |----------------------------|---------------------------------------------------------|
75
+ | `tbkit.Lattice` | Define and manipulate site positions and sublattices. |
76
+ | `tbkit.System` | Build the real-space Hamiltonian from a `Lattice` and solve it. |
77
+ | `tbkit.KSpace` | Build and solve the Bloch Hamiltonian of a periodic `Lattice`; bands, Berry curvature/Chern numbers, ribbons, DOS. |
78
+ | `tbkit.Plot` | Plot lattices, spectra, eigenstates, and the density of states. |
79
+ | `tbkit.Propagation` | Time-evolve a wavepacket. |
80
+ | `tbkit.Save` | Save figures/animations to disk. |
81
+ | `tbkit.lattices` | Ready-made common lattices. |
82
+ | `tbkit.dos` | Broadened density of states from a set of eigenenergies. |
83
+
84
+ ## Install
85
+
86
+ Requires Python >= 3.10.
87
+
88
+ ```bash
89
+ git clone https://github.com/cpoli/tbkit
90
+ cd tbkit
91
+ pip install -e .
92
+ ```
93
+
94
+ or, to also install the tools needed to run the test suite:
95
+
96
+ ```bash
97
+ pip install -e ".[test]"
98
+ pytest tests/
99
+ ```
100
+
101
+ ## Quick start
102
+
103
+ Real-space flake, nearest-neighbor square lattice:
104
+
105
+ ```python
106
+ from tbkit.lattice import Lattice
107
+ from tbkit.system import System
108
+
109
+ lat = Lattice(unit_cell=[{'tag': 'a', 'r0': (0., 0.)}],
110
+ prim_vec=[(1., 0.), (0., 1.)])
111
+ lat.get_lattice(n1=10, n2=10)
112
+
113
+ sys = System(lat)
114
+ sys.set_hopping([{'n': 1, 't': 1.}])
115
+ sys.get_ham()
116
+ sys.get_eig()
117
+ print(sys.en)
118
+ ```
119
+
120
+ Graphene band structure (reciprocal space):
121
+
122
+ ```python
123
+ import numpy as np
124
+ from tbkit.lattice import Lattice
125
+ from tbkit.kspace import KSpace, reciprocal_vectors
126
+
127
+ DX, DY = 0.5 * 3 ** 0.5, 0.5
128
+ unit_cell = [{'tag': 'a', 'r0': (0., 0.)}, {'tag': 'b', 'r0': (DX, DY)}]
129
+ prim_vec = [(2 * DX, 0.), (DX, 1.5)]
130
+ lat = Lattice(unit_cell=unit_cell, prim_vec=prim_vec)
131
+
132
+ gra = KSpace(lat)
133
+ gra.set_hopping([{'i': 0, 'j': 1, 'R': (0, 0), 't': 1.},
134
+ {'i': 0, 'j': 1, 'R': (-1, 0), 't': 1.},
135
+ {'i': 0, 'j': 1, 'R': (0, -1), 't': 1.}])
136
+
137
+ b1, b2 = (np.array(v) for v in reciprocal_vectors(prim_vec))
138
+ Gamma, K, M = np.zeros(2), (b1 - b2) / 3, b1 / 2
139
+ gra.k_path([Gamma, K, M, Gamma], nk=60)
140
+ fig = gra.plot_bands(node_labels=[r'$\Gamma$', 'K', 'M', r'$\Gamma$'])
141
+ fig.savefig('graphene_bands.png')
142
+ ```
143
+
144
+ A magnetic field is added with `System.set_magnetic_field` (uniform field) or
145
+ `System.set_peierls_phase` (arbitrary vector potential), applied to the
146
+ hoppings *after* `set_hopping`/`set_hopping_manual`:
147
+
148
+ ```python
149
+ sys.set_hopping_manual(hop_dict)
150
+ sys.set_magnetic_field(alpha=0.01) # flux quanta per unit area
151
+ sys.get_ham()
152
+ ```
153
+
154
+ See [`examples/magnetic_field/plot_magnetic_field.py`](examples/magnetic_field/plot_magnetic_field.py) for a full
155
+ worked example (an Aharonov-Bohm ring, reproducing the textbook result that
156
+ the spectrum is periodic in the enclosed flux with period one flux quantum).
157
+
158
+ A Chern number is the Berry curvature of a group of bands, integrated over
159
+ the Brillouin zone:
160
+
161
+ ```python
162
+ chern = gra.chern_number(bands=[0], nk=40) # ~0 for plain graphene
163
+ ```
164
+
165
+ See [`examples/topology/plot_haldane_topology.py`](examples/topology/plot_haldane_topology.py) for the
166
+ Haldane model (the first Chern insulator), reproducing its topological
167
+ phase transition (Chern number 1 -> 0) and Berry-curvature map.
168
+
169
+ A spin-1/2 degree of freedom is added with `KSpace(lat, spin=True)`; onsite
170
+ values and hoppings then also accept 2x2 (Pauli) matrices:
171
+
172
+ ```python
173
+ from tbkit.kspace import KSpace, PAULI
174
+
175
+ kmele = KSpace(lat, spin=True)
176
+ kmele.set_hopping([{'i': 0, 'j': 0, 'R': (1, 0), 't': 1j*lam*PAULI['z']}]) # intrinsic SOC
177
+ ```
178
+
179
+ A ribbon -- periodic in one direction, finite in the other, the standard
180
+ way to see edge states -- is cut out of a periodic model with
181
+ `tbkit.kspace.ribbon`:
182
+
183
+ ```python
184
+ from tbkit.kspace import ribbon
185
+
186
+ rib = ribbon(lat, list_hop, width=30, direction=1) # 30 unit cells wide
187
+ fig = rib.plot_bands()
188
+ ```
189
+
190
+ See [`examples/topology/plot_edge_states.py`](examples/topology/plot_edge_states.py) for the zigzag
191
+ graphene ribbon's zero-energy edge band, and the Kane-Mele ribbon's helical
192
+ edge states crossing a spin-orbit gap.
193
+
194
+ ## Examples
195
+
196
+ `examples/` is organized as a [Sphinx-Gallery](https://sphinx-gallery.github.io/)
197
+ source tree, one topic per subfolder, each with a `README.rst` blurb. Every
198
+ `plot_*.py` script is self-contained and runnable directly
199
+ (`python examples/<section>/<script>.py`), and checks its own key numeric
200
+ claims with `assert` before plotting -- nothing is asserted in the docs
201
+ that isn't also verified in code. Building the docs (`pip install -e ".[docs]"`
202
+ then `cd docs && make html`) renders these same scripts into an executed,
203
+ thumbnailed example gallery under `docs/source/api/gallery/`.
204
+
205
+ | Script | What it shows |
206
+ |---------------------------------------------------------------------------|----------------|
207
+ | [`tight_binding/plot_graphene_bands.py`](examples/tight_binding/plot_graphene_bands.py) | Real-space flake + reciprocal-space band structure; graphene's Dirac point and Wallace's 1947 linear dispersion. |
208
+ | [`tight_binding/plot_visualizing_a_model.py`](examples/tight_binding/plot_visualizing_a_model.py) | `tbkit.plot.Plot`: lattice, spectrum with sublattice polarization, density of states, eigenstate intensity. |
209
+ | [`magnetic_field/plot_magnetic_field.py`](examples/magnetic_field/plot_magnetic_field.py) | Peierls substitution; an Aharonov-Bohm ring's flux-periodic spectrum. |
210
+ | [`magnetic_field/plot_hofstadter_butterfly.py`](examples/magnetic_field/plot_hofstadter_butterfly.py) | The fractal spectrum of a lattice threaded by a continuously swept flux. |
211
+ | [`magnetic_field/plot_landau_levels.py`](examples/magnetic_field/plot_landau_levels.py) | Landau levels: a square lattice's non-relativistic ladder vs. graphene's relativistic sqrt(n) ladder and zero mode. |
212
+ | [`topology/plot_ssh_model.py`](examples/topology/plot_ssh_model.py) | The SSH model: bulk gap closing and topologically protected edge states. |
213
+ | [`disorder/plot_anderson_localization.py`](examples/disorder/plot_anderson_localization.py) | Anderson localization: IPR vs. disorder strength, extended vs. localized states. |
214
+ | [`topology/plot_haldane_topology.py`](examples/topology/plot_haldane_topology.py) | The Haldane model: Berry curvature, Chern number, topological phase transition. |
215
+ | [`flat_bands/plot_flat_bands.py`](examples/flat_bands/plot_flat_bands.py) | Exactly flat bands on the kagome and Lieb lattices. |
216
+ | [`topology/plot_kagome_chern_band.py`](examples/topology/plot_kagome_chern_band.py) | Gapping the kagome flat band into a Chern insulator (C=-1) with complex nearest-neighbor hopping. |
217
+ | [`topology/plot_edge_states.py`](examples/topology/plot_edge_states.py) | Zigzag graphene ribbon edge band; Kane-Mele helical edge states. |
218
+ | [`dynamics/plot_bloch_oscillations.py`](examples/dynamics/plot_bloch_oscillations.py) | Wannier-Stark ladder, its localization, and Bloch oscillations under a uniform tilt. |
219
+ | [`topology/plot_thouless_pump.py`](examples/topology/plot_thouless_pump.py) | The Rice-Mele model as a Thouless quantum pump: quantized Chern number and polarization winding. |
220
+
221
+ The `examples/` directory also has five older Jupyter notebooks (graphene
222
+ flakes, kagome/Lieb/dumbbell lattices, disorder, strain, time propagation)
223
+ predating the 0.2 API refresh below.
224
+
225
+ ## Documentation
226
+
227
+ Rendered docs (tutorial, API reference, example gallery): https://cpoli.github.io/tbkit/
228
+
229
+ * [`docs/source/tutorial.rst`](docs/source/tutorial.rst) -- a narrative walkthrough of the
230
+ package, from building a lattice through topology, spin-orbit coupling,
231
+ and edge states.
232
+ * [`docs/source/history.rst`](docs/source/history.rst) -- a chronology of the breakthroughs
233
+ behind Tight-Binding theory (Bloch's theorem through the Kane-Mele model),
234
+ each one linked to the corresponding **tbkit** functionality and example
235
+ above.
236
+ * `docs/source/tbkit.rst` -- the API reference (auto-generated from docstrings).
237
+
238
+ Build the HTML docs with `cd docs && make html` (output in `docs/build/html`).
239
+
240
+ ## A note on the API
241
+
242
+ Version 0.2 modernized the package to run on current Python/NumPy/SciPy and
243
+ cleaned up the API:
244
+
245
+ * Sublattice tags are plain one-character **strings** (`'a'`) rather than
246
+ byte strings (`b'a'`).
247
+ * Classes are named in `PascalCase` (`Lattice`, `System`, ...) rather than
248
+ lowercase names identical to their module (`lattice.lattice`,
249
+ `system.system`, ...), which used to make `import tbkit.lattice as lattice`
250
+ silently bind the wrong object.
251
+
252
+ For continuity, the pre-0.2 lowercase class names (`lattice`, `system`,
253
+ `plot`, `propagation`, `save`) remain available as aliases of the new
254
+ classes, so `from tbkit.lattice import lattice` still works. Example
255
+ notebooks predating 0.2 still use byte-string tags (`b'a'`) and will need
256
+ that one mechanical change to run on the current version.
257
+
258
+ ## License
259
+
260
+ BSD 3-Clause, see [LICENSE](LICENSE).
@@ -0,0 +1,16 @@
1
+ tbkit/__init__.py,sha256=4oIxjdWVTIySp0RHOkTSYSOWoFFzPZekFaX8B2x7ER8,1022
2
+ tbkit/dos.py,sha256=AYwc0x0QLOa-NO1f1lwYEd4XWAZ9f-xT63EcxGADzxY,2580
3
+ tbkit/error_handling.py,sha256=VRWR2XdsxoHDNFXLhFlDO3fdqYpJXhnWHSuD79eEEic,35301
4
+ tbkit/graphene.py,sha256=-MvTKuXUSSuLqG_ClYdJeN22OU6PqFeChUcRTu7VQyI,6475
5
+ tbkit/kspace.py,sha256=MBXMh3oDxae0FXzeOKG_SaSjoIMAoJDpfcpBBOZGkeQ,23305
6
+ tbkit/lattice.py,sha256=NKf7gtf6rPjDH67GwMpyhtEPTq6VrNroWv1mvBSxcT4,15274
7
+ tbkit/lattices.py,sha256=H7_0CCzl3IhqDj6XB91sTV_IzbKdCNucYNEKvQ_Kt28,4630
8
+ tbkit/plot.py,sha256=dnbIQTrxSAKdouF2aAaFkGqek-gK6-RPfuHaoRTHF2U,27800
9
+ tbkit/propagation.py,sha256=UMz6uHBrOo5Becs5dzbAiz-2Wfb5YjcYzOJYvTgzKhg,13196
10
+ tbkit/save.py,sha256=ExHHGi9JNcI3pUMmpURcNKZQUccrE49C6VuY0ax9zX0,3282
11
+ tbkit/system.py,sha256=r6Twd3P-BxwhXxWOU5NCcBiCw0Md0qQIJ6GjANs1t9s,31654
12
+ tbkit-0.2.0.dist-info/licenses/LICENSE,sha256=JE3xsa7NaI8cwUVrJPn77CUK6ib_in9qsHFX_eGhsR4,1520
13
+ tbkit-0.2.0.dist-info/METADATA,sha256=WOusCZZyjTc4SZsQQwsAzQMSuP4H_gh7QC0_loH_Df8,12646
14
+ tbkit-0.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
15
+ tbkit-0.2.0.dist-info/top_level.txt,sha256=izcfLM9OtEjvZP5Cf5VJg91Dmlt_THAufNDok9iLXEQ,6
16
+ tbkit-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2014, Charles Poli
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1 @@
1
+ tbkit