Code examples

This page presents various example scripts grouped into categories.

Standalone automation scripts

As described in the introduction, automation scripts are standalone Python programs that perform various actions in a non-interactive manner. You typically execute them from a system terminal via an external Python interpreter (or ovitos). The following examples demonstrate how to automate tasks and accomplish some new things that cannot be easily done using the graphical desktop application.

User-defined modifier functions

OVITO’s Python API allows you to implement your own type of analysis modifier by writing a Python function that gets called every time the data pipeline is evaluated. User-defined modifier functions have access to the coordinates and other properties of particles, bonds, etc. and can output newly computed information.

User-defined viewport layers

You can also implement new types of viewport layers by writing a Python function to be called every time a viewport image is being rendered. This allows you to enrich rendered images or movies with text or graphics and include additional information, e.g. data plots dynamically computed from simulation data. In OVITO Pro, user-defined viewport layers appear in the interactive viewports and can display live information.

User-defined file readers

You can also implement file readers in Python that can import data from new file formats into OVITO. Custom file readers are integrated into the file import dialog of OVITO Pro and participate in the automatic format detection mechanism of the ovito.io.import_file() Python function.