このリポジトリは「1回の注入 → vacancy_list / N_list → ヒストグラム」になっていたので、 注入位置 (x,y) を run ごとに変えた 10回分の結果をまとめてヒストグラム化できるようにしました。
-
tools/run_ensemble_implantation.py
- 既存の LAMMPS 入力ファイル(テンプレ)を複製し、run ごとに
variable seed equal ...variable x_pos equal ...variable y_pos equal ...を書き換えたrun_01 .. run_10フォルダを作ります。
- さらに
--lammps "..."を指定すれば各 run を連続実行もできます。
- 既存の LAMMPS 入力ファイル(テンプレ)を複製し、run ごとに
-
10Ncluster_implantation to C_0.5keV(final)/analysis3_graph_vacancy_list.py
- 複数の
vacancy_list(フォルダ指定/ワイルドカード指定)をまとめ読みして 1枚の分布ヒストグラムを出せます。
- 複数の
-
10Ncluster_implantation to C_0.5keV(final)/analysis2_graph_N_list3.py
- 複数入力をまとめ読みできます。
- LAMMPS dump を直接渡す場合に
--atom-type 3のように type フィルタできるようにしました(dump に type 列がある前提)。
- Python でグラフを保存するために
matplotlibが必要です。- 例:
python -m pip install matplotlib
- 例:
リポジトリルートで:
python tools/run_ensemble_implantation.py `
--template-dir "10Ncluster_implantation to C_5keV" `
--input "10atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt" `
--out "10Ncluster_implantation to C_5keV/runs" `
--runs 10 `
--seed 12345 `
--x-range -20 20 `
--y-range -20 20- bash では 改行継続にバッククォート ` は使いません(PowerShell 用です)。
- bash の改行継続は バックスラッシュ
\です。 - 迷ったら、まずは「1行」で実行してください(スペース入りパスは必ずダブルクォート)。
1行版(bash):
python3 tools/run_ensemble_implantation.py --template-dir "10Ncluster_implantation to C_5keV" --input "10atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt" --out "10Ncluster_implantation to C_5keV/runs" --runs 10 --seed 12345 --x-range -20 20 --y-range -20 20複数行版(bash):
python3 tools/run_ensemble_implantation.py \
--template-dir "10Ncluster_implantation to C_5keV" \
--input "10atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt" \
--out "10Ncluster_implantation to C_5keV/runs" \
--runs 10 \
--seed 12345 \
--x-range -20 20 \
--y-range -20 20python3 tools/run_ensemble_implantation.py --template-dir "10Ncluster_implantation to C_7keV(final)" --input "10atoms_7keV_N_implantation_to_C_ZBL_potential_filedata.txt" --out "10Ncluster_implantation to C_7keV(final)/runs" --runs 10 --seed 12345 --x-range -20 20 --y-range -20 20 --lammps "mpirun -np 8 lmp -in in.lmp"これで 10Ncluster_implantation to C_5keV/runs/run_01/in.lmp のように生成されます。
LAMMPS のコマンド名は環境により違います(lmp, lmp_mpi, lammps など)。例:
python tools/run_ensemble_implantation.py `
--template-dir "10Ncluster_implantation to C_5keV" `
--input "10atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt" `
--out "10Ncluster_implantation to C_5keV/runs" `
--runs 10 `
--seed 12345 `
--x-range -20 20 `
--y-range -20 20 `
--lammps "lmp -in in.lmp"例: N_implantation_to_C_random_5keV_noreset_10_10(final)/1atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt
このタイプのテンプレは LAMMPS入力の中で variable m loop 10 のように「10回の連続注入」を自前で回す作りになっています。
なので「10回連続注入」を さらに ensemble で10回(= 10注入×10run)やるには、
テンプレを run_01 .. run_10 に複製して 各runで乱数の基準seed(例: 12345/67890)だけを変えて LAMMPS を実行するのが簡単です。
ポイント:
- このテンプレは
x_pos/y_posを入力内でrandom(...)で決めます(Python側でx-range/y-rangeを渡す方式ではありません)。 12345+${m}/67890+${m}の「12345/67890」を run ごとに変えると、10回注入の乱数系列が run ごとに変わります。
--template-style loop-random-xy を使うと、連続注入テンプレ内の
rnd_seed/rnd_seed_yの基準値x_pos/y_posのrandom(xmin,xmax,...)の範囲
を run ごとに差し替えた run_01..run_10 を作り、そのまま LAMMPS まで実行できます。
python3 tools/run_ensemble_implantation.py \
--template-style loop-random-xy \
--template-dir "N_implantation_to_C_random_5keV_noreset_10_10(final)" \
--input "1atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt" \
--out "N_implantation_to_C_random_5keV_noreset_10_10(final)/runs_ensemble" \
--runs 10 \
--seed 12345 \
--x-range -4.6 4.6 \
--y-range -4.6 4.6 \
--lammps "mpirun -np 8 lmp -in in.lmp"$templateDir = "N_implantation_to_C_random_5keV_noreset_10_10(final)"
$templateIn = "1atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt"
$outRoot = "N_implantation_to_C_random_5keV_noreset_10_10(final)/runs_ensemble"
New-Item -ItemType Directory -Force $outRoot | Out-Null
for ($i=1; $i -le 10; $i++) {
$runDir = Join-Path $outRoot ("run_{0:D2}" -f $i)
New-Item -ItemType Directory -Force $runDir | Out-Null
# テンプレフォルダから必要ファイルをコピー(状況に応じて追加)
Copy-Item -Force (Join-Path $templateDir "*.data") $runDir -ErrorAction SilentlyContinue
Copy-Item -Force (Join-Path $templateDir "*.zbl") $runDir -ErrorAction SilentlyContinue
Copy-Item -Force (Join-Path $templateDir "*.tersoff*") $runDir -ErrorAction SilentlyContinue
# 入力ファイルを in.lmp として複製し、seed基準を run ごとに変更
$text = Get-Content (Join-Path $templateDir $templateIn) -Raw
$seedBaseX = 12345 + 1000*$i
$seedBaseY = 67890 + 1000*$i
$text = $text.Replace("variable rnd_seed equal 12345+${m}", "variable rnd_seed equal $seedBaseX+${m}")
$text = $text.Replace("variable rnd_seed_y equal 67890+${m}","variable rnd_seed_y equal $seedBaseY+${m}")
Set-Content -Path (Join-Path $runDir "in.lmp") -Value $text -Encoding utf8
# 実行(LAMMPSコマンドは環境に合わせて)
Push-Location $runDir
# 例: mpirun / lmp は環境で調整
mpirun -np 8 lmp -in in.lmp
Pop-Location
}template_dir="N_implantation_to_C_random_5keV_noreset_10_10(final)"
template_in="1atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt"
out_root="N_implantation_to_C_random_5keV_noreset_10_10(final)/runs_ensemble"
mkdir -p "$out_root"
for i in $(seq -w 1 10); do
run_dir="$out_root/run_$i"
mkdir -p "$run_dir"
cp -f "$template_dir"/*.data "$run_dir" 2>/dev/null || true
cp -f "$template_dir"/*.zbl "$run_dir" 2>/dev/null || true
cp -f "$template_dir"/*.tersoff* "$run_dir" 2>/dev/null || true
seed_base_x=$((12345 + 1000*10#$i))
seed_base_y=$((67890 + 1000*10#$i))
sed \
-e "s/variable rnd_seed equal 12345+\${m}/variable rnd_seed equal ${seed_base_x}+\${m}/" \
-e "s/variable rnd_seed_y equal 67890+\${m}/variable rnd_seed_y equal ${seed_base_y}+\${m}/" \
"$template_dir/$template_in" > "$run_dir/in.lmp"
(cd "$run_dir" && mpirun -np 8 lmp -in in.lmp)
done調整したい場合:
- 位置の範囲はテンプレ内の
random(-4.6,4.6,...)を基板サイズに合わせて調整してください。 - 各runが
dump_all.xyzやfinal_data_run_*.dataを出します(runフォルダ分けしているので上書きはしません)。
run_* をフォルダ指定で渡せます:
python "10Ncluster_implantation to C_0.5keV(final)/analysis3_graph_vacancy_list.py" `
"10Ncluster_implantation to C_5keV/runs/run_*" `
--out "vacancy_depths_ensemble.png" `
--surface-z 125 `
--bin-width 1Ubuntu/WSL(bash) 例(C_7keV(final) の runs から出す):
python3 "10Ncluster_implantation to C_0.5keV(final)/analysis3_graph_vacancy_list.py" \
"10Ncluster_implantation to C_7keV(final)/runs/run_*" \
--out "10Ncluster_implantation to C_7keV(final)/runs/vacancy_depths_ensemble.png" \
--surface-z 125 \
--bin-width 1analysis3_graph_vacancy_list2.py は、2つの vacancy_list(またはその親フォルダ)を指定して、
深さ分布を 線グラフ2本で同じ図に重ね描きして保存します。
前提(あなたの想定):
10Ncluster_implantation to C_5keV(final)と同じ階層にanalysis3_graph_vacancy_list2.pyを置く- 例:
10Ncluster_implantation to C_5keV(final)/analysis3_graph_vacancy_list2.py
- 例:
- 比較したい入力は
10Ncluster_implantation to C_5keV(final)/runs/run_01/vacancy_list10Ncluster_implantation to C_7keV(final)/runs/run_01/vacancy_list
PowerShell 例(リポジトリルートで実行):
python "10Ncluster_implantation to C_5keV(final)/analysis3_graph_vacancy_list2.py" `
--a "10Ncluster_implantation to C_5keV(final)/runs/run_01/vacancy_list" `
--b "10Ncluster_implantation to C_7keV(final)/runs/run_01/vacancy_list" `
--label-a "10cluster total 5keV" `
--label-b "10cluster 7keV" `
--surface-z 125 `
--bin-width 1 `
--out "vacancy_depths_5keV_vs_7keV_run01.png"Ubuntu/WSL(bash) 例:
python3 "10Ncluster_implantation to C_5keV(final)/analysis3_graph_vacancy_list2.py" \
--a "10Ncluster_implantation to C_5keV(final)/runs/run_01/vacancy_list" \
--b "10Ncluster_implantation to C_7keV(final)/runs/run_01/vacancy_list" \
--label-a "10cluster total 5keV" \
--label-b "10cluster 7keV" \
--surface-z 125 \
--bin-width 1 \
--out "vacancy_depths_5keV_vs_7keV_run01.png"補足:
--a/--bにはvacancy_listファイルだけでなく、run_01のような フォルダも指定できます(その場合はフォルダ内のvacancy_list.xyz / vacancy_list / vacancy_list.txtを自動探索します)。--bin-widthは「線グラフの刻み(ヒストグラムのビン幅)」です。滑らかにしたい場合は大きく(例: 2〜5Å)、細かく見たい場合は小さく(例: 1Å)します。
注意:
- このスクリプトは 引数なしで実行すると「スクリプトと同じフォルダ」にある
N_listを探します。 - runs 配下のデータで分布を作る場合は、必ず
run_*/...の 入力パターンを引数として渡してください。
dump_run_1_min0K.lammpstrj を直接読む例(N が type=3 の場合):
python "10Ncluster_implantation to C_0.5keV(final)/analysis2_graph_N_list3.py" `
"10Ncluster_implantation to C_5keV/runs/run_*/dump_run_1_min0K.lammpstrj" `
--atom-type 3 `
--out "nitrogen_depths_ensemble.png" `
--surface-z 125 `
--bin-width 5 `
--max-depth 250Ubuntu/WSL(bash) 例(C_7keV(final) の runs から出す):
python3 "10Ncluster_implantation to C_0.5keV(final)/analysis2_graph_N_list3.py" \
"10Ncluster_implantation to C_7keV(final)/runs/run_*/dump_run_1_min0K.lammpstrj" \
--atom-type 3 \
--out "10Ncluster_implantation to C_7keV(final)/runs/nitrogen_depths_ensemble.png" \
--surface-z 125 \
--bin-width 5 \
--max-depth 250補足:
- パスにスペースがあるので、
run_*/...の引数はダブルクォートで囲んでOKです。 その場合でもスクリプト側でワイルドカードを展開して読み込みます。 --max-depth 250を付けると、基板厚(例: 250Å)より深い値(底から抜けた原子など)を描画から除外できます。
事前確認(ファイルが本当にあるか):
ls "10Ncluster_implantation to C_7keV(final)/runs/run_01"
ls "10Ncluster_implantation to C_7keV(final)/runs/run_01/dump_run_1_min0K.lammpstrj"--x-range/--y-rangeは「基板の有効領域(表面の中央付近)」に合わせて調整してください。--surface-zは基板モデルの表面 z に合わせてください(いまは既存スクリプトと同じ125 Åをデフォルトにしています)。
原因はほぼ次のどれかです:
--template-dirのフォルダ名が実際と違う(例:...finalが付いている等)--inputのファイル名が実際と違う(keV値や_filedataの有無など)- 実行しているカレントディレクトリがリポジトリルートではない
bash/WSL なら、まず次で「存在する名前」を確認してコピペしてください:
pwd
ls
ls "10Ncluster_implantation to C_5keV"その上で、--template-dir と --input を 実在する名前 に合わせます。
まず、どのエラーでも共通で次を確認してください:
# リポジトリルートにいるか確認
pwd
ls
# runフォルダに必要ファイルがあるか確認(例: run_01)
ls "10Ncluster_implantation to C_7keV(final)/runs/run_01"よくある原因:
ModuleNotFoundError: No module named 'matplotlib'- 対処:
python3 -m pip install --user matplotlib
- 対処:
...入力が見つかりません(vacancy_list / dump が無い)- N分布: 各runに
dump_run_1_min0K.lammpstrjがあるか確認 - vacancy分布: 各runに
vacancy_list(または vacancy_list.xyz 等)が必要です(OVITO等でrunごとに出力)
- N分布: 各runに
- パスにスペースがある
- 対処: 文字列は必ずダブルクォートで囲む(例:
"10Ncluster_implantation to C_7keV(final)/...")
- 対処: 文字列は必ずダブルクォートで囲む(例:
こちらで原因を特定するため、エラーが出たときは「実行したコマンド」と「Traceback全文」をそのまま貼ってください。
2つのコマンド例は、どちらも tools/run_ensemble_implantation.py が
テンプレート入力を複製して run_01 〜 run_10 を作り、各 run で 変数(seed / 注入位置 or 乱数基準seed)だけを差し替えることで実現しています。
共通の仕組み(どのテンプレでも同じ):
--runs 10によりrun_01〜run_10の 10フォルダを作ります(run_{i:02d}形式)。- それぞれの run フォルダに
- テンプレフォルダから
*.data,*.zbl,*.tersoff*(--copyで変更可)をコピー - 入力ファイルをパッチして
in.lmpとして保存 - 実際に差し替えた値を
run_params.txtに保存
- テンプレフォルダから
--lammps "..."を付けると、各 run フォルダをカレントにして、そのコマンドを run_01 → run_02 → … → run_10 の順に逐次実行します。
つまり「run10までやってる」のは、LAMMPS 側ではなく Python 側の --runs 10 の for ループです。
例(あなたのコマンド):
python3 tools/run_ensemble_implantation.py --template-dir "10Ncluster_implantation to C_7keV(final)" --input "10atoms_7keV_N_implantation_to_C_ZBL_potential_filedata.txt" --out "10Ncluster_implantation to C_7keV(final)/runs" --runs 10 --seed 12345 --x-range -20 20 --y-range -20 20 --lammps "mpirun -np 8 lmp -in in.lmp"このケースでは、各 run_XX/in.lmp の中で次の行を runごとに直接書き換えます:
variable seed equal ...variable x_pos equal ...variable y_pos equal ...
runごとの値の決まり方(実装):
- 乱数生成器は
random.Random(--seed)で初期化され、x_pos/y_posはそこから一様乱数で作られます。--seed 12345を固定すると、毎回同じrun_01..run_10が再現されます。
seedはseed_i = (--seed) + i(i は 1..10)になります。- 例:
run_01は 12346、run_10は 12355。
- 例:
ここでいう「10回」は **10回の独立な単発注入(初期状態から開始)**です。 (テンプレ側が「前runの最終構造を読み込む」作りでない限り、run間で状態は引き継がれません)
例(あなたのコマンド):
python3 tools/run_ensemble_implantation.py \
--template-style loop-random-xy \
--template-dir "N_implantation_to_C_random_5keV_noreset_10_10(final)" \
--input "1atoms_5keV_N_implantation_to_C_ZBL_potential_filedata.txt" \
--out "N_implantation_to_C_random_5keV_noreset_10_10(final)/runs_ensemble" \
--runs 10 \
--seed 12345 \
--x-range -4.6 4.6 \
--y-range -4.6 4.6 \
--lammps "mpirun -np 8 lmp -in in.lmp"このケースは「連続注入(noreset)」テンプレが、LAMMPS 入力内部で注入ループ(例: variable m loop 10)を回し、
注入位置も入力内部の random(...) で決める前提です。
そのため Python は x_pos/y_pos を数値に固定せず、テンプレ内の次の行を runごとに差し替えます:
variable rnd_seed equal ...(連続注入ループで使う乱数seedの“基準値”)variable rnd_seed_y equal ...variable x_pos equal random(xmin,xmax,${rnd_seed})(random の範囲だけ)variable y_pos equal random(ymin,ymax,${rnd_seed_y})
runごとの値の決まり方(実装):
seed_x_base = (--seed) + 1000*iseed_y_base = (--seed) + 50000 + 1000*ix_pos/y_posの範囲は--x-range/--y-rangeをそのままrandom(xmin,xmax,...)に反映
注意:
- この
loop-random-xyでは、Python 側の乱数(random.Random(...))は注入位置の生成に使いません。--seedは「テンプレ内で使う rnd_seed の基準値」を runごとにずらすための元になります。
例として、コマンドが次だとします(あなたの例と同じ値):
--runs 10--seed 12345--x-range -4.6 4.6--y-range -4.6 4.6
このとき Python が各 run の in.lmp に書き込むのは、概ね次の形です(${m} はテンプレ側の loop 変数):
variable rnd_seed equal seed_x_base+${m}variable rnd_seed_y equal seed_y_base+${m}variable x_pos equal random(-4.6,4.6,${rnd_seed})variable y_pos equal random(-4.6,4.6,${rnd_seed_y})
そして seed_x_base / seed_y_base は run 番号 i(run_01 なら i=1)から次で決まります:
seed_x_base = 12345 + 1000*iseed_y_base = 12345 + 50000 + 1000*i
なので具体的には:
-
run_01(i=1)
seed_x_base = 13345seed_y_base = 63345- もしテンプレが
variable m loop 10(m=1..10)なら- x側 seed:
rnd_seed = 13345+${m}→ 13346, 13347, …, 13355 - y側 seed:
rnd_seed_y = 63345+${m}→ 63346, 63347, …, 63355 - 各 m ごとに
x_pos=random(-4.6,4.6,<その時のseed>)、y_pos=random(-4.6,4.6,<その時のseed>)が1回ずつ決まり、合計10回の (x,y) が生成されます。
- x側 seed:
-
run_02(i=2)
seed_x_base = 14345seed_y_base = 64345- m=1..10 のとき
- x側 seed: 14346..14355
- y側 seed: 64346..64355
ポイント:
- run_01 と run_02 は「基準seed」が違うので、同じ
m=1..10を回しても (x,y) の系列が別物になります。 --x-range/--y-rangeは 範囲を変えるだけで、「10回回す」はテンプレ内の loop 回数(例:loop 10)で決まります。
連続照射(10回照射)をやりたいとき、次の2パターンは物理的な意味が変わります。
- 同一run内で連続(テンプレ内で loop 10)
- 1つの run フォルダで LAMMPS を1回走らせ、その入力の中で注入を10回繰り返します。
- noreset テンプレなら、照射ダメージが蓄積した状態で次の注入が行われます。
- run を分けて実行(run_01..run_10 を別々に走らせる)
template-style simpleの 10回は、基本的に 初期状態からの単発注入×10回の独立試行です。template-style loop-random-xyの 10回は、「10連続照射」を1セットとしてそれを独立に10回(= 10照射×10run)やる、という意味になります。
- (重要)runを分けて「連続照射を繋ぐ」
- 「run_01 の最終構造を run_02 が読み、さらに1照射…」のように、run間で状態を引き継いで連続照射したい場合、 現状の tools/run_ensemble_implantation.py はその“チェーン”を自動生成しません。
- 実現するには、テンプレ入力側で
read_data/read_restartの参照先を前runの出力に向ける(または手動で run を1つのフォルダで連続実行する)必要があります。