Timeline Custom Programs

From PyMOLWiki
Jump to navigation Jump to search

Introduction

Programs are animations that occur over a function of time. Before PyMOL3, there were several included programs users could choose from: nutate, rock, roll, etc... For the Timeline, the user can create their own animations as a function of relative time (t).

All information on this page is below subject to change during PyMOL3 beta (and beyond).

Class structure

In order to create a custom program, the only requirements currently is to create a class that contains a method `animate` that contains a single float parameter (t). This parameter represents the relative time within the range of [0, 1] that describes any change of animation or property over time. Programs are represented as clips (rectangle shapes) on a track and must not overlap with any other clip or keyframe on the same subtrack.

class MyCustomProgram:
    def animate(t: float) -> None:
        # ... logic here based on t

and to register this program to PyMOL:

timeline_register_program(program_name: str, program_type: object)

See Timeline_Python_API for more information about this function


Example

class RailLook:
    """
    Example PyMOL Timeline Program
    RailLook will move an object along a curve object while orienting
    itself toward a specified direction given by a target object.
    """
    def __init__(self, track) -> None:
        self.this_object = "_Camera"
        self.curve_object = "Curve01"
        self.target_object = "1obyA"

    def animate(self, t: float) -> None:
        cmd.move_on_curve(self.this_object, self.curve_object, t)
        cmd.look_at(self.target_object, self.this_object)

cmd.timeline_register_program(program_name="rail_look", program_type=RailLook)