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.2.tar.gz (91.9 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.2-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.2-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.2-cp310-abi3-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7ef11834219046be5639ee43a30361d5e4a85c5792bdbea40a746bd28d4f6e35
MD5 632ccf7102912af9369f83d160c2f916
BLAKE2b-256 aa4c040ef915bb4fcaac681a24aad17dae6c222abe6fa48d2ed1515942d589e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de66f406da864f26cabe6a7b9926503e9ca15c8639815874a18605250dcc5276
MD5 de5b52f52bd2a0824ae9202879fe991f
BLAKE2b-256 7017b2b67c041bf42df19ee19e6192f7ace7de1a8e15d2134cd1acd22a951c6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 02b3b2f3a923ffa806788267d520f386ec6de4ff8f6f6a18b79055033545239e
MD5 f660194b45f33a6e6b95e6c42b52b573
BLAKE2b-256 cc30c793882a2b1d5875c36aa51cd3ea7b89dba7b7897e6955ba65a21f12002c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 742a2bebeb5b1234d1f8762cc19a91be43396aa45c3b25d4c9fb4a085f475aaa
MD5 5d37e6a006d3394420ebe102e095393d
BLAKE2b-256 06135c2dfdd4afca999c5a65d0e2b97d4dc8b239232c73c69aa57d1afe05523a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 dbe9305ed2f9bb64f82bd8a1cba04b3126299eae1831fd0b450d1b76c30ed1b7
MD5 6f4f948bde654fbc4c2fa6537c897a80
BLAKE2b-256 1aa5b8b52edef42845c9ba4a050e90da32d46a5df724ca68f1ec751696f7ee1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd37eb5519075d2069f7b4b5d3573491b8db12deb24fbf9153014cc1825f6e5b
MD5 27a72587de24fcf21f1b6d37ff0e82a3
BLAKE2b-256 c11809d15a98fb0d99aad103826b4aa98896927c442a6de0cd64b073ff0cbde3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b4f851871441c71622f78093cfbb6ea75f5e3dda85f642e522a784a2fd4b99ab
MD5 121e3a87ab83af383d73d5fed50c8315
BLAKE2b-256 cc6bd5ee1116276eff2bcc74a09e330d6377022b54de11b8afa0e919c1f4a3d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4092116bf6247fbd7a381985586fa2b61029fcf911202367ecd68e94127f12c9
MD5 25abb51f8b279f4e6a6f7aa99f5847a2
BLAKE2b-256 d274d99b3493e265ba2d9fbee9c5ee5581ca87724ebdbdf357c181dd16541a04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d391bdda5ce47bca47d58fec28d9cf6858fa9af08be3f17885003e50b7899db1
MD5 f363ae983bd0f024cdfc3400f9b77c03
BLAKE2b-256 d8ebfa98c9833cb11f7abec016568c7cc2d19b9c11b6bb47ae77d0873e4d8dea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d832230c59aff9b747e2c62c50ff651f303fe409b357f18066af4ac3de90b3b3
MD5 795f55b0eb1d9095c98e92a5c7119e4e
BLAKE2b-256 a8433bf5b29b06e7771a934417b6f49dcaa1047b151230db9e42b5d3523e29ca

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