A collection of Molstar molecular visualization applications built for Val Town, using JSR imports and TSX.
This Val serves four different Molstar visualization applications:
- Viewer 𧬠- Standard Mol* viewer for visualizing molecular structures
- Docking Viewer π¬ - Specialized viewer for molecular docking results
- Mesoscale Explorer π - Explore mesoscale biological structures
- MVS Stories π - Interactive molecular visualization stories
MolstarViewer/
βββ index.tsx # Main entry point (imports backend)
βββ backend/ # Server-side routing and logic
β βββ index.tsx # Hono app with routes
β βββ routes/ # Individual route handlers (future)
β βββ README.md
βββ frontend/ # Client-side TSX components
β βββ apps/ # Individual app components
β β βββ viewer.tsx
β β βββ docking-viewer.tsx
β β βββ mesoscale-explorer.tsx
β β βββ mvs-stories.tsx
β βββ README.md
βββ shared/ # Shared types and utilities
β βββ types.ts
β βββ README.md
βββ viewer/ # Original Molstar viewer source (reference)
βββ docking-viewer/ # Original docking viewer source (reference)
βββ mesoscale-explorer/ # Original mesoscale explorer source (reference)
βββ mvs-stories/ # Original MVS stories source (reference)
βββ README.md # This file
- Runtime: Val Town (Deno-based)
- Framework: Hono for routing
- UI: React 18.2.0 via esm.sh
- Molstar: JSR package
jsr:@zachcp/molstar@5.3.4 - Language: TypeScript/TSX
All dependencies are imported using the JSR protocol:
import { Viewer } from "jsr:@zachcp/molstar@5.3.4";
Available exports from jsr:@zachcp/molstar:
.(main export - includes Viewer class)./plugin-ui./plugin./plugin-state./canvas3d./data./state./task./util
import { Hono } from "jsr:@hono/hono@4";
JSR (JavaScript Registry) provides native Deno/TypeScript support and works seamlessly in Val Town's runtime environment.
The backend uses Hono from JSR for HTTP routing. Each route corresponds to a Molstar app:
import { Hono } from "jsr:@hono/hono@4";
import { renderToString } from "https://esm.sh/react-dom@18.2.0/server";
const app = new Hono();
app.get("/", (c) => {
// Home page listing all apps
});
app.get("/viewer", (c) => {
const html = renderToString(ViewerApp());
return c.html(html);
});
// ... etc
Each app is a self-contained TSX component that returns a complete HTML document:
/** @jsxImportSource https://esm.sh/react@18.2.0 */
export default function ViewerApp() {
return (
<html lang="en">
<head>
<meta charSet="UTF-8" />
<title>Mol* Viewer</title>
</head>
<body>
<div id="molstar-container" />
<script type="module" dangerouslySetInnerHTML={{ __html: `
import { Viewer } from "jsr:@zachcp/molstar@5.3.4";
// Initialize viewer
`}} />
</body>
</html>
);
}
Common TypeScript interfaces and constants are defined in shared/types.ts for use across backend and frontend.
The project is currently scaffolded with:
- β Backend routing with Hono from JSR
- β TSX components for each app
- β Shared types and metadata
- β Viewer app fully functional with JSR imports
- β³ Docking viewer (scaffolded)
- β³ Mesoscale explorer (scaffolded)
- β³ MVS Stories (scaffolded)
- Implement Molstar initialization in each app component
- Add proper error handling and loading states
- Style the apps with proper CSS
- Add interactive controls for each viewer
- Implement app-specific features:
- Viewer: Load PDB structures by ID
- Docking Viewer: Load and compare docking results
- Mesoscale Explorer: Load mesoscale structures
- MVS Stories: Story navigation and playback
- All components use the
/** @jsxImportSource https://esm.sh/react@18.2.0 */pragma - JSR imports use the
jsr:protocol (e.g.,jsr:@zachcp/molstar@5.3.4) - Inline styles use React style objects with camelCase properties
- Client-side scripts are injected using
dangerouslySetInnerHTML - Code in
shared/must work in both server and browser environments
When adding new features:
- Keep backend routing logic in
backend/ - Keep TSX components in
frontend/apps/ - Keep shared types in
shared/types.ts - Use JSR imports for Molstar dependencies
- Follow Val Town best practices from
AGENTS.md
Copyright (c) 2018-2025 mol* contributors, licensed under MIT