phono3py 4.12.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.
Files changed (83) hide show
  1. phono3py/__init__.py +26 -0
  2. phono3py/_lang.py +124 -0
  3. phono3py/_version.py +24 -0
  4. phono3py/api_isotope.py +243 -0
  5. phono3py/api_jointdos.py +415 -0
  6. phono3py/api_phono3py.py +3339 -0
  7. phono3py/conductivity/__init__.py +42 -0
  8. phono3py/conductivity/build_components.py +349 -0
  9. phono3py/conductivity/calculators.py +1212 -0
  10. phono3py/conductivity/collision_matrix_kernel.py +1538 -0
  11. phono3py/conductivity/exceptions.py +9 -0
  12. phono3py/conductivity/factory.py +550 -0
  13. phono3py/conductivity/grid_point_data.py +290 -0
  14. phono3py/conductivity/heat_capacity_solvers.py +273 -0
  15. phono3py/conductivity/ibdb19/__init__.py +19 -0
  16. phono3py/conductivity/interband_kappa_formula.py +90 -0
  17. phono3py/conductivity/interband_kappa_solvers.py +385 -0
  18. phono3py/conductivity/interband_variant.py +142 -0
  19. phono3py/conductivity/kappa_solvers.py +243 -0
  20. phono3py/conductivity/lbte_collision_solver.py +182 -0
  21. phono3py/conductivity/lbte_init.py +667 -0
  22. phono3py/conductivity/njc23/__init__.py +13 -0
  23. phono3py/conductivity/output.py +484 -0
  24. phono3py/conductivity/protocols.py +137 -0
  25. phono3py/conductivity/rta_init.py +446 -0
  26. phono3py/conductivity/scattering_solvers.py +1076 -0
  27. phono3py/conductivity/utils.py +474 -0
  28. phono3py/conductivity/velocity_solvers.py +282 -0
  29. phono3py/cui/create_force_constants.py +384 -0
  30. phono3py/cui/create_force_sets.py +548 -0
  31. phono3py/cui/create_supercells.py +199 -0
  32. phono3py/cui/kaccum_script.py +564 -0
  33. phono3py/cui/kdeplot_script.py +400 -0
  34. phono3py/cui/load.py +729 -0
  35. phono3py/cui/phono3py_argparse.py +1211 -0
  36. phono3py/cui/phono3py_script.py +1693 -0
  37. phono3py/cui/settings.py +982 -0
  38. phono3py/cui/show_log.py +249 -0
  39. phono3py/cui/triplets_info.py +145 -0
  40. phono3py/file_IO.py +1975 -0
  41. phono3py/interface/calculator.py +83 -0
  42. phono3py/interface/fc_calculator.py +320 -0
  43. phono3py/interface/phono3py_yaml.py +694 -0
  44. phono3py/interface/wien2k.py +37 -0
  45. phono3py/other/isotope.py +857 -0
  46. phono3py/phonon/degeneracy.py +63 -0
  47. phono3py/phonon/func.py +81 -0
  48. phono3py/phonon/heat_capacity_matrix.py +178 -0
  49. phono3py/phonon/solver.py +555 -0
  50. phono3py/phonon3/collision_matrix.py +357 -0
  51. phono3py/phonon3/dataset.py +97 -0
  52. phono3py/phonon3/displacement_fc3.py +465 -0
  53. phono3py/phonon3/fc3.py +1107 -0
  54. phono3py/phonon3/gruneisen.py +559 -0
  55. phono3py/phonon3/imag_self_energy.py +1433 -0
  56. phono3py/phonon3/interaction.py +1298 -0
  57. phono3py/phonon3/joint_dos.py +545 -0
  58. phono3py/phonon3/real_self_energy.py +838 -0
  59. phono3py/phonon3/real_to_reciprocal.py +239 -0
  60. phono3py/phonon3/reciprocal_to_normal.py +141 -0
  61. phono3py/phonon3/spectral_function.py +411 -0
  62. phono3py/phonon3/triplets.py +633 -0
  63. phono3py/phonon4/api_phono4py.py +450 -0
  64. phono3py/phonon4/dataset.py +161 -0
  65. phono3py/phonon4/displacement_fc4.py +360 -0
  66. phono3py/phonon4/fc4.py +735 -0
  67. phono3py/phonon4/file_IO.py +147 -0
  68. phono3py/phonon4/frequency_shift.py +292 -0
  69. phono3py/phonon4/phono4py_yaml.py +234 -0
  70. phono3py/phonon4/real_to_reciprocal.py +129 -0
  71. phono3py/scripts/phono3py.py +13 -0
  72. phono3py/scripts/phono3py_coleigplot.py +163 -0
  73. phono3py/scripts/phono3py_init.py +13 -0
  74. phono3py/scripts/phono3py_kaccum.py +9 -0
  75. phono3py/scripts/phono3py_kdeplot.py +8 -0
  76. phono3py/scripts/phono3py_load.py +15 -0
  77. phono3py/sscha/sscha.py +574 -0
  78. phono3py-4.12.0.dist-info/METADATA +80 -0
  79. phono3py-4.12.0.dist-info/RECORD +83 -0
  80. phono3py-4.12.0.dist-info/WHEEL +5 -0
  81. phono3py-4.12.0.dist-info/entry_points.txt +7 -0
  82. phono3py-4.12.0.dist-info/licenses/LICENSE +26 -0
  83. phono3py-4.12.0.dist-info/top_level.txt +1 -0
phono3py/__init__.py ADDED
@@ -0,0 +1,26 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """Shortcuts to important classes, methods, and variables."""
3
+
4
+ from importlib.metadata import PackageNotFoundError
5
+ from importlib.metadata import version as _package_version
6
+
7
+ try:
8
+ __version__ = _package_version("phono3py")
9
+ except PackageNotFoundError: # running from a source tree without an install
10
+ try:
11
+ from phono3py._version import __version__
12
+ except ImportError:
13
+ __version__ = "0.0.0"
14
+
15
+ from phono3py.api_isotope import Phono3pyIsotope
16
+ from phono3py.api_jointdos import Phono3pyJointDos
17
+ from phono3py.api_phono3py import Phono3py
18
+ from phono3py.cui.load import load
19
+
20
+ __all__ = [
21
+ "Phono3pyIsotope",
22
+ "Phono3pyJointDos",
23
+ "Phono3py",
24
+ "load",
25
+ "__version__",
26
+ ]
phono3py/_lang.py ADDED
@@ -0,0 +1,124 @@
1
+ """Dispatch logging and backend resolution for the C/Rust switch.
2
+
3
+ The dedicated ``phono3py.lang`` logger records which backend is selected
4
+ when a lang-aware routine is entered. It stays silent by default.
5
+
6
+ To see the messages, either:
7
+
8
+ * set the environment variable ``PHONO3PY_TRACE_LANG=1`` before running
9
+ (this configures a ``StreamHandler`` to stderr at DEBUG level), or
10
+ * configure ``logging.getLogger("phono3py.lang")`` from client code.
11
+
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import logging
17
+ import os
18
+ from typing import Literal
19
+
20
+ _logger = logging.getLogger("phono3py.lang")
21
+
22
+ if os.environ.get("PHONO3PY_TRACE_LANG"):
23
+ if not _logger.handlers:
24
+ _handler = logging.StreamHandler()
25
+ _handler.setFormatter(logging.Formatter("[phono3py.lang] %(message)s"))
26
+ _logger.addHandler(_handler)
27
+ _logger.setLevel(logging.DEBUG)
28
+
29
+
30
+ def log_dispatch(lang: str, name: str) -> None:
31
+ """Emit a dispatch-level trace line for a lang-aware call site."""
32
+ _logger.debug("dispatch name=%s lang=%s", name, lang)
33
+
34
+
35
+ def have_c_ext() -> bool:
36
+ """Return True when the ``phono3py._phono3py`` C extension is importable."""
37
+ try:
38
+ import phono3py._phono3py # noqa: F401 # type: ignore[import-untyped]
39
+ except ImportError:
40
+ return False
41
+ return True
42
+
43
+
44
+ def have_phonors() -> bool:
45
+ """Return True when the ``phonors`` Rust extension is importable."""
46
+ try:
47
+ import phonors # noqa: F401 # type: ignore[import-untyped]
48
+ except ImportError:
49
+ return False
50
+ return True
51
+
52
+
53
+ def c_omp_max_threads() -> int:
54
+ """Return ``phono3c.omp_max_threads()`` or ``0`` if C extension is absent."""
55
+ try:
56
+ import phono3py._phono3py as phono3c # type: ignore[import-untyped]
57
+ except ImportError:
58
+ return 0
59
+ return int(phono3c.omp_max_threads())
60
+
61
+
62
+ def c_include_lapacke() -> bool:
63
+ """Return ``phono3c.include_lapacke()`` or ``False`` if C extension is absent."""
64
+ try:
65
+ import phono3py._phono3py as phono3c # type: ignore[import-untyped]
66
+ except ImportError:
67
+ return False
68
+ return bool(phono3c.include_lapacke())
69
+
70
+
71
+ def c_default_colmat_solver() -> int:
72
+ """Return ``phono3c.default_colmat_solver()`` or ``4`` if C extension is absent.
73
+
74
+ ``4`` is the historical fallback used when the C extension cannot be
75
+ queried (numpy.linalg.eigh path).
76
+
77
+ """
78
+ try:
79
+ import phono3py._phono3py as phono3c # type: ignore[import-untyped]
80
+ except ImportError:
81
+ return 4
82
+ return int(phono3c.default_colmat_solver())
83
+
84
+
85
+ _fallback_warned = False
86
+
87
+
88
+ def resolve_lang(lang: Literal["C", "Rust"]) -> Literal["C", "Rust"]:
89
+ """Pick the best available backend, falling back from C to Rust.
90
+
91
+ When ``lang == "C"`` but the C extension is not installed (``pip
92
+ install`` does not build it), flip to ``"Rust"`` and emit a one-time
93
+ informational message. Raise ``ImportError`` if neither backend is
94
+ available, or if Rust is requested without ``phonors`` installed.
95
+
96
+ """
97
+ global _fallback_warned
98
+
99
+ if lang == "Rust":
100
+ if not have_phonors():
101
+ raise ImportError(
102
+ "lang='Rust' was requested but the `phonors` package is not "
103
+ "installed. Install it (e.g. `pip install phonors`) or use "
104
+ "lang='C'."
105
+ )
106
+ return "Rust"
107
+
108
+ if have_c_ext():
109
+ return "C"
110
+
111
+ if have_phonors():
112
+ if not _fallback_warned:
113
+ print(
114
+ "[phono3py] C extension `phono3py._phono3py` is not available; "
115
+ "falling back to lang='Rust' via the `phonors` package."
116
+ )
117
+ _fallback_warned = True
118
+ return "Rust"
119
+
120
+ raise ImportError(
121
+ "Neither the `phono3py._phono3py` C extension nor the `phonors` Rust "
122
+ "package is importable. Reinstall phono3py with C support, or "
123
+ "install `phonors`."
124
+ )
phono3py/_version.py ADDED
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '4.12.0'
22
+ __version_tuple__ = version_tuple = (4, 12, 0)
23
+
24
+ __commit_id__ = commit_id = 'g204fe22ea'
@@ -0,0 +1,243 @@
1
+ # SPDX-License-Identifier: BSD-3-Clause
2
+ """API for isotope scattering."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import warnings
7
+ from collections.abc import Sequence
8
+ from typing import Literal
9
+
10
+ import numpy as np
11
+ from numpy.typing import NDArray
12
+ from phonopy.harmonic.dynamical_matrix import DynamicalMatrix
13
+ from phonopy.phonon.grid import BZGrid
14
+ from phonopy.physical_units import get_physical_units
15
+ from phonopy.structure.atoms import PhonopyAtoms
16
+ from phonopy.structure.cells import Primitive
17
+
18
+ from phono3py.other.isotope import Isotope
19
+
20
+
21
+ class Phono3pyIsotope:
22
+ """Class to calculate isotope scattering."""
23
+
24
+ def __init__(
25
+ self,
26
+ mesh: float | Sequence[int] | Sequence[Sequence[int]] | NDArray[np.int64],
27
+ primitive: Primitive,
28
+ mass_variances: Sequence[float] | NDArray[np.double] | None = None,
29
+ band_indices: Sequence[int] | NDArray[np.int64] | None = None,
30
+ sigmas: Sequence[float | None] | None = None,
31
+ frequency_factor_to_THz: float | None = None,
32
+ use_grg: bool = False,
33
+ symprec: float = 1e-5,
34
+ cutoff_frequency: float | None = None,
35
+ lapack_zheev_uplo: Literal["L", "U"] | None = None,
36
+ symmetrize_tetrahedra: bool = False,
37
+ average_degenerate_weights: bool = False,
38
+ exclude_gamma_acoustic: bool = False,
39
+ use_two_sided_weights: bool = False,
40
+ lang: Literal["C", "Python", "Rust"] = "Rust",
41
+ ) -> None:
42
+ """Init method.
43
+
44
+ Parameters
45
+ ----------
46
+ mesh : float or array_like
47
+ Sampling mesh, given as a length, three mesh numbers, or a grid
48
+ matrix. shape=(3,) or (3, 3).
49
+ primitive : Primitive
50
+ Primitive cell.
51
+ mass_variances : array_like, optional
52
+ Mass variance of each atom in the primitive cell,
53
+ sum_i f_i (1 - m_i / m_ave)^2 over the isotopes i with fraction f_i
54
+ and mass m_i. If None, computed from phonopy's isotope data.
55
+ shape=(atoms,), dtype='double'
56
+ band_indices : array_like, optional
57
+ Bands at which the scattering rate is calculated. If None, all
58
+ bands. shape=(bands,), dtype='int64'
59
+ sigmas : list of float or None, optional
60
+ Widths of the Gaussian smearing in THz, one calculation for each.
61
+ None in the list means the tetrahedron method. If None, [None].
62
+ frequency_factor_to_THz : float, optional
63
+ Deprecated and will be removed in v5.0. Passing a non-None value
64
+ emits a ``DeprecationWarning``. If None,
65
+ ``get_physical_units().DefaultToTHz``.
66
+ use_grg : bool, optional, default=False
67
+ Use a generalized regular grid.
68
+ symprec : float, optional, default=1e-5
69
+ Tolerance of the symmetry search.
70
+ cutoff_frequency : float, optional
71
+ Phonon modes with frequency below this value in THz are left out.
72
+ If None, 0.
73
+ lapack_zheev_uplo : str, optional
74
+ Deprecated and will be removed in v5.0. 'L' or 'U' passed to the
75
+ LAPACK zheev phonon solver. Passing it emits a
76
+ ``DeprecationWarning``. If None, 'L'.
77
+ symmetrize_tetrahedra : bool, optional, default=False
78
+ When True, the integration weights of the tetrahedron method are
79
+ averaged over the 24 tetrahedra rotated by all the point-group
80
+ operations. The 24 tetrahedra are cut along one main diagonal, so
81
+ the weights can differ between symmetrically equivalent q-points.
82
+ Averaging removes the difference. Not available with
83
+ ``lang='C'``.
84
+ average_degenerate_weights : bool, optional, default=False
85
+ When True, the integration weights of the tetrahedron method are
86
+ averaged over each set of degenerate bands, see ``Isotope``. Used
87
+ only with the tetrahedron method (``sigma=None``).
88
+ exclude_gamma_acoustic : bool, optional, default=False
89
+ When True, the frequencies of the three modes at Gamma with the
90
+ smallest absolute values are set to zero after the phonons are
91
+ solved. The acoustic modes at Gamma are then zero on every
92
+ platform, instead of small nonzero values from rounding.
93
+ use_two_sided_weights : bool, optional, default=False
94
+ When True, the integration weights of the tetrahedron method are
95
+ the mean of those at the frequency points shifted by -1e-12 and
96
+ +1e-12 THz, see ``Isotope``. Used only with the tetrahedron method
97
+ (``sigma=None``).
98
+ lang : str, optional, default='Rust'
99
+ Backend, 'C', 'Python' or 'Rust'.
100
+
101
+ """
102
+ self._sigmas: Sequence[float | None]
103
+ if sigmas is None:
104
+ self._sigmas = [None]
105
+ else:
106
+ self._sigmas = sigmas
107
+
108
+ # REMOVE-AT-V5
109
+ if frequency_factor_to_THz is None:
110
+ _frequency_factor_to_THz = get_physical_units().DefaultToTHz
111
+ else:
112
+ warnings.warn(
113
+ "frequency_factor_to_THz parameter is deprecated and will be "
114
+ "removed in v5.0.",
115
+ DeprecationWarning,
116
+ stacklevel=2,
117
+ )
118
+ _frequency_factor_to_THz = frequency_factor_to_THz
119
+
120
+ # REMOVE-AT-V5
121
+ if lapack_zheev_uplo is None:
122
+ _lapack_zheev_uplo: Literal["L", "U"] = "L"
123
+ else:
124
+ warnings.warn(
125
+ "lapack_zheev_uplo parameter is deprecated and will be "
126
+ "removed in v5.0.",
127
+ DeprecationWarning,
128
+ stacklevel=2,
129
+ )
130
+ _lapack_zheev_uplo = lapack_zheev_uplo
131
+
132
+ self._iso = Isotope(
133
+ mesh,
134
+ primitive,
135
+ mass_variances=mass_variances,
136
+ band_indices=band_indices,
137
+ frequency_factor_to_THz=_frequency_factor_to_THz, # REMOVE-AT-V5
138
+ use_grg=use_grg,
139
+ symprec=symprec,
140
+ cutoff_frequency=cutoff_frequency,
141
+ lapack_zheev_uplo=_lapack_zheev_uplo, # REMOVE-AT-V5
142
+ symmetrize_tetrahedra=symmetrize_tetrahedra,
143
+ average_degenerate_weights=average_degenerate_weights,
144
+ exclude_gamma_acoustic=exclude_gamma_acoustic,
145
+ use_two_sided_weights=use_two_sided_weights,
146
+ lang=lang,
147
+ )
148
+
149
+ @property
150
+ def dynamical_matrix(self) -> DynamicalMatrix | None:
151
+ """Return dynamical matrix class instance."""
152
+ return self._iso.dynamical_matrix
153
+
154
+ @property
155
+ def grid(self) -> BZGrid:
156
+ """Return BZGrid class instance."""
157
+ return self._iso.bz_grid
158
+
159
+ @property
160
+ def gamma(self) -> NDArray[np.double]:
161
+ """Return calculated isotope scattering."""
162
+ return self._gamma
163
+
164
+ @property
165
+ def frequencies(self) -> NDArray[np.double]:
166
+ """Return phonon frequencies at grid points."""
167
+ assert self._iso.phonons is not None
168
+ return self._iso.phonons.frequencies[self._grid_points] # type: ignore[index]
169
+
170
+ @property
171
+ def grid_points(self) -> NDArray[np.int64]:
172
+ """Return grid points in BZ-grid."""
173
+ return self._grid_points
174
+
175
+ def run(
176
+ self,
177
+ grid_points: Sequence[int] | NDArray[np.int64],
178
+ ) -> None:
179
+ """Calculate isotope scattering.
180
+
181
+ The backend is selected by ``self._iso._lang`` set at construction.
182
+
183
+ """
184
+ gamma = np.zeros(
185
+ (len(self._sigmas), len(grid_points), len(self._iso.band_indices)),
186
+ dtype="double",
187
+ )
188
+ self._grid_points = np.array(grid_points, dtype="int64")
189
+
190
+ for j, gp in enumerate(grid_points):
191
+ self._iso.set_grid_point(gp)
192
+
193
+ print("--------------- Isotope scattering ---------------")
194
+ print("Grid point: %d" % gp)
195
+ adrs = self._iso.bz_grid.addresses[gp]
196
+ bz_grid = self._iso.bz_grid
197
+ print(bz_grid.D_diag)
198
+ q = np.dot(adrs.astype("double") / bz_grid.D_diag, bz_grid.Q.T)
199
+ print("q-point: %s" % q)
200
+
201
+ if self._sigmas:
202
+ for i, sigma in enumerate(self._sigmas):
203
+ if sigma is None:
204
+ print("Tetrahedron method")
205
+ else:
206
+ print("Sigma: %s" % sigma)
207
+ self._iso.sigma = sigma
208
+ self._iso.run()
209
+ gamma[i, j] = self._iso.gamma
210
+ assert self._iso.phonons is not None
211
+ frequencies = self._iso.phonons.frequencies
212
+ print("")
213
+ print("Phonon-isotope scattering rate in THz (1/4pi-tau)")
214
+ print(" Frequency Rate")
215
+ for g, f in zip(self._iso.gamma, frequencies[gp], strict=True): # type: ignore[index, arg-type]
216
+ print("%8.3f %5.3e" % (f, g))
217
+ else:
218
+ print("sigma or tetrahedron method has to be set.")
219
+ self._gamma = gamma
220
+
221
+ def init_dynamical_matrix(
222
+ self,
223
+ fc2: NDArray[np.double],
224
+ supercell: PhonopyAtoms,
225
+ primitive: Primitive,
226
+ nac_params: dict | None = None,
227
+ frequency_scale_factor: float | None = None,
228
+ decimals: int | None = None,
229
+ ) -> None:
230
+ """Initialize dynamical matrix."""
231
+ self._primitive = primitive
232
+ self._iso.init_dynamical_matrix(
233
+ fc2,
234
+ supercell,
235
+ primitive,
236
+ nac_params=nac_params,
237
+ frequency_scale_factor=frequency_scale_factor,
238
+ decimals=decimals,
239
+ )
240
+
241
+ def set_sigma(self, sigma: float | None) -> None:
242
+ """Set sigma. None means tetrahedron method."""
243
+ self._iso.sigma = sigma