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.7.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.7-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.7-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.7-cp37-abi3-win_amd64.whl (4.8 MB view details)

Uploaded CPython 3.7+Windows x86-64

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

Uploaded CPython 3.7+Windows x86

cosmol_viewer-0.1.7-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.7-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.7-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.7-cp37-abi3-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

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

File metadata

  • Download URL: cosmol_viewer-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 d5a1e3e65a20e230ce46e8ecb21fdd3788c634faf715e2e91457b5151ef33d0a
MD5 086eb4529ca8552426d0f562cee87f89
BLAKE2b-256 e2bb1aec65a287f82d2fbcc9bff88d09760be080a55b401b350779982f83a36b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 77429e5c04bd1ac7c8d2c49356f3f2f606cdc257de0b4e1e87ed2fe832a10474
MD5 7bfd4e834548f4d31ee999e96ff1041f
BLAKE2b-256 c3310417b785f6b99e630b0562583a1d0dc94435e17bc839e626d668b5518a04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 5cd17346c9a37a2da7d97a18eece89f3e8034b3c0fbe4a172065f9205f0dd9ab
MD5 7f184f499b428d249199612ceb8da313
BLAKE2b-256 46ba3bbb7e3708bb9857c7f74a94073a4324031a70ce2cb1fbf3b02f42f6cf14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 45e56400e0c71a6fdf30a891785781c03f8f5cd103c9eb6a6d4cc7013d665748
MD5 27f17748e961e1765eecf0ec509163c7
BLAKE2b-256 8b297b753e535a785949d6f7065fce87d9b839d7c00c7332e50d39dfbc719f24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 a11ca08a14aea0f8d99e62eb93260f64ec63f50a2fc6896a2e092ac185821fd5
MD5 110b3f494e44e94a8602a192a2cbcfb6
BLAKE2b-256 fdf3905b6be678de5237585767140fb3737bfee41d47c8f5fa84e8c187a99ce0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 28414ef4242854685fbe6c213e7ebc06b07af0ce6a66a9d1fa78ed57e9db8fdf
MD5 4ff160a66be3011e8433e297b4ba4fb8
BLAKE2b-256 bfa96b376c2dd5a25152c9199dd13caa3329a017756908fc2042ca2ac569f3d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2cb29673af81f03e678519fa6b7ff1f3c00c6cf64e5969ecf7f37628e4d77765
MD5 7d79cfa58ff1bc0234c1b01ab07b1094
BLAKE2b-256 cb7acbc6307b335dc674434b971cf978e791d1d140780515b9ceefd5ebdadede

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 22345d53b8b5c22cde553488f2512cb0e7a860c61c4f10fa5c4c6451113ac085
MD5 8854941bc19b40f52ac3796fa6a87b1b
BLAKE2b-256 2fdb77906862238bbfcb5605ef3f67a839d6859289e5f3ee77d403bb4554c5c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c727df506bfa97342ba5f8662ac019d868e636f0ef9807188d7c0c83b018897a
MD5 5324fabf72ac5074b2e7a785af38d05f
BLAKE2b-256 2d36c6f5c1a021505e0b04b5d469408cafeb0d3f39ace5aa20a3f7bf6669d58e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.1.7-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 796a5c48fa83396c443cfc0fdf2bf7cc95e07e7e25abf44dabafa88aaebee31f
MD5 c119b3b590cd6d22b86335cd43ef184e
BLAKE2b-256 f7e5d03fc7c418a97c00b58eb480da2cea613fe2460d8110b3e6275c0a1d2d3f

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