I’m trying to construct a nearest neighbor list in python that stores the nearest neighbors of a node in a finite 3d hexagonal-closest packing (HCP) lattice. I’ve done this already with a 2d square lattice defining the structure like so. I don’t want coordinates, but just a quick way to create a nearest neighbor list for an HCP out of a list of integers. Below is the sample code of how I did this task with a square lattice.
N = int #number of nodes
L = side # a 32x32 graph, L would be 32
for i in range(N):
nearNeighbor[i][0] = (i + 1 ) % N
nearNeighbor[i][1] = (i + (N - 1)) % N
nearNeighbor[i][2] = (i + L) % N
nearNeighbor[i][3] = (i + N - L) % N
if (i-L < 0):
nearNeighbor[i][3] = -2
if (i+L >= N):
nearNeighbor[i][2] = -2
if (i%L) == 0:
nearNeighbor[i][1] = -2
if ((i+1)%L) == 0:
nearN[eighbori][0] = -2
That’s it. Now an HCP lattice, when visualized, resembles a giant cube of spheres closely packed together. Each node should have at most 12 nearest neighbors and they should come out to make something like a cube. I guess largely I want to know how to use integers and modular arithmetic to represent the HCP lattice like I did with the square lattice. Can you help me stack?
The answer to this question depends on how one chooses to truncate the HCP lattice and index it. One choice is
With this choice, the following code will return a list of neighbors of a given site.
To make sure I got the logic correct, I used the following test while writing the above function
Note that the test doesn’t cover all of the unique types of sites, so, there may still be a corner case somewhere that is wrong.