API Reference#
Only the entries listed on this page are part of the supported Python API. Underscored names and modules are implementation details; see API stability.
Package exports#
moldenViz exports Atom, AtomType, GaussianPrimitive,
GridType, MolecularOrbital, Parser, Plotter, Shell,
Tabulator, and __version__.
The public moldenViz.qt module exports OrbitalViewer for embedding and
ViewerConfig for validated per-instance configuration.
The public moldenViz.testing module exports without_rendering and
NullInteractor for Qt host smoke tests that do not exercise VTK rendering.
Parser data models#
- class moldenViz.models.Atom(label, atomic_number, position, shells)[source]#
Bases:
objectA parsed atom and its basis-function shells.
- Parameters:
- position: NDArray[np.floating]#
- class moldenViz.models.GaussianPrimitive(exp, coeff)[source]#
Bases:
objectA Gaussian primitive with an exponent and contraction coefficient.
- class moldenViz.models.MolecularOrbital(sym, energy, spin, occ)[source]#
Bases:
objectMetadata for a parsed molecular orbital.
- class moldenViz.models.Shell(l, gtos)[source]#
Bases:
objectAn electron shell containing Gaussian primitives.
- Parameters:
l (int)
gtos (list[GaussianPrimitive])
- moldenViz.parser.BOHR_PER_ANGSTROM#
Number of Bohr in one Angstrom.
Visualization configuration#
AtomType is a visualization-specific model. Its supported import path is
moldenViz.AtomType; it is not part of the parser-focused
moldenViz.models namespace.
Parser#
- class moldenViz.parser.Parser(*, filename=None, content=None, only_molecule=False, mo_order='energy')[source]#
Bases:
objectParser for molden files.
- Parameters:
filename (str | os.PathLike[str] | None, optional) – Path to the Molden file. Exactly one of
filenameandcontentmust be provided.content (str | None, optional) – Complete contents of a Molden file. Exactly one of
filenameandcontentmust be provided.only_molecule (bool, optional) – Only parse the atoms and skip molecular orbitals. Default is False.
mo_order ({'energy', 'file'}, optional) – Order molecular orbitals by ascending energy or preserve their order in the Molden file. Default is
'energy'.
- Variables:
atoms (list[Atom]) – A list of Atom objects containing the label, atomic number, and position for each atom.
shells (list[Shell]) – A list of Shell objects containing the atom, angular momentum quantum number (l), and GTOs for each shell.
mos (list[MolecularOrbital]) – A list of MolecularOrbital objects containing the symmetry, energy, and coefficients for each MO.
mo_coeffs (NDArray[np.floating]) – A 2D array containing all molecular orbital coefficients, where each row represents the coefficients for one molecular orbital.
- Raises:
TypeError – If
filenameis not a string or path-like object, orcontentis not a string.ValueError – If exactly one input is not provided, or if
mo_orderis not'energy'or'file'.
Tabulator#
- class moldenViz.tabulator.Tabulator(*, filename=None, content=None, only_molecule=False, max_workers=None)[source]#
Bases:
objectExtends Parser, create grids and tabulates Gaussian-type orbitals (GTOs) from Molden files.
- Parameters:
filename (str | os.PathLike[str] | None, optional) – Path to the Molden file. Exactly one of
filenameandcontentmust be provided.content (str | None, optional) – Complete contents of a Molden file. Exactly one of
filenameandcontentmust be provided.only_molecule (bool, optional) – Only parse the atoms and skip molecular orbitals. Default is
False.max_workers (int | None, optional) – Maximum concurrent workers for GTO tabulation.
Noneuses up to four workers through 125,000 grid points and switches to sequential work for larger grids. Explicit values override the grid-size policy but remain capped at four and further bounded by the CPU and atom counts. Set to1for sequential tabulation. Default isNone.
- Variables:
grid (NDArray[np.floating]) – The grid points where GTOs and MOs are tabulated.
gtos (NDArray[np.floating]) – The cached Gaussian-type orbitals (GTOs) on the grid. Access raises
RuntimeErrorwhen no cache is available.has_gtos (bool) – Whether GTO values are currently cached.
max_workers (int) – Effective GTO worker count after applying the configured policy.
- set_grid(new_grid)[source]#
Set an arbitrary Cartesian point grid after validating its structure.
- Parameters:
new_grid (Any) – Candidate 2D array whose rows are XYZ coordinates.
- Raises:
TypeError – If
new_gridis not a NumPy array.ValueError – If the array does not have three columns or contains no rows.
- Return type:
None
- property gtos: NDArray[floating]#
The tabulated Gaussian-type orbitals (GTOs) on the grid.
- Raises:
RuntimeError – If GTOs have not been tabulated or the cache was cleared.
- set_gtos(gtos)[source]#
Install GTO values produced for the current grid.
- Parameters:
gtos (NDArray[np.floating]) – Two-dimensional GTO values with one row per grid point.
- Raises:
ValueError – If the values are not two-dimensional or do not match the grid.
- Return type:
None
- property molecular_orbitals: list[MolecularOrbital]#
Molecular-orbital metadata parsed from the Molden input.
- property grid_dimensions: tuple[int, int, int]#
The three-dimensional grid shape used by structured exporters.
- property grid_axes: tuple[NDArray[floating], ...] | None#
The original coordinate axes, if the grid was built from axes.
- static spherical_to_cartesian(r, theta, phi)[source]#
Convert spherical coordinates to Cartesian coordinates.
- static cartesian_to_spherical(x, y, z)[source]#
Convert Cartesian coordinates to spherical coordinates.
- cartesian_grid(x, y, z, *, tabulate_gtos=True)[source]#
Create cartesian grid from x, y, z arrays and tabulate GTOs.
- Parameters:
x (NDArray[np.floating]) – 1D array of x coordinates.
y (NDArray[np.floating]) – 1D array of y coordinates.
z (NDArray[np.floating]) – 1D array of z coordinates.
tabulate_gtos (bool, optional) – Whether to tabulate Gaussian-type orbitals (GTOs) after creating the grid. Defaults to True.
- Return type:
None
- spherical_grid(r, theta, phi, *, tabulate_gtos=True)[source]#
Create spherical grid from r, theta, phi arrays and tabulate GTOs.
- Parameters:
r (NDArray[np.floating]) – 1D array of radial coordinates.
theta (NDArray[np.floating]) – 1D array of polar angles (radians).
phi (NDArray[np.floating]) – 1D array of azimuthal angles (radians).
tabulate_gtos (bool, optional) – Whether to tabulate Gaussian-type orbitals (GTOs) after creating the grid. Defaults to True.
- Return type:
None
Notes
Grid points are converted to Cartesian coordinates.
- compute_gtos(grid, *, point_chunk_size=32768)[source]#
Compute GTO values for an explicit Cartesian grid.
This method does not read or update the Tabulator’s current grid or GTO cache, so it is safe to use for background work on a grid snapshot. By default, each worker evaluates at most 32,768 points at a time so temporary arrays do not grow with the full grid.
- Parameters:
grid (NDArray[np.floating]) – Cartesian grid points with shape
(n_points, 3).point_chunk_size (int or None, optional) – Maximum number of points evaluated by one worker task.
Noneevaluates each atom on the full grid and is mainly useful for performance comparisons. Defaults to 32,768.
- Returns:
Array containing the tabulated GTO data.
- Return type:
NDArray[np.floating]
- Raises:
RuntimeError – If the only_molecule flag is set to True.
ValueError – If point_chunk_size is not a positive integer or
None.
- tabulate_gtos(*, point_chunk_size=32768)[source]#
Tabulate Gaussian-type orbitals (GTOs) on the current grid.
- Parameters:
point_chunk_size (int or None, optional) – Maximum number of points evaluated by one worker task.
Noneevaluates each atom on the full grid. Defaults to 32,768.- Returns:
Array containing the tabulated GTOs data.
- Return type:
NDArray[np.floating]
- Raises:
RuntimeError – If the grid is not defined before tabulating GTOs, or if the only_molecule flag is set to True.
- tabulate_mos(mo_inds=None, *, gtos=None)[source]#
Tabulate molecular orbitals (MOs) on the current grid.
- Parameters:
mo_inds (int, array-like, or None, optional) – Indices of the MOs to tabulate. If None, all MOs are tabulated.
gtos (NDArray[np.floating] or None, optional) – Explicit GTO values to contract instead of the current grid cache. This does not modify the current grid or cached GTOs.
- Returns:
Array containing the tabulated MOs data.
If an integer is provided, it will tabulate only that MO. If an array-like is provided, it will tabulate the MOs at those indices.
- Return type:
NDArray[np.floating]
- Raises:
RuntimeError – If the grid is not defined before tabulating MOs.
RuntimeError – If GTOs are not tabulated before tabulating MOs.
ValueError – If provided mo_inds is invalid.
- export(path, *, mo_index=None)[source]#
Export the current grid data to a VTK-based or cube file.
- Parameters:
path (str | Path) – Target path for the exported data. The file extension should match the desired exporter (
.vtkfor VTK,.cubefor cube files).mo_index (int | None, optional) – Molecular orbital index to export. The parameter is optional for VTK exports. If none is given then all the molecular orbitals will be exported. Required for cube exports.
- Raises:
RuntimeError – If a grid has not been generated or only the molecular geometry was parsed.
ValueError – If an unsupported
filetypeis provided, or ifmo_indexis missing when exporting cube files.
- Return type:
None
Plotter#
- class moldenViz.plotter.Plotter(*args, **kwargs)[source]#
Bases:
QMainWindowFree-floating Qt window containing an
OrbitalViewer.If no
QApplicationexists,Plottercreates one and blocks in its event loop until the window closes. Inside an existing Qt application, construction returns immediately and the host keeps ownership of the loop.- Parameters:
filename (str | os.PathLike[str] | None, optional) – Path to the Molden file. Required when neither
contentnortabulatoris provided.content (str | None, optional) – Complete contents of a Molden file. Required when neither
filenamenortabulatoris provided.only_molecule (bool, optional) – Skip molecular-orbital parsing and controls.
tabulator (Tabulator, optional) – Existing structured-grid tabulator with cached GTO values.
config (Config | MainConfig | Mapping, optional) – Per-window configuration overrides.
parent (QWidget, optional) – Optional Qt parent for the free-floating window.
- show_orbital(index)[source]#
Delegate orbital selection to the contained viewer.
- Parameters:
index (int)
- Return type:
None
- plot_orbital(index)[source]#
Compatibility alias for
show_orbital().- Parameters:
index (int)
- Return type:
None
- wait_for_gtos(timeout=None)[source]#
Wait for background GTO tabulation.
- Parameters:
timeout (float | None)
- Return type:
None
- is_molecule_visible()[source]#
Return whether molecule actors are visible.
- Returns:
Whether at least one molecule actor is visible.
- Return type:
- are_atoms_visible()[source]#
Return whether atom actors are visible.
- Returns:
Whether at least one atom actor is visible.
- Return type:
OrbitalViewer#
- class moldenViz.qt.OrbitalViewer(*args, **kwargs)[source]#
Bases:
QWidget,_PlotterRenderingEmbeddable Qt widget for molecules and molecular orbitals.
The host must create and run
QApplication. Constructing this widget never starts an event loop or shows a top-level window.- Parameters:
filename (str | os.PathLike[str] | None, optional) – Path to the Molden file.
content (str | None, optional) – Complete contents of a Molden file.
only_molecule (bool, optional) – Skip molecular-orbital parsing and controls.
tabulator (Tabulator, optional) – Existing structured-grid tabulator with cached GTO values.
config (Config | MainConfig | Mapping, optional) – Per-viewer configuration overrides.
show_controls (bool, optional) – Show the built-in control panel. Disable it when the host supplies its own dashboard.
parent (QWidget, optional) – Parent widget supplied by the host application.
- property config: Config#
Per-instance visualization configuration.
- set_axes_visible(*, visible)[source]#
Show or hide the orientation axes.
- Parameters:
visible (bool) – Whether the orientation axes should be visible.
- Return type:
None
- reset_camera()[source]#
Restore the default isometric view and fit all visible actors.
- Return type:
None
- showEvent(event)[source]#
Watch for screen changes once the native window exists.
- Parameters:
event (QShowEvent)
- Return type:
None
- eventFilter(watched, event)[source]#
Repaint native widgets after a device-pixel-ratio change.
- Returns:
Whether the event should stop propagating.
- Return type:
- Parameters:
watched (PySide6.QtCore.QObject)
event (PySide6.QtCore.QEvent)
- property molecular_orbitals: tuple[MolecularOrbital, ...]#
Molecular orbitals available to host-provided controllers.
- set_input(*, filename=None, content=None, tabulator=None, only_molecule=None)[source]#
Load or replace the Molden input displayed by this widget.
- show_orbital(index)[source]#
Show one orbital, or clear it when
indexis-1.- Parameters:
index (int)
- Return type:
None
- set_controls_visible(*, visible)[source]#
Show or hide the built-in control panel.
- Parameters:
visible (bool)
- Return type:
None
- update_grid(axes, grid_type, *, mode=None, adaptive_scale=None)[source]#
Replace the structured grid and schedule fresh GTO tabulation.
- set_spherical_grid(*, radius, radial_points, theta_points, phi_points)[source]#
Build and apply a spherical grid from dashboard-friendly values.
- set_cartesian_grid(*, x_range, y_range, z_range, x_points, y_points, z_points)[source]#
Build and apply a Cartesian grid from bounds and point counts.
- set_adaptive_grid(*, x_range, y_range, z_range, x_points, y_points, z_points, scale)[source]#
Build and apply an adaptive Cartesian grid from explicit values.
- apply_appearance(*, contour, mo_opacity, color_scheme, custom_colors, molecule_opacity, show_atoms, show_bonds, bond_max_length, bond_radius, bond_color_type, bond_color, background_color)[source]#
Apply validated appearance settings to this viewer instance.
- update_appearance(*, contour=None, mo_opacity=None, color_scheme=None, custom_colors=None, molecule_opacity=None, show_atoms=None, show_bonds=None, bond_max_length=None, bond_radius=None, bond_color_type=None, bond_color=None, background_color=None)[source]#
Apply a partial appearance update for host-provided controllers.
- Parameters:
- Return type:
None
- set_background_color(color)[source]#
Set this viewer’s render background color.
- Parameters:
color (str)
- Return type:
None
- export_data(path, *, file_format, scope='current')[source]#
Export orbital data to an explicit destination without dialogs.
- export_image(path, *, file_format, transparent=False)[source]#
Export the current render to an explicit destination without dialogs.
- save_settings()[source]#
Persist this viewer’s current settings to the user TOML file.
- Return type:
None
- wait_for_gtos(timeout=None)[source]#
Block until background GTO tabulation finishes.
- Parameters:
timeout (float | None)
- Return type:
None
- wait_for_adaptive_grid(timeout=None)[source]#
Block until adaptive-grid tabulation finishes.
- Parameters:
timeout (float | None)
- Return type:
None
- moldenViz.qt.ViewerConfig#
alias of
MainConfig
Testing Qt hosts#
- moldenViz.testing.without_rendering()[source]#
Use
NullInteractorfor viewers constructed in this context.This allows Qt host pages to be smoke-tested under the
offscreenQt platform without asking VTK to create an unavailable OpenGL context.- Yields:
None – Control while the non-rendering interactor override is active.
- Return type:
Iterator[None]
- class moldenViz.testing.NullInteractor(*args, **kwargs)[source]#
Bases:
QWidgetNon-rendering
QtInteractorreplacement for UI smoke tests.This widget records scene operations but creates no VTK render window or OpenGL context. It is intended only for layout, lifecycle, and controller tests performed inside
without_rendering().- Parameters:
parent (QWidget | None)
_kwargs (object)
- set_background(color)[source]#
Record the requested background color.
- Parameters:
color (str)
- Return type:
None
- remove_actor(actor)[source]#
Remove a previously recorded actor.
- Parameters:
actor (_NullActor)
- Return type:
None