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.
- Example M1: Calculating mean square displacement
- Example M2: Custom order parameter calculation
- Example M3: Color mapping to visualize local lattice orientation
- Example M4: Finding overlapping particles
- Example M5: Shrink-wrap simulation box
- Example M6: Calculate local entropy
- Example M7: Displacement vectors with reference configuration
- Example M8: Compute trajectory average of a global attribute
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.