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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.0.dev5-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.0.dev5.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.0.dev5.tar.gz
Algorithm Hash digest
SHA256 3ec7a75c9fe8bcfdaaca445290f431717791c33a697f772adad4209a22dba356
MD5 1b78ae0154a7d6ded8e4f24cd8f21883
BLAKE2b-256 339e73f09d1bb990be3570e382c03978149589883a59ab12832c48f7440b18e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9053c63a78d9a71ababa031ef7dd26050e57c63343723a202a57317c77e06c8
MD5 1325a21e84582f8de941d24cb061e78e
BLAKE2b-256 c4e09d51a36a4f01732cece3fba4ee278ef230807e09ff8e5cd310e054707bef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b1045fa8f9be554c8ac39535c6fd8e5d7f314181a1e42ae617df1fdd4c737462
MD5 4733a31eda2adc00a9847d1d363c32b2
BLAKE2b-256 96230892bc8b9d8fe472387addba0f815ab90536ac04183cb9f10f6e7d54f802

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 74d52732b5914c06e6b84ed8d01d5cb81a479b1dacdbc6a7fa5cac6a229e6552
MD5 1103b31fda29cba6a373542461ac054d
BLAKE2b-256 c2d15d4714566c4dac98a94efd87cc0f933d17574482260e8a5085cfaabc62a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 2fe709af83289a9b183d5815ba8105c0bd138cb6b7d51d6b8723b84589247e16
MD5 7dc803fc9af51eae721c3287e56763a6
BLAKE2b-256 34355f603281fce3e464c74773eae907e99e90c1594c339269c8c7dd2ef002d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a6cff898acd19095ace8238284c66c39d4a1717f23ab1846592ea5b47e70af45
MD5 21ed56d599fb2e0620500a7f03292afb
BLAKE2b-256 77436182340c8ee3e587d6d93cd3ced34d48e29b9c327c54ec3c01180e3f0079

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 339aba8e3e4cba101d7413a6a20d844b05d3a7687db69420e05a942dbf527358
MD5 12ea8b6cc743b6d4f15047843a9d6e95
BLAKE2b-256 e2f608bd5a2ed391275920e8d9f5690d40c79ed5e1bbc0bab28cdbeec9279590

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 43d2f9deaf75888f0159dd28844503698a58bb8d51a0661143e8315b9a17d308
MD5 174dd4201743670195ac419b631dc8a6
BLAKE2b-256 436a88a1c18d779e43d5b1d614d893f569befe527851a01d253e5b75b7a84b3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 80f23dc3b51474191580966124d4ffb6296580d31db535b648b974e20059c5b8
MD5 1ead40968d204c72245e8dd85721f5b0
BLAKE2b-256 c1a51bef383b6c23a5532e66e08391828f6114c781eba6ed763549ac07fe92c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev5-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 431b45612de55abf87d22519a4f9164278e415a16707d8ddcf6099175cd9d705
MD5 520a2c7272901886fc87509054f69d79
BLAKE2b-256 156c9451d9baccdae2578972946f6917382d663ebd6663942535f705878b33fe

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