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

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.3.tar.gz (63.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.1.3-cp37-abi3-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.7+Windows x86-64

cosmol_viewer-0.1.3-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.3-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.3-cp37-abi3-macosx_11_0_arm64.whl (6.4 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4c39cc7f1eee2e6fcb45f44e198a6bbbd18c75bb167f3bc25fcef896d17568c9
MD5 a4e0738751aa744e664350bccf930e69
BLAKE2b-256 6fb88931e651d11226ae9aabeecd55f7133a640e510c89b35a00fc827f771bc5

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.3-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.3-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 50e6e6d331d382fc21f7dce93be6c7c302eb4ad21221d3a7ad3dc8db2683efe2
MD5 b90f207bf99e19907ad17934962fcf79
BLAKE2b-256 b120ea201bcc67309cd303d36c0ccd269e23f2db9bcfba8dde96eb574d23cead

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 acdb8ec16d49601e955b83c6c9aba6ce04843b2295d13d4643d9a147a10ad1b1
MD5 f99e17279631ca9ff2eea4860fa39c96
BLAKE2b-256 ac5ef602adcccf1ddd751131f30ae0e2cca26c31f883726e539e565b0531e86c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8bc97d27225759be9eb57057e72b64c2035219045f8655675fd2548d68f3e202
MD5 618192f58c4055b74bbdeaef6c6b5656
BLAKE2b-256 b385226f59645143fdfa48b79a9be545521c89a4f7f0accd770671dbc281ac88

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.3-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.3-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a38f3850ecbe441efcdd2fe3b5c0f21a48bc89eed1f92447d695a9d32e09f18b
MD5 446f75a19549d3f4497ea89ea6646c0a
BLAKE2b-256 a330696861a2829acf20e6f23bacb5ed0c7850d742981a092375168de7d6f027

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.3-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.3-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 178c6db069216c4a765746918fbbeba834296bb1b9a3cbf8bf4bd42800a40e19
MD5 205c27670fdcbd539b55c1e455a73a10
BLAKE2b-256 f43025cdcafbfcb11c6a05ee94eede890ed34286851cfac5811fbaaff853ba6e

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