horton_part.scripts.generate_cube module

class PartCubeProg(width=100)

Bases: PartProg

Part-Cube Program

__init__(width=100)
build_parser(*args, **kwargs)

Parse command-line arguments.

check_settings(settings)
print_charges(numbers, charges)
print_coordinates(numbers, coordinates)
print_header(header)
print_line()
print_settings(settings, fn_in, fn_out, fn_log, exclude_keys=None)

Print setting for this program.

run(args=None)

Main entry.

Return type:

int

setup_logger(settings, fn_log, **kwargs)
single_launch(settings, fn_in, fn_out, fn_log, **kwargs)

Man entry for a single job.

main(args=None)

Main entry.

Return type:

int

prepare_input_cube(iodata, chunk_size, gradient, orbitals, logger, grid=None)

Prepare input data for denspart using HORTON3 modules.

This function sets up a cubic molecular grid if none is provided, evaluates the electron density (and optionally its gradient and orbitals) on the grid points in chunks, and returns both the grid and the computed data.

Parameters:
  • iodata (IOData) – An instance of IOData containing the necessary molecular data (atomic numbers, coordinates, wavefunctions, etc.) required to compute the electron density on the grid.

  • chunk_size (int) – Number of grid points to evaluate in one pass. Controls memory usage.

  • gradient (bool) – If True, compute the gradient of the electron density on the grid.

  • orbitals (bool) – If True, compute both occupied and virtual orbitals on the grid.

  • logger (logging.Logger) – Logger for status messages.

  • grid (MolGrid, optional) – A molecular integration grid. If None, a cubic grid is generated automatically from the molecular geometry.

Returns:

  • grid (MolGrid) – The molecular integration grid used for the calculations.

  • data (dict) – Quantities evaluated on the grid. Always includes the electron density; may also include its gradient and orbital values depending on the input flags.

to_cube(fname, atnums, atcorenums, atcoords, grid, data)

Write scalar data defined on a uniform 3D grid to a Gaussian cube file.

The cube file format is commonly used to visualize scalar fields such as electron densities or molecular orbitals. This function writes both the header information (atoms, grid, and cell vectors) and the grid data in the standard cube format.

Parameters:
  • fname (str) – Output file name. Must end with the .cube extension.

  • atnums (array_like of int, shape (N,)) – Atomic numbers of the atoms in the system.

  • atcorenums (array_like of float, shape (N,)) – Effective nuclear charges (usually the number of core electrons). These are written in the second column of the atom block in the cube file.

  • atcoords (array_like of float, shape (N, 3)) – Cartesian coordinates of the atoms.

  • grid (UniformGrid) – A uniform 3D grid defining the origin, shape, and axes.

  • data (np.ndarray, shape (npoints,)) – A 1D array containing the scalar property evaluated at each grid point.

Raises:

ValueError – If fname does not end with .cube or if the size of data does not match the number of grid points.

Notes

  • Data are written in chunks of six values per line, as required by the standard cube file format.

  • The function writes a simple header identifying the file as generated by HORTON-PART.