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(sdf.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.0.dev3.tar.gz (87.0 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.0.dev3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

cosmol_viewer-0.2.0.dev3-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (4.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

cosmol_viewer-0.2.0.dev3-cp310-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

cosmol_viewer-0.2.0.dev3-cp310-abi3-win32.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.0.dev3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

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

cosmol_viewer-0.2.0.dev3-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (4.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

cosmol_viewer-0.2.0.dev3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.2.0.dev3-cp310-abi3-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.0.dev3-cp310-abi3-macosx_10_12_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.0.dev3.tar.gz
Algorithm Hash digest
SHA256 c46961f4afa199480aef2f564ec307fd2707a33bdddcfa3bccc4e82ecaa0973e
MD5 ef3e4401fa1f1ef377a0a087a646d3ae
BLAKE2b-256 d595f0fd9d1399bd7a6fd3dbefcac5030c8975f5be0cb63161d03465f0a79975

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4da1bd006cd69ded1feb1e7c92bbdfce0cceb6205ee86dcac6406916df02fe98
MD5 df4cb6dc993f7e6154f81f21f2b47aef
BLAKE2b-256 41652a9c7a375cb82c712f91226868a2bbbaf4047e3a5531b888e8402f94ccc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b94edd4649cc837201f9a2da99f1c4f111e1ad553307cc48c981e947949400b0
MD5 97401e06bd0da7ec2f6db9ba5a87d58c
BLAKE2b-256 050cf0e9aa10c192db3ac5c402ec3f0614fcd0cffcb6db4769fe5caa90784daa

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev3-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9fe26484f20b8c307c1d8498b89a5b5da08c61faf1efdbeef45f12da33ef5349
MD5 55bd9fc35ff56f83785d096523869958
BLAKE2b-256 cf3d432140a47fff631abc9047af5d552716fffc8b7535d5fe254259df57f4a3

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev3-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 ddf858ded187f18e0aa8d0975d585f73444c8726bf812d710ed878a53951c9d2
MD5 67ec187180ab660a48101d64ca0ca4cc
BLAKE2b-256 c2b06212270db900d4dcd7efcc22ca4a41f15e7b169ba8e7d152dc455918ac34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55c64c11d34b1b6b0e3194c71b6316864a754c29c7dc357915a38abe028b375e
MD5 ed39e436c1c7875ce34db7531f5058c4
BLAKE2b-256 204b0f9bec5e9c610e490c33bb072b278d033503a77e927ccdb5ffe5ed1705e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f9ffaa04a928560bba286f638f1eab26c30a5079d2503e6afaca31ec6aea8a40
MD5 e198ce7037b19afed08862f0b0f5c89a
BLAKE2b-256 d57d28943ac2db6aca1b8168c615137e13f6ed98c64b1a2b181e7a2f411bc0dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 89d5255518b9f9b099e070235014b76a37c078c69e656a16c888a64425cad841
MD5 7b47dfe47c9c6b8a2f98db34ad48be3c
BLAKE2b-256 7c1449bbf1f6f0640f91991cefaf2f0d0f8a4d16b7fde59303ce7d7f619d6284

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b75722749de8d3f41b6c67830f51a416f5b235cac300bfd8c290cde72c2a10a
MD5 26ce9818fe1b7fa595a0ee564e44323f
BLAKE2b-256 47836527b1ba89fd39a295b358ec59047ee839a4d15fb320714af25fb6a11c40

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4047b491321941dcac393a9ea445e47cdfed49f5f04f76ac99a84cdd7cd92fb6
MD5 8684a74eb94a3ebe423efde218a0c930
BLAKE2b-256 701c3e9b975304d57af585a304f6d5375abc196528269f07355a859c2273b565

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