picogl.renderer.molecular

Molecular mesh data builders shared by legacy and modern GL backends.

Submodules

Classes

MeshArrays

Immutable NumPy arrays for positions, normals, colors, and indices.

BondGeometry

Geometry parameters for a cylindrical bond shaft.

PNCBuffer

Accumulate indexed position / normal / color geometry.

Package Contents

class picogl.renderer.molecular.MeshArrays[source]

Immutable NumPy arrays for positions, normals, colors, and indices.

Geometry producers return this type. Color is optional: atom/bond geometry typically omits it, and AtomsMesh / BondsMesh attach it later. Primitive mode is not stored here; as_meshdata() supplies MeshDrawInfo.

positions: numpy.ndarray
normals: numpy.ndarray
colors: numpy.ndarray | None = None
indices: numpy.ndarray | None = None
__post_init__() → None[source]
property indexed: bool

Whether this mesh carries an index buffer.

classmethod from_pnc(part: picogl.renderer.meshdata.PNCPart, *, indices: numpy.ndarray | None = None) → MeshArrays[source]

Build MeshArrays from a PNCPart.

Parameters:
  • part – (positions, normals, colors)

  • indices – Optional element buffer

Returns:

New MeshArrays value

as_pnc() → picogl.renderer.meshdata.PNCPart[source]

Return (positions, normals, colors).

Raises:

ValueError – When colors are missing

with_colors(colors: numpy.ndarray) → MeshArrays[source]

Return a copy with colors replacing the current color array.

Parameters:

colors – RGB triples with shape (3,) or (N, 3).

Returns:

New value with the same positions, normals, and indices.

Return type:

MeshArrays

as_meshdata(*, mode: picogl.backend.gl.enums.GLDrawMode = GLDrawMode.TRIANGLES, indexed: bool | None = None, elements_per_item: int | None = None, vertices_per_item: int | None = None) → picogl.renderer.meshdata.MeshData[source]

Convert these arrays into renderable MeshData.

Parameters:
  • mode – Primitive mode. Defaults to triangles so unindexed geometry is not inferred as points.

  • indexed – Whether drawing uses an element buffer. Defaults to indexed.

  • elements_per_item – Indices (or vertices, when unindexed) per logical item.

  • vertices_per_item – Vertices per logical item, used when expanding per-item attributes.

Returns:

CPU mesh with draw_info built from mode and the layout arguments.

Return type:

MeshData

class picogl.renderer.molecular.BondGeometry[source]

Geometry parameters for a cylindrical bond shaft.

Builds an open-sided cylinder between two world-space points. Color is applied by BondsMesh.

radius: float = 0.06
segments: int = 8
property vertices_per_item: int

Number of vertices in one cylinder (two rings).

property elements_per_item: int

Number of triangle indices in one cylinder.

build(start: collections.abc.Iterable[float], end: collections.abc.Iterable[float]) → picogl.renderer.mesh_arrays.MeshArrays[source]

Build an oriented cylinder spanning start to end.

Parameters:
  • start – World-space cylinder origin.

  • end – World-space cylinder terminus.

Returns:

Positions, radial normals, and indices. Empty when the axis length is below 1e-12.

Return type:

MeshArrays

build_many(starts: numpy.ndarray, ends: numpy.ndarray) → tuple[picogl.renderer.mesh_arrays.MeshArrays, numpy.ndarray][source]

Build cylinders for many bonds simultaneously.

Zero-length shafts (axis shorter than 1e-12) are omitted from the returned arrays. The boolean valid mask has one entry per input row.

Parameters:
  • starts – (N, 3) world-space origins

  • ends – (N, 3) world-space termini

Returns:

(mesh, valid) where mesh has no colors

class picogl.renderer.molecular.PNCBuffer[source]

Accumulate indexed position / normal / color geometry.

This class does not construct primitives. Geometry producers append via extend() (world-space MeshArrays) or add_instance() / add_instances() (translated templates). to_mesh_arrays() materializes combined geometry; to_mesh_data() is the render boundary.

_positions: list[numpy.ndarray] = []
_normals: list[numpy.ndarray] = []
_colors: list[numpy.ndarray] = []
_indices: list[numpy.ndarray] = []
vertex_offset: int = 0
add_instance(mesh: picogl.renderer.mesh_arrays.MeshArrays, translation: collections.abc.Iterable[float], color: tuple[float, float, float], *, scale: float = 1.0) → None[source]

Translate a geometry template and append it with a uniform color.

Template colors are ignored; color is tiled onto every new vertex.

Parameters:
  • mesh – Origin-centered positions, normals, and local indices

  • translation – World-space offset applied to every template vertex

  • color – RGB triple copied onto every new vertex

  • scale – Uniform scale applied to template positions before translation

add_instances(mesh: picogl.renderer.mesh_arrays.MeshArrays, translations: numpy.ndarray, colors: numpy.ndarray, *, scales: numpy.ndarray | None = None) → None[source]

Translate one template to many instances in a single NumPy expand.

Template colors are ignored; each row of colors is tiled onto that instance’s vertices.

Parameters:
  • mesh – Origin-centered positions, normals, and local indices

  • translations – World-space offsets with shape (N, 3)

  • colors – Per-instance RGB triples with shape (N, 3)

  • scales – Optional per-instance uniform scales with shape (N,)

extend(mesh: picogl.renderer.mesh_arrays.MeshArrays, *, color: tuple[float, float, float] | None = None) → None[source]

Append world-space geometry and offset local indices.

Parameters:
  • mesh – Positions, normals, and indices already in world space

  • color – Optional RGB triple tiled onto every vertex. Used when given; otherwise mesh.colors is required.

Raises:

ValueError – If neither color nor mesh.colors is present

_resolve_colors(mesh: picogl.renderer.mesh_arrays.MeshArrays, n_verts: int, color: tuple[float, float, float] | None) → numpy.ndarray[source]
_offset_indices(indices: numpy.ndarray | None) → numpy.ndarray[source]
_append_chunk(positions: numpy.ndarray, normals: numpy.ndarray, colors: numpy.ndarray, indices: numpy.ndarray, n_verts: int) → None[source]
to_mesh_arrays() → picogl.renderer.mesh_arrays.MeshArrays[source]

Materialize accumulated chunks as combined geometry.

Returns:

Positions, normals, colors, and offset triangle indices

to_mesh_data() → picogl.renderer.meshdata.MeshData[source]

Build renderable MeshData.

Returns:

Mesh with positions, normals, colors, and triangle indices

to_arrays(dtype: numpy.dtype | type = np.float32) → tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Return concatenated NumPy arrays for to_mesh_arrays().

Parameters:

dtype – Floating-point dtype for positions, normals, and colors

Returns:

(vertices, normals, colors, indices)