電子密度の解析

電子密度の断面図とラインプロファイル

電子密度を NumPy 配列として取り出し、結合を含む面での 2 次元マップと、結合に沿った 1 次元プロファイルを描きます。

カテゴリ
電子密度の解析
使用する機能
calc.rhomatplotlibscipy.ndimage.map_coordinates
スクリプト
density_plot.py

電子密度は NumPy 配列として扱えるので、Matplotlib でそのまま可視化できます。ここでは Si 結晶を例に、Si-Si 結合のジグザグ鎖を含む (1-10) 面の電子密度マップと、結合に沿ったラインプロファイルを描きます。

density_plot.pyダウンロード
"""
Advance/OF-DFT example: plot the electron density on a plane and along a bond.

Copyright (C) 2026 AdvanceSoft Corporation, All rights reserved.
"""

import matplotlib.pyplot as plt
import numpy as np
from ase.build import bulk
from scipy.ndimage import map_coordinates

from aofdft.calculator import AOFDFTCalculator

VPS_DIR = "path/to/DFT_DATA19_AS/VPS"  # edit these two paths for your environment
PAO_DIR = "path/to/DFT_DATA19_AS/PAO"

a     = 5.43
atoms = bulk("Si", crystalstructure="diamond", a=a, cubic=True)

atoms.calc = AOFDFTCalculator(
    console      = False,
    logging_file = "si_density.log",
    kin_type     = "AS26",
    kin_model    = "Crystal26",
    vps_dir      = VPS_DIR,
    pao_dir      = PAO_DIR,
)
atoms.get_potential_energy()

density    = atoms.calc.rho[0].detach().cpu().numpy()  # (na, nb, nc), e/Bohr^3
na, nb, nc = density.shape

# ---------------------------------------------------------------------------
# 1) 2D map on the (1-10) plane, which contains the zigzag chain of Si-Si bonds.
#    In the cubic cell this plane is x = y, i.e. the grid points density[i, i, k].
# ---------------------------------------------------------------------------
idx   = np.arange(na)
plane = density[idx, idx, :]              # shape (na, nc)
plane = np.vstack([plane, plane[:1]])     # close the periodic image along [110]
plane = np.hstack([plane, plane[:, :1]])  # ... and along [001]

u = np.linspace(0.0, a * np.sqrt(2.0), na + 1)  # distance along [110] (Angstrom)
z = np.linspace(0.0, a, nc + 1)                 # distance along [001] (Angstrom)

fig, ax = plt.subplots(figsize=(6.4, 4.6))
cs = ax.contourf(u, z, plane.T, levels=24, cmap="viridis")
fig.colorbar(cs, ax=ax, label=r"Electron density ($e$/Bohr$^3$)")

# mark the atoms lying on the plane (x = y), including periodic images at the cell edges
on_plane = [p for p in atoms.positions if abs(p[0] - p[1]) < 1.0e-6]
for p in on_plane:
    for du in (0.0, a * np.sqrt(2.0)):
        for dz in (0.0, a):
            uu, zz = p[0] * np.sqrt(2.0) + du, p[2] + dz
            if uu <= u[-1] + 1.0e-6 and zz <= z[-1] + 1.0e-6:
                ax.plot(uu, zz, "o", color="white", markeredgecolor="black", markersize=7)

ax.set_xlabel("[110] (Angstrom)")
ax.set_ylabel("[001] (Angstrom)")
ax.set_aspect("equal")
fig.tight_layout()
fig.savefig("si_density_plane.png", dpi=150)
print("Saved si_density_plane.png")

# ---------------------------------------------------------------------------
# 2) line profile along a Si-Si bond: from the atom at (0, 0, 0) to (a/4, a/4, a/4).
#    The density is interpolated on the periodic grid.
# ---------------------------------------------------------------------------
start, end = np.array([0.0, 0.0, 0.0]), np.array([a / 4, a / 4, a / 4])
t          = np.linspace(-0.5, 1.5, 201)  # extend the line beyond both atoms
points     = start + t[:, None] * (end - start)

frac   = points @ np.linalg.inv(atoms.cell.array)              # fractional coordinates
coords = (frac * np.array([na, nb, nc])).T                     # grid coordinates, shape (3, npoint)
line   = map_coordinates(density, coords, order=3, mode="grid-wrap")
dist   = t * np.linalg.norm(end - start)

fig, ax = plt.subplots(figsize=(6.4, 3.6))
ax.plot(dist, line)
ax.axvline(0.0, color="gray", linestyle=":")
ax.axvline(np.linalg.norm(end - start), color="gray", linestyle=":")
ax.set_xlabel("Distance along the Si-Si bond (Angstrom)")
ax.set_ylabel(r"Electron density ($e$/Bohr$^3$)")
fig.tight_layout()
fig.savefig("si_density_line.png", dpi=150)
print("Saved si_density_line.png")

実行結果の例

Si の (1-10) 面における電子密度。白丸は面上の Si 原子で、原子間の結合上に電子が集まっている様子がわかります。
Si の (1-10) 面における電子密度。白丸は面上の Si 原子で、原子間の結合上に電子が集まっている様子がわかります。
Si-Si 結合に沿った電子密度のプロファイル。点線は Si 原子の位置。
Si-Si 結合に沿った電子密度のプロファイル。点線は Si 原子の位置。

ポイント

  • 立方晶のセルでは、(1-10) 面は x = y を満たす点の集合です。a 軸と b 軸のグリッド数が等しいので、density[i, i, k] を取り出すだけで断面が得られます。
  • 任意の点での値が必要な場合は、scipy.ndimage.map_coordinates でグリッド上の密度を補間します。mode="grid-wrap" を指定すると周期境界条件が考慮されます。
  • 補間に渡す座標はグリッド座標 (分率座標 × グリッド数) です。直交座標からは points @ inv(cell) で分率座標に変換できます。
  • ノルム保存型擬ポテンシャルの価電子密度なので、原子核の位置では密度が小さくなります。