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)
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.