解析機能
Analysis
Section titled “Analysis”FBTKの解析機能は、ASE オブジェクトや Trajectory データを直接受け取り、Rust エンジンで高速に処理します。
ASE オブジェクトの直接解析
Section titled “ASE オブジェクトの直接解析”fbtk.compute_rdf や fbtk.compute_msd は、ASE の Atoms オブジェクトやそのリストを直接引数に取ることができます。
RDF の例: 銅結晶の解析
Section titled “RDF の例: 銅結晶の解析”import fbtkfrom ase.build import bulk
# 銅の FCC 結晶を作成 (4x4x4 supercell, 256 atoms)atoms = bulk('Cu', 'fcc', a=3.614) * (4, 4, 4)
# RDF を計算 (r_max=10.0 A, 100 bins)r, g_r = fbtk.compute_rdf(atoms, query="element Cu", r_max=10.0, n_bins=100)
# ピーク付近のデータを表示print("RDF Result (Cu FCC):")for i in range(20, 50): print(f" r = {r[i]:.2f} A, g(r) = {g_r[i]:.2f}")出力例:
RDF Result (Cu FCC): r = 2.05 A, g(r) = 0.00 r = 2.15 A, g(r) = 0.00 r = 2.25 A, g(r) = 0.00 r = 2.35 A, g(r) = 0.00 r = 2.45 A, g(r) = 0.00 r = 2.55 A, g(r) = 17.33 <-- 第1近接ピーク r = 2.65 A, g(r) = 0.00 ... r = 3.55 A, g(r) = 0.00 r = 3.65 A, g(r) = 4.23 <-- 第2近接ピーク r = 3.75 A, g(r) = 0.00 ... r = 4.35 A, g(r) = 0.00 r = 4.45 A, g(r) = 7.28 <-- 第3近接ピーク r = 4.55 A, g(r) = 0.00MSD の例: 軌跡データの解析
Section titled “MSD の例: 軌跡データの解析”拡散係数の見積もりに必要な MSD を高速に計算します。
import fbtkfrom ase.io import read
# Trajectory ファイルを読み込み (例: 100フレーム)traj = read("traj.lammpstrj", index=":")
# MSD を計算# dt: フレーム間の時間間隔 (例: 1000ステップごとに保存し、1step=1fs なら dt=1000)res = fbtk.compute_msd(traj, query="resname SOL", dt=1000.0)
# 結果を表示print("MSD Result:")for i in range(4): print(f" t = {res['time'][i]:.1f}, MSD = {res['msd'][i]:.3f}")出力例:
MSD Result: t = 0.0, MSD = 0.000 t = 1000.0, MSD = 0.005 t = 2000.0, MSD = 0.018 t = 3000.0, MSD = 0.033スマートクエリのセマンティクス
Section titled “スマートクエリのセマンティクス”クエリ内では、原子グループを絞り込む and と、ペアを定義するセパレータ(with または -)を使い分けます。
1. グループの絞り込み (and, or)
Section titled “1. グループの絞り込み (and, or)”単一のグループを定義する際に、条件を組み合わせます。
resname SOL and element O: 「残基名が SOL」かつ「元素が O」である原子のグループ。
2. ペアの定義 (with または -)
Section titled “2. ペアの定義 (with または -)”RDF 解析において、相関を見る 2 つのグループを分けるために使用します。
GroupA with GroupBまたはGroupA - GroupB: GroupA(ソース)と GroupB(ターゲット)の間のペアを定義します。
# 例: 水分子(WAT)の中の酸素(O)と、溶質(ION)の間の相関fbtk.compute_rdf(atoms, query="resname WAT and element O with resname ION")具体的なクエリ例
Section titled “具体的なクエリ例”1. 元素と残基名
Section titled “1. 元素と残基名”element C: 炭素原子すべて。resname POLY: 残基名が POLY の原子すべて。
2. インデックス (原子 ID) の直接指定
Section titled “2. インデックス (原子 ID) の直接指定”多数の原子をピンポイントで指定したり、範囲で指定したりできます。
index 0 1 2 5 10: 特定の原子 ID をリストアップ。index 0 to 99: 原子 ID 0 から 99 までを選択。index 0 to 49 with index 50 to 99: 特定の ID 範囲間の相関を計算。
ASE 互換の高速解析機能
Section titled “ASE 互換の高速解析機能”ASE の Atoms オブジェクトに対してよく行われる計算も Rust で高速化されています。
# System オブジェクト (system = builder.build()) からの解析distances = system.get_all_distances(mic=True) # 周期境界 (PBC) を考慮した最短距離com = system.get_center_of_mass() # 重心計算neighbors = system.get_neighbor_list(cutoff=5.0) # 近傍リスト取得