vibesketch.render.nanostructures

Nanostructure depictions for figures, chemfig and the canvas (#138).

A generated nanostructure (#137) has thousands of atoms, which a figure does not draw one by one with labels. It is drawn the way papers draw it, from its atoms and parameters:

  • lattice: the side projection of the lattice, the front wall solid and the rear wall lighter or left out (rear); a sheet or ribbon seen from above, a fullerene from the front;

  • schematic: a tube’s outline with the front wall’s hexagons as a light texture, for schemes; the ends of inner walls show at the left end;

  • end-on: a tube’s cross-section, one ring per wall;

  • unrolled: the graphene sheet a wall is rolled from, with the chiral vector Ch and the translation vector T (Saito, Dresselhaus and Dresselhaus 1998).

A long tube is drawn with its middle cut out and a break mark (brk); the optional label gives (n,m), the diameter and the number of walls. Lines are the style preset’s width (thinner for the lattice); grey is used for the rear wall and texture only, never colour (IUPAC 2008, GR-0.5).

On the canvas a depiction is one KET image (Ketcher 3.18), whose SVG carries a metadata element naming the species, its key, the style and the anchors: points where a molecule attaches, such as a tube’s ends. Ketcher moves and resizes the image and keeps its data, so figures find the species again and draw it afresh, in the figure’s preset, in the image’s box. The SVG in the canvas is never itself embedded in a figure: a KET file may come from anyone.

Module Attributes

ANCHOR_REACH

How close, in bond lengths, an attachment atom must be to an anchor to join it.

Functions

anchor_points(node)

The anchors of a depiction image in KET coordinates, with their bond directions.

canvas_image(species, depiction, at[, width])

A KET image node of the depiction, its top-left corner at at, width bonds wide.

caption_room(pic, size)

How far a picture's caption reaches below its box, in the units of size.

depiction_of(node)

The depiction a KET image node stands for and its anchors, or None for another image.

image_box(node)

A KET image's box: left, top, width, height in KET units (y up); refused if not finite.

picture(species, depiction)

The depiction of a nanostructure species; raises DepictionRefused.

picture_svg(pic, box, line, font, size)

SVG elements of pic fitted into box (SVG units, y down).

picture_tikz(pic, box)

TikZ commands of pic fitted into box (KET units, y up: left, top, width, height).

Classes

Depiction(species, key[, style, label, ...])

How one nanostructure species is drawn.

Picture([items, anchors])

A depiction in its own coordinates (angstrom, y up), with named anchors.

Exceptions

DepictionRefused

A depiction that cannot be drawn as asked; the message says why.

vibesketch.render.nanostructures.ANCHOR_REACH = 0.6

How close, in bond lengths, an attachment atom must be to an anchor to join it.

class vibesketch.render.nanostructures.Depiction(species, key, style='schematic', label=False, rear='light', brk='auto')[source]

Bases: object

How one nanostructure species is drawn.

Parameters:
  • species (str)

  • key (str)

  • style (Literal['lattice', 'schematic', 'end-on', 'unrolled'])

  • label (bool)

  • rear (Literal['light', 'omit'])

  • brk (Literal['auto', 'on', 'off'])

species: str
key: str
style: Literal['lattice', 'schematic', 'end-on', 'unrolled'] = 'schematic'
label: bool = False

Print (n,m), the diameter and the walls under it.

rear: Literal['light', 'omit'] = 'light'

lighter, or left out.

Type:

The rear wall in the lattice style

brk: Literal['auto', 'on', 'off'] = 'auto'

always, never, or when it is over six diameters.

Type:

Cut out the middle of a long tube

metadata(anchors)[source]
Parameters:

anchors (dict[str, list[float]])

Return type:

dict[str, Any]

exception vibesketch.render.nanostructures.DepictionRefused[source]

Bases: ValueError

A depiction that cannot be drawn as asked; the message says why.

class vibesketch.render.nanostructures.Picture(items=<factory>, anchors=<factory>)[source]

Bases: object

A depiction in its own coordinates (angstrom, y up), with named anchors.

An anchor is a point and the direction a bond leaves it, (x, y, dx, dy).

Parameters:
items: list[_Line | _Ellipse | _Text]
anchors: dict[str, tuple[float, float, float, float]]
bounds()[source]
Return type:

tuple[float, float, float, float]

vibesketch.render.nanostructures.canvas_image(species, depiction, at, width=8.0)[source]

A KET image node of the depiction, its top-left corner at at, width bonds wide.

The image’s SVG carries the depiction and its anchors in a metadata element; the anchors are given as fractions of the box, so they follow the image when it is moved or resized.

Parameters:
Return type:

dict[str, Any]

vibesketch.render.nanostructures.depiction_of(node)[source]

The depiction a KET image node stands for and its anchors, or None for another image.

Only the metadata element is read, as JSON within bounds; the rest of the SVG is ignored.

Parameters:

node (dict[str, Any])

Return type:

tuple[Depiction, dict[str, list[float]]] | None

vibesketch.render.nanostructures.picture(species, depiction)[source]

The depiction of a nanostructure species; raises DepictionRefused.

Parameters:
Return type:

Picture

vibesketch.render.nanostructures.caption_room(pic, size)[source]

How far a picture’s caption reaches below its box, in the units of size.

Parameters:
Return type:

float

vibesketch.render.nanostructures.picture_svg(pic, box, line, font, size)[source]

SVG elements of pic fitted into box (SVG units, y down).

Parameters:
Return type:

str

vibesketch.render.nanostructures.picture_tikz(pic, box)[source]

TikZ commands of pic fitted into box (KET units, y up: left, top, width, height).

Parameters:
Return type:

list[str]