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

Can't exports create_property by export file

Hello everyone.

I write the code to create my property.
But I got an error while I exported the IMD file.

At first, I have three nodes. (node, node1, node2)
I use node one and node 2 to calculate the property value and combine them to a property for a node to export.
The code is shown below :

for frame_index in range(node.source.num_frames):
#calculate is a function to compute property and return a list
    calculate_1 = calculate(frame_index, node_1.compute(frame_index), ref_list_1)
    calculate_2 = calculate(frame_index, node_2.compute(frame_index), ref_list_2)
    calculate_list = calculate_1+calculate_2
    data = node.compute(frame_index)
    data.particles_.create_property('Variant', data = calculate_list)
    f = open('file,'w')
    export_file(node, 'file', 'imd',columns = ['Particle Identifier','Particle Type','Position','Variant'],frame = frame_index)

The error message : RuntimeError: The specified list of output file columns is invalid. The property 'Variant,' which is needed to write file column 6, does not exist or could not be computed.

I watch the method to export my property in documentation. Its parameter only frame & data, but I have three nodes, and the calculate list will change with a different frame.
Have anyone can tell me how to export my property? Thanks.

Hello Eason,

with the short example you provided above I have no way of verifying that your functions calculate_1 and calculate_2 work the way there supposed to and that the particle property 'Variant' is properly created. However, given that that is the case, it should be enough to change your export function to this:

export_file(data, 'file_{}'.format(frame_index), 'imd',columns = ['Particle Identifier','Particle Type','Position','Variant'],frame = frame_index)

where you replace node with data and also include the frame number in the file name, otherwise you would overwrite it with each file export.

Also you should remove these two'file', w) and f.close()since they are not needed.
Does that solve your problem?



Hello Constanze,

I think calculate_list  works well. Because I print it and see the correct result.
I also include the frame number in the file name.
But I still meet the same problem. I think the problem is in create_property.
How should I verify create_property is work?


Hello Eason,

as an example, let's say calculate_list was a list of ones. Then the following should work without problems:

import ovito
from import import_file, export_file
import numpy as np

node = import_file("your-file")

for frame_index in range(node.source.num_frames):
                data = node.compute(frame_index)
                calculate_list = np.ones(len(data.particles["Particle Identifier"]))
                data.particles_.create_property('Variant', data = calculate_list)
                export_file(data, 'file_{}'.format(frame_index), 'imd', columns = ['Particle Identifier','Particle Type','Position','Variant'], frame = frame_index)

Can you try this and report back if this minimal example works for you?


Hello Constanze,

I run your small case. And it is work!
So I restart to check my calculate_list, I ensure the length of calculate_list is correct.
Do I need to transform the calculate_list to array from the list?

No that should not be necessary. Let me know how it goes.

Hello, Constanze

I find why the error happened.
I type the export_file(node) to replace the export_file(data).It causes the error.
But the examples in documentation type the export_file(pipeline). What's different? Because the property is assigned to data, not to node?


Hello Eason,

yes, exactly, the keyword "node" needs to be replaced by "data" in your case. In your script the particle property "Variant" does not exist in every frame yet  when you're trying to call export_file(node) and this is why this fails. It is sufficient to only pass the DataCollection "data" which is returned by node.compute() and manipulated by you in the for-loop.

By the way, the export_file() function can export many different types of data objects, not only a pipeline object, see manual


New for our users in China: OVITO on WeChat 

Official OVITO WeChat channel operated by Foshan Diesi Technology Co., Ltd.