Using the VoronoiAnalysisModifier to obtain the surface information of Voronoi cells

Hello.
I would like to use the VoronoiAnalysisModifier to identify the neighbors for each atom. Specifically, I want to find three neighbors that share a vertex of a Voronoi cell; together with the central atom, these three neighbors form a tetrahedron. Therefore, I need to know which neighbors form each face of the Voronoi cell.

However, when I used the VoronoiAnalysisModifier to obtain the vertex coordinates for each face, I noticed that the vertex coordinates provided by OVITO seem to have issues. For instance, below is the Voronoi cell I obtained from the OVITO graphical interface, and it is clear that the z-coordinates of the vertices cannot exceed the box length (which is 27.1).
voronoi_cell
While processing with the following code, I found that some of the printed z-components exceed 30.
print_vertices
Could you please explain what might be happening here? Additionally, if I want to know which neighbors form each face, can OVITO directly provide this information? I noticed that it does not seem to be mentioned in the manual.

Thank you in advance for your assistance.
Codes and Data

from ovito.io import import_file
from ovito.modifiers import VoronoiAnalysisModifier, ExpressionSelectionModifier, DeleteSelectedModifier, WrapPeriodicImagesModifier


file = "./particle_id_532_movecenter.colloid"
atom_id = 532

pipeline = import_file(file)
pipeline.modifiers.append(WrapPeriodicImagesModifier())
pipeline.modifiers.append(VoronoiAnalysisModifier(generate_polyhedra=True, ))
pipeline.modifiers.append(ExpressionSelectionModifier(operate_on="surface_regions", expression="ParticleIdentifier!=%s" % atom_id))
pipeline.modifiers.append(DeleteSelectedModifier())
pipeline_atoms = pipeline.compute(0)

mesh = pipeline_atoms.surfaces["voronoi-polyhedra"]
face_vertices = mesh.get_face_vertices()
vertices = mesh.vertices["Position"]

print("face ver pos")
for one_face_ver in face_vertices:
    print(vertices[one_face_ver])

particle_id_532_movecenter.colloid (29.5 KB)

While processing with the following code, I found that some of the printed z-components exceed 30.

Keep in mind that those might be unwrapped, equivalent positions coming from the voro++ routine. While OVITO automatically maps the Voronoi polyhedra back into the cell for visualization purposes, there is no guarantee that the internal mesh coordinates are wrapped. You can do this with just a few of lines of python code.

Additionally, if I want to know which neighbors form each face, can OVITO directly provide this information?

You can find the Voronoi neighbors by inspecting the Voronoi bonds,


here you can see the Voronoi cell of the particle with the ID 532 and its neighbors.

Alternatively, you can inspect the Voronoi faces, which are associated with the neighboring cells.

Hello.
If I want to use Python code to perform batch processing on the server instead of through a graphical interface, how can I utilize OVITO’s Python package to obtain the area of each face of a Voronoi cell and the corresponding neighbor ID for each face? I noticed that the section on ovito.data.SurfaceMesh in the manual does not mention this information. If possible, could you show an example code?
Thank you in advance.

You linked the correct manual entry! :slight_smile: Please refer to the description of the faces Property container of the Surface Mesh class: see this subsection.
You can access the information listed in the Voronoi polyhedra data table (as shown in the above screenshot) like this:

voro_faces = data.surfaces['voronoi-polyhedra'].faces
for i in range(voro_faces.count):
    area = voro_faces['Area'][i]
    adjacent_cell = voro_faces['Adjacent Cell'][i]
    print(i, area, adjacent_cell)