Canvas configures the active Blender scene for Molecular Nodes renders (engine, resolution, transparency, color management), exposes convenient properties for common render settings, and provides helpers to point the camera at objects/views and render stills or animations.
Scene template to load. If a string is provided it can be either the name of an installed Blender app template (e.g. "Molecular Nodes"), or a path to a .blend file. A template given here is always loaded, replacing whatever is in the scene. Left out, the “Molecular Nodes” preset is loaded only when the scene holds no molecules, so that re-running mn.Canvas() - as a notebook cell does - binds to the scene instead of wiping the work in it. None binds without loading anything. Use load_preset to reload a preset deliberately.
molecularnodes.scene.engines.EEVEE : Render engine configuration for EEVEE. molecularnodes.scene.engines.Cycles : Render engine configuration for Cycles. molecularnodes.scene.camera.Camera : Camera controller used by Canvas.
Output format, either "MP4" or "GIF" (case-insensitive). When not specified, inferred from the suffix of path, defaulting to MP4. GIF output requires the pillow package.
The rendered animation (a Video for MP4, an Image for GIF), which displays automatically as the result of a notebook cell. None if IPython is not installed.
clear
Canvas.clear()
Empty the scene, keeping the setup that renders it.
Removes the molecules and any other content objects, and purges the data they leave behind. The camera and lights are kept, as are the render settings, world shader and compositor - all of which are how the scene is lit and rendered rather than what is in it. The canvas is left configured and ready to render whatever is added next.
Notes
Data-blocks orphaned by the removed objects are purged recursively. A single molecule leaves over a hundred behind - its mesh, material and the node groups backing its styles - which would otherwise accumulate in the file on every load-and-clear cycle. This also collects unused data-blocks that were already in the file.
Objects that are not cameras or lights are removed, so set dressing such as the preset’s backdrop does not survive. Use load_preset to bring a whole preset scene back.
Only this canvas’s scene is emptied - objects living in other scenes of the same file are left alone.
Examples
Clearing between renders keeps the lighting and the render settings:
Load a preset scene, replacing everything in the current one.
A preset is a whole scene - its lighting setup, camera, world shader and render settings - so loading one replaces all of them. The shipped “Molecular Nodes” preset is a small studio: a backdrop, a camera, a key light and a rim light.
To empty the scene while keeping how it is rendered, use clear instead.
Position the camera to look at and contain a target.
The camera is moved as close to the target as keeping all of it in frame allows, without changing where it points, leaving a small margin so that the subject does not sit right against the edge of the frame.
What to look at: a Molecular Nodes entity, a Blender object, or any (N, 3) set of positions - a bounding box from get_view(), or the positions themselves. Views can be combined with + before passing. An entity or object is framed on the geometry it renders, so styling one chain of four frames that chain rather than the whole molecule.
Viewing direction along a principal axis — one of {“default”, “front”, “back”, “top”, “bottom”, “left”, “right”} — or a custom XYZ Euler rotation as three angles in degrees.
Fraction of the frame to leave empty around the target. 0 fits the target exactly to the frame, 0.1 leaves a ten percent border, and a negative value crops in past its edges.
0.05
Examples
import molecularnodes as mncanvas = mn.Canvas(engine="CYCLES", resolution=(400, 300))canvas.samples =8mol = mn.Molecule.fetch("8H1B").add_style("cartoon", selection="chainID A")# frames the styled chain, not the whole moleculecanvas.look_at(mol, viewpoint="front")display(canvas.snapshot())# room to breathe, and framing on a selection rather than the whole entitycanvas.look_at(mol.get_view("chainID A and resid 1-40"), margin=0.15)display(canvas.snapshot())
See Also
molecularnodes.scene.camera.Camera.frame_points : The underlying solve.
Where animation plays back the Blender timeline, a recording puts the loop in your hands: change anything about the scene between frames and call render() on the recorder to capture the scene as it stands as the next frame, then finalize() to assemble the frames into an MP4 or GIF.
Default file path for finalize() to write the animation to. When the recorder is used as a context manager, leaving the with block without an exception finalizes to this path automatically.
Directory to render the PNG frames into, created if it doesn’t exist. Frames written there are kept after the recorder is gone. When not given, frames go to a temporary directory that is removed with the recorder.
When False, a frame whose numbered file already exists in frames_dir is reused instead of re-rendered, so re-running the same loop resumes an interrupted recording, only rendering the frames that are missing. Requires frames_dir.
Scale of the rendered image with respect to the resolution.
100
Returns
Name
Type
Description
IPython.display.Image | None
The rendered image, which displays automatically as the result of a notebook cell. None if IPython is not installed or the format cannot be displayed in a notebook (e.g. "OPEN_EXR").