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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.3-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.3.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.3.tar.gz
Algorithm Hash digest
SHA256 a174fbc3bf270b341617885b1bfb6ee1878b4813ea788ba18a09603e97d5bd7d
MD5 862c71cdfc17182c578cc75d2db94bbd
BLAKE2b-256 5c2e6ff3a27ae5b669e7442628e959b917c9bd406b52c3f4366dd8b2b6efc2bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 511f18ffbaabec8ba350dd5fa561bb0de6afb79f9c176aaceb654e50b9f387a6
MD5 f858175e5b23a0473a4b9830cb2159a4
BLAKE2b-256 a3ec097bacc64947c680a43556e27a96ac371572bf7775d5c503cec5683aeae0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 567ecbd3f219afb7924d23029a110802ed4e53d8cdd10992adb4cbf357f8f0be
MD5 7f8d853c490051c24024dff811e578ce
BLAKE2b-256 00b974de724b316974ebd8494e34dfeca37e138ef27c25fae8055ec1ae7b4385

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 958e48e47e83403b9acbd739a4a3a7561c158b320fee3e6b0ba1652a2b7e815f
MD5 dc46a4cf880154b0e2ad08cfcb0db44c
BLAKE2b-256 67266c2f2710955895c48d02194f21525eec0281972fd27783baddb7f040326b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 026ddabd99a472921e8be29d4a2f496beaf86a30c529b170a20be7a213136742
MD5 079063bb53f546f70ec5c09561419485
BLAKE2b-256 4f4633f9c38ccf28e474f98b5c6981b97cbe87fe678dfef250f815952ba4dfcf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7111bc2ab7cd77073d597b779c988d3ba5efa6925ea8b363d7cde5b3559695dc
MD5 76aa0bbe58f7aa073c05f7d21861ffa7
BLAKE2b-256 c637f762ee7bdf371a3f2a585c0bf4686fff0d59a0a1f3177b499e30f446ac52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 c0900d195fb2d9d999b296bce86f880d2a94091385e8001291543fb106cb151f
MD5 fdcaa850de9df6de1bbea2401cc76a36
BLAKE2b-256 83070a4293ed07638020156d7eb4a1d0c29a6e1c0002314ba972e745295ac316

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ac882e469e32ddb591dce7f0a81c4b6805a24f5db3c83f38181f82721f9349bb
MD5 449eb8ce3d9b130144362de529107d17
BLAKE2b-256 eb4da4c2890ffe7c6320366afc4e8e0a408a04ec798ee2585dbda3b93222eabd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 75ddbe6bf6378120651687e2d12e6c3c1a9aec2cbc92a6ddaf086c9a2a670df5
MD5 516342959b70eb4c0ea5d44881529d31
BLAKE2b-256 49b18db8e4f0054f4149ef2b18ac08be5f2471f2b8cca7093518a8333eae6fb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6231da313d9949b43d8a51b8e1b2859686983e02bcc9b4ad8b08d778866f3c3a
MD5 e7deeefd07b269e9f96c9990df7b266a
BLAKE2b-256 9b411e8167cae23a6ecd28876d0bad6d0db4e263668e4647864baa907d9de77c

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