boltz_data.draw.mol3d

boltz_data.draw.mol3d#

Code for generating SVGs of 3D molecules.

Functions

ball_and_stick(bzmol)

Generate ball-and-stick representation primitives for a molecule.

draw_3d_svg(*primitives[, padding, depth])

Render 3D primitives to an SVG string with depth-based shading.

grid(*groups[, padding])

Arrange multiple groups of primitives in a grid layout.

boltz_data.draw.mol3d.ball_and_stick(bzmol)[source]#

Generate ball-and-stick representation primitives for a molecule.

Creates spheres for atoms and line segments for bonds, colored using CPK coloring. Only includes resolved atoms and bonds between resolved atoms.

Parameters:

bzmol (BZMol) – The molecule to visualize.

Return type:

list[Text | DrawnSphere | DrawnLineSegment]

Returns:

List of primitives (spheres, line segments, text) representing the molecule.

boltz_data.draw.mol3d.draw_3d_svg(*primitives, padding=2, depth=True)[source]#

Render 3D primitives to an SVG string with depth-based shading.

Projects 3D primitives onto 2D using orthographic projection (dropping Z coordinate). Applies depth-based darkening to create a pseudo-3D effect. Sorts primitives by depth for correct occlusion.

Parameters:
  • *primitives (Text | DrawnSphere | DrawnLineSegment) – Variable number of primitives to render.

  • padding (float) – Padding around the bounding box in coordinate units.

  • depth (bool) – Whether to apply depth-based shading.

Return type:

str

Returns:

SVG string representation of the 3D scene.

Raises:

ValueError – If no primitives are provided.

boltz_data.draw.mol3d.grid(*groups, padding=2)[source]#

Arrange multiple groups of primitives in a grid layout.

Computes bounding boxes for each group and arranges them in a grid pattern (approximately square). All groups are sized to fit the largest bounding box plus padding.

Parameters:
  • *groups (list[Text | DrawnSphere | DrawnLineSegment]) – Variable number of primitive groups to arrange.

  • padding (float) – Padding between grid cells.

Return type:

list[Text | DrawnSphere | DrawnLineSegment]

Returns:

Flat list of all primitives with positions adjusted for grid layout.