Rotate a single frame

I am using OVITO’s python module, and would like to use the render_anim() function to animate the rotation of a single frame. How do I go about achieving that?

There is a OVITO GUI tutorial that handles your question.

There is also a corresponding Python example slightly hidden here in the TurntableAnimation(ModifierInterface) class.

These should give you a good starting point for your script.

1 Like

Thanks for that!

This is how I’m doing it right now:

from ovito.modifiers import AffineTransformationModifier

total_frames = 12

def rotate_system(frame, data):

    angle = 2 * np.pi * (frame / total_frames)

    center = np.mean(data.particles.positions, axis=0)

    cos_a = np.cos(angle)
    sin_a = np.sin(angle)

    R = np.array([
        [cos_a, -sin_a, 0],
        [sin_a,  cos_a, 0],
        [0,      0,     1]
    ])

    offset = center - np.dot(R, center)

    matrix = [
        [cos_a, -sin_a, 0, offset[0]],
        [sin_a,  cos_a, 0, offset[1]],
        [0,      0,     1, offset[2]]
    ]

    data.apply(AffineTransformationModifier(transformation=matrix))

pipeline.modifiers.append(rotate_system)
pipeline.compute()

vp.render_anim(
    size=(1500, 1500),
    filename=f"abc.mp4",
    background=(0,0,0),
    renderer=TachyonRenderer(),
    fps=1,
    ffmpeg_executable='/usr/bin/ffmpeg',
    ffmpeg_codec='libx265',
    ffmpeg_quality='low',
    range=(0, total_frames - 1)
)

I guess using it by defining it as a class and actually creating a trajectory/timeline of the frames is better?

Having it as a modifier class definitely helps OVITO handle caching of intermediate results and prefetching of data from disk, which can make pipeline evaluation faster and more efficient.

So I would say that when starting a new project, developing a modifier class is the better approach.

1 Like