moldesign.viewer package

class moldesign.viewer.ChemicalGraphViewer(mol, carbon_labels=True, names=None, display=False, _forcebig=False, **kwargs)[source]

Bases: nbmolviz.widget2d.MolViz2DBaseWidget, moldesign.viewer.common.ColorMixin

Create a JSON-format graph representing the chemical structure and draw it using the NBMolViz 2D widget.

Parameters:
  • mol (moldesign.molecules.AtomContainer) – A collection of atoms (eg a list of atoms, a residue, a molecule. etc)
  • carbon_labels (bool) – If True, draw atom names for carbons
  • names (List[str]) – (optional) a list of strings to label the atoms in the drawing (default: [atom.name for atom in mol.atoms])
  • display (bool) – immediately display this drawing
MAXATOMS = 200
get_atom_index(atom)[source]

Return the atom’s index in this object’s storage

handle_click(trait_name, old, new)[source]
handle_selection_event(selection)[source]

Highlight atoms in response to a selection event

Parameters:selection (dict) – Selection event from moldesign.uibase.selectors
to_graph(atoms)[source]
unset_color(atoms=None, render=None)[source]
class moldesign.viewer.DistanceGraphViewer(atoms, distance_sensitivity=(<Quantity(3.0, 'ang')>, <Quantity(7.0, 'ang')>), bond_edge_weight=1.0, minimum_edge_weight=0.2, nonbond_weight_factor=0.66, angstrom_to_px=22.0, charge=-300, **kwargs)[source]

Bases: moldesign.viewer.viewer2d.ChemicalGraphViewer

Create a 2D graph that includes edges with 3D information. This gives a 2D chemical that shows contacts from 3D space.

Parameters:
  • mol (moldesign.molecules.AtomContainer) – A collection of atoms (eg a list of atoms, a residue, a molecule. etc)
  • distance_sensitivity (Tuple[u.Scalar[length]]) – a tuple containing the minimum and maximum 3D distances to create edges for (default: (3.0*u.ang, 7.0*u.ang))
  • bond_edge_weight (float) – edge weight for covalent bonds
  • nonbond_weight_factor (float) – scale non-covalent edge weights by this factor
  • angstrom_to_px (int) – number of pixels per angstrom
  • charge (int) – the force-directed layout repulsive “charge”
draw_contacts(group1, group2, radius=<Quantity(2.25, 'ang')>, label=True)[source]
to_graph(atoms)[source]
class moldesign.viewer.GeometryViewer(mol=None, style=None, display=False, render=True, **kwargs)[source]

Bases: nbmolviz.drivers3d.MolViz_3DMol, moldesign.viewer.common.ColorMixin

Viewer for static and multiple-frame geometries

Variables:mol – Buckyball molecule
DEFAULT_COLOR_MAP(cats, mplmap='auto')
DEFAULT_HEIGHT = 400
DEFAULT_WIDTH = 625
DEF_PADDING = <Quantity(2.25, 'ang')>
DISTANCE_UNITS = <Unit('ang')>
HIGHLIGHT_COLOR = '#1FF3FE'
add_click_callback(fn)[source]
append_frame(positions=None, wfn=None, render=True)[source]
autostyle(render=True)[source]
calc_orb_grid(orbname, npts, framenum)[source]

Calculate orbitals on a grid

Parameters:
  • orbname – Either orbital index (for canonical orbitals) or a tuple ( [orbital type], [orbital index] ) where [orbital type] is a keyword (e.g., canonical, natural, nbo, ao, etc)
  • npts (int) – resolution in each dimension of the grid
  • framenum (int) – wavefunction for which frame number?
Returns:

orbital values on a grid

Return type:

moldesign.viewer.VolumetricGrid

draw_atom_vectors(vecs, rescale_to=1.75, scale_factor=None, opacity=0.85, radius=0.11, render=True, **kwargs)[source]

For displaying atom-centered vector data (e.g., momenta, forces) :param rescale_to: rescale to this length (in angstroms) (not used if scale_factor is passed) :param scale_factor: Scaling factor for arrows: dimensions of [vecs dimensions] / [length] :param render: render immediately :param kwargs: keyword arguments for self.draw_arrow

draw_axis(on=True, render=True)[source]
draw_forces(**kwargs)[source]
draw_momenta(**kwargs)[source]
get_input_file()[source]
get_orbnames()[source]
get_positions()[source]
handle_click(trait_name, old, new)[source]
handle_selection_event(selection)[source]

Deals with an external selection event :param selection:todo :return:

highlight_atoms(atoms=None, render=True)[source]
Parameters:
  • atoms (list[Atoms]) – list of atoms to highlight. If None, remove all highlights
  • render (bool) – render this change immediately
label_atoms(atoms=None, render=True, **kwargs)[source]
orbital_is_selected
redraw_orbs(render=True)[source]
remove_click_callback(fn)[source]
set_color(*args, **kwargs)[source]
set_colors(*args, **kwargs)[source]
Parameters:colormap (Mapping[str,List[Atoms]]) – mapping of colors to atoms
show_frame(*args, **kwargs)[source]
show_unbonded(radius=0.5)[source]
unset_color(*args, **kwargs)[source]
wfn

Submodules

moldesign.viewer.bondclicker module

class moldesign.viewer.bondclicker.BondClicker(mol, **kwargs)[source]

Bases: moldesign.viewer.viewer3d.GeometryViewer

Allow the user to highlight bonds - this is a hack around 3dmol.js to allow clickable bonds.

ATOMRADIUS = 0.35
BONDCOLOR = '#C8C8C8'
DOUBLEOFFSET = 0.16
DOUBLERADIUS = 0.13
SINGLERADIUS = 0.18
TRIPLEOFFSET = 0.14
TRIPLERADIUS = 0.12
draw_all_bonds(render=True, batch=True)[source]
draw_bond(bond, render=True, batch=False, **shape_args)[source]
handle_click(trait_name, old, new)[source]
set_bond_color(color, bond, render=True)[source]
set_positions(*args, **kwargs)[source]
unset_bond_color(bond, render=True)[source]

moldesign.viewer.common module

class moldesign.viewer.common.ColorMixin[source]

Bases: object

color_by(atom_callback, atoms=None, mplmap='auto', render=True, force_cmap=False)[source]
Color atoms according to either:
  • an atomic attribute (e.g., ‘chain’, ‘residue’, ‘mass’)
  • a callback function that accepts an atom and returns a color or a category
Parameters:
  • atom_callback (callable OR str) – callable f(atom) returns color OR category OR an atom attribute (e.g., atnum, mass, residue.type)
  • atoms (moldesign.molecules.AtomContainer) – atoms to color (default: self.atoms)
  • mplmap (str) – name of the matplotlib colormap to use if colors aren’t explicitly specified)
  • force_cmap (bool) – force the use of a colormap
  • render (bool) – draw these changes immediately

Notes

If you’d like to explicitly specify colors, the callback can return color specifications as an HTML string ('#1234AB'), a hexadecimal integer ( 0x12345AB), or a CSS3 color keyword ('green', 'purple', etc., see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value)

If the callback returns an integer, it may be interpreted as a color spec (since RGB colors are just hexadecimal integers). Use force_cmap=True to force the creation of a colormap.

Returns:mapping of categories to colors
Return type:dict

moldesign.viewer.viewer2d module

class moldesign.viewer.viewer2d.ChemicalGraphViewer(mol, carbon_labels=True, names=None, display=False, _forcebig=False, **kwargs)[source]

Bases: nbmolviz.widget2d.MolViz2DBaseWidget, moldesign.viewer.common.ColorMixin

Create a JSON-format graph representing the chemical structure and draw it using the NBMolViz 2D widget.

Parameters:
  • mol (moldesign.molecules.AtomContainer) – A collection of atoms (eg a list of atoms, a residue, a molecule. etc)
  • carbon_labels (bool) – If True, draw atom names for carbons
  • names (List[str]) – (optional) a list of strings to label the atoms in the drawing (default: [atom.name for atom in mol.atoms])
  • display (bool) – immediately display this drawing
MAXATOMS = 200
get_atom_index(atom)[source]

Return the atom’s index in this object’s storage

handle_click(trait_name, old, new)[source]
handle_selection_event(selection)[source]

Highlight atoms in response to a selection event

Parameters:selection (dict) – Selection event from moldesign.uibase.selectors
to_graph(atoms)[source]
unset_color(atoms=None, render=None)[source]
class moldesign.viewer.viewer2d.DistanceGraphViewer(atoms, distance_sensitivity=(<Quantity(3.0, 'ang')>, <Quantity(7.0, 'ang')>), bond_edge_weight=1.0, minimum_edge_weight=0.2, nonbond_weight_factor=0.66, angstrom_to_px=22.0, charge=-300, **kwargs)[source]

Bases: moldesign.viewer.viewer2d.ChemicalGraphViewer

Create a 2D graph that includes edges with 3D information. This gives a 2D chemical that shows contacts from 3D space.

Parameters:
  • mol (moldesign.molecules.AtomContainer) – A collection of atoms (eg a list of atoms, a residue, a molecule. etc)
  • distance_sensitivity (Tuple[u.Scalar[length]]) – a tuple containing the minimum and maximum 3D distances to create edges for (default: (3.0*u.ang, 7.0*u.ang))
  • bond_edge_weight (float) – edge weight for covalent bonds
  • nonbond_weight_factor (float) – scale non-covalent edge weights by this factor
  • angstrom_to_px (int) – number of pixels per angstrom
  • charge (int) – the force-directed layout repulsive “charge”
draw_contacts(group1, group2, radius=<Quantity(2.25, 'ang')>, label=True)[source]
to_graph(atoms)[source]
moldesign.viewer.viewer2d.make_contact_view(entity, view_radius=<Quantity(5.0, 'ang')>, contact_radius=<Quantity(2.25, 'ang')>, angstrom_to_px=44.0, **kwargs)[source]
Parameters:kwargs
Returns:

moldesign.viewer.viewer3d module

class moldesign.viewer.viewer3d.GeometryViewer(mol=None, style=None, display=False, render=True, **kwargs)[source]

Bases: nbmolviz.drivers3d.MolViz_3DMol, moldesign.viewer.common.ColorMixin

Viewer for static and multiple-frame geometries

Variables:mol – Buckyball molecule
DEFAULT_COLOR_MAP(cats, mplmap='auto')
DEFAULT_HEIGHT = 400
DEFAULT_WIDTH = 625
DEF_PADDING = <Quantity(2.25, 'ang')>
DISTANCE_UNITS = <Unit('ang')>
HIGHLIGHT_COLOR = '#1FF3FE'
add_click_callback(fn)[source]
append_frame(positions=None, wfn=None, render=True)[source]
autostyle(render=True)[source]
calc_orb_grid(orbname, npts, framenum)[source]

Calculate orbitals on a grid

Parameters:
  • orbname – Either orbital index (for canonical orbitals) or a tuple ( [orbital type], [orbital index] ) where [orbital type] is a keyword (e.g., canonical, natural, nbo, ao, etc)
  • npts (int) – resolution in each dimension of the grid
  • framenum (int) – wavefunction for which frame number?
Returns:

orbital values on a grid

Return type:

moldesign.viewer.VolumetricGrid

draw_atom_vectors(vecs, rescale_to=1.75, scale_factor=None, opacity=0.85, radius=0.11, render=True, **kwargs)[source]

For displaying atom-centered vector data (e.g., momenta, forces) :param rescale_to: rescale to this length (in angstroms) (not used if scale_factor is passed) :param scale_factor: Scaling factor for arrows: dimensions of [vecs dimensions] / [length] :param render: render immediately :param kwargs: keyword arguments for self.draw_arrow

draw_axis(on=True, render=True)[source]
draw_forces(**kwargs)[source]
draw_momenta(**kwargs)[source]
get_input_file()[source]
get_orbnames()[source]
get_positions()[source]
handle_click(trait_name, old, new)[source]
handle_selection_event(selection)[source]

Deals with an external selection event :param selection:todo :return:

highlight_atoms(atoms=None, render=True)[source]
Parameters:
  • atoms (list[Atoms]) – list of atoms to highlight. If None, remove all highlights
  • render (bool) – render this change immediately
label_atoms(atoms=None, render=True, **kwargs)[source]
orbital_is_selected
redraw_orbs(render=True)[source]
remove_click_callback(fn)[source]
set_color(*args, **kwargs)[source]
set_colors(*args, **kwargs)[source]
Parameters:colormap (Mapping[str,List[Atoms]]) – mapping of colors to atoms
show_frame(*args, **kwargs)[source]
show_unbonded(radius=0.5)[source]
unset_color(*args, **kwargs)[source]
wfn