API Module

This module provides functions for drawing molecules using atoms and bonds.

class Style(value)[source]

The style of the depiction.

Variables:
  • SpaceFilling – The space-filling style.

  • BallAndStick – The ball-and-stick style.

  • Tube – The tube style.

  • Wireframe – The wireframe style.

class Look(value)[source]

The look of the depiction.

Variables:
  • Cartoon – The cartoon look.

  • Glossy – The glossy look.

class Atom(index: int, symbol: str, coordinates: Tuple[float, float, float], radius: float | None = None, color: Tuple[int, int, int] | None = None, opacity: float = 1.0)[source]

Represents an atom in a molecule.

Variables:
  • index – The index of the atom.

  • symbol – The symbol of the atom.

  • coordinates – The coordinates of the atom.

  • radius – The radius of the atom.

  • color – The color of the atom.

  • opacity – The opacity of the atom.

class Bond(start_index: int, end_index: int, order: int, radius: float | None = None, color: Tuple[int, int, int] | None = None, opacity: float = 1.0)[source]

A bond between two atoms in a molecule.

Variables:
  • start_index – The index of the start atom.

  • end_index – The index of the end atom.

  • order – The order of the bond.

filter_atoms_and_bonds(atoms: List[Atom], bonds: List[Bond], exclude_atoms: List[str] | None = None) Tuple[List[Atom], List[Bond]][source]

Filter atoms and bonds based on the given exclude atoms.

Parameters:
  • atoms (ty.List[Atom]) – The atoms in the molecule.

  • bonds (ty.List[Bond]) – The bonds in the molecule.

  • exclude_atoms (ty.Optional[ty.List[str]]) – The atoms to exclude from the depiction (list of atom symbols).

Returns:

The filtered atoms and bonds.

Return type:

ty.Tuple[ty.List[Atom], ty.List[Bond]]

draw_bonds_in_wireframe_style(scene: Scene, atoms: List[Atom], bonds: List[Bond], wire_width: float = 0.05) None[source]

Draw a molecule using the given atoms and bonds in wireframe style.

Parameters:
  • scene (Scene) – The scene to draw the molecule in.

  • atoms (ty.List[Atom]) – The atoms in the molecule. We need this to get the position and color of the atoms to draw the bonds.

  • bonds (ty.List[Bond]) – The bonds in the molecule.

  • wire_width (float) – The width of the wires.

draw_atoms_in_spacefilling_style(scene: Scene, atoms: List[Atom], look: Look, stroke_color: Color, stroke_width: float, radius_scale: float = 1.0) None[source]

Draw a molecule using the given atoms in space-filling style.

Parameters:
  • scene (Scene) – The scene to draw the molecule in.

  • atoms (ty.List[Atom]) – The atoms in the molecule.

  • look (Look) – The look of the depiction.

  • stroke_color (Color) – The stroke color of the depiction.

  • stroke_width (float) – The stroke width of the depiction.

  • radius_scale (float) – Divide the radius of the atoms by this value.

Raises:

ValueError – If an unknown look is given.

draw_bonds_in_tube_style(scene: Scene, atoms: List[Atom], bonds: List[Bond], tube_bond_style: Style, look: Look, cap_type: CylinderCapType, stroke_color: Color, stroke_width: float) None[source]

Draw a molecule using the given atoms and bonds in tube style.

Parameters:
  • scene (Scene) – The scene to draw the molecule in.

  • atoms (ty.List[Atom]) – The atoms in the molecule. We need this to get the position and color of the atoms to draw the bonds.

  • bonds (ty.List[Bond]) – The bonds in the molecule.

  • tube_bond_style (Style) – The style of the depiction. Ball-and-stick will draw bond order as cylinders, while tube will draw any bond order as a single cylinder.

  • look (Look) – The look of the depiction.

  • cap_type (CylinderCapType) – The cap type of the cylinders.

  • stroke_color (Color) – The stroke color of the depiction.

  • stroke_width (float) – The stroke width of the depiction.

Raises:

ValueError – If an unknown look is given.

draw_molecule(atoms: List[Atom], bonds: List[Bond], style: Style, look: Look, resolution: int, window: Tuple[float, float] | None = None, view_box: Tuple[float, float, float, float] | None = None, rotation_over_x_axis: float = 0.0, rotation_over_y_axis: float = 0.0, rotation_over_z_axis: float = 0.0, scale: float = 1.0, focal_length: float | None = None, exclude_atoms: List[str] | None = None) Svg[source]

Draw a molecule using the given atoms and bonds.

Parameters:
  • atoms (ty.List[Atom]) – The atoms in the molecule.

  • bonds (ty.List[Bond]) – The bonds in the molecule.

  • style (Style) – The style of the depiction.

  • look (Look) – The look of the depiction.

  • resolution (int) – The resolution of the depiction.

  • window (ty.Optional[ty.Tuple[float, float]]) – The window of the depiction.

  • view_box (ty.Optional[ty.Tuple[float, float, float, float]]) – The view box of the depiction.

  • rotation_over_x_axis (float) – The rotation over the x-axis of the depiction.

  • rotation_over_y_axis (float) – The rotation over the y-axis of the depiction.

  • rotation_over_z_axis (float) – The rotation over the z-axis of the depiction.

  • scale – The scale of the depiction.

  • focal_length (ty.Optional[float]) – The focal length of the depiction. If None, the focal length is calculated based on the dimensions of the scene.

  • exclude_atoms (ty.Optional[ty.List[str]]) – The atoms to exclude from the depiction (list of atom symbols).

Returns:

The SVG of the depiction.

Return type:

Svg

Raises:

ValueError – If an unknown style or look is given.