From 45fd0385fd7d22da9066c5dcfead2ff123fca6a5 Mon Sep 17 00:00:00 2001 From: samwaseda Date: Sun, 19 May 2024 16:44:58 +0000 Subject: [PATCH 1/5] separate drawing cell for plotly --- structuretoolkit/visualize.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index 4f0f67078..20db8167f 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -164,6 +164,14 @@ def _get_box_skeleton(cell: np.ndarray): # All 12 two-point lines on the unit square return all_lines @ cell +def _draw_box_plotly(fig, structure): + cell = get_cell(structure) + data = fig.data + for lines in _get_box_skeleton(cell): + fig = px.line_3d(**{xx: vv for xx, vv in zip(["x", "y", "z"], lines.T)}) + fig.update_traces(line_color="#000000") + data = fig.data + data + return go.Figure(data=data) def _plot3d_plotly( structure: Atoms, @@ -223,12 +231,7 @@ def _plot3d_plotly( ), ) if show_cell: - data = fig.data - for lines in _get_box_skeleton(structure.cell): - fig = px.line_3d(**{xx: vv for xx, vv in zip(["x", "y", "z"], lines.T)}) - fig.update_traces(line_color="#000000") - data = fig.data + data - fig = go.Figure(data=data) + fig = _draw_box_plotly(fig, structure) fig.layout.scene.camera.projection.type = camera rot = _get_orientation(view_plane).T rot[0, :] *= distance_from_camera * 1.25 From 5675ead2cfe624f6ba5517291f6fbad24bde22f5 Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Mon, 20 May 2024 06:06:38 +0000 Subject: [PATCH 2/5] Format black --- structuretoolkit/visualize.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index 20db8167f..df0478abc 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -164,6 +164,7 @@ def _get_box_skeleton(cell: np.ndarray): # All 12 two-point lines on the unit square return all_lines @ cell + def _draw_box_plotly(fig, structure): cell = get_cell(structure) data = fig.data @@ -173,6 +174,7 @@ def _draw_box_plotly(fig, structure): data = fig.data + data return go.Figure(data=data) + def _plot3d_plotly( structure: Atoms, show_cell: bool = True, From fa34ca11a068e1ea2b854aa63e178f40bac12a24 Mon Sep 17 00:00:00 2001 From: samwaseda Date: Mon, 20 May 2024 06:15:48 +0000 Subject: [PATCH 3/5] pass px --- structuretoolkit/visualize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index 20db8167f..8ef8936a8 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -164,7 +164,7 @@ def _get_box_skeleton(cell: np.ndarray): # All 12 two-point lines on the unit square return all_lines @ cell -def _draw_box_plotly(fig, structure): +def _draw_box_plotly(fig, structure, px): cell = get_cell(structure) data = fig.data for lines in _get_box_skeleton(cell): @@ -231,7 +231,7 @@ def _plot3d_plotly( ), ) if show_cell: - fig = _draw_box_plotly(fig, structure) + fig = _draw_box_plotly(fig, structure, px) fig.layout.scene.camera.projection.type = camera rot = _get_orientation(view_plane).T rot[0, :] *= distance_from_camera * 1.25 From 43b59baeb344350ebd9a9c3982bccf88dfd33578 Mon Sep 17 00:00:00 2001 From: samwaseda Date: Mon, 20 May 2024 06:17:29 +0000 Subject: [PATCH 4/5] replace get_cell which is not defined in this PR --- structuretoolkit/visualize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index 03d9c814d..d3423c69f 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -166,7 +166,7 @@ def _get_box_skeleton(cell: np.ndarray): def _draw_box_plotly(fig, structure, px): - cell = get_cell(structure) + cell = structure.cell data = fig.data for lines in _get_box_skeleton(cell): fig = px.line_3d(**{xx: vv for xx, vv in zip(["x", "y", "z"], lines.T)}) From 29f5eeac530561a82d065dc575842dd1b0dd805a Mon Sep 17 00:00:00 2001 From: samwaseda Date: Mon, 20 May 2024 06:18:38 +0000 Subject: [PATCH 5/5] pass go --- structuretoolkit/visualize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index d3423c69f..e2634f855 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -165,7 +165,7 @@ def _get_box_skeleton(cell: np.ndarray): return all_lines @ cell -def _draw_box_plotly(fig, structure, px): +def _draw_box_plotly(fig, structure, px, go): cell = structure.cell data = fig.data for lines in _get_box_skeleton(cell): @@ -233,7 +233,7 @@ def _plot3d_plotly( ), ) if show_cell: - fig = _draw_box_plotly(fig, structure, px) + fig = _draw_box_plotly(fig, structure, px, go) fig.layout.scene.camera.projection.type = camera rot = _get_orientation(view_plane).T rot[0, :] *= distance_from_camera * 1.25