jasperyeoh2 commited on
Commit
a8babc6
·
verified ·
1 Parent(s): 545fc96

Add MM-PBSA scripts + summary (exclude work dirs)

Browse files
revision_exec/analysis/mmpbsa/README.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MM-PBSA (`gmx_MMPBSA`)
2
+
3
+ This folder contains the **dimer rep1/rep2/rep3 last-50ns (350–400 ns)** MM-PBSA-GB runs used for the revision.
4
+
5
+ ## Current status on this node (2026-05-06)
6
+
7
+ - `gmx_MMPBSA` runs in conda env `mmpbsa` (`gmx_MMPBSA v1.5.0.3`).
8
+ - `cpptraj` is required by `gmx_MMPBSA`. On this node it is available (may be provided via a local fix if the base env is missing it).
9
+
10
+ ## Numerical overflow in bond terms (known issue)
11
+
12
+ Some `sander` GB outputs may show fixed-width overflow in bond terms (e.g., `BOND = *************`). Those bond energy terms were **excluded from per-frame reporting**. This does **not** affect binding free energy reporting because bond contributions cancel upon subtraction (Complex − Receptor − Ligand); the reported **ΔTOTAL** is unaffected.
13
+
14
+ ## Fix: create a clean MM-PBSA env that includes `cpptraj`
15
+
16
+ On some images, the existing `mmpbsa` env may have AmberTools installed without `cpptraj`.
17
+ The robust fix is to create a fresh env pinned to a supported Python version:
18
+
19
+ ```bash
20
+ CONDA_SOLVER=classic conda create -n mmpbsa_py311 -c conda-forge -c bioconda \
21
+ python=3.11 gmx_mmpbsa ambertools mpi4py -y
22
+
23
+ conda run -n mmpbsa_py311 which cpptraj
24
+ conda run -n mmpbsa_py311 gmx_MMPBSA -h
25
+ ```
26
+
27
+ ## Run (GB, last 50 ns)
28
+
29
+ Smoke test (few frames, sanity check):
30
+
31
+ ```bash
32
+ MMPBSA_ENV=mmpbsa_py311 bash revision_exec/analysis/mmpbsa/run_dimer_rep1_last50ns_mmpbsa.sh
33
+ ```
34
+
35
+ Subsampled full-window GB-only (default interval targets ~50 snapshots in 350–400 ns):
36
+
37
+ ```bash
38
+ MMPBSA_ENV=mmpbsa_py311 MMPBSA_MODE=full bash revision_exec/analysis/mmpbsa/run_dimer_rep1_last50ns_mmpbsa.sh
39
+ ```
40
+
41
+ Outputs are written under:
42
+ - `revision_exec/analysis/mmpbsa/work_dimer_rep{1,2,3}_last50ns_smoke/`
43
+ - `revision_exec/analysis/mmpbsa/work_dimer_rep{1,2,3}_last50ns_full/`
44
+
45
+ Summary CSV (all three replicates):
46
+ - `revision_exec/analysis/mmpbsa/mmpbsa_summary.csv`
47
+
revision_exec/analysis/mmpbsa/mmpbsa_dimer_rep1_last50ns_gb.in ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Production-style GB run on 350–400 ns segment (md_400ns.part0005.xtc).
2
+ # ~5000 frames at 10 ps → interval=250 ≈ 20 snapshots (edit as needed).
3
+
4
+ &general
5
+ sys_name = "dimer_rep1_last50ns_gb"
6
+ startframe = 1
7
+ endframe = 9999999
8
+ # 350–400 ns segment saved every 10 ps → ~5000 frames. interval=100 ≈ 50 snapshots (~1 ns spacing).
9
+ interval = 100
10
+ forcefields = "oldff/leaprc.ff99SB,leaprc.gaff"
11
+ ions_parameters = 1
12
+ PBRadii = 3
13
+ temperature = 298.15
14
+ # IMPORTANT: leave empty so gmx_MMPBSA uses $PATH for ALL external programs
15
+ # (cpptraj/tleap/parmchk2/sander/gmx). If set, it must be a PATH-like string.
16
+ gmx_path = ""
17
+ keep_files = 2
18
+ solvated_trajectory = 1
19
+ verbose = 1
20
+ /
21
+
22
+ &gb
23
+ igb = 5
24
+ intdiel = 1.0
25
+ extdiel = 78.5
26
+ saltcon = 0.0
27
+ /
revision_exec/analysis/mmpbsa/mmpbsa_dimer_rep1_smoke_gb.in ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Smoke test: few frames on md_400ns.part0005.xtc (350–400 ns), GB only.
2
+ # Receptor = GROMACS index group 1 (Protein), ligand = 13 (CPP) — see revision_exec/input/index.ndx
3
+
4
+ &general
5
+ sys_name = "dimer_rep1_last50ns_smoke"
6
+ startframe = 1
7
+ endframe = 12
8
+ interval = 3
9
+ forcefields = "oldff/leaprc.ff99SB,leaprc.gaff"
10
+ ions_parameters = 1
11
+ PBRadii = 3
12
+ temperature = 298.15
13
+ # IMPORTANT: leave empty so gmx_MMPBSA uses $PATH for ALL external programs
14
+ # (cpptraj/tleap/parmchk2/sander/gmx). If set, it must be a PATH-like string.
15
+ gmx_path = ""
16
+ keep_files = 2
17
+ solvated_trajectory = 1
18
+ verbose = 1
19
+ /
20
+
21
+ &gb
22
+ igb = 5
23
+ intdiel = 1.0
24
+ extdiel = 78.5
25
+ saltcon = 0.0
26
+ /
revision_exec/analysis/mmpbsa/mmpbsa_summary.csv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ replicate,n_frames,delta_vdw_avg_kcal_mol,delta_vdw_sd_kcal_mol,delta_eel_avg_kcal_mol,delta_eel_sd_kcal_mol,delta_egb_avg_kcal_mol,delta_egb_sd_kcal_mol,delta_esurf_avg_kcal_mol,delta_esurf_sd_kcal_mol,delta_total_avg_kcal_mol,delta_total_sd_kcal_mol
2
+ rep1,51,-40.57,3.07,-4.95,3.52,23.01,3.26,-5.4,0.18,-27.92,3.33
3
+ rep2,51,-42.07,1.99,-4.34,3.53,22.04,3.09,-5.57,0.14,-29.94,2.4
4
+ rep3,51,-43.23,2.87,-8.45,28.33,21.83,25.9,-5.86,0.14,-35.71,4.58
5
+
6
+ aggregate_across_reps,,mean_of_rep_avgs,sd_of_rep_avgs
7
+ ΔTOTAL,,-31.19,4.042635279121775
revision_exec/analysis/mmpbsa/run_dimer_rep1_last50ns_mmpbsa.sh ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # MM-PBSA (gmx_MMPBSA) for heterodimer rep1, trajectory window 350–400 ns only.
3
+ # Prerequisites: conda env `mmpbsa`, GROMACS in gmx-lite (path in mmpbsa input).
4
+ #
5
+ # Usage:
6
+ # bash run_dimer_rep1_last50ns_mmpbsa.sh # smoke (few frames)
7
+ # MMPBSA_MODE=full bash run_dimer_rep1_last50ns_mmpbsa.sh # subsampled full window
8
+ #
9
+ set -eo pipefail
10
+
11
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+ REV="$(cd "$SCRIPT_DIR/../.." && pwd)"
13
+ MMPBSA_MODE="${MMPBSA_MODE:-smoke}"
14
+ MMPBSA_ENV="${MMPBSA_ENV:-mmpbsa}"
15
+ REP="${REP:-${1:-rep1}}"
16
+
17
+ MMPBSA_PREFIX="/hpc2hdd/home/jyang577/miniconda3/envs/${MMPBSA_ENV}"
18
+ GMX_MMPBSA="${MMPBSA_PREFIX}/bin/gmx_MMPBSA"
19
+ CPPTRAJ="${MMPBSA_PREFIX}/bin/cpptraj"
20
+
21
+ [[ -x "$GMX_MMPBSA" ]] || { echo "ERROR: missing executable $GMX_MMPBSA" >&2; exit 1; }
22
+ [[ -x "$CPPTRAJ" ]] || { echo "ERROR: missing executable $CPPTRAJ" >&2; exit 1; }
23
+
24
+ # Ensure external programs are discoverable via $PATH (gmx_MMPBSA uses $PATH
25
+ # when gmx_path="" in the input file).
26
+ export PATH="${MMPBSA_PREFIX}/bin:/hpc2hdd/home/jyang577/miniconda3/envs/gmx-lite/bin.AVX2_256:${PATH}"
27
+
28
+ PROD="$REV/$REP/prod"
29
+ NDX="$REV/input/index.ndx"
30
+ TPR="$PROD/md_400ns.tpr"
31
+
32
+ if [[ -f "$PROD/md_400ns.part0005.xtc" ]]; then
33
+ TRJ="$PROD/md_400ns.part0005.xtc"
34
+ elif [[ -f "$PROD/md_400ns.part0004.xtc" ]]; then
35
+ TRJ="$PROD/md_400ns.part0004.xtc"
36
+ else
37
+ echo "ERROR: could not find last-segment xtc under $PROD (expected md_400ns.part0004/0005.xtc)" >&2
38
+ exit 1
39
+ fi
40
+
41
+ # gmx_MMPBSA expects `-cp` to be a `.top`. Default to the preparation topology.
42
+ # If you want to use a different `.top`, set TOPOLOGY_FILE=/path/to/topol.top.
43
+ TOP_DEFAULT="$REV/prep/gate_topol.top"
44
+ TOP="${TOPOLOGY_FILE:-$TOP_DEFAULT}"
45
+
46
+ for f in "$NDX" "$TOP" "$TPR" "$TRJ"; do
47
+ [[ -f "$f" ]] || { echo "ERROR: missing $f" >&2; exit 1; }
48
+ done
49
+
50
+ if [[ "$MMPBSA_MODE" == "full" ]]; then
51
+ INFILE="$SCRIPT_DIR/mmpbsa_dimer_rep1_last50ns_gb.in"
52
+ OUTTAG="last50ns_gb_subsample"
53
+ else
54
+ INFILE="$SCRIPT_DIR/mmpbsa_dimer_rep1_smoke_gb.in"
55
+ OUTTAG="smoke_gb"
56
+ fi
57
+
58
+ [[ -f "$INFILE" ]] || { echo "ERROR: missing input $INFILE" >&2; exit 1; }
59
+
60
+ WORKDIR="$SCRIPT_DIR/work_dimer_${REP}_last50ns_${MMPBSA_MODE}"
61
+ mkdir -p "$WORKDIR"
62
+ cd "$WORKDIR"
63
+
64
+ LOG="$WORKDIR/mmpbsa_${OUTTAG}_$(date +%Y%m%d_%H%M%S).log"
65
+
66
+ echo "WORKDIR=$WORKDIR" | tee "$LOG"
67
+ echo "INFILE=$INFILE" | tee -a "$LOG"
68
+ echo "TPR=$TPR" | tee -a "$LOG"
69
+ echo "TRJ=$TRJ" | tee -a "$LOG"
70
+
71
+ # Protein = index 1, CPP = 13 (0-based group order in index.ndx)
72
+ set +e
73
+ "$GMX_MMPBSA" -O -nogui \
74
+ -i "$INFILE" \
75
+ -cs "$TPR" \
76
+ -ci "$NDX" \
77
+ -cg 1 13 \
78
+ -cp "$TOP" \
79
+ -ct "$TRJ" \
80
+ -eo "${OUTTAG}_perframe.csv" \
81
+ -o "${OUTTAG}_FINAL_RESULTS.dat" \
82
+ 2>&1 | tee -a "$LOG"
83
+ rc=${PIPESTATUS[0]}
84
+ set -e
85
+ exit "$rc"
revision_exec/analysis/mmpbsa/summarize_mmpbsa_gb_last50ns.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import csv
6
+ import math
7
+ from dataclasses import dataclass
8
+ from pathlib import Path
9
+ from statistics import mean, stdev
10
+
11
+
12
+ @dataclass(frozen=True)
13
+ class DeltaStats:
14
+ avg: float
15
+ sd: float
16
+
17
+
18
+ DELTA_KEYS = ("ΔVDWAALS", "ΔEEL", "ΔEGB", "ΔESURF", "ΔTOTAL")
19
+
20
+
21
+ def _parse_float(s: str) -> float:
22
+ s = s.strip()
23
+ if s.lower() == "nan":
24
+ return float("nan")
25
+ return float(s)
26
+
27
+
28
+ def parse_final_results(path: Path) -> dict[str, DeltaStats]:
29
+ """Parse gmx_MMPBSA FINAL_RESULTS file and return delta avg + SD (SD column, not SD(Prop.))."""
30
+ txt = path.read_text(errors="replace").splitlines()
31
+ in_delta = False
32
+ out: dict[str, DeltaStats] = {}
33
+
34
+ for line in txt:
35
+ if line.startswith("Delta (Complex - Receptor - Ligand):"):
36
+ in_delta = True
37
+ continue
38
+ if not in_delta:
39
+ continue
40
+ if not line.strip():
41
+ continue
42
+ if line.startswith("Δ"):
43
+ parts = line.split()
44
+ if len(parts) < 4:
45
+ continue
46
+ key = parts[0]
47
+ if key not in DELTA_KEYS:
48
+ # Skip terms like "Δ1-4 VDW" whose key is split across tokens.
49
+ continue
50
+ avg = _parse_float(parts[1])
51
+ sd = _parse_float(parts[3])
52
+ out[key] = DeltaStats(avg=avg, sd=sd)
53
+
54
+ missing = [k for k in DELTA_KEYS if k not in out]
55
+ if missing:
56
+ raise ValueError(f"Missing delta terms {missing} in {path}")
57
+ return out
58
+
59
+
60
+ def safe_stdev(xs: list[float]) -> float:
61
+ xs2 = [x for x in xs if not math.isnan(x)]
62
+ if len(xs2) < 2:
63
+ return float("nan")
64
+ return float(stdev(xs2))
65
+
66
+
67
+ def main() -> None:
68
+ ap = argparse.ArgumentParser()
69
+ ap.add_argument("--rep1", required=True, type=Path)
70
+ ap.add_argument("--rep2", required=True, type=Path)
71
+ ap.add_argument("--rep3", required=True, type=Path)
72
+ ap.add_argument("--out-csv", required=True, type=Path)
73
+ ap.add_argument("--n-frames", type=int, default=51)
74
+ args = ap.parse_args()
75
+
76
+ reps = {
77
+ "rep1": parse_final_results(args.rep1),
78
+ "rep2": parse_final_results(args.rep2),
79
+ "rep3": parse_final_results(args.rep3),
80
+ }
81
+
82
+ args.out_csv.parent.mkdir(parents=True, exist_ok=True)
83
+ with args.out_csv.open("w", newline="") as f:
84
+ w = csv.writer(f)
85
+ w.writerow(
86
+ [
87
+ "replicate",
88
+ "n_frames",
89
+ "delta_vdw_avg_kcal_mol",
90
+ "delta_vdw_sd_kcal_mol",
91
+ "delta_eel_avg_kcal_mol",
92
+ "delta_eel_sd_kcal_mol",
93
+ "delta_egb_avg_kcal_mol",
94
+ "delta_egb_sd_kcal_mol",
95
+ "delta_esurf_avg_kcal_mol",
96
+ "delta_esurf_sd_kcal_mol",
97
+ "delta_total_avg_kcal_mol",
98
+ "delta_total_sd_kcal_mol",
99
+ ]
100
+ )
101
+
102
+ for rep, d in reps.items():
103
+ w.writerow(
104
+ [
105
+ rep,
106
+ args.n_frames,
107
+ d["ΔVDWAALS"].avg,
108
+ d["ΔVDWAALS"].sd,
109
+ d["ΔEEL"].avg,
110
+ d["ΔEEL"].sd,
111
+ d["ΔEGB"].avg,
112
+ d["ΔEGB"].sd,
113
+ d["ΔESURF"].avg,
114
+ d["ΔESURF"].sd,
115
+ d["ΔTOTAL"].avg,
116
+ d["ΔTOTAL"].sd,
117
+ ]
118
+ )
119
+
120
+ tot_avgs = [reps[r]["ΔTOTAL"].avg for r in ("rep1", "rep2", "rep3")]
121
+ w.writerow([])
122
+ w.writerow(["aggregate_across_reps", "", "mean_of_rep_avgs", "sd_of_rep_avgs"])
123
+ w.writerow(["ΔTOTAL", "", float(mean(tot_avgs)), safe_stdev(tot_avgs)])
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
128
+