epc_ml_data / 4_epw /diamond.jl
Koulb's picture
Add files using upload-large-folder tool
db31a41 verified
#!/usr/bin/env julia
#=
EPW electron-phonon coupling workflow for diamond using ElectronPhonon.jl.
Generates frozen-displacement (FD) EPC braket files compatible with EPW.
Workflow (set flags at top):
create = true β†’ create symmetry-reduced displacement structures
run = true β†’ run QE SCF for all structures
prepare = true β†’ read QE output, create JLD2 eigenvalue/phonon files
calc_ep = true β†’ compute FD EPC brakets β†’ displacements/epw/ (save_epw=true)
After calc_ep, run the standalone QE/EPW workflow (see run.sh):
SCF β†’ NSCF β†’ ph.x β†’ epw0 (Wannierize) β†’ epw1 (DFPT ref) β†’ parse_ml_data.py β†’ epw2
Usage:
cd example/diamond/4_epw
julia diamond.jl
=#
using ElectronPhonon, PythonCall, ProgressMeter
# ============================================================
# Workflow flags β€” set interactively or via command-line ARGS:
# julia diamond.jl create run prepare calc_ep
# ============================================================
create = "create" in ARGS || false
from_scratch = "scratch" in ARGS || false
run = "run" in ARGS || false
prepare = "prepare" in ARGS || false
calc_ep = "calc_ep" in ARGS || false
# ============================================================
# Paths
# ============================================================
SCRIPT_DIR = @__DIR__
path_to_calc = SCRIPT_DIR * "/"
# Path to QE binary directory (must contain pw.x).
# Update to match your local QE installation.
path_to_qe = "/home/apolyukhin/Development/q-e_tmp/"
mpi_ranks = 8
# ============================================================
# Diamond FCC primitive cell (a = 3.567 Γ…)
# EPW uses only 4 valence bands; nosym/noinv for all 216 k-pts in save/
# ============================================================
a = 3.567
sc_size = [1, 1, 1]
k_mesh = [6, 6, 6]
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]),
)
# nosym/noinv: ensures all 216 k-pts are in scf.save/ for fake2nscf eigenvalue patching
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 => 4,
:electron_maxstep => 1000,
:nosym => true,
:noinv => true,
)
# use_symm=true: symmetry-reduced displacements compatible with EPW
abs_disp = 1e-3 # Angstrom
use_symm = true
# Ensure pw.x is on PATH when Julia runs QE subprocesses
ENV["PATH"] = path_to_qe * "bin:" * get(ENV, "PATH", "")
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,
unitcell = unitcell,
scf_parameters = scf_parameters,
use_symm = use_symm,
)
# When not creating, detect existing displacement dirs to set Ndispalce
if !create
disp_dir = path_to_calc * "displacements/"
if isdir(disp_dir)
n = length(filter(d -> startswith(d, "group_"), readdir(disp_dir)))
model.Ndispalce = n
println("Detected $n displacement groups from displacements/")
end
end
# ============================================================
# Step 1: Create displacement structures
# ============================================================
if create
println("Creating symmetry-reduced displacement structures...")
create_disp_calc!(model; from_scratch = from_scratch)
println("Done. Created displacements/scf_0/ and symmetry-reduced group dirs.")
end
# ============================================================
# Step 2: Run QE SCF for all structures
# ============================================================
if run
println("Running QE SCF for all displacement structures...")
run_calculations(model)
println("Done. QE calculations complete.")
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. JLD2 eigenvalue and phonon files created.")
end
# ============================================================
# Step 4: Compute FD EPC brakets (save_epw=true β†’ displacements/epw/)
# ============================================================
if calc_ep
electrons = load_electrons(model)
phonons = load_phonons(model)
ik_list = collect(1:prod(k_mesh .* sc_size)) # 1..216
iq_list = [1] # q=Gamma only
mkpath(path_to_calc * "displacements/epw")
progress = Progress(length(ik_list) * length(iq_list), dt=5.0)
println("Computing FD EPC brakets for $(length(ik_list)) k-points (q=Gamma)...")
for ik in ik_list
for iq in iq_list
electron_phonon(model, ik, iq, electrons, phonons; save_epw = true)
next!(progress)
end
end
println("Done. FD braket files written to displacements/epw/")
println("Next: run the standalone QE/EPW workflow (see run.sh), then parse_ml_data.py")
end