Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit autoupdate #404

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.7.2
hooks:
- id: ruff
args: [ --fix, --unsafe-fixes ]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

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

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
stages: [ commit, commit-msg ]
stages: [ pre-commit, commit-msg ]
exclude_types: [ html ]
additional_dependencies: [ tomli ] # needed to read pyproject.toml below py3.11

Expand All @@ -42,12 +42,12 @@ repos:
- id: double-quote-cython-strings

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
rev: 1.19.1
hooks:
- id: blacken-docs

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0
rev: v0.42.0
hooks:
- id: markdownlint
# MD013: line too long
Expand All @@ -58,12 +58,12 @@ repos:
args: [ --disable, MD013, MD024, MD025, MD033, MD041, "--" ]

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.0
hooks:
- id: nbstripout
args: [ --drop-empty-cells, --keep-output ]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.369
rev: v1.1.387
hooks:
- id: pyright
11 changes: 6 additions & 5 deletions examples/neb_idpp_solver.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
"metadata": {},
"outputs": [],
"source": [
"from pymatgen.core import Structure\n",
"from pymatgen.analysis.diffusion.neb.pathfinder import IDPPSolver\n",
"import numpy as np\n",
"from __future__ import annotations\n",
"\n",
"import os\n",
"\n",
"from pymatgen.analysis.diffusion.neb.pathfinder import IDPPSolver\n",
"from pymatgen.core import Structure\n",
"\n",
"dirname = \"../pymatgen/analysis/diffusion/neb/tests/pathfinder_files/\"\n",
"\n",
"init_struct = Structure.from_file(os.path.join(dirname, \"CONTCAR-0\"), False)\n",
"final_struct = Structure.from_file(os.path.join(dirname, \"CONTCAR-1\"), False)\n",
"\n",
"obj = IDPPSolver.from_endpoints(endpoints=[init_struct, final_struct], nimages=3, \n",
" sort_tol=1.0)\n",
"obj = IDPPSolver.from_endpoints(endpoints=[init_struct, final_struct], nimages=3, sort_tol=1.0)\n",
"new_path = obj.run(maxiter=5000, tol=1e-5, gtol=1e-3, species=[\"Li\"])"
]
}
Expand Down
8 changes: 6 additions & 2 deletions examples/neb_path_mapping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"outputs": [],
"source": [
"# Start with a lithiated structure\n",
"from __future__ import annotations\n",
"\n",
"from pymatgen.core import Structure\n",
"\n",
"struct = Structure.from_file(\"../pymatgen/analysis/diffusion/neb/tests/full_path_files/Li6MnO4.cif\")"
]
},
Expand All @@ -25,7 +28,8 @@
"outputs": [],
"source": [
"from pymatgen.analysis.diffusion.neb.full_path_mapper import MigrationGraph\n",
"# Instantiate MigrationGraph and consider all hops within 4 Angstroms \n",
"\n",
"# Instantiate MigrationGraph and consider all hops within 4 Angstroms\n",
"mg = MigrationGraph.with_distance(structure=struct, migrating_specie=\"Li\", max_distance=4)"
]
},
Expand Down Expand Up @@ -316,7 +320,7 @@
"source": [
"# Get migration paths through the material of interest using the MigrationGraph hop data\n",
"paths = []\n",
"for u, path in mg.get_path():\n",
"for _u, path in mg.get_path():\n",
" paths.append(path)"
]
},
Expand Down
33 changes: 18 additions & 15 deletions examples/probability_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,25 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"import numpy as np\n",
"\n",
"from pymatgen.analysis.diffusion.aimd.pathway import ProbabilityDensityAnalysis\n",
"from pymatgen.core import Structure\n",
"import numpy as np\n",
"\n",
"#First prepare the structure and ionic trajectories files\n",
"# First prepare the structure and ionic trajectories files\n",
"trajectories = np.load(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_trajectories.npy\")\n",
"structure = Structure.from_file(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4.cif\", False)\n",
"\n",
"#ProbabilityDensityAnalysis object\n",
"# ProbabilityDensityAnalysis object\n",
"pda = ProbabilityDensityAnalysis(structure, trajectories, interval=0.5)\n",
"#Save probability distribution to a CHGCAR-like file\n",
"# Save probability distribution to a CHGCAR-like file\n",
"pda.to_chgcar(filename=\"CHGCAR_new.vasp\")\n",
"\n",
"print(\"Maximum: %s, Minimum: %s\" % (pda.Pr.max(), pda.Pr.min()))\n",
"print(f\"Maximum: {pda.Pr.max()}, Minimum: {pda.Pr.min()}\")\n",
"# \\int P(r)d^3r = 1\n",
"print(\"Total probability: %s\" % np.sum(pda.Pr * pda.structure.lattice.volume / pda.lens[0]/pda.lens[1]/pda.lens[2]))\n"
"print(f\"Total probability: {np.sum(pda.Pr * pda.structure.lattice.volume / pda.lens[0]/pda.lens[1]/pda.lens[2])}\")"
]
},
{
Expand All @@ -69,23 +72,23 @@
}
],
"source": [
"from pymatgen.analysis.diffusion.analyzer import DiffusionAnalyzer\n",
"import json\n",
"\n",
"#ProbabilityDensityAnalysis object\n",
"filename=\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\"\n",
"from pymatgen.analysis.diffusion.analyzer import DiffusionAnalyzer\n",
"\n",
"# ProbabilityDensityAnalysis object\n",
"filename = \"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\"\n",
"\n",
"data = json.load(open(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\", \"r\"))\n",
"data = json.load(open(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\"))\n",
"diff_analyzer = DiffusionAnalyzer.from_dict(data)\n",
"\n",
"pda = ProbabilityDensityAnalysis.from_diffusion_analyzer(diff_analyzer, interval=0.5,\n",
" species=(\"Na\", \"Li\"))\n",
"#Save probability distribution to a CHGCAR-like file\n",
"pda = ProbabilityDensityAnalysis.from_diffusion_analyzer(diff_analyzer, interval=0.5, species=(\"Na\", \"Li\"))\n",
"# Save probability distribution to a CHGCAR-like file\n",
"pda.to_chgcar(filename=\"CHGCAR_new2.vasp\")\n",
"\n",
"print(\"Maximum: %s, Minimum: %s\" % (pda.Pr.max(), pda.Pr.min()))\n",
"print(f\"Maximum: {pda.Pr.max()}, Minimum: {pda.Pr.min()}\")\n",
"# \\int P(r)d^3r = 1\n",
"print(\"Total probability: %s\" % np.sum(pda.Pr * pda.structure.lattice.volume / pda.lens[0]/pda.lens[1]/pda.lens[2]))\n"
"print(f\"Total probability: {np.sum(pda.Pr * pda.structure.lattice.volume / pda.lens[0]/pda.lens[1]/pda.lens[2])}\")"
]
}
],
Expand Down
63 changes: 35 additions & 28 deletions examples/radial_distribution_function.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
"metadata": {},
"outputs": [],
"source": [
"from pymatgen.analysis.diffusion.aimd.rdf import RadialDistributionFunction, RadialDistributionFunctionFast\n",
"from monty.serialization import loadfn\n",
"from __future__ import annotations\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from monty.serialization import loadfn\n",
"\n",
"from pymatgen.analysis.diffusion.aimd.rdf import RadialDistributionFunction, RadialDistributionFunctionFast\n",
"\n",
"%matplotlib inline"
]
},
Expand All @@ -27,7 +31,7 @@
}
],
"source": [
"obj = loadfn('../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json')"
"obj = loadfn(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\")"
]
},
{
Expand All @@ -39,7 +43,8 @@
"structure_list = []\n",
"for i, s in enumerate(obj.get_drift_corrected_structures()):\n",
" structure_list.append(s)\n",
" if i == 9: break"
" if i == 9:\n",
" break"
]
},
{
Expand All @@ -49,12 +54,11 @@
"outputs": [],
"source": [
"rdf_func = RadialDistributionFunction.from_species(\n",
" structures=structure_list, ngrid=101, rmax=10.0, cell_range=1,\n",
" sigma=0.2, species=['Na'], reference_species=['S'])\n",
" structures=structure_list, ngrid=101, rmax=10.0, cell_range=1, sigma=0.2, species=[\"Na\"], reference_species=[\"S\"]\n",
")\n",
"\n",
"# fewer parameters in new implementations\n",
"rdf_func_faster = RadialDistributionFunctionFast(structures=structure_list, \n",
" ngrid=101, rmax=10.0, sigma=0.2)"
"rdf_func_faster = RadialDistributionFunctionFast(structures=structure_list, ngrid=101, rmax=10.0, sigma=0.2)"
]
},
{
Expand Down Expand Up @@ -152,7 +156,7 @@
}
],
"source": [
"r, rdf2 = rdf_func_faster.get_rdf('S', 'Na')\n",
"r, rdf2 = rdf_func_faster.get_rdf(\"S\", \"Na\")\n",
"plt.plot(r, rdf2)\n",
"plt.title(\"New RDF implementation\")"
]
Expand Down Expand Up @@ -186,9 +190,9 @@
}
],
"source": [
"r, cn = rdf_func_faster.get_coordination_number('S', 'Na')\n",
"r, cn = rdf_func_faster.get_coordination_number(\"S\", \"Na\")\n",
"plt.plot(r[:70], cn[:70])\n",
"plt.title('New coordination number')"
"plt.title(\"New coordination number\")"
]
},
{
Expand Down Expand Up @@ -220,18 +224,16 @@
}
],
"source": [
"r, rdf_na_p_s = rdf_func_faster.get_rdf(\"S\", [\"Na\", \"P\", \"S\"])\n",
"r, rdf_na = rdf_func_faster.get_rdf(\"S\", [\"Na\"])\n",
"r, rdf_p = rdf_func_faster.get_rdf(\"S\", [\"P\"])\n",
"r, rdf_s = rdf_func_faster.get_rdf(\"S\", [\"S\"])\n",
"\n",
"r, rdf_na_p_s = rdf_func_faster.get_rdf('S', ['Na', 'P', 'S'])\n",
"r, rdf_na = rdf_func_faster.get_rdf('S', ['Na'])\n",
"r, rdf_p = rdf_func_faster.get_rdf('S', ['P'])\n",
"r, rdf_s = rdf_func_faster.get_rdf('S', ['S'])\n",
"\n",
"plt.plot(r, rdf_na_p_s, label='S-[Na, P, S]')\n",
"plt.plot(r, rdf_na, label='S-Na')\n",
"plt.plot(r, rdf_p, label='S-P')\n",
"plt.plot(r, rdf_s, label='S-S')\n",
"plt.legend()\n",
"\n"
"plt.plot(r, rdf_na_p_s, label=\"S-[Na, P, S]\")\n",
"plt.plot(r, rdf_na, label=\"S-Na\")\n",
"plt.plot(r, rdf_p, label=\"S-P\")\n",
"plt.plot(r, rdf_s, label=\"S-S\")\n",
"plt.legend()"
]
},
{
Expand Down Expand Up @@ -264,8 +266,14 @@
],
"source": [
"rdf_func = RadialDistributionFunction.from_species(\n",
" structures=structure_list, ngrid=101, rmax=10.0, cell_range=1,\n",
" sigma=0.2, species=['Na','P', 'S'], reference_species=['S'])\n",
" structures=structure_list,\n",
" ngrid=101,\n",
" rmax=10.0,\n",
" cell_range=1,\n",
" sigma=0.2,\n",
" species=[\"Na\", \"P\", \"S\"],\n",
" reference_species=[\"S\"],\n",
")\n",
"\n",
"plt.plot(rdf_func.interval, rdf_func.rdf)\n",
"plt.ylim([-0.2, 6.2])"
Expand All @@ -288,8 +296,8 @@
"%%timeit -n 1\n",
"\n",
"rdf_func = RadialDistributionFunction.from_species(\n",
" structures=structure_list, ngrid=101, rmax=10.0, cell_range=1,\n",
" sigma=0.2, species=['Na'], reference_species=['S'])"
" structures=structure_list, ngrid=101, rmax=10.0, cell_range=1, sigma=0.2, species=[\"Na\"], reference_species=[\"S\"]\n",
")"
]
},
{
Expand All @@ -308,8 +316,7 @@
"source": [
"%%timeit -n 1\n",
"# fewer parameters in new implementations\n",
"rdf_func_faster = RadialDistributionFunctionFast(structures=structure_list, \n",
" ngrid=101, rmax=10.0, sigma=0.2)"
"rdf_func_faster = RadialDistributionFunctionFast(structures=structure_list, ngrid=101, rmax=10.0, sigma=0.2)"
]
}
],
Expand Down
23 changes: 14 additions & 9 deletions examples/van_hove.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,24 @@
}
],
"source": [
"from __future__ import annotations\n",
"\n",
"import json\n",
"import numpy as np\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from pymatgen.analysis.diffusion.analyzer import DiffusionAnalyzer\n",
"\n",
"from pymatgen.analysis.diffusion.aimd.van_hove import VanHoveAnalysis\n",
"from pymatgen.analysis.diffusion.analyzer import DiffusionAnalyzer\n",
"\n",
"%matplotlib inline\n",
"\n",
"data = json.load(open(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\", \"r\"))\n",
"data = json.load(open(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\"))\n",
"\n",
"new_obj = DiffusionAnalyzer.from_dict(data)\n",
"\n",
"vhfunc = VanHoveAnalysis(diffusion_analyzer=new_obj, avg_nsteps=5, ngrid=101, rmax=10.0, \n",
" step_skip=5, sigma=0.1, species = [\"Li\", \"Na\"])\n",
"vhfunc = VanHoveAnalysis(\n",
" diffusion_analyzer=new_obj, avg_nsteps=5, ngrid=101, rmax=10.0, step_skip=5, sigma=0.1, species=[\"Li\", \"Na\"]\n",
")\n",
"\n",
"vhfunc.get_3d_plot(mode=\"self\")\n",
"vhfunc.get_3d_plot(mode=\"distinct\")"
Expand Down Expand Up @@ -126,21 +130,22 @@
],
"source": [
"import json\n",
"import numpy as np\n",
"\n",
"from pymatgen.analysis.diffusion.aimd.rdf import RadialDistributionFunction\n",
"\n",
"%matplotlib inline\n",
"\n",
"# The generated structure list in this example is for illustration purposes only.\n",
"data = json.load(open(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\", \"r\"))\n",
"data = json.load(open(\"../pymatgen/analysis/diffusion/aimd/tests/cNa3PS4_pda.json\"))\n",
"new_obj = DiffusionAnalyzer.from_dict(data)\n",
"\n",
"structure_list = []\n",
"for i, s in enumerate(new_obj.get_drift_corrected_structures()):\n",
" structure_list.append(s)\n",
" if i == 9: break\n",
" if i == 9:\n",
" break\n",
"\n",
"# Compute and plot RDF for Na and S \n",
"# Compute and plot RDF for Na and S\n",
"species = [\"Na\", \"S\"]\n",
"obj = RadialDistributionFunction(structure_list, ngrid=101, rmax=10.0, sigma=0.1, indices=[0], reference_indices=[2, 3])\n",
"plt = obj.get_rdf_plot(label=\"RDF\")"
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/diffusion/utils/tests/test_maggma.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
__date__ = "April 10, 2019"


@pytest.fixture()
@pytest.fixture
def maggma_stores() -> dict[str, JSONStore]:
return {
"sgroups": JSONStore(f"{dir_path}/maggma_sgroup_store.json", key="group_id"),
Expand Down
Loading