### Author Topic: How should I edit this script to get the Voronoi index of certain particle?  (Read 435 times)

#### RMCtestFYP

• Newbie
• Posts: 18
##### 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.

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)))    `
« Last Edit: August 06, 2018, 12:51:46 AM by RMCtestFYP »

#### Constanze Kalcher

• Full Member
• Posts: 121
##### Re: How should I edit this script to get the Voronoi index of certain particle?
« Reply #1 on: August 06, 2018, 05:01:51 PM »
First of all, you made a mistake when you copy-pasted Alexander's example script again. You should remove the first 6 lines.
Moreover, you need to be more clear in your wording. What do you mean by "Voronoi index of certain particle"?

Do you want to know the Voronoi index of a certain particle? Or are you asking how to get the distribution of Voronoi-indices for a certain particle type?
Those are two different things.

-Constanze

#### RMCtestFYP

• Newbie
• Posts: 18
##### Re: How should I edit this script to get the Voronoi index of certain particle?
« Reply #2 on: August 06, 2018, 07:23:13 PM »
Oh, ok, I make some wrong copy.

It should the 'distribution of Voronoi index of certain type of atom'.
For example, my sample  have A, B, C type atoms.

I want to find the distribution of polyhedron formed around A.

Since the above script is to find the distribution of polyhedron formed around A, B and C totally,
I have no idea on how to edit it.

Sorry for my confusing wording!

#### Constanze Kalcher

• Full Member
• Posts: 121
##### Re: How should I edit this script to get the Voronoi index of certain particle?
« Reply #3 on: August 07, 2018, 10:10:20 AM »
In that case, just change the line where you calculate the Voronoi polyhedra.
Code: [Select]
`voro_indices = input.particles['Voronoi Index']`to this:
Code: [Select]
`voro_indices = input.particles['Voronoi Index'][ input.particles['Particle Type'] == 1 ]`
-Constanze

#### RMCtestFYP

• Newbie
• Posts: 18
##### Re: How should I edit this script to get the Voronoi index of certain particle?
« Reply #4 on: August 08, 2018, 09:37:31 AM »
Thank you for your instruction! It works!