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
smoothinterpolation between frames for visually pleasing playback even when input frame rate is low.
Why keep update?
updateis 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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cosmol_viewer-0.2.0.dev4.tar.gz.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4.tar.gz
- Upload date:
- Size: 87.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1ddb74501eb8cb6515c5096e99fc7641c234df1c0c81084177f06b6d7b5a002
|
|
| MD5 |
41765fb3e34e768d384ab8cd8a630384
|
|
| BLAKE2b-256 |
efd5f3a09a7ffc9a470187fb3bdd369ab04c16990dcbd443f3495e93c7e3b4aa
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.0 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea3db4b95027022a5a995120a7ad5cb61aa3da2d0fb872addcf902b6092959ab
|
|
| MD5 |
4dc594fa51d95b4463998e32e55cf2c5
|
|
| BLAKE2b-256 |
fcc710a01765e3d37000b029ad0af195e75272b556b0dd0d052e62c27ccc6238
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 4.2 MB
- Tags: PyPy, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
804be4d14536ffbd9d21c2b64274f40a0ea57a6bfe4cc0f02f4c46e4fdee79b7
|
|
| MD5 |
36ae3b7fb0a135da4c5ead7b8734f979
|
|
| BLAKE2b-256 |
5ba5ecc2e4751cefc2893b4cabb9a13f318503e35abceef8872e62f1f32060a0
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4647648ba8c5a8245caed97ae468d87733426d7a069aecd1b10df9d363fe74cb
|
|
| MD5 |
86faaee6cadf4327b91e14a4ec24ddb6
|
|
| BLAKE2b-256 |
e58f8641a1eeb6246ca0d3cb31a889cada80ffb7786007371827fc8f25209f7d
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-cp310-abi3-win32.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-cp310-abi3-win32.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.10+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dff9c71f91dd9fb0c6f62d77c28d0fc146cc5b25cc23a2a2520932e3387262c
|
|
| MD5 |
14f386686f24fa6ccb5f7fe86e446304
|
|
| BLAKE2b-256 |
74ccac44ccf8f608a4a2bea427da3e0c2dd8a4a8674c24fd62ac64299364735c
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42f5bcd5d4aad938c45594507c41ac36986d8df29d674abb5782e09bab9c03f8
|
|
| MD5 |
ca9cd4c9f3d2a85a2979321f305023bf
|
|
| BLAKE2b-256 |
ece1db7cff083dcb34640f07fcc7f6f9112ed1b1fa7ee80343c934a0a4490460
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 4.2 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90c44c05f50eff43a734f0ea55b1d88e91243536a641e87897049e50ecb35473
|
|
| MD5 |
bc742238fe9a6e807d84c68d15601ca3
|
|
| BLAKE2b-256 |
442b5017204b3cf745bb44984314b157dadadcd7a714b9d3898c8c5d974496a7
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04be24d6cddfd8409e67fdcf481e974d68d6055b3c983220a52f88d1314b164b
|
|
| MD5 |
2e90fc7e0fed1c7dc6f4f3bb15025de2
|
|
| BLAKE2b-256 |
c52fa64a217ca380fba5eb6cac73a7c4b21e7715f28e26912ca4749cb4d4bf9c
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60b461803db9a268385060bd6e55c3c729a2e87cbc6b78ab7b7db3e1154e41ba
|
|
| MD5 |
c58da5892e78c7ba472d9a79a970c566
|
|
| BLAKE2b-256 |
afc20c980fd00b1e70721d9bb8010ecadbe0c6ca7854f16c803407b5e8365e87
|
File details
Details for the file cosmol_viewer-0.2.0.dev4-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: cosmol_viewer-0.2.0.dev4-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bad1c2ac2d0dfecace07e74c45d79f52ad1cf578fe4df61f288ebb589f39028
|
|
| MD5 |
996b5d37c3aaf6732eb0ca097746e162
|
|
| BLAKE2b-256 |
ef6deccefcd6b41e7f1c044f209ba2ed19591a35fef1dd1db86c5bb9fc71ca78
|