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).
  • Animation: An Animation object containing frames and settings.
  • Viewer.play(animation, 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 Molecule, Scene, Viewer

mol_data = open("molecule.sdf", "r", encoding="utf-8").read()

mol = Molecule.from_sdf(mol_data).centered()

scene = Scene()

scene.set_scale(1.0)

scene.add_shape_with_id("molecule", mol)

viewer = Viewer.render(scene, width=800, height=500)

viewer.save_image("screenshot.png")

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, Molecule, Animation

anim = Animation(interval=0.05, loops=-1, smooth=False)
for i in range(1, 10):
    with open(f"frames/frame_{i}.sdf", "r") as f:
        mol = Molecule.from_sdf(f.read())

    scene = Scene()
    scene.add_shape(mol)
    anim.add_frame(scene)

Viewer.play(anim, width=800, height=500) # 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.2.12.tar.gz (127.4 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.2.12-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

cosmol_viewer-0.2.12-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (5.6 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

cosmol_viewer-0.2.12-cp310-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

cosmol_viewer-0.2.12-cp310-abi3-win32.whl (4.5 MB view details)

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.4 MB view details)

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

cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (5.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.2.12-cp310-abi3-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.12-cp310-abi3-macosx_10_12_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.12.tar.gz
Algorithm Hash digest
SHA256 8413330103563fa117185d9a2d22873dce09e9d03f2c5588f762b80a533b0917
MD5 9f4dc3bc07c35696d73f7d223d2c109a
BLAKE2b-256 c3840d93d3839e07e4bba2b09d95a683102e0028272f1d81f6e70213ca38fcbe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 495bdeea5252b912e45294551ae2b52f7ada4c3f936cb0f02ce997d1f1c477f3
MD5 4082a6892b52c3178bb4931c2e2cd0e4
BLAKE2b-256 e74550590fbd88f672be0ed050b0951488f0e7c821fc58c633a2ec1e876e6fa6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 841286bf7355245c5791e4c2e83745574ba77bc7c904a362095227073a0dba5c
MD5 b4d30635301b81333210ea4f04b08d57
BLAKE2b-256 a74bdf0dd43e3d7ea529ef3df00c0501ccfa754e4690b6d5bb779f05c694ae83

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.12-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 407658d29ca71792522b715f212f624dd4f1039bc5c6bfa4e8c351015f330dcb
MD5 a2aa2a35af9a4744847c8bfd8269b0a6
BLAKE2b-256 3d049a87f883d0f088eecad724d5fdcb4651ab9653321d126c38f1d5c82477f3

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.12-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 1178522babb1a70b50f76158f1f02e2977dce4ffa40a5fb6eaa91fc6b1cffe56
MD5 457ebc81686ac7eb050790c944d788b0
BLAKE2b-256 91892f1e8629e3d371e7f9798b763546fea9ea407add8d7f728b2f67c41e4998

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4c77758d2e05318bf0d46469fa715f768b109aeec303f8a4bce491b656866398
MD5 c06e0f6400e1656fd8cf74aae86841c7
BLAKE2b-256 38121a184888a4b716d79d50103604f248926befbf174ffacc9c9116d026f7a3

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 133c8bda658b326e492f1ba22dfade9df6679e6bcf80277ff98c988e026c2ca4
MD5 9a487273644ec625f0b73b5248320cb6
BLAKE2b-256 6defe5ff840b8e30bb4d6c850fcf0f1e62f7f47a2fec1a1e0e49f0f22b43dbc1

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9cdf24cf93b471213f3f1e3a2948d55be57503b40ca53c67949a3e36a971b329
MD5 174577ea9e24c5b11516754ce33406d1
BLAKE2b-256 ec8cad9f560e55e8cecb17c7def1fecb68529a8b5c72e8f19185d9d9f8a7859a

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.12-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee7df39f4ac6de10413c49ea51c0d4e6fb05e74051bec1b53b281644cd5bd100
MD5 a57da30cfa63ef4ab08ccdd59907979b
BLAKE2b-256 217e0673b6382fb7284cc344b663c206d3be80d4b77663631a225156370bf81d

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.12-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.12-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 93d9580ee61b468922be4fe6168a4442282aa9b44b01d9b8f5601aeb6a809ffe
MD5 81d9dc7b6c9fce31d8b667f1fc437dbd
BLAKE2b-256 e5d61b6cc4020b51b33fd80463ae3da2ef27bcc1517fd053e52b31ffe37252f9

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