This is the code I wrote, and I do feel that the index of the single particle integral is important. Below, h1 is the single particle integral in the basis ABABAB, where A,B are the sublattices (similar to spin), and I use "unitary_matrix" to change it AAA...BBB... which is the basis for h1_qubit. The construction of "unitary_matrix" can be found in the qiskit function "FermionicOperator".
Now, one important checking is that the ground state energy of two Hamiltonians, one is the fermionic single particle Hamiltonian (which is h1), and one is the Hamiltonian in the qubit basis (which is qubitOp), are identical. For the latter, it is a many-body Hamiltonian, and the ground state is the many-body ground state. If we naively compare this to the "lowest energy" of h1, then we will find that they are different, for h1 is the single-particle Hamiltonian. To properly obtain the many-body ground state from h1, we need to fill all the states below the Fermi-level of the spectrum of h1. Once we have done that, we found that the two Hamiltonians give the same many-body ground state energy.
import numpy as np
from scipy.linalg import eig
from qiskit.aqua.algorithms import VQE, NumPyEigensolver
from qiskit.chemistry import FermionicOperator
from qiskit.aqua.operators import Z2Symmetries
t1 = np.random.rand() # intra
t2 = np.random.rand() # inter
t0 = np.random.rand() # onsite energy
N = 4 # number of unit cell
BC = 1 # BC=1 is PBC, BC=0 is OBC
h1 = np.zeros( (2*N , 2*N ) )
for i in range(0,(2*N-1)):
if i % 2==1:
h1[ i , i ] = t0
h1[ i , i+1 ] = t2
h1[ i+1 , i ] = t2
else:
h1[ i , i ] = -t0
h1[ i , i+1 ] = t1
h1[ i+1 , i ] = t1
h1[2*N-1,2*N-1] = t0
if BC==1:
h1[ 0 , 2*N-1 ] = t2
h1[ 2*N-1 , 0 ] = t2
print( 'The fermionic Hamiltonian is\n' , h1 )
eigh1 = eig(h1)[0]
idx = np.argsort(eigh1)
eigh1 = eigh1[idx]
print( 'The *single* particle spectrum is \n' , eigh1 )
unitary_matrix = np.zeros((h1.shape), h1.dtype)
n = unitary_matrix.shape[0]
j = np.arange(n // 2)
unitary_matrix[j, 2 * j] = 1.0
unitary_matrix[j + n // 2, 2 * j + 1] = 1.0
h1_qubit = unitary_matrix.dot(h1.dot(unitary_matrix.T.conj()))
ferOp = FermionicOperator(h1=h1_qubit )
qubitOp = ferOp.mapping(map_type='parity' , threshold=0.00000001)
numEigenvalue = 1
result = NumPyEigensolver( qubitOp , k = numEigenvalue ).run()
eigvals = result['eigenvalues']
eigvecs = result['eigenstates']
print( 'The *many-body* grond state energy is \n ' , eigvals[0] )
print( 'We check the *many-body* ground state energy is the same as the sum of the energy below the fermi level of the *single* particle spectrum')
print( eigvals[0] - sum( eigh1[0:int(len(eigh1)/2)]))