The visual module#

Biobuild can generate a variety of visualizations for molecules using multiple backends. The visual module is technically part of the biobuild.utils package but is documented separately here.

Visualizing from the Molecule class#

Each Molecule (and AtomGraph, and ResidueGraph) comes with a number of visualization methods that can be used to generate the below listed visualizations. So, there is no need to set them up manually, but if the user wishes to customize the visualizations, they can do so by using the visualization classes directly.

Visualizing with Plotly#

Plotly is a web-based visualization library that can be used to generate interactive plots of any kind. Biobuild uses Plotly’s 3D scatter plots to visualize molecules and their graph representations.

PlotlyViewer3D
class biobuild.utils.visual.PlotlyViewer3D[source]#

Bases: object

add(fig)[source]#

Add a plotly figure to the viewer.

draw_atom(atom, id=None, color=None, opacity=None)[source]#
draw_atoms(*atoms, names: list = None, colors: list = None, opacity: float = None, showlegend: bool = True, hoverinfo: str = 'name')[source]#
draw_bond(atom_a, atom_b, color='black', linewidth=1.5, showlegend=True, elongate: float = 1.0)[source]#
draw_edges(*edges, color='black', linewidth=1, opacity=1.0, elongate: float = 1.0, showlegend: bool = True, name: str = None)[source]#
draw_point(id: str, coord, color='black', opacity=1.0, showlegend=True)[source]#
draw_points(ids: list, coords: list, colors: list = None, opacities: list = None, showlegends: list = None)[source]#
draw_residues(*residues, bond_colors: list = None, opacity: float = None, linewidth: float = 2)[source]#
draw_vector(id, coord_a, coord_b, color='black', linewidth=1.5, opacity=1.0, showlegend=True, hoverinfo: str = 'skip', elongate: float = 1.0, legendgroup: str = None)[source]#
highlight_atoms(*atoms, names: list = None, colors: list = None, opacity: float = 1, showlegend: bool = True, hoverinfo: str = 'name')[source]#
highlight_residues(*residues, bond_colors: list = None, opacity: float = 0.6, linewidth: float = 2)[source]#
reset()[source]#
show()[source]#
write_html(path)[source]#
MoleculeViewer3D
class biobuild.utils.visual.MoleculeViewer3D[source]#

Bases: PlotlyViewer3D

make_df(mol) tuple[source]#
rainbow()[source]#

Colorize the residues in rainbow colors

reset()[source]#
AtomGraphViewer3D
class biobuild.utils.visual.AtomGraphViewer3D[source]#

Bases: PlotlyViewer3D

make_df(graph)[source]#
ResidueGraphViewer3D
class biobuild.utils.visual.ResidueGraphViewer3D[source]#

Bases: PlotlyViewer3D

make_df(graph)[source]#
rainbow()[source]#

Visualizing with NglView#

NglView is a Python package that can be used to visualize molecules in Jupyter notebooks. If it is installed, Biobuild can use it to visualize molecules (but not their graph representations).

NglViewer3D
class biobuild.utils.visual.NglViewer(molecule)[source]#

Bases: object

View a molecule in 3D using the NGLView library.

Parameters:

molecule – The molecule to view. This may be any object that holds a biopython structure e.g. a Molecule, AtomGraph, or ResidueGraph.

show()[source]#

Show the molecule in a Jupyter notebook

Visualizing with 3DMol.js#

3DMol.js is a JavaScript library that can be used to visualize molecules in Jupyter notebooks. It has a python wrapper py3Dmol that Biobuild can use (if installed) to visualize molecules (but not their graph representations).

Py3DmolViewer
class biobuild.utils.visual.Py3DmolViewer(molecule, width: int = 500, height: int = 500)[source]#

Bases: object

View a molecule in 3D using the py3Dmol library.

view#

The py3Dmol view object.

Type:

py3Dmol.view

Parameters:
  • molecule – The molecule to view. This may be any object that holds a biopython structure e.g. a Molecule, AtomGraph, or ResidueGraph.

  • width (int) – The width of the viewer in pixels.

  • height (int) – The height of the viewer in pixels.

show()[source]#

Show the molecule in a Jupyter notebook

Visualizing 2D molecules#

Biobuild can also visualize 2D molecules using the rdkit package (if installed). RDKit is a cheminformatics package that can be used to generate high quality 2D molecule schematics.

Chem2DViewer
class biobuild.utils.visual.Chem2DViewer(molecule, highlight_color: str = 'cyan')[source]#

Bases: object

View a molecule in 2D using the RDKit library.

Parameters:

molecule – The molecule to view. This may be any object that holds a biopython structure e.g. a Molecule, AtomGraph, or ResidueGraph.

draw(draw_hydrogens: bool = False, width: int = 1000, height: int = 500)[source]#

Generate the 2D image.

Parameters:
  • draw_hydrogens (bool) – Whether to draw hydrogens.

  • width (int) – The width of the image in pixels.

  • height (int) – The height of the image in pixels.

highlight_atoms(*atoms)[source]#

Highlight atoms in the molecule.

Parameters:

atoms (list) – The Biobuild Atoms to highlight.

highlight_bonds(*bonds)[source]#

Highlight bonds in the molecule.

Parameters:

bonds (list) – The bonds (tuples of Biobuild Atoms) to highlight.

show(draw_hydrogens: bool = False)[source]#

Show the molecule

Parameters:

draw_hydrogens (bool) – Whether to draw hydrogens.