Repomixを実行するApptainerコンテナのビルド手順とRepomixの利用例 (ChatGPT & Boltz-2)
※ コードブロック における 🥭 は、プロンプトを表している
以下、本記事を執筆した際の自宅環境。
| specifications | |
|---|---|
CPU |
Ryzen 7 5700X (AMD) |
グラフィックボード |
GeForce RTX 2080 Ti VENTUS GP OC (MSI) |
メモリ |
DDR4-3200 32 GB×2 (Crucial) |
| version | |
|---|---|
Windows 10 |
22H2 |
NVIDIA グラフィクス ドライバー |
576.52 |
WSL2 |
2.5.7.0 |
Ubuntu on WLS2 |
24.04 LTS |
Apptainer |
1.4.1 |
Repomixについて
とにかくケチりたい、そんな気持ちで作ったツールの話です。
元々開発にCline (Claude Dev) やAiderなどの開発ツールを駆使していました。
ただ、APIの料金が常に心配で、できる限り安く済ませたい気持ちもあり、Claude Proを契約してWeb版にファイルを1つ1つアップロードする日々を過ごしていました。ある日それが面倒になってきて「全部1ファイルにしたらいい感じに読み込んでくれるのでは?」と思い、作ってみたら思いのほかうまくいったので公開しました。
GitHubのリポジトリは GitHub | yamadashy/repomix です。
ChatGPT などに任意のGitHubリポジトリを背景情報として与えたい際、リポジトリを .xml などの1ファイルにまとめることで、ファイル添付しやすくするためのツールのようです (知らなかった)。
(あんまり需要はなさそうだけど) 以下ではRepomix 用の Apptainer コンテナのビルドガイドと簡単な利用例を紹介します! Apptainer を使うことで、外部ネットワークへの接続を遮断した状態での利用が可能です (仕事で使う場合は精神衛生上大事)。
Apptainer 関係については、別記事を参照ください。
🥭 Apptainerコンテナのビルド
任意のディレクトリに以下のような repomix-v1.1.0.def を作成します。
BootStrap: docker
From: ubuntu:24.04
%post
# localtime関係のWARNINGに対処
touch /etc/localtime
# 必要なパッケージのインストール (冗長)
apt update && apt upgrade -y
apt install -y build-essential git curl wget aria2 zip nodejs npm
# localeにen_US.UTF-8を追加する (WSL2だけで使用するなら不要)
apt install -y locales
locale-gen en_US.UTF-8
# node.jsとnpmの安定板をインストールする
npm install n -g
n stable
# apt関係のお掃除
apt purge -y nodejs npm
rm -rf /var/lib/apt/lists/* && apt autoremove -y && apt clean
# repomixのインストール
export PATH="/usr/local/bin:${PATH}"
npm install -g repomix
%environment
# repomixにPATHを通す
export PATH="/usr/local/bin:${PATH}"
%runscript
# コンテナ実行時のスクリプトを定義
# "$@"は追加の引数を利用するための設定
exec "$@"
続いて以下のように repomix-v1.1.0.sif をビルドします ( もちろん .def の場所などは任意です )。
🥭 apptainer build ./repomix-v1.1.0.sif ./def_file/repomix-v1.1.0.def
🥭 Repomixを使ってみる
~/.bashrcの編集
必須ではないですが、以下のように ~/.bashrc でコマンドを定義しておくと便利です。
# Apptainer
export APPTAINER_IMAGE="/mnt/d/apptainer_image"
# repomix
function repomix-app() {
apptainer run \
--net --network none \
--bind /mnt/d \
${APPTAINER_IMAGE}/repomix-v1.1.0.sif repomix "$@"
}
/mnt/d/apptainer_image は任意の場所です。ここにビルドした .sif を配置しておきます。
--net --network none でコンテナから外部ネットワークへの接続を遮断します。
--bind /mnt/d でコンテナが /mnt/d 以下にアクセスできるようにしています (ホームディレクトリ内での作業であれば --bind によるマウント指定は不要です)。
外部ネットワークへの接続遮断を確認
repomix --remote 'github url' (ここでは repomix-app であることに注意) で公開リポジトリについて1ファイル集約が可能ですが、上記の --net --network none によりこれが無効かされているはずです。
例えば Boltz-2 のリポジトリについてやってみます。
🥭 repomix-app --remote https://github.com/jwohlwend/boltz
📦 Repomix v1.1.0
✖ Archive download failed, trying git clone...
Clone repository: https://github.com/jwohlwend/boltz.git to temporary directory. path: /tmp/repomix-lqA5QF
✖ Error during repository cloning. cleanup...
✖ Failed to clone repository: Command failed: git clone --depth 1 https://github.com/jwohlwend/boltz.git /tmp/repomix-lqA5QF
Cloning into '/tmp/repomix-lqA5QF'...
fatal: unable to access 'https://github.com/jwohlwend/boltz.git/': Could not resolve host: github.com
Need help?
• File an issue on GitHub: https://github.com/yamadashy/repomix/issues
• Join our Discord community: https://discord.gg/wNYzTwZFku
こんな感じで接続が遮断されました。
--net --network none を削除すれば普通に動作します (ここでは省略)。
ローカルリポジトリに対するRepomixの実行
それではローカルにクローンしておいたリポジトリに対して実行してみましょう。
🥭 git clone https://github.com/jwohlwend/boltz
🥭 repomix-app ./boltz
📦 Repomix v1.1.0
No custom config found at repomix.config.json5, repomix.config.jsonc, repomix.config.json or global config at /home/hoge/.config/repomix/repomix.config.json5, /home/hoge/.config/repomix/repomix.config.jsonc, /home/hoge/.config/repomix/repomix.config.json.
You can add a config file for additional settings. Please check https://github.com/yamadashy/repomix for more information.
✔ Packing completed successfully!
📈 Top 5 Files by Token Count:
──────────────────────────────────────────────────
1. examples/msa/seq1.a3m (33,356 tokens, 112,688 chars, 9.1%)
2. src/boltz/data/feature/featurizerv2.py (20,552 tokens, 91,118 chars, 5.6%)
3. src/boltz/data/parse/schema.py (13,046 tokens, 60,299 chars, 3.5%)
4. src/boltz/data/parse/mmcif_with_constraints.py (11,424 tokens, 51,472 chars, 3.1%)
5. src/boltz/model/models/boltz1.py (11,250 tokens, 51,872 chars, 3.1%)
🔎 Security Check:
──────────────────
✔ No suspicious files detected.
📊 Pack Summary:
────────────────
Total Files: 129 files
Total Tokens: 368,228 tokens
Total Chars: 1,506,305 chars
Output: repomix-output.xml
Security: ✔ No suspicious files detected
🎉 All Done!
Your repository has been successfully packed.
💡 Repomix is now available in your browser! Try it at https://repomix.com
こんな感じでうまく動作しました。
ChatGPT等に投げる際には、トークン数の節約も重要です。
📈 Top 5 Files by Token Count: を確認して、いらなそうなファイルは除外してしまうのも手です ( repomix-app --ignore "**/*.a3m" ./boltz )。
あるいは以下のように、必要そうな拡張子のみ抽出することも可能です。
🥭 repomix-app --include "**/*.md,**/*.py,**/*.sh,**/*.yml,**/*.yaml,**/*.json,**/*.toml" --output ./repomix_boltz.xml ./boltz
📦 Repomix v1.1.0
No custom config found at repomix.config.json5, repomix.config.jsonc, repomix.config.json or global config at /home/hoge/.config/repomix/repomix.config.json5, /home/hoge/.config/repomix/repomix.config.jsonc, /home/hoge/.config/repomix/repomix.config.json.
You can add a config file for additional settings. Please check https://github.com/yamadashy/repomix for more information.
✔ Packing completed successfully!
📈 Top 5 Files by Token Count:
──────────────────────────────────────────────────
1. src/boltz/data/feature/featurizerv2.py (20,552 tokens, 91,118 chars, 6.4%)
2. src/boltz/data/parse/schema.py (13,046 tokens, 60,299 chars, 4.1%)
3. src/boltz/data/parse/mmcif_with_constraints.py (11,424 tokens, 51,472 chars, 3.6%)
4. src/boltz/model/models/boltz1.py (11,250 tokens, 51,872 chars, 3.5%)
5. src/boltz/main.py (10,888 tokens, 45,760 chars, 3.4%)
🔎 Security Check:
──────────────────
✔ No suspicious files detected.
📊 Pack Summary:
────────────────
Total Files: 119 files
Total Tokens: 320,267 tokens
Total Chars: 1,364,898 chars
Output: ./repomix_boltz.xml
Security: ✔ No suspicious files detected
🎉 All Done!
Your repository has been successfully packed.
💡 Repomix is now available in your browser! Try it at https://repomix.com
※ --output で出力ファイル名を指定できます。
🥭 ChatGPTで試してみる
先ほど作成した repomix_boltz.xml をChatGPTにアップロードし、以下のように質問してみました。
添付した
repomix_boltz.xmlはBoltz-1およびBoltz-2のGitHubリポジトリを一つのファイルに集約したものです (ただし、サイズの大きなファイルは省略されています)。この情報に基づき
Boltz-2で利用可能なオプションを網羅的に解説してください。
※ 以下はChatGPT 4.1の出力です
Boltz-2で利用可能な全ての主要なオプションについて、網羅的に解説します。
(主に docs/prediction.md の記載に基づいていますが、YAMLやFASTA形式の入力・出力例、関連フラグなども含めて詳説します)
Boltz-2の主要コマンド
基本的な予測実行コマンドは下記です:
boltz predict <INPUT_PATH> [OPTIONS]
-
<INPUT_PATH>はFASTAまたはYAMLファイル、もしくはそれらが含まれるディレクトリ。
Boltz-2で利用可能なオプション(predictサブコマンド)
| オプション | 型 | デフォルト値 | 説明 |
|---|---|---|---|
--out_dir |
PATH | ./ |
予測結果の保存先ディレクトリ |
--cache |
PATH | ~/.boltz |
モデルやデータのダウンロード先 |
--checkpoint |
PATH | なし | 任意のモデルチェックポイント(デフォルトはBoltz-2) |
--devices |
整数 | 1 |
利用するデバイス数(例:GPU台数) |
--accelerator |
[gpu, cpu, tpu] |
gpu |
利用するアクセラレータ種別 |
--recycling_steps |
整数 | 3 |
リサイクル(構造再帰更新)回数 |
--sampling_steps |
整数 | 200 |
サンプリングステップ数 |
--diffusion_samples |
整数 | 1 |
拡散サンプル数(1実行あたりの構造予測数) |
--max_parallel_samples |
整数 | 5 |
並列サンプリング最大数 |
--step_scale |
浮動小数 | 1.638 |
拡散プロセスの温度スケール(1~2推奨) |
--output_format |
[pdb, mmcif] |
mmcif |
出力フォーマット |
--num_workers |
整数 | 2 |
DataLoaderワーカ数 |
--method |
文字列 | なし | 予測に使うメソッド種別 |
--preprocessing-threads |
整数 | CPUコア数 | 前処理用スレッド数 |
--affinity_mw_correction |
フラグ | False | 親和性推定時に分子量補正を行うか |
--sampling_steps_affinity |
整数 | 200 |
親和性推定用サンプリングステップ数 |
--diffusion_samples_affinity |
整数 | 5 |
親和性推定用サンプル数 |
--affinity_checkpoint |
PATH | なし | 親和性推定用のチェックポイント |
--max_msa_seqs |
整数 | 8192 |
MSAに利用する最大配列数 |
--subsample_msa |
フラグ | False | MSAをサブサンプルするか |
--num_subsampled_msa |
整数 | 1024 |
サブサンプリング後のMSA配列数 |
--no_kernels |
フラグ | False | Trifastカーネルを無効化 |
--override |
フラグ | False | 既存予測ファイルを上書きするか |
--use_msa_server |
フラグ | False | mmseqs2サーバでMSA自動生成 |
--msa_server_url |
文字列 | https://api.colabfold.com |
MSAサーバのURL |
--msa_pairing_strategy |
文字列 | greedy |
MSAペアリング方式(greedy/complete) |
--use_potentials |
フラグ | False | 推論時に物理ポテンシャルを利用 |
--write_full_pae |
フラグ | False | PAE行列をnpzファイルで出力 |
--write_full_pde |
フラグ | False | PDE行列をnpzファイルで出力 |
認証関係オプション
-
--msa_server_username/--msa_server_password -
--api_key_header/--api_key_value
環境変数(BOLTZ_MSA_USERNAME など)でも設定可能。API Key/basicauthは排他利用。
入力フォーマットの特徴
-
FASTA形式
- 基本的な多鎖/多分子入力可。カスタムMSAやligand(SMILES, CCD)指定可能。
- ただし、修飾残基・共有結合・ポケット制約・親和性指定は不可。
-
YAML形式
- 複雑な分子設計(修飾/共有結合/ポケット/親和性/テンプレート/複数配列)まで全てサポート。
特徴的なオプションの詳細
-
--use_msa_server
mmseqs2サーバを利用し、自動でMSAを計算。サーバURL/認証も指定可能。 -
--use_potentials
物理ポテンシャルを推論時に適用し、立体構造の物理妥当性を向上(特に異常な重なり等に有効)。 -
--affinity_mw_correction
分子量補正をbinding affinity推定値に加味(親和性推定時のみ)。
出力ファイルと内容
- 予測構造(CIF/PDB)、信頼度(plddt, ptm, iptm等)、親和性(affinity_pred_value/logIC50, affinity_probability_binary)、PAE/PDE行列など多彩。
- 詳細なJSON出力(per-chain/ペア別/複合体別などの信頼度指標)。
サンプル実行例
# MSA自動計算、親和性も計算、物理ポテンシャルも利用し、5サンプル生成
boltz predict input.yaml --use_msa_server --diffusion_samples 5 --use_potentials --write_full_pae --write_full_pde --affinity_mw_correction
その他
- テンプレート利用(YAMLの
templates指定)はAlphaFold/ColabFoldに類似だが、チェーンID明示・強制/閾値指定も可。 - カスタムMSA(csv/a3m指定)、サブサンプリングもコマンドで制御可能。
まとめ
Boltz-2は、「構造予測の多サンプル化」「物理的ポテンシャルの適用」「親和性推定」「MSA自動化」などAlphaFold/ColabFold系列モデルでよく求められるフラグや追加機能がほぼ網羅されています。
また、YAML入力を使えば、創薬現場で求められる複雑な分子・プロトコルも柔軟に記述・制御可能です。
ご希望であれば、各オプションのベストプラクティスや創薬用途での推奨設定、入力YAMLテンプレートなどもご提案可能です。
さらに細かな挙動やコードレベルの実装仕様を知りたい場合は、該当するsrc/boltz/以下のスクリプトもご案内できますのでご相談ください。
Discussion