Skip to content

Commit 6f35553

Browse files
Refactor to only require pymatgen-core, and fix docs building (#224)
* Update imports to match latest ``pymatgen``, and update minimum version * Fix docs building issue * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 39765d5 commit 6f35553

14 files changed

Lines changed: 69 additions & 63 deletions

File tree

.github/workflows/testing.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
runs-on: ubuntu-latest
3535
strategy:
3636
matrix:
37-
python-version: ["3.10", "3.11", "3.12", "3.13"]
37+
python-version: ["3.11", "3.12", "3.13"]
3838

3939
env:
4040
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
@@ -59,7 +59,7 @@ jobs:
5959
run: pytest --nbmake ./docs/source/content
6060

6161
- uses: codecov/codecov-action@v4
62-
if: matrix.python-version == '3.10'
62+
if: matrix.python-version == '3.13'
6363
with:
6464
token: ${{ secrets.CODECOV_TOKEN }}
6565
file: ./coverage.xml
@@ -79,7 +79,7 @@ jobs:
7979

8080
- uses: actions/setup-python@v5
8181
with:
82-
python-version: "3.10"
82+
python-version: "3.13"
8383
cache: pip
8484
cache-dependency-path: pyproject.toml
8585

@@ -88,10 +88,7 @@ jobs:
8888
python -m pip install --upgrade pip
8989
pip install -e .[docs]
9090
- name: Build
91-
if: github.ref == 'refs/heads/develop'
92-
# This line below is wrong and needs to be updated
9391
run: jupyter-book build --path-output docs docs/source
94-
# Develop branch only
9592
- name: Deploy
9693
if: github.ref == 'refs/heads/main'
9794
uses: peaceiris/actions-gh-pages@v4

pymatgen/analysis/defects/ccd.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _parse_vasprun(vasprun: Vasprun) -> tuple[float, Structure]:
184184
energy_struct[-1],
185185
lambda x, y: get_dQ(x[1], y[1]),
186186
)
187-
energies, structures = list(zip(*sorted_list))
187+
energies, structures = list(zip(*sorted_list, strict=False))
188188

189189
if not np.allclose(unsorted_e, energies, atol=1e-99): # pragma: no cover
190190
msg = "The vaspruns should already be in order."
@@ -347,7 +347,8 @@ def read_wswqs(
347347
msg,
348348
)
349349
self.wswqs = [
350-
{"Q": d, "wswq": WSWQ.from_file(f)} for d, f in zip(distortions, wswq_files)
350+
{"Q": d, "wswq": WSWQ.from_file(f)}
351+
for d, f in zip(distortions, wswq_files, strict=False)
351352
]
352353

353354
def get_elph_me(self, defect_state: tuple) -> npt.ArrayLike:
@@ -574,7 +575,7 @@ def get_dQ(ground: Structure, excited: Structure) -> float:
574575
np.sum(
575576
[
576577
x[0].distance(x[1]) ** 2 * x[0].specie.atomic_mass
577-
for x in zip(ground, excited)
578+
for x in zip(ground, excited, strict=False)
578579
],
579580
),
580581
)
@@ -631,7 +632,12 @@ def _get_wswq_slope(distortions: list[float], wswqs: list[WSWQ]) -> npt.NDArray:
631632
Since there is always ambiguity in the phase, we require that the output
632633
is always positive.
633634
"""
634-
yy = np.stack([np.abs(ww.data) * np.sign(qq) for qq, ww in zip(distortions, wswqs)])
635+
yy = np.stack(
636+
[
637+
np.abs(ww.data) * np.sign(qq)
638+
for qq, ww in zip(distortions, wswqs, strict=False)
639+
]
640+
)
635641
_, *oldshape = yy.shape
636642
return np.polyfit(distortions, yy.reshape(yy.shape[0], -1), deg=1)[0].reshape(
637643
*oldshape,

pymatgen/analysis/defects/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
import numpy as np
1212
from monty.json import MSONable
1313
from pymatgen.analysis.defects.supercells import get_sc_fromstruct
14-
from pymatgen.analysis.structure_matcher import ElementComparator, StructureMatcher
1514
from pymatgen.core import Element, PeriodicSite, Species
1615
from pymatgen.core.periodic_table import DummySpecies
16+
from pymatgen.core.structure_matcher import ElementComparator, StructureMatcher
1717
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
1818

1919
from .utils import get_plane_spacing
2020

2121
if TYPE_CHECKING:
22+
from typing import Self
23+
2224
from numpy.typing import ArrayLike
2325
from pymatgen.core import Structure
2426
from pymatgen.symmetry.structure import SymmetrizedStructure
25-
from typing_extensions import Self
2627

2728
# TODO Possible redesign idea: ``DefectSite`` class defined with a defect object.
2829
# This makes some of the accounting logic a bit harder since we will probably

pymatgen/analysis/defects/corrections/freysoldt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def get_freysoldt_correction(
162162
list_bulk_plnr_avg_esp,
163163
list_defect_plnr_avg_esp,
164164
[0, 1, 2],
165+
strict=False,
165166
):
166167
alignment_corr, md = perform_pot_corr(
167168
axis_grid=x,

pymatgen/analysis/defects/finder.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ def get_native_defect_position(
124124
(in fractional coordinates)
125125
"""
126126
distored_sites, distortions = list(
127-
zip(*self.get_most_distorted_sites(defect_structure, base_structure)),
127+
zip(
128+
*self.get_most_distorted_sites(defect_structure, base_structure),
129+
strict=False,
130+
),
128131
)
129132
positions = [defect_structure[isite].frac_coords for isite in distored_sites]
130133
return get_weighted_average_position(
@@ -370,7 +373,7 @@ def get_weighted_average_position(
370373
raise ValueError(msg)
371374

372375
# TODO: can be replaced with the zip(..., strict=True) syntax in Python 3.10
373-
pos_weights = list(zip(frac_positions, weights))
376+
pos_weights = list(zip(frac_positions, weights, strict=False))
374377
pos_weights.sort(key=lambda x: x[1], reverse=True)
375378

376379
# initial guess at the center with zero weight

pymatgen/analysis/defects/generators.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ def generate( # type: ignore[override]
388388
raise ValueError(msg)
389389
cand_sites_mul_and_equiv_fpos = [*self._get_candidate_sites(structure)]
390390
for species in insert_species:
391-
cand_sites, multiplicity, equiv_fpos = zip(*cand_sites_mul_and_equiv_fpos)
391+
cand_sites, multiplicity, equiv_fpos = zip(
392+
*cand_sites_mul_and_equiv_fpos, strict=False
393+
)
392394

393395
yield from super().generate(
394396
structure,
@@ -490,7 +492,9 @@ def generate( # type: ignore[override]
490492
raise ValueError(msg)
491493
cand_sites_mul_and_equiv_fpos = [*self._get_candidate_sites(chgcar)]
492494
for species in insert_species:
493-
cand_sites, multiplicity, equiv_fpos = zip(*cand_sites_mul_and_equiv_fpos)
495+
cand_sites, multiplicity, equiv_fpos = zip(
496+
*cand_sites_mul_and_equiv_fpos, strict=False
497+
)
494498
if self.max_insertions is not None:
495499
cand_sites = cand_sites[: self.max_insertions]
496500
multiplicity = multiplicity[: self.max_insertions]

pymatgen/analysis/defects/plotting/thermo.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _plot_line(
5959
Returns:
6060
None, modifies the fig object in place.
6161
"""
62-
x_pos, y_pos = tuple(zip(*pts))
62+
x_pos, y_pos = tuple(zip(*pts, strict=False))
6363
trace_ = go.Scatter(
6464
x=x_pos,
6565
y=y_pos,
@@ -108,13 +108,13 @@ def _label_slopes(fig: go.Figure) -> None:
108108
fig: A plotly figure object.
109109
"""
110110
for data_ in filter(lambda x: x.meta.get("formation_energy_plot", False), fig.data):
111-
transitions_arr_ = np.array(tuple(zip(data_.x, data_.y)))
111+
transitions_arr_ = np.array(tuple(zip(data_.x, data_.y, strict=False)))
112112
diff_arr = transitions_arr_[1:] - transitions_arr_[:-1]
113113
slopes = tuple(
114114
int(slope) for slope in np.round(diff_arr[:, 1] / diff_arr[:, 0])
115115
)
116116
pos = (transitions_arr_[:-1] + transitions_arr_[1:]) / 2.0
117-
x_pos, y_pos = tuple(zip(*pos))
117+
x_pos, y_pos = tuple(zip(*pos, strict=False))
118118
fig.add_trace(
119119
go.Scatter(
120120
x=x_pos,
@@ -203,6 +203,7 @@ def get_plot_data(
203203
grouped_feds,
204204
get_line_style_and_color_sequence(PLOTLY_COLORS, PLOTLY_STYLES),
205205
x_annos_,
206+
strict=False,
206207
):
207208
if chempot is None:
208209
cation_el_ = fed.chempot_diagram.elements[0]

pymatgen/analysis/defects/recombination.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
import itertools
99
import logging
10-
from typing import TYPE_CHECKING, Callable
10+
from typing import TYPE_CHECKING
1111

1212
import numpy as np
1313
from scipy.interpolate import PchipInterpolator
1414

1515
from .constants import AMU2KG, ANGS2M, EV2J, HBAR_EV, HBAR_J, KB, LOOKUP_TABLE
1616

17+
if TYPE_CHECKING:
18+
from collections.abc import Callable
19+
1720
_logger = logging.getLogger(__name__)
1821

1922
try:

pymatgen/analysis/defects/supercells.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import numpy as np
1010
from monty.dev import deprecated
11-
from pymatgen.analysis.structure_matcher import ElementComparator, StructureMatcher
1211
from pymatgen.core import Lattice
12+
from pymatgen.core.structure_matcher import ElementComparator, StructureMatcher
1313
from pymatgen.util.coord_cython import pbc_shortest_vectors
1414

1515
# from ase.build import find_optimal_cell_shape, get_deviation_from_optimal_cell_shape

pymatgen/analysis/defects/thermo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dataclasses import dataclass, field
88
from itertools import chain, groupby
99
from pathlib import Path
10-
from typing import TYPE_CHECKING, Any, Callable
10+
from typing import TYPE_CHECKING, Any
1111

1212
import numpy as np
1313
from matplotlib import pyplot as plt
@@ -20,18 +20,18 @@
2020
from pymatgen.analysis.defects.supercells import get_closest_sc_mat
2121
from pymatgen.analysis.defects.utils import get_zfile, group_docs
2222
from pymatgen.analysis.phase_diagram import PhaseDiagram
23-
from pymatgen.analysis.structure_matcher import ElementComparator, StructureMatcher
2423
from pymatgen.core import Composition, Element
24+
from pymatgen.core.entries import ComputedEntry
25+
from pymatgen.core.structure_matcher import ElementComparator, StructureMatcher
2526
from pymatgen.electronic_structure.dos import FermiDos
26-
from pymatgen.entries.computed_entries import ComputedEntry
2727
from pymatgen.io.vasp import Locpot, Vasprun, VolumetricData
2828
from pyrho.charge_density import get_volumetric_like_sc
2929
from scipy.constants import value as _cd
3030
from scipy.optimize import bisect
3131
from scipy.spatial import ConvexHull
3232

3333
if TYPE_CHECKING:
34-
from collections.abc import Generator, Sequence
34+
from collections.abc import Callable, Generator, Sequence
3535

3636
from matplotlib.axes import Axes
3737
from numpy.typing import ArrayLike, NDArray
@@ -523,7 +523,7 @@ def _vbm_formation_energy(self, defect_entry: DefectEntry, chempots: dict) -> fl
523523
def chempot_limits(self) -> list[dict[Element, float]]:
524524
"""Return the chemical potential limits in dictionary format."""
525525
return [
526-
dict(zip(self.chempot_diagram.elements, vertex))
526+
dict(zip(self.chempot_diagram.elements, vertex, strict=False))
527527
for vertex in self._chempot_limits_arr
528528
]
529529

@@ -535,7 +535,9 @@ def competing_phases(self) -> list[dict[str, ComputedEntry]]:
535535
res = []
536536
for pt in self._chempot_limits_arr:
537537
competing_phases = {}
538-
for hp_ent, hp in zip(cd._hyperplane_entries, cd._hyperplanes):
538+
for hp_ent, hp in zip(
539+
cd._hyperplane_entries, cd._hyperplanes, strict=False
540+
):
539541
if hp_ent.composition.reduced_formula == bulk_formula:
540542
continue
541543
if _is_on_hyperplane(pt, hp):

0 commit comments

Comments
 (0)