kpath_pymatgen.py ダウンロード/コピー
kpath_pymatgen.py
kpath_pymatgen.py
1"""
2pymatgen を用いて結晶構造の高対称k点経路を計算し表示するスクリプト。
3
4概要:
5 入力された結晶構造のBravais格子に基づいて高対称k点経路を計算し、表示します。
6
7詳細説明:
8 このスクリプトは、指定されたCIFファイルから結晶構造を読み込み、
9 その原始構造 (`primitive structure`) に基づいて高対称k点経路を生成します。
10 経路タイプは `hinuma` (Hinuma et al. 2017) または `sc` (Setyawan-Curtarolo 2010)
11 から選択でき、デフォルトは `hinuma` です。
12 計算されたk点経路のセグメントと、各高対称点の分数座標を標準出力に表示します。
13 コマンドライン引数を使用することで、入力ファイルと経路タイプを動的に指定できます。
14 例: `python kpath_pymatgen.py my_structure.cif sc`
15
16引数 (Parameters):
17 :param sys.argv[1]: (str, optional) 入力CIFファイルへのパス。デフォルトは 'ZnO.cif' です。
18 :param sys.argv[2]: (str, optional) 使用する高対称k点経路のタイプ。'hinuma' (デフォルト) または 'sc'。
19
20戻り値 (Returns):
21 :returns: None. 計算結果は標準出力に表示されます。エラーが発生した場合はメッセージを表示し終了します。
22
23関連リンク:
24 :doc:`kpath_pymatgen_usage`
25"""
26
27import sys
28from pymatgen.core import Structure
29from pymatgen.symmetry.bandstructure import HighSymmKpath
30
31infile = 'ZnO.cif'
32path_type = "hinuma" # hinuma: Hinuma–Pizzi–Kumagai–Oba–Tanaka (2017)
33 # sc: Setyawan–Curtarolo (2010)
34
35if __name__ == "__main__":
36 if len(sys.argv) > 1:
37 infile = sys.argv[1]
38 if len(sys.argv) > 2:
39 path_type = sys.argv[2]
40
41
42def main():
43 structure = Structure.from_file(infile)
44 prim = structure.get_primitive_structure()
45
46# 高対称点と経路を生成
47 kpath = HighSymmKpath(prim, path_type = path_type)
48 if kpath is None or kpath.kpath is None:
49 print(f"\nError: Could not get k path for [{infile}] with the path_type={path_type}\n")
50 exit()
51
52# 経路の定義を見やすく表示
53 print("\n=== k-path 経路 ===")
54 for segment in kpath.kpath["path"]:
55 print(" → ".join(segment))
56
57# 高対称点座標を見やすく表示
58 print("\n=== 高対称点座標 ===")
59 for point, coord in kpath.kpath["kpoints"].items():
60 print(f"{point:3s} : {coord}")
61
62
63if __name__ == '__MAIN__':
64 main()
65