QE 准粒子拟合、谱展宽与 NEB 路径插值
从 GWW 或 NEB 的真实输出做二次处理,识别两个已安装程序的读取问题并在个人目录运行修正版。
阅读本篇目录
在 login01 打开自己的工作目录。每节使用独立算例目录。阅读完本节后执行其中的命令;计算程序均通过下面的 Slurm 函数提交。每次重新登录后先定义一次。它读取你输入的命令并逐行写入当前作业的脚本,将该目录作为工作目录。
qe_job() {
local script
script=$(mktemp -p "$PWD" qe-step.XXXXXXXX.sh) || return
cat > "$script" <<'HEADER'
#!/bin/bash
#SBATCH --partition=cpu-8173m
#SBATCH --nodes=1
#SBATCH --ntasks=2
#SBATCH --output=qe-%j.out
set -eo pipefail
source /etc/profile.d/lmod.sh
module load qe/7.6-8173m
export OMP_NUM_THREADS=1
cd "$SLURM_SUBMIT_DIR"
HEADER
cat >> "$script"
sbatch "$script"
}
提交后用 squeue -u "$USER" 看队列,结束后用 sacct -j 作业号 --format=JobID,State,ExitCode 看终态。输出文件与脚本保存在当前目录。
1. 从 GWW 结果拟合准粒子能级#
mkdir -p ~/qe-practice/gww-fit
cd ~/qe-practice/gww-fit
QE_SOURCE=/public/software/package/qe/7.6/source/q-e
先按甲烷 GWW 流程产生同一轮的 ch4-bands.dat、ch4-re_on_im00001…00005 和 ch4-im_on_im00001…00005。把它们复制到新的拟合目录。公共 gww_fit.x 在这套 7.6 构建里读取未初始化的 Fortran 文件单元,会报 Bad file descriptor。下面在自己的目录修正两个文件单元,再用集群已装的 QE 库编译,文件名 fit-local.x。原版 gww.x 的流程仍可用。
cp "$QE_SOURCE/GWW/gww/gww_fit.f90" fit-local.f90
python3 - <<'PATCH'
from pathlib import Path
p=Path("fit-local.f90")
s=p.read_text()
for old,new in [(" open( unit=iun,"," iun=find_free_unit()\n open( unit=iun,"),(" open( unit=iun2,"," iun2=find_free_unit()\n open( unit=iun2,")]:
assert old in s
s=s.replace(old,new,1)
p.write_text(s)
PATCH
cat > CMakeLists.txt <<'INPUT_FILE'
cmake_minimum_required(VERSION 3.20)
project(PrivateFit LANGUAGES Fortran C)
set(QER /public/software/qe/7.6/8173m)
add_executable(fit-local.x fit-local.f90)
file(GLOB MODDIRS LIST_DIRECTORIES true ${QER}/include/qe/*)
target_include_directories(fit-local.x PRIVATE ${MODDIRS} /public/software/qe/deps/7.6/8173m/hdf5/include /public/software/qe/deps/7.6/8173m/libxc/include)
target_compile_options(fit-local.x PRIVATE -fpp -O2 -qopenmp -xCORE-AVX512 -qmkl=sequential)
target_compile_definitions(fit-local.x PRIVATE __MPI __MPI_MODULE __SCALAPACK __HDF5 __ELPA __DFTI __LIBXC)
file(GLOB QELIBS ${QER}/lib/*.a)
set(DEPS /public/software/qe/deps/7.6/8173m)
file(GLOB XCLIBS ${DEPS}/libxc/lib/libxcf03.a ${DEPS}/libxc/lib/libxc.a)
target_link_libraries(fit-local.x PRIVATE -Wl,--start-group ${QELIBS} ${XCLIBS} -Wl,--end-group ${DEPS}/elpa/lib/libelpa_openmp.so ${DEPS}/hdf5/lib/libhdf5_fortran.so ${DEPS}/hdf5/lib/libhdf5.so ${CMAKE_DL_LIBS} m /lib/x86_64-linux-gnu/libz.so.1)
target_link_options(fit-local.x PRIVATE -qopenmp -qmkl=sequential -Wl,--no-as-needed /public/toolkit/oneapi/2024.2/mkl/2024.2/lib/libmkl_scalapack_lp64.so.2 /public/toolkit/oneapi/2024.2/mkl/2024.2/lib/libmkl_blacs_intelmpi_lp64.so.2)
INPUT_FILE
本例是闭壳层 CH₄,5 个待处理态,第 4 个是最高占据态。常规 GWW 表开头两行是态数和自旋通道数,而独立拟合程序要求第一行是最高占据态编号,随后直接跟数据行。只在新的拟合目录内转换副本。
mv -n ch4-bands.dat bands.original
{ echo 4; tail -n +3 bands.original; } > ch4-bands.dat
cat > fit.in <<'INPUT_FILE'
&inputgww
ggwin%prefix='ch4'
ggwin%max_i=5,
ggwin%i_min=1
ggwin%i_max=5
ggwin%omega=20
ggwin%n=118,
ggwin%tau=11.8
ggwin%grid_freq=5
ggwin%second_grid_i=3
ggwin%second_grid_n=10
ggwin%omega_fit=20
ggwin%n_grid_fit=240
ggwin%n_fit=120,
ggwin%n_multipoles=4,
ggwin%starting_point=7,
ggwin%ending_point=7
ggwin%l_truncated_coulomb=.true.
ggwin%outdir='./'
/
INPUT_FILE
qe_job <<'QE_JOB'
cmake -S . -B build -DCMAKE_Fortran_COMPILER=mpiifx -DCMAKE_C_COMPILER=icx
cmake --build build -j2
./build/fit-local.x < fit.in > fit.out
grep "State:.*GW-PERT" fit.out
QE_JOB
2. graph.x 从离散能级生成展宽曲线#
留在拟合目录。graph.x 需要首行给出态数,然后是态编号和四列能量。沿用前一节 bands.original 的实际甲烷能级;以下取 −30 到 5 eV、0.15 eV 展宽、350 点,不读额外投影文件。当前 7.6 源码将第二个能量通道反复写到同一行,因此仅使用可正确逐行读取的 LDA、GW 和 HF 通道。
{ head -1 bands.original; tail -n +3 bands.original; } > qpe_range.dat
qe_job <<'QE_JOB'
printf '%s\n' -30 5 0.15 0 350 0 1 | graph.x > graph.log
head grafico_gw.dat
QE_JOB
grafico_gw.dat 的两列是能量轴和展宽强度。峰宽由输入控制;画能级对照图时要明确使用 GW、GW-PERT 或 LDA 的哪一列。
3. plotproj.x 用轨道权重筛选能带#
mkdir -p ~/qe-practice/select-band
cd ~/qe-practice/select-band
QE_SOURCE=/public/software/package/qe/7.6/source/q-e
该旧工具需要固定宽度的能带表和旧版投影格式,不能直接拿 atomic_proj.xml 替代。下面给出一个可执行的最小格式示范,1 个 k 点、2 条带,投影权重分别为 0.8、0.1。阈值 0.5 时只应留下第一条。保留文件中的空行和空格。
cat > band.input <<'INPUT_FILE'
2 1
0.0000 0.0000 0.0000
-2.0000 3.0000
INPUT_FILE
cat > proj.input <<'INPUT_FILE'
projection-format example
1 1 1 1 1 1 1 1
header
header
header
header
1 1 2
header
orbital 1
1 1 0.8000000000
1 2 0.1000000000
INPUT_FILE
cat > projplot.in <<'INPUT_FILE'
band.input
proj.input
band.sel
0.5
1
1 1
INPUT_FILE
qe_job <<'QE_JOB'
plotproj.x < projplot.in > select.out
cat band.sel
QE_JOB
4. path_interpolation.x 将已有 NEB 路径从 7 个镜像插值到 13 个#
mkdir -p ~/qe-practice/neb-path
cd ~/qe-practice/neb-path
QE_SOURCE=/public/software/package/qe/7.6/source/q-e
先用NEB 路径计算取得自己体系的 .path 文件。此例为三个原子的 H₃,7 个原始镜像。公共 7.6 程序读旧头 ENERGIES, POSITIONS AND GRADIENTS 时参数次序颠倒,会输出 an error occured reading 而且可能返回零。下面只改个人副本,然后按输出文件检查。
cp "$QE_SOURCE/NEB/src/path_interpolation.f90" path-local.f90
python3 - <<'PATCH'
from pathlib import Path
p=Path("path-local.f90")
s=p.read_text()
before='matches( input_line, &\n "ENERGIES, POSITIONS AND GRADIENTS" )'
assert s.count(before)==1
p.write_text(s.replace(before,'matches( "ENERGIES, POSITIONS AND GRADIENTS", &\n input_line )'))
PATCH
cat > CMakeLists.txt <<'INPUT_FILE'
cmake_minimum_required(VERSION 3.20)
project(PrivateFit LANGUAGES Fortran C)
set(QER /public/software/qe/7.6/8173m)
add_executable(path-local.x path-local.f90)
file(GLOB MODDIRS LIST_DIRECTORIES true ${QER}/include/qe/*)
target_include_directories(path-local.x PRIVATE ${MODDIRS} /public/software/qe/deps/7.6/8173m/hdf5/include /public/software/qe/deps/7.6/8173m/libxc/include)
target_compile_options(path-local.x PRIVATE -fpp -O2 -qopenmp -xCORE-AVX512 -qmkl=sequential)
target_compile_definitions(path-local.x PRIVATE __MPI __MPI_MODULE __SCALAPACK __HDF5 __ELPA __DFTI __LIBXC)
file(GLOB QELIBS ${QER}/lib/*.a)
set(DEPS /public/software/qe/deps/7.6/8173m)
file(GLOB XCLIBS ${DEPS}/libxc/lib/libxcf03.a ${DEPS}/libxc/lib/libxc.a)
target_link_libraries(path-local.x PRIVATE -Wl,--start-group ${QELIBS} ${XCLIBS} -Wl,--end-group ${DEPS}/elpa/lib/libelpa_openmp.so ${DEPS}/hdf5/lib/libhdf5_fortran.so ${DEPS}/hdf5/lib/libhdf5.so ${CMAKE_DL_LIBS} m /lib/x86_64-linux-gnu/libz.so.1)
target_link_options(path-local.x PRIVATE -qopenmp -qmkl=sequential -Wl,--no-as-needed /public/toolkit/oneapi/2024.2/mkl/2024.2/lib/libmkl_scalapack_lp64.so.2 /public/toolkit/oneapi/2024.2/mkl/2024.2/lib/libmkl_blacs_intelmpi_lp64.so.2)
INPUT_FILE
cat > path.in <<'INPUT_FILE'
3
7
13
1
7
h3.path
h3-new.path
20
CELL_PARAMETERS
1 0 0
0 1 0
0 0 1
INPUT_FILE
qe_job <<'QE_JOB'
cmake -S . -B build -DCMAKE_Fortran_COMPILER=mpiifx -DCMAKE_C_COMPILER=icx
cmake --build build -j2
./build/path-local.x < path.in > path.out
test -s h3-new.path
grep -c "Image:" h3-new.path
QE_JOB
输入依次是原子数、原始和目标镜像数、选取的首末镜像、旧新路径名、晶格尺度(Bohr)及晶格矩阵。本例的单位阵仅适用于所示立方盒;自己的计算要照原 NEB 晶胞填写。新文件用于路径初猜,实际势垒仍应使用优化后的 NEB 能量。
整理数据并画图#
回到生成 fit.out 的拟合目录。按同一态编号对照本征能与准粒子能级;例中第 1 态从约 −16.61 eV 移至 −23.52 eV。 在所述结果目录执行。图可用 MobaXterm 下载到本地。
module load ase/3.29.0
python - <<'PLOT'
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import re
from pathlib import Path
s=Path("fit.out").read_text()
a=re.findall(r"State:\s*(\d+)LDA\s*:\s*([-\d.]+).*? GW\s*:\s*([-\d.]+)",s)
state,lda,gw=zip(*[(int(i),float(e),float(q)) for i,e,q in a])
print(list(zip(state,lda,gw)))
plt.plot(state,lda,"o-",label="LDA"); plt.plot(state,gw,"s-",label="GW")
plt.xticks(state); plt.xlabel("State index"); plt.ylabel("Energy (eV)"); plt.legend()
plt.tight_layout()
plt.savefig("result.png", dpi=160)
PLOT
ls -lh result.png
