Hello I am running this python code with ovito 3.0:
from ovito.io import import_file
from ovito.modifiers import ComputePropertyModifier, SpatialBinningModifier
print(“Total particles:”, data.particles.count)
if ‘T1’ in data.particles:
print(“Sum of T1 (should be number of type 1 atoms):”, data.particles[‘T1’].array.sum())
else:
print(“T1 property not created — check ParticleType availability.”)
Check if spatial binning result exists
if “Spatial binning: T1” in data.grids:
grid = data.grids[“Spatial binning: T1”]
print(grid.field[:, 0, 0]) #
else:
print(" Spatial binning failed: No voxel grid was generated for ‘T1’.“)
print(” Possible reasons: no atoms of type 1, invalid bin range, or missing property.")
And I receive the error:
Available particle properties: KeysView(Particles())
Total particles: 33024
Sum of T1 (should be number of type 1 atoms): 32350.0
Spatial binning failed: No voxel grid was generated for ‘T1’.
Possible reasons: no atoms of type 1, invalid bin range, or missing property.
It computes the property T1 but does not perform binning. I do not know where I am making the mistake
Please take a look at the docs of the SpatialBinningModifier class. When set to SpatialBinningModifier.Direction.Z, the modifier creates a 1-dimensional DataTable object, not a 2- or 3-dimensional VoxelGrid object. This data table can be accessed as follows:
table = data.tables['binning']
z = table['Position'] # z-coordinates of the bins
T1 = table['T1'] # Bin values