391

**Support Forum / Re: Property summation and periodic boundary conditions**

« **on:**November 11, 2017, 08:13:53 PM »

Hi Jeremy,

The Compute Property modifier is probably not the right tool to compute an aggregate value from a set of atoms. If I understand you correctly, you used the

A better solution is to use a simple Python Script modifier to do the reduction computation. Let's say you want to compute the sum of the 'Potential Energy' property of all currently selected atoms. The following script function does that for you:

The computed total value is output as a global

You could extend the script further and let it compute the aggregate values for each cluster simultaneously (not just the currently selected one) and write the per-cluster values directly to an output file.

-Alex

The Compute Property modifier is probably not the right tool to compute an aggregate value from a set of atoms. If I understand you correctly, you used the

*Include Neighbour Terms*option and a cutoff range that is large enough to include the entire atom cluster. Then all atoms in the cluster are visited during the computation and you can sum up their property values at one or all atoms of the cluster. However, if your system is periodic, additional images of the same cluster may reach into the cutoff range and you get additional, undesired contributions.A better solution is to use a simple Python Script modifier to do the reduction computation. Let's say you want to compute the sum of the 'Potential Energy' property of all currently selected atoms. The following script function does that for you:

Code: [Select]

`import numpy as np`

def modify(frame, input, output):

energies = input.particle_properties['Potential Energy'].array

selection = input.particle_properties['Selection'].array

output.attributes['energy_sum'] = np.sum(energies[selection != 0])

The computed total value is output as a global

*attribute*by the script. You can access the value in various ways, for example export it to a text file using OVITO's file export function or display it in the viewports using the Text Label Overlay.You could extend the script further and let it compute the aggregate values for each cluster simultaneously (not just the currently selected one) and write the per-cluster values directly to an output file.

-Alex