diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 26276eed..81ced310 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] split: [1, 2, 3, 4, 5, 6] steps: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ae1a9c69..01bbd389 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,19 +29,19 @@ repos: - id: blacken-docs additional_dependencies: [black] exclude: README.md -- repo: https://github.com/pycqa/flake8 - rev: 7.0.0 - hooks: - - id: flake8 - entry: pflake8 - files: lobsterpy/.* - additional_dependencies: - - pyproject-flake8==6.0.0a1 - - flake8-bugbear==22.12.6 - - flake8-typing-imports==1.14.0 - - flake8-docstrings==1.6.0 - - flake8-rst-docstrings==0.3.0 - - flake8-rst==0.8.0 +#- repo: https://github.com/pycqa/flake8 +# rev: 7.0.0 +# hooks: +# - id: flake8 +# entry: pflake8 +# files: lobsterpy/.* +# additional_dependencies: +# - pyproject-flake8==6.0.0a1 +# - flake8-bugbear==22.12.6 +# - flake8-typing-imports==1.14.0 +# - flake8-docstrings==1.6.0 + # - flake8-rst-docstrings==0.3.0 + # - flake8-rst==0.8.0 - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: diff --git a/docs/tutorial/tutorial.ipynb b/docs/tutorial/tutorial.ipynb index 99eac9c2..4bfce366 100644 --- a/docs/tutorial/tutorial.ipynb +++ b/docs/tutorial/tutorial.ipynb @@ -48,14 +48,14 @@ "metadata": { "hide_input": false }, - "outputs": [], "source": [ "from pathlib import Path\n", "from lobsterpy.cohp.analyze import Analysis\n", "from lobsterpy.cohp.describe import Description\n", "import warnings\n", "warnings.filterwarnings('ignore')" - ] + ], + "outputs": [] }, { "cell_type": "code", @@ -66,11 +66,11 @@ "remove-cell" ] }, - "outputs": [], "source": [ "# Directory of your VASP and Lobster computations\n", "directory = Path(\".\") / \"..\" / \"..\" / \"tests\" / \"test_data\" / \"CdF_comp_range\"" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -88,7 +88,6 @@ "execution_count": null, "id": "2ca066a3", "metadata": {}, - "outputs": [], "source": [ "# Initialize Analysis object\n", "analyse = Analysis(\n", @@ -98,30 +97,31 @@ " path_to_charge=directory / \"CHARGE.lobster.gz\",\n", " which_bonds=\"cation-anion\",\n", ")" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "87f41407", "metadata": {}, - "outputs": [], "source": [ "# Initialize Description object and to get text description of the analysis\n", "describe = Description(analysis_object=analyse)\n", "describe.write_description()" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "6a0e3916", "metadata": {}, - "outputs": [], "source": [ "# Get static plots for detected relevant bonds\n", "describe.plot_cohps(ylim=[-10, 2], xlim=[-4, 4])" - ] + ], + "outputs": [] }, { "cell_type": "code", @@ -132,14 +132,14 @@ "remove-output" ] }, - "outputs": [], "source": [ "# Get interactive plots of relevant bonds, \n", "\n", "# Setting label_resolved arg to True will plot each COHP curve separately, alongside summed COHP for the bonds.\n", "fig = describe.plot_interactive_cohps(label_resolved=True, hide=True)\n", "fig.show(renderer='notebook')" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -156,33 +156,33 @@ "execution_count": null, "id": "3c695d06", "metadata": {}, - "outputs": [], "source": [ "# Dict summarizing the automatic analysis results\n", "analyse.condensed_bonding_analysis" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "b079043b", "metadata": {}, - "outputs": [], "source": [ "# Dict with bonds identified\n", "analyse.final_dict_bonds" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "bcab3c31", "metadata": {}, - "outputs": [], "source": [ "# Dict with ions and their co-ordination environments\n", "analyse.final_dict_ions" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -229,7 +229,6 @@ "execution_count": null, "id": "ae5c791f", "metadata": {}, - "outputs": [], "source": [ "analyse = Analysis(\n", " path_to_poscar=directory / \"POSCAR.gz\",\n", @@ -240,18 +239,19 @@ " orbital_resolved=True,\n", " orbital_cutoff=0.03,\n", ")" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "468a2478", "metadata": {}, - "outputs": [], "source": [ "# Access the dict summarizing the results including orbital-wise analysis data \n", "analyse.condensed_bonding_analysis" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -276,12 +276,12 @@ "execution_count": null, "id": "2df4b44a", "metadata": {}, - "outputs": [], "source": [ "# Initialize the Description object\n", "describe = Description(analysis_object=analyse)\n", "describe.write_description()" - ] + ], + "outputs": [] }, { "cell_type": "code", @@ -292,12 +292,12 @@ "remove-output" ] }, - "outputs": [], "source": [ "# Automatic interactive plots\n", "fig = describe.plot_interactive_cohps(orbital_resolved=True, ylim=[-15,5], hide=True)\n", "fig.show(renderer='notebook')" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -332,11 +332,11 @@ "remove-cell" ] }, - "outputs": [], "source": [ "# Directory to your VASP and Lobster computations\n", "directory = Path(\".\") / \"..\" / \"..\" / \"tests\" / \"test_data\" / \"K3Sb\"" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -354,7 +354,6 @@ "execution_count": null, "id": "87a8eb35", "metadata": {}, - "outputs": [], "source": [ "# Get calculation quality summary dict\n", "calc_quality_K3Sb = Analysis.get_lobster_calc_quality_summary(\n", @@ -372,21 +371,22 @@ " n_bins=256,\n", " )\n", "calc_quality_K3Sb" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "8bca8893", "metadata": {}, - "outputs": [], "source": [ "# Get a text description from calculation quality summary dictionary\n", "calc_quality_k3sb_des = Description.get_calc_quality_description(\n", " calc_quality_K3Sb\n", " )\n", "Description.write_calc_quality_description(calc_quality_k3sb_des)" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -401,12 +401,12 @@ "execution_count": null, "id": "240ae59d", "metadata": {}, - "outputs": [], "source": [ "from matplotlib import style\n", "from pymatgen.io.lobster import Doscar\n", "from lobsterpy.plotting import InteractiveCohpPlotter, IcohpDistancePlotter, PlainCohpPlotter, PlainDosPlotter, get_style_list" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -431,7 +431,6 @@ "execution_count": null, "id": "3da81099", "metadata": {}, - "outputs": [], "source": [ "# Using PlainCohpPlotter to get static plots of relevant bonds from Analysis object\n", "\n", @@ -442,7 +441,8 @@ " cohp = analyse.chemenv.completecohp.get_summed_cohp_by_label_list(label_list=label_list)\n", " cohp_plot_static.add_cohp(plot_label, cohp)\n", "cohp_plot_static.get_plot(ylim=[-15,2]);" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -459,7 +459,6 @@ "execution_count": null, "id": "b01bf48a", "metadata": {}, - "outputs": [], "source": [ "# Using PlainCohpPlotter to get static plots of relevant orbitals COHPs from Analysis object\n", "\n", @@ -473,28 +472,29 @@ " orbital_list=[orb]*len(label_list))\n", " cohp_plot_static.add_cohp(orb, cohp)\n", "cohp_plot_static.get_plot(ylim=[-15,2]);" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "866cd67a", "metadata": {}, - "outputs": [], "source": [ "# Using interactive plotter to add relevant cohps\n", "interactive_cohp_plot = InteractiveCohpPlotter()" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "60f64578", "metadata": {}, - "outputs": [], "source": [ "interactive_cohp_plot.add_all_relevant_cohps(analyse=analyse, label_resolved=False,orbital_resolved=True,suffix='')" - ] + ], + "outputs": [] }, { "cell_type": "code", @@ -505,11 +505,11 @@ "remove-output" ] }, - "outputs": [], "source": [ "fig = interactive_cohp_plot.get_plot()\n", "fig.show(renderer='notebook')" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -538,13 +538,13 @@ "remove-cell" ] }, - "outputs": [], "source": [ "# Load Lobster DOS\n", "directory = Path(\".\") / \"..\" / \"..\" / \"tests\" / \"test_data\" / \"NaCl_comp_range\"\n", "dos = Doscar(doscar=directory / 'DOSCAR.lobster.gz',\n", " structure_file=directory / 'POSCAR.gz')" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -574,7 +574,6 @@ "metadata": { "scrolled": false }, - "outputs": [], "source": [ "style.use('default') # Complete reset the matplotlib figure style\n", "style.use(get_style_list()[0]) # Use the LobsterPy style sheet for the generated plots\n", @@ -584,7 +583,8 @@ "dos_plotter.add_dos_dict(dos_dict=dos.completedos.get_element_dos()) # Add element dos\n", "dos_plotter.add_dos_dict(dos_dict=dos.completedos.get_spd_dos()) # add spd dos\n", "dos_plotter.get_plot(xlim=[-10, 3]);" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -599,12 +599,12 @@ "execution_count": null, "id": "660b35ad", "metadata": {}, - "outputs": [], "source": [ "dos_plotter = PlainDosPlotter(summed=True, stack=False, sigma=0.03)\n", "dos_plotter.add_site_orbital_dos(dos = dos.completedos, site_index=0, orbital='3s')\n", "dos_plotter.get_plot(xlim=[-10, 3]);" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -619,10 +619,10 @@ "execution_count": null, "id": "45988996", "metadata": {}, - "outputs": [], "source": [ "from lobsterpy.structuregraph.graph import LobsterGraph" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -641,7 +641,6 @@ "remove-cell" ] }, - "outputs": [], "source": [ "graph_NaCl_all = LobsterGraph(\n", " path_to_poscar=directory / \"POSCAR.gz\",\n", @@ -655,7 +654,8 @@ " which_bonds=\"all\",\n", " start=None,\n", ")" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -684,20 +684,20 @@ "execution_count": null, "id": "604bfa7e", "metadata": {}, - "outputs": [], "source": [ "graph_NaCl_all.sg.graph.nodes.data() # view node data" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "c77c2b06", "metadata": {}, - "outputs": [], "source": [ "graph_NaCl_all.sg.graph.edges.data() # view edge data" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -730,11 +730,11 @@ "execution_count": null, "id": "8882b3f5", "metadata": {}, - "outputs": [], "source": [ "from lobsterpy.featurize.batch import (BatchCoxxFingerprint, BatchDosFeaturizer,\n", " BatchSummaryFeaturizer, BatchStructureGraphs)" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -763,7 +763,6 @@ "remove-cell" ] }, - "outputs": [], "source": [ "# Initialize the batch COXX featurizer \n", "fp_cohp_bonding = BatchCoxxFingerprint(\n", @@ -775,7 +774,8 @@ " n_jobs=3,\n", " fingerprint_for='cohp' # changing this to cobi/coop will result in reading cobicar/coopcar file\n", " )" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -803,22 +803,22 @@ "metadata": { "scrolled": true }, - "outputs": [], "source": [ "# Access the fingerprints dataframe\n", "fp_cohp_bonding.fingerprint_df" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "cafc1f90", "metadata": {}, - "outputs": [], "source": [ "# Get the fingerprints similarity matrix\n", "fp_cohp_bonding.get_similarity_matrix_df()" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -849,7 +849,6 @@ "remove-cell" ] }, - "outputs": [], "source": [ "# Initialize the batch DOS featurizer\n", "batch_dos = BatchDosFeaturizer(path_to_lobster_calcs=directory / \"..\" / \"Featurizer_test_data\" / \"Lobster_calcs\", # path to parent lobster calcs\n", @@ -859,7 +858,8 @@ " fingerprint_type=\"summed_pdos\", # fingerprint type (s,p,d,f, summed_pdos)\n", " n_bins=256,\n", " n_jobs=3,)" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -883,22 +883,22 @@ "execution_count": null, "id": "3b958625", "metadata": {}, - "outputs": [], "source": [ "# get the DOS moments df\n", "batch_dos.get_df()" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": null, "id": "b9ad30a1", "metadata": {}, - "outputs": [], "source": [ "# get the DOS fingerprints df\n", "batch_dos.get_fingerprints_df()" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -930,7 +930,6 @@ "remove-cell" ] }, - "outputs": [], "source": [ "# Initialize batch summary featurizer\n", "summary_features = BatchSummaryFeaturizer(\n", @@ -941,7 +940,8 @@ " e_range=[-15, 0],\n", " n_jobs=3,\n", " )" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -968,11 +968,11 @@ "execution_count": null, "id": "1bfad526", "metadata": {}, - "outputs": [], "source": [ "# get summary stats features \n", "summary_features.get_df()" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -999,14 +999,14 @@ "remove-cell" ] }, - "outputs": [], "source": [ "batch_sg = BatchStructureGraphs(path_to_lobster_calcs=directory / \"..\" / \"Featurizer_test_data\" / \"Lobster_calcs\",\n", " add_additional_data_sg=True,\n", " which_bonds='all',\n", " n_jobs=3,\n", " start=None)" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -1028,11 +1028,11 @@ "execution_count": null, "id": "9a8178bc", "metadata": {}, - "outputs": [], "source": [ "# get the structure graphs df\n", "batch_sg.get_df()" - ] + ], + "outputs": [] } ], "metadata": { diff --git a/lobsterpy/plotting/__init__.py b/lobsterpy/plotting/__init__.py index 846b6c7c..3d715db3 100644 --- a/lobsterpy/plotting/__init__.py +++ b/lobsterpy/plotting/__init__.py @@ -7,13 +7,13 @@ import typing from itertools import cycle +from pathlib import Path from typing import TYPE_CHECKING, Any import matplotlib as mpl import numpy as np import plotly.graph_objs as go from matplotlib import pyplot as plt -from pkg_resources import resource_filename from pymatgen.core import Structure from pymatgen.electronic_structure.cohp import Cohp, CompleteCohp, IcohpCollection from pymatgen.electronic_structure.core import Spin @@ -24,8 +24,6 @@ from lobsterpy.cohp.analyze import Analysis from lobsterpy.plotting import layout_dicts as ld -base_style = resource_filename("lobsterpy.plotting", "lobsterpy_base.mplstyle") - def get_style_list( no_base_style: bool = False, @@ -43,7 +41,7 @@ def get_style_list( :param kwargs: matplotlib-style sheet keyword arguments """ - base = [] if no_base_style else [base_style] + base = [] if no_base_style else [str(Path(__file__).absolute().parent / "lobsterpy_base.mplstyle")] if styles is None: styles = [] diff --git a/pyproject.toml b/pyproject.toml index e3cd1659..1e79aef2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,13 +22,14 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Development Status :: 5 - Production/Stable", "Intended Audience :: Science/Research", "Operating System :: OS Independent", ] -requires-python = ">=3.9,<3.12" +requires-python = ">=3.9,<3.13" dependencies = [ - "pymatgen>=2024.4.13", + "pymatgen>=2024.5.1", "numpy", "typing", ] diff --git a/tests/cohp/test_describe.py b/tests/cohp/test_describe.py index 2d0344ee..6c35201e 100644 --- a/tests/cohp/test_describe.py +++ b/tests/cohp/test_describe.py @@ -371,10 +371,27 @@ def test_warnings(self): dos_comparison=True, bva_comp=False, ) - assert "Consider using DOSCAR.LSO.lobster" in str(w[0].message) - assert "Minimum energy range requested" in str(w[1].message) - assert "Maximum energy range requested" in str(w[2].message) - assert "Input DOS files have very few points" in str(w[3].message) + messages = [] + for warning in w: + messages.append(str(warning.message)) + count0 = 0 + count1 = 0 + count2 = 0 + count3 = 0 + for msg in messages: + if "Consider using DOSCAR.LSO.lobster" in msg: + count0 += 1 + if "Minimum energy range requested" in msg: + count1 += 1 + if "Maximum energy range requested" in msg: + count2 += 1 + if "Input DOS files have very few points" in msg: + count3 += 1 + + assert count0 == 1 + assert count1 == 1 + assert count2 == 1 + assert count3 == 1 calc_des = Description.get_calc_quality_description(calc_quality_warnings) @@ -419,8 +436,11 @@ def test_warnings(self): potcar_symbols=["Be_sv", "Te"], bva_comp=True, ) - assert "Consider rerunning the calc with the minimum basis" in str(w3[0].message) - + assert ( + str(w3[0].message) == "Consider rerunning the calc with the minimum basis as well. " + "Choosing is larger basis set is recommended if you see a significant " + "improvement of the charge spilling and material has non-zero band gap." + ) calc_des3 = Description.get_calc_quality_description(calc_quality_warnings3) assert calc_des3 == [