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 in a native window or notebook canvas. 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.
  • Animation(interval, loops, interpolate): stores precomputed frames and playback settings.
  • Viewer.play(animation, width, height): 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 interpolate mode 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")  # Native desktop backend.

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, interpolate=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.14.tar.gz (101.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.14-cp310-abi3-win_amd64.whl (6.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

cosmol_viewer-0.2.14-cp310-abi3-win32.whl (6.0 MB view details)

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.14-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.3 MB view details)

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

cosmol_viewer-0.2.14-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (7.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

cosmol_viewer-0.2.14-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.2.14-cp310-abi3-macosx_11_0_arm64.whl (5.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.14-cp310-abi3-macosx_10_12_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.14.tar.gz
Algorithm Hash digest
SHA256 47bf65892cb4a729b665418f962a1f8df34ba9909fb1a3a339a121685478a9e4
MD5 d0b1896eeda4a5521e716626620316e4
BLAKE2b-256 8c2df8b0f0251be44d680a37c6e4f189c0552fb5fa6ff5be0583ea86520ac5b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.14-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4ae90c1a4565ac0c0d1835be5da669da01b35bde11a97a230daa8657ecfe5b41
MD5 4bbff0ed387431fb90f721923c2bdb99
BLAKE2b-256 6613af04aafe59ca1b4ba6396aaf4308e204a0b5d40cf1135659742bc840a6fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.14-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 45bc1ae6d9ebb94e0da82af9783dbb0db6a01631fee9b16876ddfae8eacc490a
MD5 eb86e79187bfe9d479f6745277d98fac
BLAKE2b-256 50877a544167ed20f3748cf14adf65919cd9ab3e6e010839f13bc4d287bc8d74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.14-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e5dfe9ed0406b1d76e415bb07603cab9eee306baa6e12379c5aefb1ab40177e
MD5 146fce968d7cf77e2db79f6ae6b80ab5
BLAKE2b-256 60829dc0dbb649c3d1f9ffbee15d8a2c2ff288022b016e4ac64ea5b2a2b03ec0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.14-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 903362701e3d81211359834d8cad9d3fc76e75afd05b2a55fd379d559848845c
MD5 c53a5c852c8fd44b71e8a8f6e2d00919
BLAKE2b-256 b96109224142abe2709248c3954f2027099df0b6b3cafb6e3a7f293a51a2a3e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.14-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 eab0a05245b5bb77395a6a446224adf12d8f1c0fe028147d53c77f272cbaf81e
MD5 487ac58284f8110c62f7f10bb30c9134
BLAKE2b-256 c7f8d456157d356061e306280fadbfb96c1a91c1fc76244461cb2045abed5720

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.14-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1472aa113e741a7de618d24bdfeb0342546a20e87e00eb5c99dc6bd544c86141
MD5 728ec9df51f86b0fdb8881d33b31e1ea
BLAKE2b-256 916ee20e6b3143d6c5b587443233ec816620217568d64058a565faf9a115b90a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.14-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cfdf0b95878ed753dfbd968d547a01b2e0a54344a221e30272d4e7b51ca11547
MD5 37de877f257324a9018f4f2f0ec68ec2
BLAKE2b-256 856f47bfc1367aedc051981a02e08c864e0b76ebaf6e3465462fe193860e1b54

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