Forum Navigation
You need to log in to create posts and topics.

Multiframe xyz: overlay with changing opacity

Hi guys,

 

quick question: I have a multi-frame xyz file (basically a trajectory). I want the first and last frame rendered at full opacity but every frame in between at increasingly lower opacity; then I want the overlay of all these frames as graphics file. I used to do this using jmol which can assign a transparency to every frame but I can't figure out who to do this with ovito(s)?

 

Thanks in advance!
Chris

Hi Chris,

I see two ways to go about this:

1)

You could use the Compute Property modifier to gradually ramp up or down the Transparency property value of all particles (see also here).  The user-defined formula for calculating the transparency values can refer to the time-dependent Frame input variable. Furthermore, if you are going to superimpose the rendered images, make sure you set the background to transparent in the render settings panel of OVITO.

However, I doubt that this approach will give you good results, because the effective level of semi-transparency that you get will depend on the number of overlapping atoms. You will get areas which are more or less transparent, depending on how "thick" the atomic structure is in that region.

2)

Perhaps it makes more sense to change the alpha value of the rendered image as a whole. There is no built-in function that would allow you to do that. But the Python programming interface, specifically the Viewport.render_image() function, gives you access to a rendered image before it gets written to disk, and you can manipulate its alpha value. Here is a fragment of a Python script (for ovitos) that demonstrates what I mean:

# Trajectory rendering loop over all frames of the loaded animation:
for frame in range(pipeline.source.num_frames):

    # Render the current frame.
    print("Rendering frame", frame)
    img = vp.render_image(size = (400,400), frame=frame)

    # Compute alpha value for current frame.
    alpha = 1.0 - frame / pipeline.source.num_frames

    # Replace alpha channel of rendered image.
    alpha_img = QImage(img.size(), QImage.Format_Alpha8)
    alpha_img.fill(QColor.fromRgbF(1,1,1,alpha))
    img.setAlphaChannel(alpha_img)

    # Write rendered image to an output file. 
    img.save('frame%i.png' % frame)

This for-loop produces are series of PNG image files, each with a different uniform alpha value. Of course, it would also be possible do compose all images into one final result image directly in the script before writing it to disk, if this is what you have in mind.

-Alex