# OVITO Forum

## OVITO => Support Forum => Topic started by: eason1021 on January 22, 2019, 08:01:19 AM

Title: How to combine NearestNeighborFinder and periodic boundary setting
Post by: eason1021 on January 22, 2019, 08:01:19 AM
Hello everyone,
I tried to use this NearestNeighborFinder to find neighboring atoms and form unit cells.
I set periodic boundary conditions, the program also has the correct atomic identifier.
But when I tried to calculate the distance between adjacent atoms and adjacent atoms, I found that the coordinates of the atoms would still use the original coordinates, and would not be updated to the coordinates of the periodic boundary. Is there any way to obtain the coordinates of the periodic boundary?
Code: [Select]
`cell = node.compute().cell_with cell:    cell.pbc=(True,True,False)data = node.compute()#Found REF nearest 6 atoms around the center atomN= 6finder = NearestNeighborFinder(N, data)ptypes = data.particles['Particle Type']positions = data.particles['Position']# Loop over all input particles:for index in range(data.particles.count):    neighbors = [ (neigh.index, neigh.delta) for neigh in finder.find(index) ]`

Title: Re: How to combine NearestNeighborFinder and periodic boundary setting
Post by: Constanze Kalcher on January 22, 2019, 10:05:53 AM
Hello,

if I understand you correctly you're asking how to obtain the coordinates of the closest image of a neighbor atom, right? Note that the NearestNeighborFinder function takes into account periodicity when calculating the distance vector to each neighbor,
it however does not "generate new atoms" for each image of an atom. Thus when you look up the position of the neighbor atom it will always be the original image.
What you have to do to obtain the coordinates of the closest image of a neighbor atom is to simply add the neighbor distance vector to the position of the central atom, try e.g.

Code: [Select]
`for index in range(data.particles.count):    neighbors = [ (neigh.index, neigh.delta + positions[index]) for neigh in finder.find(index) ]    print("Neighbor Atom \t Position")    for neigh in neighbors:        print( "{} \t {}".format(neigh,neigh))`
-Constanze