Cluster Analysis with selection types

Hello,

I am trying to do cluster analysis for data with two types of particles. I want to get two cluster lists for each type of particle, is that possible, or do I need to do the calculation twice?

It seems there was a post on the forum (https://www.ovito.org/forum/topic/cluster-analysis-for-three-type-of-particles/), but i cant access it, can you help?

I am trying this, but i am getting an error

pipeline = import_file(file,sort_particles=True)
pipeline.modifiers.append(SelectTypeModifier(property = 'Particle Type', types = {'1'}))
pipeline.modifiers.append(ClusterAnalysisModifier(cutoff = 1.12, sort_by_size = True, only_selected = True))
data = pipeline.compute()

The error is

RuntimeError: Data pipeline failure: Modifier 'Select type' reported: Type '1' does not exist in the type list of property 'Particle Type'.

Thank you

Hi,

What are the Particle Type IDs of the particle types in your data set? The error message tells you that the particle type you are trying to select does not exist.

Most likely you have to change this

 types = {'1'}

to this

 types = {1}

in order to select all particles of numeric type 1. Your version looks for a particle type named “1”, which is probably wrong.

Keep in mind that all particles types in OVITO have a numeric ID and, optionally, a name. Only if types have a name, e.g., a chemical symbol, you can select them by listing Python strings in the types set. If the particle types are unnamed, you have to list their numeric IDs (integer values).

1 Like

Thank you it worked.

In python, how can I get the cluster list for each type?

In the software, the cluster analysis with selected particles doesnt color each cluster differently, is it a bug or not implemented?

Have a look at the code example given in the Python reference of the Cluster Analysis Modifier which demonstrates how to access the data table called “Cluster list” in the OVITO desktop application. If you have multiple instances of Cluster Analysis modifiers in your pipeline, their respective python modifiers are called “clusters”, “clusters.2”, etc.

In the software, the cluster analysis with selected particles doesnt color each cluster differently, is it a bug or not implemented?

Possibly you forgot to add a Clear Selection Modifier at the top of the pipeline? Note that in the interactive viewports of the Desktop application, particle selections are highlighted as red particles to be clearly visible at all times.

1 Like

That fixed it, now i can see them.

I know this, but I wanted to do the cluster analysis for each type independently and access the cluster list.
Cluster analysis with selection modifiers will only work on one type, but if i try to apply it again for the second type, it will override the previous cluster list for type one, any fix for this?

Analogous to what you would do in the desktop application, the idea is to use multiple instances of Select Type and Cluster Analysis modifiers. As explained above, several cluster tables will be generated.

Thank you, but this doesn’t work.
It’s true that each cluster modifier has detected the clusters correctly.
But in the Data Tables, if you look at particles of Type 3 (in your example), they will have cluster 0! So I think the 2nd modifier overrode the 1st modifier.

I am trying to achieve this in python, but it will have the same issue (2nd modifier overrides 1st modifier!).

I see, you’re pointing out that each time you perform cluster analysis, the Cluster identifiers assigned to the particles in the clusters begin anew from 1. To address this, one could develop a short tailored Python solution that updates those identifiers that appear in both the cluster list data.tables["clusters"] and the particle property data.particles["Cluster"].

This extent of assistance is what I can provide within the limits of free support. If you have an active OVITO Pro subscription, please reach out via email to request more in-depth guidance.