File size: 6,046 Bytes
db31a41 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | #!/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
|