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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

cosmol_viewer-0.2.8-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.8.tar.gz.

File metadata

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

File hashes

Hashes for cosmol_viewer-0.2.8.tar.gz
Algorithm Hash digest
SHA256 ab978fe14fbbf2d2fe70479d725df16d9ab63dd6bdd0abf45b10513fa1fe5419
MD5 471c8febd7fe806b70e451dec9c72790
BLAKE2b-256 7503f34df9d767f0f6113a33269b1b3fdf5b9f0c80d49f0fcc41398cb6964660

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 73c4af7048f94e18773a95aabee69532fe74081589043e99ae9a896749a37ea1
MD5 9c7101a03388848129fba13b4e12cd98
BLAKE2b-256 ea48f4fbd5334c8fd8e7ee6ff79c7469b8ba6da261e0ad4b2b1b6fe8498c9b68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2ea1738bd59c1cd2f040e395040293bbe2c5677787e53f73a4ef399d2cdfa8fd
MD5 63a178115d837c44ba7832a0b85ed6d7
BLAKE2b-256 e7c8f4ebda9028f50d5310a12bacd5069ea53bc26eef99a826705b5e9bd64114

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 863704b04c15e5f985843898630e94b62a268dd8630e838383ff48fa72ea142b
MD5 52a1d8743d0673f25248d4dc1b54811b
BLAKE2b-256 6d1ed60d1f7337f2add32e705f4e9dffe67bf93cdc1e86bc034f526e9c575649

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 84423bcc56be87800c0fb91794e647204e7b7563a864b9762a81daa5c3d88ade
MD5 6fd3254251f5fb73d3b0b0a8952a7a69
BLAKE2b-256 23a3ddc825124a4f98a59e2c29eaf1eca913ea7ecb53968bd2c5e90d3f29f87b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bd101fe333f6bc9c0be54ed681743ad19e71d15bcf8f936a8db71fffc4ddbe09
MD5 81b351ff6ded761f6d350370167ccbc1
BLAKE2b-256 93a167687f57001496f5a86bfaef533f93aabe9d1a9b3165b89542faac1de735

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f32fd435b44aeda92e83edaa0bc0e92bd47b6bc7915f9873d771e325ba39251d
MD5 5f6bbe28ff731b85fafea41dca44e68d
BLAKE2b-256 8e17614de3d0599d11859c16066d754c9c22302cbd4bc9fa2a49eead5ca9547e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bebe9608a0b9b333ce54da0306f926cb6c907b4d5f5b2c868ab9ef1b6e916350
MD5 18f205f506385efb3b7e9aeb1c23462f
BLAKE2b-256 e0f39b30e05586911ad72ebcf5b3655d35ab4dbbe896e64b0e722aa4bf2a4716

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 926e36fa80e4675da6c0eb27cba3130b1ac0df708c4ab1fc3a44520f91a31a6c
MD5 f96c332ef9522d8b67b3dcda260e8794
BLAKE2b-256 b7dda44bd6bdda1a5f6db34b6818e104db00cb939122e0a79598fd81e821b886

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cosmol_viewer-0.2.8-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dabe79159b2ddf6f9392da528b2ed5dfbdf746b9137ca1814d9ffba9fd2bf5a0
MD5 5eb2f062755c4482c43e0270a90a31cc
BLAKE2b-256 e1d3c7ac5a56e770cc218c3ca5c077e45ffa30f5985bc0f95d61ca7ce34d0b3e

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