using DFTK using Plots using Unitful using UnitfulAtomic # 1. Define lattice and atomic positions a = 5.431u"angstrom" # Silicon lattice constant lattice = a / 2 * [[0 1 1.]; # Silicon lattice vectors [1 0 1.]; # specified column by column [1 1 0.]]; # Load HGH pseudopotential for Silicon Si = ElementPsp(:Si, psp=load_psp("hgh/lda/Si-q4")) # Specify type and positions of atoms atoms = [Si, Si] positions = [ones(3)/8, -ones(3)/8] # 2. Select model and basis model = model_LDA(lattice, atoms, positions) kgrid = [4, 4, 4] # k-point grid (Regular Monkhorst-Pack grid) Ecut = 7 # kinetic energy cutoff # Ecut = 190.5u"eV" # Could also use eV or other energy-compatible units basis = PlaneWaveBasis(model; Ecut, kgrid) # Note the implicit passing of keyword arguments here: # this is equivalent to PlaneWaveBasis(model; Ecut=Ecut, kgrid=kgrid) # 3. Run the SCF procedure to obtain the ground state scfres = self_consistent_field(basis, tol=1e-5); scfres.energies hcat(scfres.eigenvalues...) hcat(scfres.occupation...) rvecs = collect(r_vectors(basis))[:, 1, 1] # slice along the x axis x = [r[1] for r in rvecs] # only keep the x coordinate plot(x, scfres.ρ[1, :, 1, 1], label="", xlabel="x", ylabel="ρ", marker=2) plot_bandstructure(scfres; kline_density=10) compute_forces_cart(scfres)