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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.11-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.11.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.11.tar.gz
Algorithm Hash digest
SHA256 2988d1cc5a3a4fd7bb213bda97a8281ce86ed774b937c6284bbbe583ceea8e4f
MD5 372b0f4372840871055c77ae289ea594
BLAKE2b-256 b86cba41007baac0c39c2734a13d10c1d520feac3881dca92a6127d51f2f97c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 570ac8bb8d3a48570f9c139c11ee427e8973c8553d0f7c88d5cc84cf2da4fb4e
MD5 bb264905ca46f30c9ab92f0760cb8581
BLAKE2b-256 13a2fb06235a6b817a18e063bda74a4c4fc8cdaad3499223856f1fbfc4f9dbb7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6d5ebb827a9b80931cb4bd71988c600b8d3056c434576a39d8f90ec18d04f2d6
MD5 26a5ff029e6db557f596f86196948fdc
BLAKE2b-256 d01a7739306af72d3051bb028ecb4b00093bc00a5baac8abc7bfbb1be5ccaac2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c0f2b3c7c04a57f139d740bc8958e749af0252a5ed938de33bcca98ec7b739cd
MD5 f9d722fa780b936517c2c313f171043f
BLAKE2b-256 4cacbedd07c1e00b969eb6ebae64b7fa87496fb8fd1926823136d2b804377cae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 7ba989436bcb50a65471bbe6a8bd371841e7fb800ba26d42c38b2550f7e549f6
MD5 dcd2436e27c1b79eef16d798f264edfd
BLAKE2b-256 4c0e993fff5cf3d56d8a2c459cad2575b1422a68842bc8b1a6b6a42a8be0e920

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5586d9ed13e39077d2da10ba30acd64c2706038be189485501075eb39726e068
MD5 8fc9d9102c8ec1b8f11e9cb873a731bd
BLAKE2b-256 c7786a8a4e8e714f280960fe41f30f8de47e0383d5eba23b0a00d76347ee6a63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 bd6e79304ee95537ddd58481ac8c4c5b49522870c7f29ae2205449f6f6cee177
MD5 01b0337e6f002de1fd76e9d64c619546
BLAKE2b-256 3b70fefab62e52c1949635adf84818d5a8017800351dead365dd4dcebb06ffba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7a28e8f1c108309565563ccbf774db48349fcc36f1770381985cbab25db7968f
MD5 40341823c530060e0bc2147b0e9935dc
BLAKE2b-256 bd240a9acdf0b413b58014696ee5bac93b77152a0b2d16f106ae0dd365b0e0b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18b395fb817e0edd393ef847c50878146f544dc4dc141059bff3abfaccbda896
MD5 9654a1ff0e9d55a1ffaa5d5d05faf7c9
BLAKE2b-256 e72777c218d277a81d686c57e1e6d7cd25d18f230bc6ad594f35a435cc9f63dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.11-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a728edc9762f67ac771019777dc846e25363d3d0c03bb574fb135047e69202cb
MD5 0d12753267d945ff514425f07d8ced3b
BLAKE2b-256 08a99b406291725ba30bb5f57cb1974f6caed12122d9d9a31df72697ec624f73

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