OVITO Forum

OVITO => Support Forum => Topic started by: Kevin on February 13, 2018, 04:49:58 AM

Title: How to calculate max and min of cluster's position
Post by: Kevin on February 13, 2018, 04:49:58 AM
Hello everyone,

I figured out this problem after writing all the question and right before submitting it,
but I will just post this anyways with the working code in case someone finds helpful.

Following is the code that identifies a cluster of HCP atoms, extracts only the atoms in the cluster, and calculates maximum and minimum x-position of this cluster.

Essentially I was trying to find the stackingfault width of a dissociated dislocation.

Code: [Select]
from ovito.io import *
from ovito.modifiers import *
import numpy

node = import_file("dump.200.*",
                   multiple_frames = True)
# Modifiers                                                                                                 
# Modifier 1: CNA                                                                                           
node.modifiers.append(CommonNeighborAnalysisModifier())

# Modifier 2: Select HCP (dislocation)                                                                     
node.modifiers.append(SelectExpressionModifier
                      (expression = 'StructureType==2'))
# Modifier 3: Cluster HCP                                                                                   
node.modifiers.append(ClusterAnalysisModifier
                      (cutoff=3.5,
                       only_selected = True))
# Modifier 4: Select cluster 0, which doesn't belong to any cluster.                                                                           
node.modifiers.append(SelectExpressionModifier
                      (expression = 'Cluster==0'))
# Modifier 5: Delete cluster 0                                                                                       
node.modifiers.append(DeleteSelectedParticlesModifier())

#Each particle's Position.X in addition to cluster id                                                                   
#can be outputted to xyz format file as follows:                                                           
export_file(node, "1xyz", "xyz",
            columns = ["Cluster", "Position.X"])

# BUT, I wanted to have access to position data in this script level
# to calculate Min and Max values of Position.X
# All particle_properties that belong to 'deleted_particles' seem
# to get deleted
data = node.compute()
cluster = data.particle_properties['Cluster'].array #this is not necessary
pos = data.particle_properties['Position'].array
xpos = pos[:,0]
leading = max(xpos)
trailing= min(xpos)


PS. Just in case someone new to OVITO finds this post and is trying to understand better way of manipulating clustering feature, I found the following post helpful:
http://forum.ovito.org/index.php?topic=118.msg222#msg222
(Note that the post was written 2017 Feb, and note the version of OVITO by then.)
Title: Re: How to calculate max and min of cluster's position
Post by: Alexander Stukowski on February 13, 2018, 09:20:46 AM
Hi Kevin,

Thank you for sharing the solution to your own problem. I hope you don't mind if I comment on your script. I agree with the way you determine the size of the stacking fault. But I am wondering if the sequence of 5 modifiers is really necessary to extract the SF atoms. In my eyes, the ClusterAnalysisModifier is not necessary. You could have directly deleted all non-HCP atoms as follows:

Code: [Select]
# Modifier 1: CNA                                                                                           
node.modifiers.append(CommonNeighborAnalysisModifier())
# Modifier 2: Select non-HCP atoms                                                                 
node.modifiers.append(SelectExpressionModifier(expression = 'StructureType!=2'))
# Modifier 3: Delete them                                                                                   
node.modifiers.append(DeleteSelectedParticlesModifier())

A ClusterAnalysisModifier would only be necessary if there are several independent HCP atom clusters in your system and you want to focus on a particular one of them, perhaps the largest one. Then, however, you should make use of the ClusterAnalysisModifier.sort_by_size (http://ovito.org/manual/python/modules/ovito_modifiers.html#ovito.modifiers.ClusterAnalysisModifier.sort_by_size) option and delete all atoms with property Cluster!=1.

Best regards
-Alex
Title: Re: How to calculate max and min of cluster's position
Post by: Kevin on February 13, 2018, 06:41:08 PM
Yes definitely, it's always nice to have someone look at my code.

Yes, I don't know why I decided to use clustering when there is going to be only 1 cluster. Thanks for pointing that out.

-Kevin
Title: Re: How to calculate max and min of cluster's position
Post by: Kevin on February 14, 2018, 09:00:46 PM
I just wanted to add why I decided to add clustering feature when identifying stackingfault width.
This was a safety feature that will exclude some of the HCP structures randomly appearing from thermal fluctuation.

-Kevin