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.4.dev1.tar.gz (64.9 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.dev1-cp37-abi3-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.7+Windows x86-64

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.1.4.dev1.tar.gz
Algorithm Hash digest
SHA256 4ffbb15ec92a2103cf82f847540e764473be34a67a69af556f313ab30a5e1601
MD5 4c606f39ccdc3cfd6f970159a0bd3f32
BLAKE2b-256 1d292392b34cd111bfabd8bdbf44e27eef6f2951474a798db82fa3111bf60290

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1391f7ac35b9753b90c16d7db4cf420f00fc05e92c3bbbcdaf7a8962a761e237
MD5 776e658e99c89adee79ecd59e41dc2d8
BLAKE2b-256 85c2a9f6d1448dbd3a96b552826abe0ddcf430ef65315ebcbf67d97bcf9d5b17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b6f5d7094070ea134f6ea2bc016615cc776ff34bf54c853e7144c7dc4b5dd4d0
MD5 8e8fd3d6328278cedc896e086aa68617
BLAKE2b-256 45474df893ef8321ddd23c6fdca92721bca3ab46595a69f1d9faa2f313bc2553

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5310282899e64254d85fd501b64ac385500a764e862c01a4e37321d75916bde6
MD5 cfc475253cce3999763491fa38107245
BLAKE2b-256 129f36e1010d90b977b219d801da4879f4340ffba8e911881e4e0d8d1780efc8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 04733025aea6008f8d99453ff5ddcf29f7fb122ea45d39ebab0a9203da11f357
MD5 edd2a7976a5280ecb2bd31ac62db699e
BLAKE2b-256 b7dccc2c1b8626c5e5f8d44ae1608fa9d935f8539893bbd5de0122ed07f52f73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.4.dev1-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f9ba568e046741fc160297e2823706f54c3a320c111a45058a502b3b880961a1
MD5 b3e03da30306713c207bb5bf42d8c744
BLAKE2b-256 a20d6a367d467c1193d89cbde07d18d5667c2af9a77a4ceb9326cb56e61eadb1

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