#!/usr/bin/env julia #= DFT electron-phonon coupling calculation for diamond using ElectronPhonon.jl. Workflow (set one flag to true at a time): create = true → create EPC displacement structures in displacements/ run = true → run QE SCF + pw2bgw for all structures prepare = true → read QE output, create JLD2 eigenvalue/phonon files calc_ep = true → compute DFT EPC matrix elements → displacements/out_dft/ Usage: cd example/diamond/3_epc julia diamond.jl =# using ElectronPhonon, PythonCall, ProgressMeter # ============================================================ # Workflow flags — set ONE to true at a time # ============================================================ create = false from_scratch = false run = false prepare = false calc_ep = true # ============================================================ # Paths # ============================================================ SCRIPT_DIR = @__DIR__ path_to_calc = SCRIPT_DIR * "/" # Path to the QE binary directory (must contain pw.x and pw2bgw.x). # Update this to match your local QE installation. path_to_qe = "/home/apolyukhin/Development/q-e_tmp/" mpi_ranks = 8 # from params.json execution.mpi_np # ============================================================ # Diamond FCC primitive cell (a = 3.567 Å, matches scf.in) # ============================================================ a = 3.567 sc_size = [1, 1, 1] k_mesh = [6, 6, 6] natoms = 2 Ndisplace = 6 * natoms # 12: 2 atoms × 3 directions × 2 signs pseudo_dir = SCRIPT_DIR * "/../pseudos/" unitcell = Dict( :symbols => pylist(["C", "C"]), :cell => pylist([ [0.0, a/2, a/2], [a/2, 0.0, a/2], [a/2, a/2, 0.0] ]), :scaled_positions => pylist([ (0.0, 0.0, 0.0), (0.25, 0.25, 0.25) ]), :masses => pylist([12.011, 12.011]), ) scf_parameters = Dict( :format => "espresso-in", :kpts => pytuple((k_mesh[1], k_mesh[2], k_mesh[3])), :calculation => "scf", :prefix => "scf", :outdir => "./tmp/", :pseudo_dir => pseudo_dir, :ecutwfc => 60, :conv_thr => 1.0e-13, :pseudopotentials => Dict("C" => "C.upf"), :diagonalization => "david", :mixing_mode => "plain", :mixing_beta => 0.7, :crystal_coordinates => true, :verbosity => "high", :tstress => false, :ibrav => 0, :tprnfor => true, :nbnd => 8, :electron_maxstep => 1000, :nosym => true, :noinv => true, ) abs_disp = 1e-3 # Angstrom model = create_model( path_to_calc = path_to_calc, abs_disp = abs_disp, path_to_qe = path_to_qe, mpi_ranks = mpi_ranks, sc_size = sc_size, k_mesh = k_mesh, Ndispalce = Ndisplace, unitcell = unitcell, scf_parameters = scf_parameters, use_symm = false, ) # ============================================================ # Step 1: Create displacement structures # ============================================================ if create println("Creating displacement structures in displacements/...") create_disp_calc!(model; from_scratch = from_scratch) println("Done. Created displacements/scf_0/ and displacements/group_1..$(Ndisplace)/") end # ============================================================ # Step 2: Run QE SCF + pw2bgw # ============================================================ if run println("Running QE SCF + pw2bgw for all $(Ndisplace + 1) structures...") run_calculations(model) println("Done. QE calculations complete.") println("Next: run HPRO reconstruction via ml_epc.py (step 'hpro'), then set prepare=true") end # ============================================================ # Step 3: Prepare model # ============================================================ if prepare println("Preparing model (reading QE output, creating JLD2 files)...") prepare_model(model) electrons = create_electrons(model) phonons = create_phonons(model) println("Done. Eigenvalue and phonon JLD2 files created.") end # ============================================================ # Step 4: Compute DFT EPC matrix elements # ============================================================ if calc_ep electrons = load_electrons(model) phonons = load_phonons(model) disp_dir = path_to_calc * "displacements/" out_dir = disp_dir * "out/" out_dft = disp_dir * "out_dft/" ik_list = collect(1:prod(k_mesh)) iq_list = [1] progress = Progress(length(ik_list) * length(iq_list), dt=5.0) println("Calculating DFT EPC for $(length(ik_list)) k-points...") for ik in ik_list for iq in iq_list electron_phonon(model, ik, iq, electrons, phonons; phonons_dfpt=false) next!(progress) end end # Rename out/ → out_dft/ to preserve DFT reference if isdir(out_dft) rm(out_dft; recursive=true) end if isdir(out_dir) mv(out_dir, out_dft) println("Done. DFT EPC saved to: displacements/out_dft/ ($(length(readdir(out_dft))) files)") else println("WARNING: out/ not found after EPC calculation.") end end