[Solved] Error when computing relative displacement with Python frame offset

Dear Ovito users,

I am using the following python code to compute displacement between successive lammps dump file.

    pipeline = import_file(datafile)
    Dispmod = CalculateDisplacementsModifier(
        use_frame_offset=True,
    )
    TRAJmod = LoadTrajectoryModifier()
    TRAJmod.source.load(dumpfile)

    pipeline.modifiers.append(TRAJmod)
    pipeline.modifiers.append(Dispmod)

    export_file(pipeline, output, format="txt/attr", columns=["Timestep",
                                                              "AveMSD"],
                multiple_frames=True)

However, with the default value of frame_offset set to -1 in the ReferenceConfigurationModifier, I get the following error when loading the trajectory:

RuntimeError: Export of frame 0 failed, because data pipeline evaluation has failed.
Requested reference frame -1 is out of range. Cannot perform calculation at the current animation time.

So I am guessing that the modifier attempts to look for a -1 frame which obviously does not exist. Is it normal? Is there a way to start the computation at the frame number 1 or does it need a bug fix?

Best regards,
Germain.

Solved my problem myself. The behaviour was triggered by the export_file function which was indeed trying to compute the displacement for frame 0 with regard to frame -1.

I solved it by using the following options:

    export_file(pipeline, output, format="txt/attr",
                columns=["Timestep", "AveMSD"],
                multiple_frames=True,
                start_frame=1,)

Leaving it here in case, sorry for the inconvenience.

1 Like