Author Topic: NearestNeighborFinder - Access to other particle attributes  (Read 361 times)

matsciguy

  • Newbie
  • *
  • Posts: 2
NearestNeighborFinder - Access to other particle attributes
« on: February 14, 2018, 10:36:48 PM »
My current understanding of NearestNeighborFinder is that it accesses particle position and particle selection properties only. I obtained this from the following link to the source code
https://gitlab.com/stuko/ovito/blob/master/src/plugins/particles/util/NearestNeighborFinder.cpp

I would like to be able to calculate on other particle properties once I know that a particle is close to the particle of interest. I want to do this for an imported property but an easy example to test would be to calculate the average centrosymmetry parameter for a particle's neighbors. According to my understanding there is no way to do this.

I would appreciate any help regarding this matter.

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 515
Re: NearestNeighborFinder - Access to other particle attributes
« Reply #1 on: February 15, 2018, 08:41:14 AM »
The NearestNeighborFinder.find() yields a bunch of information about the neighbors of a particle. Aside from the distance and the neighbor vector, it also returns the global index of the current neighbor particle. This index can be used to access other properties of the neighbor particle. Example:

Code: [Select]
foo_values = data.particle_properties['foo'].array
for index in range(data.number_of_particles):
    for neigh in finder.find(index):
        neigh_foo = foo_values[neigh.index]  # Access the 'foo' value of the current neighbor
        ...
« Last Edit: February 28, 2018, 11:08:06 PM by Alexander Stukowski »

matsciguy

  • Newbie
  • *
  • Posts: 2
Re: NearestNeighborFinder - Access to other particle attributes
« Reply #2 on: February 28, 2018, 10:22:07 PM »
Awesome! We figured you had a way to do this but just couldn't understand it. Thanks for your quick response and help!