Select surface particles

Dear Ovito users,

I have a system with a void space in the middle. I want to identify and save the id of the particles on the void surface. To do that, I write:

pipeline = import_file(filename)
celldata = pipeline.compute() = (True,True,True)

method = ConstructSurfaceModifier.Method.AlphaShape,
radius = 1.0,
identify_regions = True,
select_surface_particles = True))

data = pipeline.compute()

However, I cannot access the information about the particles on the surface. Can someone help me?

Thank you so much in advance for your time and help.

Kind regards,


What information would you like to access specifically?

Analogous to what you would see in the OVITO desktop application, the Construct Surface Mesh modifier adds a new particle property Selection to the data collection, with values of 1 for the surface particles and values of 0 for all other particles.
You can use this information to index into other particle property arrays, e.g., the particle identifiers or particle types:

print(data.particles.identifiers[data.particles.selection == 1])
print(data.particles.particle_types[data.particles.selection == 1])

Also, please set the periodic boundary conditions of the simulation cell within the scope of a Python modifier function that is inserted into the pipeline. See 2nd Attenion Box here for a detailed explanation.

Hi Kalcher,

Thank you so much for your message. I have attached a snapshot to show what information I am looking for.

As I explained before, I have a system of particles with a hole in the middle. I invoke the ConstructSurfaceModifier.Method.AlphaShape to identify the surface between the two phases. Then, I would like to extract the IDs regarding particles on the surface (in the snapshot, these particles are represented in red; I removed the other particles in the solid phase were removed to clarify). I do not know how to extract this information by combining Python and Ovito.

I have tried with print(data.particles.identifiers[data.particles.selection == 1]), but the IDs provided do not correspond with the particles on the surface.


That sounds like you might confuse the unique particle identifiers with the particle indices. The latter of course shift when you delete particles from the scene. Please read the Note box here.

I have removed particles only to highlight what information I want. But in the python script, I do not remove any particle.

but the IDs provided do not correspond with the particles on the surface.

Can you explain how you come to this conclusion?

Hi Kalcher,

My apologies. You were right, and I made a mistake reading the array where I store the IDs from data.particles.identifiers[data.particles.selection == 1]. Your solution is correct, and I got the particle IDs on the surface.

Thank you so much for your time and help.

Kind regards,

Okay, great! I’m glad it’s working for you now.