Author Topic: Changes to the python module between stable and developer version?  (Read 281 times)


  • Newbie
  • *
  • Posts: 1

I am working with python in OVITO. I recently had to switch to the developer version because ovito was quitting at startup on my Mac. I tried reinstalling, and I also tried the solutions recommended in the forum adding the lines
<true/> to <false/>
to the file $HOME/Library/Preferences/org.ovito.Ovito.plist

This did not work. I installed the developer version and now the program runs. Unfortunately, part of my python script no longer runs in the developer version. In the modify function definition, I try to create the particle property of type "selection" in my output object using the following command:

output.create_particle_property(ParticleProperty.Type.Selection), but I get the error: name "ParticleProperty" is not defined.

Is there an alternative way to do this in the new version of Ovito?‚Äč It seems that the python module has changed significantly between the stable and developer versions.

Much appreciated,

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 638

I would say switching to the Ovito 3.0-dev release is right choice, because sooner or later you will need to adapt your scripts in any case.

The data structures in Ovito 3 have changed and it wasn't possible to keep the Python interface fully backward-compatible. One of the classes that have been removed completely is ParticleProperty. That's why you get the error message. The Type.XXX constants are still available in the Particles class. Thus, you can now write Particles.Type.Selection. However, the new documentation suggests you better specify the property using its string name, i.e. "Selection". Instead of the old create_particle_property() method, the new interface provides the PropertyContainer.create_property() method:

Code: [Select]
sel = output.particles_.create_property("Selection")

Note the _ (underscore) that has been appended to the particles accessor. It is required to express your intention to modify the Particles property container that this accessor field returns. Without the underscore suffix, the returned object will be locked and any attempt to modify it will result in an error message.