ovito.vis

This module contains classes related to data visualization and image rendering.

Rendering:

Render engines:

Data visualization:

Viewport overlays:

class ovito.vis.RenderSettings

A data structure with parameters that control image and movie generation.

You typically pass an instance of this class to the Viewport.render() method to specify various render settings such as the resolution of the output image and the rendering engine to use:

from ovito.vis import RenderSettings, Viewport, TachyonRenderer

settings = RenderSettings(
    size = (320,240),
    filename = "output/myfigure.png",
    background_color = (0,0,0),
    renderer = TachyonRenderer(shadows=False, direct_light=False)
)

The rendering engine, which produces the two-dimensional rendering of the three-dimensional scene, is part of the RenderSettings structure. You can choose from three different rendering backends:

  • OpenGLRenderer – The quick renderer which is also used by the interactive viewports of OVITO.
  • TachyonRenderer – A software-based, high-quality raytracing renderer.
  • OSPRayRenderer – Another software-based, high-quality raytracing renderer.
  • POVRayRenderer – A rendering backend that calls the external POV-Ray raytracing program.

To render an image, one must create a Viewport, set up its virtual camera, and finally invoke its render() method with the RenderSettings structure:

vp = Viewport(type=Viewport.Type.PERSPECTIVE, camera_dir=(-100, -50, -50))
vp.zoom_all()
vp.render(settings)

This will render a single frame at the current animation time position, which is given by the global AnimationSettings.current_frame setting (frame 0 by default).

Rendering animations

To render an animation, the rendering range must be set to RenderSettings.Range.ANIMATION. The chosen output filename determines the kind of file(s) that will be produced: If the name suffix is .mp4, .avi or .mov, a single encoded movie file will be produced from all rendered frames. The playback speed of the final movie is determined by the global AnimationSettings.frames_per_second setting in this case:

import ovito

settings = RenderSettings(
    size = (1280,720), 
    filename = 'output/movie.mp4', 
    range = RenderSettings.Range.ANIMATION)

ovito.dataset.anim.frames_per_second = 30

Alternatively, a series of images can be rendered, which may subsequently be combined into a movie with an external video encoding tool:

settings = RenderSettings(
    size = (1280,720), 
    filename = 'output/frame.png', 
    range = RenderSettings.Range.ANIMATION)

This produces image files named frame0000.png, frame0001.png, etc.

background_color

Controls the background color of the rendered image.

Default:(1,1,1) – white
custom_range

Specifies the range of animation frames to render if range is set to CUSTOM_INTERVAL.

Default:(0,100)
filename

A string specifying the file path under which the rendered image or movie should be saved.

Default:None
generate_alpha

When saving the image to a file format that supports transparency information (e.g. PNG), this option will make those parts of the output image transparent which are not covered by an object.

Default:False
range

Selects the animation frames to be rendered.

Possible values:
  • RenderSettings.Range.CURRENT_FRAME (default): Renders a single image at the current animation time.
  • RenderSettings.Range.ANIMATION: Renders a movie of the entire animation sequence.
  • RenderSettings.Range.CUSTOM_INTERVAL: Renders a movie of the animation interval given by the custom_range attribute.
renderer

The renderer that is used to generate the image or movie. Depending on the selected renderer you can use this to set additional parameters such as the anti-aliasing level.

See the OpenGLRenderer, TachyonRenderer and POVRayRenderer classes for the list of parameters specific to each rendering backend.

size

The size of the image or movie to be generated in pixels.

Default:(640,480)
skip_existing_images

Controls whether animation frames for which the output image file already exists will be skipped when rendering an animation sequence. This flag is ignored when directly rendering to a movie file and not an image file sequence. Use this flag when the image sequence has already been partially rendered and you want to render just the missing frames.

Default:False
class ovito.vis.Viewport

A viewport defines the view on the three-dimensional scene.

You can create an instance of this class to define a camera position from which a picture of the three-dimensional scene should be generated. After the camera has been set up, you can render an image or movie using the viewport’s render() method:

vp = Viewport()
vp.type = Viewport.Type.PERSPECTIVE
vp.camera_pos = (100, 50, 50)
vp.camera_dir = (-100, -50, -50)

rs = RenderSettings(size=(800,600), filename="image.png")
vp.render(rs)

Note that the four interactive viewports in OVITO’s main window are instances of this class. If you want to manipulate these existing viewports, you can access them through the DataSet.viewports attribute.

camera_dir

The viewing direction vector of the viewport’s camera. This can be an arbitrary vector with non-zero length.

camera_pos

The position of the viewport’s camera. For example, to move the camera of the active viewport in OVITO’s main window to a new location in space:

dataset.viewports.active_vp.camera_pos = (100, 80, -30)
fov

The field of view of the viewport’s camera. For perspective projections this is the camera’s angle in the vertical direction (in radians). For orthogonal projections this is the visible range in the vertical direction (in world units).

overlays

A list-like sequence of viewport overlay objects that are attached to this viewport. They render graphical content on top of the three-dimensional scene. See the following classes for more information:

render(settings=None)

Renders an image or movie of the viewport’s view.

Parameters:settings (RenderSettings) – A settings object, which specifies the resolution, background color, output filename etc. of the image to be rendered. If None, the global settings are used (given by DataSet.render_settings).
Returns:A QImage object on success, which contains the rendered picture; None if the rendering operation has been canceled by the user.

The rendered image of movie will automatically be saved to disk when the RenderSettings.filename attribute contains a non-empty string. Alternatively, you can save the returned QImage explicitly using its save() method. This gives you the opportunity to paint additional graphics on top of the image before saving it. For example:

import ovito
from ovito.vis import *
from PyQt5.QtGui import QPainter

# Let OVITO render an image of the active viewport.
vp = ovito.dataset.viewports.active_vp
rs = RenderSettings(size = (320,240), renderer = TachyonRenderer())
image = vp.render(rs)

# Paint something on top of the rendered image.
painter = QPainter(image)
painter.drawText(10, 20, "Hello world!")
del painter

# Save image to disk.
image.save("output/image.png")
type

The type of projection:

  • Viewport.Type.PERSPECTIVE
  • Viewport.Type.ORTHO
  • Viewport.Type.TOP
  • Viewport.Type.BOTTOM
  • Viewport.Type.FRONT
  • Viewport.Type.BACK
  • Viewport.Type.LEFT
  • Viewport.Type.RIGHT
  • Viewport.Type.NONE

The first two types (PERSPECTIVE and ORTHO) allow you to set up custom views with arbitrary camera orientation.

zoom_all()

Repositions the viewport camera such that all objects in the scene become completely visible. The camera direction is not changed.

class ovito.vis.OpenGLRenderer

The standard OpenGL-based renderer.

This is the default built-in rendering engine that is also used by OVITO to render the contents of the interactive viewports. Since it accelerates the generation of images by using the computer’s graphics hardware, it is very fast.

antialiasing_level

A positive integer controlling the level of supersampling. If 1, no supersampling is performed. For larger values, the image in rendered at a higher resolution and then scaled back to the output size to reduce aliasing artifacts.

Default:3
class ovito.vis.DataVis

Abstract base class for visualization elemnts that are reponsible for the visual appearance of data objects in the visualization. Some DataObject are associated with a corresponding DataVis element (see DataObject.vis property), making them visual data objects that appear in the viewports and in rendered images.

See the ovito.vis module for the list of visual element types available in OVITO.

enabled

Boolean flag controlling the visibility of the data. If set to False, the data will not be visible in the viewports or in rendered images.

Default:True
class ovito.vis.CoordinateTripodOverlay

Displays a coordinate tripod in the rendered image of a viewport. You can attach an instance of this class to a viewport by adding it to the viewport’s overlays collection:

import ovito
from ovito.vis import CoordinateTripodOverlay
from PyQt5 import QtCore

# Create an overlay.
tripod = CoordinateTripodOverlay()
tripod.size = 0.07
tripod.alignment = QtCore.Qt.AlignRight ^ QtCore.Qt.AlignBottom

# Attach overlay to the active viewport.
viewport = ovito.dataset.viewports.active_vp
viewport.overlays.append(tripod)
alignment

Selects the corner of the viewport where the tripod is displayed. This must be a valid Qt.Alignment value value as shown in the example above.

Default:PyQt5.QtCore.Qt.AlignLeft ^ PyQt5.QtCore.Qt.AlignBottom
axis1_color

RGB display color of the first axis.

Default:(1.0, 0.0, 0.0)
axis1_dir

Vector specifying direction and length of first axis, expressed in the global Cartesian coordinate system.

Default:(1,0,0)
axis1_enabled

Enables the display of the first axis.

Default:True
axis1_label

Text label for the first axis.

Default:“x”
axis2_color

RGB display color of the second axis.

Default:(0.0, 0.8, 0.0)
axis2_dir

Vector specifying direction and length of second axis, expressed in the global Cartesian coordinate system.

Default:(0,1,0)
axis2_enabled

Enables the display of the second axis.

Default:True
axis2_label

Text label for the second axis.

Default:“y”
axis3_color

RGB display color of the third axis.

Default:(0.2, 0.2, 1.0)
axis3_dir

Vector specifying direction and length of third axis, expressed in the global Cartesian coordinate system.

Default:(0,0,1)
axis3_enabled

Enables the display of the third axis.

Default:True
axis3_label

Text label for the third axis.

Default:“z”
axis4_color

RGB display color of the fourth axis.

Default:(1.0, 0.0, 1.0)
axis4_dir

Vector specifying direction and length of fourth axis, expressed in the global Cartesian coordinate system.

Default:(0.7071, 0.7071, 0.0)
axis4_enabled

Enables the display of the fourth axis.

Default:False
axis4_label

Label for the fourth axis.

Default:“w”
font_size

The font size for rendering the text labels of the tripod. The font size is specified in terms of the tripod size.

Default:0.4
line_width

Controls the width of axis arrows. The line width is specified relative to the tripod size.

Default:0.06
offset_x

This parameter allows to displace the tripod horizontally. The offset is specified as a fraction of the output image width.

Default:0.0
offset_y

This parameter allows to displace the tripod vertically. The offset is specified as a fraction of the output image height.

Default:0.0
size

Scaling factor controlling the overall size of the tripod. The size is specified as a fraction of the output image height.

Default:0.075
class ovito.vis.PythonViewportOverlay

This overlay type can be attached to a viewport to run a Python script every time an image of the viewport is rendered. The Python script can execute arbitrary drawing commands to paint on top of the rendered image.

Note that an alternative to using the PythonViewportOverlay class is to directly manipulate the static image returned by the Viewport.render() method before saving it to disk.

You can attach a Python overlay to a viewport by adding an instance of this class to the viewport’s overlays collection:

import ovito
from ovito.vis import PythonViewportOverlay

# Define a function that paints on top of the rendered image.
def render_overlay(painter, **args):
    painter.drawText(10, 10, "Hello world")

# Create the overlay.
overlay = PythonViewportOverlay(function = render_overlay)

# Attach overlay to the active viewport.
viewport = ovito.dataset.viewports.active_vp
viewport.overlays.append(overlay)
function

The Python function to be called every time the viewport is repainted or when an output image is being rendered.

The function must have a signature as shown in the example above. The painter parameter passed to the user-defined function contains a QPainter object, which provides painting methods to draw arbitrary 2D graphics on top of the image rendered by OVITO.

Additional keyword arguments are passed to the function in the args dictionary. The following keys are defined:

  • viewport: The Viewport being rendered.
  • render_settings: The active RenderSettings.
  • is_perspective: Flag indicating whether projection is perspective or parallel.
  • fov: The field of view.
  • view_tm: The camera transformation matrix.
  • proj_tm: The projection matrix.

Implementation note: Exceptions raised by the custom rendering function are not propagated to the calling context.

Default:None
class ovito.vis.TextLabelOverlay

Displays a text label in a viewport and in rendered images. You can attach an instance of this class to a viewport by adding it to the viewport’s overlays collection:

import ovito
from ovito.vis import TextLabelOverlay
from PyQt5 import QtCore

# Create an overlay.
overlay = TextLabelOverlay(
    text = 'Some text', 
    alignment = QtCore.Qt.AlignHCenter ^ QtCore.Qt.AlignBottom,
    offset_y = 0.1,
    font_size = 0.03,
    text_color = (0,0,0))

# Attach overlay to the active viewport.
viewport = ovito.dataset.viewports.active_vp
viewport.overlays.append(overlay)

Text labels can display dynamically computed values. See the text property for an example.

alignment

Selects the corner of the viewport where the text is displayed (anchor position). This must be a valid Qt.Alignment value as shown in the example above.

Default:PyQt5.QtCore.Qt.AlignLeft ^ PyQt5.QtCore.Qt.AlignTop
font_size

The font size, which is specified as a fraction of the output image height.

Default:0.02
offset_x

This parameter allows to displace the label horizontally from its anchor position. The offset is specified as a fraction of the output image width.

Default:0.0
offset_y

This parameter allows to displace the label vertically from its anchor position. The offset is specified as a fraction of the output image height.

Default:0.0
outline_color

The text outline color. This is used only if outline_enabled is set.

Default:(1.0,1.0,1.0)
outline_enabled

Enables the painting of a font outline to make the text easier to read.

Default:False
source_node

The ObjectNode whose modification pipeline is queried for dynamic attributes that can be referenced in the text string. See the text property for more information.

text

The text string to be rendered.

The string can contain placeholder references to dynamically computed attributes of the form [attribute], which will be replaced by their actual value before rendering the text label. Attributes are taken from the pipeline output of the ObjectNode assigned to the overlay’s source_node property.

The following example demonstrates how to insert a text label that displays the number of currently selected particles:

import ovito
from ovito.io import import_file
from ovito.vis import TextLabelOverlay
from ovito.modifiers import ExpressionSelectionModifier

# Import a simulation dataset and select some atoms based on their potential energy:
node = import_file("input/simulation.dump")
node.add_to_scene()
node.modifiers.append(ExpressionSelectionModifier(expression = 'peatom > -4.2'))

# Create the overlay. Note that the text string contains a reference
# to an output attribute of the ExpressionSelectionModifier.
overlay = TextLabelOverlay(text = 'Number selected atoms: [SelectExpression.num_selected]')
# Specify source of dynamically computed attributes.
overlay.source_node = node

# Attach overlay to the active viewport.
viewport = ovito.dataset.viewports.active_vp
viewport.overlays.append(overlay)
Default:“Text label”
text_color

The text rendering color.

Default:(0.0,0.0,0.5)
class ovito.vis.SimulationCellVis
Base class:ovito.vis.DataVis

Controls the visual appearance of SimulationCell objects.The following script demonstrates how to change the line width of the simulation cell:

from ovito.io import import_file
from ovito.data import SimulationCell

pipeline = import_file("input/simulation.dump")
pipeline.add_to_scene()

cell = pipeline.source.expect(SimulationCell)
cell.vis.line_width = 1.3
line_width

The width of the simulation cell line (in simulation units of length).

Default:0.14% of the simulation box diameter
render_cell

Boolean flag controlling the cell’s visibility in rendered images. If False, the cell will only be visible in the interactive viewports.

Default:True
rendering_color

The line color used when rendering the cell.

Default:(0, 0, 0)
class ovito.vis.SurfaceMeshVis
Base class:ovito.vis.DataVis

Controls the visual appearance of a surface mesh object, which can be generated by modifiers such as ConstructSurfaceModifier or CreateIsosurfaceModifier.

cap_color

The display color of the cap polygons at periodic boundaries.

Default:(0.8, 0.8, 1.0)
cap_transparency

The level of transparency of the displayed cap polygons. Valid range is 0.0 – 1.0.

Default:0.0
reverse_orientation

Flips the orientation of the surface. This affects the generation of cap polygons.

Default:False
show_cap

Controls the visibility of cap polygons, which are created at the intersection of the surface mesh with periodic box boundaries.

Default:True
smooth_shading

Enables smooth shading of the triangulated surface mesh.

Default:True
surface_color

The display color of the surface mesh.

Default:(1.0, 1.0, 1.0)
surface_transparency

The level of transparency of the displayed surface. Valid range is 0.0 – 1.0.

Default:0.0
class ovito.vis.DislocationVis
Base class:ovito.vis.DataVis

Controls the visual appearance of dislocation lines extracted by a DislocationAnalysisModifier. An instance of this class is attached to every DislocationNetwork data object.

burgers_vector_color

The color of Burgers vector arrows.

Default:(0.7, 0.7, 0.7)
burgers_vector_width

The scaling factor applied to displayed Burgers vectors. This can be used to exaggerate the arrow size.

Default:1.0
indicate_character

Controls how the display color of dislocation lines is chosen.Possible values:

  • DislocationVis.ColoringMode.ByDislocationType (default)
  • DislocationVis.ColoringMode.ByBurgersVector
  • DislocationVis.ColoringMode.ByCharacter
line_width

Controls the display width (in units of length of the simulation) of dislocation lines.

Default:1.0
shading

The shading style used for the lines. Possible values:

  • DislocationVis.Shading.Normal (default)
  • DislocationVis.Shading.Flat
show_burgers_vectors

Boolean flag that enables the display of Burgers vector arrows.

Default:False
show_line_directions

Boolean flag that enables the visualization of line directions.

Default:False
class ovito.vis.OSPRayRenderer

This is one of the software-based rendering backends of OVITO. OSPRay is an open-source raytracing engine integrated into OVITO.

It can render scenes with ambient occlusion lighting, semi-transparent objects, and depth-of-field focal blur. For technical details of the supported rendering algorithms and parameters, see the www.ospray.org website.

ambient_brightness

Controls the radiance of the ambient light.

Default:0.8
ambient_light_enabled

Enables the ambient light, which surrounds the scene and illuminates it from infinity with constant radiance.

Default:True
aperture

The aperture radius controls how blurred objects will appear that are out of focus if dof_enabled was set.

Default:0.5
default_light_angular_diameter

Specifies the apparent size (angle in radians) of the default directional light source. Setting the angular diameter to a value greater than zero will result in soft shadows when the rendering backend uses stochastic sampling (which is only the case for the Path Tracer backend).

Default:0.0
default_light_intensity

The intensity of the default directional light source. The light source must be enabled by setting direct_light_enabled.

Default:3.0
direct_light_enabled

Enables the default directional light source that is positioned behind the camera and is pointing roughly along the viewing direction. The brightness of the light source is controlled by the default_light_intensity parameter.

Default:True
dof_enabled

Enables the depth-of-field effect. Only objects exactly at the distance from the camera specified by the focal_length will appear sharp when depth-of-field rendering is active. Objects closer to or further from the camera will appear blurred.

Default:False
focal_length

Only objects exactly at this distance from the camera will appear sharp when dof_enabled is set. Objects closer to or further from the camera will appear blurred.

Default:40.0
material_shininess

Specular Phong exponent value for the default material. Usually in the range between 2.0 and 10,000.

Default:10.0
material_specular_brightness

Controls the specular reflectivity of the default material.

Default:0.05
max_ray_recursion

The maximum number of recursion steps during raytracing. Normally, 1 or 2 is enough, but when rendering semi-transparent objects, a larger recursion depth is needed.

Default:20
refinement_iterations

The OSPRay renderer supports a feature called adaptive accumulation, which is a progressive rendering method. During each rendering pass, the rendered image is progressively refined. This parameter controls the number of iterations until the refinement stops.

Default:8
samples_per_pixel

The number of raytracing samples computed per pixel. Larger values can help to reduce aliasing artifacts.

Default:4
class ovito.vis.ParticleVis
Base class:ovito.vis.DataVis

This object controls the visual appearance of particles.

An instance of this class is attached to the Position ParticleProperty and can be accessed via its vis property.

For example, the following script demonstrates how to change the display shape of particles to a square:

from ovito.io import import_file
from ovito.vis import ParticleVis

pipeline = import_file("input/simulation.dump")
pipeline.add_to_scene()
vis = pipeline.source.particle_properties.position.vis
vis.shape = ParticleVis.Shape.Square
radius

The standard display radius of particles. This value is only used if no per-particle or per-type radii have been set. A per-type radius can be set via ovito.data.ParticleType.radius. An individual display radius can be assigned to particles by creating a Radius ParticleProperty, e.g. using the ComputePropertyModifier.

Default:1.2
shape

The display shape of particles. Possible values are:

  • ParticleVis.Shape.Sphere (default)
  • ParticleVis.Shape.Box
  • ParticleVis.Shape.Circle
  • ParticleVis.Shape.Square
  • ParticleVis.Shape.Cylinder
  • ParticleVis.Shape.Spherocylinder
class ovito.vis.VectorVis
Base class:ovito.vis.DataVis

Controls the visual appearance of vectors (arrow elements).

An instance of this class may be attached to particle properties that represent three-dimensional vector quantities, like for example the Displacement property. It can be accessed via the vis property of the ParticleProperty class.

For example, the following script demonstrates how to change the display color of force vectors loaded from an input file:

from ovito.io import import_file
from ovito.vis import VectorVis

node = import_file("input/simulation.dump")
node.add_to_scene()
vis = node.source.particle_properties.force.vis
vis.color = (1.0, 0.5, 0.5)
alignment

Controls the positioning of arrows with respect to the particles. Possible values:

  • VectorVis.Alignment.Base (default)
  • VectorVis.Alignment.Center
  • VectorVis.Alignment.Head
color

The display color of arrows.

Default:(1.0, 1.0, 0.0)
reverse

Boolean flag controlling the reversal of arrow directions.

Default:False
scaling

The uniform scaling factor applied to vectors.

Default:1.0
shading

The shading style used for the arrows. Possible values:

  • VectorVis.Shading.Normal (default)
  • VectorVis.Shading.Flat
width

Controls the width of arrows (in natural length units).

Default:0.5
class ovito.vis.BondsVis
Base class:ovito.vis.DataVis

Controls the visual appearance of particle bonds. An instance of this class is attached to every Bonds data object.

color

The display color of bonds. Used only if use_particle_colors == False.

Default:(0.6, 0.6, 0.6)
shading

The shading style used for bonds. Possible values:

  • BondsVis.Shading.Normal (default)
  • BondsVis.Shading.Flat
use_particle_colors

If True, bonds are assigned the same color as the particles they are adjacent to.

Default:True
width

The display width of bonds (in natural length units).

Default:0.4
class ovito.vis.TrajectoryLineVis
Base class:ovito.vis.DataVis

Controls the visual appearance of particle trajectory lines. An instance of this class is attached to every TrajectoryLineGenerator data object.

color

The display color of trajectory lines.

Default:(0.6, 0.6, 0.6)
shading

The shading style used for trajectory lines. Possible values:

  • TrajectoryLineVis.Shading.Normal
  • TrajectoryLineVis.Shading.Flat (default)
upto_current_time

If True, trajectory lines are only rendered up to the particle positions at the current animation time. Otherwise, the complete trajectory lines are displayed.

Default:False
width

The display width of trajectory lines.

Default:0.2
class ovito.vis.POVRayRenderer

This is one of the rendering backends of OVITO.

POV-Ray (The Persistence of Vision Raytracer) is an open-source raytracing program. The POV-Ray rendering backend streams the scene data to a temporary file, which is then processed and rendered by the external POV-Ray program. The final rendered image is read back into OVITO.

The rendering backend requires the POV-Ray executable to be installed on the system. It will automatically look for the executable povray in the system path. If the executable is not in the default search path, its location must be explicitly specified by setting the povray_executable attribute.

For a more detailed description of the rendering parameters exposed by this Python class, please consult the official POV-Ray documentation.

antialiasing

Enables supersampling to reduce aliasing effects.

Default:True
aperture

Controls the aperture of the camera, which is used for depth-of-field rendering.

Default:1.0
blur_samples

Controls the maximum number of rays to use for each pixel to compute focus blur (depth-of-field).

Default:1.0
depth_of_field

This flag enables focus blur (depth-of-field) rendering.

Default:False
focal_length

Controls the focal length of the camera, which is used for depth-of-field rendering.

Default:40.0
interpupillary_distance

Controls interpupillary distance (eye separation) for stereoscopic rendering. This setting is only used if the omni_stereo option has been set.

Default:0.5
omni_stereo

This flag enables omni­directional stereo projection for stereoscopic 360-degree VR videos and images. Note that this requires POV-Ray 3.7.1 or newer. The eye separation distance is controlled by the interpupillary_distance parameter.

Default:False
povray_executable

The absolute path to the external POV-Ray executable on the local computer, which is called by this rendering backend to render an image. If no path is set, OVITO will look for povray in the default executable search path.

Default:""
quality_level

The image rendering quality parameter passed to POV-Ray.

Default:9
radiosity

Enables radiosity light calculations.

Default:False
radiosity_raycount

The number of rays that are sent out whenever a new radiosity value has to be calculated.

Default:50
show_window

Controls whether the POV-Ray window is shown during rendering. This allows you to follow the image generation process.

Default:True
class ovito.vis.ColorLegendOverlay

Renders a color legend for a ColorCodingModifier on top of the three-dimensional scene. You can attach an instance of this class to a Viewport by adding it to the viewport’s overlays collection:

import ovito
from ovito.io import import_file
from ovito.vis import ColorLegendOverlay
from ovito.modifiers import ColorCodingModifier
from PyQt5.QtCore import Qt

# Prepare a data pipeline containing a ColorCodingModifier:
pipeline = import_file("input/simulation.dump")
color_mod = ColorCodingModifier(particle_property = 'peatom')
pipeline.modifiers.append(color_mod)
pipeline.add_to_scene()

# Configure the viewport overlay and link it to the ColorCodingModifier:
overlay = ColorLegendOverlay(
    modifier = color_mod,
    title = 'Potential energy per atom:', 
    alignment = Qt.AlignLeft ^ Qt.AlignTop,
    orientation = Qt.Vertical,
    offset_y = -0.04,
    font_size = 0.12,
    format_string = '%.2f eV')

# Attach the overlay to the Viewport that is going to be used for rendering:
viewport = ovito.dataset.viewports.active_vp
viewport.overlays.append(overlay)
alignment

Selects the corner of the viewport where the color bar is displayed (anchor position). This must be a valid Qt.Alignment value as shown in the code example above.

Default:PyQt5.QtCore.Qt.AlignHCenter ^ PyQt5.QtCore.Qt.AlignBottom
aspect_ratio

The aspect ratio of the color bar. Larger values make it more narrow.

Default:8.0
font_size

The relative size of the font used for text labels.

Default:0.1
format_string

The format string used with the sprintf() function to generate the text representation of floating-point values. You can change this format string to control the number of decimal places or add units to the numeric values, for example.

Default:‘%g’
label1

Sets the text string displayed at the upper end of the bar. If empty, the end_value of the ColorCodingModifier is used.

Default:‘’
label2

Sets the text string displayed at the lower end of the bar. If empty, the start_value of the ColorCodingModifier is used.

Default:‘’
legend_size

Controls the overall size of the color bar relative to the output image size.

Default:0.3
modifier

The ColorCodingModifier for which the color legend should be rendered.

offset_x

This parameter allows to displace the color bar horizontally from its anchor position. The offset is specified as a fraction of the output image width.

Default:0.0
offset_y

This parameter allows to displace the color bar vertically from its anchor position. The offset is specified as a fraction of the output image height.

Default:0.0
orientation

Selects the orientation of the color bar. This must be a valid Qt.Orientation value as shown in the code example above.

Default:PyQt5.QtCore.Qt.Horizontal
outline_color

The text outline color. This is used only if outline_enabled is set.

Default:(1.0,1.0,1.0)
outline_enabled

Enables the painting of a font outline to make the text easier to read.

Default:False
text_color

The RGB color used for text labels.

Default:(0.0,0.0,0.0)
title

The text displayed next to the color bar. If empty, the name of the input property selected in the ColorCodingModifier is used.

Default:‘’
class ovito.vis.TachyonRenderer

This is one of the software-based rendering backends of OVITO. Tachyon is an open-source raytracing engine integrated into OVITO.

It can render scenes with ambient occlusion lighting, semi-transparent objects, and depth-of-field focal blur.

ambient_occlusion

Enables ambient occlusion shading. Enabling this lighting technique mimics some of the effects that occur under conditions of omnidirectional diffuse illumination, e.g. outdoors on an overcast day.

Default:True
ambient_occlusion_brightness

Controls the brightness of the sky light source used for ambient occlusion.

Default:0.8
ambient_occlusion_samples

Ambient occlusion is implemented using a Monte Carlo technique. This parameters controls the number of samples to compute. A higher sample count leads to a more even shading, but requires more computation time.

Default:12
antialiasing

Enables supersampling to reduce aliasing effects.

Default:True
antialiasing_samples

The number of supersampling rays to generate per pixel to reduce aliasing effects.

Default:12
aperture

Controls the aperture of the camera, which is used for depth-of-field rendering.

Default:0.01
depth_of_field

This flag enables depth-of-field rendering.

Default:False
direct_light

Enables the parallel light source, which is positioned at an angle behind the camera.

Default:True
direct_light_intensity

Controls the brightness of the directional light source.

Default:0.9
focal_length

Controls the focal length of the camera, which is used for depth-of-field rendering.

Default:40.0
shadows

Enables cast shadows for the directional light source.

Default:True