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
Prev Previous commit
Next Next commit
update bond labels in label resolved, add more tests to increase cove…
…rage
  • Loading branch information
naik-aakash committed Jun 1, 2023
commit afd32e3e268814dd34da36417d26c30c36f0edcf
2 changes: 1 addition & 1 deletion lobsterpy/TestData/interactive_plotter_ref/analyse_K3Sb.json
100755 → 100644

Large diffs are not rendered by default.

49 changes: 31 additions & 18 deletions lobsterpy/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ def get_plot(
Returns:
A matplotlib object.
"""
if self.are_coops:
if self.are_coops and not self.are_cobis:
cohp_label = "COOP"
elif self.are_cobis:
elif self.are_cobis and not self.are_coops:
cohp_label = "COBI"
elif self.are_cobis and self.are_coops:
raise ValueError(
"Plot data should not contain COBI and COOP data at same time"
)
else:
cohp_label = "COHP"

Expand Down Expand Up @@ -301,7 +305,16 @@ def add_all_relevant_cohps(
populations = cohp.get_cohp()
int_populations = cohp.get_icohp()
outer_key = label_with_count + label_addition
key = label
struct = analyse.structure
atom_pairs = []
for site in complete_cohp.bonds[label]["sites"]:
atom = site.species_string + str(struct.sites.index(site) + 1)
atom_pairs.append(atom)
key = "{}: {} ({} \u00c5)".format(
label,
"-".join(atom_pairs),
str(round(complete_cohp.bonds[label]["length"], 2)),
)
self._cohps[outer_key].update(
{
key: {
Expand All @@ -313,16 +326,16 @@ def add_all_relevant_cohps(
}
)

alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
new_label = (
bond_key.split(":")[0].strip(alpha)
+ "_"
+ bond_key.split(":")[1].strip()
+ ": "
+ label
)
# alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
# new_label = (
# bond_key.split(":")[0].strip(alpha)
# + "_"
# + bond_key.split(":")[1].strip()
# + ": "
# + label
# )
naik-aakash marked this conversation as resolved.
Show resolved Hide resolved
outer_key = "All"
key = new_label + label_addition
key = key + label_addition
self._cohps[outer_key].update(
{
key: {
Expand Down Expand Up @@ -487,10 +500,14 @@ def get_plot(
Returns:
A plotly.graph_objects.Figure object.
"""
if self.are_coops:
if self.are_coops and not self.are_cobis:
cohp_label = "COOP"
elif self.are_cobis:
elif self.are_cobis and not self.are_coops:
cohp_label = "COBI"
elif self.are_cobis and self.are_coops:
raise ValueError(
"Plot data should not contain COBI and COOP data at same time"
)
else:
cohp_label = "COHP"

Expand Down Expand Up @@ -631,10 +648,6 @@ def get_plot(
fig.update_yaxes(range=ylim)

fig.update_yaxes(automargin=True)
# TODO:
# improve display of legend
# somehow y axis scaling inside image?
# maybe dashed line at Ef

return fig

Expand Down
53 changes: 53 additions & 0 deletions lobsterpy/plotting/test/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,39 @@ def test_add_cohps_from_plot_data_json(self):
self.assertEqual(og_trace.line, ref_trace.line)
self.assertEqual(og_trace.visible, ref_trace.visible)

def test_plot_labels(self):
# plain cohp plotter
self.plotter = PlainCohpPlotter(are_cobis=True)
fig = self.plotter.get_plot().gca()

self.assertEqual(fig.get_xlabel(), "COBI")

self.plotter = PlainCohpPlotter(are_coops=True)
fig = self.plotter.get_plot().gca()

self.assertEqual(fig.get_xlabel(), "COOP")

self.plotter = PlainCohpPlotter()
fig = self.plotter.get_plot().gca()

self.assertEqual(fig.get_xlabel(), "$-$COHP")

# interactive plotter
self.iplotter = InteractiveCohpPlotter(are_cobis=True)
fig = self.iplotter.get_plot()

self.assertEqual(fig.layout.xaxis["title"]["text"], "COBI")

self.iplotter = InteractiveCohpPlotter(are_coops=True)
fig = self.iplotter.get_plot()

self.assertEqual(fig.layout.xaxis["title"]["text"], "COOP")

self.iplotter = InteractiveCohpPlotter()
fig = self.iplotter.get_plot()

self.assertEqual(fig.layout.xaxis["title"]["text"], "−COHP")


class TestPlotterExceptions(unittest.TestCase):
def test_plotter_exception(self):
Expand All @@ -226,3 +259,23 @@ def test_plotter_exception(self):
err.exception.__str__(),
"The data provided could not be converted to cohp object.Please recheck the input data",
)

with self.assertRaises(Exception) as err:
self.iplotter = InteractiveCohpPlotter(are_cobis=True, are_coops=True)

fig = self.iplotter.get_plot()

self.assertEqual(
err.exception.__str__(),
"Plot data should not contain COBI and COOP data at same time",
)

with self.assertRaises(Exception) as err:
self.plotter = PlainCohpPlotter(are_cobis=True, are_coops=True)

fig = self.plotter.get_plot()

self.assertEqual(
err.exception.__str__(),
"Plot data should not contain COBI and COOP data at same time",
)