Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

permissions:
contents: read
id-token: write

jobs:
deploy:
Expand All @@ -26,5 +27,3 @@ jobs:
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]

env:
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
Expand All @@ -58,8 +58,8 @@ jobs:
- name: Test Notebooks
run: pytest --nbmake ./docs/source/content

- uses: codecov/codecov-action@v1
if: matrix.python-version == 3.10
- uses: codecov/codecov-action@v4
if: matrix.python-version == '3.10'
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
# Develop branch only
- name: Deploy
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./docs/_build/html
8 changes: 4 additions & 4 deletions .github/workflows/update-precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
auto-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
- uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ 3.10 }}
python-version: "3.11"
cache: pip
cache-dependency-path: pyproject.toml

Expand All @@ -25,7 +25,7 @@ jobs:
run: pre-commit autoupdate

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v6
with:
branch: update/pre-commit-autoupdate
title: Auto-update pre-commit hooks
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,4 @@ docs.old/_build/
docs.old/

docs/source/api_ref/pymatgen.*.rst
.envrc
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.4
rev: v0.12.4
hooks:
# Run the linter.
- id: ruff
args: [ --fix, --unsafe-fixes]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.17.0
hooks:
- id: mypy
files: ^pymatgen/
Expand All @@ -20,20 +20,20 @@ repos:
- tokenize-rt==4.1.0
- types-pkg_resources==0.1.2
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.4.1
hooks:
- id: codespell
name: codespell
description: Checks for common misspellings in text files.
entry: codespell
language: python
types: [text]
files: \.(md|py)$
args: [
--ignore-words-list, 'titel,statics,ba,nd,te,mater,commun,vise,dscribe',
--skip, "*.ipynb,./tests,*paper*",
]
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.1
hooks:
- id: nbstripout
args: [
Expand Down
4 changes: 1 addition & 3 deletions docs/source/content/defect-finder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"from pymatgen.io.vasp import Locpot\n",
"\n",
"TEST_FILES = Path(\"../../../tests/test_files\")\n",
"import glob\n",
"\n",
"from pymatgen.analysis.defects.finder import DefectSiteFinder\n",
"from pymatgen.core.structure import Structure\n",
Expand All @@ -37,7 +35,7 @@
"finder = DefectSiteFinder()\n",
"\n",
"for q in range(-1, 3):\n",
" fname = f\"{str(TEST_FILES)}/v_N_GaN/q={q}/CONTCAR.gz\"\n",
" fname = f\"{TEST_FILES!s}/v_N_GaN/q={q}/CONTCAR.gz\"\n",
" struct = Structure.from_file(fname)\n",
" fpos = finder.get_defect_fpos(defect_structure=struct, base_structure=base_struct)\n",
" fpos -= np.round(fpos)\n",
Expand Down
7 changes: 4 additions & 3 deletions docs/source/content/formation-energy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
"outputs": [],
"source": [
"import warnings\n",
"\n",
"from monty.serialization import loadfn\n",
"from pymatgen.analysis.defects.thermo import FormationEnergyDiagram\n",
"from pymatgen.io.vasp import Vasprun\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
Expand Down Expand Up @@ -131,7 +131,7 @@
"source": [
"for i, p in enumerate(fed.chempot_limits):\n",
" print(f\"Limits for the chemical potential changes for point {i}\")\n",
" for k,v in p.items():\n",
" for k, v in p.items():\n",
" print(f\"Δμ_{k} = {v:.2f} eV\")"
]
},
Expand Down Expand Up @@ -164,10 +164,11 @@
"outputs": [],
"source": [
"from pymatgen.analysis.defects.corrections.freysoldt import plot_plnr_avg\n",
"\n",
"plot_data = fed.defect_entries[1].corrections_metadata[\"freysoldt\"][\"plot_data\"]\n",
"plot_plnr_avg(plot_data[0], title=\"Lattice Direction 1\")\n",
"plot_plnr_avg(plot_data[1], title=\"Lattice Direction 2\")\n",
"plot_plnr_avg(plot_data[2], title=\"Lattice Direction 3\")\n"
"plot_plnr_avg(plot_data[2], title=\"Lattice Direction 3\")"
]
}
],
Expand Down
6 changes: 3 additions & 3 deletions docs/source/content/freysoldt-correction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
" defect_frac_coords=center,\n",
" )\n",
" align = np.mean(list(freysoldt_results[q].metadata[\"alignments\"].values()))\n",
" print(f\"alignment correction: {align}\")\n"
" print(f\"alignment correction: {align}\")"
]
},
{
Expand Down Expand Up @@ -114,7 +114,7 @@
" \"\"\"\n",
" v_line_file = DEFECT_DIR / f\"q={q}/vline-eV-a{direction}.dat\"\n",
" # split the file into blocks based on the location of the string \"&\"\n",
" with open(v_line_file, \"r\") as f:\n",
" with open(v_line_file) as f:\n",
" blocks = f.read().split(\"&\")\n",
"\n",
" # convert each block into a list of lines and convert to a numpy array\n",
Expand Down Expand Up @@ -210,7 +210,7 @@
"outputs": [],
"source": [
"def get_sxd_result(q):\n",
" \"\"\"Read the output of sxdefectalign\"\"\"\n",
" \"\"\"Read the output of sxdefectalign.\"\"\"\n",
" fname = str(DEFECT_DIR / f\"q={q}/corr_align.out\")\n",
" gen = reverse_readfile(fname)\n",
" line = next(gen)\n",
Expand Down
22 changes: 15 additions & 7 deletions docs/source/content/nonradiative.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
"source": [
"# disable warnings\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\", category=UserWarning)\n",
"from pathlib import Path\n",
"\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"from pymatgen.analysis.defects.ccd import HarmonicDefect, get_SRH_coefficient"
Expand Down Expand Up @@ -186,7 +188,7 @@
"wswq_dir = TEST_FILES / \"ccd_0_-1\" / \"wswqs\"\n",
"print(f\"The parsed WSWQ files are: {[f.name for f in wswq_dir.glob('WSWQ*')]}\")\n",
"hd0.read_wswqs(TEST_FILES / \"ccd_0_-1\" / \"wswqs\")\n",
"print(f\"Parsed {len(hd0.wswqs)} WSWQ files.\")\n"
"print(f\"Parsed {len(hd0.wswqs)} WSWQ files.\")"
]
},
{
Expand All @@ -205,11 +207,15 @@
"metadata": {},
"outputs": [],
"source": [
"print(f\"The automatically determined defect electronic states are: {hd0.defect_band} \"\n",
" \"(with [band, k-point, spin] indexing).\")\n",
"print(\n",
" f\"The automatically determined defect electronic states are: {hd0.defect_band} \"\n",
" \"(with [band, k-point, spin] indexing).\"\n",
")\n",
"epME = hd0.get_elph_me(defect_state=(138, 1, 1))\n",
"print(f\"The resulting array of shape {epME.shape} contains the matrix elements from the \"\n",
" \"defect state to all other states at the same k-point.\")\n"
"print(\n",
" f\"The resulting array of shape {epME.shape} contains the matrix elements from the \"\n",
" \"defect state to all other states at the same k-point.\"\n",
")"
]
},
{
Expand All @@ -233,7 +239,7 @@
"hd1 = HarmonicDefect.from_directories(\n",
" directories=dirs10,\n",
" store_bandstructure=True,\n",
")\n"
")"
]
},
{
Expand All @@ -252,7 +258,9 @@
"outputs": [],
"source": [
"T = np.linspace(100, 1000, 20)\n",
"srh_c = get_SRH_coefficient(initial_state=hd0, final_state=hd1, defect_state=(138, 1, 1), T=T, dE=0.3)\n",
"srh_c = get_SRH_coefficient(\n",
" initial_state=hd0, final_state=hd1, defect_state=(138, 1, 1), T=T, dE=0.3\n",
")\n",
"plt.plot(T, srh_c)\n",
"plt.xlabel(\"Temperature [K]\")\n",
"plt.ylabel(\"SRH coefficient [cm$^{-3}$s$^{-1}$]\");"
Expand Down
51 changes: 30 additions & 21 deletions docs/source/content/photo-conduct.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
"outputs": [],
"source": [
"# disable tqdm progress bar\n",
"from tqdm import tqdm\n",
"from functools import partialmethod\n",
"\n",
"from tqdm import tqdm\n",
"\n",
"tqdm.__init__ = partialmethod(tqdm.__init__, disable=True)\n",
"# disable warnings\n",
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\", category=UserWarning)"
]
},
Expand All @@ -40,13 +43,15 @@
"metadata": {},
"outputs": [],
"source": [
"import bisect\n",
"import collections\n",
"from pathlib import Path\n",
"from pymatgen.analysis.defects.ccd import HarmonicDefect, get_SRH_coefficient\n",
"from pymatgen.io.vasp.optics import DielectricFunctionCalculator, Spin, Vasprun, Waveder\n",
"\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"import bisect\n",
"import collections\n",
"from pymatgen.analysis.defects.ccd import HarmonicDefect\n",
"from pymatgen.io.vasp.optics import Spin, Waveder\n",
"\n",
"TEST_FILES = Path(\"../../../tests/test_files/v_Ga/\")"
]
},
Expand Down Expand Up @@ -96,37 +101,36 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"def print_eigs(vr, bwind=5, defect_bands = ()):\n",
"def print_eigs(vr, bwind=5, defect_bands=()):\n",
" \"\"\"Print the eigenvalues in a small band window around the Fermi level.\n",
"\n",
" Args:\n",
" vr (Vasprun): The Vasprun object.\n",
" bwind (int): The number of bands above and below the Fermi level to print.\n",
" defect_bands (list): A list of tuples of the form (band index, kpt index, spin index)\n",
" \"\"\"\n",
" def _get_spin_idx(spin):\n",
"\n",
" def _get_spin_idx(spin) -> int:\n",
" if spin == Spin.up:\n",
" return 0\n",
" return 1\n",
"\n",
" occ = vr.eigenvalues[Spin.up][0, :, 1] * -1\n",
" fermi_idx = bisect.bisect_left(occ, -0.5) \n",
" fermi_idx = bisect.bisect_left(occ, -0.5)\n",
" output = collections.defaultdict(list)\n",
" for k, spin_eigs in vr.eigenvalues.items():\n",
" spin_idx = _get_spin_idx(k)\n",
" for kpt in range(spin_eigs.shape[0]):\n",
" for ib in range(fermi_idx - bwind, fermi_idx + bwind):\n",
" e, o = spin_eigs[kpt, ib, :]\n",
" idx = (ib, kpt, spin_idx)\n",
" if idx in defect_bands:\n",
" e_out = f\"{e:7.4f}*\"\n",
" else:\n",
" e_out = f\"{e:8.5f}\"\n",
" e_out = f\"{e:7.4f}*\" if idx in defect_bands else f\"{e:8.5f}\"\n",
" output[(ib)].append(e_out)\n",
" print(\"band s=0,k=0 s=0,k=1 s=1,k=0 s=1,k=1\")\n",
" for ib, eigs in output.items():\n",
" print(f\"{ib:3d} {' '.join(eigs)}\")\n",
"\n",
"\n",
"print_eigs(vr=hd0.vrun, defect_bands=hd0.defect_band)"
]
},
Expand Down Expand Up @@ -177,7 +181,7 @@
"metadata": {},
"outputs": [],
"source": [
"energy, eps_vbm, eps_cbm = hd0.get_dielectric_function(idir=0,jdir=0)\n",
"energy, eps_vbm, eps_cbm = hd0.get_dielectric_function(idir=0, jdir=0)\n",
"# plotting\n",
"plt.plot(energy, np.imag(eps_vbm), label=\"VBM\")\n",
"plt.plot(energy, np.imag(eps_cbm), label=\"CBM\")\n",
Expand Down Expand Up @@ -216,15 +220,20 @@
"metadata": {},
"outputs": [],
"source": [
"from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n",
"import matplotlib as mpl\n",
"from pymatgen.analysis.defects.plotting.optics import plot_optical_transitions\n",
"\n",
"fig, ax = plt.subplots()\n",
"cm_ax = fig.add_axes([0.8,0.1,0.02,0.8])\n",
"df_k0, cmap, norm = plot_optical_transitions(hd0, kpt_index=1, band_window=5, x0=3, ax=ax)\n",
"df_k1, _, _ = plot_optical_transitions(hd0, kpt_index=0, band_window=5, x0=0, ax=ax, cmap=cmap, norm=norm)\n",
"mpl.colorbar.ColorbarBase(cm_ax,cmap=cmap,norm=norm,orientation='vertical')\n",
"ax.set_ylabel(\"Energy (eV)\");\n",
"ax.set_xticks([0,3])\n",
"cm_ax = fig.add_axes([0.8, 0.1, 0.02, 0.8])\n",
"df_k0, cmap, norm = plot_optical_transitions(\n",
" hd0, kpt_index=1, band_window=5, x0=3, ax=ax\n",
")\n",
"df_k1, _, _ = plot_optical_transitions(\n",
" hd0, kpt_index=0, band_window=5, x0=0, ax=ax, cmap=cmap, norm=norm\n",
")\n",
"mpl.colorbar.ColorbarBase(cm_ax, cmap=cmap, norm=norm, orientation=\"vertical\")\n",
"ax.set_ylabel(\"Energy (eV)\")\n",
"ax.set_xticks([0, 3])\n",
"ax.set_xticklabels([\"Kpoint-0\", \"Kpoint-1\"])"
]
},
Expand Down
10 changes: 0 additions & 10 deletions docs/source/content/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
"To ensure that the namespace is installed properly run"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pymatgen.analysis.defects.core import __file__"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -127,7 +118,6 @@
"\n",
"from monty.serialization import loadfn\n",
"from pymatgen.analysis.defects.thermo import FormationEnergyDiagram\n",
"from pymatgen.io.vasp import Vasprun\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"\n",
Expand Down
Loading