Forum Navigation
You need to log in to create posts and topics.

Additional property array "Nearest N Neighbors"

Is it possible to get an array of N nearest neighbor index, without doing any looping for a given snapshot?

I think it may be an integral part of some of the OVITO modifiers like Voronoi or Structure Identifier.

Just want to avoid "For loops" and additional property array "neighbor list" similar to  "trajectory coordinates"

So property can be accessible via just one command.

With Current method:

from import import_file
from import NearestNeighborFinder

# Load input simulation file.
pipeline = import_file("input/simulation.dump")
data = pipeline.compute()

# Initialize neighbor finder object.
# Visit the 12 nearest neighbors of each particle.
N = 12
finder = NearestNeighborFinder(N, data)

# Prefetch the property array containing the particle type information:
ptypes = data.particles.particle_types

# Loop over all input particles:
for index in range(data.particles.count):
    print("Nearest neighbors of particle %i:" % index)
    # Iterate over the neighbors of the current particle, starting with the closest:
    for neigh in finder.find(index):
        print(neigh.index, neigh.distance,
        # The index can be used to access properties of the current neighbor, e.g.
        type_of_neighbor = ptypes[neigh.index]


No, the current version of the OVITO Python API doesn't provide a direct way of getting the neighbour lists for all atoms at once.

However, I took your question as a request and added a new method NearestNeighborFinder.find_all() to the development version of OVITO. Please take a look at the description of this new method. Does it provide the functionality you need?

Furthermore, I am wondering whether the particle indices being the only output of the find_all() method is sufficient. I can imagine that, for some applications, one also needs access to the spatial neighbour vectors ("delta" vectors computed by the find() method). What is you opinion on this? Are you only interested in the indices of the neighbouring atoms, or do we need a second version of find_all(), computing both the neighbour indices and vectors?

Sorry for delayed response, Alex.

It will be great if you include delta and distance as well in find_all functionality.



Here you go - a revised version of find_all(): Python API documentation

You can test it if you like by running your script with the ovitos interpreter from these OVITO Pro development builds:

Thanks a lot!!!



New for our users in China: OVITO on WeChat 

Official OVITO WeChat channel operated by Foshan Diesi Technology Co., Ltd.