Forum Navigation
You need to log in to create posts and topics.

Trajectory Lines Color Mapping Functionality Missing in Python Interface

I've been perusing the scripting documentation, and have looked into the source code to try and figure this out, but I'm still not finding a solution.

I have several simulations that I want to process and extract trajectory lines for a subset of the atoms (specifically by type). I am able to read the snapshot files and generate a non-colored version of the trajectories using the following commands:

from import import_file, export_file
import ovito.modifiers as om
from ovito.vis import Viewport, TrajectoryVis
from ovito import scene

pipeline = import_file("*.dump") # loads all dump files in the current directory
data = pipeline.compute()
num_types = max(data.particles['Particle Type'].array)

select_types_modifiers = []
for i in range(1, num_types + 1):
    select_types_modifiers.append(om.SelectTypeModifier(types = {i}))

select_all_types = om.SelectTypeModifier(types = set([i for i in range(1,num_types + 1)]))

unwrap_trajectories_modifer = om.UnwrapTrajectoriesModifier()

trajectory_modifier = om.GenerateTrajectoryLinesModifier(only_selected = True)

delete_modifer = om.DeleteSelectedModifier(operate_on = {'particles'})

for i in range(1, num_types):
    pipeline.modifiers.append(select_types_modifiers[i]) # selects type
    pipeline.modifiers.append(select_all_types) # selects all atoms
    data = pipeline.compute()

    #"trajectories_type_{i + 1}.ovito")
    vp.render_image(filename = f"trajectories_type_{i + 1}.png")

However, I would like to color the trajectories via the 'Time' property. This is possible in the GUI as shown below, but when I try to include the ColorCodingModifier as

ccm = om.ColorCodingModifier(operate_on = 'trajectories',
    property = 'Time',
    gradient = om.ColorCodingModifier.Rainbow(),
    auto_adjust_range = True,
    only_selected = True

I get the error: "'trajectories' is not a valid type of data element this modifier can operate on." This is consistent with the documentation found at, but inconsistent with the documentation found at It seems like the ability to color trajectories was added in a later patch to 3.5.4, but this change has not been updated in the ovito python module. Is there a way to color these trajectories by time in the current version of the Ovito Python Interface, or, barring that, is there a way to update my local version of ovito?



Uploaded files:
  • example.png

Hi Jarin,

The Color Coding modifier's ability to operate on trajectory lines is something we added after the latest stable release 3.5.4 of OVITO. In other words, it is available only in our current development builds. Documentation under reflects the state of the current development build. Note that the version number is typically incremented close to the official release. Thus, the documentation belonging to the preview version may still show the version number of latest stable release. I'm sorry if this contributed to your confusion.

I've now updated the documentation under again to reflect the latest development state as we are getting closer to the release date of the next stable release 3.6.0 of OVITO. Note that, in the meantime, important changes to some of the visual elements were made, including the TrajectoryVis element. It has now gained the capability to directly render the trajectory lines with pseudo-colors that are based on one of the line properties (e.g. the "Time" property). Thus, applying the ColorCodingModifier should no longer be necessary in your case. You can find a code example showing how to do the line coloring in the TrajectoryVis element here.

Finally, here are the download links to the latest dev builds of Ovito:


That does clear things up, thanks for the quick response. Is there a way to access the development build of the Ovito Python Interface? The download links you provide seem to exclusively be for the GUI, though I'm a little unclear on how the source code and the Python interface interact.

You can download the OVITO Pro package above and use the included 'ovitos' interpreter to run Python scripts (a OVITO Pro license is not needed for that). It ships with the latest preview version of the ovito Python package.

PyPI and Anaconda packages with the preview version of the ovito Python package for installation in an external Python interpreter are not available yet. I may be able to build those next week, I hope.

New for our users in China: OVITO on WeChat 

Official OVITO WeChat channel operated by Foshan Diesi Technology Co., Ltd.