Python documentationView source β†—

Quick StartΒΆ

Render an SDF molecule to a reproducible PNG:

from cosmol_viewer import Molecule, Scene

sdf = open("molecule.sdf", encoding="utf-8").read()
molecule = Molecule.from_sdf(sdf).centered().enable_outline(width=0.04)

scene = Scene()
scene.add_shape_with_id("molecule", molecule)
scene.set_camera_view(
    azimuth=35,
    elevation=20,
    distance=32,
    fov=18,
)
scene.save_image("molecule.png", width=1200, height=900)

In a Jupyter or Colab notebook, display the same offscreen result inline:

scene.display(width=1200, height=900)

For an interactive view, let Viewer select the native desktop or notebook WebAssembly backend:

from cosmol_viewer import Viewer

viewer = Viewer.render(scene, width=800, height=500)

Shape methods such as centered(), stick(), color(), and opacity() update the Python shape and return it, allowing method chaining. Scene methods mutate the scene in place.