Hello,
I would like to know how I can distinguish the vertices making up the surface mesh with respect to the regions they belong to. I have a hollow microgel (spherical polymer network with a cavity), hence I have to regions for the surface mesh (along the cavity and around the whole thing). Since I only need the data points around the microgel I would like to be able which vertices/faces of vertices (I do not really care I need them for the R_H calculation) belong to the outside region so that I can continue to work with those.
Thank you in advance for any help
Leah
Hi Leah,
In general, you can use OVITO’s Python API to look up the vertices belonging to a specific region, e.g., like this
region_id = 2
mesh = data.surfaces['surface']
face_indices = np.where(mesh.faces["Region"] == region_id)[0]
verts = mesh.vertices["Position"][np.unique(mesh.get_face_vertices()[face_indices])]
print(verts)
https://www.ovito.org/docs/current/python/modules/ovito_data.html#ovito.data.SurfaceMesh
Without seeing the actual data, it’s challenging to say for sure, but it seems you should look for the region ID corresponding to the interface between your microgel and the “outer”/ empty region. To do this, open the Surfaces tab in the Data Inspector of the OVITO desktop application and switch to the Regions view. Look for the region that has the properties Exterior=1
and Filled=0
. Alternatively, you could find the region ID programmatically with:
region_id = np.where((mesh.regions['Filled'] == 0) & (mesh.regions['Exterior'] == 1))[0]
Hi Constanze,
Thank you so much for your reply. I am using this version:
import pkg_resources
on)
print(pkg_resources.get_distribution(“ovito”).version)
3.3.4
… somehow that is the only one I got to work on my node and I do not have the rights to do updates. Therefore, I got this error: AttributeError: ‘MeshPython.SurfaceMesh’ object has no attribute ‘get_face_vertices’ . Is there a way to do it on my ovito version; otherwise I have to see how I can get an update. I just want to use the outer data points of my surface mesh since I care about its overall size and not the region inside around the cavity of my hollow microgel:
pipeline = import_file("/home/leah/RCORE29-SHELL27.5/alfa_" + str(Alfa) + "/mgel.dump." + str(e))
probe_radius = 5.0
# Add surface modifier to identify regions
pipeline.modifiers.append(ConstructSurfaceModifier(
method=ConstructSurfaceModifier.Method.AlphaShape,
radius=probe_radius,
identify_regions=True))
data = pipeline.compute()
mesh = data.surfaces['surface']
region_id = 2
face_indices = np.where(mesh.faces["Region"] == region_id)[0]
outer_vertices = mesh.vertices["Position"][np.unique(mesh.get_face_vertices()[face_indices])]
outer_file_path = "/home/leah/RCORE29-SHELL27.5/alfa_{}/outer_region_vertices_{}.csv".format(Alfa, e)
np.savetxt(outer_file_path, outer_vertices, delimiter=',', header='x,y,z', comments='')
Best,
Leah
No, sorry, unfortunately the only solution is to upgrade your OVITO version.
Ok… thank you so much though for your help! <3