### Author Topic: calculate average displacement vector in bins  (Read 667 times)

#### ckt624

• Newbie
• Posts: 1
##### calculate average displacement vector in bins
« on: June 03, 2018, 03:42:18 AM »
Hi! I want to divide the system into 200 bins in the y-direction and calculate average displacement vector in each bin.

My code:

Code: [Select]
`# Import OVITO modules.import ovitoimport sysimport numpy# Load the simulation dataset to be analyzed.node = ovito.io.import_file("/mnt/io1/home/kongtao/ShearCoupling_revisit/600K1000bar0ev310/310.600.1000.0.0.cfg")x_displacement = ovito.modifiers.CalculateDisplacementsModifier()x_displacement.reference.load("/mnt/io1/home/kongtao/ShearCoupling_revisit/600K1000bar0ev310/310.600.1000.0.0.cfg")node.modifiers.append(x_displacement)node.modifiers.append(ovito.modifiers.CentroSymmetryModifier())centrol_symmetry_y = ovito.modifiers.BinAndReduceModifier(direction = ovito.modifiers.BinAndReduceModifier.Direction.Vector_2, property = ovito.data.ParticleProperty.Type.CentroSymmetry, bin_count_x = 200)x_displacement_along_y = ovito.modifiers.BinAndReduceModifier(direction = ovito.modifiers.BinAndReduceModifier.Direction.Vector_2, property = ovito.data.ParticleProperty.Type.Displacement.X, bin_count_x = 200)z_displacement_along_y = ovito.modifiers.BinAndReduceModifier(direction = ovito.modifiers.BinAndReduceModifier.Direction.Vector_2, property = ovito.data.ParticleProperty.Type.Displacement.Y, bin_count_x = 200)node.modifiers.append(centrol_symmetry_y)node.modifiers.append(x_displacement_along_y)node.modifiers.append(z_displacement_along_y)node.compute()with open("/mnt/io1/home/kongtao/ShearCoupling_revisit/600K1000bar0ev310/310.600.1000.0.0.centrosymmetry.txt", 'w') as fout:    for i in range(len(centrol_symmetry_y.bin_data)):        fout.write(str(centrol_symmetry_y.axis_range_x[0] + (centrol_symmetry_y.axis_range_x[1] - centrol_symmetry_y.axis_range_x[0]) / (len(centrol_symmetry_y.bin_data) - 1) * i) + ' ' + str(centrol_symmetry_y.bin_data[i]) + "\n")with open("/mnt/io1/home/kongtao/ShearCoupling_revisit/600K1000bar0ev310/310.600.1000.0.0.displacement.txt", 'w') as fout:    for i in [0, len(x_displacement_along_y.bin_data) // 4, len(x_displacement_along_y.bin_data) // 4 * 3, len(x_displacement_along_y.bin_data) - 1]:        fout.write(str(x_displacement_along_y.axis_range_x[0] + (x_displacement_along_y.axis_range_x[1] - x_displacement_along_y.axis_range_x[0]) / (len(x_displacement_along_y.bin_data) - 1) * i) + ' ' + str(x_displacement_along_y.bin_data[i]) + ' ' + str(z_displacement_along_y.bin_data[i]) + '\n')`However, when I try to run ovitos 2.8.1, it says that AttributeError: 'Particles.Type' object has no attribute 'X'.
If I replace ovito.data.ParticleProperty.Type.Displacement.X with ovito.data.ParticleProperty.Type.Displacement, it works, but it's a scaler rather than a displacement vector.
What's wrong?
« Last Edit: June 03, 2018, 10:25:40 AM by Alexander Stukowski »

#### Alexander Stukowski

• Hero Member
• Posts: 638
##### Re: calculate average displacement vector in bins
« Reply #1 on: June 03, 2018, 10:37:49 AM »
Hi,

For referring to a particle property, for example when setting the input of the Bin and Reduce modifier, the scripting interface provides two ways. The first is to make use of the predefined enum constants, e.g.
Code: [Select]
`ovito.data.ParticleProperty.Type.Displacement`The second method is to refer to a property by name using a Python string:
Code: [Select]
`"Displacement"`A table with enum constants for all the standard properties and the corresponding property names is found here. However, as you noted, the enum constants do not allow you to select individual components of a vector property. That means you can use this notation only in places where a reference to a particle property as a whole is needed. The string-based notation, in contrast, lets you select individual vector components, e.g.
Code: [Select]
`"Displacement.X"`So in the present case this would be the way to go.

-Alex