picogl.renderer.molecular ========================= .. py:module:: picogl.renderer.molecular .. autoapi-nested-parse:: Molecular mesh data builders shared by legacy and modern GL backends. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/picogl/renderer/molecular/atoms/index /autoapi/picogl/renderer/molecular/bond_geometry/index /autoapi/picogl/renderer/molecular/pnc_buffer/index Classes ------- .. autoapisummary:: picogl.renderer.molecular.MeshArrays picogl.renderer.molecular.BondGeometry picogl.renderer.molecular.PNCBuffer Package Contents ---------------- .. py:class:: MeshArrays Immutable NumPy arrays for positions, normals, colors, and indices. Geometry producers return this type. Color is optional: atom/bond geometry typically omits it, and :class:`~picogl.renderer.molecular.atoms.AtomsMesh` / :class:`~picogl.renderer.molecular.bonds.BondsMesh` attach it later. Primitive mode is not stored here; :meth:`as_meshdata` supplies :class:`~picogl.renderer.draw_spec.MeshDrawInfo`. .. py:attribute:: positions :type: numpy.ndarray .. py:attribute:: normals :type: numpy.ndarray .. py:attribute:: colors :type: Optional[numpy.ndarray] :value: None .. py:attribute:: indices :type: Optional[numpy.ndarray] :value: None .. py:method:: __post_init__() -> None .. py:property:: indexed :type: bool Whether this mesh carries an index buffer. .. py:method:: from_pnc(part: picogl.renderer.meshdata.PNCPart, *, indices: Optional[numpy.ndarray] = None) -> MeshArrays :classmethod: Build :class:`MeshArrays` from a :data:`~picogl.renderer.meshdata.PNCPart`. :param part: ``(positions, normals, colors)`` :param indices: Optional element buffer :return: New MeshArrays value .. py:method:: as_pnc() -> picogl.renderer.meshdata.PNCPart Return ``(positions, normals, colors)``. :raises ValueError: When colors are missing .. py:method:: with_colors(colors: numpy.ndarray) -> MeshArrays Return a copy with *colors* replacing the current color array. :param colors: RGB triples with shape ``(3,)`` or ``(N, 3)``. :returns: New value with the same positions, normals, and indices. :rtype: MeshArrays .. py:method:: 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 Convert these arrays into renderable :class:`~picogl.renderer.meshdata.MeshData`. :param mode: Primitive mode. Defaults to triangles so unindexed geometry is not inferred as points. :param indexed: Whether drawing uses an element buffer. Defaults to :attr:`indexed`. :param elements_per_item: Indices (or vertices, when unindexed) per logical item. :param 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. :rtype: MeshData .. py:class:: BondGeometry Geometry parameters for a cylindrical bond shaft. Builds an open-sided cylinder between two world-space points. Color is applied by :class:`~picogl.renderer.molecular.bonds.BondsMesh`. .. py:attribute:: radius :type: float :value: 0.06 .. py:attribute:: segments :type: int :value: 8 .. py:property:: vertices_per_item :type: int Number of vertices in one cylinder (two rings). .. py:property:: elements_per_item :type: int Number of triangle indices in one cylinder. .. py:method:: build(start: collections.abc.Iterable[float], end: collections.abc.Iterable[float]) -> picogl.renderer.mesh_arrays.MeshArrays Build an oriented cylinder spanning ``start`` to ``end``. :param start: World-space cylinder origin. :param end: World-space cylinder terminus. :returns: Positions, radial normals, and indices. Empty when the axis length is below ``1e-12``. :rtype: MeshArrays .. py:method:: build_many(starts: numpy.ndarray, ends: numpy.ndarray) -> tuple[picogl.renderer.mesh_arrays.MeshArrays, numpy.ndarray] 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. :param starts: ``(N, 3)`` world-space origins :param ends: ``(N, 3)`` world-space termini :return: ``(mesh, valid)`` where *mesh* has no colors .. py:class:: PNCBuffer Accumulate indexed position / normal / color geometry. This class does not construct primitives. Geometry producers append via :meth:`extend` (world-space :class:`~picogl.renderer.mesh_arrays.MeshArrays`) or :meth:`add_instance` / :meth:`add_instances` (translated templates). :meth:`to_mesh_arrays` materializes combined geometry; :meth:`to_mesh_data` is the render boundary. .. py:attribute:: _positions :type: list[numpy.ndarray] :value: [] .. py:attribute:: _normals :type: list[numpy.ndarray] :value: [] .. py:attribute:: _colors :type: list[numpy.ndarray] :value: [] .. py:attribute:: _indices :type: list[numpy.ndarray] :value: [] .. py:attribute:: vertex_offset :type: int :value: 0 .. py:method:: add_instance(mesh: picogl.renderer.mesh_arrays.MeshArrays, translation: collections.abc.Iterable[float], color: tuple[float, float, float], *, scale: float = 1.0) -> None Translate a geometry template and append it with a uniform color. Template colors are ignored; *color* is tiled onto every new vertex. :param mesh: Origin-centered positions, normals, and local indices :param translation: World-space offset applied to every template vertex :param color: RGB triple copied onto every new vertex :param scale: Uniform scale applied to template positions before translation .. py:method:: add_instances(mesh: picogl.renderer.mesh_arrays.MeshArrays, translations: numpy.ndarray, colors: numpy.ndarray, *, scales: numpy.ndarray | None = None) -> None 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. :param mesh: Origin-centered positions, normals, and local indices :param translations: World-space offsets with shape ``(N, 3)`` :param colors: Per-instance RGB triples with shape ``(N, 3)`` :param scales: Optional per-instance uniform scales with shape ``(N,)`` .. py:method:: extend(mesh: picogl.renderer.mesh_arrays.MeshArrays, *, color: tuple[float, float, float] | None = None) -> None Append world-space geometry and offset local indices. :param mesh: Positions, normals, and indices already in world space :param 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 .. py:method:: _resolve_colors(mesh: picogl.renderer.mesh_arrays.MeshArrays, n_verts: int, color: tuple[float, float, float] | None) -> numpy.ndarray .. py:method:: _offset_indices(indices: numpy.ndarray | None) -> numpy.ndarray .. py:method:: _append_chunk(positions: numpy.ndarray, normals: numpy.ndarray, colors: numpy.ndarray, indices: numpy.ndarray, n_verts: int) -> None .. py:method:: to_mesh_arrays() -> picogl.renderer.mesh_arrays.MeshArrays Materialize accumulated chunks as combined geometry. :return: Positions, normals, colors, and offset triangle indices .. py:method:: to_mesh_data() -> picogl.renderer.meshdata.MeshData Build renderable :class:`~picogl.renderer.meshdata.MeshData`. :return: Mesh with positions, normals, colors, and triangle indices .. py:method:: to_arrays(dtype: numpy.dtype | type = np.float32) -> tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] Return concatenated NumPy arrays for :meth:`to_mesh_arrays`. :param dtype: Floating-point dtype for positions, normals, and colors :return: ``(vertices, normals, colors, indices)``