Text label viewport layer

This viewport layer displays a user-defined text string in the rendered image. The text string may contain placeholders that get replaced with the current values of global attributes dynamically computed by OVITO's data pipeline. This makes it possible to display dynamic information such as the current simulation timestep, number of atoms, or analysis results in rendered images or movies.

The lower panel displays the list of variables output by the current pipeline, which can be included in the text label and which will get replaced with their current values.

Defining derived attributes

Sometimes the global attributes output by the data pipeline do not have the right format or normalization that is desired for the text label. For instance, the data pipeline may output only the absolute count of particles fulfilling a certain criterion. The CommonNeighborAnalysis.counts.BCC attribute generated by the Common Neighbor Analysis modifier reports the number of BCC atoms in the system. But what if you want to print the fraction of BCC atoms instead of the total count?

In order to divide the count by the total number of atoms in the system we need to define a new derived attribute. This can be accomplished by inserting a Python script modifier into the data pipeline. This modifier executes a simple Python function that computes the value of our new attribute from the of existing attributes(s):

def modify(frame, data):
    bcc_count = data.attributes['CommonNeighborAnalysis.counts.BCC']
    data.attributes['bcc_fraction'] = bcc_count / data.particles.count

The new attribute bcc_fraction can subsequently be referenced in the text label string as a dynamic variable. Note that you can use the same technique to precisely control the formatting of numeric values in the text label. This is done by converting the numeric value to a text string in a user-defined Python modifier function. For example:

def modify(frame, data):
    surface_area = data.attributes['ConstructSurfaceMesh.surface_area']
    data.attributes['surface_area_str'] = '{:.2g}'.format(surface_area)

The function converts the numeric input attribute to a string attribute using a formatting rule that rounds the floating-point value after two decimal places.