label_generation
This module calculates the value and gradient label from the KSDFT simulation results.
Coefficients of the orbitals and the density in the orbital basis are provided by the KSDFT calculation. The energies calculated include:
Kinetic energy (\(E_{kin}(C) = T_s(C)\)),
Hartree energy (\(E_{H}(C)\)),
Exchange-correlation energy (\(E_{XC}(C)\)),
External energy (\(E_{ext}(C)\)),
Atomic nuclei repulsion energy (\(E_{nuc-nuc}\)),
Total energy (\(E_{tot}(C) = T_S(C) + E_H(C) + E_{XC}(C) + E_{ext}(C) + E_{nuc-nuc}\)).
The coefficients of the basis functions in the density basis are determined by density fitting. From these, \(E_{H}(\mathbf{p})\), \(E_{XC}(\mathbf{p})\), and \(E_{ext}(\mathbf{p})\) can be calculated, which now depend on the fitted density. The nuclear repulsion energy (\(E_{nuc-nuc}\)) remains constant.
The label for the kinetic energy in these coordinates is indirectly calculated by:
We cannot calculate the gradient of the kinetic energy directly from this equation as the density \(p\) depends on the coefficients in the orbital basis \(C\) in a nontrivial way. Instead, we make use of the minimization procedure in the ksdft calculation. Each iteration the energy is minimized as follows:
Where \(\pi^{(i)}_k\) are the DIIS coefficients of the KSDFT calculation and
is the effective potential of the \(k'\)-th iteration integrated over the density of the new density. This is solved using Laplace multipliers:
The projected gradient of the kinetic energy is then calculated as the DIIS weighted average over the projected last few effective potentials:
- calculate_labels(results: dict, initialization: dict, data_of_iteration: list[dict], mol_orbital_basis: Mole, mol_density_basis: Mole, density_fitting_method: str = 'hartree+external') dict[source]
Calculate labels from the results of a KSDFT calculation and return them in dict-form.
- Parameters:
results – The parameters of a ksdft-calculation, provided in dict form.
initialization – The density matrix and energy of the first iteration of the ksdft-calculation.
data_of_iteration – List of the data of all ksdft iterations of the molecule.
mol_orbital_basis – A gto.Mole object of the molecule in the orbital basis.
mol_density_basis – A gto.Mole object of the molecule in the density basis.
density_fitting_method – The method used for density fitting.
- Returns:
A dict of all data relevant for ofdft calculations and comparison.
- Raises:
KeyError – if one of the required keys is not inside the result dict
ValueError – if the number of basis functions in data_of_iteration and the molecule differ
Notes
All ks… values are calculated directly from the Kohn-Sham calculation. They are calculated at each iteration step of the ksdft-calculation. All of… values are calculated from the density “p” that was fitted to the density of the orbitals in ksdft.
- diis_weighted_average(iteration: int, diis_coeffs: ndarray, effective_potential_p: ndarray) ndarray[source]
Calculates the DIIS weighted average of the effective potential needed for the calculation of the gradient label.
\[{v}_{eff\{p^{k'}\}_{k'< k}} = \sum_{k'< k} \pi^{(k)}_{k'} v_{eff_{p^{(k')}}}\]\(\pi^{(k)}_{k'}\) are the DIIS - coefficients of the KSDFT - calculation.
- Parameters:
iteration – the iteration of which the weighted average of the effective potential should be computed. i=0 is the first iteration, not the initial guess.
diis_coeffs – the DIIS coefficients of this iteration (d)
effective_potential_p – the effective potentials of every iteration step (n_of_basis_functions)
- Returns:
the DIIS weighted average of the effective potential or any other tensor that is computed for every iteration and is of the shape (n_iterations, …)
- Return type:
effective_potential_p_k
- Raises:
ValueError – if diis_c is longer then iterations have been computed so far
- eval_density_functionals(coeffs: ndarray, functionals: list[str], mol: Mole, grid: Grids, aos: ndarray | None, aos_torch: Tensor | None, grid_weights: Tensor | None, use_torch: bool, use_blocked: bool, max_memory: float) dict[source]
Evaluate the classical density functionals.
- Parameters:
coeffs – The coefficients of the basis functions in the density basis.
functionals – The list of functionals to evaluate.
mol – The molecule in the density basis.
grid – The integration grid for the functionals.
aos – The atomic orbitals.
aos_torch – The atomic orbitals as a torch tensor.
grid_weights – The weights of the grid.
use_torch – Whether to use the torch implementation of the functionals.
use_blocked – Whether to use the blocked implementation of the torch functionals.
max_memory – The maximum memory for the functionals
- Returns:
A dictionary with the functionals as keys and tuples of the energies and gradients as values.
- get_data_dict(ks_energies: dict, of_energies: dict, of_coeffs: ndarray, of_gradients: dict, has_energy_label: ndarray, e_nuc_nuc: float)[source]
Create a dict with all data that should be stored.
Naming:
of_ = orbital free
ks_ = kohn sham
e_ = energy
grad_ = gradient
- Parameters:
ks_energies – The energies in the Kohn-Sham basis.
of_energies – The energies in the density basis.
of_coeffs – The coefficients in the density basis.
of_gradients – The gradients in the density basis.
has_energy_label – Whether the energy label is available for an iteration.
e_nuc_nuc – The nuclear-nuclear repulsion energy.
- get_energies_and_gradients(gamma: ndarray, grad_external_energy_c: ndarray, grad_external_energy_p: ndarray, kinetic_and_external_energy_hamiltonian: ndarray, coulomb_matrix: ndarray, e_nuc_nuc: float, e_hartree_c: float | None, mol_orbital: Mole, mol_density: Mole, density_fitting: callable, grid: Grids, aos: ndarray | None, aos_torch: Tensor | None, grid_weights: Tensor | None, xc: str, use_torch: bool, use_blocked: bool, max_memory: float, sanity_check_fit: bool = False) tuple[dict, dict, ndarray, dict][source]
Calculates the energies and gradients in the orbital and density basis.
The gradient of the kinetic energy can’t be calculated directly as the previous effective potentials are needed.
- Parameters:
gamma – The density matrix in the orbital basis.
grad_external_energy_c – The gradient of the nuclear attraction energy in the orbital basis.
grad_external_energy_p – The gradient of the nuclear attraction energy in the density basis.
kinetic_and_external_energy_hamiltonian – The one-electron Hamiltonian.
coulomb_matrix – The Coulomb matrix (density basis).
e_nuc_nuc – The nuclear-nuclear repulsion energy.
e_hartree_c – The Hartree energy in the orbital basis (optional). If not provided, it is calculated from the density matrix (this is a bit more expensive since a four index tensor is involved).
mol_orbital – The molecule in the orbital basis.
mol_density – The molecule in the density basis.
density_fitting – The density fitting function.
grid – The integration grid for the XC and APBE functionals.
aos – The atomic orbitals.
aos_torch – The atomic orbitals as a torch tensor.
grid_weights – The weights of the grid.
xc – The exchange-correlation functional.
use_torch – Whether to use the torch implementation of the XC functional.
use_blocked – Whether to use the blocked implementation of the XC functional.
max_memory – The maximum memory for the functionals.
sanity_check_fit – Whether to perform a sanity check (compute l1 norm of density differenceof the density fitting.
- Returns:
A tuple of the KS energies, OF energies, the coefficients in the density basis, and the gradients in the density basis.