schrodinger.graphics3d.common module

Utility functions for the graphics3d package.

The common module contains functions commonly used by the graphics3d modules. This includes the Group class, which is one clients use as a container for actual drawing primitive instances (like Arrow, etc.). See the Group class’ docstring for more details.

This code will automatically keep track of and handle each instance that is added to a Group instance. For information on how to create a Group and add intances to the Group, see the class docstring for Group and the method docstring for Group’s add() method, respectively.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.graphics3d.common.get_normalized(v)

Calculate and return normalized vector.

Arguments:

v: List containing 3 floating values of x, y, z

Returns:

List of 3 floating values reprsenting the normalized vector.

schrodinger.graphics3d.common.get_cross(v, w)

Get the cross product of v and w

Return type

[float, floatg, float]

schrodinger.graphics3d.common.create_normal(vertices)

Method to create a normal for the polygon defined by specified vertices.

Arguments:
vertices: List of floating value lists of [x, y, z] representing

a vertex.

Returns:

List of 3 floating values representing the normal

FIXME: We use only the first three vertices to calculate the normal

and currently ignore the rest. Other vertices won’t matter if all the vectors are in a plane, which is going to the be case most of the time.

schrodinger.graphics3d.common.color_arg_to_rgb(colorarg)

Returns a tuple of (r, g, b) [range 0.0-1.0 inclusive for each].

Arguments:

colorarg: Can be one of the following types -

Color: Color object instance string: Color name integer: Color index

class schrodinger.graphics3d.common.Primitive(maestro_objects=[])

Bases: object

All 3D objects derive from this class.

__init__(maestro_objects=[])
hide()

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

show()

Display this object, if it was hidden

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.

isShown()

Returns True if this object shown. False otherwise.

isGroupShown()

Returns True if this object’s group is 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.

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

setIsGlowing(is_glowing)

Enables or disables glow effect for the object.

Parameters

is_glowing (bool) – Whether the object is glowing.

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]

class schrodinger.graphics3d.common.Group

Bases: object

Class to group a bunch of primitives and draw them out.

Example for non-Maestro objects:

my_box1 = box.Box(…) my_box2 = box.Box(…) my_sphere = sphere.Sphere(…)

my_group = box.Group() (or sphere.Group(), etc) my_group.add(my_box1) my_group.add(my_box2) my_group.add(my_sphere)

__init__()

Constructor takes no arguments.

__len__()

Return the number of primitives in this group. Note that each primitive type can have multiple instances registered and each of these is counted towards the total.

getTotalTypes()

Return the number of unique primitive types in this group. This differs from the standard length operation. That returns a count of all primitive instances.

hide()

Do not draw objects belonging to this group. Will also modify Maestro’s bounding rect to exclude these objects.

show()

Cancel effect of hide() method, and draw the objects belonging to this group. Will modify Maestro’s bounding rect to exclude these objects.

isShown()

Returns True if this group is shown; False otherwise.

add(item)

Add a drawing primitive instance (Box, etc.) to this group.

remove(item)

Remove a drawing primitive instance (Box, etc.) from this group.

clear(item_type=None)

Clear up drawing instances.

Parameters

item_type – Can be one of the following: None, Arrow, Box, etc.

Note:

  • If item_type is None, all drawing instances will be removed; if item_type is not None, all drawing instances of the item_type class will be removed.

  • No effects if there is no drawing instances of the item_type class.

boundingBoxCallback(r00, r01, r02, r03, r10, r11, r12, r13, r20, r21, r22, r23, r30, r31, r32, r33)

Called when the workspace is fit to screen

allPrimitives()

Iterate through all the objects in this group and yield primitives.