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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.6.tar.gz
Algorithm Hash digest
SHA256 2f381a4a2c0e39f4ae28af03daca24915688312aed163ec15be5dbf59035eebf
MD5 987041257becc8331779c24e4bc91b76
BLAKE2b-256 3b27c7516068e8ae7cd8efa0c540df1c7411ddeba5d327ee6c353d97214afd06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9326e0a4987e336f0f4216496fc78ff571a94fa02c414f5a1022ba85961d3a55
MD5 e4dd8da5002698ebf57ff9f9d3b239bd
BLAKE2b-256 2af9070b6733077bd4dba2fde384d9c56292c2ef665ed0d650db5fd690668a07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 7a786a6d5d8c8784fa4160e2b2767131c593ecc5ec2c310e31ee7cb6c7e41bf4
MD5 5e7bfbf8cf6284e1678d13fb1dfae4ef
BLAKE2b-256 5b51bdf88fc251c6a758c0e672ec37c599fdf6c29cdb482b7cfeffb313ac2561

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e7ed96d4dd014aeeade5af7fbc409d1dddcac163706e617b5d2816c820535424
MD5 d7a652e6589ee1c3c110c4042a66bc4d
BLAKE2b-256 42515a122f357e23fe541b3df55400ec7a04a47ea0d56749440524c0720829d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 81cbbcda7d62a16475b593118c21dea999b2baf41e53d659529c7aa945c1fbc6
MD5 a44ea6097af3a331331d1b5a9f91eec6
BLAKE2b-256 83375fa1771827b7cd4e96163033a3bd3c0e2f3d093b0ad68fbd3ede3a308c82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 66ed7bf41aac26d571287af887b22d2a96d7123a16d93307dbff5bb03eff0d01
MD5 6e47bd5e044a2f220d21a9b829d16b35
BLAKE2b-256 585d74e1dd369d201ec9ae6c53f77d7253fedc2ca75ea76ae11ed99229f316b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b07fab0caaaf1b604a92bace5baae8c69c5f8090844dc5888af4538591fd0706
MD5 3e165519cb649ee1a56224a5c265e37e
BLAKE2b-256 8622d05fdcabb3b6ba9de4ba96bdb5c4c5664ac2b82b2b647dc454a25df518ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 456ca86f227a79b205c09f44f5359923144e1c449518b7af673d8691da29740f
MD5 481b0ce29d42eb9364c59a8170701b3c
BLAKE2b-256 7c18f9ab042cf0ae54b30df3c35b591dcf03ca1e9256d198d5f8f6177e98a865

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2814c99e09540f0c96a5fd22d404bde0752a07e61e28dbbca533418ced7ac6cf
MD5 765e52287289447ad435b35aee432c06
BLAKE2b-256 5561ac41ba67a7f85ff611ec03b729dc589b16063e73d2c9fd71422fbac09084

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.6-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8d718b656ae9541ac19232f589195c53a8e1e0f95a6241f744babafd109affb6
MD5 713b45f6c09866cd961106ddbab8aa5f
BLAKE2b-256 bb6e2a70a4b3cddc49066aa2eb4576baac8516d5fefc60cfcc55b44f7ad290e3

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