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

Interactive plotter #81

Merged
merged 60 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
436e118
First draft of InteractiveCohpPlotter
kaueltzen Nov 15, 2022
bf77096
Fixed layout_dict import, color scheme
kaueltzen Nov 16, 2022
fa554ab
fixed relevant bonds iter. error, added x axis rangeslider
kaueltzen Nov 24, 2022
5b4eedd
Merge branch 'interactive_plotter' of github.com:ahtakkatha/LobsterPy…
kaueltzen Nov 24, 2022
6946097
Fixed merging error
kaueltzen Nov 29, 2022
7eaf71b
Added plot_interactive_cohps() to description class (summed COHPs)
kaueltzen Dec 4, 2022
9df8c4c
Fixed plot_interactive_cohps() to plot COHPs in same plot
kaueltzen Dec 4, 2022
9bec1b3
Made rangeslider optional, fixed legend display, added different inte…
kaueltzen Dec 16, 2022
ae21a80
Merge branch 'JaGeo:main' into interactive_plotter
kaueltzen Dec 19, 2022
79eb6b5
Removed integration options that were recently moved to another branc…
kaueltzen Apr 27, 2023
e22744b
Merge branch 'main' into interactive_plotter
kaueltzen Apr 27, 2023
376b009
Removed redundant COHPCAR reading (significantly faster), modified pl…
kaueltzen Apr 27, 2023
6d42115
Fixed importation error.
kaueltzen Apr 27, 2023
e8ba02e
Merge branch 'JaGeo:main' into interactive_plotter
naik-aakash May 5, 2023
52bd8a9
add dropdown to interactive plotter layout, add option to plot direct…
naik-aakash May 15, 2023
7ea3f94
Merge branch 'JaGeo:main' into interactive_plotter
naik-aakash May 15, 2023
cd80e13
Merge branch 'JaGeo:main' into interactive_plotter
naik-aakash May 16, 2023
5a7bda3
update plotter
naik-aakash May 16, 2023
773ef9b
adapt plot_interactive_cohps of describe method
naik-aakash May 16, 2023
2ca4f13
Fix linting issues
naik-aakash May 16, 2023
3c7bdb7
add preliminary tests for interactive plotter
naik-aakash May 17, 2023
c58b9c6
attempt to fix failing 3.9 and 3.10 tests
naik-aakash May 18, 2023
caf2d01
fix interactive plot test
naik-aakash May 18, 2023
cc230ff
Fix interactive plotlyfigure object data checking
naik-aakash May 18, 2023
4343ac4
remove unused import
naik-aakash May 18, 2023
807c44c
add test for interactive plotter from describe method
naik-aakash May 18, 2023
d33c63f
update test_plotting.py
naik-aakash May 18, 2023
3c3bd40
fix pylint error for describe.py
naik-aakash May 18, 2023
6fa68ef
update test_plotting.py
naik-aakash May 18, 2023
c2bb10a
make interactive plot labels consistent to analyze output, add test f…
naik-aakash May 22, 2023
84df95a
clean up interactive plotter code,fix handle duplicate label with lab…
naik-aakash May 23, 2023
af242ed
more cleanup: remove redundant dropdown from interactive plotter, upd…
naik-aakash May 23, 2023
447f287
remove redundant _update_cohps_data method, simplify code logic
naik-aakash May 23, 2023
7de1cf3
Fix visibility inconsitency for "All" key in dropdown menu
naik-aakash May 24, 2023
7df457d
Merge branch 'JaGeo:main' into interactive_plotter
naik-aakash May 31, 2023
afd32e3
update bond labels in label resolved, add more tests to increase cove…
naik-aakash Jun 1, 2023
0594cdf
Merge branch 'interactive_plotter' of github.com:kaueltzen/LobsterPy …
naik-aakash Jun 1, 2023
8f6918e
Merge branch 'JaGeo:main' into interactive_plotter
naik-aakash Jun 5, 2023
71240bc
Merge branch 'main' of github.com:JaGeo/LobsterPy into interactive_pl…
JaGeo Jun 20, 2023
aa80966
Change set to seq
JaGeo Jun 20, 2023
b43b74c
fix bug and reformat
JaGeo Jun 20, 2023
655e638
Fix hide
JaGeo Jun 20, 2023
a667a72
Fix cation anion
JaGeo Jun 20, 2023
5165ba3
Fix documentation
JaGeo Jun 20, 2023
a6b54f1
Fix cation anion
JaGeo Jun 20, 2023
bccacde
code reformatting based on review
naik-aakash Jun 30, 2023
99e2671
remove unused import
naik-aakash Jun 30, 2023
32a5dfd
fix doc string
naik-aakash Jun 30, 2023
20cd3bd
fix exception text
naik-aakash Jun 30, 2023
36f0de9
add docstring to private _insert_number_of_bonds_in_label
naik-aakash Jun 30, 2023
545e6c5
fix doc-string linting error, improve code readability
naik-aakash Jun 30, 2023
2bac25b
imporve code formatting
naik-aakash Jul 24, 2023
0896844
add color arg to get_plot, refactor add_all_relevant_cohps method, ad…
naik-aakash Jul 24, 2023
abcb119
run black
naik-aakash Jul 24, 2023
1eed7f8
removed __future__ import
naik-aakash Jul 24, 2023
250d236
attempt to fix python3.8 linitng error
naik-aakash Jul 24, 2023
d012563
remove unnecessary variable assignment
naik-aakash Jul 24, 2023
f5f6a8d
update tests for custom colors, update tutorial for interactiveplotte…
naik-aakash Jul 25, 2023
79d5749
update tutorial files
naik-aakash Jul 25, 2023
3924374
update doc generation conf.py file to exclude plotter test
naik-aakash Jul 25, 2023
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
61 changes: 61 additions & 0 deletions lobsterpy/cohp/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pathlib import Path
from lobsterpy.plotting import PlainCohpPlotter
from LobsterPy.lobsterpy.plotting import InteractiveCohpPlotter


class Description:
Expand Down Expand Up @@ -266,6 +267,66 @@ def plot_cohps(
else:
plot.close()

def plot_interactive_cohps(
self,
save_as_html=False,
filename=None,
ylim=None,
xlim=None,
integrated=False,
title="",
sigma=None,
):
"""
Will automatically generate interactive plots of the most relevant COHP

Args:
save (bool): will save the plot to a file
filename (str/Path):
ylim (list of float): energy scale that is shown in plot (eV)
xlim(list of float): energy range for COHPs in eV
integrated (bool): if True, integrated COHPs will be shown
sigma: Standard deviation of Gaussian broadening applied to
population data. If None, no broadening will be added.
skip_show (bool): if True, the plot will not be shown.

Returns:
A plotly.graph_objects.Figure object.

"""
set_cohps = self.analysis_object.set_cohps
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is quite confusing to have data attributes named "set_x" as this looks like it will be a setter method like obj.set_cohps(cohps). (Again, I appreciate that isn't really an issue with this PR!)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you are correct. We can still fix this. It will amke the code mich better.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have adapted the name. As we are only using this within the package so far, it should not have any larger effects.

if self.analysis_object.whichbonds == "cation-anion":
set_inequivalent_cations = self.analysis_object.set_inequivalent_ions
elif self.analysis_object.whichbonds == "all":
set_inequivalent_cations = self.analysis_object.set_inequivalent_ions
set_labels_cohps = self.analysis_object.set_labels_cohps
structure = self.analysis_object.structure

for iplot, (ication, labels, cohps) in enumerate(
zip(set_inequivalent_cations, set_labels_cohps, set_cohps)
):

namecation = str(structure[ication].specie)

ia = InteractiveCohpPlotter()
for label, cohp in zip(labels, cohps):
if label is not None:
ia.add_cohp(namecation + str(ication + 1) + ": " + label, cohp)
plot = ia.get_plot(integrated=integrated, xlim=xlim, ylim=ylim)

plot.update_layout(title_text=title)
if save_as_html:
if len(set_inequivalent_cations) > 1:
if isinstance(filename, str):
filename = Path(filename)
filename_new = (
filename.parent / f"{filename.stem}-{iplot}{filename.suffix}"
)
else:
filename_new = filename
plot.write_html(filename_new)
naik-aakash marked this conversation as resolved.
Show resolved Hide resolved
plot.show()

@staticmethod
def _coordination_environment_to_text(ce):
"""
Expand Down
24 changes: 4 additions & 20 deletions lobsterpy/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,26 +228,11 @@ def _broaden(energies: np.ndarray, population: np.ndarray, sigma=None, cutoff=4.
return convolve(population, kernel, mode="same") / kernel.sum()


class InteractiveCohpPlotter:
class InteractiveCohpPlotter(CohpPlotter):
"""
Interactive COHP plotter to view all relevant / multiple COHPs in one figure
"""

def __init__(self, zero_at_efermi=True, are_coops=False, are_cobis=False):
"""
Args:
zero_at_efermi: Whether to shift all populations to have zero
energy at the Fermi level. Defaults to True.
are_coops: Switch to indicate that these are COOPs, not COHPs.
Defaults to False for COHPs.
are_cobis: Switch to indicate that these are COBIs, not COHPs/COOPs.
Defaults to False for COHPs
"""
self.zero_at_efermi = zero_at_efermi
self.are_coops = are_coops
self.are_cobis = are_cobis
self._cohps = {}

def add_all_relevant_cohps(self, complete_cohp, analyse):
"""
Adds all relevant COHPs from lobsterpy analyse object.
Expand Down Expand Up @@ -355,13 +340,12 @@ def get_plot(
else:
energy_label = "$E$ (eV)"


# Setting up repeating color scheme (same as for matplotlib plots in .mplstyle)
palette = ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999']
pal_iter = cycle(palette)
naik-aakash marked this conversation as resolved.
Show resolved Hide resolved

traces = []
for item in self._cohps.values():
for label, item in self._cohps.items():
population_key = item["ICOHP"] if integrated else item["COHP"]
band_color = next(pal_iter)
for spin in [Spin.up, Spin.down]:
Expand All @@ -370,7 +354,7 @@ def get_plot(
x = population if invert_axes else item["energies"]
y = item["energies"] if invert_axes else population
if spin == Spin.up:
trace = go.Scatter(x=x, y=y, name=item["plot_label"])
trace = go.Scatter(x=x, y=y, name=label)
trace.update(ld.spin_up_trace_style_dict)
else:
trace = go.Scatter(x=x, y=y, name="")
Expand Down Expand Up @@ -399,7 +383,7 @@ def get_plot(
#TODO:
# improve display of legend
# somehow y axis scaling inside image?
# inherit CohpPlotter fr. pymatgen?
# add sigma arg
# maybe dashed line at Ef

return fig