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.13.tar.gz (131.8 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.13-cp310-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

cosmol_viewer-0.2.13-cp310-abi3-win32.whl (4.5 MB view details)

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.13-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.5 MB view details)

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

cosmol_viewer-0.2.13-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (5.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

cosmol_viewer-0.2.13-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.2.13-cp310-abi3-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.13-cp310-abi3-macosx_10_12_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.13.tar.gz
Algorithm Hash digest
SHA256 6f2c61ce53e8cbb642628f80336e277af78d4590af916e4efa1c7048cda53ee1
MD5 020cce84fa86d1a04bebc5514406b4bd
BLAKE2b-256 5887085ab208b5d52e79c80b8d3d989d7322538254c20b80713c5d1508b120bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.13-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 caa7a946baa5782baf940672de19b8231de0ee003a7c99f6233edf6d883ce688
MD5 8f3c0f8c1d6775ada737f0d7a8a9570b
BLAKE2b-256 eda7700c7d5aa859d847f4291285249d38e9f213bf1af642a9ab201e35e02b1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.13-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 e406429126c4905dc9457dd2cc73c40a39277e821b8206ef6f6c5c90dbeb8ded
MD5 dfca80a1383640bc45fdeec4da8eb3f7
BLAKE2b-256 9ea527f3e72aa929ae8cdacc386a8bc1216330af061ab3c0326fa512d89b39ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.13-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d0f15cdfd8518fa60cbe1fb45f7f434c3b124b57336cc86071c75d6256eae92
MD5 71f37756f119f9aedb5cacf9282ddb80
BLAKE2b-256 b44672556732967238a411140f03dbfb34c006ab150da9c2c964c1494f17ceb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.13-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e26c8f3e49c7fdd9f91558bbdb5251eeb2618e731784490c2aab83b065df06cc
MD5 99480d76e86a31b6ab1160e63cf1cfb7
BLAKE2b-256 eb5d43dcb1cdda5ec7eac19e62144bb70ecf1f02e3b264f59fc263b1ea21b81d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.13-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3f24cfc08deb9d4514c3573dc3a0ad9498cd349f8440e2de6f2ca2bea3a2462a
MD5 b2cea47b568d45e4c38abec57c356c51
BLAKE2b-256 656c29cbb9121b8ef8f52267c6c64f304c5681a21f9fdb6746b4c85928fe65eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.13-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 61d786962651ef868c00499e8f822d92b48d1e2770566f4390a2a647efa31fb8
MD5 f6e533c8f6cf61ee6d3d3fef53d7c904
BLAKE2b-256 74b8715c190cead6c633b95927b6178fcf1e95e88dd8d340d61f7c5b7192ad37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.13-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 84dcf30a75a6b17540a6505ab6635722fa3620921677bce872637ed9e08b8959
MD5 f56fdb18ff17415490c2b186eaeb9418
BLAKE2b-256 4c225d082e3cb7dc62d6bcb0fb6f51255f30c98839a7056ba740bb6b004f81d2

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