Gromacsの温度の設定を一括変更するシェルスクリプト

温度レプリカ交換MDシミュレーションを実行するためのmdpファイルを一括設定するための備忘録.

Temperature generator for REMD-simulations(2022/5/29、リンク先変更)を使って,レプリカ毎の温度を計算すると,

表とカンマ区切りの数値のリストを得られます.

310.00, 313.19, 316.34, 319.51, 322.72, 325.94, 329.06, 332.34, 335.64, 338.97, 342.31, 345.69, 349.09, 352.53, 355.98, 359.48

これをremd.txtという名前で保存しておきます.

16個のレプリカを動かすために,ディレクトリ1,2,3,…,16を作成します.

$ mkdir {1...16}

それぞれのディレクトリにGromacsのシミュレーション設定が書かれたmdpファイル (npt.mdp) をコピーします.

$ (for dir in `seq 1 16`; do cp npt.mdp $dir; done)

このファイル中のの温度に関する設定は,例えばtemperature couplingグループが2つの場合,以下のようになっています.設定温度ref_tには数値ではなくTEMPという文字列が入っています.

tcoupl      = V-rescale                 ; modified Berendsen thermostat
tc-grps     = Protein Water_and_Ions    ; two coupling groups - more accurate
tau_t       = 0.1   0.1                 ; time constant, in ps
ref_t       = TEMP   TEMP

この文字列TEMPをレプリカ毎の温度値で置き換えます.

以下のshell script (remd.shという名前にする) を実行して,各ディレクトリ中のmdpファイルの中の文字列TEMPを順番に置き換えます.

#!/bin/bash
j=0
for L in `cat remd.txt | sed -e 's/,//g'`
do
    j=`expr $j + 1`
    sed -i.bak -e 's/TEMP/'$L'/g' $j/*.mdp
    echo $j: $L
done
$ sh ./remd.sh
$ grep ref_t */npt.mdp

というコマンドでref_tが含まれる行を抜き出して確かめてみると温度が書き込まれているのが確認できます.

1/npt.mdp:ref_t       = 310.00 310.00                     ; reference temperature, one for each group, in K
10/npt.mdp:ref_t       = 341.08 341.08                     ; reference temperature, one for each group, in K
11/npt.mdp:ref_t       = 344.67 344.67                     ; reference temperature, one for each group, in K
12/npt.mdp:ref_t       = 348.30 348.30                     ; reference temperature, one for each group, in K
13/npt.mdp:ref_t       = 351.96 351.96                     ; reference temperature, one for each group, in K
14/npt.mdp:ref_t       = 355.68 355.68                     ; reference temperature, one for each group, in K
15/npt.mdp:ref_t       = 359.41 359.41                     ; reference temperature, one for each group, in K
16/npt.mdp:ref_t       = 363.28 363.28                     ; reference temperature, one for each group, in K
2/npt.mdp:ref_t       = 313.34 313.34                     ; reference temperature, one for each group, in K
3/npt.mdp:ref_t       = 316.71 316.71                     ; reference temperature, one for each group, in K
4/npt.mdp:ref_t       = 320.10 320.10                     ; reference temperature, one for each group, in K
5/npt.mdp:ref_t       = 323.53 323.53                     ; reference temperature, one for each group, in K
6/npt.mdp:ref_t       = 326.98 326.98                     ; reference temperature, one for each group, in K
7/npt.mdp:ref_t       = 330.46 330.46                     ; reference temperature, one for each group, in K
8/npt.mdp:ref_t       = 333.97 333.97                     ; reference temperature, one for each group, in K
9/npt.mdp:ref_t       = 337.51 337.51                     ; reference temperature, one for each group, in K

Gromacsの実行 (レプリカ交換の場合).

$ (for dir in `seq 1 16`; do cd $dir; gmx grompp -f npt.mdp -c ../conf.gro -p ../topol.top -o md_01.tpr; cd ..; done)
$ mpirun -np 16 mdrun_mpi -deffnm md_01 -multidir 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 -replex 500

mdrun_mpiは,build-mdrun-onlyとOpen-MPIをONにしてcompileしたもの.スパコンでは “mdrun_mpi” の代わりに “gmx_mpi mdrun”.自分のコンピュータの少ないコア数で多くのreplicaを動かしたい時は,

localhost slots=16

と書き込んだファイル (my-hosts) を作っておいて,

$ mpirun --hostfile my-hosts -np 16 mdrun_mpi -deffnm md_01 -multidir 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 -replex 500

とすると動く.

(了)

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください