Author Topic: surface mesh creation in for loop version 3.0.0  (Read 156 times)


  • Newbie
  • *
  • Posts: 7
surface mesh creation in for loop version 3.0.0
« on: March 12, 2019, 05:23:53 PM »
I'm looking at how surface area and volume proportion change for different radii of probe sphere using the Ovitos interface.

I had a script that was working for version 2.9, but then I noticed that the locate_point feature was only available in version 3.0.0, so I'm in the process of re-writing it for that.

In version 2.9, I was able to use a for loop over a range of radii along the lines of:

Code: [Select]
node = import_file(file)

node.modifiers.append(SelectParticleType(types = {'W'}) #constructing a surface over water molecules

loops = numpy.linspace(5,16,50)

for i in loops:
    node.modifiers.append(ConstructSurfaceModifier(only_selected = True, radius = i))

    area = node.output.attributes['ConstructSurfaceMesh.surface_area']
    fraction = node.output.attributes['ConstructSurfaceMesh.solid_volume'] / node.output.cell.volume

where I'd then write out area and fraction to look at the change with probe sphere radius

Translating this over to version 3.0.0, it looks like there's a problem with continually appending to the pipeline. The area and fraction are the constant for all radii of probe spheres.

Please could I have some advice about how best to iterate over probe sphere radius in version 3.0.0?



Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 601
Re: surface mesh creation in for loop version 3.0.0
« Reply #1 on: March 12, 2019, 09:17:40 PM »
Hi Chris,

Please don't keep appending additional instances of the ConstructSurfaceModifier to the same pipeline in your loop. This may easily lead to a situation where Ovito needlessly constructs the surface mesh multiple times during every call to Pipeline.compute().

That being said, the first real problem in your script I see is in this line:
Code: [Select]

This isn't a proper function call, because the parentheses are missing. Unfortunately, Python silently accepts this syntax and won't tell you about the fact that the pipeline doesn't get computed. Please correct it to
Code: [Select]

Here is how I would translate the script to the new Ovito 3.0 style:

Code: [Select]
pipeline = import_file(file)

pipeline.modifiers.append(SelectParticleType(types = {'W'}) #constructing a surface over water molecules
mod = ConstructSurfaceModifier(only_selected = True)

loops = numpy.linspace(5,16,50)

for radius in loops:
    mod.radius = radius
    data = pipeline.compute()
    area = data.attributes['ConstructSurfaceMesh.surface_area']
    fraction = data.attributes['ConstructSurfaceMesh.solid_volume'] / data.cell.volume


  • Newbie
  • *
  • Posts: 7
Re: surface mesh creation in for loop version 3.0.0
« Reply #2 on: March 13, 2019, 09:00:43 AM »
Hi Alexander,

Thank you for the great reply! I only noticed the missing () when you highlighted them, they were in my script but got lost in copying, don't worry!

The code now works as I expected.   :)