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.1.tar.gz (91.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.2.1-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.1-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.1-cp310-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.1-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.1-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.1-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.1-cp310-abi3-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.1.tar.gz
Algorithm Hash digest
SHA256 28e2653d00a20506d1817b094d9960f0031fee9b9787aed6257d2a1e24ac5b9e
MD5 72b56bbabccb9c3fbc50bf5e980a14fd
BLAKE2b-256 1c22813d279b04782d5a42c64f85c06ccc6a32df647463a87189fc9f95960191

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c3521f0b60bdbd43d19477d9590f4da1cabf9db777cde056050fd92f6b1ed82
MD5 4b0e58c5a9647c2389bfe15c98e1e199
BLAKE2b-256 6b508659dc6e9d3b46ee5694df77554d493ae1f7439c064fa9bf062a739de10a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 97d00465f15e5f28256b4f62d23c48b42c30bd6b80f0286606f6404092e1664c
MD5 9fd2219b6474fb26dd85e6eaed9d25d7
BLAKE2b-256 f4a92f943d06d1d956c14f1215c92f409682d4d681c247613d7567547675ef48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ff11503760d702ce3dd61acd858d4556ad012bcc15218efd791e1fd311abb47b
MD5 d820f97bb7cab2b349cdb1c79c4bb5e2
BLAKE2b-256 56a3ce1b6dce95eee1f89ef5f0562c68c62d351838dc65047da55fbbd08e558f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 de3c5e3583e46c03fd7041d72ba8aa5cb1122c9b3115268defb3416f39e85b78
MD5 a121ff67a319a31e17a9071cf7106286
BLAKE2b-256 bfe5eeb07c6cd876282f7a744b8f57e1b88d51332128b76b156b51ff4a1eed5d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 38b13b266e12caefcc353b8a7731dcdeec4f75f2a365f29cea0d534efbb5e902
MD5 b484635a56d849848459dcf1bbc76298
BLAKE2b-256 eeacf7b6193d580591873c0eba205dfd49deb82c94be587c404276104cf7f27d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 180117b6fa8fcfdac244aca28b599ead66ccd5cec5bb8e9638f89625eb2bed62
MD5 cb00fa336264bc4daa384c7d5265dff4
BLAKE2b-256 d9d63f230f82e0e2c8c4c949fb58c3a19cfa8fe37824e40a95ac94db52cfcd28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5e08423b10c29e56e0cdd810801322dd21dcf8e20cf61398c861dd1b44cb4dbf
MD5 b2d0db14574a940df13e45f0fdb171e9
BLAKE2b-256 f68725ed980eb684d831426d31b579964cb6da2334d10887b7069c6754f0eaa7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e923aa4d0db9063924c9417e9cb05275b42160254dfd2aab441e696aeff89674
MD5 19ee3789b57e51f56a4e039bb9f1e680
BLAKE2b-256 a4b94da73e41d6bf75faadf21c94f783e137492dbe57ecc65ed84965e9271551

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 90873d0cbc9b58b77f803393cbfbd905969e955b30887f000728f544ae525e5a
MD5 afd795846b7e45cc67a6e44215d64059
BLAKE2b-256 99084130ecd4fc487d9899026da503d776b79d78375f8a12fc758f547ab9821b

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