这是一个轻量级 Python 脚本,用于从 DMol3 结果中计算功函数:
- 静电势网格文件:
*.grd - 费米能级:
*.outmol
输出内容包括:
- 平面平均静电势
V(z) - 自动识别真空平台
V_vac - 功函数:Φ = V_vac − E_F
- 一张Materials Studio 风格的功函数图(使用分数坐标并可做周期延展显示)
- 与 Materials Studio 作图习惯一致
- 强制符号约定:
V_plot(z) = - V_grd(z) - 将真空平台在图中平移到 0 eV
- 强制符号约定:
- 鲁棒的真空平台自动识别
- 全局平台检测 + 兜底滑动窗口(困难体系不会直接报错崩溃)
- 支持超大 .grd 文件
- 采用流式读取与计算,降低内存压力
- MS 风格横坐标
- 使用分数坐标
z/c - 支持周期延展(例如 0.1–1.1 会显示 1.0–1.1 的曲线数据)
- 使用分数坐标
pip install -r requirements.txt示例 1:标准运行(默认 MS 风格 0.1–1.1)
python dmol3_wf_stream_style_final.py --grd NCS.grd --outmol NCS.outmol --prefix NCS示例 2:调整横坐标范围
python dmol3_wf_stream_style_final.py --grd NCS.grd --outmol NCS.outmol --prefix NCS --xlim -0.1 1.2示例 3:COF 等“平台较难识别”的体系 尝试更强的平滑与更宽松的平台判据:
python dmol3_wf_stream_style_final.py --grd COF-WF_potential.grd --outmol COF-WF.outmol --prefix COF --smooth-w 41 --slope-percentile 80以 --prefix NCS 为例,会得到:
NCS_Vz.csv
列:z_A, fractional_z, V_plot_eV(=-Vgrd), V_shift_eV(vac=0)NCS_Vz_raw.png
符号翻转后的原始平面平均V(z)(尚未平移真空到 0 eV)NCS_WF_style.png
MS 风格功函数图(真空线在 0 eV、费米能级线与 Φ 箭头)
*.grd必须是 DMol3 的 electrostatic potential(静电势) 网格文件。- 脚本强制使用
V_plot = -V_grd以匹配 Materials Studio 的符号约定。 - 真空能级
V_vac来自平面平均V(z)的真空平台区间平均值。 - 功函数计算公式:
[
\Phi = V_{vac} - E_F
]
其中
E_F从 outmol 解析得到(单位 eV)。
--xlim XMIN XMAX:分数坐标 x 轴范围(默认0.10 1.10)- 若
XMAX > 1,脚本会自动做周期延展,显示1.0–1.1(与 MS 一致)
- 若
--smooth-w N:平滑窗口(默认17)--slope-percentile P:平坦判据分位数(默认30)--prefer-frac F0 F1:偏好的真空平台范围(默认0.25 0.95)--order xyz|xzy|...:如果曲线形态异常,尝试更换网格顺序--chunk-mb N:超大网格可降低(如8)以减少内存占用
更多参数请查看脚本头部 docstring。
MIT License,见 LICENSE。
A lightweight Python script to compute work function from DMol3:
- Electrostatic potential grid:
*.grd - Fermi energy:
*.outmol
It outputs:
- Planar-averaged potential
V(z) - Automatically detected vacuum plateau
V_vac - Work function: Φ = V_vac − E_F
- A Materials Studio-like work-function plot (fractional coordinate with periodic extension)
- Matches Materials Studio plot convention
- Enforces sign convention:
V_plot(z) = - V_grd(z) - Shifts vacuum plateau to 0 eV in the plot
- Enforces sign convention:
- Robust vacuum detection
- Global plateau detection + fallback sliding-window (no hard crash on difficult cases)
- Huge .grd supported
- Streaming parser for large text grids
- MS-like x-axis
- Fractional coordinate
z/c - Optional periodic extension (e.g., 0.1–1.1 shows data in 1.0–1.1)
- Fractional coordinate
pip install -r requirements.txtExample 1: Standard run (MS-like 0.1–1.1)
python dmol3_wf_stream_style_final.py --grd NCS.grd --outmol NCS.outmol --prefix NCSExample 2: Adjust x-axis range
python dmol3_wf_stream_style_final.py --grd NCS.grd --outmol NCS.outmol --prefix NCS --xlim -0.1 1.2Example 3: COF-like cases (plateau harder to detect) Try stronger smoothing + looser flatness threshold:
python dmol3_wf_stream_style_final.py --grd COF-WF_potential.grd --outmol COF-WF.outmol --prefix COF --smooth-w 41 --slope-percentile 80For --prefix NCS, you will get:
NCS_Vz.csv
Columns:z_A, fractional_z, V_plot_eV(=-Vgrd), V_shift_eV(vac=0)NCS_Vz_raw.png
Raw planar-averagedV(z)after sign flip (before vacuum shift)NCS_WF_style.png
MS-like work function plot (vacuum level at 0 eV, Fermi level, Φ arrow)
- The
*.grdmust be DMol3 electrostatic potential grid. - The script forces
V_plot = -V_grdto match Materials Studio convention. - Vacuum level
V_vacis obtained from the planar-averaged potentialV(z)vacuum plateau. - Work function is computed as:
[
\Phi = V_{vac} - E_F
]
where
E_Fis parsed fromoutmol(eV).
--xlim XMIN XMAX: fractional-coordinate x-axis limits (default0.10 1.10)- if
XMAX > 1, the curve is periodically extended to show1.0–1.1like MS
- if
--smooth-w N: smoothing window (default17)--slope-percentile P: flatness threshold percentile (default30)--prefer-frac F0 F1: preferred vacuum region (default0.25 0.95)--order xyz|xzy|...: try different grid orders if curve shape looks wrong--chunk-mb N: lower it (e.g.,8) for huge grids or low-memory machines
See the script docstring for the full argument list.
MIT License. See LICENSE.