Hi there,
First, I run Voronoi analysis and generate neighbor bonds, and then common neighbor analysis. After that, I was trying to use the following code to analyze the CNA bond indices generated by “Voronoi analysis” in the Python Script section in Ovito. However, it always shows that “Invalid Python script. It does not define the function named render().” Could you help me look into this problem?
Thank you,
Han
from ovito.data import *
import numpy
def row_histogram(a):
ca = numpy.ascontiguousarray(a).view([(’’, a.dtype)] * a.shape[1])
unique, indices, inverse = numpy.unique(ca, return_index=True, return_inverse=True)
counts = numpy.bincount(inverse)
return (a[indices], counts)
def modify(frame, data):
# Used below for enumerating the bonds of each particle:
bond_enumerator = BondsEnumerator(data.particles.bonds)
cna_indices = data.particles.bonds['CNA Indices']
# Loop over particles and print their CNA indices.
for particle_index in range(data.particles.count):
# Print particle index (1-based).
sys.stdout.write("%i " % (particle_index+1))
# Create local list with CNA indices of the bonds of the current particle.
bond_index_list = list(bond_enumerator.bonds_of_particle(particle_index))
local_cna_indices = cna_indices[bond_index_list]
# Count how often each type of CNA triplet occurred.
unique_triplets, triplet_counts = row_histogram(local_cna_indices)
# Print list of triplets with their respective counts.
for triplet, count in zip(unique_triplets, triplet_counts):
sys.stdout.write("%s:%i " % (triplet, count))
# End of particle line
sys.stdout.write("\n")