+
+
+ PDB {pdbId.toUpperCase()}
+
+
{REP_LABELS.map(({ key, label }) => (
- {/* Viewer canvas */}
-
-
-
- {loading && (
-
-
-
- Loading {pdbId.toUpperCase()} from RCSB…
-
-
- )}
-
- {error && (
-
- )}
-
-
- {/* Footer hint */}
- {!loading && !error && (
-
-
- Drag to rotate · Scroll to zoom · Right-drag to translate ·
- Ligand shown as ball+stick · Binding pocket surface (electrostatic)
-
+ {loading && (
+
+
+
Loading {pdbId.toUpperCase()} from RCSB…
)}
+ {error && (
+
+ )}
+ {!loading && !error && (
+
+ Drag to rotate · scroll to zoom · pocket surface coloured by charge
+
+ )}
);
}
diff --git a/frontend/src/features/pharma/components/science-figures.tsx b/frontend/src/features/pharma/components/science-figures.tsx
new file mode 100644
index 00000000..7d2fca01
--- /dev/null
+++ b/frontend/src/features/pharma/components/science-figures.tsx
@@ -0,0 +1,344 @@
+"use client";
+
+import {
+ CartesianGrid,
+ ComposedChart,
+ ErrorBar,
+ Line,
+ PolarAngleAxis,
+ PolarGrid,
+ PolarRadiusAxis,
+ Radar,
+ RadarChart,
+ ReferenceArea,
+ ReferenceLine,
+ ResponsiveContainer,
+ Scatter,
+ ScatterChart,
+ Tooltip,
+ XAxis,
+ YAxis,
+} from "recharts";
+import type { ADMETResult, VQEDescriptor } from "../types";
+import type { ScorePoint } from "../types-live";
+import { admetLoad, CHEMICAL_ACCURACY_HA, type EvaluatedMolecule } from "../lib/pharma-science";
+
+// Validated with the dataviz palette script on #07090d (lightness, chroma, CVD, contrast all pass).
+const C = {
+ dg: "#10b981",
+ homo: "#0284c7",
+ lumo: "#d97706",
+ pass: "#10b981",
+ fail: "#e11d48",
+ ink: "rgba(255,255,255,0.78)",
+ muted: "rgba(255,255,255,0.38)",
+ grid: "rgba(255,255,255,0.06)",
+ surface: "#07090d",
+};
+
+const AXIS_TICK = { fontSize: 10, fill: C.muted, fontFamily: "var(--font-mono, ui-monospace)" };
+const TOOLTIP_STYLE = {
+ background: "#0d1017",
+ border: "1px solid rgba(255,255,255,0.1)",
+ borderRadius: 6,
+ fontSize: 11,
+ fontFamily: "ui-monospace, monospace",
+};
+
+/** Journal-style figure: bold panel letter, title, plot, caption. */
+export function Figure({
+ panel,
+ title,
+ caption,
+ aside,
+ children,
+ className = "",
+}: {
+ panel: string;
+ title: string;
+ caption?: React.ReactNode;
+ aside?: React.ReactNode;
+ children: React.ReactNode;
+ className?: string;
+}) {
+ return (
+
+
+ {panel}
+ {title}
+ {aside && {aside}
}
+
+ {children}
+ {caption && (
+
+ {caption}
+
+ )}
+
+ );
+}
+
+function Empty({ children }: { children: React.ReactNode }) {
+ return
{children}
;
+}
+
+// ── ΔG convergence ────────────────────────────────────────────────────────────
+
+/** ΔG per evaluated ligand with its 95% CI, plus the running minimum. */
+export function ConvergencePlot({ molecules, fallback }: { molecules: EvaluatedMolecule[]; fallback: ScorePoint[] }) {
+ const source = molecules.length
+ ? molecules.map((m) => ({ dg: m.dg, err: [m.dg - m.ciLo, m.ciHi - m.dg] as [number, number], it: m.iteration }))
+ : fallback.map((p) => ({ dg: p.score, err: [0, 0] as [number, number], it: p.iteration }));
+ if (!source.length) return
ΔG appears after the first VQC scoring round;
+
+ const rows = source.map((r, i) => ({ n: i + 1, ...r, best: Math.min(...source.slice(0, i + 1).map((s) => s.dg)) }));
+
+ return (
+
+
+
+
+ r.n)}
+ tick={AXIS_TICK}
+ tickLine={false}
+ axisLine={{ stroke: C.grid }}
+ label={{ value: "evaluation #", position: "insideBottom", offset: -8, fontSize: 10, fill: C.muted }}
+ />
+
+
+ `evaluation ${n}`}
+ formatter={(v: unknown, name: unknown) => [`${(v as number).toFixed(2)} kcal/mol`, name === "best" ? "running min" : "ΔG"]}
+ />
+
+
+
+
+
+
+
+ );
+}
+
+// ── Chemical space ────────────────────────────────────────────────────────────
+
+/** MW × cLogP of every scored ligand, with the Lipinski box and the optimisation path. */
+export function ChemicalSpacePlot({ molecules }: { molecules: EvaluatedMolecule[] }) {
+ const pts = molecules
+ .filter((m) => m.admet)
+ .map((m, i) => ({ x: m.admet!.mw, y: m.admet!.logp, pass: m.admet!.pass, smiles: m.smiles, n: i + 1, qed: m.admet!.qed }));
+ if (!pts.length) return
Ligand properties appear after the first ADMET pass;
+
+ const xMax = Math.max(600, ...pts.map((p) => p.x + 60));
+ const yMin = Math.min(-2, ...pts.map((p) => Math.floor(p.y - 0.5)));
+ const yMax = Math.max(6, ...pts.map((p) => Math.ceil(p.y + 0.5)));
+
+ return (
+
+
+
+
+
+
+
+ {
+ const p = payload?.[0]?.payload as (typeof pts)[number] | undefined;
+ if (!p) return null;
+ return (
+
+
#{p.n} {p.smiles}
+
MW {p.x.toFixed(1)} · cLogP {p.y.toFixed(2)} · QED {p.qed.toFixed(3)}
+
{p.pass ? "✓ ADMET pass" : "✕ ADMET fail"}
+
+ );
+ }}
+ />
+ {
+ const { cx = 0, cy = 0, payload } = props;
+ const pass = payload?.pass;
+ return pass ? (
+
+ ) : (
+
+
+
+
+ );
+ }}
+ />
+
+
+
+ );
+}
+
+// ── Property radar ────────────────────────────────────────────────────────────
+
+/** Each ADMET property as a fraction of its limit; the dashed ring is the limit itself. */
+export function PropertyRadar({ admet }: { admet: ADMETResult }) {
+ const data = admetLoad(admet).map((d) => ({ ...d, plot: Math.min(d.value, 1.5), limit: 1 }));
+ return (
+
+
+
+
+
+
+
+
+
+ name === "limit" ? [null, null] : [`${item.payload?.raw} (${Math.round((item.payload?.value ?? 0) * 100)}% of limit)`, item.payload?.key]
+ }
+ labelFormatter={() => ""}
+ />
+
+
+
+ );
+}
+
+// ── Frontier orbitals ─────────────────────────────────────────────────────────
+
+/** HOMO/LUMO levels per fragment on a shared eV axis, with the gap annotated. */
+export function OrbitalDiagram({ descriptors, names }: { descriptors: VQEDescriptor[]; names: (d: VQEDescriptor) => string }) {
+ if (!descriptors.length) return
No VQE descriptors;
+ const W = 360;
+ const H = 230;
+ const pad = { l: 42, r: 10, t: 14, b: 34 };
+ const lo = Math.floor(Math.min(...descriptors.map((d) => d.homo_energy_ev)) / 5) * 5 - 5;
+ const hi = Math.ceil(Math.max(...descriptors.map((d) => d.lumo_energy_ev)) / 5) * 5 + 5;
+ const y = (ev: number) => pad.t + ((hi - ev) / (hi - lo)) * (H - pad.t - pad.b);
+ const col = (W - pad.l - pad.r) / descriptors.length;
+ const ticks: number[] = [];
+ for (let t = lo; t <= hi; t += 5) ticks.push(t);
+
+ return (
+
+ );
+}
+
+// ── VQE error vs exact diagonalisation ───────────────────────────────────────
+
+/** |E_VQE − E_exact| per fragment on a log scale, against the 1 kcal/mol line. */
+export function VqeErrorPlot({ descriptors, names }: { descriptors: VQEDescriptor[]; names: (d: VQEDescriptor) => string }) {
+ const rows = descriptors
+ .filter((d) => d.exact_energy_hartree != null)
+ .map((d) => ({ d, err: Math.abs(d.ground_state_energy_hartree - d.exact_energy_hartree!) }));
+ if (!rows.length) return
No exact reference energies for this run;
+
+ const W = 360;
+ const rowH = 26;
+ const pad = { l: 92, r: 14, t: 10, b: 30 };
+ const H = pad.t + pad.b + rows.length * rowH;
+ const decades = [-7, -6, -5, -4, -3, -2, -1];
+ const lx = (ha: number) => pad.l + ((Math.log10(Math.max(ha, 1e-7)) + 7) / 6) * (W - pad.l - pad.r);
+
+ return (
+
+ );
+}
+
+function truncate(s: string, n: number) {
+ return s.length > n ? `${s.slice(0, n - 1)}…` : s;
+}
diff --git a/frontend/src/features/pharma/lib/pharma-science.ts b/frontend/src/features/pharma/lib/pharma-science.ts
new file mode 100644
index 00000000..0fcff623
--- /dev/null
+++ b/frontend/src/features/pharma/lib/pharma-science.ts
@@ -0,0 +1,99 @@
+import type { ADMETResult, PipelineLogEntry } from "../types";
+
+/** 1 kcal/mol in hartree: the usual "chemical accuracy" bar for VQE energies. */
+export const CHEMICAL_ACCURACY_HA = 0.0016;
+
+/** ADMET limits, mirroring backend ADMETFilter defaults (pharma/stages/stage_6.py). */
+export const ADMET_RULES = {
+ mw: { label: "MW", max: 500, unit: "Da" },
+ logp: { label: "cLogP", max: 5, unit: "" },
+ tpsa: { label: "TPSA", max: 140, unit: "Ų" },
+ hbd: { label: "HBD", max: 5, unit: "" },
+ hba: { label: "HBA", max: 10, unit: "" },
+ sa: { label: "SA", max: 4, unit: "" },
+ qed: { label: "QED", min: 0.4, unit: "" },
+} as const;
+
+/** Each property as a fraction of its limit; > 1 breaks the rule (QED is inverted so the same holds). */
+export function admetLoad(a: ADMETResult) {
+ return [
+ { key: "MW", value: a.molecular_weight / 500, raw: a.molecular_weight.toFixed(1) },
+ { key: "cLogP", value: Math.max(a.logp, 0) / 5, raw: a.logp.toFixed(2) },
+ { key: "TPSA", value: a.tpsa / 140, raw: a.tpsa.toFixed(1) },
+ { key: "HBD", value: a.hbd / 5, raw: String(a.hbd) },
+ { key: "HBA", value: a.hba / 10, raw: String(a.hba) },
+ { key: "SA", value: a.synthetic_accessibility / 4, raw: a.synthetic_accessibility.toFixed(2) },
+ { key: "1−QED", value: (1 - a.qed_score) / 0.6, raw: a.qed_score.toFixed(3) },
+ ];
+}
+
+export interface EvaluatedMolecule {
+ iteration: number;
+ smiles: string;
+ dg: number;
+ ciLo: number;
+ ciHi: number;
+ admet?: { pass: boolean; mw: number; logp: number; qed: number; sa: number };
+}
+
+export interface VqeFragmentRun {
+ iteration: number;
+ smiles: string;
+ energy: number;
+ exact: number | null;
+ gapEv: number;
+ qubits: number;
+ peer: string;
+}
+
+export interface ScaffoldHop {
+ iteration: number;
+ to: string;
+ reason: string;
+}
+
+const RE_ITER = /Iteration (\d+)\/(\d+)/;
+const RE_SCORE = /Binding affinity: ([-\d.]+) kcal\/mol\s+confidence \[([-\d.]+), ([-\d.]+)\]\s+SMILES:(\S+)/;
+const RE_ADMET = /ADMET (PASS|FAIL) — MW=([\d.]+)\s+LogP=([-\d.]+)\s+QED=([\d.]+)\s+SA=([\d.]+)/;
+const RE_VQE = /^\s*(\S+): E=([-\d.]+) Ha \(exact ([-\d.]+|n\/a)\), gap=([\d.]+) eV, (\d+) qubits, computed on (\S+)/;
+const RE_HOP = /Hop → (\S+)\s+reason: (.+)$/;
+
+/** Rebuilds the per-iteration science record from the orchestrator's log lines (formats in pharma/orchestrator.py). */
+export function parseScienceLog(lines: PipelineLogEntry[]) {
+ let iteration = 0;
+ let maxIterations = 0;
+ const molecules: EvaluatedMolecule[] = [];
+ const vqe: VqeFragmentRun[] = [];
+ const hops: ScaffoldHop[] = [];
+
+ for (const { message } of lines) {
+ let m: RegExpMatchArray | null;
+ if ((m = message.match(RE_ITER))) {
+ iteration = parseInt(m[1], 10);
+ maxIterations = parseInt(m[2], 10);
+ } else if ((m = message.match(RE_SCORE))) {
+ molecules.push({ iteration, smiles: m[4], dg: +m[1], ciLo: +m[2], ciHi: +m[3] });
+ } else if ((m = message.match(RE_ADMET))) {
+ const last = molecules[molecules.length - 1];
+ if (last && !last.admet) last.admet = { pass: m[1] === "PASS", mw: +m[2], logp: +m[3], qed: +m[4], sa: +m[5] };
+ } else if ((m = message.match(RE_VQE))) {
+ vqe.push({
+ iteration,
+ smiles: m[1],
+ energy: +m[2],
+ exact: m[3] === "n/a" ? null : +m[3],
+ gapEv: +m[4],
+ qubits: +m[5],
+ peer: m[6],
+ });
+ } else if ((m = message.match(RE_HOP))) {
+ hops.push({ iteration, to: m[1], reason: m[2].trim() });
+ }
+ }
+ return { molecules, vqe, hops, maxIterations };
+}
+
+/** Fragment SMILES keyed by ground-state energy (6 dp), the only field shared by descriptors and log lines. */
+export function fragmentSmilesByEnergy(vqe: VqeFragmentRun[]): Map
{
+ return new Map(vqe.map((v) => [v.energy.toFixed(6), v.smiles]));
+}
diff --git a/frontend/src/features/pharma/types.ts b/frontend/src/features/pharma/types.ts
index 2e3b2754..4e0413af 100644
--- a/frontend/src/features/pharma/types.ts
+++ b/frontend/src/features/pharma/types.ts
@@ -42,13 +42,17 @@ export interface VQCScore {
export interface QUBOPlacement {
fragment_id: string;
grid_site_index: number;
+ binary_variable_assignment: number[];
interaction_energy_kcal: number;
+ clash_penalty: number;
+ bond_geometry_penalty: number;
}
export interface DockingPose {
ligand_smiles: string;
fragment_placements: QUBOPlacement[];
total_qubo_energy: number;
+ rmsd_angstrom: number | null;
qaoa_approximation_ratio: number;
dc_qaoa_alpha: number;
qaoa_params_beta: number[];
@@ -60,6 +64,7 @@ export interface ScaffoldIteration {
input_smiles: string;
output_smiles: string;
reason_for_hop: string;
+ replacement_fragment_smiles: string;
}
export interface VQEDescriptor {
@@ -68,6 +73,9 @@ export interface VQEDescriptor {
lumo_energy_ev: number;
homo_lumo_gap_ev: number;
chemical_hardness_ev: number;
+ ground_state_energy_hartree: number;
+ exact_energy_hartree: number | null;
+ vqe_starts: number;
qubit_count: number;
gate_count: number;
vqe_iterations: number;