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

Quote from Kingsley Carter on October 18, 2021, 4:59 amDear Ovito developers,
I am trying to calculate the most frequent polyhedra using the OVITO script:
https://www.ovito.org/docs/current/python/introduction/examples/batch_scripts/voronoi_indices.php
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.
Dear Ovito developers,
I am trying to calculate the most frequent polyhedra using the OVITO script:
https://www.ovito.org/docs/current/python/introduction/examples/batch_scripts/voronoi_indices.php
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.

Quote from Constanze Kalcher on October 18, 2021, 10:01 pmHi 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]])
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]])

Quote from Kingsley Carter on October 18, 2021, 11:55 pmDear 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.
... ... out1=open("CuZr.txt",'a') 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) out1.close()
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.
... ... out1=open("CuZr.txt",'a') 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) out1.close()

Quote from Constanze Kalcher on October 19, 2021, 3:36 pmIn 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.
Thanks.
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.
Thanks.

Quote from Kingsley Carter on October 20, 2021, 4:45 amDear Consanze,
Thank you very much for your information.
Dear Consanze,
Thank you very much for your information.
新的OVITO微信频道!
New for our users in China: OVITO on WeChat
Official OVITO WeChat channel operated by Foshan Diesi Technology Co., Ltd.
