How to read and access the electron-phonon databases (gkkp / gkkp_expanded) in lumen/yambo.
Key source files:
| File | Role |
|---|---|
src/io/io_ELPH.F |
Database read/write function |
src/io/variables_ELPH.F |
Header variable definitions |
src/allocations/ELPH_alloc.F |
Array allocation |
src/modules/mod_ELPH.F |
GKKP_me type and module variables |
All database reads go through io_control + a database-specific function.
The full io_control reference is in IO_Quick_Reference.md; here is the subset
relevant for ELPH reading.
use IO_m, ONLY: OP_RD, OP_RD_CL, RD, RD_CL, RD_CL_IF_END, &
DUMP, VERIFY, REP, NONE, manage_action
use IO_int, ONLY: io_control
| Parameter | Values | Meaning |
|---|---|---|
ACTION |
OP_RD |
Open + read header, keep file open |
RD |
Read next section (file already open) | |
RD_CL |
Read section + close file | |
OP_RD_CL |
Open + read + close (single shot) | |
RD_CL_IF_END |
Read; close only on last iteration | |
SEC |
(/1/) |
Header section |
(/iq+1/) |
Data section for q-point iq |
|
COM |
REP / NONE |
Print messages or silent |
MODE |
DUMP / VERIFY |
Full read or structure check only |
ID |
integer | File handle (output on open, reuse afterward) |
integer function io_ELPH(ID, what)
integer :: ID ! file handle from io_control
character(*) :: what ! database selector (see below)
what string |
NetCDF file | Description |
|---|---|---|
'gkkp' |
elph_gkkp |
Standard grid el-ph matrix elements |
'gkkp_expanded' |
elph_gkkp_expanded |
Expanded (full BZ) grid |
'gkkp no_matrix_elements' |
elph_gkkp |
Header + energies only, skip dVc |
| Section | Contents |
|---|---|
SEC=1 |
Header: lattice, k-grid, elph_bands, ph_modes, elph_nQ, elph_nk_bz, phonon Q/K grids |
SEC=iq+1 |
Data for q-point iq: phonon frequencies, polarization vectors, E(k+q), GKKP matrix elements |
variables_ELPH)| NetCDF variable | Fortran target | Type |
|---|---|---|
[ELPH] Phonon modes |
ph_modes |
integer |
[ELPH] Q points [avail] |
elph_nQ |
integer |
[ELPH] K points |
elph_nk_bz (= nkbz) |
integer |
[ELPH] El-PH bands |
elph_bands(2) |
integer(2) |
[ELPH] Branches |
elph_branches(2) |
integer(2) |
MAX_PH_FREQ |
Debye frequency | real |
PH_Q |
PH_qpt(elph_nQ, 3) |
real |
PH_K |
PH_kpt_bz(nkbz, 3) |
real (expanded only) |
When section > 1, io_ELPH reads these NetCDF variables in order:
PH_FREQS_{iq} → PH_freqs_sq(iq, 1:ph_modes) real
POLARIZATION_VECTORS → PH_pol_vector(:,:,:,iq) complex(ph_modes, n_atoms, 3)
E_K_PLUS_Q_{iq} → GKKP%E_kpq(iq)%E real(elph_nb, nkbz, 1)
ELPH_GKKP_Q_{iq} → GKKP%dVc(:,:,:,:,1) complex(ph_modes, elph_nb, elph_nb, nkbz)
ELPH_GKKP_BARE_Q_{iq} → GKKP_bare%dVc(:,:,:,:,1) [optional]
ELPH_DW_Q_{iq} → GKKP%dVr(:,:,:,:,1) [optional]
Source: src/allocations/ELPH_alloc.F
On the first data-section read, io_ELPH calls:
call ELPH_alloc("LEVELS dV DW", GKKP=GKKP)
GKKP%dVc( GKKP%Nmodes(1) : GKKP%Nmodes(2), & ! 1 : ph_modes
GKKP%Nb(1) : GKKP%Nb(2), & ! elph_bands(1) : elph_bands(2)
GKKP%Nb(1) : GKKP%Nb(2), & ! elph_bands(1) : elph_bands(2)
GKKP%Nk_mem, & ! nkbz
GKKP%Nq_mem ) ! 1 (one q-point at a time)
Band dimensions use elph_bands-based lower bounds, NOT 1-based.
Example: if elph_bands = (/46, 58/), the valid band indices are 46 through 58.
GKKP%dVc(il, 46, 50, ik, 1) is valid. Use absolute band indices directly.
| Command | Array | Shape |
|---|---|---|
'LEVELS' |
GKKP%E_kpq(iq)%E |
(elph_bands(1):elph_bands(2), nkbz, 1) per q |
'DW' |
GKKP%dVr |
Same shape as dVc but real |
'dV_bare' |
GKKP_bare%dVc |
Same shape as dVc |
'PHONONS' |
PH_freqs_sq, PH_pol_vector, PH_qpt, PH_kpt_bz |
Various |
mod_ELPH.F)type GKKP_me
character(schlen) :: KIND = "none" ! "dV", "dV_bare", "dV_sq", "DW"
complex(SP), allocatable :: dVc(:,:,:,:,:) ! complex el-ph matrix elements
real(SP), allocatable :: dVr(:,:,:,:,:) ! real (Debye-Waller)
type(levels), allocatable :: E_kpq(:) ! k+q energies (array over q)
integer :: Nb(2) = 0 ! band range
integer :: Nmodes(2) = 0 ! mode range
integer :: Nk_mem = 0 ! number of k-points in memory
integer :: Nq_mem = 0 ! number of q-points in memory
end type
GKKP%dVc(il, ib, ob, ik_db, i_sp) = < ib, k | dV_{q,il} | ob, k-q >
| Index | Meaning | Range |
|---|---|---|
il |
Phonon branch (mode) | 1 : ph_modes |
ib |
"Bra" band (absolute) | elph_bands(1) : elph_bands(2) |
ob |
"Ket" band (absolute) | elph_bands(1) : elph_bands(2) |
ik_db |
K-point (database index) | 1 : nkbz |
i_sp |
Spin polarization | usually 1 |
This is the raw deformation potential dV/du, not yet divided by sqrt(2*omega_ph).
To get the standard electron-phonon coupling g:
ph_E = sqrt(abs(ph_freqs_sq(iq_db, il)))
g = GKKP%dVc(il, ib, ob, ik_db, 1) / sqrt(2.0_SP * ph_E)
use ELPH, ONLY: Q_io_map, K_io_map
iq_db = Q_io_map(iq_bz) ! BZ q-index → database q-index (for SEC)
ik_db = K_io_map(ik_bz) ! BZ k-index → database k-index (for dVc)
The database may store q/k-points in a different order than the BZ grid. Always map before indexing.
integer :: ID_gkkp, io_err, iq_db
integer :: elph_branches_save(2)
integer, external :: io_ELPH
iq_db = Q_io_map(1) ! Gamma point
elph_branches_save = elph_branches ! save before header overwrites
! Step 1: open + read header (keep file open)
call io_control(ACTION=OP_RD, COM=REP, MODE=DUMP, SEC=(/1/), ID=ID_gkkp)
io_err = io_ELPH(ID_gkkp, 'gkkp_expanded')
if (io_err /= 0) call error('El-Ph database not found')
elph_branches = elph_branches_save ! restore
! Step 2: read Gamma fragment + close
call io_control(ACTION=RD_CL, SEC=(/iq_db+1/), ID=ID_gkkp)
io_err = io_ELPH(ID_gkkp, 'gkkp_expanded')
if (io_err /= 0) call error('Error reading gkkp_expanded at Gamma')
! Now use GKKP%dVc with absolute band indices:
gcc = GKKP%dVc(il, ic, icp, K_io_map(ik_bz), 1) / sqrt(2.0_SP * ph_E)
From: src/raman/RAMAN_oneph_ip.F
! Header (done once, typically in a driver routine)
call io_control(ACTION=OP_RD, COM=REP, MODE=DUMP, SEC=(/1/), ID=ID_gkkp)
io_err = io_ELPH(ID_gkkp, 'gkkp_expanded')
! Called per (iq_bz, il) pair inside the loop:
iq_db = Q_io_map(iq_bz)
IO_ACT = RD ! default: keep open
if (il == elph_branches(2)) &
IO_ACT = manage_action(RD_CL_IF_END, iq_bz, 1, q%nbz) ! close on last q
call io_control(ACTION=IO_ACT, SEC=(/iq_db+1/), ID=ID_gkkp)
io_err = io_ELPH(ID_gkkp, 'gkkp_expanded')
! Use data
elph_gkkp = GKKP%dVc(il, iv, ivp, K_io_map(ik_bz), 1) / sqrt(2._SP * ph_E)
manage_action(RD_CL_IF_END, current, first, last) returns RD for intermediate
iterations and RD_CL for the last one. The file stays open across q-points.
From: src/exc-ph/EXCPH_gkkp_eval.F
call io_control(ACTION=OP_RD_CL, COM=NONE, MODE=DUMP, SEC=(/1/), ID=ID)
io_err = io_ELPH(ID, 'gkkp')
! io_err == 0 means database exists and header is readable
From: src/interface/INIT_check_databases.F
Header overwrites elph_branches: The header read resets elph_branches
to database values. Save and restore if you set custom values beforehand.
OP_RD_CL closes the file: If you need data sections after the header,
use OP_RD (keeps open) for the header, then RD_CL for the last data section.
K/Q-point mapping is mandatory: Always use K_io_map(ik_bz) for the 4th
index of GKKP%dVc, and Q_io_map(iq_bz) for section numbers.
Band indices are absolute: GKKP%dVc is allocated with bounds
elph_bands(1):elph_bands(2), not 1:elph_nb. Use absolute band indices.
GKKP%dVc is the raw deformation potential: Always divide by sqrt(2*omega_ph)
to get the physical electron-phonon coupling g.
GKKP%dVc is overwritten each q-point: Only one q-point of data lives in
memory at a time (Nq_mem=1). Process each q-point before reading the next.
ph_freqs_sq stores frequencies squared: The physical phonon energy is
ph_E = sqrt(abs(ph_freqs_sq(iq_db, il))).
io_control(ACTION=OP_RD, SEC=(/1/), ...)
│
▼
io_ELPH(ID, 'gkkp_expanded')
│
├── SEC=1: io_header() + variables_ELPH()
│ → sets: elph_bands, ph_modes, elph_nQ, elph_nk_bz, PH_qpt, ...
│
io_control(ACTION=RD_CL, SEC=(/iq+1/), ...)
│
▼
io_ELPH(ID, 'gkkp_expanded')
│
├── SEC>1: io_fragment(iq)
│ → ELPH_alloc("LEVELS dV DW") [first time only]
│ → reads: PH_freqs_sq(iq,:)
│ PH_pol_vector(:,:,:,iq)
│ GKKP%E_kpq(iq)%E
│ GKKP%dVc(:,:,:,:,1)
│
▼
Ready to use: GKKP%dVc(il, ib, ob, K_io_map(ik_bz), 1)
use ELPH, ONLY: GKKP, ph_freqs_sq, elph_branches, elph_bands, &
Q_io_map, K_io_map, ph_modes
use ALLOC, ONLY: ELPH_alloc
use IO_m, ONLY: OP_RD, RD_CL, REP, DUMP, manage_action, RD_CL_IF_END, RD
use IO_int, ONLY: io_control
integer, external :: io_ELPH