Author Topic: Question about output.particle_properties.*.array  (Read 282 times)

Qriver

  • Newbie
  • *
  • Posts: 19
Question about output.particle_properties.*.array
« on: June 30, 2018, 07:45:13 PM »
Hi every one,
In my dump file, there is a particle property called c_pepa, I want to analyze this data, but the wrong is:  AttributeError: DataCollection does not contain the particle property 'c_pepa'.
How can I do with this wrong?
Thank you!
Shuai


Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 516
Re: Question about output.particle_properties.*.array
« Reply #1 on: July 01, 2018, 07:57:57 AM »
Dear Shuai,

The following type of particle property access in a data collection works only for standard particle properties but not for user-defined properties:
Code: [Select]
output.particle_properties.c_pepa
Instead, for user-defined properties, you have to use the normal dictionary-based lookup approach (which will become mandatory for standard properties as well in Ovito 3.0):
Code: [Select]
output.particle_properties['c_pepa']

See the documentation of the DataCollection class.

Furthermore, you are working with a user-defined modifier function in your script. I noticed that your definition of the modify() function is not quite correct (but it probably works anyhow after fixing problem 1 described above). Modifier functions should, under normal circumstances, be pure (=stateless and deterministic) functions that do not access any scene objects that exists outside of the function. They should only access data that is being passed to them by the system via the input function parameter. Thus, you should change the reference to the external node.output field to the input data collection of the modifier function, i.e.:
Code: [Select]
def modify(frame, input, output):
    output.attributes['b'] = np.sum(input.particle_properties['c_pepa'].array)

-Alex
« Last Edit: July 01, 2018, 07:59:56 AM by Alexander Stukowski »

Qriver

  • Newbie
  • *
  • Posts: 19
Re: Question about output.particle_properties.*.array
« Reply #2 on: July 01, 2018, 09:13:32 PM »
Hi Alexander,

Thank you for your help!

Shuai