Author Topic: Coordination Analysis using Python Scripting Interface  (Read 1258 times)

jhart

  • Newbie
  • *
  • Posts: 22
Coordination Analysis using Python Scripting Interface
« on: March 10, 2017, 08:21:58 PM »
Hello:

I am trying to use the python scripting interface to perform coordination analysis on all my time steps. I want to output this property.

I keep getting many errors, most recently that Coordination is not defined.

Can someone take a quick look at my script and point out the problem?

I want to select particles of type 1 and coordination of 1 and output that as O1
Then type 1 and coordination of 3 etc.


Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638
Re: Coordination Analysis using Python Scripting Interface
« Reply #1 on: March 11, 2017, 07:28:46 PM »
Hi,

here is a script that hopefully does what you want. It counts and exports the number of particles of type 1 that have exactly one neighbour within the given cutoff radius.

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

node = import_file("coordination.dump", multiple_frames = True)

# Calculate coordination numbers:
modifier = CoordinationNumberModifier(cutoff=2.0)
node.modifiers.append(modifier)

# Add a user-defined modifier that counts the number of particles of type 1
# and which have a coordination equal to 1.
def count_coordinated_particles(frame, input, output):
selection1 = (input.particle_properties['Particle Type'].array == 1) & (input.particle_properties['Coordination'].array == 1)
output.attributes['O1'] = np.count_nonzero(selection1)

# Insert Python modifier into the data pipeline.
node.modifiers.append(PythonScriptModifier(function = count_coordinated_particles))

# Let OVITO do the computation and export the calculated numbers as a function
# of simulation time to a text file:
export_file(node, "coordination.txt", "txt",
    columns = ['Timestep', 'O1'],
    multiple_frames = True)