Skip to main content

Molecular visualization tools

Project description

COSMol-viewer

A high-performance molecular viewer for Python and Rust, backed by Rust. Supports both static rendering and smooth animation playback — including inside Jupyter notebooks.

A compact, high-performance renderer for molecular and scientific shapes with two usage patterns:

  • Static rendering + update — push individual scene updates from your application or simulation.
  • Play (recommended for demonstrations & smooth playback) — precompute frames and hand the sequence to the viewer to play back with optional interpolation (smooth).

Quick concepts

  • Scene: container for shapes (molecules, spheres, lines, 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 (real-time / streaming use-cases).
  • Viewer.play(frames, 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.

Installation

pip install cosmol-viewer

Quick Start

See examples in Google Colab.

1. Static molecular rendering

from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules

with open("molecule.sdf", "r") as f:
    sdf = f.read()
    mol = Molecules(parse_sdf(sdf)).centered()

scene = Scene()
scene.scale(0.1)
scene.add_shape(mol, "mol")

viewer = Viewer.render(scene, width=600, height=400)

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, parse_sdf, Molecules
import time

interval = 0.033   # ~30 FPS

frames = []

for i in range(1, 10):
    with open(f"frames/frame_{i}.sdf", "r") as f:
        sdf = f.read()
        mol = Molecules(parse_sdf(sdf)).centered()

    scene = Scene()
    scene.scale(0.1)
    scene.add_shape(mol, "mol")

    frames.append(scene)

Viewer.play(frames, interval=interval, loops=1, width=600, height=400, smooth=True)

Documentation

For API reference and advanced usage, please see the latest documentation.

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.1.4.dev3.tar.gz (65.4 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.1.4.dev3-cp37-abi3-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.7+Windows x86-64

cosmol_viewer-0.1.4.dev3-cp37-abi3-win32.whl (6.3 MB view details)

Uploaded CPython 3.7+Windows x86

cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.7 MB view details)

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

cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (10.1 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ i686

cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.1.4.dev3-cp37-abi3-macosx_11_0_arm64.whl (6.4 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

cosmol_viewer-0.1.4.dev3-cp37-abi3-macosx_10_12_x86_64.whl (6.6 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file cosmol_viewer-0.1.4.dev3.tar.gz.

File metadata

  • Download URL: cosmol_viewer-0.1.4.dev3.tar.gz
  • Upload date:
  • Size: 65.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.6

File hashes

Hashes for cosmol_viewer-0.1.4.dev3.tar.gz
Algorithm Hash digest
SHA256 6e34354aadab0e7eee41799613332003c8fa06161ab6cd025d7706e75351eab9
MD5 b4b11c33bb97f884a252af0e7ae1e406
BLAKE2b-256 0d27e04f193d45f776905bc033ac3a44eec17e57f8cafff1f345698ba023b2c5

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.4.dev3-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev3-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 77612b1988a0bbb934dae4e5935129b118ca8a50dd8e0ae7e86ebd38a78f6b57
MD5 0e04bd543a1d8c08e55416b1c309c630
BLAKE2b-256 6c3e7a23c7f0f2c784101c345f3fb5a1d6c0376f4755525c4a78054b549d024d

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.4.dev3-cp37-abi3-win32.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev3-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 8a9ff0b7704e89f6081c0a95730fccfff5cd3f401868546ca02442ef254f75af
MD5 07f37d7665d57c7651177840ca54118d
BLAKE2b-256 2636f2e5df6690b9fac03cfd07ee2c0c98caca557900246ca509f52409cf24b2

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e325dc90333670113de0c88aac54427f8ddf38cef3256f8e010cc4f62d208525
MD5 68a9d41036fdb9412d16bc7e1670c4ad
BLAKE2b-256 54f0dd1df2091fb54d7dfd1c8d6afdf4807e25a5d11947d4137c33cef6505dbb

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 152300b7f68d968af04ca0e5bcb46d61e62cf5ce83a28862e629cfeffd286d05
MD5 be171d73d8e94d5010874e7be5c52230
BLAKE2b-256 310e2c1f4d9248359a9c02f6e44b42cae116293e083aa2253a1285a5ceaa19fe

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e8fad804a1241c57da90c40d46d28fe7fc9ea197a9b079ee56863846c23a94ba
MD5 95aa8f563d88c8d8343486470dceb2de
BLAKE2b-256 f869186b0c3ccb975edafe9d6f5301ec022fe407f1e36015ab2bb0664e9a48e1

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.4.dev3-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev3-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b3bc3dff1b9a15a8bc549b29fce36240bec724b451ca1dc2c0c55bd49eeae94d
MD5 4f3c981ea9bdd2365bdb46c88b18e7ad
BLAKE2b-256 f3853508f94dafead87a5b474911a2a6c5aa5271db210fbac8aca39251cd6f91

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.4.dev3-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev3-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 95ad69964cc41f496d00950cf244fc0f9ca1bad6fb930712818572f4869dc2ee
MD5 ba5b69de5464ee7fd29177cd9585c0f7
BLAKE2b-256 f7a3a650d32cc67d27efbb31f268f5d2761564902b87fb884f2c30844f9bbac0

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