File size: 5,395 Bytes
e9e349d | 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 | #!/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
|