# 3dmol/3dmol.js architecture

> Architecture diagram of the GitHub repository 3dmol/3dmol.js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/3dmol/3dmol.js
- Repository: https://github.com/3dmol/3dmol.js

## Overview

3Dmol.js is a browser-based molecular visualization library. Its main workflow is to accept molecular data, parse it into models, let a viewer apply molecular styles and optional surfaces or shapes, then render the scene interactively with WebGL. The graph also preserves documented capabilities for labels, atom selection, trajectories, and the optional learning controls. Some relationships are supported only by the README or source-index references; unsampled implementation details are not inferred.

Main entry points: [`src/GLViewer.ts`](https://github.com/3dmol/3dmol.js/blob/master/src/GLViewer.ts) (Viewer API), [`src/GLModel.ts`](https://github.com/3dmol/3dmol.js/blob/master/src/GLModel.ts) (Molecular model), [`src/ui/ui.ts`](https://github.com/3dmol/3dmol.js/blob/master/src/ui/ui.ts) (Viewer controls), [`src/GLShape.ts`](https://github.com/3dmol/3dmol.js/blob/master/src/GLShape.ts) (Geometric shapes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Molecular data"]
  node_parsers["Format parsers"]
  node_parser_registry["Parser registry<br/>[index.ts]"]
  node_model["Molecular model<br/>[GLModel.ts]"]
  node_specs["Selection and style specs<br/>[specs.ts]"]
end

subgraph group_scene["Scene construction"]
  node_viewer["Viewer API<br/>[GLViewer.ts]"]
  node_draw["Molecular drawing<br/>[GLDraw.ts]"]
  node_cartoon["Cartoon rendering<br/>[glcartoon.ts]"]
  node_surface_algorithm["Surface computation<br/>[ProteinSurface4.ts]"]
  node_surface_worker["Surface worker<br/>[SurfaceWorker.js]"]
  node_volume_data["Volume data<br/>[VolumeData.ts]"]
  node_shapes["Geometric shapes<br/>[GLShape.ts]"]
  node_labels["Labels<br/>[Label.ts]"]
  node_colors["Colors and gradients<br/>[colors.ts]"]
  node_gradient["Color gradients<br/>[Gradient.ts]"]
  node_scene_state["Scene serialization<br/>[SceneState.ts]"]
end

subgraph group_render["WebGL rendering"]
  node_renderer["WebGL renderer<br/>[Renderer.ts]"]
  node_webgl_core["WebGL primitives"]
  node_webgl_materials["Render materials"]
  node_resource_disposal["GPU resource disposal"]
end

subgraph group_interaction["Viewer interaction"]
  node_ui_state["Control state<br/>[state.ts]"]
  node_ui["Viewer controls<br/>[ui.ts]"]
  node_selection["Selection controls<br/>[selection.ts]"]
  node_styles["Style controls<br/>[styles.ts]"]
  node_trajectory["Trajectory controls<br/>[trajectory.ts]"]
  node_learning["Learning interface<br/>[learning.ts]"]
end

node_user(("Application user"))
node_remote_data(("Structure source"))

node_user -->|"uses"| node_viewer
node_remote_data -->|"loads data"| node_viewer
node_viewer -->|"creates models"| node_model
node_model -->|"parses input"| node_parser_registry
node_parser_registry -->|"dispatches formats"| node_parsers
node_viewer -->|"adds shapes"| node_shapes
node_viewer -->|"manages labels"| node_labels
node_viewer -->|"uses volume data"| node_volume_data
node_viewer -->|"encodes scene"| node_scene_state
node_model -->|"builds geometry"| node_draw
node_model -->|"uses cartoon code"| node_cartoon
node_model -->|"uses atom specs"| node_specs
node_shapes -->|"computes surfaces"| node_surface_algorithm
node_shapes -->|"uses volume data"| node_volume_data
node_shapes -->|"snapshots geometry"| node_scene_state
node_model -->|"colors atoms"| node_colors
node_gradient -->|"uses color values"| node_colors
node_renderer -->|"uses primitives"| node_webgl_core
node_renderer -->|"uses materials"| node_webgl_materials
node_renderer -->|"disposes resources"| node_resource_disposal
node_viewer -.->|"renders scene"| node_renderer
node_ui_state -->|"controls viewer"| node_viewer
node_ui -->|"reads state"| node_ui_state
node_ui -->|"uses selection controls"| node_selection
node_ui -->|"uses style controls"| node_styles
node_ui -->|"creates controls"| node_trajectory
node_learning -->|"uses control state"| node_ui_state
node_surface_worker -.->|"may compute surfaces"| node_surface_algorithm

click node_parsers "https://github.com/3dmol/3dmol.js/tree/master/src/parsers"
click node_parser_registry "https://github.com/3dmol/3dmol.js/blob/master/src/parsers/index.ts"
click node_model "https://github.com/3dmol/3dmol.js/blob/master/src/GLModel.ts"
click node_specs "https://github.com/3dmol/3dmol.js/blob/master/src/specs.ts"
click node_viewer "https://github.com/3dmol/3dmol.js/blob/master/src/GLViewer.ts"
click node_draw "https://github.com/3dmol/3dmol.js/blob/master/src/GLDraw.ts"
click node_cartoon "https://github.com/3dmol/3dmol.js/blob/master/src/glcartoon.ts"
click node_surface_algorithm "https://github.com/3dmol/3dmol.js/blob/master/src/ProteinSurface4.ts"
click node_surface_worker "https://github.com/3dmol/3dmol.js/blob/master/src/SurfaceWorker.js"
click node_volume_data "https://github.com/3dmol/3dmol.js/blob/master/src/VolumeData.ts"
click node_shapes "https://github.com/3dmol/3dmol.js/blob/master/src/GLShape.ts"
click node_labels "https://github.com/3dmol/3dmol.js/blob/master/src/Label.ts"
click node_colors "https://github.com/3dmol/3dmol.js/blob/master/src/colors.ts"
click node_gradient "https://github.com/3dmol/3dmol.js/blob/master/src/Gradient.ts"
click node_scene_state "https://github.com/3dmol/3dmol.js/blob/master/src/SceneState.ts"
click node_renderer "https://github.com/3dmol/3dmol.js/blob/master/src/WebGL/Renderer.ts"
click node_webgl_core "https://github.com/3dmol/3dmol.js/tree/master/src/WebGL/core"
click node_webgl_materials "https://github.com/3dmol/3dmol.js/tree/master/src/WebGL/materials"
click node_resource_disposal "https://github.com/3dmol/3dmol.js/blob/master/src/WebGL/disposeObjectResources.ts"
click node_ui_state "https://github.com/3dmol/3dmol.js/blob/master/src/ui/state.ts"
click node_ui "https://github.com/3dmol/3dmol.js/blob/master/src/ui/ui.ts"
click node_selection "https://github.com/3dmol/3dmol.js/blob/master/src/ui/selection.ts"
click node_styles "https://github.com/3dmol/3dmol.js/blob/master/src/ui/styles.ts"
click node_trajectory "https://github.com/3dmol/3dmol.js/blob/master/src/ui/trajectory.ts"
click node_learning "https://github.com/3dmol/3dmol.js/blob/master/src/ui/learning.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_parsers,node_parser_registry,node_model,node_specs,node_user toneBlue
class node_viewer,node_draw,node_cartoon,node_surface_algorithm,node_surface_worker,node_volume_data,node_shapes,node_labels,node_colors,node_gradient,node_scene_state toneAmber
class node_renderer,node_webgl_core,node_webgl_materials,node_resource_disposal toneMint
class node_ui_state,node_ui,node_selection,node_styles,node_trajectory,node_learning toneRose
class node_remote_data toneIndigo
```

## Components

### Molecular data

- [Format parsers](https://github.com/3dmol/3dmol.js/tree/master/src/parsers): `src/parsers`
- [Parser registry](https://github.com/3dmol/3dmol.js/blob/master/src/parsers/index.ts): `src/parsers/index.ts`
- [Molecular model](https://github.com/3dmol/3dmol.js/blob/master/src/GLModel.ts): `src/GLModel.ts`
- [Selection and style specs](https://github.com/3dmol/3dmol.js/blob/master/src/specs.ts): `src/specs.ts`

### Scene construction

- [Viewer API](https://github.com/3dmol/3dmol.js/blob/master/src/GLViewer.ts): `src/GLViewer.ts`
- [Molecular drawing](https://github.com/3dmol/3dmol.js/blob/master/src/GLDraw.ts): `src/GLDraw.ts`
- [Cartoon rendering](https://github.com/3dmol/3dmol.js/blob/master/src/glcartoon.ts): `src/glcartoon.ts`
- [Surface computation](https://github.com/3dmol/3dmol.js/blob/master/src/ProteinSurface4.ts): `src/ProteinSurface4.ts`
- [Surface worker](https://github.com/3dmol/3dmol.js/blob/master/src/SurfaceWorker.js): `src/SurfaceWorker.js`
- [Volume data](https://github.com/3dmol/3dmol.js/blob/master/src/VolumeData.ts): `src/VolumeData.ts`
- [Geometric shapes](https://github.com/3dmol/3dmol.js/blob/master/src/GLShape.ts): `src/GLShape.ts`
- [Labels](https://github.com/3dmol/3dmol.js/blob/master/src/Label.ts): `src/Label.ts`
- [Colors and gradients](https://github.com/3dmol/3dmol.js/blob/master/src/colors.ts): `src/colors.ts`
- [Color gradients](https://github.com/3dmol/3dmol.js/blob/master/src/Gradient.ts): `src/Gradient.ts`
- [Scene serialization](https://github.com/3dmol/3dmol.js/blob/master/src/SceneState.ts): `src/SceneState.ts`

### WebGL rendering

- [WebGL renderer](https://github.com/3dmol/3dmol.js/blob/master/src/WebGL/Renderer.ts): `src/WebGL/Renderer.ts`
- [WebGL primitives](https://github.com/3dmol/3dmol.js/tree/master/src/WebGL/core): `src/WebGL/core`
- [Render materials](https://github.com/3dmol/3dmol.js/tree/master/src/WebGL/materials): `src/WebGL/materials`
- [GPU resource disposal](https://github.com/3dmol/3dmol.js/blob/master/src/WebGL/disposeObjectResources.ts): `src/WebGL/disposeObjectResources.ts`

### Viewer interaction

- [Control state](https://github.com/3dmol/3dmol.js/blob/master/src/ui/state.ts): `src/ui/state.ts`
- [Viewer controls](https://github.com/3dmol/3dmol.js/blob/master/src/ui/ui.ts): `src/ui/ui.ts`
- [Selection controls](https://github.com/3dmol/3dmol.js/blob/master/src/ui/selection.ts): `src/ui/selection.ts`
- [Style controls](https://github.com/3dmol/3dmol.js/blob/master/src/ui/styles.ts): `src/ui/styles.ts`
- [Trajectory controls](https://github.com/3dmol/3dmol.js/blob/master/src/ui/trajectory.ts): `src/ui/trajectory.ts`
- [Learning interface](https://github.com/3dmol/3dmol.js/blob/master/src/ui/learning.ts): `src/ui/learning.ts`

### Other components

- **Application user**
- **Structure source**

## Connections

- Application user → Viewer API: uses (evidence: `README.md`)
- Structure source → Viewer API: loads data (evidence: `README.md`)
- Viewer API → Molecular model: creates models (evidence: `src/GLViewer.ts`)
- Molecular model → Parser registry: parses input (evidence: `src/GLModel.ts`)
- Parser registry → Format parsers: dispatches formats (evidence: `src/parsers/index.ts`)
- Viewer API → Geometric shapes: adds shapes (evidence: `src/GLViewer.ts`)
- Viewer API → Labels: manages labels (evidence: `src/GLViewer.ts`)
- Viewer API → Volume data: uses volume data (evidence: `src/GLViewer.ts`)
- Viewer API → Scene serialization: encodes scene (evidence: `src/GLViewer.ts`)
- Molecular model → Molecular drawing: builds geometry (evidence: `src/GLModel.ts`)
- Molecular model → Cartoon rendering: uses cartoon code (evidence: `src/GLModel.ts`)
- Molecular model → Selection and style specs: uses atom specs (evidence: `src/GLModel.ts`)
- Geometric shapes → Surface computation: computes surfaces (evidence: `src/GLShape.ts`)
- Geometric shapes → Volume data: uses volume data (evidence: `src/GLShape.ts`)
- Geometric shapes → Scene serialization: snapshots geometry (evidence: `src/GLShape.ts`)
- Molecular model → Colors and gradients: colors atoms (evidence: `src/GLModel.ts`)
- Color gradients → Colors and gradients: uses color values (evidence: `src/Gradient.ts`)
- WebGL renderer → WebGL primitives: uses primitives (evidence: `src/WebGL/Renderer.ts`)
- WebGL renderer → Render materials: uses materials (evidence: `src/WebGL/Renderer.ts`)
- WebGL renderer → GPU resource disposal: disposes resources (evidence: `src/WebGL/Renderer.ts`)
- Viewer API → WebGL renderer: renders scene
- Control state → Viewer API: controls viewer (evidence: `src/ui/state.ts`)
- Viewer controls → Control state: reads state (evidence: `src/ui/ui.ts`)
- Viewer controls → Selection controls: uses selection controls (evidence: `src/ui/ui.ts`)
- Viewer controls → Style controls: uses style controls (evidence: `src/ui/ui.ts`)
- Viewer controls → Trajectory controls: creates controls (evidence: `src/ui/ui.ts`)
- Learning interface → Control state: uses control state (evidence: `src/ui/learning.ts`)
- Surface worker → Surface computation: may compute surfaces
