Skip to main content

MolGFX

Documentation

MolGFX is a semantic molecular-rendering library for Python, Rust, and WebGPU. It renders structures supplied by MolFrame as interactive browser scenes or deterministic native images. MolGFX does not parse, fetch, dock, simulate, or open an application window.

MolGFX haemoglobin cartoon, heme, and local pocket

Install

macOS builds include native Metal and Vulkan portability. For repeatable headless images on virtual machines, install a software Vulkan adapter and select it with WGPU_BACKEND=vulkan and VK_DRIVER_FILES. Byte-exact rendering is checked on an explicit reference adapter; Apple's hosted paravirtual Metal device produces different pixels for repeated static exposures.

python -m pip install --upgrade molgfx

Render a structure

import molframe
import molgfx

# Infer bonds so atom-and-bond representations have sticks to draw.
structure = molframe.read("structure.cif").infer_bonds()
scene = molgfx.Scene(structure)
scene.add(molgfx.rep.cartoon(target=molgfx.sel.protein(), color=molgfx.color.chain()))
scene.add(molgfx.rep.ball_and_stick(target=molgfx.sel.ligands()))

molgfx.Renderer().render_image(scene, size=(1920, 1080)).save("structure.png")

Cartoon representations accept aspect_ratio (width divided by depth, default 5.0) and arrow_factor (terminal beta-arrow shoulder scale, default 1.5). Set arrow_factor=0.0 to disable arrows. The Rust builder and browser scene contract expose the same controls. helix_profile and nucleic_profile select "elliptical", "rounded" (planar faces with semicircular ends), or "square" cross-sections (helix default: elliptical; nucleic default: square). Rust uses molgfx::rep::CartoonProfile. Profiles change the cross-section while preserving source guide coordinates and picking anchors.

Set direction_wedges=True on molgfx.rep.cartoon(...) to draw a flat N-to-C direction triangle at each selected polymer guide (default: False). The triangle's width and length are half the cartoon width. It follows live source coordinates and picks the guide atom. A selection containing one guide uses the direction of its source polymer; an isolated residue requires N/CA/C (or C5'/C4'/C3' for nucleic acids). Missing direction atoms produce a render error. Glycan cartoon mode rejects this control. Rust uses .direction_wedges(true); commands use direction_wedges=true.

Use gaps="dashed" on cartoon, backbone, trace, tube or putty to connect missing polymer intervals with closed tubes of radius 0.15 Å and 0.5 Å dashes separated by 0.5 Å. The default is "hidden". Chain boundaries and excluded residues remain disconnected. Connectors follow live coordinates and retain source atom identity for picking. Rust uses .gaps(molgfx::rep::GapStyle::Dashed); commands use gaps=dashed.

Presentation effects are explicit values on a render profile:

profile = molgfx.profile.converged().with_effect(molgfx.effect.bloom(intensity=0.8))
renderer = molgfx.Renderer(profile=profile)

molgfx.effect also provides depth cue, depth of field, motion blur, backdrop, lighting, shape cues, display and anti-aliasing constructors. Invalid settings raise an error before rendering. without_effect(kind) restores the quality recipe's default for that kind. Rust exposes the same values under molgfx::profile; WASM Renderer.create accepts an optional effects JSON array of { "kind": ..., "settings": ... } records validated by the shared core.

For native HDR export, retain scene-linear highlights in half-float OpenEXR:

hdr = molgfx.Renderer(profile=molgfx.profile.converged()).render_hdr_image(scene, size=(1920, 1080))
hdr.save("structure.exr")

HdrImage exposes width, height, exr_bytes(), rgba16f() and quality_json(). HDR capture completes the profile's exposure without baking in bloom, exposure, tone mapping, display conversion or screen overlays. Python .save() accepts only .exr filenames and raises ValueError before writing any other format. Rust uses HdrImage::save_exr and also supports an explicit camera through Renderer::render_hdr_image_with_camera.

A structure is optional for a scalar-volume scene. Bind voxel values separately from the portable scene specification; the same grid can drive several presentations without another upload:

import hashlib
import struct
import molgfx

values = [
    max(0.0, 1.0 - ((x - 3.5) ** 2 + (y - 3.5) ** 2 + (z - 3.5) ** 2) ** 0.5 / 4.0)
    for z in range(8)
    for y in range(8)
    for x in range(8)
]
source = molgfx.data.source(hashlib.sha256(struct.pack("<512f", *values)).hexdigest())
scene = molgfx.Scene()
volume = molgfx.density.volume(source=source, dimensions=(8, 8, 8))
volume = volume.isosurface(0.5, color=(220, 40, 70)).direct(
    [
        (0.0, (50, 150, 255), 0.0),
        (1.0, (50, 150, 255), 0.4),
    ]
)
identity = scene.add(volume)
scene.bind_volume(identity, values)
molgfx.Renderer().render_image(scene, size=(640, 480)).save("density.png")

values are indexed with x fastest, then y, then z. For a map read by MolFrame, supply its column-major voxel_to_world affine instead of assuming unit voxels at the origin. Region bounds use half-open voxel indices.

Targets are MolFrame queries, and a small command language works around them through molgfx.Session:

show cartoon, protein
select pocket, byres (within 5 of resname HEM) and protein
show licorice, $pocket
color orange, $pocket

Named snapshots capture the complete authored scene (camera, styles, interaction state, assemblies and overlays), not coordinates, pixels or renderer buffers:

session.snapshot_save("overview")
session.execute("color orange, protein")
session.snapshot_restore("overview")
session.undo()  # Return to the state immediately before restoration.
session.snapshot_remove("overview")

The same operations are commands: snapshot save|restore|remove NAME. Named captures round-trip in Session.to_json() and Session.from_json(scene, json). Restoration requires local bindings with matching content identities; missing or mismatched assets leave the live scene unchanged. Revisions advance on restore and undo rather than returning to the captured revision. Rust uses the canonical interop::SceneSnapshot, Scene::snapshot, Scene::restore_snapshot and PatchOperation::RestoreSnapshot. Frame export remains render_sequence or render_camera_path; no retained movie request is an export implementation.

The Rust engine opens no window and owns no application panels. This repository also supplies the official browser host: a canvas, navigation and semantic picks, not a Workbench, console, toolbar or file picker. Session remains the sole command and undo/redo authority. Python notebooks use this same frontend through AnyWidget, a normal package dependency.

session = molgfx.Session(structure)
session.execute("show cartoon, protein")
viewer = molgfx.Viewer(session)
viewer  # Display in Jupyter.

Browser SDK

npm install molgfx
import { Viewer } from "molgfx";
import "molgfx/viewer.css";

const viewer = await Viewer.create(document.getElementById("scene")!);
await viewer.load(await fetch("structure.cif").then(r => r.arrayBuffer()), { name: "structure.cif" });
viewer.execute("show cartoon, protein");
// On host teardown:
await viewer.dispose();

The one npm package exports molgfx, molgfx/viewer, molgfx/anywidget and molgfx/react. The React adapter owns viewer mount/dispose, not molecular state. Public TypeScript declarations never expose the raw wasm ABI.

"use client";
import { MolGFXViewer } from "molgfx/react";
import "molgfx/viewer.css";

export function Protein({ bytes }: { bytes: Uint8Array }) {
  return <MolGFXViewer structure={bytes} name="protein.cif"
    style={{ width: "100%", height: 480 }}
    onError={error => console.error(error.message)} />;
}

Keep the input byte object stable between unchanged React renders. The adapter reuses its Viewer for structure updates and disposes it on unmount; it does not duplicate Scene, Session or rendering semantics.

Shared frontend build

nix develop -c npm ci --prefix web
nix develop -c npm run build --prefix web
nix develop -c npm test --prefix web
nix develop -c npm pack ./web --pack-destination web

web/scripts/build.mjs runs wasm-pack into ignored web/generated, then emits the official package into ignored web/dist and copies identical artifacts to Python static assets. The documentation site imports the public npm package; Next.js emits its WASM asset rather than loading a private runtime directory. A content-hash manifest and archive-level checks prove that npm tarballs and Python wheels carry identical runtime bytes. Build before running maturin from a source checkout; PyPI source distributions include the prebuilt runtime and need Python >=3.12, Rust and dependency fetching, but no Node, wasm-pack or adjacent MolFrame checkout. Cargo, Python and npm versions must match. Native wheel builds repair external libraries; release gates rebuild the source archive and exercise fresh installed wheels before publication.

Python and npm have separate release workflows. Published versions are immutable; release 0.4.1 supersedes the existing PyPI 0.4.0 package. npm trusted publishing requires the package owner to authorize this repository and release workflow. Until the first registry publication, the docs use the public package through a local npm dependency, exercising the same exports and bundler asset resolution.

The optional Mol* adapter runs the requested local Mol* source checkout in real Chromium/WebGL2. Install its locked Node transport dependencies, then provide a real Chromium executable and PyMOL binary:

nix develop -c npm ci --prefix crates/molgfx-bench/parity
MOLSTAR_CHROMIUM=/path/to/chrome nix develop -c cargo run -p molgfx-bench --bin parity -- \
  --manifest crates/molgfx-bench/parity/gallery.json --cache ~/.cache/molgfx-corpus \
  --output target/gallery --case P2-iso-solid-skewMRC \
  --recipe molgfx-converged --recipe pymol-ray --recipe molstar-imagepass \
  --molstar-root ../molstar --pymol /path/to/pymol

The manifest records explicit omissions for recipes that cannot faithfully represent a case; failures are never counted as omissions. Review visual semantics before blessing golden images. Motion-blur orbit cases also require --ffmpeg /path/to/ffmpeg.

Writing queries and commands walks through both, and the MolFrame query reference lists every keyword.

Status

Beta. Public APIs are available through the molgfx facade; MolFrame provides structure input and molecular selection semantics.

License

MIT

Metadata

Release files for molgfx 0.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for molgfx 0.5.3
File Size Uploaded Provenance
molgfx-0.5.3.tar.gz 4.4 MB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for molgfx 0.5.3
File
molgfx-0.5.3-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
molgfx-0.5.3-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details
molgfx-0.5.3-cp312-abi3-manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64 Details
molgfx-0.5.3-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
molgfx-0.5.3-cp312-abi3-macosx_10_12_x86_64.whl CPython 3.12 abi3 macOS 10.12+ x86-64 Details

Total release size: 83.4 MB

Release files / molgfx-0.5.3.tar.gz

Download URL molgfx-0.5.3.tar.gz
Size 4.4 MB
Tags Source
SHA-256 checksum
How to use checksums
da14d75836871d5d2dfcc6294137849d9e1f03370b6a76ea968a7b6e16ae9990
BLAKE2b-256 checksum
How to use checksums
fcd5ae7baf9251a638cf7da8a000f62e5948bce63d212467ec13895bc9826946
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / molgfx-0.5.3-cp312-abi3-win_amd64.whl

Download URL molgfx-0.5.3-cp312-abi3-win_amd64.whl
Size 23.5 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
40b02feb3c86be6e1bc5b08812b746e799501dd7c9a7381f216ab6009cb785be
BLAKE2b-256 checksum
How to use checksums
90e20187395b33976b87fe69d6eef641b62a2901b120ab9db82c1248053eaec5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / molgfx-0.5.3-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL molgfx-0.5.3-cp312-abi3-manylinux_2_28_x86_64.whl
Size 14.3 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
b1a4d4023ec320e3b1f0150748bf9d67b3e0fd712e19f422da7c399e461b5759
BLAKE2b-256 checksum
How to use checksums
de54a1b04211176764615fae54fd9fa89efcff3a22b23bcf44cd69732d6fa84c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / molgfx-0.5.3-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL molgfx-0.5.3-cp312-abi3-manylinux_2_28_aarch64.whl
Size 13.8 MB
Tags CPython 3.12 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
9250da1da512be4bea6320c0aa8c86cd3022a93ff41fad29d84867ecd0efc106
BLAKE2b-256 checksum
How to use checksums
2cad147bb704d93460e1b0fa5fd3bec0e9ce1e29a0099f3461b54c85e8b655d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / molgfx-0.5.3-cp312-abi3-macosx_11_0_arm64.whl

Download URL molgfx-0.5.3-cp312-abi3-macosx_11_0_arm64.whl
Size 13.4 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
29b7cf4e41b86b3c0bd7298eee31b958beee2ef2cc1ded8dcb54d5f0239faadc
BLAKE2b-256 checksum
How to use checksums
332d1aa94d4baf160c7ad0e3ef69501137525763a99e93924037c242da57bb98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / molgfx-0.5.3-cp312-abi3-macosx_10_12_x86_64.whl

Download URL molgfx-0.5.3-cp312-abi3-macosx_10_12_x86_64.whl
Size 14.1 MB
Tags CPython 3.12 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
367618c7de7c7c13dc98601978d8a4d9c5821c3b32e9254f0f6827ec634241c9
BLAKE2b-256 checksum
How to use checksums
9a9b992a998eec2e7881bc6d80de8e4df48581e6e0b429c67817613261b3c542
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Security for molgfx 0.5.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for molgfx-0.5.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page