Source code for schrodinger.graphics3d.gridbox

"""
Module for drawing a grid box to the Workspace.
"""

import types

import schrodinger
from schrodinger.graphics3d import box

maestro = schrodinger.get_maestro()

DARK_GREEN = (0.0, 0.6, 0.0)


[docs]class GridBox(object): """ Class for drawing a grid box to the Workspace. """
[docs] def __init__(self, center=(0.0, 0.0, 0.0), inner_box_size=(10.0, 10.0, 10.0), outer_box_size=(30.0, 30.0, 30.0), display_center_box=True, display_enclosing_box=True): """ Create an instance of the grid box, hidden initially. Call the show() method to display the box. The box parameters can be modified by setting the object's attributes with same names as the arguments to this init method - the box will be automatically re-drawn. :type center: (float, float, float) :param center: Center coordinates of the box. :type inner_box_size: (float, float, float) :param inner_box_size: Inner box size. Defaults to 10 in all dimensions. Typical range is 6-40A. :type outer_box_size: (float, float, float) :param outer_box_size: Outer box size. Defaults to 30 in all dimensions. Usually set to inner_box_size + maximum ligand length. :type display_center_box: bool :param display_center_box: Whether to show the center (inner) box. :type display_enclosing_box: bool :param display_enclosing_box: Whether to show the outer grid box. """ self._shown = False self._axes = None self._grid_box_group = box.Group() self.center = center self.inner_box_size = inner_box_size self.outer_box_size = outer_box_size self.display_center_box = True self.display_enclosing_box = True
def __del__(self, _isinstance=isinstance, _module=types.ModuleType, _hasattr=hasattr, _maestro=maestro): if _isinstance(_maestro, _module) or _maestro.__bool__(): if _hasattr(self, "_axes"): maestro.remove_object(self._axes) def __setattr__(self, name, value): """ Custom setter for the attributes that affect the drawing of the box. """ object.__setattr__(self, name, value) if name in ("center", "inner_box_size", "outer_box_size", "display_center_box", "display_enclosing_box"): self._updateObjects()
[docs] def isShown(self): """ :rtype: bool :return: Whether the grid box is currently shown. """ return self._shown
[docs] def hide(self): """ Hide the grid box (don't draw to the Workspace). """ self._shown = False self._grid_box_group.hide() if maestro and self._axes: maestro.hide_object(self._axes)
# Hiding the axes will redraw the Workspace.
[docs] def show(self): """ Show the grid box. """ self._shown = True self._updateObjects() self._grid_box_group.show() if maestro: maestro.show_object(self._axes)
# Showing the axes will redraw the Workspace. def _updateObjects(self): """ Will re-create the boxes and axes objects, and draw them if the grid box is currently shown. """ if not maestro or not self._shown: return self._grid_box_group.clear() if self.display_center_box: inner_box = box.MaestroBox(center=self.center, extents=self.inner_box_size, color=DARK_GREEN, opacity=1.0, line_width=2.0, style=box.LINE) self._grid_box_group.add(inner_box) if self.display_enclosing_box: outer_box = box.MaestroBox(center=self.center, extents=self.outer_box_size, color="purple", opacity=1.0, line_width=2.0, style=box.LINE) self._grid_box_group.add(outer_box) lengths = (4, 4, 4) # Lengths of the axes lines. if self._axes: # If not initializing maestro.remove_object(self._axes) args = tuple(self.center) + lengths + DARK_GREEN # Will trigger Maestro re-draw event: self._axes = maestro.create_model_xyz_axes(*args)