diff --git a/frontend/src/components/RugnuxHero.tsx b/frontend/src/components/RugnuxHero.tsx index 274515a21..d27d9c266 100644 --- a/frontend/src/components/RugnuxHero.tsx +++ b/frontend/src/components/RugnuxHero.tsx @@ -157,7 +157,7 @@ function ModelTile({s, modelLoaded}: { s: rugnux_live_status, modelLoaded: boole } // column: the tiles as a rail, top to bottom, sharing the rail's height (two or three to a row on a phone, -// where the rail is the width of the screen) +// where the rail is the width of the screen); else a row of tiles, five to a row, ten on a wide screen // givenCell: the unit cell the collection was started with, if any function RugnuxHero({s, modelLoaded, givenCell, column}: { s: rugnux_live_status, modelLoaded: boolean, givenCell?: string, column?: boolean }) { @@ -176,7 +176,7 @@ function RugnuxHero({s, modelLoaded, givenCell, column}: *": {display: "flex", flexDirection: "column", justifyContent: "center"}} - : {gridTemplateColumns: {xs: "repeat(3, minmax(0, 1fr))", md: "repeat(10, minmax(0, 1fr))"}})}}> + : {gridTemplateColumns: {xs: "repeat(3, minmax(0, 1fr))", sm: "repeat(5, minmax(0, 1fr))", xl: "repeat(10, minmax(0, 1fr))"}})}}> `${x.toFixed(2)} Å`)} caption="Resolution" tone={pending} tip={o.fit !== undefined ? `Where the CC½ fall-off is fitted: the resolution to quote. The reflections are written to ${o.d_min?.toFixed(2)} Å, a shell beyond, on purpose.` diff --git a/frontend/src/components/RugnuxPage.tsx b/frontend/src/components/RugnuxPage.tsx index a58be1df9..76fc04397 100644 --- a/frontend/src/components/RugnuxPage.tsx +++ b/frontend/src/components/RugnuxPage.tsx @@ -25,8 +25,9 @@ import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import ClearAllIcon from "@mui/icons-material/ClearAll"; import {lazy, Suspense, useEffect, useRef, useState} from "react"; -// The live page as one control-room screen, in the app's own light or dark: a stage the height of the window, -// edged in the colour of the run's phase, that shows everything at once - images, structure, statistics. +// The live page as one control-room screen, in the app's own light or dark: on a wide window a stage the height +// of the window, edged in the colour of the run's phase, that shows everything at once - images, structure, +// statistics; in a narrower one the same pieces flow down the page (FlowDashboard). // Across the top, the phase, the two progress bars (the detector's and rugnux's) and the clock the run is // judged by. Below, left to right: the hero numbers of the merge as a rail with the triage badges under them, // the diffraction image the broker is on, and the placed model in Mol* (the run's step until there is one). @@ -198,71 +199,72 @@ function useHeight() { return [ref, height] as const; } +// The checks: what the pathology checklist made of the merge, a failed run's message, or what is still to come +function Checks({s, pal}: { s: rugnux_live_status, pal: LivePalette }) { + if (s.triage && s.triage.length > 0) + return ; + if (s.state === "Failed") + return {s.message}; + return ; +} + +function ShellPlotsOrLater({s, height}: { s: rugnux_live_status, height: number }) { + if (!s.shells || s.shells.length === 0) + return ; + return ; +} + +type DashboardProps = { s: rugnux_live_status, name?: string, givenCell?: string, deadline_s: number, modelLoaded: boolean, + measuring: boolean, pal: LivePalette }; + +// Spots and predictions are drawn on an image only where the broker analysed it: a serial run's images after +// the pre-pass. A rotation run's images are analysed by rugnux's own passes and carry neither. +const overlaysOn = (s: rugnux_live_status) => s.stills !== undefined && s.stills.images_analysed > 0; + // The height of the bottom row of plots, from the window's height so the stage holds everything without // scrolling: the image and the model take what the header and the plots leave. const PLOTS = "clamp(190px, 23vh, 440px)"; const RAIL = "clamp(200px, 12vw, 420px)"; -function Dashboard({s, name, givenCell, deadline_s, modelLoaded, measuring, pal}: - { s: rugnux_live_status, name?: string, givenCell?: string, deadline_s: number, modelLoaded: boolean, - measuring: boolean, pal: LivePalette }) { - // Only on the fixed-height stage (xl) do the plots and the image take their height from their box; below it - // the stage flows and the boxes take their height from their content, so a measured height would feed back. - const stage = useMediaQuery(useTheme().breakpoints.up("xl")); +// The stage of a wide window (xl): the height of the window, nothing scrolls. +function StageDashboard({s, name, givenCell, deadline_s, modelLoaded, measuring, pal}: DashboardProps) { const [plotsRef, plotsHeight] = useHeight(); const [imageRef, imageHeight] = useHeight(); - const plotHeight = stage ? Math.max(150, plotsHeight) : 220; - const later = s.stills ? "after the first merge" : "after scaling"; - // Spots and predictions are drawn on an image only where the broker analysed it: a serial run's images after - // the pre-pass. A rotation run's images are analysed by rugnux's own passes and carry neither. - const overlays = s.stills !== undefined && s.stills.images_analysed > 0; - const hairline = {borderLeft: {xl: "1px solid"}, borderColor: {xl: "divider"}, pl: {xl: 2.5}}; + const plotHeight = Math.max(150, plotsHeight); + const hairline = {borderLeft: "1px solid", borderColor: "divider", pl: 2.5}; return (
- + {/* the merge's numbers, and under them what the checks made of it */} - + - - {s.triage && s.triage.length > 0 ? - : s.state === "Failed" ? {s.message} - : } - + {/* the image, square with the row's height, in a column of its own width; the model takes the rest */} - + - - + + - {/* below the stage the model takes the whole width under the image, only as tall as Mol* needs, and - nothing when there is no model to show */} - + {/* four plots across the bottom: the collection image by image, wide - a point an image - and the merge by resolution, square - a point a shell - each as wide as the row is high */} - - + + - By resolution{s.stills && s.shells_merge && ` · ${s.shells_merge}`}} - sx={{...hairline, minHeight: {xs: 200, xl: 0}}}> - - {s.shells && s.shells.length > 0 - ? - - - : } + By resolution{s.stills && s.shells_merge && ` · ${s.shells_merge}`}} sx={hairline}> + *": {width: "100%"}}}> + @@ -271,6 +273,46 @@ function Dashboard({s, name, givenCell, deadline_s, modelLoaded, measuring, pal} ); } +// The side of the square shell plots and the height of the collection strip, below the stage +const FLOW_SQUARE = 240; +const FLOW_STRIP = 200; + +// A narrower window (the common case: a browser beside other windows), where the page scrolls: the merge's +// numbers as a row of tiles under the header, then the image and the model side by side, as large as the width +// allows - one above the other where that would leave them under 360 px - then the collection plots, wide, and +// the shell plots, square, with the checks beside them. +function FlowDashboard({s, name, givenCell, deadline_s, modelLoaded, measuring, pal}: DashboardProps) { + const twoUp = useMediaQuery("(min-width: 1000px)"); + return ( + +
+ + + + {/* beside the image the model is as tall as the image; under it, as tall as Mol* needs */} + + + + + + + By resolution{s.stills && s.shells_merge && ` · ${s.shells_merge}`}} + sx={{width: 2 * FLOW_SQUARE + 12, maxWidth: "100%", minHeight: {xs: 120, sm: FLOW_SQUARE}}}> + *": {width: "100%"}}}> + + + + + + + ); +} + +function Dashboard(props: DashboardProps) { + const stage = useMediaQuery(useTheme().breakpoints.up("xl")); + return stage ? : ; +} + // What the stage leaves out, below it: the timeline, the steps with their notes, the summary rows // and warnings, the model's scores, and the serial pre-pass geometry. function Details({s, deadline_s}: { s: rugnux_live_status, deadline_s: number }) { diff --git a/frontend/src/components/RugnuxStructureViewer.tsx b/frontend/src/components/RugnuxStructureViewer.tsx index ba8ebc6d5..b241778b7 100644 --- a/frontend/src/components/RugnuxStructureViewer.tsx +++ b/frontend/src/components/RugnuxStructureViewer.tsx @@ -12,6 +12,7 @@ import {applyModelDisplay, clearScene, getStructureAtoms, getStructureBox, Loade import {loadMapLayer, MAP_COLORS, MapLayer, removeMapLayer, setLayerVisible} from "./structure/loadMaps"; import {FullCellMap, fullCellFromCcp4, prepareMap} from "./structure/densityCrop"; import {revealCamera} from "./structure/reveal"; +import {fitCamera} from "./structure/fitCamera"; import {PEAK_MAP_RADIUS_A, viewPeak} from "./structure/peakView"; @@ -19,7 +20,8 @@ import {PEAK_MAP_RADIUS_A, viewPeak} from "./structure/peakView"; // 2mFo-DFc at 1 sigma, mFo-DFc at +-3 sigma and (where the data carry anomalous signal) the anomalous difference // map at 4 sigma, in Mol*. Set up as aaredb's structure viewer (gitea.psi.ch/mx/aaredb, pages/StructureView.tsx // and components/Structure/, the PSI MX group's own code): its plugin, Coot mouse controls, model presets, map -// meshes, crop and carve - on a black stage. It is not a viewer to work in: what it shows is gone with the next +// meshes, crop and carve - on a black stage, the model fitted to the panel (fitCamera.ts), and again whenever the +// panel changes shape. It is not a viewer to work in: what it shows is gone with the next // collection, so the controls are a toggle for the difference map and arrows through the refined model's // difference-map peaks (the blobs of the live result, highest first), in a bar over the stage. Every map is carved // within the same radius of the atoms (aaredb carves 2Fo-Fc only); at a peak the maps are drawn uncarved within @@ -88,6 +90,7 @@ function RugnuxStructureViewer({resultKey, anomalous, anomalousSignal, fill, pea const [hasMap, setHasMap] = useState>({twofofc: false, fofc: false, anom: false}); // The stage stays dark until the first model and its maps are in, then fades up as the camera eases in. const [revealed, setRevealed] = useState(false); + const stageRef = useRef(null); // aaredb factory defaults (state/viewerDefaults.ts:16-23); anomalous as a difference map, +4 sigma const SIGMA: Record = {twofofc: 1.0, fofc: 3.0, anom: 4.0}; @@ -159,6 +162,7 @@ function RugnuxStructureViewer({resultKey, anomalous, anomalousSignal, fill, pea } if (firstScene && !abort.signal.aborted) { await nextFrames(); // the camera reset loadModel asked for is applied on a draw + fitCamera(plugin, atoms, 0); if (!reducedMotion()) revealCamera(plugin, REVEAL_MS); } @@ -176,6 +180,22 @@ function RugnuxStructureViewer({resultKey, anomalous, anomalousSignal, fill, pea return () => abort.abort(); }, [pluginReady, resultKey, anomalous]); + // The panel changed shape: the whole model is fitted to it again (a peak keeps its own view) + useEffect(() => { + const stage = stageRef.current; + if (!stage) + return; + const observer = new ResizeObserver(() => { + const plugin = pluginRef.current; + if (plugin && sceneLoadedRef.current && peakRef.current === null) { + plugin.handleResize(); + fitCamera(plugin, atomsRef.current, 0); + } + }); + observer.observe(stage); + return () => observer.disconnect(); + }, []); + const toggleLayer = useCallback((kind: Kind, visible: boolean) => { setShow(s => ({...s, [kind]: visible})); const plugin = pluginRef.current; @@ -198,7 +218,9 @@ function RugnuxStructureViewer({resultKey, anomalous, anomalousSignal, fill, pea // at a peak the side chains about it matter: sticks over the cartoon applyModelDisplay(plugin, modelRefsRef.current, i === null ? REPR : 'both', false); if (i === null) { - plugin.managers.camera.reset(undefined, reducedMotion() ? 0 : 400); + plugin.managers.camera.reset(undefined, 0); + await nextFrames(); // the reset is applied on a draw; the fit starts from it + fitCamera(plugin, atomsRef.current, reducedMotion() ? 0 : 400); return; } const p = sortedRef.current[i]; @@ -270,7 +292,7 @@ function RugnuxStructureViewer({resultKey, anomalous, anomalousSignal, fill, pea )} - + diff --git a/frontend/src/components/structure/fitCamera.ts b/frontend/src/components/structure/fitCamera.ts new file mode 100644 index 000000000..ed0e7e937 --- /dev/null +++ b/frontend/src/components/structure/fitCamera.ts @@ -0,0 +1,39 @@ +import { PluginContext } from 'molstar/lib/mol-plugin/context'; +import { Vec3 } from 'molstar/lib/mol-math/linear-algebra'; + +// The camera moved along its line of sight until the atoms fill the panel: Mol*'s own reset frames the +// structure's bounding sphere within the panel's shorter side, which leaves a compact molecule small in a +// wide or tall panel. Here the atoms' extent across and up the view is what has to fit, with a little air, +// so the model is as large as the panel lets it be, whatever the panel's shape; the view direction and the +// focus radius (the clipping) are left as they are. +const AIR = 1.08; + +export function fitCamera(plugin: PluginContext, atoms: Float32Array, durationMs: number): void { + const camera = plugin.canvas3d?.camera; + if (!camera || atoms.length < 3) + return; + const s = camera.getSnapshot(); + const dir = Vec3.normalize(Vec3(), Vec3.sub(Vec3(), s.position, s.target)); + const up = Vec3.normalize(Vec3(), Vec3.sub(Vec3(), s.up, Vec3.scale(Vec3(), dir, Vec3.dot(s.up, dir)))); + const right = Vec3.cross(Vec3(), up, dir); + const n = atoms.length / 3; + const centre = Vec3(); + for (let i = 0; i < atoms.length; i += 3) + Vec3.add(centre, centre, Vec3.create(atoms[i], atoms[i + 1], atoms[i + 2])); + Vec3.scale(centre, centre, 1 / n); + let hx = 0, hy = 0, hz = 0; + const d = Vec3(); + for (let i = 0; i < atoms.length; i += 3) { + Vec3.sub(d, Vec3.create(atoms[i], atoms[i + 1], atoms[i + 2]), centre); + hx = Math.max(hx, Math.abs(Vec3.dot(d, right))); + hy = Math.max(hy, Math.abs(Vec3.dot(d, up))); + hz = Math.max(hz, Math.abs(Vec3.dot(d, dir))); + } + const { width, height } = camera.viewport; + const t = Math.tan(s.fov / 2); + // the extent across the view fits the width, the one up the view the height; the nearest atoms sit hz + // in front of the centre + const distance = Math.max(hy / t, hx / (t * Math.max(width / Math.max(height, 1), 1e-3))) * AIR + hz; + camera.setState({ ...s, target: centre, position: Vec3.add(Vec3(), centre, Vec3.scale(Vec3(), dir, distance)) }, + durationMs, { easing: 'cubic-out' }); +}