Export mulitple_frames with custom property arrays

I was trying to export the trajectory with additional properties, while doing I have to do it frame by frame, is it possible to do it in single trajectory (multi-frame) file?

following is the code

#voxel and lbl is a  [n,3] array (n is number of atoms in each frame)

for iframe in range(traj.source.num_frames):
    dc = traj.compute(iframe)
    dc.particles_.create_property('d', data=np.array(voxel)[iframe], dtype=float, components=3)
    dc.particles_.create_property('s', data=np.array(lbl)[iframe], dtype=float, components=3)
    export_file(dc, f"ap/trajec_xyz/traj_{iframe}.xyz", "xyz", columns =["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z", "d.0", "d.1", "d.2", "s.0", "s.1","s.2"])

I also tried with

export_file(dc, f"ap/trajec_xyz/traj_{iframe}.xyz", "xyz", columns =["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z", "d.0", "d.1", "d.2", "s.0", "s.1","s.2"], mutiple_frame=True)

but output is not as expected

It would be best to create the particle properties within the scope of a Python script modifier function, which you then append to the pipeline. That way you can invoke the export_file function like this:

export_file(traj, "ap/trajec_xyz/traj_*.xyz", "xyz", columns =["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z", "d.0", "d.1", "d.2", "s.0", "s.1","s.2"], multiple_frames = True)

to evaluate the complete trajectory and export the results. Have a look at this more detailed introduction to the topic here: User-defined modifiers — OVITO Python Reference 3.9.2 documentation.

I tried above method to write a single array using of shape (55550, ) and also by reshaping to (55550, 1)

using

data.particles_.create_property('type_Y', data=(np.array(type_Y))[frame], dtype=int)
 
and also by 

data.particles_.create_property('type_Y', data=(np.array(type_Y).reshape(-1,1))[frame], dtype=int, component=1)

and export with

export_file(data, f"ap/trajec_xyz/traj_{iframe}.xyz", "xyz", columns =["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z", "type_Y.0"], mutiple_frame=True)

also tried

export_file(data, f"ap/trajec_xyz/traj_{iframe}.xyz", "xyz", columns =["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z", "type_Y"], mutiple_frame=True)

But the same results

I was getting 0 in some frames and some other values in other frames. I’m unable to write a correct array?

It’s difficult to provide a precise answer without access to the entire script. Nonetheless, please note that this assistance is exclusively available to paying customers. If you own an OVITO Pro license key, you are encouraged to reach out to the Pro support team for further help.

This is the script

#type is  [n,1] array (n is number of atoms in each frame)

for iframe in range(traj.source.num_frames):
    dc = traj.compute(iframe)
    dc.particles_.create_property('type', data=np.array(type)[iframe], dtype=int, components=1)

    export_file(dc, f"ap/trajec_xyz/traj_{iframe}.xyz", "xyz", columns =["Particle Identifier", "Particle Type", "Position.X", "Position.Y", "Position.Z", "type.0"])