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).
  • Viewer.play(frames, 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 Scene, Viewer, parse_sdf, Molecules
    
mol_data  = parse_sdf(open("molecule.sdf", "r", encoding="utf-8").read())

mol = Molecules(mol_data).centered()

scene = Scene()
scene.add_shape(mol, "mol")

viewer = Viewer.render(scene, width=600, height=400)

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, parse_sdf, Molecules

frames = []

for i in range(1, 10):
    with open(f"frames/frame_{i}.sdf", "r") as f:
        sdf = f.read()
        mol = Molecules(parse_sdf(sdf)).centered()

    scene = Scene()
    scene.add_shape(mol, "mol")
    frames.append(scene)

Viewer.play(frames, interval=0.033, loops=-1, width=800, height=500, smooth=True) # 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.0.dev2.tar.gz (92.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.0.dev2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

cosmol_viewer-0.2.0.dev2-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (6.5 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

cosmol_viewer-0.2.0.dev2-cp310-abi3-win_amd64.whl (4.8 MB view details)

Uploaded CPython 3.10+Windows x86-64

cosmol_viewer-0.2.0.dev2-cp310-abi3-win32.whl (4.8 MB view details)

Uploaded CPython 3.10+Windows x86

cosmol_viewer-0.2.0.dev2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

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

cosmol_viewer-0.2.0.dev2-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (6.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

cosmol_viewer-0.2.0.dev2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

cosmol_viewer-0.2.0.dev2-cp310-abi3-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.0.dev2-cp310-abi3-macosx_10_12_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file cosmol_viewer-0.2.0.dev2.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.0.dev2.tar.gz
Algorithm Hash digest
SHA256 26113c17641b604db05ef1e2c08df3f9d4872cf9881ecc2c37fd9f89c7717302
MD5 c5a81cabcd0fd53a9964a3757148845a
BLAKE2b-256 48e441a10809d3ac5eb4e58d9e584d863a55b5c8b7ea90791bbc2cea8545c2eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03c37c96265c479c9f59b4b22f02d023c12fbf0816eac5743e2ec7c262089a86
MD5 640eff4c20fb07733295a4db410a9062
BLAKE2b-256 f6a34f3c6ac96f51d07c276c4b888c7652a7f640b1f1d18c0a9cc5f59f6ecc7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b481ac76af1eeb87ecccc4cd544758e324364a6e35ab1e647baee810ba2e6f39
MD5 df2baeb09e57934a48a818d6cd787b30
BLAKE2b-256 93f5d568678a04976b678fb70e6facb94d3c7a6a81840d2522ba550f84464340

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev2-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e7b73a2646ce66a849959bf20a75b3823679be728da0356e3e772a4a2e9e2afc
MD5 cdbbdac4a779f1d984ce00c3ac7303d6
BLAKE2b-256 3270fa01b50f6003f2b1494b64e698d751e04a0b1bcf5424d18fad812c215ca9

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev2-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 1ec2ef779fc57912e73299b3eaa25a1c9b5c54991f9a7b44d5e1cece65ddfc13
MD5 b9071c428fab711f7331c4574550bbbd
BLAKE2b-256 3fcc4a79b25b0fc785177587b75cf9c717310aaffff9cc8e1c91e953353eceaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96190e4bcaa754082cb320e1e2e98e0dd478a96ef97cc6cfe9ec7f915878493b
MD5 9f50f41f2263aa19b9b1d701c17bda0f
BLAKE2b-256 289a339a3565401aa4b4b18a8fc7eb2e59d819c4e9d22765254c5ff07de1213b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 16de5c903d5ab6369c26635332de8bf193bf411df06de1a8dbcaae1411229687
MD5 d6e07b430c78fa66023d1fe5a269389c
BLAKE2b-256 913e12d9041bbbdc5b8a834c66a5df19a6ac8cf88e8d44396a07973a416463e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0da0b9ada39447957606e65a6f99e5a570b1d5fe1e3815a9286fe5bd64f0809b
MD5 644f458048b103d4241aec8a77e322b4
BLAKE2b-256 eb6cd43ef11a3ca09c2149edabdecab2ac807b1f3332754add5125d739b19211

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce80c6da831c71f8dd4e4be6c087f2afc97261875dc7baad1512c876f4aadad3
MD5 0a53f37b796594f6dbacde172849fb8f
BLAKE2b-256 4ad6483cb3d85c1b5414c5f1af3cc7273b7a465ec7f8775a6a604b877f741d74

See more details on using hashes here.

File details

Details for the file cosmol_viewer-0.2.0.dev2-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cosmol_viewer-0.2.0.dev2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b4149bbdee5038fa67c64eb216d6fb61bca9679fbbbd535f4471034193a50628
MD5 634e02ef46ce704b80b6b4e6d1ee480f
BLAKE2b-256 5d3058591e87f39a12f7e85852ae96794682c479e8b8a5d33800f8f5db2003a4

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