quant-met 0.0.2__tar.gz → 0.0.4__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.
Files changed (29) hide show
  1. quant_met-0.0.4/LICENSES/MIT.txt +9 -0
  2. {quant_met-0.0.2 → quant_met-0.0.4}/PKG-INFO +11 -7
  3. {quant_met-0.0.2 → quant_met-0.0.4}/README.md +6 -0
  4. quant_met-0.0.4/pyproject.toml +76 -0
  5. quant_met-0.0.4/src/quant_met/__init__.py +5 -0
  6. quant_met-0.0.4/src/quant_met/mean_field/__init__.py +61 -0
  7. quant_met-0.0.4/src/quant_met/mean_field/_utils.py +27 -0
  8. quant_met-0.0.4/src/quant_met/mean_field/base_hamiltonian.py +310 -0
  9. quant_met-0.0.4/src/quant_met/mean_field/eg_x.py +173 -0
  10. quant_met-0.0.4/src/quant_met/mean_field/free_energy.py +130 -0
  11. quant_met-0.0.4/src/quant_met/mean_field/graphene.py +142 -0
  12. quant_met-0.0.4/src/quant_met/mean_field/quantum_metric.py +108 -0
  13. quant_met-0.0.4/src/quant_met/mean_field/superfluid_weight.py +146 -0
  14. quant_met-0.0.4/src/quant_met/plotting/__init__.py +28 -0
  15. quant_met-0.0.4/src/quant_met/plotting/plotting.py +230 -0
  16. quant_met-0.0.4/src/quant_met/utils.py +71 -0
  17. quant_met-0.0.2/pyproject.toml +0 -39
  18. quant_met-0.0.2/src/quant_met/__init__.py +0 -7
  19. quant_met-0.0.2/src/quant_met/hamiltonians/__init__.py +0 -14
  20. quant_met-0.0.2/src/quant_met/hamiltonians/_base_hamiltonian.py +0 -172
  21. quant_met-0.0.2/src/quant_met/hamiltonians/_eg_x.py +0 -124
  22. quant_met-0.0.2/src/quant_met/hamiltonians/_free_energy.py +0 -39
  23. quant_met-0.0.2/src/quant_met/hamiltonians/_graphene.py +0 -93
  24. quant_met-0.0.2/src/quant_met/hamiltonians/_superfluid_weight.py +0 -130
  25. quant_met-0.0.2/src/quant_met/hamiltonians/_utils.py +0 -10
  26. quant_met-0.0.2/src/quant_met/plotting/__init__.py +0 -7
  27. quant_met-0.0.2/src/quant_met/plotting/_plotting.py +0 -156
  28. quant_met-0.0.2/src/quant_met/utils.py +0 -28
  29. {quant_met-0.0.2 → quant_met-0.0.4}/LICENSE.txt +0 -0
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Tjark <tsievers@physnet.uni-hamburg.de>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,22 +1,26 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: quant-met
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Calculate superconductivity in flat-band systems.
5
5
  Author: Tjark Sievers
6
6
  Author-email: tsievers@physnet.uni-hamburg.de
7
- Requires-Python: >=3.10,<4.0
7
+ Requires-Python: >=3.11,<4.0
8
8
  Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.10
10
9
  Classifier: Programming Language :: Python :: 3.11
11
10
  Classifier: Programming Language :: Python :: 3.12
12
11
  Requires-Dist: h5py (>=3.11.0,<4.0.0)
13
- Requires-Dist: matplotlib (>=3.8.4,<4.0.0)
14
- Requires-Dist: numpy (>=1.26.4,<2.0.0)
12
+ Requires-Dist: matplotlib (>=3.9.1,<4.0.0)
13
+ Requires-Dist: numpy (>=2.0.0,<3.0.0)
15
14
  Requires-Dist: pandas (>=2.2.2,<3.0.0)
16
- Requires-Dist: scipy (>=1.13.0,<2.0.0)
17
- Requires-Dist: sympy (>=1.12,<2.0)
15
+ Requires-Dist: scipy (>=1.14.0,<2.0.0)
18
16
  Description-Content-Type: text/markdown
19
17
 
18
+ <!--
19
+ SPDX-FileCopyrightText: 2024 Tjark Sievers
20
+
21
+ SPDX-License-Identifier: MIT
22
+ -->
23
+
20
24
  # quant-met
21
25
 
22
26
  [![Test](https://github.com/Ruberhauptmann/quant-met/actions/workflows/test.yml/badge.svg)](https://github.com/Ruberhauptmann/quant-met/actions/workflows/test.yml)
@@ -1,3 +1,9 @@
1
+ <!--
2
+ SPDX-FileCopyrightText: 2024 Tjark Sievers
3
+
4
+ SPDX-License-Identifier: MIT
5
+ -->
6
+
1
7
  # quant-met
2
8
 
3
9
  [![Test](https://github.com/Ruberhauptmann/quant-met/actions/workflows/test.yml/badge.svg)](https://github.com/Ruberhauptmann/quant-met/actions/workflows/test.yml)
@@ -0,0 +1,76 @@
1
+ # SPDX-FileCopyrightText: 2024 Tjark Sievers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ [project]
6
+ name = "quant-met"
7
+ requires-python = ">=3.11"
8
+
9
+ [tool.poetry]
10
+ name = "quant-met"
11
+ version = "0.0.4"
12
+ description = "Calculate superconductivity in flat-band systems."
13
+ authors = ["Tjark Sievers <tsievers@physnet.uni-hamburg.de>"]
14
+ readme = "README.md"
15
+
16
+ [tool.poetry.dependencies]
17
+ python = "^3.11"
18
+ numpy = "^2.0.0"
19
+ scipy = "^1.14.0"
20
+ matplotlib = "^3.9.1"
21
+ pandas = "^2.2.2"
22
+ h5py = "^3.11.0"
23
+
24
+ [tool.poetry.group.dev.dependencies]
25
+ pre-commit = "^3.7.0"
26
+ scriv = "^1.5.1"
27
+ jupyter = "^1.0.0"
28
+ ipympl = "^0.9.4"
29
+ sphinx = "^7.3.7"
30
+ myst-parser = "^3.0.1"
31
+ nbsphinx = "^0.9.4"
32
+ sphinx-gallery = "^0.16.0"
33
+ pydata-sphinx-theme = "^0.15.4"
34
+ sphinx-design = "^0.6.0"
35
+ tox = "^4.15.0"
36
+ mypy = "^1.10.0"
37
+ pytest = "^8.2.1"
38
+ pytest-cov = "^5.0.0"
39
+ hypothesis = {extras = ["numpy"], version = "^6.103.0"}
40
+ pytest-regressions = "^2.5.0"
41
+ numpydoc = "^1.7.0"
42
+ ruff = "^0.5.0"
43
+
44
+ [build-system]
45
+ requires = ["poetry-core"]
46
+ build-backend = "poetry.core.masonry.api"
47
+
48
+ # Config for ruff
49
+ [tool.ruff]
50
+ line-length = 100
51
+ force-exclude = true
52
+ extend-exclude = ["tests", "docs/source/conf.py"]
53
+
54
+ [tool.ruff.lint]
55
+ #select = []
56
+ #select = ["D", "E", "F", "I", "W"]
57
+ select = ["ALL"]
58
+ ignore = [
59
+ "D203", # one-blank-line-before-class
60
+ "D212", # multi-line-summary-first-line
61
+ "COM812",
62
+ "ISC001",
63
+ "Q000",
64
+ "Q003",
65
+ "S101", # This checks against using assert
66
+ "PLR0913", # This checks against using more than 5 function arguments
67
+ "PLR2004", # Check against "magic values"
68
+ "T201", # Warn about print statements
69
+ ]
70
+
71
+
72
+ [tool.ruff.lint.pydocstyle]
73
+ convention = "numpy"
74
+
75
+ #[format]
76
+ #docstring-code-format = true
@@ -0,0 +1,5 @@
1
+ # SPDX-FileCopyrightText: 2024 Tjark Sievers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """quant-met, a package to treat superconductivity in flat-band systems."""
@@ -0,0 +1,61 @@
1
+ # SPDX-FileCopyrightText: 2024 Tjark Sievers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """
6
+ Mean field treatment (:mod:`quant_met.mean_field`)
7
+ ==================================================
8
+
9
+ Hamiltonians
10
+ ------------
11
+
12
+ Base
13
+
14
+ .. autosummary::
15
+ :toctree: generated/
16
+
17
+ BaseHamiltonian
18
+
19
+ .. autosummary::
20
+ :toctree: generated/
21
+
22
+ GrapheneHamiltonian
23
+ EGXHamiltonian
24
+
25
+
26
+ Functions
27
+ ---------
28
+
29
+ .. autosummary::
30
+ :toctree: generated/
31
+
32
+ superfluid_weight
33
+ quantum_metric
34
+ free_energy
35
+ free_energy_uniform_pairing
36
+ """ # noqa: D205, D400
37
+
38
+ from .base_hamiltonian import BaseHamiltonian
39
+ from .eg_x import EGXHamiltonian
40
+ from .free_energy import (
41
+ free_energy,
42
+ free_energy_complex_gap,
43
+ free_energy_real_gap,
44
+ free_energy_uniform_pairing,
45
+ )
46
+ from .graphene import GrapheneHamiltonian
47
+ from .quantum_metric import quantum_metric, quantum_metric_bdg
48
+ from .superfluid_weight import superfluid_weight
49
+
50
+ __all__ = [
51
+ "superfluid_weight",
52
+ "quantum_metric",
53
+ "quantum_metric_bdg",
54
+ "free_energy",
55
+ "free_energy_complex_gap",
56
+ "free_energy_real_gap",
57
+ "free_energy_uniform_pairing",
58
+ "BaseHamiltonian",
59
+ "GrapheneHamiltonian",
60
+ "EGXHamiltonian",
61
+ ]
@@ -0,0 +1,27 @@
1
+ # SPDX-FileCopyrightText: 2024 Tjark Sievers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ from typing import Any
6
+
7
+ import numpy as np
8
+ import numpy.typing as npt
9
+
10
+
11
+ def _check_valid_array(array_in: npt.NDArray[Any]) -> bool:
12
+ if np.isnan(array_in).any() or np.isinf(array_in).any():
13
+ msg = "k is NaN or Infinity"
14
+ raise ValueError(msg)
15
+
16
+ return True
17
+
18
+
19
+ def _validate_float(float_in: float, parameter_name: str) -> float:
20
+ if np.isinf(float_in):
21
+ msg = f"{parameter_name} must not be Infinity"
22
+ raise ValueError(msg)
23
+ if np.isnan(float_in):
24
+ msg = f"{parameter_name} must not be NaN"
25
+ raise ValueError(msg)
26
+
27
+ return float_in
@@ -0,0 +1,310 @@
1
+ # SPDX-FileCopyrightText: 2024 Tjark Sievers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Provides the base class for Hamiltonians."""
6
+
7
+ import pathlib
8
+ from abc import ABC, abstractmethod
9
+
10
+ import h5py
11
+ import numpy as np
12
+ import numpy.typing as npt
13
+ import pandas as pd
14
+
15
+ from ._utils import _check_valid_array
16
+
17
+
18
+ class BaseHamiltonian(ABC):
19
+ """Base class for Hamiltonians."""
20
+
21
+ @property
22
+ @abstractmethod
23
+ def number_of_bands(self) -> int:
24
+ """Number of bands in the model."""
25
+ raise NotImplementedError
26
+
27
+ @property
28
+ def coloumb_orbital_basis(self) -> npt.NDArray[np.float64]:
29
+ """
30
+ Coloumb interaction split up in orbitals.
31
+
32
+ Returns
33
+ -------
34
+ :class:`numpy.ndarray`
35
+
36
+ """
37
+ raise NotImplementedError
38
+
39
+ @property
40
+ def delta_orbital_basis(self) -> npt.NDArray[np.complex64]:
41
+ """
42
+ Order parameter in orbital basis.
43
+
44
+ Returns
45
+ -------
46
+ :class:`numpy.ndarray`
47
+
48
+ """
49
+ raise NotImplementedError
50
+
51
+ @delta_orbital_basis.setter
52
+ @abstractmethod
53
+ def delta_orbital_basis(self, new_delta: npt.NDArray[np.complex64]) -> None:
54
+ raise NotImplementedError
55
+
56
+ @abstractmethod
57
+ def hamiltonian(self, k: npt.NDArray[np.float64]) -> npt.NDArray[np.complex64]:
58
+ """
59
+ Return the normal state Hamiltonian in orbital basis.
60
+
61
+ Parameters
62
+ ----------
63
+ k : :class:`numpy.ndarray`
64
+ List of k points.
65
+
66
+ Returns
67
+ -------
68
+ :class:`numpy.ndarray`
69
+ Hamiltonian in matrix form.
70
+
71
+ """
72
+ raise NotImplementedError
73
+
74
+ @abstractmethod
75
+ def hamiltonian_derivative(
76
+ self, k: npt.NDArray[np.float64], direction: str
77
+ ) -> npt.NDArray[np.complex64]:
78
+ """
79
+ Deriative of the Hamiltonian.
80
+
81
+ Parameters
82
+ ----------
83
+ k: :class:`numpy.ndarray`
84
+ List of k points.
85
+ direction: str
86
+ Direction for derivative, either 'x' oder 'y'.
87
+
88
+ Returns
89
+ -------
90
+ :class:`numpy.ndarray`
91
+ Derivative of Hamiltonian.
92
+
93
+ """
94
+ raise NotImplementedError
95
+
96
+ def save(self, filename: pathlib.Path) -> None:
97
+ """
98
+ Save the Hamiltonian as a HDF5 file.
99
+
100
+ Parameters
101
+ ----------
102
+ filename : :class:`pathlib.Path`
103
+ Filename to save the Hamiltonian to, should end in .hdf5
104
+
105
+ """
106
+ with h5py.File(f"{filename}", "w") as f:
107
+ f.create_dataset("delta", data=self.delta_orbital_basis)
108
+ for key, value in vars(self).items():
109
+ if not key.startswith("_"):
110
+ f.attrs[key] = value
111
+
112
+ @classmethod
113
+ def from_file(cls, filename: pathlib.Path) -> "BaseHamiltonian":
114
+ """
115
+ Initialise a Hamiltonian from a HDF5 file.
116
+
117
+ Parameters
118
+ ----------
119
+ filename : :class:`pathlib.Path`
120
+ File to load the Hamiltonian from.
121
+
122
+ """
123
+ with h5py.File(f"{filename}", "r") as f:
124
+ config_dict = dict(f.attrs.items())
125
+ config_dict["delta"] = f["delta"][()]
126
+
127
+ return cls(**config_dict)
128
+
129
+ def bdg_hamiltonian(self, k: npt.NDArray[np.float64]) -> npt.NDArray[np.complex64]:
130
+ """
131
+ Bogoliuobov de Genne Hamiltonian.
132
+
133
+ Parameters
134
+ ----------
135
+ k : :class:`numpy.ndarray`
136
+ List of k points.
137
+
138
+ Returns
139
+ -------
140
+ :class:`numpy.ndarray`
141
+ BdG Hamiltonian.
142
+
143
+ """
144
+ assert _check_valid_array(k)
145
+ if k.ndim == 1:
146
+ k = np.expand_dims(k, axis=0)
147
+
148
+ h = np.zeros(
149
+ (k.shape[0], 2 * self.number_of_bands, 2 * self.number_of_bands), dtype=np.complex64
150
+ )
151
+
152
+ h[:, 0 : self.number_of_bands, 0 : self.number_of_bands] = self.hamiltonian(k)
153
+ h[
154
+ :,
155
+ self.number_of_bands : 2 * self.number_of_bands,
156
+ self.number_of_bands : 2 * self.number_of_bands,
157
+ ] = -self.hamiltonian(-k).conjugate()
158
+
159
+ for i in range(self.number_of_bands):
160
+ h[:, self.number_of_bands + i, i] = self.delta_orbital_basis[i]
161
+ h[:, 0:2, 2:4] = h[:, 2:4, 0:2].copy().conjugate()
162
+
163
+ return h.squeeze()
164
+
165
+ def bdg_hamiltonian_derivative(
166
+ self, k: npt.NDArray[np.float64], direction: str
167
+ ) -> npt.NDArray[np.complex64]:
168
+ """
169
+ Deriative of the BdG Hamiltonian.
170
+
171
+ Parameters
172
+ ----------
173
+ k: :class:`numpy.ndarray`
174
+ List of k points.
175
+ direction: str
176
+ Direction for derivative, either 'x' oder 'y'.
177
+
178
+ Returns
179
+ -------
180
+ :class:`numpy.ndarray`
181
+ Derivative of Hamiltonian.
182
+
183
+ """
184
+ assert _check_valid_array(k)
185
+ if k.ndim == 1:
186
+ k = np.expand_dims(k, axis=0)
187
+
188
+ h = np.zeros(
189
+ (k.shape[0], 2 * self.number_of_bands, 2 * self.number_of_bands), dtype=np.complex64
190
+ )
191
+
192
+ h[:, 0 : self.number_of_bands, 0 : self.number_of_bands] = self.hamiltonian_derivative(
193
+ k, direction
194
+ )
195
+ h[
196
+ :,
197
+ self.number_of_bands : 2 * self.number_of_bands,
198
+ self.number_of_bands : 2 * self.number_of_bands,
199
+ ] = -self.hamiltonian_derivative(-k, direction).conjugate()
200
+
201
+ return h.squeeze()
202
+
203
+ def diagonalize_nonint(
204
+ self, k: npt.NDArray[np.float64]
205
+ ) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]:
206
+ """
207
+ Diagonalize the normal state Hamiltonian.
208
+
209
+ Parameters
210
+ ----------
211
+ k : :class:`numpy.ndarray`
212
+ List of k points.
213
+
214
+ Returns
215
+ -------
216
+ :class:`numpy.ndarray`
217
+ Eigenvalues of the normal state Hamiltonian.
218
+ :class:`numpy.ndarray`
219
+ Diagonalising matrix of the normal state Hamiltonian.
220
+
221
+ """
222
+ k_point_matrix = self.hamiltonian(k)
223
+ if k_point_matrix.ndim == 2:
224
+ k_point_matrix = np.expand_dims(k_point_matrix, axis=0)
225
+ k = np.expand_dims(k, axis=0)
226
+
227
+ bloch_wavefunctions = np.zeros(
228
+ (len(k), self.number_of_bands, self.number_of_bands),
229
+ dtype=complex,
230
+ )
231
+ band_energies = np.zeros((len(k), self.number_of_bands))
232
+
233
+ for i in range(len(k)):
234
+ band_energies[i], bloch_wavefunctions[i] = np.linalg.eigh(k_point_matrix[i])
235
+
236
+ return band_energies.squeeze(), bloch_wavefunctions.squeeze()
237
+
238
+ def diagonalize_bdg(
239
+ self, k: npt.NDArray[np.float64]
240
+ ) -> tuple[npt.NDArray[np.float64], npt.NDArray[np.complex64]]:
241
+ """
242
+ Diagonalize the BdG Hamiltonian.
243
+
244
+ Parameters
245
+ ----------
246
+ k : :class:`numpy.ndarray`
247
+ List of k points.
248
+
249
+ Returns
250
+ -------
251
+ :class:`numpy.ndarray`
252
+ Eigenvalues of the BdG Hamiltonian.
253
+ :class:`numpy.ndarray`
254
+ Diagonalising matrix of the BdG Hamiltonian.
255
+
256
+ """
257
+ bdg_matrix = self.bdg_hamiltonian(k)
258
+ if bdg_matrix.ndim == 2:
259
+ bdg_matrix = np.expand_dims(bdg_matrix, axis=0)
260
+ k = np.expand_dims(k, axis=0)
261
+
262
+ bdg_wavefunctions = np.zeros(
263
+ (len(k), 2 * self.number_of_bands, 2 * self.number_of_bands),
264
+ dtype=np.complex64,
265
+ )
266
+ bdg_energies = np.zeros((len(k), 2 * self.number_of_bands))
267
+
268
+ for i in range(len(k)):
269
+ bdg_energies[i], bdg_wavefunctions[i] = np.linalg.eigh(bdg_matrix[i])
270
+
271
+ return bdg_energies.squeeze(), bdg_wavefunctions.squeeze()
272
+
273
+ def calculate_bandstructure(
274
+ self,
275
+ k: npt.NDArray[np.float64],
276
+ overlaps: tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]] | None = None,
277
+ ) -> pd.DataFrame:
278
+ """
279
+ Calculate the band structure.
280
+
281
+ Parameters
282
+ ----------
283
+ k : :class:`numpy.ndarray`
284
+ List of k points.
285
+ overlaps : tuple(:class:`numpy.ndarray`, :class:`numpy.ndarray`), optional
286
+ Overlaps.
287
+
288
+ Returns
289
+ -------
290
+ `pandas.DataFrame`
291
+ Band structure.
292
+
293
+ """
294
+ results = pd.DataFrame(
295
+ index=range(len(k)),
296
+ dtype=float,
297
+ )
298
+ energies, wavefunctions = self.diagonalize_nonint(k)
299
+
300
+ for i, (energy_k, wavefunction_k) in enumerate(zip(energies, wavefunctions, strict=False)):
301
+ for band_index in range(self.number_of_bands):
302
+ results.loc[i, f"band_{band_index}"] = energy_k[band_index]
303
+
304
+ if overlaps is not None:
305
+ results.loc[i, f"wx_{band_index}"] = (
306
+ np.abs(np.dot(wavefunction_k[:, band_index], overlaps[0])) ** 2
307
+ - np.abs(np.dot(wavefunction_k[:, band_index], overlaps[1])) ** 2
308
+ )
309
+
310
+ return results