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.10.tar.gz (94.6 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.10-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.10-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.10-cp310-abi3-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.10-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.10-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.10-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.10-cp310-abi3-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.10-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.10.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.10.tar.gz
Algorithm Hash digest
SHA256 f6faa40b8a6271f7ea3c5a60c6787ed10f674e2ea78f35dfe06a962c44ae8cee
MD5 9f80c2bb3c1980fb7934e946e45c3e9b
BLAKE2b-256 cf341998cf19f9a310a456a76bb9a7d2b6286cd87cbb1b70253db0440d96ff81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34d39e1f89d37142eae2b728b1bc5f25bf811fbbeef5cd68e5283369c79f3da4
MD5 93dd6c272d149c80d08e32859dddfdee
BLAKE2b-256 d4fd22ba4a381296a7524761056b36411d9e3ed8edec77ffe798f4b1c5bb512e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 897b45ebae28a81e58ac01739c604e8cd01b40bfe0a04257c7ffee6fe654526b
MD5 ce0a119cd9f97953aae44351f4dead2f
BLAKE2b-256 a9c2ee6e3445c332b4be243856ef0352adeb620079534566a0c46c697dde6574

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 adea1b1022c0fcdbf0a798604aa6699d679f7319795c991546fd09ec6a6200f2
MD5 106cf0aa5b6cc8b06f1afc7d801a41da
BLAKE2b-256 e8431aeb4f3a9ba693f9201d14ed266c335d3ad8f8e7ea2ec4783e0c38bb8e4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 56f056ccf5d2419dd930d9d97eba3177516637b29e931625b5c87579e9a8434c
MD5 0fc1f46cc6a1d308f127fbd9534761f1
BLAKE2b-256 9b8824b1470ed6c79a8680953c851f2ae9a918e069651eac1b74db64492d3476

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 917dc7d7a041138afe9acdcb10181cb7af7ddc1036e2b2ffbe50c233de80e92d
MD5 dddc0ba92db52eccd14351bb1d70998e
BLAKE2b-256 14e6b7a27ff99a197e0adf80bc56ff7dc501aaa63190e27a31ba3a04ddf25bce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 80746bbf375ab8df39dbfe9ec1b81331fe5f3e32911184f48f491aad09a7c823
MD5 8b6b6339df499a4e1c55ee66659a46e4
BLAKE2b-256 a4e1be2f5404db2f1022830ca7b7275a9cf653b0b0c8a4572edfa6f11482f117

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a08544262ca817418b1aa881833a2418f78d9cd6e796f275103f63ab73b35379
MD5 c4e35df4d0d015ce9b06c7436347ec16
BLAKE2b-256 9d48fd4fb4437e08b91bab82de350c18b4b2e2c2f88e669d7dd847373f4cbd49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 38b3b13f19ac9de23a1b19db89c0264eb1dfa3399c90acf8b6441cb75d096aa2
MD5 716292b43358e9abc90d03c45a5d51a0
BLAKE2b-256 fd044c86df27b221f1a957d34ea89d1b14a4de3e8d3c28f803fee70449fc5d09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.10-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8f8730c7fc75506cec7d2c42e50ac6900c5ab58eec6652fe95e11fe0e4d3eaf5
MD5 21694c9cb1e6c1c96adc4f2a87a1a12a
BLAKE2b-256 e15e426d543a4250f01e1f03295a50b99e950924d65f57999b2e4b617d815547

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