Skip to content

Commit b406c01

Browse files
authored
Merge branch 'master' into cleanup-test-files
2 parents 1930d8b + 4adc00f commit b406c01

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+388
-262
lines changed

.github/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ changelog:
1414
labels: [housekeeping]
1515
- title: 🚀 Performance
1616
labels: [performance]
17+
- title: 🚧 CI
18+
labels: [ci]
1719
- title: 💡 Refactoring
1820
labels: [refactor]
1921
- title: 🧪 Tests

docs/CHANGES.md

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pymatgen/analysis/chempot_diagram.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ def __init__(
103103
renormalized_entries = []
104104
for entry in entries:
105105
comp_dict = entry.composition.as_dict()
106-
renormalization_energy = sum(
107-
[comp_dict[el] * _el_refs[Element(el)].energy_per_atom for el in comp_dict]
108-
)
106+
renormalization_energy = sum(comp_dict[el] * _el_refs[Element(el)].energy_per_atom for el in comp_dict)
109107
renormalized_entries.append(_renormalize_entry(entry, renormalization_energy / sum(comp_dict.values())))
110108

111109
entries = renormalized_entries

pymatgen/analysis/diffraction/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ def get_pattern(self, structure: Structure, scaled=True, two_theta_range=(0, 90)
6868
sphere of radius 2 / wavelength.
6969
7070
Returns:
71-
(DiffractionPattern)
71+
DiffractionPattern
7272
"""
73+
raise NotImplementedError
7374

7475
def get_plot(
7576
self,

pymatgen/analysis/diffraction/neutron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def get_pattern(self, structure: Structure, scaled=True, two_theta_range=(0, 90)
7979
sphere of radius 2 / wavelength.
8080
8181
Returns:
82-
(NDPattern)
82+
DiffractionPattern: ND pattern
8383
"""
8484
if self.symprec:
8585
finder = SpacegroupAnalyzer(structure, symprec=self.symprec)

pymatgen/analysis/diffraction/xrd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def get_pattern(self, structure: Structure, scaled=True, two_theta_range=(0, 90)
140140
sphere of radius 2 / wavelength.
141141
142142
Returns:
143-
(XRDPattern)
143+
DiffractionPattern: XRD pattern
144144
"""
145145
if self.symprec:
146146
finder = SpacegroupAnalyzer(structure, symprec=self.symprec)

pymatgen/analysis/ewald.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def get_site_energy(self, site_index):
291291
site_index (int): Index of site
292292
293293
Returns:
294-
(float) - Energy of that site
294+
float: Energy of that site
295295
"""
296296
if not self._initialized:
297297
self._calc_ewald_terms()

pymatgen/analysis/local_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ def _is_in_targets(site, targets):
11681168
targets ([Element]) List of elements
11691169
11701170
Returns:
1171-
(boolean) Whether this site contains a certain list of elements
1171+
boolean: Whether this site contains a certain list of elements
11721172
"""
11731173
elems = _get_elements(site)
11741174
return all(elem in targets for elem in elems)

pymatgen/analysis/structure_analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def sulfide_type(structure):
518518
structure (Structure): Input structure.
519519
520520
Returns:
521-
(str) sulfide/polysulfide or None if structure is a sulfate.
521+
str: sulfide/polysulfide or None if structure is a sulfate.
522522
"""
523523
structure = structure.copy().remove_oxidation_states()
524524
sulphur = Element("S")

pymatgen/analysis/surface_analysis.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __init__(
121121
"""
122122
self.miller_index = miller_index
123123
self.label = label
124-
self.adsorbates = adsorbates if adsorbates else []
124+
self.adsorbates = adsorbates or []
125125
self.clean_entry = clean_entry
126126
self.ads_entries_dict = {str(next(iter(ads.composition.as_dict()))): ads for ads in self.adsorbates}
127127
self.mark = marker
@@ -180,7 +180,7 @@ def surface_energy(self, ucell_entry, ref_entries=None):
180180
float: The surface energy of the slab.
181181
"""
182182
# Set up
183-
ref_entries = ref_entries if ref_entries else []
183+
ref_entries = ref_entries or []
184184

185185
# Check if appropriate ref_entries are present if the slab is non-stoichiometric
186186
# TODO: There should be a way to identify which specific species are
@@ -861,6 +861,7 @@ def chempot_vs_gamma_plot_one(
861861
"""
862862
delu_dict = delu_dict or {}
863863
chempot_range = sorted(chempot_range)
864+
ax = ax or plt.gca()
864865

865866
# use dashed lines for slabs that are not stoichiometric
866867
# w.r.t. bulk. Label with formula if non-stoichiometric
@@ -884,9 +885,10 @@ def chempot_vs_gamma_plot_one(
884885

885886
se_range = np.array(gamma_range) * EV_PER_ANG2_TO_JOULES_PER_M2 if JPERM2 else gamma_range
886887

887-
mark = entry.mark if entry.mark else mark
888-
c = entry.color if entry.color else self.color_dict[entry]
889-
return plt.plot(chempot_range, se_range, mark, color=c, label=label)
888+
mark = entry.mark or mark
889+
color = entry.color or self.color_dict[entry]
890+
ax.plot(chempot_range, se_range, mark, color=color, label=label)
891+
return ax
890892

891893
def chempot_vs_gamma(
892894
self,
@@ -941,7 +943,7 @@ def chempot_vs_gamma(
941943
delu_dict = {}
942944
chempot_range = sorted(chempot_range)
943945

944-
plt = plt if plt else pretty_plot(width=8, height=7)
946+
plt = plt or pretty_plot(width=8, height=7)
945947
axes = plt.gca()
946948

947949
for hkl in self.all_slab_entries:
@@ -1175,7 +1177,7 @@ def surface_chempot_range_map(
11751177
"""
11761178
# Set up
11771179
delu_dict = delu_dict or {}
1178-
ax = ax if ax else pretty_plot(12, 8)
1180+
ax = ax or pretty_plot(12, 8)
11791181
el1, el2 = str(elements[0]), str(elements[1])
11801182
delu1 = Symbol(f"delu_{elements[0]}")
11811183
delu2 = Symbol(f"delu_{elements[1]}")
@@ -1255,7 +1257,7 @@ def surface_chempot_range_map(
12551257
# Label the phases
12561258
x = np.mean([max(xvals), min(xvals)])
12571259
y = np.mean([max(yvals), min(yvals)])
1258-
label = entry.label if entry.label else entry.reduced_formula
1260+
label = entry.label or entry.reduced_formula
12591261
ax.annotate(label, xy=[x, y], xytext=[x, y], fontsize=fontsize)
12601262

12611263
# Label plot
@@ -1314,7 +1316,7 @@ def entry_dict_from_list(all_slab_entries):
13141316
hkl = tuple(entry.miller_index)
13151317
if hkl not in entry_dict:
13161318
entry_dict[hkl] = {}
1317-
clean = entry.clean_entry if entry.clean_entry else entry
1319+
clean = entry.clean_entry or entry
13181320
if clean not in entry_dict[hkl]:
13191321
entry_dict[hkl][clean] = []
13201322
if entry.adsorbates:
@@ -1425,7 +1427,7 @@ def get_locpot_along_slab_plot(self, label_energies=True, plt=None, label_fontsi
14251427
14261428
Returns plt of the locpot vs c axis
14271429
"""
1428-
plt = plt if plt else pretty_plot(width=6, height=4)
1430+
plt = plt or pretty_plot(width=6, height=4)
14291431

14301432
# plot the raw locpot signal along c
14311433
plt.plot(self.along_c, self.locpot_along_c, "b--")
@@ -1769,7 +1771,7 @@ def plot_one_stability_map(
17691771
label="",
17701772
increments=50,
17711773
delu_default=0,
1772-
plt=None,
1774+
ax=None,
17731775
from_sphere_area=False,
17741776
e_units="keV",
17751777
r_units="nanometers",
@@ -1797,8 +1799,11 @@ def plot_one_stability_map(
17971799
r_units (str): Can be nanometers or Angstrom
17981800
e_units (str): Can be keV or eV
17991801
normalize (str): Whether or not to normalize energy by volume
1802+
1803+
Returns:
1804+
plt.Axes: matplotlib Axes object
18001805
"""
1801-
plt = plt or pretty_plot(width=8, height=7)
1806+
ax = ax or pretty_plot(width=8, height=7)
18021807

18031808
wulff_shape = analyzer.wulff_from_chempot(delu_dict=delu_dict, delu_default=delu_default, symprec=self.symprec)
18041809

@@ -1818,21 +1823,21 @@ def plot_one_stability_map(
18181823
r_list.append(radius)
18191824

18201825
ru = "nm" if r_units == "nanometers" else r"\AA"
1821-
plt.xlabel(rf"Particle radius (${ru}$)")
1826+
ax.xlabel(rf"Particle radius (${ru}$)")
18221827
eu = f"${e_units}/{ru}^3$"
1823-
plt.ylabel(rf"$G_{{form}}$ ({eu})")
1828+
ax.ylabel(rf"$G_{{form}}$ ({eu})")
18241829

1825-
plt.plot(r_list, gform_list, label=label)
1830+
ax.plot(r_list, gform_list, label=label)
18261831

1827-
return plt
1832+
return ax
18281833

18291834
def plot_all_stability_map(
18301835
self,
18311836
max_r,
18321837
increments=50,
18331838
delu_dict=None,
18341839
delu_default=0,
1835-
plt=None,
1840+
ax=None,
18361841
labels=None,
18371842
from_sphere_area=False,
18381843
e_units="keV",
@@ -1857,17 +1862,20 @@ def plot_all_stability_map(
18571862
from_sphere_area (bool): There are two ways to calculate the bulk
18581863
formation energy. Either by treating the volume and thus surface
18591864
area of the particle as a perfect sphere, or as a Wulff shape.
1865+
1866+
Returns:
1867+
plt.Axes: matplotlib Axes object
18601868
"""
1861-
plt = plt or pretty_plot(width=8, height=7)
1869+
ax = ax or pretty_plot(width=8, height=7)
18621870

1863-
for i, analyzer in enumerate(self.se_analyzers):
1864-
label = labels[i] if labels else ""
1865-
plt = self.plot_one_stability_map(
1871+
for idx, analyzer in enumerate(self.se_analyzers):
1872+
label = labels[idx] if labels else ""
1873+
ax = self.plot_one_stability_map(
18661874
analyzer,
18671875
max_r,
18681876
delu_dict,
18691877
label=label,
1870-
plt=plt,
1878+
ax=ax,
18711879
increments=increments,
18721880
delu_default=delu_default,
18731881
from_sphere_area=from_sphere_area,
@@ -1877,7 +1885,7 @@ def plot_all_stability_map(
18771885
scale_per_atom=scale_per_atom,
18781886
)
18791887

1880-
return plt
1888+
return ax
18811889

18821890

18831891
def sub_chempots(gamma_dict, chempots):

pymatgen/analysis/wulff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def get_plot(
378378
Joules per square meter (True)
379379
380380
Returns:
381-
(matplotlib.pyplot)
381+
mpl_toolkits.mplot3d.Axes3D: 3D plot of the Wulff shape.
382382
"""
383383
from mpl_toolkits.mplot3d import art3d
384384

@@ -472,7 +472,7 @@ def get_plot(
472472
ax_3d.grid("off")
473473
if axis_off:
474474
ax_3d.axis("off")
475-
return plt
475+
return ax_3d
476476

477477
def get_plotly(
478478
self,

pymatgen/core/composition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ def reduce_formula(sym_amt, iupac_ordering: bool = False) -> tuple[str, float]:
11991199
the elements.
12001200
12011201
Returns:
1202-
(reduced_formula, factor).
1202+
tuple[str, float]: reduced formula and factor.
12031203
"""
12041204
syms = sorted(sym_amt, key=lambda x: [get_el_sp(x).X, x])
12051205

0 commit comments

Comments
 (0)