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).
  • Animation: An Animation object containing frames and settings.
  • Viewer.play(animation, 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 Molecule, Scene, Viewer

mol_data = open("molecule.sdf", "r", encoding="utf-8").read()

mol = Molecule.from_sdf(mol_data).centered()

scene = Scene()

scene.set_scale(1.0)

scene.add_shape_with_id("molecule", mol)

viewer = Viewer.render(scene, width=800, height=500)

viewer.save_image("screenshot.png")

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, Molecule, Animation

anim = Animation(interval=0.05, loops=-1, smooth=False)
for i in range(1, 10):
    with open(f"frames/frame_{i}.sdf", "r") as f:
        mol = Molecule.from_sdf(f.read())

    scene = Scene()
    scene.add_shape(mol)
    anim.add_frame(scene)

Viewer.play(anim, width=800, height=500) # 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.7.tar.gz (94.7 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.7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

cosmol_viewer-0.2.7-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (4.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

cosmol_viewer-0.2.7-cp310-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

cosmol_viewer-0.2.7-cp310-abi3-win32.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

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

cosmol_viewer-0.2.7-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (4.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

cosmol_viewer-0.2.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.2.7-cp310-abi3-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.7-cp310-abi3-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file cosmol_viewer-0.2.7.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.7.tar.gz
Algorithm Hash digest
SHA256 bf220484c8fef71547778c2b9298549c2c3f3e1f419a8dfd1020d3dd88203882
MD5 e21689c8cc85b58ce9a066d4e3cf073a
BLAKE2b-256 3f25e15f5b43757f418adba6d73334bba6f78d54a1b8193cc80251ad839ad2f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9bb8ab89fccc89b01eb33583cb9da54f0041ff0b63f2e4a7f08df1ff0c9f8f5c
MD5 058109eeb32e7399bd6ecea5fdf72bf2
BLAKE2b-256 f10b47a1e7ff720c969d2f181e848943808b6d3e91c79cceaa70641e6a199bb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 75602ef8d81159503500e9d60d3b9eecbdf666b317fee0561e688abc3e01569a
MD5 d4b450da98392dec3f4ac0caadbdaa07
BLAKE2b-256 57e77459a909e085ff6e56eb5433d4c6c630e316d8aa613b7dea391d35934658

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.7-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 560c318b8d81811ad1ba56feb507e9bcbedac31af50db6d4f83ace4210754d1b
MD5 d2584e8d0fab7b9682afb414cfe93354
BLAKE2b-256 9b8c536284bde5eef4b7509af34cc1ac5c4a939e9fb0be939a2848beb919b293

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.7-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 61cc4ddf24fb67eaabc4be8e8b65e8aed6af2465ec3a3666452ee47f0823040d
MD5 31b26edbbff430ad7f33b90d273a1f95
BLAKE2b-256 04f8a207b6a6925f5fba1f51fe7c1bb574893e8a3aca605ef73eb4fbb830f390

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 19d59c2c732aa08a6787e80b12c35e6532608ae93faa2139c6b34f74a81ab231
MD5 3999270c5eeceb10aabe8905cecba6fc
BLAKE2b-256 910d252d1cadd6f274b2dec771ed6ea89116aa773161cdbe08f3e58bda658368

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ac38fa3d567e38e2404da634af0b62d5fef499756f4bc5aa785d8d0fa2c4dd0a
MD5 d302a50352f20eb361a95ca1bb0092d2
BLAKE2b-256 c6ed1d4113e6a39fe1a50772e56cc3e3e0f09fd59274ee6ec008c5221bb51261

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dd098fd21edcb7b0de6ed54e02b6355830d6f99e4da930c7cba8444ff1230d7b
MD5 50e79db50e7c09bda5107d764360c317
BLAKE2b-256 cc4ab74c2d1eb8aeef7b4a5c0a9c8fa9ac015a6dc38dd1f33824c852743d763d

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.7-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d8f315b9d68efab0c876b1c036cea601470b4e70ddb399f50716ec9de4df9c0
MD5 ee669f9c3da3064f55297c713dd5c0a5
BLAKE2b-256 21f527aa7e51094ae706ff2dd5ad931970e2049c623cfa15d668eef8901e63ee

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.7-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.7-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7c7fd05534a69fc264c601ae73796d06b074fe265ed06c84e64e818754660e52
MD5 83bc3409a2fe52e72ef2dd73bfafadd3
BLAKE2b-256 6ebf12939e53b6549cf8c81e756111318109fb478933c2ba9c3352f347c2f033

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