# 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.

- Example B1: Computing Voronoi indices
- Example B2: Computing CNA bond indices
- Example B3: Creating particles and bonds programmatically
- Example B4: Standalone trajectory viewer

## 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.

- Example O1: Scale bar
- Example O2: Add a data plot to rendered images
- Example O3: Highlight a particle

## 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.

- Example FR1: Custom file reader loading particle properties and the simulation cell
- Example FR2: Optimizing the performance of Example FR1