Skip to content

Commit

Permalink
Merge branch 'JaGeo:main' into structure_graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
naik-aakash authored Aug 11, 2023
2 parents 7f7258a + 24025ef commit cb915d2
Show file tree
Hide file tree
Showing 22 changed files with 1,112 additions and 76 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
split: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Number of splits
split: [1, 2, 3, 4, 5] # Number of splits

steps:
- uses: actions/checkout@v3
Expand All @@ -39,8 +39,10 @@ jobs:
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest and coverage
# run this locally to update tests durations
# pytest --cov=lobsterpy --cov-append --splits 1 --group 1 --durations-path ./lobsterpy/TestData/.pytest-split-durations --store-durations
run: |
pytest --cov=lobsterpy --cov-append --splits 10 --group ${{ matrix.split }} --durations-path ./lobsterpy/.pytest-split-durations
pytest --cov=lobsterpy --cov-append --splits 5 --group ${{ matrix.split }} --durations-path ./lobsterpy/TestData/.pytest-split-durations
- name: Upload coverage
uses: actions/upload-artifact@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## v0.3.0
- addition of an interactive plotter by @naik-aakash and @kaueltzen. Reviews by @ajjackson and @jageo
## v0.2.9
- fix the error handling in cases ChemEnv cannot determine a coordination environment and we use coordination numbers instead for the cation-anion mode

Expand Down
14 changes: 14 additions & 0 deletions docs/source/Lobsterpy_tutorial_files/CdF2.html

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions docs/source/commandlineinterface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ command. Below is an example and sample output using this command.
.. image:: Lobsterpy_tutorial_files/ICOHP.png

- ``lobsterpy automatic-plot-ia`` command can be used to obtain a interactive plot of analysis automatically. It will evaluate all COHPs with ICOHP values down to
10% of the strongest ICOHP. You can enforce an analysis of all bonds
by using ``lobsterpy automatic-plot-ia --allbonds``. Currently, the
computed Mulliken charges will be used to determine cations and
anions. If no CHARGE.lobster is available, the algorithm will fall
back to the BondValence analysis from pymatgen. Please be aware that
LobsterPy can only analyze bonds that have been included in the
initial Lobster computation. Below is an example and sample output
using this command. You can also obtain label resolved plot using
``lobsterpy automatic-plot-ia --allbonds --label-resolved`` option

.. raw:: html
:file: Lobsterpy_tutorial_files/CdF2.html

2. Plotting of COHPs/COBIs/COOPs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 3 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["../../lobsterpy/test","../../lobsterpy/cohp/test","../../lobsterpy/TestData","Thumbs.db", ".DS_Store",]
exclude_patterns = ["../../lobsterpy/test","../../lobsterpy/cohp/test","../../lobsterpy/plotting/test","../../lobsterpy/TestData","Thumbs.db", ".DS_Store",]

def run_apidoc(_):
import subprocess
Expand All @@ -57,9 +57,10 @@ def run_apidoc(_):
output_path = os.path.abspath(os.path.dirname(__file__))
excludes = glob.glob(os.path.join(output_path, "../../lobsterpy/cohp/test"))
excludes1 = glob.glob(os.path.join(output_path, "../../lobsterpy/test"))
excludes2 = glob.glob(os.path.join(output_path, "../../lobsterpy/plotting/test"))
module = os.path.join(output_path, "../../lobsterpy")
cmd_path = "sphinx-apidoc"
command = [cmd_path, "-e", "-o", output_path, module, " ".join(excludes)," ".join(excludes1), "--force"]
command = [cmd_path, "-e", "-o", output_path, module, " ".join(excludes)," ".join(excludes1)," ".join(excludes2), "--force"]
subprocess.check_call(command)


Expand Down
8 changes: 7 additions & 1 deletion docs/source/pythoninterface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ Import the necessary modules
# Automatic plots
describe.plot_cohps(ylim=[-10, 2], xlim=[-4, 4])
.. image:: Lobsterpy_tutorial_files/Lobsterpy_tutorial_38_0.png

.. code:: ipython3
# Automatic interactive plots
describe.plot_interactive_cohps()
.. image:: Lobsterpy_tutorial_files/Lobsterpy_tutorial_38_0.png
.. raw:: html
:file: Lobsterpy_tutorial_files/CdF2.html


.. code:: ipython3
Expand Down
62 changes: 62 additions & 0 deletions lobsterpy/TestData/.pytest-split-durations
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_ICOHP_sum_CdF": 74.60168297588825,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_ICOHP_sum_NaCl": 70.55211293883622,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_BaTiO3": 71.29058763198555,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_CdF": 72.19752324093133,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_K3Sb": 72.58499348722398,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_K3Sb_all": 72.2198564982973,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_NaCl_Mulliken": 70.49185390630737,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_NaCl_all": 66.83933831006289,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_NaCl_nan": 64.23106821579859,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_NaCl_valences": 66.02353994967416,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_NaSbF6": 67.69128251960501,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_all_attributes_NaSbF6_anbd": 77.39906527288258,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_exception": 74.9940577801317,
"lobsterpy/cohp/test/test_analyze.py::TestAnalyse::test_final_dicts": 71.91315609263256,
"lobsterpy/cohp/test/test_describe.py::TestDescribe::test_coordination_environment_to_text": 60.532792599871755,
"lobsterpy/cohp/test/test_describe.py::TestDescribe::test_plot": 88.35905195400119,
"lobsterpy/cohp/test/test_describe.py::TestDescribe::test_text": 58.00953777041286,
"lobsterpy/cohp/test/test_describe.py::TestDescribe::test_write_description": 62.47553640883416,
"lobsterpy/plotting/test/test_plotting.py::InteractiveCohpPlotterTest::test_add_all_relevant_cohps_K3Sb": 48.36465826490894,
"lobsterpy/plotting/test/test_plotting.py::InteractiveCohpPlotterTest::test_add_all_relevant_cohps_NaCl": 14.395964342169464,
"lobsterpy/plotting/test/test_plotting.py::InteractiveCohpPlotterTest::test_add_cohps_by_lobster_label_NaCl": 14.143686045892537,
"lobsterpy/plotting/test/test_plotting.py::InteractiveCohpPlotterTest::test_add_cohps_from_plot_data": 14.694280326366425,
"lobsterpy/plotting/test/test_plotting.py::InteractiveCohpPlotterTest::test_add_cohps_from_plot_data_json": 18.901866920292377,
"lobsterpy/plotting/test/test_plotting.py::InteractiveCohpPlotterTest::test_plot_colors": 50.03976339753717,
"lobsterpy/plotting/test/test_plotting.py::InteractiveCohpPlotterTest::test_plot_labels": 14.167344754561782,
"lobsterpy/plotting/test/test_plotting.py::TestPlotterExceptions::test_plotter_exception": 0.0038974578492343426,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_errors[args0-IndexError]": 0.19080257462337613,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_errors[args1-IndexError]": 0.20083071431145072,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_errors[args2-IndexError]": 0.22901855362579226,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_interactive_plotter": 0.9448978300206363,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args0]": 1.3463104199618101,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args10]": 0.37567619839683175,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args11]": 0.49541555624455214,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args12]": 0.3643593993037939,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args13]": 0.3989682081155479,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args14]": 0.3308272184804082,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args15]": 0.6352701694704592,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args16]": 1.414562267716974,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args17]": 0.6187749514356256,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args18]": 0.45203554816544056,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args1]": 1.277391605079174,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args2]": 1.110627113841474,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args3]": 0.8713983865454793,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args4]": 0.7319109700620174,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args5]": 0.9687392474152148,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args6]": 0.9414747003465891,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args7]": 0.48369616316631436,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args8]": 0.5601856517605484,
"lobsterpy/test/test_cli.py::TestCLI::test_cli_results[args9]": 0.37080864515155554,
"lobsterpy/test/test_cli.py::TestCLI::test_generate_ref_data": 0.004219974856823683,
"lobsterpy/test/test_cli.py::TestCLI::test_gz_cli_plot": 3.995695054065436,
"lobsterpy/test/test_cli.py::TestCLI::test_gz_file_cli": 14.55165875563398,
"lobsterpy/test/test_cli.py::TestCLI::test_gz_file_cli_lobsterinput_generation": 0.01727287331596017,
"lobsterpy/test/test_cli.py::TestCLI::test_hideplot_cli": 3.988109601661563,
"lobsterpy/test/test_cli.py::TestCLI::test_iaplot_saved": 0.8917648741044104,
"lobsterpy/test/test_cli.py::TestCLI::test_json_saved": 1.117712059058249,
"lobsterpy/test/test_cli.py::TestCLI::test_lobsterin_generation": 0.979003781452775,
"lobsterpy/test/test_cli.py::TestCLI::test_lobsterin_generation_error": 0.9563554651103914,
"lobsterpy/test/test_cli.py::TestCLI::test_lobsterin_generation_error_userbasis": 0.01105657871812582,
"lobsterpy/test/test_cli.py::TestCLI::test_plot_saved": 0.9114251169376075
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lobsterpy/TestData/interactive_plotter_ref/fig_mp8818.json

Large diffs are not rendered by default.

Binary file not shown.
66 changes: 62 additions & 4 deletions lobsterpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from lobsterpy.cohp.analyze import Analysis
from lobsterpy.cohp.describe import Description
from lobsterpy.plotting import PlainCohpPlotter, get_style_list
from lobsterpy.plotting import PlainCohpPlotter, get_style_list, InteractiveCohpPlotter


def main() -> None:
Expand Down Expand Up @@ -199,6 +199,14 @@ def get_parser() -> argparse.ArgumentParser:
plotting_group.add_argument(
"--fontsize", "--font-size", type=float, default=None, help="Base font size"
)
plotting_group.add_argument(
"--labelresolved",
"--label-resolved",
action="store_true",
help="Will create automatic interactive plots with all relevant bond labels. "
"If not set, plots will consists of summed cohps. (This argument works only"
"for interactive plots) ",
)

auto_parent = argparse.ArgumentParser(add_help=False)
auto_group = auto_parent.add_argument_group("Automatic analysis")
Expand Down Expand Up @@ -244,6 +252,16 @@ def get_parser() -> argparse.ArgumentParser:
),
)

subparsers.add_parser(
"automatic-plot-ia",
aliases=["automaticplotia", "autoplotia", "auto-plot-ia"],
parents=[input_parent, auto_parent, plotting_parent],
help=(
"Creates an interactive plot of most important COHPs automatically. Implementation "
"of COBIs and COOPs will follow."
),
)

subparsers.add_parser(
"create-inputs",
aliases=["createinputs"],
Expand Down Expand Up @@ -349,6 +367,11 @@ def run(args):
"description",
"automatic-plot",
"plot",
"automatic-plot-ia",
"interactplot",
"automaticplotia",
"auto-plot-ia",
"autoplotia",
]:
# Check for .gz files exist for default values and update accordingly
default_files = {
Expand All @@ -373,7 +396,17 @@ def run(args):
if args.action in ["automaticplot", "autoplot", "auto-plot"]:
args.action = "automatic-plot"

if args.action in ["description", "automatic-plot"]:
if args.action in ["automaticplotia", "automatic-plot-ia", "auto-plot-ia"]:
args.action = "automaticplotia"

if args.action in [
"description",
"automatic-plot",
"automatic-plot-ia",
"automaticplotia",
"auto-plot-ia",
"autoplotia",
]:
if args.allbonds:
whichbonds = "all"
else:
Expand All @@ -395,7 +428,14 @@ def run(args):
with open(args.json, "w") as fd:
json.dump(analysedict, fd)

if args.action in ["plot", "automatic-plot"]:
if args.action in [
"plot",
"automatic-plot",
"automaticplotia",
"automatic-plot-ia",
"auto-plot-ia",
"autoplotia",
]:
style_kwargs = {}
style_kwargs.update(_user_figsize(args.width, args.height))
if args.fontsize:
Expand All @@ -422,7 +462,25 @@ def run(args):
filename=args.save_plot,
title=args.title,
sigma=sigma,
skip_show=args.hideplot,
hide=args.hideplot,
)

if args.action in [
"automatic-plot-ia",
"automaticplotia",
"auto-plot-ia",
"autoplotia",
]:
describe.plot_interactive_cohps(
ylim=args.ylim,
xlim=args.xlim,
integrated=args.integrated,
save_as_html=args.save_plot,
filename=args.save_plot,
title=args.title,
sigma=sigma,
hide=args.hideplot,
label_resolved=args.labelresolved,
)

if args.action == "plot":
Expand Down
Loading

0 comments on commit cb915d2

Please sign in to comment.