| Crates.io | cosmol_viewer |
| lib.rs | cosmol_viewer |
| version | 0.2.0-nightly.2 |
| created_at | 2025-07-15 01:06:29.310492+00 |
| updated_at | 2026-01-15 10:06:10.90507+00 |
| description | Molecular visualization tools by rust |
| homepage | https://github.com/COSMol-repl/COSMol-viewer |
| repository | https://github.com/COSMol-repl/COSMol-viewer |
| max_upload_size | |
| id | 1752381 |
| size | 209,057 |
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:
eguiAll implementations share the same Rust rendering engine, ensuring consistent performance and visual output.
Viewer.render() (real-time / streaming use-cases).Why prefer play for demos?
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.See examples in Google Colab.
Install with pip install cosmol-viewer
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
Viewer.playfrom 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
Install with cargo add cosmol_viewer
see examples in examples folder:
cd cosmol_viewer
cargo run --example render_protein
Please check out our documentation at here.
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.