Forum Navigation
You need to log in to create posts and topics.

cluster size

Hi Constanze, Hi Alex,

would it be possible to also return the cluster size as a per atom value from the cluster modifier? Sometimes I just want to color specific types of molecules or delete cluster smaller than a specific size. This would come in really handy in the pipeline. I know that one can sort the clusters by size, but especially in the first case an "expression selection" by cluster size would be nice. 

Or maybe I just oversaw sth again. In that case, I'd be glad if you could point out to me. 

Regards

Wolfgang

Hi Wolfgang,

you can use the particle property "Cluster", that tells you the Cluster-Id to which each particle belongs, to look up the Cluster Size from the list of clusters that appears under Data Tables in the Data Inspector and save that as a custom particle property.

If you like you can try the following python script modifier in the GUI:

from ovito.data import *
import numpy as np
def modify(frame, data):
    #Get the cluster size list data table
    cluster_sizes = data.tables['clusters'].y
    #Create a new particle property Cluster size
    cluster_size_pp = data.particles_.create_property("Cluster Size", data=cluster_sizes[data.particles["Cluster"] - 1])

 

Best,

Constanze

Hi Constaze,

works like a charm. Thanks

Wolfgang

Hi Constanze,

I am using Ovito Pro 3.0, and I first run cluster analysis and then sort cluster by size. When I was trying to use the above code to compute cluster size, the following error popped up:

The Python script has exited with an error.
Traceback (most recent call last):
File "<string>", line 5, in modify
AttributeError: 'PyScript.DataCollection' object has no attribute 'tables'

Could you help me look into this problem? Thank you.

Take care,

Han

 

Hi Han,

Access to the cluster statistics through the python scripting interface didn't exist yet in OVITO 3.0, this is why you see this error message. You will need to update and license your OVITO Pro version.

Hi Constanze,

I'm using python environment (Not GUI) and I have a small issue related to this topic.

I want to export the aforementioned cluster list, to simply overlook small clusters later (let's say to keep those which contain more than 3 atoms). Can you let me know how I can select and delete such clusters?

Thanks a million in advance!

P.S I also add my python code for you and others to check and enjoy!

def ClusterFinder(DumpFileAddress_V, WriteOvitoDump_V = False):
    DumpFilePath = os.path.dirname(os.path.abspath(DumpFileAddress_V))
    DumpFileName = os.path.splitext(os.path.basename(DumpFileAddress_V))[0]
    pipeline = import_file(DumpFileAddress_V,columns=["id", "type", "Position.x", "Position.y", "Position.z", "c_peng", "c_keng", "c_eng"])

    pipeline.modifiers.append(CreateBondsModifier(cutoff=3.2))
    pipeline.modifiers.append(CommonNeighborAnalysisModifier(mode=CommonNeighborAnalysisModifier.Mode.AdaptiveCutoff))
    pipeline.modifiers.append(ExpressionSelectionModifier(expression='StructureType==2'))
    pipeline.modifiers.append(DeleteSelectedModifier())
    pipeline.modifiers.append(ClusterAnalysisModifier(
        neighbor_mode=ClusterAnalysisModifier.NeighborMode.Bonding,
        cutoff=3.2,
        sort_by_size=True,
        compute_com=True,
        compute_gyration=True,
        cluster_coloring=True))
    Data = pipeline.compute()

    # print(list(Data.particles.keys()))

    #Cluster Size
    cluster_sizes = Data.tables['clusters'].y   # Get the cluster size list data table
    Data.particles_.create_property("ClusterSize", data=cluster_sizes[Data.particles["Cluster"] - 1])     # Create a new particle property Cluster size
    # print(list(Data.particles.keys()))


#THIS IS THE PART WHICH BAFFLES ME!

    # Data.modifiers.append(ExpressionSelectionModifier(expression='ClusterSize < 3')) 
    # Data.modifiers.append(DeleteSelectedModifier())

    #Numpy Export
    ClusterSize = Data.particles['ClusterSize']
    # print('ClusterSize is: ', ClusterSize[:])
    ID = Data.particles['id']
    # print('ID is: ', ID[:])
    Positions = Data.particles['Position']
    # print('Position is: ', Positions[...])
    Cluster = Data.particles['Cluster']
    # print('Cluster is: ', Cluster[:])

    if WriteOvitoDump_V:
        OutputFile = DumpFilePath + "/" + DumpFileName + ".OvitoDump"
        export_file(Data, OutputFile, "lammps/dump", columns=['id', 'type', 'Position.X', 'Position.Y', "Position.z", "c_peng", "c_keng", "c_eng", "Cluster",'ClusterSize'])

 


 

Hi,

I think there's a misconception about how OVITO pipeline systems works, please let me refer you to: https://www.ovito.org/docs/current/python/introduction/pipelines.html

You shouldn't call pipeline.compute() before you are done adding all modifiers to your pipeline. In your script, Data is a DataCollection object - not a pipeline.

You can delete lines 17 - 41 and instead append the custom modifier I had posted above to your pipeline and subsequently the Expression Selection and Delete Selected modifiers. You can then pass the pipeline to OVITO's export_file() function - it is automatically evaluated for you and the output of this pipeline is exported as a dump file.

新的OVITO微信频道!
New for our users in China: OVITO on WeChat 

Official OVITO WeChat channel operated by Foshan Diesi Technology Co., Ltd.