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.5.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.5-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.5-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.5-cp310-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.5-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.5.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.5.tar.gz
Algorithm Hash digest
SHA256 631bd175dc60d8f919aa9258085fdd7c141c3b6799f49f45459cf5ed7ca77b3c
MD5 1e9e14d44ec83b35d4c2a4cf5239cbbe
BLAKE2b-256 56a709be8ddf562a36acd1b2643d4b0f301337e279b47e59f9f8c383853d33ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 348bce59648aecdfe81791a437a033eb3ec83b0e83395c07bb726b55e8f1a876
MD5 1c3c5095e2e19df319cf230939d8d890
BLAKE2b-256 ffcfe5b9693c8cf75f527d422a000227acf5ecac4c3eb4dd573d707818c0efed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ef53f5d3855aafeadf1080be8ca41281dbdda6149ad9ca4bb4147bcc61d1b6b3
MD5 07ebc4eb6991dadd5653e5fd00e8e250
BLAKE2b-256 73170ed8627cf9cb1ff33e1a175a83a389193755f892f13c5d4faf74e834fce9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c92f55a6fedc95a178ada06c36cc4a443e7a8fd73a78c7176585f5709c1bab53
MD5 584ef1ab53a2b3e207cb021e2c25c0c3
BLAKE2b-256 68833f1b8705d18bfae3f05895f87c2461696a93988be52791eefcc5dfead668

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 f199c6adf3da6bbc55fdc608338e8f38ebf12f1a7754b251535ea5901c4a22be
MD5 ae426b9e067ad8d523754f809dce6187
BLAKE2b-256 80819c70c67b2c6e35f623a7db8fbc0e742bdbc53e24fcbadcb6895f02b5753d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e208b886db263fa542a6fc434a3827aba733289c5ea505341d658888baae2908
MD5 2c64093a2842bdd171e341b3104a21b0
BLAKE2b-256 a5eddae328aca5db6fc3a121493282b0a436bd6198186edf049b3ef33f7dd576

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 dd6e8fd309d647f61ae3210f90ae4c73a93a11bfe43599228bd7161d7939815a
MD5 dfbd9ba114e19f6456aaa2cfdf7fdc23
BLAKE2b-256 7deda7bfe17db7bfa550f6b65305035465984a0706cf9b1a86ca4510570611dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b7739bdac90cb4ad6ea31688228c19daee21090ae8ec35f13749091104e2c17d
MD5 93c5080c93fe1b1eb339d1479e3ac2d8
BLAKE2b-256 4b3de5bf1f2f7e323ac73998d44b59fc89fe00b18f575ac4ccccf9e2f29274dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca6adc609d0e22cab8b60749c67b29f9a7943a9e8eca0780d31ec2cb4e06ad42
MD5 3f952b7979989aa58ca57ebe1053a8ee
BLAKE2b-256 6d5ba7779e419836a50d44a9209ec68797f37c5f161c430e4a0f3e1b362aec1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.5-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 bd896656b80a3cd8206e34e050a89b15a75d40e68341d53f99620ed081f076ff
MD5 a467f180a021833b1b93f35b3f90cb53
BLAKE2b-256 afc858f34e7e39207cf16bed2637cc3cd0bb3696d85b074405454012e7c31f8a

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