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

How to export the number of different atoms?

Hi,

I want to export the number of different atoms in the selected atoms, but I do not know how to do it.

from ovito.io import *
from ovito import dataset
from ovito.modifiers import *
from ovito.data import *
import numpy as np
import math

node = import_file('D:/Science data/NiAlCu/Dump_File/dump.190000')
node.modifiers.append(PolyhedralTemplateMatchingModifier())

node.modifiers.append(SelectExpressionModifier(expression = 'ParticleIdentifier == 123763 || ParticleIdentifier == 214839 || ParticleIdentifier == 312201 || ParticleIdentifier == 142980 ||ParticleIdentifier == 273790 || ParticleIdentifier == 225157 || ParticleIdentifier == 163231 || ParticleIdentifier == 165975 ||ParticleIdentifier == 144013 || ParticleIdentifier == 183804 || ParticleIdentifier == 212371 || ParticleIdentifier == 224394 ||ParticleIdentifier == 234345 || ParticleIdentifier == 265391 || ParticleIdentifier == 232208 || ParticleIdentifier == 275171 ||ParticleIdentifier == 184179 || ParticleIdentifier == 196198 || ParticleIdentifier == 225781 || ParticleIdentifier == 224626 ||ParticleIdentifier == 173967 || ParticleIdentifier == 252814 || ParticleIdentifier == 245596 || ParticleIdentifier == 224977 ||ParticleIdentifier == 183627 || ParticleIdentifier == 252234 || ParticleIdentifier == 265386 || ParticleIdentifier == 255168 || ParticleIdentifier == 294217'))
node.modifiers.append(ExpandSelectionModifier(cutoff = 3.5))
node.modifiers.append(ExpandSelectionModifier(cutoff = 3.5))
node.modifiers.append(InvertSelectionModifier())
node.modifiers.append(DeleteSelectedParticlesModifier())
node.modifiers.append(SelectExpressionModifier(expression = 'ParticleIdentifier == 123763 || ParticleIdentifier == 214839 || ParticleIdentifier == 312201 || ParticleIdentifier == 142980 ||ParticleIdentifier == 273790 || ParticleIdentifier == 225157 || ParticleIdentifier == 163231 || ParticleIdentifier == 165975 ||ParticleIdentifier == 144013 ))
node.modifiers.append(InvertSelectionModifier())
node.modifiers.append(DeleteSelectedParticlesModifier())
node.compute()

print(np.count_nonzero( ParticleType == Type 1))
print(np.count_nonzero( ParticleType == Type 2))
print(np.count_nonzero( ParticleType == Type 3))

 

Uploaded files:
  • Export_number_of_different_atoms.PNG

Hi Shuai,

you should modify the last 4 lines to:

data = node.compute()
ptype = data.particles["Particle Type"]
print(np.count_nonzero(ptype == 1))
print(np.count_nonzero(ptype == 2))
print(np.count_nonzero(ptype == 3))

-Constanze

Hi Constanze,

Thank you for your help!

Shuai