OVITO Forum

OVITO => Support Forum => Topic started by: eason1021 on July 09, 2018, 07:02:26 PM

Title: Order of neighbors from NearestNeighborFinder
Post by: eason1021 on July 09, 2018, 07:02:26 PM
And I still want to ask a question.
Now I stored 6 nearest neighbors around the central atom.
The neigh index in NearestNeighborFinder is sorted list of nearest neighbors.
But I want to sort these 6 atoms is array by +x +y +z -x -y -z direction to central atom.
Has any function to re-array the neigh index list?
Title: Re: Order of neighbors from NearestNeighborFinder
Post by: Constanze Kalcher 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:

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] )