Skip to content

Commit 8284fdc

Browse files
committed
Merge remote-tracking branch 'upstream/master' into 4158-fix-eq-check
2 parents 95ec56a + 0d14d72 commit 8284fdc

File tree

246 files changed

+10129
-9017
lines changed

Some content is hidden

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

246 files changed

+10129
-9017
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ jobs:
5252
split: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
5353

5454
runs-on: ${{ matrix.config.os }}
55-
5655
env:
57-
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
5856
MPLBACKEND: Agg # non-interactive backend for matplotlib
59-
57+
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
58+
PYTHONWARNDEFAULTENCODING: "true" # PEP 597: Enable optional EncodingWarning
6059
steps:
6160
- name: Check out repo
6261
uses: actions/checkout@v4
@@ -106,6 +105,8 @@ jobs:
106105
107106
- name: pytest split ${{ matrix.split }}
108107
env:
108+
MPLBACKEND: Agg # non-interactive backend for matplotlib
109+
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
109110
PMG_TEST_FILES_DIR: "${{ github.workspace }}/tests/files"
110111
run: |
111112
micromamba activate pmg

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ci:
88

99
repos:
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.8.1
11+
rev: v0.9.0
1212
hooks:
1313
- id: ruff
1414
args: [--fix, --unsafe-fixes]
@@ -22,7 +22,7 @@ repos:
2222
- id: trailing-whitespace
2323

2424
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: v1.13.0
25+
rev: v1.14.1
2626
hooks:
2727
- id: mypy
2828

@@ -65,6 +65,6 @@ repos:
6565
args: [--drop-empty-cells, --keep-output]
6666

6767
- repo: https://github.com/RobertCraigie/pyright-python
68-
rev: v1.1.389
68+
rev: v1.1.391
6969
hooks:
7070
- id: pyright

dev_scripts/chemenv/explicit_permutations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ class Algo:
9393
cg._algorithms = [ExplicitPermutationsAlgorithm(permutations=explicit_permutations)]
9494
new_geom_dir = "new_geometry_files"
9595
os.makedirs(new_geom_dir, exist_ok=True)
96-
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w") as file:
96+
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
9797
json.dump(cg.as_dict(), file)

dev_scripts/chemenv/explicit_permutations_plane_algorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,5 @@
159159
if test == "y":
160160
cg._algorithms = new_algos
161161
cg_dict = cg.as_dict()
162-
with open(f"../coordination_geometries_files_new/{cg_symbol}.json", mode="w") as file:
162+
with open(f"../coordination_geometries_files_new/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
163163
json.dump(cg_dict, file)

dev_scripts/chemenv/get_plane_permutations_optimized.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,5 +444,5 @@ def random_permutations_iterator(initial_permutation, n_permutations):
444444
if test == "y":
445445
new_geom_dir = "new_geometry_files"
446446
os.makedirs(new_geom_dir, exist_ok=True)
447-
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w") as file:
447+
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
448448
json.dump(cg.as_dict(), file)

dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def get_structure(self, morphing_factor):
171171

172172
for morphing in self.morphing_description:
173173
if morphing["site_type"] != "neighbor":
174-
raise ValueError(f"Key \"site_type\" is {morphing['site_type']} while it can only be neighbor")
174+
raise ValueError(f'Key "site_type" is {morphing["site_type"]} while it can only be neighbor')
175175

176176
site_idx = morphing["ineighbor"] + 1
177177
if morphing["expansion_origin"] == "central_site":

dev_scripts/chemenv/view_environment.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
vis = None
3030
while True:
3131
cg_symbol = input(
32-
'Enter symbol of the geometry you want to see, "l" to see the list '
33-
'of existing geometries or "q" to quit : '
32+
'Enter symbol of the geometry you want to see, "l" to see the list of existing geometries or "q" to quit : '
3433
)
3534
if cg_symbol == "q":
3635
break

dev_scripts/potcar_scrambler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def scramble_single_potcar(self, potcar: PotcarSingle) -> str:
124124
return scrambled_potcar_str
125125

126126
def to_file(self, filename: str) -> None:
127-
with zopen(filename, mode="wt") as file:
127+
with zopen(filename, mode="wt", encoding="utf-8") as file:
128128
file.write(self.scrambled_potcars_str)
129129

130130
@classmethod

dev_scripts/regen_libxcfunc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
from __future__ import annotations
1111

1212
import json
13-
import os
1413
import sys
1514
from copy import deepcopy
1615

16+
from pymatgen.core import PKG_DIR
17+
1718

1819
def parse_libxc_docs(path):
1920
"""Parse libxc_docs.txt file, return dictionary {libxc_id: info_dict}."""
@@ -27,7 +28,7 @@ def parse_section(section):
2728
return int(dct["Number"]), dct
2829

2930
dct = {}
30-
with open(path) as file:
31+
with open(path, encoding="utf-8") as file:
3132
section = []
3233
for line in file:
3334
if not line.startswith("-"):
@@ -62,7 +63,7 @@ def write_libxc_docs_json(xc_funcs, json_path):
6263
if desc is not None:
6364
xc_funcs[num][opt] = desc
6465

65-
with open(json_path, "w") as fh:
66+
with open(json_path, "w", encoding="utf-8") as fh:
6667
json.dump(xc_funcs, fh)
6768

6869
return xc_funcs
@@ -85,8 +86,7 @@ def main():
8586
xc_funcs = parse_libxc_docs(path)
8687

8788
# Generate new JSON file in pycore
88-
pmg_core = os.path.abspath("../pymatgen/core/")
89-
json_path = f"{pmg_core}/libxc_docs.json"
89+
json_path = f"{PKG_DIR}/core/libxc_docs.json"
9090
write_libxc_docs_json(xc_funcs, json_path)
9191

9292
# Build new enum list.
@@ -99,8 +99,8 @@ def main():
9999

100100
# Re-generate enumerations.
101101
# [0] read py module.
102-
xc_funcpy_path = f"{pmg_core}/libxcfunc.py"
103-
with open(xc_funcpy_path) as file:
102+
xc_funcpy_path = f"{PKG_DIR}/core/libxcfunc.py"
103+
with open(xc_funcpy_path, encoding="utf-8") as file:
104104
lines = file.readlines()
105105

106106
# [1] insert new enum values in list

dev_scripts/update_pt_data.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from monty.serialization import dumpfn, loadfn
1414
from ruamel import yaml
1515

16-
from pymatgen.core import Element, get_el_sp
16+
from pymatgen.core import PKG_DIR, Element, get_el_sp
1717

1818
try:
1919
from bs4 import BeautifulSoup
@@ -25,7 +25,7 @@
2525

2626
def parse_oxi_state():
2727
data = loadfn(PTABLE_YAML_PATH)
28-
with open("oxidation_states.txt") as file:
28+
with open("oxidation_states.txt", encoding="utf-8") as file:
2929
oxi_data = file.read()
3030
oxi_data = re.sub("[\n\r]", "", oxi_data)
3131
patt = re.compile("<tr>(.*?)</tr>", re.MULTILINE)
@@ -57,13 +57,13 @@ def parse_oxi_state():
5757
data[el]["Common oxidation states"] = common_oxi
5858
else:
5959
print(el)
60-
with open("periodic_table2.yaml", mode="w") as file:
60+
with open("periodic_table2.yaml", mode="w", encoding="utf-8") as file:
6161
yaml.dump(data, file)
6262

6363

6464
def parse_ionic_radii():
6565
data = loadfn(PTABLE_YAML_PATH)
66-
with open("ionic_radii.csv") as file:
66+
with open("ionic_radii.csv", encoding="utf-8") as file:
6767
radii_data = file.read()
6868
radii_data = radii_data.split("\r")
6969
header = radii_data[0].split(",")
@@ -87,13 +87,13 @@ def parse_ionic_radii():
8787
data[el]["Ionic_radii"] = ionic_radii
8888
else:
8989
print(el)
90-
with open("periodic_table2.yaml", mode="w") as file:
90+
with open("periodic_table2.yaml", mode="w", encoding="utf-8") as file:
9191
yaml.dump(data, file)
9292

9393

9494
def parse_radii():
9595
data = loadfn(PTABLE_YAML_PATH)
96-
with open("radii.csv") as file:
96+
with open("radii.csv", encoding="utf-8") as file:
9797
radii_data = file.read()
9898
radii_data = radii_data.split("\r")
9999

@@ -121,9 +121,9 @@ def parse_radii():
121121
data[el]["Van der waals radius"] = vdw_radii
122122
else:
123123
print(el)
124-
with open("periodic_table2.yaml", mode="w") as file:
124+
with open("periodic_table2.yaml", mode="w", encoding="utf-8") as file:
125125
yaml.dump(data, file)
126-
with open("../pymatgen/core/periodic_table.json", mode="w") as file:
126+
with open(f"{PKG_DIR}/core/periodic_table.json", mode="w", encoding="utf-8") as file:
127127
json.dump(data, file)
128128

129129

@@ -140,9 +140,9 @@ def update_ionic_radii():
140140
if "Ionic_radii_ls" in dct:
141141
dct["Ionic radii ls"] = {k: v / 100 for k, v in dct["Ionic_radii_ls"].items()}
142142
del dct["Ionic_radii_ls"]
143-
with open("periodic_table2.yaml", mode="w") as file:
143+
with open("periodic_table2.yaml", mode="w", encoding="utf-8") as file:
144144
yaml.dump(data, file)
145-
with open("../pymatgen/core/periodic_table.json", mode="w") as file:
145+
with open(f"{PKG_DIR}/core/periodic_table.json", mode="w", encoding="utf-8") as file:
146146
json.dump(data, file)
147147

148148

@@ -180,19 +180,19 @@ def parse_shannon_radii():
180180
data[el]["Shannon radii"] = dict(radii[el])
181181

182182
dumpfn(data, PTABLE_YAML_PATH)
183-
with open("../pymatgen/core/periodic_table.json", mode="w") as file:
183+
with open(f"{PKG_DIR}/core/periodic_table.json", mode="w", encoding="utf-8") as file:
184184
json.dump(data, file)
185185

186186

187187
def gen_periodic_table():
188188
data = loadfn(PTABLE_YAML_PATH)
189189

190-
with open("../pymatgen/core/periodic_table.json", mode="w") as file:
190+
with open(f"{PKG_DIR}/core/periodic_table.json", mode="w", encoding="utf-8") as file:
191191
json.dump(data, file)
192192

193193

194194
def gen_iupac_ordering():
195-
periodic_table = loadfn("../pymatgen/core/periodic_table.json")
195+
periodic_table = loadfn(f"{PKG_DIR}/core/periodic_table.json")
196196
order = [
197197
([18], range(6, 0, -1)), # noble gasses
198198
([1], range(7, 1, -1)), # alkali metals
@@ -274,16 +274,16 @@ def add_electron_affinities():
274274
missing_electron_affinities = set(range(1, 93)) - Z_set
275275
raise ValueError(f"{missing_electron_affinities=}")
276276
print(element_electron_affinities)
277-
pt = loadfn("../pymatgen/core/periodic_table.json")
277+
pt = loadfn(f"{PKG_DIR}/core/periodic_table.json")
278278
for key, val in pt.items():
279279
val["Electron affinity"] = element_electron_affinities.get(Element(key).long_name)
280-
dumpfn(pt, "../pymatgen/core/periodic_table.json")
280+
dumpfn(pt, f"{PKG_DIR}/core/periodic_table.json")
281281

282282

283283
def add_ionization_energies():
284284
"""Update the periodic table data file with ground level and ionization energies from NIST."""
285285

286-
with open("NIST Atomic Ionization Energies Output.html") as file:
286+
with open("NIST Atomic Ionization Energies Output.html", encoding="utf-8") as file:
287287
soup = BeautifulSoup(file.read(), "html.parser")
288288
table = None
289289
for table in soup.find_all("table"):
@@ -302,11 +302,11 @@ def add_ionization_energies():
302302
if not set(data).issuperset(range(1, 93)):
303303
raise RuntimeError("Failed to get data up to Uranium")
304304

305-
pt = loadfn("../pymatgen/core/periodic_table.json")
305+
pt = loadfn(f"{PKG_DIR}/core/periodic_table.json")
306306
for key, val in pt.items():
307307
del val["Ionization energy"]
308308
val["Ionization energies"] = data.get(Element(key).long_name, [])
309-
dumpfn(pt, "../pymatgen/core/periodic_table.json")
309+
dumpfn(pt, f"{PKG_DIR}/core/periodic_table.json")
310310

311311

312312
if __name__ == "__main__":

docs/CHANGES.md

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

docs/apidoc/pymatgen.util.rst

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

0 commit comments

Comments
 (0)