From 57e268e85ab025db8643fe1845d781528e0e9433 Mon Sep 17 00:00:00 2001 From: samwaseda Date: Thu, 8 Feb 2024 13:21:34 +0000 Subject: [PATCH 1/6] make height available --- structuretoolkit/visualize.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index aa67049fe..a8c3899bb 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -41,6 +41,7 @@ def plot3d( view_plane=np.array([0, 0, 1]), distance_from_camera=1.0, opacity=1.0, + height=600 ): """ Plot3d relies on NGLView or plotly to visualize atomic structures. Here, we construct a string in the "protein database" @@ -128,6 +129,7 @@ def plot3d( view_plane=view_plane, distance_from_camera=distance_from_camera, opacity=opacity, + height=height, ) elif mode == "ase": return _plot3d_ase( @@ -162,6 +164,7 @@ def _plot3d_plotly( view_plane=np.array([1, 1, 1]), distance_from_camera=1, opacity=1, + height=600, ): """ Make a 3D plot of the atomic structure. @@ -224,6 +227,7 @@ def _plot3d_plotly( fig.update_layout(scene_camera=angle) fig.update_traces(marker=dict(line=dict(width=0.1, color="DarkSlateGrey"))) fig.update_scenes(aspectmode="data") + fig.update_layout(autosize=True, height=height) return fig From 3e785ed644db9659bdf43aff48cfdd3e233ecac8 Mon Sep 17 00:00:00 2001 From: samwaseda Date: Thu, 8 Feb 2024 13:23:28 +0000 Subject: [PATCH 2/6] add doc string --- structuretoolkit/visualize.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index a8c3899bb..3b9e54eaa 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -83,6 +83,7 @@ def plot3d( call. (Default is np.array([0, 0, 1]), which is view normal to the x-y plane.) distance_from_camera (float): Distance of the camera from the structure. Higher = farther away. (Default is 14, which also seems to be the NGLView default value.) + height (int/float): height of the plot area in pixel (only available in plotly) Possible NGLView color schemes: " ", "picking", "random", "uniform", "atomindex", "residueindex", @@ -183,6 +184,7 @@ def _plot3d_plotly( distance_from_camera (float): Distance of the camera from the structure. Higher = farther away. (Default is 14, which also seems to be the NGLView default value.) opacity (float): opacity + height (int/float): height of the plot area in pixel (only available in plotly) Returns: (plotly.express): The NGLView widget itself, which can be operated on further or viewed as-is. From 59ce25b4b9f2e389f7560410086243c305c08742 Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Fri, 9 Feb 2024 07:11:22 +0000 Subject: [PATCH 3/6] Format black --- structuretoolkit/visualize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index fb2afd3a8..95e329c47 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -41,7 +41,7 @@ def plot3d( view_plane=np.array([0, 0, 1]), distance_from_camera=1.0, opacity=1.0, - height=600 + height=600, ): """ Plot3d relies on NGLView or plotly to visualize atomic structures. Here, we construct a string in the "protein database" From 433a464764b8a4e552832892c9ea5da8f405d956 Mon Sep 17 00:00:00 2001 From: samwaseda Date: Fri, 9 Feb 2024 07:20:20 +0000 Subject: [PATCH 4/6] add warning for height --- structuretoolkit/visualize.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index 1590682a6..533f8cb11 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -41,7 +41,7 @@ def plot3d( view_plane=np.array([0, 0, 1]), distance_from_camera=1.0, opacity=1.0, - height=600 + height=None ): """ Plot3d relies on NGLView or plotly to visualize atomic structures. Here, we construct a string in the "protein database" @@ -98,6 +98,10 @@ def plot3d( * The colour interpretation of some hex codes is weird, e.g. 'green'. """ if mode == "NGLview": + if height is not None: + warnings.warn( + "`height` is not implemented in NGLview", SyntaxWarning + ) return _plot3d( structure=structure, show_cell=show_cell, @@ -133,6 +137,10 @@ def plot3d( height=height, ) elif mode == "ase": + if height is not None: + warnings.warn( + "`height` is not implemented in ase", SyntaxWarning + ) return _plot3d_ase( structure=structure, show_cell=show_cell, @@ -168,7 +176,7 @@ def _plot3d_plotly( view_plane=np.array([1, 1, 1]), distance_from_camera=1, opacity=1, - height=600, + height=None, ): """ Make a 3D plot of the atomic structure. @@ -232,7 +240,8 @@ def _plot3d_plotly( fig.update_layout(scene_camera=angle) fig.update_traces(marker=dict(line=dict(width=0.1, color="DarkSlateGrey"))) fig.update_scenes(aspectmode="data") - fig.update_layout(autosize=True, height=height) + if height is not None: + fig.update_layout(autosize=True, height=height) return fig From ec4dbbed2fdf7dd21cc89e83a216439aa08f6774 Mon Sep 17 00:00:00 2001 From: samwaseda Date: Fri, 9 Feb 2024 07:23:06 +0000 Subject: [PATCH 5/6] satisfy black --- structuretoolkit/visualize.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index 4a2033a9f..bc92376f3 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -41,7 +41,7 @@ def plot3d( view_plane=np.array([0, 0, 1]), distance_from_camera=1.0, opacity=1.0, - height=None + height=None, ): """ Plot3d relies on NGLView or plotly to visualize atomic structures. Here, we construct a string in the "protein database" @@ -99,9 +99,7 @@ def plot3d( """ if mode == "NGLview": if height is not None: - warnings.warn( - "`height` is not implemented in NGLview", SyntaxWarning - ) + warnings.warn("`height` is not implemented in NGLview", SyntaxWarning) return _plot3d( structure=structure, show_cell=show_cell, @@ -138,9 +136,7 @@ def plot3d( ) elif mode == "ase": if height is not None: - warnings.warn( - "`height` is not implemented in ase", SyntaxWarning - ) + warnings.warn("`height` is not implemented in ase", SyntaxWarning) return _plot3d_ase( structure=structure, show_cell=show_cell, From 0af1b42eb90bf00b17caebfb40c335987020e609 Mon Sep 17 00:00:00 2001 From: samwaseda Date: Fri, 9 Feb 2024 07:27:39 +0000 Subject: [PATCH 6/6] set default and correct doc string --- structuretoolkit/visualize.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index bc92376f3..053e1c43b 100644 --- a/structuretoolkit/visualize.py +++ b/structuretoolkit/visualize.py @@ -83,7 +83,8 @@ def plot3d( call. (Default is np.array([0, 0, 1]), which is view normal to the x-y plane.) distance_from_camera (float): Distance of the camera from the structure. Higher = farther away. (Default is 14, which also seems to be the NGLView default value.) - height (int/float): height of the plot area in pixel (only available in plotly) + height (int/float/None): height of the plot area in pixel (only + available in plotly) Default: 600 Possible NGLView color schemes: " ", "picking", "random", "uniform", "atomindex", "residueindex", @@ -191,7 +192,7 @@ def _plot3d_plotly( distance_from_camera (float): Distance of the camera from the structure. Higher = farther away. (Default is 14, which also seems to be the NGLView default value.) opacity (float): opacity - height (int/float): height of the plot area in pixel (only available in plotly) + height (int/float/None): height of the plot area in pixel. Default: 600 Returns: (plotly.express): The NGLView widget itself, which can be operated on further or viewed as-is. @@ -236,8 +237,9 @@ def _plot3d_plotly( fig.update_layout(scene_camera=angle) fig.update_traces(marker=dict(line=dict(width=0.1, color="DarkSlateGrey"))) fig.update_scenes(aspectmode="data") - if height is not None: - fig.update_layout(autosize=True, height=height) + if height is None: + height = 600 + fig.update_layout(autosize=True, height=height) fig.update_layout(legend={"itemsizing": "constant"}) return fig