ase_notebook.backend.svg module

A module for creating an SVG visualisation of a structure.

ase_notebook.backend.svg.cart2polar(x, y)[source]

Convert cartesian to polar coordinates.

ase_notebook.backend.svg.concatenate_svgs(svgs, max_columns=None, scale=None, label=False, size=12, weight='bold', inset=(0.1, 0.1))[source]

Create a grid of SVGs, with a maximum number of columns.

Parameters
  • svgs (list) – Items may be raw SVG strings, or any objects with a tostring or to_str method.

  • max_columns (int or None) – max number of columns, or if None, only use one row

  • scale (float or None) – scale the entire composition

  • label (bool) – whether to add a label for each SVG (cycle through upper case letters)

  • size (int) – label font size

  • weight (str) – label font weight

  • inset (tuple) – inset the label by x times the SVG width and y times the SVG height

Returns

Return type

svgutils.compose.Figure

ase_notebook.backend.svg.create_arc_element(center, start, end, radius, **kwargs)[source]

Create an arc (circle section) path element.

Parameters
  • center (tuple) – (x, y)

  • start (float) – starting angle from x axis (in degrees)

  • end (float) – final angle from x axis (in degrees)

  • radius (float) –

Returns

Return type

svgwrite.path.Path

ase_notebook.backend.svg.create_axes_elements(axes, window_size, *, length=15, font_size=14, inset=(20, 20), font_offset=1.0, line_width=1, line_color='black', labels=('X', 'Y', 'Z'), colors=('red', 'green', 'blue'))[source]

Create the SVG elements, related to the axes.

ase_notebook.backend.svg.create_svg_document(elements, size, viewbox=None, background_color='white', background_opacity=1.0)[source]

Create the full SVG document.

Parameters

viewbox – (minx, miny, width, height)

ase_notebook.backend.svg.create_svg_document_with_light(elements, size, viewbox=None, background_color='white', background_opacity=1.0)[source]

Create the full SVG document, with a lighting filter.

Resources:

Parameters

viewbox – (minx, miny, width, height)

ase_notebook.backend.svg.generate_svg_elements(element_group, element_colors=None, background_color='white')[source]

Create the SVG elements, related to the 3D objects.

Parameters
Returns

Return type

list[svgwrite.base.BaseElement]

ase_notebook.backend.svg.get_svg_string(svg)[source]

Return the raw string of an SVG object with a tostring or to_str method.

ase_notebook.backend.svg.polar2cart(radius, angle)[source]

Convert polar to cartesian coordinates.

ase_notebook.backend.svg.string_to_compose(string)[source]

Convert an SVG string to a svgutils.compose.SVG.

ase_notebook.backend.svg.svg_to_pdf(svg, file_name=None)[source]

Convert SVG to PDF.

To view in notebook:

from IPython.display import display_pdf

rlg_drawing = svg_to_pdf(svg)
display_pdf(rlg_drawing.asString("pdf"), raw=True)
ase_notebook.backend.svg.tessellate_rectangles(sizes, max_columns=None)[source]

Compute the minimum size grid, required to fit a list of rectangles.