List of available renderers¶
Interfaces¶
-
class
chemlab.graphics.renderers.
AbstractRenderer
(widget, *args, **kwargs)¶ AbstractRenderer is the standard interface for renderers. Each renderer have to implement an initialization function __init__ and a draw method to do the actual drawing using OpenGL or by using other, more basic, renderers.
Usually the renderers have also some custom functions that they use to update themselves. For example a SphereRenderer implements the function update_positions to move the spheres around without having to regenerate all of the other properties.
See also
Graphics and Visualization for a tutorial on how to develop a simple renderer.
Parameters
- widget:
chemlab.graphics.QChemlabWidget
- The parent QChemlabWidget. Renderers can use the widget to access the camera, lights, and other informations.
args, kwargs: Any other argument that they may use.
-
draw
()¶ Generic drawing function to be implemented by the subclasses.
- widget:
-
class
chemlab.graphics.renderers.
ShaderBaseRenderer
(widget, vertex, fragment)¶ Bases:
chemlab.graphics.renderers.base.AbstractRenderer
Instruments OpenGL with a vertex and a fragment shader.
This renderer automatically binds light and camera information. Subclasses should not reimplement the
draw
method but thedraw_vertices
method where you can bind and draw the objects.Parameters
- widget:
- The parent
QChemlabWidget
- vertex: str
- Vertex program as a string
- fragment: str
- Fragment program as a string
-
draw_vertices
()¶ Method to be reimplemented by the subclasses.
-
class
chemlab.graphics.renderers.
DefaultRenderer
(widget)¶ Bases:
chemlab.graphics.renderers.base.ShaderBaseRenderer
Same as
ShaderBaseRenderer
with the default shaders.You can find the shaders in
chemlab/graphics/renderers/shaders/
under the names ofdefault_persp.vert
anddefault_persp.frag
.-
draw_vertices
()¶ Subclasses should reimplement this method.
-
SphereRenderer¶
-
class
chemlab.graphics.renderers.
SphereRenderer
(widget, poslist, radiuslist, colorlist, shading='phong')¶ Renders a set of spheres.
The method used by this renderer is approximating a sphere by using triangles. While this is reasonably fast, for best performance and animation you should use
SphereImpostorRenderer
Parameters
- widget:
- The parent
QChemlabWidget
- poslist: np.ndarray((NSPHERES, 3), dytpe=float)
- A position array. While there aren’t dimensions, in the context of chemlab 1 unit of space equals 1 nm.
- radiuslist: np.ndarray(NSPHERES, dtype=float)
- An array with the radius of each sphere.
- colorlist: np.ndarray(NSPHERES, 4) or list of tuples
- An array with the color of each sphere. Suitable colors are
those found in
chemlab.graphics.colors
or any tuple with values (r, g, b, a) in the range [0, 255]
-
update_positions
(positions)¶ Update the sphere positions.
SphereImpostorRenderer¶
-
class
chemlab.graphics.renderers.
SphereImpostorRenderer
(viewer, poslist, radiuslist, colorlist, transparent=False, shading='phong')¶ The interface is identical to
SphereRenderer
but uses a different drawing method.The spheres are squares that always face the user. Each point of the sphere, along with the lighting, is calculated in the fragment shader, resulting in a perfect sphere.
SphereImpostorRenderer is an extremely fast rendering method, it is perfect for rendering a lot of spheres ( > 50000) and for animations.
AtomRenderer¶
-
class
chemlab.graphics.renderers.
AtomRenderer
(widget, r_array, type_array, backend="impostors", color_scheme=colors.default_atom_map, radii_map=vdw_dict)¶ Render atoms by using different rendering methods.
Parameters
- widget:
- The parent QChemlabWidget
- r_array: np.ndarray((NATOMS, 3), dtype=float)
- The atomic coordinate array
- type_array: np.ndarray((NATOMS, 3), dtype=object)
- An array containing all the atomic symbols like Ar, H, O. If the atomic type is unknown, use the Xx symbol.
- backend: “impostors” | “polygons” | “points”
- You can choose the rendering method between the sphere impostors, polygonal sphere and points.
- color_scheme: dict, should contain the ‘Xx’ key,value pair
- A dictionary mapping atom types to colors. By default it is the color scheme provided by chemlab.graphics.colors.default_atom_map. The ‘Xx’ symbol value is taken as the default color.
- radii_map: dict, should contain the ‘Xx’ key,value pair.
- A dictionary mapping atom types to radii. The default is the mapping contained in chemlab.db.vdw.vdw_dict
-
update_positions
(r_array)¶ Update the atomic positions
BondRenderer¶
-
class
chemlab.graphics.renderers.
BondRenderer
(widget, bonds, r_array, type_array, radius=0.02, style='cylinders', shading='phong')¶ Render chemical bonds as cylinders or lines.
Parameters
- widget:
- The parent QChemlabWidget
- bonds: np.ndarray((NBONDS, 2), dtype=int)
- An array of integer pairs that represent the bonds.
- r_array: np.ndarray((NATOMS, 3), dtype=float)
- The coordinate array
- type_array: np.ndarray((NATOMS, 3), dtype=object)
- An array containing all the atomic symbols like Ar, H, O. If the atomic type is unknown, use the Xx symbol.
- radius: float, default=0.02
- The radius of the bonds
- style: “cylinders” | “lines”
- Whether to render the bonds as cylinders or lines.
BallAndStickRenderer¶
-
class
chemlab.graphics.renderers.
BallAndStickRenderer
(widget, r_array, type_array, bonds, shading='phong')¶ Render a ball and stick representation of a series of coordinates and bonds.
Parameters
- widget:
- The parent QChemlabWidget
- r_array: np.ndarray((NATOMS, 3), dtype=float)
- The coordinate array
- type_array: np.ndarray((NATOMS, 3), dtype=object)
- An array containing all the atomic symbols like Ar, H, O. If the atomic type is unknown, use the Xx symbol.
- bonds: np.ndarray((NBONDS, 2), dtype=int)
- An array of integer pairs that represent the bonds.
-
update_positions
(r_array)¶ Update the coordinate array r_array
WireframeRenderer¶
-
class
chemlab.graphics.renderers.
WireframeRenderer
(widget, r_array, type_array, bonds)¶ Render a wireframe representation of a series of coordinates and bonds.
Parameters
- widget:
- The parent QChemlabWidget
- r_array: np.ndarray((NATOMS, 3), dtype=float)
- The coordinate array
- type_array: np.ndarray((NATOMS, 3), dtype=object)
- An array containing all the atomic symbols like Ar, H, O. If the atomic type is unknown, use the Xx symbol.
- bonds: np.ndarray((NBONDS, 2), dtype=int)
- An array of integer pairs that represent the bonds.
PointRenderer¶
-
class
chemlab.graphics.renderers.
PointRenderer
(widget, positions, colors)¶ Render colored points.
Parameters
- widget:
- The parent QChemlabWidget
- positons: np.ndarray((NPOINTS, 3), dtype=np.float32)
- Positions of the points to draw.
- colors: np.ndarray((NPOINTS, 4), dtype=np.uint8) or list of tuples
- Color of each point in the (r,g,b,a) format in the interval [0, 255]
-
update_colors
(colors)¶ Update the colors
-
update_positions
(vertices)¶ Update the point positions
TriangleRenderer¶
-
class
chemlab.graphics.renderers.
TriangleRenderer
(widget, vertices, normals, colors, shading='phong')¶ Renders an array of triangles.
A lot of renderers are built on this, for example
SphereRenderer
. The implementation is relatively fast since it’s based on VertexBuffers.Parameters
- widget:
- The parent QChemlabWidget
- vertices: np.ndarray((NTRIANGLES*3, 3), dtype=float)
- The triangle vertices, keeping in mind the unwinding order. If the face of the triangle is pointing outwards, the vertices should be provided in clokckwise order.
- normals: np.ndarray((NTRIANGLES*3, 3), dtype=float)
- The normals to each of the triangle vertices, used for lighting calculations.
- colors: np.ndarray((NTRIANGLES*3, 4), dtype=np.uint8)
- Color for each of the vertices in (r,g,b,a) values in the interval [0, 255]
-
update_colors
(colors)¶ Update the triangle colors.
-
update_normals
(normals)¶ Update the triangle normals.
-
update_vertices
(vertices)¶ Update the triangle vertices.
BoxRenderer¶
-
class
chemlab.graphics.renderers.
BoxRenderer
(widget, vectors, origin=<Mock object>, color=(0, 0, 0, 255))¶ Used to render one wireframed box.
Parameters
- widget:
- The parent QChemlabWidget
- vectors: np.ndarray((3,3), dtype=float)
- The three vectors representing the sides of the box.
- origin: np.ndarray((3,3), dtype=float), default to zero
- The origin of the box.
- color: 4 int tuple
- r,g,b,a color in the range [0,255]
-
update
(vectors)¶ Update the box vectors.
LineRenderer¶
-
class
chemlab.graphics.renderers.
LineRenderer
(widget, startends, colors, width=1.5)¶ Render a set of lines.
Parameters
- widget:
- The parent QChemlabWidget
- startends: np.ndarray((NLINES, 2, 3), dtype=float)
Start and end position of each line in the form of an array:
s1 = [0.0, 0.0, 0.0] startends = [[s1, e1], [s2, e2], ..]
- colors: np.ndarray((NLINES, 2, 4), dtype=np.uint8)
- The corresponding color of each extrema of each line.
-
update_colors
(colors)¶ Update the colors
-
update_positions
(vertices)¶ Update the line positions
CylinderRenderer¶
-
class
chemlab.graphics.renderers.
CylinderRenderer
(widget, bounds, radii, colors)¶ Renders a set of cylinders.
The API is quite similar to
LineRenderer
Parameters
- widget:
- The parent QChemlabWidget
- bounds: np.ndarray((NCYL, 2, 3), dtype=float)
- Start and end points of the cylinder.
- colors: np.ndarray((NYCL, 4), dtype=np.uint8)
- The color for each cylinder.
-
update_bounds
(bounds)¶ Update cylinders start and end positions