Forum Navigation
You need to log in to create posts and topics.

How to calculate the average volume of each Voronoi polyhedra type?

Dear Ovito developers,

I am trying to calculate the most frequent polyhedra using the OVITO script:


This helps me calculating the most frequent indices easily, but I also want to calculate the average volume of each frequent index or each polyhedra type.

What can I do? Could you please help?

Thank you.


Hi Kingsley,

You can find the indices of atoms with a specific Voronoi Index (in this example the most frequent one) like this,

numpy.where((voro_indices == unique_indices[0]).all(axis=1))[0]

that means you can look up their corresponding Voronoi volumes like this:

voro_volumes = data.particles["Atomic Volume"]
voro_volumes[numpy.where((voro_indices == unique_indices[0]).all(axis=1))[0]])]

and simply use numpy.mean()to calculate the average value:

numpy.mean(voro_volumes[numpy.where((voro_indices == unique_indices[0]).all(axis=1))[0]])


Dear Constanze,


Thank you very much for your tip. But I got some errors here.

I want to calculate 500 frame data and save all results of each frame into a file. But it has some errors in getting the average polyhedra volume of every index or something. Could you please have a look?

Thank you.


for frame in range(pipeline.source.num_frames):
    data = pipeline.compute(frame)
    voro_indices = data.particles["Voronoi Index"]
    unique_indices, counts = row_histogram(voro_indices)

    # Find the average volume of every index
    voro_volumes = data.particles["Atomic Volume"]
    avol = numpy.empty([20], dtype=float)
    for v in range(20):
        vol = voro_volumes[numpy.where((voro_indices == unique_indices[v]).all(axis=1))[0]]
        avols = numpy.mean(voro_volumes[numpy.where((voro_indices == unique_indices[v]).all(axis=1))[0]])

    for i in range(20):
        print("%s\t= %i\t\t%.2f %%\t%.2f" % (tuple(unique_indices[i][2:]),counts[i],100.0*float(counts[i])/len(voro_indices),avol[i]),file=out1)


In your code snippet, avol is an empty numpy array of shape (20,), so using it in your print statement in line 56 doesn't make much sense.

If you would like us to send you a ready-to-use solution, please contact our Pro support via email and let us know your OVITO Pro license key.


Dear Consanze,

Thank you very much for your information.

New for our users in China: OVITO on WeChat 

Official OVITO WeChat channel operated by Foshan Diesi Technology Co., Ltd.