Author Topic: How to combine NearestNeighborFinder and periodic boundary setting  (Read 185 times)

eason1021

  • Newbie
  • *
  • Posts: 24
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 atom
N= 6
finder = 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) ]




Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 277
Re: How to combine NearestNeighborFinder and periodic boundary setting
« Reply #1 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[0],neigh[1]))

-Constanze