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.4.tar.gz (95.1 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.4-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.4-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.4-cp310-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.4-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.4-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.4-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.4-cp310-abi3-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.4-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.4.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.4.tar.gz
Algorithm Hash digest
SHA256 9fe400cf39e392f532eef5b52906058e1d7f56735389a77170bc921b48003e1f
MD5 86581879a6ecc33ce766eb6ee8fbac22
BLAKE2b-256 16ec9415d5f093d97fe33c5855cb5d36c328953797f1d00ae7d9c336e3620d43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8f715f12581a96f95081c2556830afe9e618d8a9e03c04656ad94eed4545953
MD5 0c9df0642c912efa0810a6d17289729c
BLAKE2b-256 73f4dde9fa0ca3c6a432a73533044c21c770988e4e96474078082d1b217e7fab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e7b03402fc999d7fe8bad6916fc6dbd3187caa8b1f8807d1b3df6a71474b842e
MD5 51dc1c15ad4bcc4dc74d98f7a6e2727a
BLAKE2b-256 80fe0150e89b06955b0da7f6f48e93c7a0194d27bda1d2db59f6ee6ac7b164c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d24033c84cf3bc7520ca4a13a70dc8c5d49492650a2844f802322aaa91560cac
MD5 1f92b2181a322745ce5b559471511165
BLAKE2b-256 9965008082e35d3da470411c03e78b68fe5283d8b04ab47b26fcbb54a723753d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 61429a33cebe3b8e3b4eb9c2938ef3efff47a511fa70004baffd43d2a304cab6
MD5 69461611a9ac7bee9f144837c88b4527
BLAKE2b-256 cdcb9323f71706bc5ae406c19f91b2ad204ff099bee13568e5549d22b8959227

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 89c7ec0c092c59792509ba354c9d457a9549aa55b59cf477d561f80caecb9fb8
MD5 5eabc0644df5eb393b72892783637c09
BLAKE2b-256 d9c4691fa2ab35d1d5774d708cea16f43521e73fc72c041356ebcea228791a79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 df4cefeb95532f401f86559581cfc7e194f982e0e17ec5105ee8895486d9237f
MD5 fe6d65a380d1cd338b0a0a33167f1318
BLAKE2b-256 96b8fecc4994a97e49227c1ef0516950c1cdcafaa130e9b1808c99c2dfd91af5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7f1c74c58209268460066992f8a5ffabdaeb608995b2769f4ef44359b58ba13d
MD5 c6fbe14f11d37fbdf4fcb26df9c930be
BLAKE2b-256 1b579b89dd8b8f69f58330d60d45eb84ded7cb44abe9e03885954aa6a273193c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0313cdae6a61fcecfd45ffc68164c0a58cb373e91f15e819fa1130d617d75959
MD5 c175562832941d3fd80790fff5467ac0
BLAKE2b-256 e8ea5c137323e6921f7e95e7d01343a510a4dc6cb2f3ce000f63f8c4b90e112b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.4-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d0510c8dace8c97150f2eae1c873564edcfc9794aead25db2110aa91aa75bb82
MD5 3490c266d8b44993e4958509398f2fa2
BLAKE2b-256 a048f7a8da4240432d8f6622f67b6ad086c7671fb9fcfe2649306b8581f1aa06

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