How to provide minimum cluster size in lammps?

I want to calculate cluster sizes for a box of particles using the following method:

Compute cluster IDs for atoms

compute myCluster all cluster/atom 0.9

Define chunks based on cluster IDs

compute myChunks all chunk/atom c_myCluster compress yes

Compute the number of atoms in each chunk

compute sizeChunks all property/chunk myChunks count

fix chunkSizes all ave/time 10000 1 10000 c_sizeChunks file chunk_sizes.dat mode vector

However as LAMMPS documentation said,

A cluster is defined as a set of atoms, each of which is within the cutoff distance from one or more other atoms in the cluster. If an atom has no neighbors within the cutoff distance, then it is a 1-atom cluster.

I want to discard one atom clusters. More precisely I want to define cluster only if number of particles(N) in cluster becomes more than a cutoff (say, N>10).

LAMMPS version: 2023

Well, couldn’t you just ignore all entries “1” in the output file when you’re post-processing it?

In principle, yes. That works perfectly.

On the other hand, what I am trying to implement is to dynamically achieve a predefined cluster:free ratio by varying LJ pair interaction strength iteratively.

A post-processing dependent method would require multiple rerun of LAMMPS script. I am curious if there is a smart way to get it in a single LAMMPS run.

After computing the size of the clusters, you can use the compute chunk/spread/atom command — LAMMPS documentation to turn the size of the cluster into a per-atom property. Next step is to define an atom style variable that computes a comparison of whether this number of larger that the threshold that you want. That variable will have the value 0 for atoms that are in smaller clusters and 1 for atoms that are in larger clusters.
For that variable you can do a compute reduce sum to get the count of the atoms in the larger clusters.
Finally, the ratio of the this reduction with the total number of atoms will give you the ration you are asking for. This can be computed with an equal style variable.

So it is quite tedious and requires careful debugging, but it should be possible.