density_fitting
Functions to help with density fitting and value and gradient label calculation.
OFDFT uses different atomic basis functions for the density than KSDFT uses for the representation of the orbitals. For the basis transformation the density coefficients in the OFDFT-basis are fitted to the density defined by the orbitals, such that they minimize the error in the Hartree and external Energy of the residual density.
The following definitions are used in the following derivations:
- _check_data_format(results: dict, data_per_iteration: list[dict], mol: Mole) None[source]
- Checks if the data provided by the .chk file contains all the parameters required for the density fitting and that the provided molecule object fits this data dimension wise. - Parameters:
- results – The dict containing the parameters of the ksdft calculation 
- data_per_iteration – List of dicts containing the data of every individual scf-iteration 
- mol – The molecule object providing information about the atoms and the basis set 
 
- Raises:
- KeyError – if one of the required Keys is not inside of the result dict 
- ValueError – if the Number of basis functions in Data and Molecule is different 
 
 
- contract_coulomb_tensor(mol_orbital_basis: Mole, mol_density_basis: Mole, gamma: ndarray | Tensor, max_memory: int | float | None = 4000) Tensor[source]
- Computes the contraction of the 3-center coulomb tensor with the density coefficients in the orbital basis. - Parameters:
- mol_orbital_basis – The molecule in the orbital basis 
- mol_density_basis – The molecule in the density basis 
- gamma – The density coefficients in the orbital basis 
- max_memory – The maximum memory to use per process in MB. 
 
- Returns:
- The contracted coulomb tensor as a numpy array. 
 
- density_fitting_hartree(W_coulomb: ndarray, L_coulomb: ndarray, gamma: ndarray) ndarray[source]
- Constructs the (n_auxmol) tensor which describes a the of-coefficients. The target to optimize is the Hartree energy of the residual density: \[\begin{aligned} \mathcal{L}(\mathbf{p}) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \bar\Gamma \tilde{\mathbf{D}}\bar\Gamma \end{aligned}\]- This is solved by assuming that \(\tilde{W}\) is invertible: \[\begin{split}\begin{aligned} \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma=0\\ \mathbf{p}&=\tilde{W}^{-1}\bar {\tilde L} \bar\Gamma\\ &=\bar{\mathbf{P}} \bar\Gamma \end{aligned}\end{split}\]- Parameters:
- L_overlap – 3-center coulomb matrix 
- W_overlap – 2-center coulomb matrix 
- gamma – coefficients of the density in the orbital basis 
 
- Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - Corresponds to ´´df_coeff´´¸in the MOFDFT implementation. But is probably not used by them. This function is also used to compute the map if one wants to minimize the L2 - norm of the residual density. For this W_coulomb and L_coulomb have to be replaced with W_overlap and L_overlap. 
- density_fitting_hartree_external(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, gamma: ndarray, max_memory: int | float | None = 4000) ndarray[source]
- Constructs the (n_auxmol) tensor which describes a the of-coefficients. The target to optimize is the sum of Hartree energy and external energy of the residual density: \[\begin{aligned} \mathcal{L}(\mathbf{p}) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \bar\Gamma \tilde{\mathbf{D}}\bar\Gamma + (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})^2 \end{aligned}\]- This is solved by assuming that \(A=\tilde{W}+\mathbf{v}_{ext}\mathbf{v}_{ext}^T\) is invertible: \[\begin{split}\begin{aligned} \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + 2\mathbf{v}_{ext}\mathbf{v}_{ext}^T\mathbf{p} - 2\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}\\ &= 2 A \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma - 2\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}=0\\ \mathbf{p}&=A^{-1}\left(\bar {\tilde L}+\mathbf{v}_{ext}\bar{V}_{ext}\right) \bar\Gamma\\ &=\bar{\mathbf{P}} \bar\Gamma \end{aligned}\end{split}\]- Parameters:
- W_coulomb – 2-center coulomb matrix of the of-coefficients 
- L_coulomb – 3-center coulomb matrix of the overlap of ks- and of-coefficients 
- v_external_p – 1 center external potential vector of the of-coefficients 
- v_external_C – 1 center external potential matrix of the ks-coefficients 
- gamma – coefficients of the density in the orbital basis 
- max_memory – The maximum memory to use per process in MB. 
 
- Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - The energy lagragian is mentioned in the [M-OFDFT] paper but the equation they derive does not minimize it. This function depicts the correct solution to the minimization problem. 
- density_fitting_hartree_external_fixed_density(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, basis_integrals: ndarray, n_electrons: ndarray, gamma: ndarray) ndarray[source]
- Constructs the (n_auxmol) tensor which describes a the of-coefficients.
- The target to optimize is the sum of Hartree energy and external energy of the residual density,
- the L1 norm of the density and the external energy are enforced to stay constant after the mapping: 
 
 \[\begin{split}\begin{aligned} \mathcal{L}(\mathbf{p},\mu) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})^2+\mu(\mathbf{p}\mathbf{w}-\bar\Gamma\bar S)\\ \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + 2\mathbf{v}_{ext}(\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})+\mu \mathbf{w}\\ &= 2(\tilde{W}+\mathbf{v}_{ext}\mathbf{v}_{ext}^T) \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + 2\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}+\mu \mathbf{w}= 0\\ \partial_\mu\mathcal{L}&= (\mathbf{p}\mathbf{w}-\bar\Gamma\bar S)=0\\ \end{aligned}\end{split}\]- If we assume that \(A=\tilde{W}+\mathbf{v}_{ext}\mathbf{v}_{ext}^T\) is invertible \[\begin{split}\begin{aligned} \mathbf{w}A^{-1}\partial_{\mathbf p}\mathcal L&= 2 \mathbf{w}\mathbf{p}-2 \mathbf{w}A^{-1}\bar {\tilde L} \bar\Gamma-2\mathbf{w}A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext} + \mu \mathbf{w}A^{-1}\mathbf{w}\\ &=2\bar\Gamma\bar S -2 \mathbf{w}A^{-1}\bar {\tilde L} \bar\Gamma-2\mathbf{w}A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext} + \mu \mathbf{w}A^{-1}\mathbf{w}=0\\ \mu &= 2\frac{-\bar\Gamma\bar S + \mathbf{w}A^{-1}\bar {\tilde L} \bar\Gamma+\mathbf{w}A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}}{\mathbf{w}A^{-1}\mathbf{w}}\\ &=2\frac{\mathbf{w}A^{-1}\bar {\tilde L} +\mathbf{w}A^{-1}\mathbf{v}_{ext} \bar{V}_{ext}-\bar S}{\mathbf{w}A^{-1}\mathbf{w}}\bar\Gamma\\ \partial_{\mathbf p}\mathcal L&= 2A\mathbf{p}- 2 \bar {\tilde L} \bar\Gamma - 2\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}+\mu \mathbf{w}=0\\ \Leftrightarrow\mathbf p&=A^{-1}\bar {\tilde L} \bar\Gamma + A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}-\frac{1}{2}\mu A^{-1}\mathbf{w}\\ &=A^{-1}\bar {\tilde L} \bar\Gamma + A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}- A^{-1}\mathbf{w}\frac{\mathbf{w}A^{-1}\bar {\tilde L} +\mathbf{w}A^{-1}\mathbf{v}_{ext} \bar{V}_{ext}-\bar S}{\mathbf{w}A^{-1}\mathbf{w}}\bar\Gamma\\ &=A^{-1}\left(\bar {\tilde L} + \mathbf{v}_{ext} \bar{V}_{ext}- \mathbf{w}\frac{\mathbf{w}A^{-1}\bar {\tilde L} +\mathbf{w}A^{-1}\mathbf{v}_{ext} \bar{V}_{ext}-\bar S}{\mathbf{w}A^{-1}\mathbf{w}}\right)\bar\Gamma\\ &= \bar {\mathbf{P}}\bar\Gamma \end{aligned}\end{split}\]- Where \(\bar{\mathbf{P}}\) is a three index tensor only dependent on the geometry of the molecule. - Parameters:
- W_coulomb – 2-center overlap matrix 
- L_coulomb – 3-center overlap matrix 
- basis_integrals – integrals over the basis functions 
- v_external_p – the density coefficients of the external potential 
- v_external_C – the orbital coefficients of the external potential 
- overlap_matrix – 2-center overlap matrix 
- gamma – coefficients of the density in the orbital basis 
 
- Returns:
- the density coefficients in the new space 
- Return type:
- \(\bar{\mathbf{P}}\) 
 
- density_fitting_hartree_fixed_density_external(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, basis_integrals: ndarray, n_electrons: ndarray, gamma: ndarray) ndarray[source]
- Constructs the (n_auxmol) tensor which describes a the of-coefficients. The target to optimize is the Hartree energy of the residual density, the L1 norm of the density and the external energy are enforced to stay constant after the mapping: \[\begin{split}\begin{aligned} \mathcal{L}(\mathbf{p},\mu,\nu) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \nu(\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})+\mu(\mathbf{p}\mathbf{w}-\bar\Gamma\bar S)\\ \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + \nu\mathbf{v}_{ext}+\mu \mathbf{w}= 0\\ \partial_\mu\mathcal{L}&= (\mathbf{p}\mathbf{w}-\bar\Gamma\bar S)=0\\ \partial_\nu\mathcal{L}&= (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})=0\\ \end{aligned}\end{split}\]- If we assume that \(A=\tilde{W}\) is invertible \[\begin{split}\begin{aligned} \mathbf{w}\tilde W^{-1}\partial_{\mathbf p}\mathcal L&= 2 \mathbf{w}\mathbf{p}-2 \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma+\nu\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext} + \mu \mathbf{w}\tilde W^{-1}\mathbf{w}\\ &=2\bar\Gamma\bar S -2 \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma+\nu\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext} + \mu \mathbf{w}\tilde W^{-1}\mathbf{w}=0\\ \mu &= 2\frac{\bar\Gamma\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{w}\tilde W^{-1}\mathbf{w}}+\nu\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{w}\tilde W^{-1}\mathbf{w}}\\ \mathbf{v}_{ext}\tilde W^{-1}\partial_{\mathbf p}\mathcal L&= 2 \mathbf{v}_{ext}\mathbf{p}-2 \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma+\nu\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext} + \mu \mathbf{v}_{ext}\tilde W^{-1}\mathbf{w}\\ &=2\bar\Gamma \bar{V}_{ext} -2 \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma+\nu\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext} + \mu \mathbf{v}_{ext}\tilde W^{-1}\mathbf{w}=0\\ \nu &= 2\frac{\bar\Gamma \bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}+\mu\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}\\ &= 2\frac{\bar\Gamma \bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}+\left(2\frac{\bar\Gamma\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{w}\tilde W^{-1}\mathbf{w}}+\nu\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{w}\tilde W^{-1}\mathbf{w}}\right)\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}\\ \nu\left(1-\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{w}\tilde W^{-1}\mathbf{w}}\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}\right)&= -2\frac{\bar\Gamma \bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}+2\frac{\bar\Gamma\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{w}\tilde W^{-1}\mathbf{w}}\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}\\ \nu\left(\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}-(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2\right)&= -2\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\left(\bar\Gamma \bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma\right)+2\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}\left(\bar\Gamma\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma\right)\\ \nu&= 2\frac{-\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\left(\bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L}\right)+\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}\left(\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L}\right)}{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}-(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2}\bar\Gamma\\ \mu&= 2\frac{-\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}\cdot\left(\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \right)+\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}\left( \bar{V}_{ext}- \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \right)}{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}-(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2}\bar\Gamma\\ \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + \nu\mathbf{v}_{ext}+\mu \mathbf{w}= 0\\ \Leftrightarrow\mathbf{p} &= \tilde W^{-1}\bar {\tilde L} \bar\Gamma - \frac{1}{2}\nu\tilde W^{-1}\mathbf{v}_{ext}-\frac{1}{2}\mu \tilde W^{-1}\mathbf{w}\\ &= \tilde W^{-1}\left(\bar {\tilde L} - \mathbf{v}_{ext}\frac{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\left(\bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L}\right)+\left(\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L}\right)}{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}+(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2}-\mathbf{w}\frac{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}\cdot\left(\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \right)+\left( \bar{V}_{ext}- \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \right)}{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}+(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2}\right)\bar\Gamma\\ &= \bar{\mathbf{P}}\bar\Gamma\\ \end{aligned}\end{split}\]- Where \(\bar{\mathbf{P}}\) is a three index tensor only dependent on the geometry of the molecule. - Parameters:
- W_coulomb – 2-center overlap matrix 
- L_coulomb – 3-center overlap matrix 
- basis_integrals – integrals over the basis functions 
- v_external_p – the density coefficients of the external potential 
- v_external_C – the orbital coefficients of the external potential 
- overlap_matrix – 2-center overlap matrix 
- gamma – coefficients of the density in the orbital basis 
 
- Returns:
- the density coefficients in the new space 
- Return type:
- \(\bar{\mathbf{P}}\) 
 
- density_fitting_mofdft(mol_orbital_basis, mol_density_basis, W_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, gamma: ndarray, max_memory: int | float | None = 4000) ndarray[source]
- Constructs the (n_auxmol) tensor which describes a the of-coefficients. The target to optimize is mentioned as the sum of the Hartree energy of the residual density and the external energy: \[\begin{aligned} \mathcal{L}(\mathbf{p}) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \bar\Gamma \tilde{\mathbf{D}}\bar\Gamma + (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})^2 \end{aligned}\]- But the following equation does not necessarily minimizes this Energy function. \[\begin{split}\left(\begin{array}{c}\tilde{W}\\v_{ext}^T\end{array}\right) \mathbf{p} = \left(\begin{array}{c}\tilde{L} \bar{\Gamma} \\ \bar{\Gamma}\bar{V}_{ext}\end{array}\right)\end{split}\]- It is solved using least squares methods. :param mol_orbital_basis: The molecule in the orbital basis :param mol_density_basis: The molecule in the density basis :param W_coulomb: 2-center coulomb matrix of the of-coefficients :param v_external_p: 1 center external potential vector of the of-coefficients :param v_external_C: 1 center external potential matrix of the ks-coefficients :param gamma: coefficients of the density in the orbital basis :param max_memory: The maximum memory to use per process in MB. - Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - The energy Lagragian is mentioned in the [M-OFDFT] paper but the equation derived does not minimize it. Called - df_coeff_jextin the MOFDFT ìmplementation. This is the method mentioned [M-OFDFT] mention to use in their implementation.
- density_fitting_mofdft_enforced_density(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, basis_integrals: ndarray, overlap_matrix: ndarray, gamma: ndarray) ndarray[source]
- Constructs the (n_auxmol) tensor which describes the of-coefficients. - The target to optimize is mentioned as the sum of the Hartree energy of the residual density and the external energy modified and also to enforce density conversation. The minimized lagrangian is defined as follows: \[\begin{split}\begin{aligned} \mathcal{L}(\mathbf{p}) &= \left\lVert\left(\begin{array}{c}\tilde{W}\\v_{ext}^T\end{array}\right) \mathbf{p} - \left(\begin{array}{c}\tilde{L} \bar{\Gamma} \\ \bar{\Gamma}\bar{V}_{ext}\end{array}\right)\right\rVert^2 + \lambda (\mathbf{w}\mathbf{p}-N) \end{aligned}\end{split}\]- This is solved by the following equation and least squares methods. \[\begin{split}\begin{aligned} \mathbf{\tilde{p}} &= \text{argmin} \left\lVert\left(\begin{array}{c}\tilde{W}\\v_{ext}^T\end{array}\right) \mathbf{p} - \left(\begin{array}{c}\tilde{L} \bar{\Gamma} \\ \bar{\Gamma}\bar{V}_{ext}\end{array}\right)\right\rVert^2 \mathbf{M} &= \left(\begin{array}{c}\tilde{W}\\v_{ext}^T\end{array}\right)^T\left(\begin{array}{c}\tilde{W}\\v_{ext}^T\end{array}\right) \mathbf{p} &= \mathbf{\tilde{p}} - \frac{\mathbf{w\tilde{p}}-N}{\mathbf{w}\mathbf{M}^{-1}\mathbf{w}}\mathbf{M}^{-1}\mathbf{w} \end{aligned}\end{split}\]- It is solved using least squares methods. - Parameters:
- L_overlap – 3-center coulomb matrix of the overlap of ks- and of-coefficients 
- W_overlap – 2-center coulomb matrix of the of-coefficients 
- v_external_p – 1 center external potential vector of the of-coefficients 
- v_external_C – 1 center external potential matrix of the ks-coefficients 
- gamma – coefficients of the density in the orbital basis 
 
- Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - This is a modification of the mofdft version of density fitting which enforces the conservation of the electron number. 
- density_fitting_mofdft_fixed_density(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, basis_integrals: ndarray, n_electrons: ndarray, gamma: ndarray) ndarray[source]
- Constructs the (n_auxmol) tensor which describes a the of-coefficients. The target to optimize is mentioned as the sum of the Hartree energy of the residual density and the external energy as well as the differences in L1 norm of the density: \[\begin{aligned} \mathcal{L}(\mathbf{p}) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \bar\Gamma \tilde{\mathbf{D}}\bar\Gamma + (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})^2 + (\mathbf{p}\mathbf{w}-\bar\Gamma \bar{S})^2 \end{aligned}\]- But the following equation does not necessarily minimizes this Energy function. \[\begin{split}\left(\begin{array}{c}\tilde{W}\\\mathbf{v}_{ext}^T\\\mathbf{w}^T\end{array}\right) \mathbf{p} = \left(\begin{array}{c}\tilde{L} \bar{\Gamma} \\ \bar{\Gamma}\bar{V}_{ext}\\\bar S\bar \Gamma\end{array}\right)\end{split}\]- It is solved using least squares methods. :param L_overlap: 3-center coulomb matrix of the overlap of ks- and of-coefficients :param W_overlap: 2-center coulomb matrix of the of-coefficients :param v_external_p: 1 center external potential vector of the of-coefficients :param v_external_C: 1 center external potential matrix of the ks-coefficients :param basis_integrals: 1 center integrals over the basis functions of the of basis :param overlap_matrix: 1 center intergrals over products of the basis functions of the ks-basis :param gamma: coefficients of the density in the orbital basis - Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - The energy Lagragian is not mentioned in [M-OFDFT] , but it is implemented in the MOFDFT Github project. Called - get_rho_coeff_jextnelec_fitin the MOFDFT ìmplementation.
- density_fitting_mofdft_torch(mol_orbital_basis: Mole, mol_density_basis: Mole, W_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, gamma: Tensor, max_memory: int | float | None = 4000) Tensor[source]
- Same as - density_fitting_mofdft(), but using torch (backpropagatable)- Parameters:
- W_coulomb – 2-center coulomb matrix of the of-coefficients 
- contracted_coulomb_tensor – The contracted coulomb tensor 
- v_external_p – 1 center external potential vector of the of-coefficients 
- v_external_C – 1 center external potential matrix of the ks-coefficients 
- gamma – coefficients of the density in the orbital basis 
- max_memory – The maximum memory to use per process in MB. 
 
 
- density_fitting_mol(gamma: ndarray, mol_orbital: Mole, mol_density: Mole, method='hartree+external_mofdft') ndarray[source]
- Calculates all needed basis integrals and returns density coefficients. - This is a wrapper around - density_fitting()which calculates the necessary integrals given the molecule objects and the density matrix in the orbital basis.- Parameters:
- gamma – the density matrix in the orbital basis 
- mol_orbital – the molecule object containing information about the orbital basis 
- mol_rho – the molecule object containing information about the density basis 
 
- Returns:
- the density coefficients in the density basis 
- Return type:
- coeffs 
- Raises:
- AssertionError – if the two molecule geometries are not the same 
- AssertionError – if the number of electrons is not conserved 
 
 
- get_KSDFT_Hartree_potential(mol: Mole, gamma: ndarray, hermitian: int = 1, **kwargs) ndarray[source]
- Wrapper around the get_j function from pyscf which returns the potential matrix for the Hartree potential. Necessary for checking the quality of the density optimisation. \[J_{\alpha,\beta} = (\eta_\alpha \eta_\beta,\eta_\gamma\eta_\delta) \Gamma_{\gamma,\delta}\]- Parameters:
- mol – The Molecule object which contains information over the used basis 
- gamma – the density matrix in the orbital basis 
- kwargs – keyword arguments passed to pyscf.dft.RKS.get_j 
- hermitian – whether the matrix is hermitian (0: no symmetry, 1: hermitian, -1: anti-hermitian) 
 
- Returns:
- the hartree potential in the orbital basis shape (n_b,n_b) 
- Return type:
- v_hart 
 
- get_density_fitting_function(method_name: str, mol_orbital_basis: Mole, mol_density_basis: Mole, W_coulomb: ndarray, v_external_C: ndarray, v_external_p: ndarray, max_memory: int | float | None = 4000) Callable[[ndarray], ndarray][source]
- Return a Python function density_fitting(gamma: np.ndarray) -> np.ndarray which transforms the density coefficients in the orbital basis into the coefficients in the orbital free basis according to a specified method. \[p^i = \mathbf{P}^i_{jk}\Gamma^{jk}\]- Parameters:
- method_name – The name of the method used to calculate the density fitting 
- mol_orbital_basis – The molecule in the orbital basis 
- mol_density_basis – The molecule in the density basis 
- W_coulomb – 2-center coulomb matrix 
- v_external_p – 1 center external potential vector of the of-coefficients 
- v_external_C – 1 center external potential matrix of the ks-coefficients 
- max_memory – The maximum memory to use per process in MB. 
 
 - The tensor is based on the method to choose the coefficients such that they optimize a target. 
- get_density_fitting_map(method_name: str, mol_orbital_basis: Mole, mol_density_basis: Mole, W_coulomb: ndarray, L_coulomb: ndarray, v_external_C: ndarray, v_external_p: ndarray) ndarray[source]
- Constructs the (n_auxmol,n_mol,n_mol) tensor which describes a linear map from ks-to of- coefficients. \[p^i = \mathbf{P}^i_{jk}\Gamma^{jk}\]- The tensor is based on the method to choose the coefficients such that they optimize a target. The advantage on calculation the linear map from old to new coefficients is that the leased square functions has only to be evaluated once for all iterations, but calculating the map takes way longer than calculating a single coefficient. Only worth it if there are very many coefficients to transform for a single molecule. 
- get_density_fitting_map_hartree(W_coulomb: ndarray, L_coulomb: ndarray) ndarray[source]
- Constructs the (n_auxmol,n_mol,n_mol) tensor which describes a linear map from ks-to of-coefficients. The target to optimize is the Hartree energy of the residual density: \[\begin{aligned} \mathcal{L}(\mathbf{p}) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \bar\Gamma \tilde{\mathbf{D}}\bar\Gamma \end{aligned}\]- This is solved by assuming that \(\tilde{W}\) is invertible: \[\begin{split}\begin{aligned} \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma=0\\ \mathbf{p}&=\tilde{W}^{-1}\bar {\tilde L} \bar\Gamma\\ &=\bar{\mathbf{P}} \bar\Gamma \end{aligned}\end{split}\]- Parameters:
- L_overlap – 3-center coulomb matrix 
- W_overlap – 2-center coulomb matrix 
 
- Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - Corresponds to ´´df_coeff´´¸in the MOFDFT implementation. But is probably not used by them. This function is also used to compute the map if one wants to minimize the L2 - norm of the residual density. For this W_coulomb and L_coulomb have to be replaced with W_overlap and L_overlap. 
- get_density_fitting_map_hartree_external(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray) ndarray[source]
- Constructs the (n_auxmol,n_mol,n_mol) tensor which describes a linear map from ks-to of-coefficients. The target to optimize is the sum of Hartree energy and external energy of the residual density: \[\begin{aligned} \mathcal{L}(\mathbf{p}) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \bar\Gamma \tilde{\mathbf{D}}\bar\Gamma + (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})^2 \end{aligned}\]- This is solved by assuming that \(A=\tilde{W}+\mathbf{v}_{ext}\mathbf{v}_{ext}^T\) is invertible: \[\begin{split}\begin{aligned} \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + 2\mathbf{v}_{ext}\mathbf{v}_{ext}^T\mathbf{p} - 2\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}\\ &= 2 A \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma - 2\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}=0\\ \mathbf{p}&=A^{-1}\left(\bar {\tilde L}+\mathbf{v}_{ext}\bar{V}_{ext}\right) \bar\Gamma\\ &=\bar{\mathbf{P}} \bar\Gamma \end{aligned}\end{split}\]- Parameters:
- L_overlap – 3-center coulomb matrix of the overlap of ks- and of-coefficients 
- W_overlap – 2-center coulomb matrix of the of-coefficients 
- v_external_p – 1 center external potential vector of the of-coefficients 
- v_external_C – 1 center external potential matrix of the ks-coefficients 
 
- Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - The energy lagragian is mentioned in the [M-OFDFT] paper but the equation they derive does not minimize it. This function depicts the correct solution to the minimization problem. 
- get_density_fitting_map_hartree_external_fixed_density(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, basis_integrals: ndarray, overlap_matrix: ndarray) ndarray[source]
- Constructs the (n_auxmol,n_mol,n_mol) tensor which describes a linear map from ks-to of-coefficients.
- The target to optimize is the sum of Hartree energy and external energy of the residual density,
- the L1 norm of the density and the external energy are enforced to stay constant after the mapping: 
 
 \[\begin{split}\begin{aligned} \mathcal{L}(\mathbf{p},\mu) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})^2+\mu(\mathbf{p}\mathbf{w}-\bar\Gamma\bar S)\\ \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + 2\mathbf{v}_{ext}(\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})+\mu \mathbf{w}\\ &= 2(\tilde{W}+\mathbf{v}_{ext}\mathbf{v}_{ext}^T) \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + 2\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}+\mu \mathbf{w}= 0\\ \partial_\mu\mathcal{L}&= (\mathbf{p}\mathbf{w}-\bar\Gamma\bar S)=0\\ \end{aligned}\end{split}\]- If we assume that \(A=\tilde{W}+\mathbf{v}_{ext}\mathbf{v}_{ext}^T\) is invertible \[\begin{split}\begin{aligned} \mathbf{w}A^{-1}\partial_{\mathbf p}\mathcal L&= 2 \mathbf{w}\mathbf{p}-2 \mathbf{w}A^{-1}\bar {\tilde L} \bar\Gamma-2\mathbf{w}A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext} + \mu \mathbf{w}A^{-1}\mathbf{w}\\ &=2\bar\Gamma\bar S -2 \mathbf{w}A^{-1}\bar {\tilde L} \bar\Gamma-2\mathbf{w}A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext} + \mu \mathbf{w}A^{-1}\mathbf{w}=0\\ \mu &= 2\frac{-\bar\Gamma\bar S + \mathbf{w}A^{-1}\bar {\tilde L} \bar\Gamma+\mathbf{w}A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}}{\mathbf{w}A^{-1}\mathbf{w}}\\ &=2\frac{\mathbf{w}A^{-1}\bar {\tilde L} +\mathbf{w}A^{-1}\mathbf{v}_{ext} \bar{V}_{ext}-\bar S}{\mathbf{w}A^{-1}\mathbf{w}}\bar\Gamma\\ \partial_{\mathbf p}\mathcal L&= 2A\mathbf{p}- 2 \bar {\tilde L} \bar\Gamma - 2\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}+\mu \mathbf{w}=0\\ \Leftrightarrow\mathbf p&=A^{-1}\bar {\tilde L} \bar\Gamma + A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}-\frac{1}{2}\mu A^{-1}\mathbf{w}\\ &=A^{-1}\bar {\tilde L} \bar\Gamma + A^{-1}\mathbf{v}_{ext}\bar\Gamma \bar{V}_{ext}- A^{-1}\mathbf{w}\frac{\mathbf{w}A^{-1}\bar {\tilde L} +\mathbf{w}A^{-1}\mathbf{v}_{ext} \bar{V}_{ext}-\bar S}{\mathbf{w}A^{-1}\mathbf{w}}\bar\Gamma\\ &=A^{-1}\left(\bar {\tilde L} + \mathbf{v}_{ext} \bar{V}_{ext}- \mathbf{w}\frac{\mathbf{w}A^{-1}\bar {\tilde L} +\mathbf{w}A^{-1}\mathbf{v}_{ext} \bar{V}_{ext}-\bar S}{\mathbf{w}A^{-1}\mathbf{w}}\right)\bar\Gamma\\ &= \bar {\mathbf{P}}\bar\Gamma \end{aligned}\end{split}\]- Where \(\bar{\mathbf{P}}\) is a three index tensor only dependent on the geometry of the molecule. - Parameters:
- W_coulomb – 2-center overlap matrix 
- L_coulomb – 3-center overlap matrix 
- basis_integrals – integrals over the basis functions 
- v_external_p – the density coefficients of the external potential 
- v_external_C – the orbital coefficients of the external potential 
- overlap_matrix – 2-center overlap matrix 
 
- Returns:
- the density coefficients in the new space 
- Return type:
- \(\bar{\mathbf{P}}\) 
 
- get_density_fitting_map_hartree_fixed_density_external(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, basis_integrals: ndarray, overlap_matrix: ndarray) ndarray[source]
- Constructs the (n_auxmol,n_mol,n_mol) tensor which describes a linear map from ks-to of-coefficients. The target to optimize is the Hartree energy of the residual density, the L1 norm of the density and the external energy are enforced to stay constant after the mapping: \[\begin{split}\begin{aligned} \mathcal{L}(\mathbf{p},\mu,\nu) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \nu(\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})+\mu(\mathbf{p}\mathbf{w}-\bar\Gamma\bar S)\\ \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + \nu\mathbf{v}_{ext}+\mu \mathbf{w}= 0\\ \partial_\mu\mathcal{L}&= (\mathbf{p}\mathbf{w}-\bar\Gamma\bar S)=0\\ \partial_\nu\mathcal{L}&= (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})=0\\ \end{aligned}\end{split}\]- If we assume that \(A=\tilde{W}\) is invertible \[\begin{split}\begin{aligned} \mathbf{w}\tilde W^{-1}\partial_{\mathbf p}\mathcal L&= 2 \mathbf{w}\mathbf{p}-2 \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma+\nu\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext} + \mu \mathbf{w}\tilde W^{-1}\mathbf{w}\\ &=2\bar\Gamma\bar S -2 \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma+\nu\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext} + \mu \mathbf{w}\tilde W^{-1}\mathbf{w}=0\\ \mu &= 2\frac{\bar\Gamma\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{w}\tilde W^{-1}\mathbf{w}}+\nu\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{w}\tilde W^{-1}\mathbf{w}}\\ \mathbf{v}_{ext}\tilde W^{-1}\partial_{\mathbf p}\mathcal L&= 2 \mathbf{v}_{ext}\mathbf{p}-2 \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma+\nu\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext} + \mu \mathbf{v}_{ext}\tilde W^{-1}\mathbf{w}\\ &=2\bar\Gamma \bar{V}_{ext} -2 \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma+\nu\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext} + \mu \mathbf{v}_{ext}\tilde W^{-1}\mathbf{w}=0\\ \nu &= 2\frac{\bar\Gamma \bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}+\mu\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}\\ &= 2\frac{\bar\Gamma \bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}+\left(2\frac{\bar\Gamma\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{w}\tilde W^{-1}\mathbf{w}}+\nu\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{w}\tilde W^{-1}\mathbf{w}}\right)\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}\\ \nu\left(1-\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{w}\tilde W^{-1}\mathbf{w}}\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}\right)&= -2\frac{\bar\Gamma \bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}+2\frac{\bar\Gamma\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma}{\mathbf{w}\tilde W^{-1}\mathbf{w}}\frac{\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}}{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}}\\ \nu\left(\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}-(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2\right)&= -2\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\left(\bar\Gamma \bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \bar\Gamma\right)+2\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}\left(\bar\Gamma\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \bar\Gamma\right)\\ \nu&= 2\frac{-\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\left(\bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L}\right)+\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}\left(\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L}\right)}{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}-(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2}\bar\Gamma\\ \mu&= 2\frac{-\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}\cdot\left(\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \right)+\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext}\left( \bar{V}_{ext}- \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \right)}{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}-(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2}\bar\Gamma\\ \partial_{\mathbf p}\mathcal L&= 2\tilde{W} \mathbf{p}- 2 \bar {\tilde L} \bar\Gamma + \nu\mathbf{v}_{ext}+\mu \mathbf{w}= 0\\ \Leftrightarrow\mathbf{p} &= \tilde W^{-1}\bar {\tilde L} \bar\Gamma - \frac{1}{2}\nu\tilde W^{-1}\mathbf{v}_{ext}-\frac{1}{2}\mu \tilde W^{-1}\mathbf{w}\\ &= \tilde W^{-1}\left(\bar {\tilde L} - \mathbf{v}_{ext}\frac{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\left(\bar{V}_{ext} - \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L}\right)+\left(\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L}\right)}{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}+(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2}-\mathbf{w}\frac{\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}\cdot\left(\bar S - \mathbf{w}\tilde W^{-1}\bar {\tilde L} \right)+\left( \bar{V}_{ext}- \mathbf{v}_{ext}\tilde W^{-1}\bar {\tilde L} \right)}{\mathbf{w}\tilde W^{-1}\mathbf{w}\cdot\mathbf{v}_{ext}\tilde W^{-1}\mathbf{v}_{ext}+(\mathbf{w}\tilde W^{-1}\mathbf{v}_{ext})^2}\right)\bar\Gamma\\ &= \bar{\mathbf{P}}\bar\Gamma\\ \end{aligned}\end{split}\]- Where \(\bar{\mathbf{P}}\) is a three index tensor only dependent on the geometry of the molecule. - Parameters:
- W_coulomb – 2-center overlap matrix 
- L_coulomb – 3-center overlap matrix 
- basis_integrals – integrals over the basis functions 
- v_external_p – the density coefficients of the external potential 
- v_external_C – the orbital coefficients of the external potential 
- overlap_matrix – 2-center overlap matrix 
 
- Returns:
- the density coefficients in the new space 
- Return type:
- \(\bar{\mathbf{P}}\) 
 
- get_density_fitting_map_mofdft(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray) ndarray[source]
- Constructs the (n_auxmol,n_mol,n_mol) tensor which describes a linear map from ks-to of-coefficients. The target to optimize is mentioned as the sum of the Hartree energy of the residual density and the external energy: \[\begin{aligned} \mathcal{L}(\mathbf{p}) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \bar\Gamma \tilde{\mathbf{D}}\bar\Gamma + (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})^2 \end{aligned}\]- But the following equation does not necessarily minimize this Energy function. \[\begin{split}\left(\begin{array}{c}\tilde{W}\\v_{ext}^T\end{array}\right) \mathbf{p} = \left(\begin{array}{c}\tilde{L} \bar{\Gamma} \\ \bar{\Gamma}\bar{V}_{ext}\end{array}\right)\end{split}\]- It is solved using least squares methods. - Parameters:
- L_overlap – 3-center coulomb matrix of the overlap of ks- and of-coefficients 
- W_overlap – 2-center coulomb matrix of the of-coefficients 
- v_external_p – 1 center external potential vector of the of-coefficients 
- v_external_C – 1 center external potential matrix of the ks-coefficients 
 
- Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - The energy Lagragian is mentioned in the [M-OFDFT] paper but the equation derived does not minimize it. Called - df_coeff_jextin the MOFDFT ìmplementation. This is the method mentioned [M-OFDFT] mention to use in their implementation.
- get_density_fitting_map_mofdft_fixed_density(W_coulomb: ndarray, L_coulomb: ndarray, v_external_p: ndarray, v_external_C: ndarray, basis_integrals: ndarray, overlap_matrix: ndarray) ndarray[source]
- Constructs the (n_auxmol,n_mol,n_mol) tensor which describes a linear map from ks-to of-coefficients. The target to optimize is mentioned as the sum of the Hartree energy of the residual density and the external energy as well as the differences in L1 norm of the density: \[\begin{aligned} \mathcal{L}(\mathbf{p}) &= \mathbf{p} \tilde{W} \mathbf{p} - 2 \mathbf{p}\bar {\tilde L} \bar\Gamma + \bar\Gamma \tilde{\mathbf{D}}\bar\Gamma + (\mathbf{p}\mathbf{v}_{ext}-\bar\Gamma \bar{V}_{ext})^2 + (\mathbf{p}\mathbf{w}-\bar\Gamma \bar{S})^2 \end{aligned}\]- But the following equation does not necessarily minimizes this Energy function. \[\begin{split}\left(\begin{array}{c}\tilde{W}\\\mathbf{v}_{ext}^T\\\mathbf{w}^T\end{array}\right) \mathbf{p} = \left(\begin{array}{c}\tilde{L} \bar{\Gamma} \\ \bar{\Gamma}\bar{V}_{ext}\\\bar S\bar \Gamma\end{array}\right)\end{split}\]- It is solved using least squares methods. :param L_overlap: 3-center coulomb matrix of the overlap of ks- and of-coefficients :param W_overlap: 2-center coulomb matrix of the of-coefficients :param v_external_p: 1 center external potential vector of the of-coefficients :param v_external_C: 1 center external potential matrix of the ks-coefficients :param basis_integrals: 1 center integrals over the basis functions of the of basis :param overlap_matrix: 1 center intergrals over products of the basis functions of the ks-basis - Returns:
- the 3-index tensor which maps Gamma to p 
- Return type:
- P 
 - Notes - The energy Lagragian is not mentioned in [M-OFDFT] , but it is implemented in the MOFDFT Github project. Called - get_rho_coeff_jextnelec_fitin the MOFDFT ìmplementation.
- ksdft_density_matrix(molecular_orbital_coefficients: T, occupation_numbers: T) T[source]
- Calculates the density matrix from the coefficients of the molecular orbitals. - The molecular orbitals are given by \(| \phi_i \rangle = \sum_{\alpha} C_{\alpha i} | \eta_ \alpha \rangle\). The density matrix is then calculated as \[\Gamma_{ \alpha \beta} = \sum_{i=1}^{n_{MO}} n_i C_{\alpha i} C_{i \beta}^\dagger,\]- where \(n_i\) are the occupation numbers of the orbital \(\phi_i\). In restricted KS, \(n_i = 2\) for occupied orbitals and \(n_i = 0\) for unoccupied orbitals. - Parameters:
- molecular_orbital_coefficients – the coefficients of the orbitals in the basis 
- occupation_numbers – the occupation number of the orbitals 
 
- Returns:
- the density matrix in the orbital basis 
- Return type:
- gamma