Skip to main content

Molecular visualization tools

Project description

COSMol-viewer

A high-performance molecular viewer for Python and Rust, powered by a unified Rust core. It supports both in-notebook visualization and native desktop rendering, with smooth playback for scientific animations.

COSMol-viewer is a compact, cross-platform renderer for molecular and geometric scenes. Unlike purely notebook-bound solutions such as py3Dmol, COSMol-viewer runs everywhere:

  • Native desktop window (Python or Rust) via egui
  • Jupyter / IPython notebook via WASM backend
  • Rust applications

All implementations share the same Rust rendering engine, ensuring consistent performance and visual output.


Quick concepts

  • Scene: container for shapes (molecules, proteins, spheres, etc.).
  • Viewer.render(scene, ...): create a static viewer bound to a canvas (native or notebook). Good for static visualization.
  • viewer.update(scene): push incremental changes after Viewer.render() (real-time / streaming use-cases).
  • Viewer.play(frames, interval, loops, width, height, smooth): recommended for precomputed animations and demonstrations. The viewer takes care of playback timing and looping.

Why prefer play for demos?

  • Single call API (hand off responsibility to the viewer).
  • Built-in timing & loop control.
  • Optional smooth interpolation between frames for visually pleasing playback even when input frame rate is low.

Why keep update?

  • update is ideal for real-time simulations, MD runs, or streaming data where frames are not precomputed. It provides strict fidelity (no interpolation) and minimal latency.

Usage

python

See examples in Google Colab.

Install with pip install cosmol-viewer

1. Static molecular rendering

from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
    
mol_data  = parse_sdf(open("molecule.sdf", "r", encoding="utf-8").read())

mol = Molecules(mol_data).centered()

scene = Scene()
scene.add_shape(mol, "mol")

viewer = Viewer.render(scene, width=600, height=400)

print("Press Any Key to exit...", end='', flush=True)
_ = input()  # Keep the viewer open until you decide to close

2. Animation playback with Viewer.play

from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules

frames = []

for i in range(1, 10):
    with open(f"frames/frame_{i}.sdf", "r") as f:
        sdf = f.read()
        mol = Molecules(parse_sdf(sdf)).centered()

    scene = Scene()
    scene.add_shape(mol, "mol")
    frames.append(scene)

Viewer.play(frames, interval=0.033, loops=-1, width=800, height=500, smooth=True) # loops=-1 for infinite repeat

more examples can be found in the examples folder:

cd cosmol_viewer
python .\examples\render_protein.py

Documentation

Please check out our documentation at here.


Contact

For any questions, issues, or suggestions, please contact wjt@cosmol.org or open an issue in the repository. We will review and address them as promptly as possible.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cosmol_viewer-0.2.0.dev1.tar.gz (93.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cosmol_viewer-0.2.0.dev1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

cosmol_viewer-0.2.0.dev1-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (6.5 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

cosmol_viewer-0.2.0.dev1-cp310-abi3-win_amd64.whl (4.8 MB view details)

Uploaded CPython 3.10+Windows x86-64

cosmol_viewer-0.2.0.dev1-cp310-abi3-win32.whl (4.8 MB view details)

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (6.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.2.0.dev1-cp310-abi3-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.0.dev1-cp310-abi3-macosx_10_12_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file cosmol_viewer-0.2.0.dev1.tar.gz.

File metadata

  • Download URL: cosmol_viewer-0.2.0.dev1.tar.gz
  • Upload date:
  • Size: 93.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for cosmol_viewer-0.2.0.dev1.tar.gz
Algorithm Hash digest
SHA256 5f325f461dff51615271f1c48987965c0a1c22274172fac0ebd111dd47d64254
MD5 e40877e67ef151f5d963ed15cd8c46a6
BLAKE2b-256 c3099012b773aa1754426d6af0755862920b2402a7353ef15de9614ccd4ae947

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9b00d299b1aac356ddbae034f94e6579a921e0c1eb1d57f5e5c2b8de9e502e2a
MD5 4e29a05d247f03e600540748de353413
BLAKE2b-256 16bdf00aa238cbc3efd9723993fc2ad2cf0b4577eac9843d087a8df9784696eb

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 cec18dc89853e9ddff8238bf19e9b7e3d9d7782513df83f7da758329b7f6a3eb
MD5 6445875b99cc2c6d338a73e10ac08324
BLAKE2b-256 694713cb3b4c09c7f48ee591c9bd33e47219f1a700d79d43538b593fee3ef053

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 86609c6ffc97ef0a4ae43c5cfb0750c644ef0c9b18953838bdb04317db7bce15
MD5 fecd030d952c6164a2a59a82ff300361
BLAKE2b-256 c6b371e19cd01f77efe21c2e78586e87980b134e93aaaf89e4bdd8acdafbee7e

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 aa91971cac666088508fc9bac9aadaf5b315d8e584d33198cf78a2632619dbfe
MD5 0ad931981b1f4fa9dfe5ff812b60e001
BLAKE2b-256 ab9ae371c31a2dfa2180a29a37ead4fef572553679c55b4b50b61fa39d27ed27

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78490d05bd7112771b74d0e3658cb842ec6214893d984ad9a1c03f24b4c4839b
MD5 7d1953cf14579515355c2112dedb58b4
BLAKE2b-256 e49b4bc71252a41f7d74a60b17826df7cc5ac2ba4b7f5a841f32f08c2c83efbf

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b6669b452dbb2f4c3953f5ff8c4d5f87790bdb19953e165a17e3cacfec483a95
MD5 63521bdd51ee212b3f8cc7dea082f4dc
BLAKE2b-256 759d9166683017016b7bfd2f21991532d3731dd56c7855901d8fac47bbb5a1b4

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 04c088a97aa9f43b94aa40a4e96a3517d80e279937df3a79781e757d4ccf3035
MD5 5caa8149500e05ac433709860ed58afe
BLAKE2b-256 c3ad059fdc887e393c22edb093c7b55e2a38ac0ece83a1f5c52c57dd99c81760

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8869ae09dd5c3441330d2d6aa3ce1c17d3dd8c93e7162f9d097457c203e349e9
MD5 49c684cd2e1e6299b590fc69085e52e6
BLAKE2b-256 6fcf9923b29cac1abbaf6a6d429a2d167d9f181c48aa57e8e596c73a2b725b03

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0a516d42ce1ef150c73bcca03d8a8ee068868739bddd77e5512d9ff852501c57
MD5 edd5ac37fd828c3809bad20e431d61c8
BLAKE2b-256 30994d783b314d42121ad68de9b9c87047d7cebfb43a44177af99acde11c088e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page