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

Added ability to adjust bead_size #1158

Merged
merged 1 commit into from
Feb 1, 2024
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
29 changes: 23 additions & 6 deletions mbuild/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,11 @@ def particles_in_range(
return particle_array[idxs]

def visualize(
self, show_ports=False, backend="py3dmol", color_scheme={}
self,
show_ports=False,
backend="py3dmol",
color_scheme={},
bead_size=0.3,
): # pragma: no cover
"""Visualize the Compound using py3dmol (default) or nglview.

Expand All @@ -1882,6 +1886,8 @@ def visualize(
keys are strings of the particle names
values are strings of the colors
i.e. {'_CGBEAD': 'blue'}
bead_size : float, Optional, default=0.3
Size of beads in visualization
"""
viz_pkg = {
"nglview": self._visualize_nglview,
Expand All @@ -1890,7 +1896,9 @@ def visualize(
if run_from_ipython():
if backend.lower() in viz_pkg:
return viz_pkg[backend.lower()](
show_ports=show_ports, color_scheme=color_scheme
show_ports=show_ports,
color_scheme=color_scheme,
bead_size=bead_size,
)
else:
raise RuntimeError(
Expand All @@ -1903,7 +1911,9 @@ def visualize(
"Visualization is only supported in Jupyter Notebooks."
)

def _visualize_py3dmol(self, show_ports=False, color_scheme={}):
def _visualize_py3dmol(
self, show_ports=False, color_scheme={}, bead_size=0.3
):
"""Visualize the Compound using py3Dmol.

Allows for visualization of a Compound within a Jupyter Notebook.
Expand All @@ -1917,6 +1927,8 @@ def _visualize_py3dmol(self, show_ports=False, color_scheme={}):
keys are strings of the particle names
values are strings of the colors
i.e. {'_CGBEAD': 'blue'}
bead_size : float, Optional, default=0.3
Size of beads in visualization

Returns
-------
Expand Down Expand Up @@ -1951,15 +1963,20 @@ def _visualize_py3dmol(self, show_ports=False, color_scheme={}):

view.setStyle(
{
"stick": {"radius": 0.2, "color": "grey"},
"sphere": {"scale": 0.3, "colorscheme": modified_color_scheme},
"stick": {"radius": bead_size * 0.6, "color": "grey"},
"sphere": {
"scale": bead_size,
"colorscheme": modified_color_scheme,
},
}
)
view.zoomTo()

return view

def _visualize_nglview(self, show_ports=False, color_scheme={}):
def _visualize_nglview(
self, show_ports=False, color_scheme={}, bead_size=0.3
):
"""Visualize the Compound using nglview.

Allows for visualization of a Compound within a Jupyter Notebook.
Expand Down
Loading