title: Creating a sphere packing nearest neighbor list from integers
body: <p>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. </p>
  
  <pre><code>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 &lt; 0):
           nearNeighbor[i][3] = -2
      if (i+L &gt;= N):
           nearNeighbor[i][2] = -2
      if (i%L) == 0:
           nearNeighbor[i][1] = -2     
      if ((i+1)%L) == 0:
           nearN[eighbori][0] = -2
  </code></pre>
  
  <p>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?</p>