Introduction — OVITO Python Reference 3.16.0 documentation

# Introduction

The OVITO Python module provides the powerful data analysis and visualization functions of OVITO and makes them available in Python scripts. You can make use of the module’s comprehensive API either in standalone Python programs, Jupyter notebooks, or within the interactive environment of OVITO Pro, which is the desktop application that comes with a fully-integrated interpreter able to run Python code and display computation results right in the program’s interactive 3d viewports.

You get access to all of OVITO’s data structures, file readers, data analysis algorithms, and visualization and rendering capabilities from within your Python scripts - even exclusive ones from OVITO Pro. This allows you to develop fully automated post-processing workflows for your simulation data and run them anywhere you want. The Python module is available free of charge and can be easily installed in any Python 3 interpreter. Furthermore, if you are an OVITO Pro user, the Python module is also the mechanism by which you can extend the desktop software with custom modifiers, file readers, and viewport layers written in Python, which seamlessly integrate into the program’s graphical user interface.

Let’s take a look at some of these typical use cases of the OVITO Python module.

Automation scripts

The OVITO Python programming interface lets you automate laborious data post-processing tasks, which you would otherwise have to perform by hand using the OVITO Basic and Pro desktop applications. The Python API allows you to carry out all actions non-interactively and process a large number of simulation datasets on a parallel computing cluster, for example.

The following standalone Python program loads an atomic structure from a simulation data file, selects all hydrogen atoms, deletes them, and writes the results back to some output file in a different format:

    from ovito.io import import_file, export_file
    from ovito.modifiers import SelectTypeModifier, DeleteSelectedModifier

    pipeline = import_file('input.data')
    pipeline.modifiers.append(SelectTypeModifier(property='Particle Type', types={'H'}))
    pipeline.modifiers.append(DeleteSelectedModifier())
    export_file(pipeline, 'output.xyz', 'xyz', columns=['Particle Type', 'Position.X', 'Position.Y', 'Position.Z'])

Like in the OVITO desktop applications, the task is performed by building up a data processing pipeline, consisting of two modifiers, which are applied in sequence to the frames of a simulation trajectory. If needed, you could also make use of the image and animation rendering functions provided by the OVITO module to generate 3d visualizations of your data.

Tip

The OVITO Pro application includes a convenient Python code generation function that can translate complex processing pipelines or visualization setups built with the graphical user interface into standalone Python programs, which you run non-interactively on any computer. This frees you from writing the Python code yourself and can save you valuable time.

Extending OVITO with custom modifiers, file readers, and viewport layers

Since it gives you direct access to all aspects of the internal data model used by OVITO, you can also use the Python API to develop completely new types of processing algorithms (modifiers) and manipulate, analyze, or visualize simulation data in ways not covered by any of the built-in algorithms of the software.

Such Python-based extensions for OVITO, which can also cover more aspects such as file import/export or visualization, can be distributed as installable Python packages and shared with other users. They can use your extension function in their own programs or install them in the OVITO Pro desktop application, seamlessly integrated into the graphical user interface.

See also

OVITO Extensions Directory