diff --git a/structuretoolkit/visualize.py b/structuretoolkit/visualize.py index 4774c4f2b..053e1c43b 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=None, ): """ Plot3d relies on NGLView or plotly to visualize atomic structures. Here, we construct a string in the "protein database" @@ -82,6 +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/None): height of the plot area in pixel (only + available in plotly) Default: 600 Possible NGLView color schemes: " ", "picking", "random", "uniform", "atomindex", "residueindex", @@ -96,6 +99,8 @@ 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, @@ -128,8 +133,11 @@ def plot3d( view_plane=view_plane, distance_from_camera=distance_from_camera, opacity=opacity, + 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, @@ -165,6 +173,7 @@ def _plot3d_plotly( view_plane=np.array([1, 1, 1]), distance_from_camera=1, opacity=1, + height=None, ): """ Make a 3D plot of the atomic structure. @@ -183,6 +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/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. @@ -227,6 +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 None: + height = 600 + fig.update_layout(autosize=True, height=height) fig.update_layout(legend={"itemsizing": "constant"}) return fig