1

**Support Forum / How should I edit this script to get the Voronoi index of certain particle?**

« **on:**August 06, 2018, 12:45:44 AM »

This script is to find the ten most frequent Voronoi index.

(This script is written by Mr. Kalcher.)

I want to find the ten most frequent Voronoi index of certain particle.

(i.e. what types of polyhedron around certain particle.)

How should I edit it?

I don't know what should be added.

(This script is written by Mr. Kalcher.)

I want to find the ten most frequent Voronoi index of certain particle.

(i.e. what types of polyhedron around certain particle.)

How should I edit it?

I don't know what should be added.

Code: [Select]

`from ovito.data import *`

def modify(frame, input, output):

print("Input particle properties:")

for name in input.particles.keys():

print(name)

from ovito.data import *

import numpy

def row_histogram(a):

ca = numpy.ascontiguousarray(a).view([('', a.dtype)] * a.shape[1])

unique, indices, inverse = numpy.unique(ca, return_index=True, return_inverse=True)

counts = numpy.bincount(inverse)

sort_indices = numpy.argsort(counts)[::-1]

return (a[indices[sort_indices]], counts[sort_indices])

def modify(frame, input, output):

voro_indices = input.particles['Voronoi Index']

# Compute frequency histogram.

unique_indices, counts = row_histogram(voro_indices)

# Print the ten most frequent histogram entries.

for i in range(10):

print("%s \t %i \t (%.1f %%)" % (tuple(unique_indices[i]), counts[i], 100.0*float(counts[i])/len(voro_indices)))