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).
  • 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.

Usage

python

See examples in Google Colab.

Install with pip install cosmol-viewer

1. Static molecular rendering

from cosmol_viewer import Scene, Viewer, parse_sdf, Molecules
    
mol_data  = parse_sdf(open("molecule.sdf", "r", encoding="utf-8").read())

mol = Molecules(mol_data).centered()

scene = Scene()
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

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.add_shape(mol, "mol")
    frames.append(scene)

Viewer.play(frames, interval=0.033, loops=-1, width=800, height=500, smooth=True) # 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.1.6.tar.gz (90.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.6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

cosmol_viewer-0.1.6-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (6.5 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

cosmol_viewer-0.1.6-cp37-abi3-win_amd64.whl (4.8 MB view details)

Uploaded CPython 3.7+Windows x86-64

cosmol_viewer-0.1.6-cp37-abi3-win32.whl (4.8 MB view details)

Uploaded CPython 3.7+Windows x86

cosmol_viewer-0.1.6-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

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

cosmol_viewer-0.1.6-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (6.5 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ i686

cosmol_viewer-0.1.6-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.3 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.1.6-cp37-abi3-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

cosmol_viewer-0.1.6-cp37-abi3-macosx_10_12_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file cosmol_viewer-0.1.6.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.1.6.tar.gz
Algorithm Hash digest
SHA256 2153ba8551ee8f0cd48c7d05941c87c8f4feae265fba040e1e4ccea7eda73b27
MD5 9b86a5931fdb56d535592644cd56957f
BLAKE2b-256 269fd9299383e46f85f98ce92e4b20539f73a8c453389d742834ab9f8e6dd1c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 919659d760422fc359d8a02c93657a5fa55f5ede1179323277b1efbb42d6c386
MD5 c059af357e981d056e73f02ab3a3c99a
BLAKE2b-256 765227b00be68f40ffa36d148f25bf991bef54ba3048f1e5fb4a0284cb02f7ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 7ca81257827d0a0b066010f11fb1f2059407041deca50b97ca2367863e822a39
MD5 ea64b998a65e0d6f413ec6808c8a19be
BLAKE2b-256 911db67b3bd3f916fd2290900f41f9538036867d356c9780678bfb56a3f8a2bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 13210f4f55d286bd0241fd83b251feaf8710ee99050c3798bc4d9384250fd9b1
MD5 f5d78b88b7bb8dfe1588d85abc402ad4
BLAKE2b-256 79beb792c1b9b010adca1d94d9772bb3e10b0abc048e22ed57c8ec45ca54b811

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.1.6-cp37-abi3-win32.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 ab74fff68c7bcf1cfc547cee51e42b8235dc43d4366c80b35b306922ef9e7874
MD5 b7fa647a0ceac87dcd25d94a97dab600
BLAKE2b-256 e46c2e191912ba6bb6ec79170be56f6c4065bcd28d4527d1d2134d8e3f549e00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c46b27c712fc97072f58f8e92422160a345b66ad9c36e72ba3b436980895762
MD5 0b5ff3a5cc9b91a2fb6d13e12ba615d9
BLAKE2b-256 193f7f023ab7b12ea5f2555ff2b3108290b4ebece4d433690945bfbeac295fd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 d1e15b602ccfee11aa958f4e2dfc7f12294adbcd2b2fe70447fced204783ceca
MD5 6d63c0ed325cdb0ada54c1e1a5f53a10
BLAKE2b-256 f3e81d5a47c708477dc3844743edd8672af401401e5dcb54f0f172572fdbe727

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 496fe4bd5b760b7a05b4cd73f096b6ab3fb0e5816658ca27490500ebe797c3b4
MD5 1a9a3e4c54a925ba46c84ab0bb7df481
BLAKE2b-256 e86470af45f533a8e42537eef727cf22b981173c8713bbb5f25a33d7597de38a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48303e65c9c37de6e04f71ee92a87596a429f0e78f0360c9dcade5984bc72421
MD5 3f13a5152a18e0a62a202fbf4e0fa3f9
BLAKE2b-256 0e822c7cdaeda78e8b0afc89a5df4ca25500dbecd6941fd7f5334ea689e3f8df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.6-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ed782a70976155a5612198594acb8425b615ee4a22c3d33922b2e0e277f8a990
MD5 0d71dceb43c338683819b4c4033fe85e
BLAKE2b-256 5d9c8e76b10544b51c92e3beb64dec15b626e9cb092734af490d8f0178ff8b7b

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