1

**Support Forum / Re: Order of neighbors from NearestNeighborFinder**

« **on:**July 10, 2018, 04:06:39 PM »

Indeed, the NearestNeighborFinder sorts the neighbors by the length of the distance vector to the central particle.

In order to print the indices of the neighbors of each particle sorted like you asked could try something along these lines:

In order to print the indices of the neighbors of each particle sorted like you asked could try something along these lines:

Code: [Select]

`from ovito.io import import_file`

from ovito.data import NearestNeighborFinder

import numpy as np

pipeline = import_file("simulation.dump")

data = pipeline.compute()

N = 3

finder = NearestNeighborFinder(N, data)

for index in range(data.particles.count):

neighbors = [ (neigh.index, neigh.delta) for neigh in finder.find(index) ]

#print neighbor indices

print( [n[0] for n in neighbors] )

resorted_neighbors = sorted( neighbors , key=lambda k: [k[1][0], k[1][1], k[1][2]], reverse=True )

#print rearranged neighbor indices

print( [n[0] for n in resorted_neighbors] )