Download code/scripts/make_schematics.py from eduzrh/LNPBench: direct link, hf CLI and curl.
- Browser
- Download file 7.43 kB
-
https://huggingface.co/datasets/eduzrh/LNPBench/resolve/main/code/scripts/make_schematics.py
- Command line
-
hf download hf://datasets/eduzrh/LNPBench/code/scripts/make_schematics.py
-
curl -L -o make_schematics.py https://huggingface.co/datasets/eduzrh/LNPBench/resolve/main/code/scripts/make_schematics.py
7.43 kB
| """Draw the two schematic figures of the manuscript (Fig. 1 task, Fig. 2 framework). | |
| All text is English on purpose: the figures are reused unchanged in the English | |
| submission, and this machine has no CJK font available to matplotlib. | |
| python scripts/make_schematics.py # writes figures/*.pdf and *.png | |
| """ | |
| from __future__ import annotations | |
| import pathlib | |
| import matplotlib | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| from matplotlib.patches import FancyArrowPatch, FancyBboxPatch | |
| FIG = pathlib.Path("figures") | |
| FIG.mkdir(exist_ok=True) | |
| INK = "#22303c" | |
| MUTED = "#6b7a88" | |
| BLUE = "#dbe8f4" | |
| BLUE_E = "#3f6f9f" | |
| GREEN = "#dcecdf" | |
| GREEN_E = "#3f7a55" | |
| ORANGE = "#f7e4d3" | |
| ORANGE_E = "#a9662f" | |
| GREY = "#eceff2" | |
| GREY_E = "#8794a1" | |
| def box(ax, x, y, w, h, text, fc, ec, fs=9.0, weight="normal", rad=0.02, lw=1.1): | |
| ax.add_patch( | |
| FancyBboxPatch( | |
| (x, y), w, h, | |
| boxstyle=f"round,pad=0.008,rounding_size={rad}", | |
| linewidth=lw, edgecolor=ec, facecolor=fc, zorder=2, | |
| ) | |
| ) | |
| ax.text(x + w / 2, y + h / 2, text, ha="center", va="center", | |
| fontsize=fs, color=INK, weight=weight, zorder=3, linespacing=1.35) | |
| def arrow(ax, xy1, xy2, color=MUTED, lw=1.2, style="-|>", ls="-", rad=0.0): | |
| ax.add_patch(FancyArrowPatch( | |
| xy1, xy2, arrowstyle=style, mutation_scale=11, | |
| linewidth=lw, color=color, linestyle=ls, | |
| connectionstyle=f"arc3,rad={rad}", zorder=1, | |
| shrinkA=2, shrinkB=2, | |
| )) | |
| def canvas(w=10.4, h=4.3): | |
| fig, ax = plt.subplots(figsize=(w, h)) | |
| ax.set_xlim(0, w) | |
| ax.set_ylim(0, h) | |
| ax.axis("off") | |
| fig.subplots_adjust(0, 0, 1, 1) | |
| return fig, ax | |
| def save(fig, stem): | |
| fig.savefig(FIG / f"{stem}.pdf", bbox_inches="tight", pad_inches=0.04) | |
| fig.savefig(FIG / f"{stem}.png", dpi=400, bbox_inches="tight", pad_inches=0.04) | |
| plt.close(fig) | |
| print("wrote", FIG / f"{stem}.pdf") | |
| # ---------------------------------------------------------------- Fig. 1 | |
| def fig_task(): | |
| fig, ax = canvas(10.6, 4.35) | |
| # (a) formulation | |
| ax.text(0.15, 4.10, "(a) Formulation", fontsize=9.5, weight="bold", color=INK) | |
| box(ax, 0.15, 2.72, 2.35, 1.16, | |
| "ionisable lipid (IL)\nhead – linker – tails\n\n" | |
| "+ helper lipid + cholesterol\n+ PEG lipid, molar ratios $w$", | |
| BLUE, BLUE_E, fs=8.4, weight="normal") | |
| box(ax, 0.15, 1.72, 2.35, 0.78, "assay context $c$\ndose · route · plate", GREY, GREY_E, fs=8.4) | |
| # (b) representation | |
| ax.text(3.05, 4.10, "(b) Identity-free representation", fontsize=9.5, weight="bold", color=INK) | |
| box(ax, 3.05, 3.12, 2.55, 0.80, "GINE over the IL graph\n(atom / bond features)", GREEN, GREEN_E, fs=8.4) | |
| box(ax, 3.05, 2.22, 2.55, 0.80, "RDKit descriptor stream\n(217-d)", GREEN, GREEN_E, fs=8.4) | |
| box(ax, 3.05, 1.20, 2.55, 0.92, "10-slot formulation set\nphysics attributes only\n(no fingerprint, no ID)", ORANGE, ORANGE_E, fs=8.4) | |
| ax.text(4.32, 1.00, "each slot: 16-d physics + slot type + $w$", | |
| ha="center", va="top", fontsize=7.4, color=MUTED) | |
| # (c) model | |
| ax.text(6.15, 4.10, "(c) Models", fontsize=9.5, weight="bold", color=INK) | |
| box(ax, 6.15, 3.10, 1.95, 0.84, "PhysSet-LNP\nset attention $\\beta_{uv}$", BLUE, BLUE_E, fs=8.4) | |
| box(ax, 6.15, 1.72, 1.95, 0.84, "PhysChem-Tree\n398-d block + RF", BLUE, BLUE_E, fs=8.4) | |
| # (d) output | |
| ax.text(8.62, 4.10, "(d) Output", fontsize=9.5, weight="bold", color=INK) | |
| box(ax, 8.55, 2.85, 1.85, 1.05, | |
| "ranked candidates\nfor a study that\nwas never seen", GREEN, GREEN_E, fs=8.4) | |
| ax.text(9.32, 2.46, "$\\hat y$", ha="right", va="center", fontsize=7.6, color=MUTED) | |
| box(ax, 8.55, 1.45, 1.85, 0.66, "LNPBench-Stack\nrank-average", GREY, GREY_E, fs=8.4) | |
| # arrows | |
| arrow(ax, (2.50, 3.50), (3.05, 3.52)) | |
| arrow(ax, (2.50, 3.10), (3.05, 2.62)) | |
| arrow(ax, (2.50, 2.30), (3.05, 1.72)) | |
| arrow(ax, (2.50, 2.05), (3.05, 1.30), ls=(0, (3, 2))) | |
| arrow(ax, (5.60, 3.52), (6.15, 3.52)) | |
| arrow(ax, (5.60, 1.66), (6.15, 2.06)) | |
| arrow(ax, (8.10, 3.42), (8.55, 3.55)) | |
| arrow(ax, (8.10, 2.02), (8.55, 1.83)) | |
| arrow(ax, (9.47, 2.11), (9.47, 2.85)) | |
| ax.text(0.15, 0.62, | |
| "Training: all formulations from the remaining study sources. Held-out study $s^*$: 0 labels (strict) or ~53 pilot labels (LNPAdapt).\n" | |
| "Headline metric: Spearman $\\rho$ computed inside $s^*$ only.", | |
| fontsize=8.0, color=MUTED, va="top", linespacing=1.5) | |
| save(fig, "fig1_task_schematic") | |
| # ---------------------------------------------------------------- Fig. 2 | |
| def fig_framework(): | |
| fig, ax = canvas(10.6, 4.9) | |
| bands = [ | |
| (3.66, 1.08, "representation layer", BLUE, BLUE_E), | |
| (2.06, 1.44, "model layer", GREEN, GREEN_E), | |
| (0.30, 1.60, "decision layer", ORANGE, ORANGE_E), | |
| ] | |
| for y, h, label, fc, ec in bands: | |
| ax.add_patch(FancyBboxPatch((0.10, y), 10.40, h, | |
| boxstyle="round,pad=0.01,rounding_size=0.03", | |
| linewidth=0, facecolor=fc, alpha=0.30, zorder=0)) | |
| ax.text(0.24, y + h - 0.07, label, fontsize=8.4, color=ec, | |
| weight="bold", ha="left", va="top", style="italic") | |
| # ---- representation layer | |
| box(ax, 0.30, 3.84, 2.05, 0.64, "IL molecular graph\n43 atom / 12 bond feats", "white", BLUE_E, fs=8.0) | |
| box(ax, 2.62, 3.84, 2.05, 0.64, "GINE $\\times$3, $d=192$\n$\\mathbf{g}$", "white", BLUE_E, fs=8.0) | |
| box(ax, 5.05, 3.84, 2.15, 0.64, "217-d RDKit descriptors\nMLP 217-128, $\\mathbf{d}$", "white", BLUE_E, fs=8.0) | |
| box(ax, 7.62, 3.70, 2.74, 0.78, | |
| "10-slot formulation set\n16-d physics · slot type · $w$\n(dual protonation state)", "white", ORANGE_E, fs=8.0) | |
| # ---- model layer | |
| box(ax, 0.30, 2.30, 2.95, 0.86, | |
| "398-d identity-free chemistry block\n217 desc + 16 cCPP + 5 ratios\n+ 96 fragment + 48 helper + 16 IL", | |
| "white", GREY_E, fs=7.9) | |
| box(ax, 4.90, 2.32, 2.70, 0.82, | |
| "physics-biased set attention $\\times$3\n$\\beta_{uv}$: 5 pair terms", "white", GREEN_E, fs=8.2) | |
| box(ax, 8.00, 2.32, 2.36, 0.82, "PMA pooling\n$\\mathbf{z}_{\\mathrm{lnp}}$ $\\to$ $\\hat y$", "white", GREEN_E, fs=8.2) | |
| # ---- decision layer | |
| box(ax, 0.30, 1.02, 2.70, 0.58, "PhysChem-Tree\nRF / ET, leaf = 2, 400 trees", "white", GREEN_E, fs=8.0) | |
| box(ax, 7.55, 1.02, 2.81, 0.58, "PhysSet-LNP output\n$\\hat y$ (neural member)", "white", GREEN_E, fs=8.0) | |
| box(ax, 1.60, 0.38, 8.00, 0.50, | |
| "rank-normalise $\\longrightarrow$ equal-weight average $\\longrightarrow$ LNPBench-Stack ($\\rho = 0.392$)", | |
| "white", ORANGE_E, fs=8.4) | |
| ax.text(10.38, 0.16, "+ LNPAdapt: refit the same estimator with $k$ pilot labels", | |
| ha="right", va="bottom", fontsize=7.0, color=MUTED, style="italic") | |
| # ---- arrows | |
| arrow(ax, (2.35, 4.16), (2.62, 4.16)) | |
| arrow(ax, (3.62, 3.84), (5.05, 3.02), rad=-0.05) | |
| arrow(ax, (6.10, 3.84), (6.25, 3.14)) | |
| arrow(ax, (8.99, 3.70), (8.99, 3.14)) | |
| arrow(ax, (7.60, 2.73), (8.00, 2.73)) | |
| arrow(ax, (9.18, 2.32), (9.18, 1.60)) | |
| arrow(ax, (1.65, 3.66), (1.65, 3.16), color=GREY_E) | |
| arrow(ax, (1.65, 2.30), (1.65, 1.60), color=GREY_E) | |
| arrow(ax, (1.65, 1.02), (1.65, 0.88)) | |
| arrow(ax, (8.95, 1.02), (8.95, 0.88)) | |
| save(fig, "fig2_framework") | |
| if __name__ == "__main__": | |
| fig_task() | |
| fig_framework() |