Tight binding Hamiltonian for 2D finite dimensional lattice and nanowire The Hamiltonian of a 1D lattice having finite $N$ atoms, (if we consider one basis per atom) is given by the following $N\times N$ matrix-

Here $E$ is the onsite energy and $t$ is the hopping integral. So, how can I construct the Hamiltonian for 2D finite size lattice? For example, if we take a slice from a nanowire (say square shape Si nanowire), we will get such 2D lattice having finite height and width.
From that Hamiltonian of one slice, I want to calculate the Hamiltonian for the complete nanowire. How can I do that?
 A: The "only" thing you need to do is to establish a mapping. You have a basis function at 
$$ \vec{R} = a\vec{X} + b\vec{Y}$$ with index i. In other words, your basis is $\phi_{abi}$. Since Matlab only understands (well) vectors and matrices, you need to map this to a continuous index n. For example, a square with sides $N_a$, and $N_b$ and $N_i$ basis functions per site.
$$n_{abi} = (a + N_a b) N_i + i.$$
Then you need to establish the rules for matrix elements. Here is an example code (wrote that in 10 minutes, might have some bugs). See how sparse-command works to understand how Hamiltonian is constructed. As you can see, there is nothing difficult. Only it is a bit tedious to keep track of the indexing. The actual diagonalization is then just one row. The example lacks k_z, so you have to put that in yourself then. This will mean that in constructing your matrix elements, you will need to take the dispersion into account.
Na = 20; % Number of atoms in x directions
Nb = 20;
Ni = 2;

H_S = [ 1.0 0.1 ; 0.1 1.0 ]; % Hamiltonian for same site interaction
H_NN = [ 0.1 0.0 ; 0.0 0.1 ]; % Hamiltonian for nearest neighbour interaction

% Values to store the constructed sparse hamiltonian
nn1 = [];
nn2 = [];
Hnn = [];

% Loop over all lattice sites
for a1=1:Na, for b1=1:Nb
  % Loop over all neighbouring sites
  for da=-1:1
  a2=a1+da;
  if (a2 <1 || a2 > Na)
    continue;
  end
  for db=-1:1
    b2=b1+db;
    if (b2 <1 || b2 > Nb)
      continue;
    end
    % Loop over all basis function pairs
    for i1=1:Ni, for i2=1:Ni
      n1 = ((a1-1) + (b1-1) * Na) * Ni + i1; % Magic happends here
      n2 = ((a2-1) + (b2-1) * Na) * Ni + i2;
      NN = max(abs(da),abs(db));
      if (NN == 0)
        nn1 = [ nn1 n1 ]; % XXX Super slow
        nn2 = [ nn2 n2 ];
        Hnn = [ Hnn H_S(i1,i2) ];
      end
      if (NN == 1)
        nn1 = [ nn1 n1 ]; % XXX Super slow
        nn2 = [ nn2 n2 ];
        Hnn = [ Hnn H_NN(i1,i2) ];
      end
    end,end
  end
end, end
end
H = sparse(nn1, nn2, Hnn);
[U,E] = eig(H);
plot(diag(E));

Update:
This are the steps (IHMO) how to build a simple TB code.
1) get the positions of the atoms and atom types (For example, take the cubic 8 atom unit cell of GaAs and repeat it 15x15x1 times and then cut out atoms which are too far from the center, to create spherical wire). Protip: Use lattice planes and well known surfaces to cut.
2) Each atom will have $N_b$ basis functions. Your Hamiltonian will consist of blocks of $N_b \times N_b$. In matlab notation, all the Hamiltonian matrix elements between two sites (indexed with a1 and a2) can be written as:
H((a1*N):(a1*N+N-1), (a2*N):(a2*N+N-1) = Hloc;

3) Loop over all atoms in the your cell (this means all the (say) 200 atoms, not the unitcell of GaAs).
   For each atom, loop over it's neighbourhood (remember to look also in the neighboring cells).
4) Calculate all Hamiltonian matrix elements of these atom pairs and ADD them to appropriate place in Hamiltonian. (remember to add phase factor, if the pairs are not in the same unit cell). 
Evaluate the difference between two atomic positions, and better yet, divide it with a/4, where a is your lattice constant.
$$\Delta R = (R_{a1} - R_{a2}) / (a/4)$$.
You might end have a vector like this (-1,-1,-1), where you can easily deduce that this is the nearest neighbor interaction, and add the appropriate matrix elements.
In $O_h$ symmetry, you could take absolute value of the three elements of the difference vector and sort them to get an unique descriptor of the matrix element. Zinc-blende structure has lower symmetry, but there might be similar tricks.
