schrodinger.graphics3d.box module

OpenGL boxes.

NOTE: This module has been deprecated for graphics3d.polyhedron

The box module allows creation and drawing of boxes. Boxes do not have to be cubes. In fact, the only requirements are that each face contain exactly four vertices, and there be a total of exactly 6 total faces.

Drawing is done in whatever is the current GL rendering context and current GL window. So you must set those prior to drawing. If you are using this with Maestro’s drawing callback mechanism you need not worry about the above details. These are handled for you automatically.

Control over the vertices, color, and opacity of a box are provided. See the Box class for more info.

To draw any number of boxes, create the Box instances, add them to a Group instance then invoke the Group’s draw() method.

Note that transparent boxes may not render correctly. The final polygons would need to be sorted and drawn based on the z position. This is not done and even if it were the box class is not (and cannot) be aware of any 3D objects Maestro draws diretly itself. If your Workspace can have multiple transparent objects and you need transparent boxes that always render properly, try polyhedron.MaestroCube class.

Copyright Schrodinger, LLC. All rights reserved.

class schrodinger.graphics3d.box.Box(vertices=None, center=None, extents=None, color=None, opacity=1.0, style=1)

Bases: schrodinger.graphics3d.common.Primitive

Class to draw a 3D box in OpenGL. Will be drawn in the current OpenGL drawable. This includes the ability to draw into Maestro’s Workspace. It just needs to be the current drawable.

Boxes should be added to a graphics3d.common.Group, or BoxGroup, and drawing done via the Group. See the graphics3d.common.Group documentation.

See note on transparency in the module level docstring.

API Example:

import schrodinger.maestro.maestro as maestro
import schrodinger.graphics3d.common as common
import schrodinger.graphics3d.box as box

box_grp = common.Group()
st = maestro.workspace_get() # Here, st is methane.
methane_vertices = [
    # plane-1, defined in clockwise order.
    st.atom[1].x + 0,
    st.atom[1].y + 1,
    st.atom[1].z + 1,

    st.atom[1].x + 1,
    st.atom[1].y + 0,
    st.atom[1].z + 1,

    st.atom[1].x + 0,
    st.atom[1].y - 1,
    st.atom[1].z + 1,

    st.atom[1].x - 1,
    st.atom[1].y + 0,
    st.atom[1].z + 1,

    # plane-2, defined in clockwise order.
    st.atom[1].x + 0,
    st.atom[1].y + 1,
    st.atom[1].z - 1,

    st.atom[1].x + 1,
    st.atom[1].y + 0,
    st.atom[1].z - 1,

    st.atom[1].x + 0,
    st.atom[1].y - 1,
    st.atom[1].z - 1,

    st.atom[1].x - 1,
    st.atom[1].y + 0,
    st.atom[1].z - 1,

]
bx = box.Box(
    vertices=methane_vertices,
    color='red',
    opacity=1.0,
    style=box.LINE
)
# Add the primitive to the container.
box_grp.add(bx)

# Add the draw callback.
maestro.workspace_draw_function_add(box_grp.draw)

# Hide the markers.
box_grp.hide()

# Remove the markers and the callback.
box_grp.clear()
maestro.workspace_draw_function_remove(box_grp.draw)
__init__(vertices=None, center=None, extents=None, color=None, opacity=1.0, style=1)

Constructor requires:

You may specify vertices OR extents and a center. These are in Angstroms

vertices: List of 24 values: x1, y1, z1 … x8, y8, z8 OR

list of 8 vertex lists [x, y, z], …, [x, y, z]

Specify 4 vertices from one face first, then the corresponding 4 vertices from the parallel opposite side. Do these in the same clockwise ordering as viewed from the same location. For example, if the first vertex in the front face is top-left, then start 2nd rear face with top-left vertex as viewed from the same direction/location.

center: List of 3 Angstrom values indicating the center coordinate
of the box. If specified, extents must also be specified and vertices will be ignored.
extents: List of 3 float values in Angstroms -
x length, y length, z length. If this is specifiied, center must also be specified
color: One of:
Color object Color name (string) Tuble of (R, G, B) (each 0.0-1.0)

Optional arguments:

opacity: 0.0 (invisible) through 1.0 (opaque)
Defaults to 1.0

style: LINE or FILL. Default is FILL.

__class__

alias of builtins.type

__del__(_hasattr=<built-in function hasattr>, _maestro=<module 'schrodinger.maestro.maestro' from '/scr/buildbot/savedbuilds/2018-4/NB/build-145/internal/lib/python3.6/site-packages/schrodinger/maestro/maestro.py'>)
__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.graphics3d.box', '__doc__': "\n Class to draw a 3D box in OpenGL. Will be drawn in the current OpenGL\n drawable. This includes the ability to draw into Maestro's Workspace. It\n just needs to be the current drawable.\n\n Boxes should be added to a graphics3d.common.Group, or BoxGroup, and\n drawing done via the Group. See the graphics3d.common.Group documentation.\n\n See note on transparency in the module level docstring.\n\n API Example::\n\n import schrodinger.maestro.maestro as maestro\n import schrodinger.graphics3d.common as common\n import schrodinger.graphics3d.box as box\n\n box_grp = common.Group()\n st = maestro.workspace_get() # Here, st is methane.\n methane_vertices = [\n # plane-1, defined in clockwise order.\n st.atom[1].x + 0,\n st.atom[1].y + 1,\n st.atom[1].z + 1,\n\n st.atom[1].x + 1,\n st.atom[1].y + 0,\n st.atom[1].z + 1,\n\n st.atom[1].x + 0,\n st.atom[1].y - 1,\n st.atom[1].z + 1,\n\n st.atom[1].x - 1,\n st.atom[1].y + 0,\n st.atom[1].z + 1,\n\n # plane-2, defined in clockwise order.\n st.atom[1].x + 0,\n st.atom[1].y + 1,\n st.atom[1].z - 1,\n\n st.atom[1].x + 1,\n st.atom[1].y + 0,\n st.atom[1].z - 1,\n\n st.atom[1].x + 0,\n st.atom[1].y - 1,\n st.atom[1].z - 1,\n\n st.atom[1].x - 1,\n st.atom[1].y + 0,\n st.atom[1].z - 1,\n\n ]\n bx = box.Box(\n vertices=methane_vertices,\n color='red',\n opacity=1.0,\n style=box.LINE\n )\n # Add the primitive to the container.\n box_grp.add(bx)\n\n # Add the draw callback.\n maestro.workspace_draw_function_add(box_grp.draw)\n\n # Hide the markers.\n box_grp.hide()\n\n # Remove the markers and the callback.\n box_grp.clear()\n maestro.workspace_draw_function_remove(box_grp.draw)\n\n ", '_blend': None, '_smooth_point': None, '_cull': None, '_lighting': None, '_lighting_model': None, '_shading_model': None, '_polygon_mode': None, '_line_width': 1.0, '__init__': <function Box.__init__>, '_checkVertexArgument': <function Box._checkVertexArgument>, '_glSetup': <staticmethod object>, '_glReset': <staticmethod object>, '_draw': <function Box._draw>, '_calculateBoundingBox': <function Box._calculateBoundingBox>, '_getLineWidth': <function Box._getLineWidth>, '_setLineWidth': <function Box._setLineWidth>, 'line_width': <property object>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.graphics3d.box'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

groupHidden()

Called when the group of this object is hidden. Hide the Maestro object(s).

groupShown()

Called when the group of this object is shown. Show the Maestro object, if we are being shown.

hide()

Hide the object. It will not be drawn when the group is drawn.

isGroupShown()

Returns True if this object’s group is shown. False otherwise.

isShown()

Returns True if this object shown. False otherwise.

setEntryID(entry_id)

Sets entry ID for Maestro object (necessary to render in tile-by-entry mode.

Parameters:entry_id (str) – Object’s entry ID.
setGlowColor(r, g, b)

Sets glow color for the object.

Parameters:
  • r (float) – Red component of glow color [0.0 .. 1.0]
  • g (float) – Green component of glow color [0.0 .. 1.0]
  • b (float) – Blue component of glow color [0.0 .. 1.0]
setIsGlowing(is_glowing)

Enables or disables glow effect for the object.

Parameters:is_glowing (bool) – Whether the object is glowing.
setRightClickOnGObject(pymodule, pyfunc)

Sets the python callback which should be called whenever given graphics object is right clicked.

Parameters:
  • pymodule (str) – Python module
  • pyfunc (str) – Python function
show()

Display this object, if it was hidden

line_width

This attribute controls the width of the lines used to draw the box. Width is a float and subject to the limitations of glLineWidth, meaning that (among other things) not all widths are supported. If an unsupported width is chosen, the nearest supported width is used. See the glLineWidth documentation for details on this and other behaviors.