Author Topic: How do I change the size of the particles rendered from ovito?  (Read 396 times)

bjcowen

  • Newbie
  • *
  • Posts: 13
I have a multi-million atom system and the cascade is lost to the eye, since the particle sizes are large. Can I Reduce the size of the atoms ( I have 2 atom types) from a python script? In the python script I render images using Tachyon renderer. Just need to figure out how to make particles smaller.

I tried this from the ovito doc pages:

Code: [Select]
atypes = node.source.particle_properties.particle_type.type_list
atypes[0].radius = 1.35     
atypes[1].radius = 1.55       

But I get the error:

  File "render.py", line 19, in <module>
    atypes = pipeline.source.particle_properties.particle_type.type_list
AttributeError: 'ovito.plugins.PyScript.FileSource' object has no attribute 'particle_properties'

My entire input script is:

Code: [Select]
from ovito.io import *
from ovito.vis import *
from ovito.modifiers import *
from math import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

pipeline = import_file("../sputter.xyz")
pipeline.add_to_scene()

# Turn off cell display:
pipeline.get_vis(SimulationCellVis).enabled = False

bar_length = 100 # Simulation units (e.g. Angstroms)
bar_color = QColor(0,0,0)
label_text = "{} nm".format(bar_length/10)
label_color = QColor(255,255,255)

atypes = pipeline.source.particle_properties.particle_type.type_list
atypes[0].radius = 0.5        # Cu atomic radius (atom type 1 in input file)
atypes[1].radius = 0.6        # Zr atomic radius (atom type 2 in input file)

# Define the overlay function, which renders the scale bar:
def render_overlay(args):
    # Compute length of bar in screen space
    screen_length = args.project_size((0,0,0), bar_length)

    # Define geometry of bar in screen space
    height = 0.05 * args.painter.window().height()
    margin = 0.02 * args.painter.window().height()
    rect = QRectF(308,1300, screen_length, height)

    # Render bar
    args.painter.fillRect(rect, bar_color)

    # Render text label
    font = args.painter.font()
    font.setPixelSize(height)
    args.painter.setFont(font)
    args.painter.setPen(QPen(label_color))
    args.painter.drawText(rect, Qt.AlignCenter, label_text)

# Create a viewport and install overlay function:
vp = Viewport()
vp.overlays.append(PythonViewportOverlay(function=render_overlay))
# This selects a parallel projection with viewing direction along -Z axis:
vp.type = Viewport.Type.TOP
# Adjust camera pos and FOV automatically:
vp.zoom_all()
# Alternatively, set parameters explicitly:
#vp.camera_pos = (251.497,251.551,550.188)
#vp.fov=100

# Set up renderer
renderer = TachyonRenderer()

# Now render the frames, one by one:
for frame in range(pipeline.source.num_frames):
    print("Rendering frame", frame)
    vp.render_image(frame=frame, size=(1920,1440), filename="t"+str(frame)+".png", renderer=renderer)

Thanks
« Last Edit: June 20, 2018, 01:22:52 AM by bjcowen »

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 497
Re: How do I change the size of the particles rendered from ovito?
« Reply #1 on: June 20, 2018, 01:46:58 PM »
Hi,

I assume you are working with the latest development version of OVITO 3.0. Here, the programming interface has changed in a way that is not backward compatible with previous versions.

It is longer possible to access the loaded input data using the expression 'pipeline.source.particle_properties', because the data source is no longer a data container itself. You need to evaluate the data source and request the data collection instead using its compute() method:

atypes = pipeline.source.compute().particles['Particle Type'].types

See the 'data access' section of the FileSource class documentation. Note that I have further adapted the code line to the new programming interface.

-Alex

bjcowen

  • Newbie
  • *
  • Posts: 13
Re: How do I change the size of the particles rendered from ovito?
« Reply #2 on: June 20, 2018, 04:32:34 PM »
Ok thanks that seemed to work. I have one more question related to the input script.

In the script, I create a bar for scale. The background of the bar is black and the writing is white. If I switch them so that the writing is black, how do I put a black border line around the white box. Having a plain white box does not look right, it needs a box outline.
Thanks
« Last Edit: June 20, 2018, 04:49:33 PM by bjcowen »

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 497
Re: How do I change the size of the particles rendered from ovito?
« Reply #3 on: June 20, 2018, 04:52:42 PM »
Your code only calls the fillRect() function. I think, additionally, you need to call drawRect() to draw a border on top. The thickness and color of the border will be determined by the pen that was previously set on the QPainter object. So probably another call to setPen() is in order as well to first specify the border color.

bjcowen

  • Newbie
  • *
  • Posts: 13
Re: How do I change the size of the particles rendered from ovito?
« Reply #4 on: June 20, 2018, 05:30:02 PM »
Is there a way to actually draw a scale bar, rather than the scale being the bar?

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 497
Re: How do I change the size of the particles rendered from ovito?
« Reply #5 on: June 20, 2018, 06:21:34 PM »
In principle, you can draw anything you like using the painting functions of the QPainter class from the Qt framework. The rudimentary scale "bar" was okay for my purposes when I wrote that demo code, but anything beyond that requires that you write additional Python code yourself.