Dear Elham,
You need two calculations. A bulk calculation where you align the band edges with respect to the average electrostatic potential. And a slab calculation with vacuum, where you align the average electrostatic potential in the center layers of the slab with respect to the vacuum potential.
In CP2K, the average electrostatic potential over the whole cell is set to zero. Hence, the bulk calculation only consists in running a CELL_OPT of a big enough supercell, and taking the values of the Fermi level and the HOMO-LUMO gap. The Fermi level represents the position of the valence band with respect to the average electrostatic potential, and the Fermi level + gap is then the conduction band. This calculation gives you the alignment of the band edges with respect to the average electrostatic potential.
For the vacuum calculation, you have to make sure you have a thick enough slab (so that the electrostatic potential in the middle layers behaves like the bulk one) and a thick enough vacuum layer, so that there the potential is flat. Run a GEO_OPT of the slab with vacuum, and then perform an ENERGY calculation on the resulting geometry with the V_HARTREE_CUBE option in the PRINT section inside DFT set to .TRUE.
Next, project the .cube file of the average potential along the axis perpendicular to the interface. Then, take the value in the middle of the vacuum region, and subtract the average over the central-most layer(s) inside the slab. This gives you the alignment of the average electrostatic potential with respect to vacuum.
You see now that combining the results of the two yields the desired alignment.
Yours sincerely,
Patrick Gono