Skip to content

Commit

Permalink
Merge pull request #41 from materialsproject/master
Browse files Browse the repository at this point in the history
Merge updates from main fork
  • Loading branch information
benrich37 authored Jan 13, 2025
2 parents b5ea1b6 + 0d14d72 commit 67a44cd
Show file tree
Hide file tree
Showing 257 changed files with 10,305 additions and 9,498 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ jobs:
split: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

runs-on: ${{ matrix.config.os }}

env:
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
MPLBACKEND: Agg # non-interactive backend for matplotlib

PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
PYTHONWARNDEFAULTENCODING: "true" # PEP 597: Enable optional EncodingWarning
steps:
- name: Check out repo
uses: actions/checkout@v4
Expand Down Expand Up @@ -106,6 +105,8 @@ jobs:
- name: pytest split ${{ matrix.split }}
env:
MPLBACKEND: Agg # non-interactive backend for matplotlib
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
PMG_TEST_FILES_DIR: "${{ github.workspace }}/tests/files"
run: |
micromamba activate pmg
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
rev: v0.9.0
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
Expand All @@ -22,7 +22,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy

Expand Down Expand Up @@ -65,6 +65,6 @@ repos:
args: [--drop-empty-cells, --keep-output]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.389
rev: v1.1.391
hooks:
- id: pyright
2 changes: 1 addition & 1 deletion dev_scripts/chemenv/explicit_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ class Algo:
cg._algorithms = [ExplicitPermutationsAlgorithm(permutations=explicit_permutations)]
new_geom_dir = "new_geometry_files"
os.makedirs(new_geom_dir, exist_ok=True)
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w") as file:
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
json.dump(cg.as_dict(), file)
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,5 @@
if test == "y":
cg._algorithms = new_algos
cg_dict = cg.as_dict()
with open(f"../coordination_geometries_files_new/{cg_symbol}.json", mode="w") as file:
with open(f"../coordination_geometries_files_new/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
json.dump(cg_dict, file)
2 changes: 1 addition & 1 deletion dev_scripts/chemenv/get_plane_permutations_optimized.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,5 +444,5 @@ def random_permutations_iterator(initial_permutation, n_permutations):
if test == "y":
new_geom_dir = "new_geometry_files"
os.makedirs(new_geom_dir, exist_ok=True)
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w") as file:
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
json.dump(cg.as_dict(), file)
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def get_structure(self, morphing_factor):

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

site_idx = morphing["ineighbor"] + 1
if morphing["expansion_origin"] == "central_site":
Expand Down
3 changes: 1 addition & 2 deletions dev_scripts/chemenv/view_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
vis = None
while True:
cg_symbol = input(
'Enter symbol of the geometry you want to see, "l" to see the list '
'of existing geometries or "q" to quit : '
'Enter symbol of the geometry you want to see, "l" to see the list of existing geometries or "q" to quit : '
)
if cg_symbol == "q":
break
Expand Down
2 changes: 1 addition & 1 deletion dev_scripts/potcar_scrambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def scramble_single_potcar(self, potcar: PotcarSingle) -> str:
return scrambled_potcar_str

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

@classmethod
Expand Down
14 changes: 7 additions & 7 deletions dev_scripts/regen_libxcfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
from __future__ import annotations

import json
import os
import sys
from copy import deepcopy

from pymatgen.core import PKG_DIR


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

dct = {}
with open(path) as file:
with open(path, encoding="utf-8") as file:
section = []
for line in file:
if not line.startswith("-"):
Expand Down Expand Up @@ -62,7 +63,7 @@ def write_libxc_docs_json(xc_funcs, json_path):
if desc is not None:
xc_funcs[num][opt] = desc

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

return xc_funcs
Expand All @@ -85,8 +86,7 @@ def main():
xc_funcs = parse_libxc_docs(path)

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

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

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

# [1] insert new enum values in list
Expand Down
36 changes: 18 additions & 18 deletions dev_scripts/update_pt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from monty.serialization import dumpfn, loadfn
from ruamel import yaml

from pymatgen.core import Element, get_el_sp
from pymatgen.core import PKG_DIR, Element, get_el_sp

try:
from bs4 import BeautifulSoup
Expand All @@ -25,7 +25,7 @@

def parse_oxi_state():
data = loadfn(PTABLE_YAML_PATH)
with open("oxidation_states.txt") as file:
with open("oxidation_states.txt", encoding="utf-8") as file:
oxi_data = file.read()
oxi_data = re.sub("[\n\r]", "", oxi_data)
patt = re.compile("<tr>(.*?)</tr>", re.MULTILINE)
Expand Down Expand Up @@ -57,13 +57,13 @@ def parse_oxi_state():
data[el]["Common oxidation states"] = common_oxi
else:
print(el)
with open("periodic_table2.yaml", mode="w") as file:
with open("periodic_table2.yaml", mode="w", encoding="utf-8") as file:
yaml.dump(data, file)


def parse_ionic_radii():
data = loadfn(PTABLE_YAML_PATH)
with open("ionic_radii.csv") as file:
with open("ionic_radii.csv", encoding="utf-8") as file:
radii_data = file.read()
radii_data = radii_data.split("\r")
header = radii_data[0].split(",")
Expand All @@ -87,13 +87,13 @@ def parse_ionic_radii():
data[el]["Ionic_radii"] = ionic_radii
else:
print(el)
with open("periodic_table2.yaml", mode="w") as file:
with open("periodic_table2.yaml", mode="w", encoding="utf-8") as file:
yaml.dump(data, file)


def parse_radii():
data = loadfn(PTABLE_YAML_PATH)
with open("radii.csv") as file:
with open("radii.csv", encoding="utf-8") as file:
radii_data = file.read()
radii_data = radii_data.split("\r")

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


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


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

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


def gen_periodic_table():
data = loadfn(PTABLE_YAML_PATH)

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


def gen_iupac_ordering():
periodic_table = loadfn("../pymatgen/core/periodic_table.json")
periodic_table = loadfn(f"{PKG_DIR}/core/periodic_table.json")
order = [
([18], range(6, 0, -1)), # noble gasses
([1], range(7, 1, -1)), # alkali metals
Expand Down Expand Up @@ -274,16 +274,16 @@ def add_electron_affinities():
missing_electron_affinities = set(range(1, 93)) - Z_set
raise ValueError(f"{missing_electron_affinities=}")
print(element_electron_affinities)
pt = loadfn("../pymatgen/core/periodic_table.json")
pt = loadfn(f"{PKG_DIR}/core/periodic_table.json")
for key, val in pt.items():
val["Electron affinity"] = element_electron_affinities.get(Element(key).long_name)
dumpfn(pt, "../pymatgen/core/periodic_table.json")
dumpfn(pt, f"{PKG_DIR}/core/periodic_table.json")


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

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

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


if __name__ == "__main__":
Expand Down
9 changes: 9 additions & 0 deletions docs/CHANGES.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions docs/apidoc/pymatgen.util.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 67a44cd

Please sign in to comment.