Construction of Hamiltonian including sublattices and orbitals, tests for 1D chain and square lattice