Skip to content
Merged
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions structuretoolkit/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand Down