 Author Topic: How to determine the mean value of a particle property of a selection of atoms?  (Read 3410 times)

Constanze Kalcher

• Sr. Member
•     • • Posts: 301 How to determine the mean value of a particle property of a selection of atoms?
« on: September 14, 2018, 04:18:12 PM »
Let's say you want to calculate the average value of a particle property for only a subset of atoms, for example the shear strain.
First you may want to use one of the Selection modifiers, e.g., Expression select, Select particle type, Slice or Manual selection to select the atoms of interest.

Then, insert a Python script modifier that calculates the mean value of the per-atom shear strain of your selection and saves it as a global attribute.
Code: [Select]
from ovito.data import *
import numpy as np

def modify(frame, input, output):
shear_strain = input.particle_properties["Shear Strain"].array
selection = input.particle_properties["Selection"].array
output.attributes["Average shear strain"] = np.mean( shear_strain[selection == 1] )

Global attributes can be exported as Calculation Results Text File output file format.

Constanze Kalcher

• Sr. Member
•     • • Posts: 301 Re: How to determine the mean value of a particle property of a selection of atoms?
« Reply #1 on: September 14, 2018, 04:20:40 PM »
The OVITO 3 equivalent of the above Python script modifier would be :
Code: [Select]
from ovito.data import *
import numpy as np

def modify(frame, data):
shear_strain = data.particles["Shear Strain"]
selection = data.particles["Selection"]
output.attributes["Average shear strain"] = np.mean( shear_strain[selection == 1] )
« Last Edit: January 23, 2019, 01:49:06 PM by Constanze Kalcher »