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.5.dev3.tar.gz (70.5 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.5.dev3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

cosmol_viewer-0.1.5.dev3-cp37-abi3-win_arm64.whl (6.6 MB view details)

Uploaded CPython 3.7+Windows ARM64

cosmol_viewer-0.1.5.dev3-cp37-abi3-win_amd64.whl (6.8 MB view details)

Uploaded CPython 3.7+Windows x86-64

cosmol_viewer-0.1.5.dev3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.2 MB view details)

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

cosmol_viewer-0.1.5.dev3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.1 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.1.5.dev3-cp37-abi3-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

cosmol_viewer-0.1.5.dev3-cp37-abi3-macosx_10_12_x86_64.whl (6.9 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.1.5.dev3.tar.gz
Algorithm Hash digest
SHA256 3cb56f7f3bb6f380409b42ffb048e87c5132a75675e7a4cb3642aba07b263b3a
MD5 c0d8b9855edb8b41a39eeb778e766417
BLAKE2b-256 908bac5b718f3bc0c8aa12c35b52c431916ae7f64071386269667478573f674b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.5.dev3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ddd239d8b3a1a921756008cb9db53b263aa0259cd04586b78da0cf2474fde482
MD5 8f2ac56e8767d856a665f0e31b9e7bae
BLAKE2b-256 e6b1140fc86e19cce281155769ae3172c6f48df03eb37fdfd2bb4de754ccd27a

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.5.dev3-cp37-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.5.dev3-cp37-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 b8a150a758e06dad61f2b3965b4e3cae5ce53102d821147fa3a194c2fbad9f30
MD5 d34a85ff8b2d0b6ad0f4036d9971c311
BLAKE2b-256 51a1cccff17c6440e763e093a65319f1c331e179d2e1a94beb9121a16a4f41bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.5.dev3-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6cb49d51f0249debc906682d6bf4e2a838d09c75da0d907a78cfdb10b25894c6
MD5 b79180f1ddbdddab87e58d3668fe80f9
BLAKE2b-256 c7f09e8932cd9f931b27b734edeaaa5c4a1d9439b4787ba3bb386035e982ba79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.5.dev3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea57083866345abf7b18ed8f27c0d311279856e4006f3745cae4668401692729
MD5 06b2de3dabb445a42a2e8ded4b7e6881
BLAKE2b-256 5cafccccbed4f54f0b0a22a121b82e6950686762d7a07d0a18546d441952bd2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.5.dev3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4ed923677f8a7a6ee5c1fc990e5e99dd72c286b3b5d2f83a3b43d42d3a287e0b
MD5 ddecef38262bd25ae3f90e73da7539ec
BLAKE2b-256 e048b92ce09165646b8ae36f29d267716f972b7441e1d90117bdcb32a9d2b28e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.5.dev3-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 462c1584d0ce62626b645c489e5989b95aeaefbf49c8d915fc7ac8cd368ec1fc
MD5 3d5570211dc77b1cda825b9d9aa25732
BLAKE2b-256 3e5b5e5c02e5f4a562b83c334328e6102132d2019481b9bf8abb2dfa94f47c91

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.5.dev3-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 44002a35abe18e2ab45cbf7094bd8da56f60dafc1b182aa3d892fb8a23255061
MD5 8c003e015a29b6893b0807f030324d67
BLAKE2b-256 0a2986b4a321f1491e9fa3762548e889a1554a26c8b44176a0d86661f55b519c

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