Author Topic: cluster size through WS analysis  (Read 53 times)

ludo

  • Newbie
  • *
  • Posts: 2
cluster size through WS analysis
« on: March 04, 2019, 01:21:42 PM »
Dear all, this is my Python script to determine the number of particles for each cluster.

The program, when started on Scripting-->run Python script doesn't crush or give error, but when I read the written file it is completely empty.

This is the script

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


node = import_file("C:/Users/lbuongio/Desktop/LAMMPS/Work/TestCascade_Bonny/cascade.*.dump.gz",multiple_frames = True)

mod = WignerSeitzAnalysisModifier()
mod.reference.load("C:/Users/lbuongio/Desktop/LAMMPS/Work/TestCascade_Bonny/config.dat.gz")
node.modifiers.append(mod)
node.modifiers.append(SelectExpressionModifier(expression ='Occupancy==0'))
node.compute()
#print("notOccupancy = %i" %node.output.attributes['SelectExpression.num_selected'])
node.modifiers.append(InvertSelectionModifier())
node.compute()
node.modifiers.append(DeleteSelectedParticlesModifier())
node.compute() 
#print("remaining = %i" %node.output.attributes['SelectExpression.num_selected'])
#export_file(node, "C:/Users/lbuongio/Desktop/LAMMPS/Work/TestCascade_Bonny/pray.txt", "txt", columns=["Timestep", "SelectExpression.num_selected"], multiple_frames=True)
select_vacancies_mod = node.modifiers.append(SelectExpressionModifier(expression ='Occupancy==0'))
node.compute(select_vacancies_mod )
# Cluster vacancies
node.modifiers.append(ClusterAnalysisModifier(cutoff = 2.2,sort_by_size = True, only_selected=True))
#data = node.compute()

data = node.compute()

cluster_sizes = numpy.bincount(data.particle_properties['Cluster'])
numpy.savetxt("C:/Users/lbuongio/Desktop/LAMMPS/Work/TestCascade_Bonny/cluster_sizes.txt", cluster_sizes)

Can someone tell me, please, if I am using all the commands correctly?

Sincerely
LB
Modify message
« Last Edit: March 05, 2019, 09:32:33 PM by Alexander Stukowski »

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 577
Re: cluster size through WS analysis
« Reply #1 on: March 05, 2019, 09:45:21 PM »
Hi LB,

The only "mistake" I can spot in your script is in this part:

Code: [Select]
select_vacancies_mod = node.modifiers.append(SelectExpressionModifier(expression ='Occupancy==0'))
node.compute(select_vacancies_mod )

The modifiers.append() method doesn't return anything which could be assigned to a variable. Neither does the node.compute() method accept a modifier as an argument. So you probably should just do:

Code: [Select]
select_vacancies_mod = SelectExpressionModifier(expression ='Occupancy==0')
node.modifiers.append(select_vacancies_mod)
node.compute()

By the way, there is no need to repeatedly call node.compute() in between adding modifiers to the pipeline. It's sufficient to call it just once at the very end once the pipeline has been completely set up and when you want to retrieve the final results.

I'm not sure why you are not getting any output. Perhaps the sequence of modifiers ends up deleting all particles for some reason? Have you already tried running your script via the "ovitos" interpreter from the command line (instead of from within Ovito)? This approach has the advantage that you can add print() statements to your program to write information and intermediate results to the console.

-Alex