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.9.tar.gz (96.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.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

cosmol_viewer-0.2.9-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (4.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

cosmol_viewer-0.2.9-cp310-abi3-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.10+Windows x86-64

cosmol_viewer-0.2.9-cp310-abi3-win32.whl (3.3 MB view details)

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.9-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

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

cosmol_viewer-0.2.9-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (4.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

cosmol_viewer-0.2.9-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.2.9-cp310-abi3-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.9-cp310-abi3-macosx_10_12_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.9.tar.gz
Algorithm Hash digest
SHA256 816d3ac54d5dcb1140902626693da1998897dcd156c5d4fdf4242fdb254bba68
MD5 83142a3f58afca036a0d15ce6dad6094
BLAKE2b-256 8b0b0406787b7c6fd4819eb8d5ba35b5f245a28caabccc82f42cf6dc919ee5d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76bc36ce46a7c58008cf802fff310cb45c08903d9d0d54b482c42ee72a8d469c
MD5 43225bb67c893b7a6f01424b016086f7
BLAKE2b-256 4dd4188313bbff6cb6a303b505e7ad963bbfb3b52fa27d85961978934494e86f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e5ed4e97f1734f5d9f34ba8fce0e7cb68bfac7619f36ba7e04dbea7bfbb12f1c
MD5 890dc2ea8a0ac070b96d96d943a1468a
BLAKE2b-256 0471e117a7efc563a79ab2a5263c12d704c8d6e7db96aab0eae742593a9e6e3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 16f7c9daf8479b98517b151baa699d7ade8a1841b088160385c17f30da0be0e1
MD5 809444a46736db1b4d457dcdf88def44
BLAKE2b-256 74896cacc9ad64c10ac96aaf5d5eb42b91bf26d2799ffbda475ce31a5ce3c538

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 9b8e0aca2264f21a2b193a16bf740fcf51ea34f1072316cb997774750ba43959
MD5 b96f39402de08c783ca3dc64b98d33cd
BLAKE2b-256 0c83843a975fd94212710f1cf70ecd1123fb41b5083aa88addacdad0f39bc94b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60fd200ecadd50da0cd3969406a25d866d06d567a2aa5c8e5c67d602451b3d66
MD5 b45a4f34ffe89fb4665ea0356b40ed16
BLAKE2b-256 3353a2989d80b1761486e17d04f3b6509cd0f24fe5dbf0d5ab2fac5978d97cb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 9104601c9c2ec0235db8d4b8af8d13c770d36073a812ba7eee6dd882fe74544f
MD5 5a9b90a3c6ae1150b7f98f15c02a52e0
BLAKE2b-256 c40475f73487226712cc878d4867dbfd026a794721985167af84fc5b6286c3c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e2adb171d457dcef194ceaf9078be65df2cf67ab48927bbc45ca9ec94a6a44b8
MD5 4fc76b4fec72f7167e463d98c852103c
BLAKE2b-256 9c4f24ee75b4fe874bd9d13788ecac962508e8f9fbcae0545d5225534ffad55e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8e806f1cad4f680ee1151486bffc447cc51bd6e6411f833e2e2ebe8c03ebc667
MD5 54fef13951147fe8f5ebe3d5d38fa7cd
BLAKE2b-256 9b7e10e64f169d5545b9cda72ec987580ff3c66bb033182be9463d8f5c048295

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.9-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cdb1918e55a0b48df3873bcc6ab3292edf38815696119e18c544cf087248c5e0
MD5 a80d29dd854a1edfe1f0d4be3fa6eb48
BLAKE2b-256 df15bb2f777282368faea245be9ade22c50dcc17cf60eca5f8972db5d400962c

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