Python ovito.gui - set background color and renderer

Hi,

I’m again impressed what is currently possible with ovito-python. Currently, I’m trying to write a simple standalone LAMMPS trajectory viewer based on the example B4. This is based on ovito.gui.create_qwidget().
It’s working well so far, I managed to implement atom sizes, atom colors, polyhedron rendering.

What I didn’t accomplish is:

How to set the background color for the viewport?
It doesn’t work like this:

vp_widget = ovito.gui.create_qwidget(vp)
vp_widget.background_color = (0.5, 0.5, 0.5)  # gray background? not working
central_layout.addWidget(vp_widget, 1)

Furthermore, it appears to work in default OpenGL rendering mode. How do I set the anari renderer? I tried something like this:

anari = AnariRenderer( # how to invoke correctly?
   [...]
)
def on_time_slider(frame: int):
    ovito.scene.anim.current_frame = frame
    # ovito.scene.anim.renderer= anari  # --> this  is not working

I would really appreciate if you could help me out.

There’s another observation. In my system, if I move the slider “fast”, the images rendered immediately during the movement are rendered in a “default” style (with atoms in CPK-like style) and after a split second - my defined style is then rendered.

Thank you!

Hi, I’m afraid I can only give you bad news in response:

Setting the background color of interactive viewport windows is currently not possible with Python. This is an aspect managed by the ViewportSettings C++ class, which hasn’t been exposed in the Python API yet.

The create_qwidget() function is currently hardcoded to create a viewport window with an OpenGL interactive renderer.

Regarding your last question: For interactive viewports, OVITO uses a progressive display method during pipeline evaluation. If the pipeline contains a long-running modifier, the viewport temporarily displays still incomplete, intermediate pipeline results. A Python modifier function in the pipeline always counts as “long-running”, as OVITO cannot know or predict how long the user function will take. This is why you can see the state from before the Python function for a brief moment in the viewport.