-
Notifications
You must be signed in to change notification settings - Fork 29
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
Changes from 38 commits
436e118
bf77096
fa554ab
5b4eedd
6946097
7eaf71b
9df8c4c
9bec1b3
ae21a80
79eb6b5
e22744b
376b009
6d42115
e8ba02e
52bd8a9
7ea3f94
cd80e13
5a7bda3
773ef9b
2ca4f13
3c7bdb7
c58b9c6
caf2d01
cc230ff
4343ac4
807c44c
d33c63f
3c3bd40
6fa68ef
c2bb10a
84df95a
af242ed
447f287
7de1cf3
7df457d
afd32e3
0594cdf
8f6918e
71240bc
aa80966
b43b74c
655e638
a667a72
5165ba3
a6b54f1
bccacde
99e2671
32a5dfd
20cd3bd
36f0de9
545e6c5
2bac25b
0896844
abcb119
1eed7f8
250d236
d012563
f5f6a8d
79d5749
3924374
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from pathlib import Path | ||
|
||
from lobsterpy.plotting import PlainCohpPlotter | ||
from lobsterpy.plotting import InteractiveCohpPlotter | ||
|
||
|
||
class Description: | ||
|
@@ -223,6 +224,7 @@ def plot_cohps( | |
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. | ||
title: sets the title of figure generated | ||
skip_show (bool): if True, the plot will not be shown. | ||
|
||
Returns: | ||
|
@@ -268,6 +270,62 @@ def plot_cohps( | |
if not save: | ||
plot.close() | ||
|
||
def plot_interactive_cohps( | ||
self, | ||
save_as_html=False, | ||
filename=None, | ||
ylim=None, | ||
xlim=None, | ||
integrated=False, | ||
title="", | ||
sigma=None, | ||
skip_show=False, | ||
): | ||
""" | ||
Will automatically generate interactive plots of the most relevant COHP | ||
|
||
Args: | ||
save_as_html (bool): will save the plot to a html 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. | ||
title : Title of the interactive plot | ||
skip_show (bool): if True, the plot will not be shown. | ||
|
||
Returns: | ||
A plotly.graph_objects.Figure object. | ||
|
||
""" | ||
cba_cohp_plot_data = {} # Initialize dict to store plot data | ||
|
||
set_cohps = self.analysis_object.set_cohps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
set_labels_cohps = self.analysis_object.set_labels_cohps | ||
set_inequivalent_cations = self.analysis_object.set_inequivalent_ions | ||
structure = self.analysis_object.structure | ||
|
||
for _iplot, (ication, labels, cohps) in enumerate( | ||
zip(set_inequivalent_cations, set_labels_cohps, set_cohps) | ||
): | ||
label_str = f"{str(structure[ication].specie)}{str(ication + 1)}: " | ||
for label, cohp in zip(labels, cohps): | ||
if label is not None: | ||
cba_cohp_plot_data[label_str + label] = cohp | ||
|
||
ia = InteractiveCohpPlotter() | ||
ia.add_cohps_from_plot_data(plot_data_dict=cba_cohp_plot_data) | ||
plot = ia.get_plot(integrated=integrated, xlim=xlim, ylim=ylim, sigma=sigma) | ||
|
||
plot.update_layout(title_text=title) | ||
if save_as_html: | ||
plot.write_html(filename, include_mathjax="cdn") | ||
if not skip_show: | ||
return plot.show() | ||
|
||
return plot | ||
|
||
@staticmethod | ||
def _coordination_environment_to_text(ce): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't
show=True
be a more natural way of expressing this? (I appreciate this also applies to plot_cohps...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. It's like this in the normal plotter classes as well as I wanted to quickly provide a fix for one project and did not fully think it through ... 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will replace it with "hide" as we would otherwise also need to adapt the atomate2 workflows and schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand, how would using "show" break a workflow but using "hide" not break it? The default behaviour can be the same either way. (i.e.
show=True
is equivalent toskip_show=False
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are correct. We have to update it in any case as I changed the argument name...🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@naik-aakash , maybe we can fix this here and the snake case issue of "whichbonds" as well... As we will break the atomate2 workflow in any case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to invert the logic at the CLI with something like
add_argument('--hide', action='store_false', dest='show', ...)