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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 50e53657bf5a9166891d15710e9a3f1d2c06a4c35ca031eed5b2a2460b475cd3
MD5 c6bb92aff8650892fe2478e3a0a7213a
BLAKE2b-256 5c6df47e5d37fe8cd85f58ee856db76f09d41eda4d3b813ca7b03c9e90e6b174

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ebea3072f8c7d46c1b4b521dcc29bcba33ec7eb02b144bf066427873937af95c
MD5 97ad7a074d86929a708e62985bb374f4
BLAKE2b-256 48050871284652a1283351b4a76ef573ccf1c5b1147009aa8e94a519297c0096

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e51f13abd907b605b1a5bef9c810a13f56948296cceba32ccb488b0bc4bf2e1f
MD5 04769a9f9ff19a47ad293a0c789d8670
BLAKE2b-256 2326d8c207c0dd3526ceef03b7826b3bccd3ee8b18e597a8e716df569779aea7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 66bc9903fc259b838d84ee660b681e4e9b2d7150d0a5240f57a8b9fe16630e5a
MD5 ac8493f757bfd60682cdcda9417e4f2f
BLAKE2b-256 9b3a3a0d945744b324842c6a5f91d12869dcdcd0f898ce10ab7e73297e6c0b97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 0e8695ae8c29c9279b1890385e6e363a4db2f63ac9dd529b0aa083c96c116a00
MD5 5861dbdbef2d2b4cde6ba5ca8a389bd8
BLAKE2b-256 e3abd2b780216fc275c3ef9e6a7225f369b36e30f80b43797dfe8c467c5c997a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e3eb1201df6c7b5bf58304a67f73b3b76363a533f4d07cf62a7a0f956ec739b5
MD5 f70a29e20411737200d3c30ce5233692
BLAKE2b-256 3d58b583da6383b56e7c2bf6a7eca86ec1a2ebd562c29861b54560bd6c5e7580

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fd03877c7cc7f6a72373a2516bd6900e3eaea4299911c3c983d21427108492ff
MD5 abc43e0b5ac7861e91d514ea0bf5b246
BLAKE2b-256 911f60223e83fb5fd6ada4e2fe6e7b6056281b2315b1f99f103d7efd7a6e80d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1670f7196aa88d71f22c711cec4d120c6a4aa70a720f7a86c65f9415e73d5870
MD5 fcbb7ebdd190493624f196a5d6cdaf68
BLAKE2b-256 a8d8c227f14715b0c8be0e004c38eea4f9570b58483e2e07f86cae6b747c73ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91366cce8054bd5a2eeeb0f33babe022237729b610fb340c7d596ec18f0ec91b
MD5 d4e6ee615a5ae4aa237c12dfc9c7832c
BLAKE2b-256 f3d6eabc70c5ee6c2479c7316fea3a0865fbf9795649d5663d59e16034a65c97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5a3fad4aadf892b8bec5312199e63fee7a55858c471576867bd4641a536789cc
MD5 6d4b22cc182a888bc84514c384d83d9e
BLAKE2b-256 768df3358d68bdabeedf83c657468e9b38eaf0005b8b89e4ff4fcea55169d1f1

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