Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Density Fitting basis generator #281

Merged
merged 54 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f399f09
DFBS generator can compute products of primitive AO functions
kshitij-05 Nov 14, 2023
6f0583a
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 Nov 14, 2023
f86a3fc
implemented pivoted cholesky algorithm and addressed comments
kshitij-05 Nov 17, 2023
b6d8b50
removed unnecessary typedefs and used std::tgamma
kshitij-05 Nov 17, 2023
74cf2fc
DFBasisSetGenerator produces reduced set of shells using pivoted chol…
kshitij-05 Nov 17, 2023
c2f1dac
DFBasisSetGenerator return a reduced BasisSet, updated hartree-fock++…
kshitij-05 Nov 17, 2023
7d43e26
refactored `uncontract()` function from `basis.h.in` to `shell.h`
kshitij-05 Nov 17, 2023
2cea2c4
increased supported `with-eri3-max-am` to 13
kshitij-05 Nov 17, 2023
56801c3
bugfix: `uncontract()` is in 'libint2::detail'
kshitij-05 Nov 17, 2023
1473522
added dox for `DFBasisGenerator`, made `reduced_basis()` return const…
kshitij-05 Nov 17, 2023
b62e2fa
`uncontract()` refactored back to `dfbs_generator.h` because its not …
kshitij-05 Nov 17, 2023
0d243c6
bugfix: `hartree-fock++` btas tensor def if btas provided
kshitij-05 Nov 18, 2023
49d1667
used && in range based for loop
kshitij-05 Nov 19, 2023
2d45d69
non-templated functions in headers are now inline
kshitij-05 Nov 20, 2023
bdf7c47
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 Nov 20, 2023
c4886a7
`DFBasisGenerator` generates density fitting basis set for one atom n…
kshitij-05 Nov 21, 2023
aeaf535
`DFBasisGenerator` generates density fitting basis set for one atom n…
kshitij-05 Nov 21, 2023
1492d0f
Merge remote-tracking branch 'origin/kshitij/feature/dfbs_generator' …
kshitij-05 Nov 21, 2023
7025626
Bugfix: `DFBasisGenerator.reduced_basis()` will not return NULL basis
kshitij-05 Nov 22, 2023
bdce06c
switched from deducing size type by `auto` to explicit `size_t`
kshitij-05 Nov 22, 2023
cb04647
reformatted code in `bfbs_generator.h` and `pivoted_cholesky.h`
kshitij-05 Nov 23, 2023
aca6d34
libint initialized before computing integrals in `hartree-fock++.cc`
kshitij-05 Nov 23, 2023
7a6fc5b
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 Nov 24, 2023
62ceda3
reformatted code in `dfbs_generator.h` and `pivoted_cholesky.h` with …
kshitij-05 Nov 25, 2023
6640567
bugfix: if only one product shell exist for an `L` then is included i…
kshitij-05 Nov 25, 2023
0884613
clang-format: reformat to resolve merge conflict
kshitij-05 Nov 26, 2023
68d4109
removed unnecessary empty file, removed passing copies as arguments
kshitij-05 Nov 27, 2023
0b6a961
use `const auto` for `const` variables, and bumped up eri2 available …
kshitij-05 Dec 14, 2023
527be9e
added unit test for `DFBasisGenerator`
kshitij-05 Jan 15, 2024
e272283
`DFBasisGenerator` uses FD occupation number as importance factor
kshitij-05 Jan 18, 2024
78fb30d
generalized weights handeling in `DFBasisGenerator` with` std::tuple<…
kshitij-05 Jan 23, 2024
77bfe57
merge master
kshitij-05 Jan 23, 2024
4343994
revert `DFBasisGenerator` back to basic cholesky implementation
kshitij-05 Jan 24, 2024
48ab8d9
removed function overload of `shell_pivoted_cholesky`
kshitij-05 Jan 24, 2024
43e79c0
enabled '--with-eri2' in CI configuration
kshitij-05 Jan 25, 2024
a3e73c5
to use autoDF `hartree-fock++.cc` uses `autodf(chol_tol)` as command …
kshitij-05 Jan 25, 2024
8f817d4
CI configures with `--enable-eri2=1`
kshitij-05 Jan 25, 2024
ad9164f
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 Feb 6, 2024
5d551bb
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 Feb 12, 2024
580ac6b
cleanup and dox fixes in `dfbs_generator.h`
kshitij-05 Feb 12, 2024
ecf3343
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 Feb 12, 2024
8665657
revert changes to ci configuration to compute 1st order derivatives o…
kshitij-05 Feb 12, 2024
1c239c4
revert changes to ci configuration to compute 1st order derivatives o…
kshitij-05 Feb 12, 2024
f8d117b
Merge remote-tracking branch 'origin/kshitij/feature/dfbs_generator' …
kshitij-05 Feb 12, 2024
3f0f729
renamed `shell_pivoted_cholesky()` to `pivoted_cholesky_in_L()`
kshitij-05 Feb 14, 2024
7f2bbd7
use `\f$` to embed LaTeX into dox of `DFBasisSetGenerator` and define…
kshitij-05 Feb 22, 2024
cbe5144
can configure with `--with-eri3-max-am=12` and `--with-eri2-max-am=12`
kshitij-05 Feb 22, 2024
e8b9b0e
[skip ci] dox++
evaleev Mar 4, 2024
8ca8948
C -> C++ headers
evaleev Mar 4, 2024
e9c577d
factorials and related quantities are computed in a safer manner, wit…
kshitij-05 Feb 23, 2024
c02797c
LIBINT_HARD_MAX_AM appears in config.h
evaleev Mar 4, 2024
c6776f6
to allow SolidHarmonicsCoefficients support higher angular momenta ge…
evaleev Mar 5, 2024
01a94ff
introduced SolidHarmonicsCoefficients::make_instance that does not ca…
evaleev Mar 5, 2024
0d1a1a5
DF autogen unit test only enabled if ERI, ERI3, and ERI2 are all supp…
evaleev Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
shell: bash
working-directory: ${{github.workspace}}/build/compiler
run: |
CPPFLAGS="-I$EIGEN3_INCLUDE_DIR" CXXFLAGS="-std=c++11 -Wno-enum-compare" ${{github.workspace}}/configure --with-max-am=2,2 --with-eri-max-am=2,2 --with-eri3-max-am=3,2 --with-eri2-max-am=3,2 --enable-eri=1 --enable-eri3=1 --enable-eri2=1 --enable-1body=1 --disable-1body-property-derivs --with-multipole-max-order=2
CPPFLAGS="-I$EIGEN3_INCLUDE_DIR" CXXFLAGS="-std=c++11 -Wno-enum-compare" ${{github.workspace}}/configure --with-max-am=2,1 --with-eri-max-am=2,2 --with-eri3-max-am=3,2 --with-eri2-max-am=3,2 --enable-eri=1 --enable-eri3=1 --enable-eri2=0 --enable-1body=1 --disable-1body-property-derivs --with-multipole-max-order=2
make -j3
make check
cd src/bin/test_eri && ./stdtests.pl && cd ../../..
Expand Down
104 changes: 58 additions & 46 deletions include/libint2/dfbs_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ namespace libint2 {

namespace detail {

/// Computes uncontracted shells from a vector of shells
/// @param[in] cluster a vector of shells
/// @brief Uncontracts a set of shells
/// @param[in] shells a vector of shells to be uncontracted
/// @return a vector of uncontracted shells
inline std::vector<Shell> uncontract(const std::vector<Shell> &shells) {
std::vector<Shell> primitive_shells;
Expand All @@ -54,12 +54,16 @@ inline std::vector<Shell> uncontract(const std::vector<Shell> &shells) {
return primitive_shells;
}

/// @brief returns \Gamma(x) of x
/// @brief returns \Gamma(x)
inline double gamma_function(const double x) { return std::tgamma(x); }

/// @brief return effective exponent of product of two primitive shells
/// @param shell1 first shell
/// @param shell2 second shell
/// @brief Computes an effective exponent for a product of two primitive
/// gaussians as as described in J. Chem. Theory Comput. 2021, 17, 6886−6900.
/// \alpha_{eff} = \left[ \frac{\Gamma(L+2)\Gamma(l_\mu +l_\nu +
kshitij-05 marked this conversation as resolved.
Show resolved Hide resolved
/// \frac{3}{2})}{\Gamma(L+ \frac{3}{2})\Gamma(l_\mu +l_\nu + 2)} \right]^2
/// (\alpha_\mu + \alpha_\nu)
/// @param shell1 first primitive shell
/// @param shell2 second primitive shell
/// @param L total angular momentum of product function
/// @return effective exponent of product function
inline double alpha_eff(const Shell &shell1, const Shell &shell2, const int L) {
Expand All @@ -74,8 +78,13 @@ inline double alpha_eff(const Shell &shell1, const Shell &shell2, const int L) {
return prefactor * (alpha1 + alpha2);
}

/// @brief creates a set of product functions from a set of primitive shells
/// @brief Creates a set of product functions from a set of primitive shells.
/// Each pair of primitive shells produces a set of product functions with an
/// effective exponent (\alpha_{eff} as described above) and angular momentum
kshitij-05 marked this conversation as resolved.
Show resolved Hide resolved
/// ranging from |l1-l2| to l1+l2 as described in J. Chem. Theory Comput. 2021,
/// 17, 6886−6900.
/// @param primitive_shells set of primitive shells
/// @return set of product functions
inline std::vector<Shell> product_functions(
kshitij-05 marked this conversation as resolved.
Show resolved Hide resolved
const std::vector<Shell> &primitive_shells) {
std::vector<Shell> product_functions;
Expand Down Expand Up @@ -103,15 +112,6 @@ inline std::vector<Shell> product_functions(
return product_functions;
}

/// @brief creates a set of candidate product shells from a set of primitive
/// shells
/// @param primitive_shells set of primitive shells
/// @return set of candidate product shells
inline std::vector<Shell> candidate_functions(
const std::vector<Shell> &primitive_shells) {
return product_functions(primitive_shells);
}

/// @brief returns a hash map of shell indices to basis function indices
inline std::vector<size_t> map_shell_to_basis_function(
const std::vector<libint2::Shell> &shells) {
Expand All @@ -127,7 +127,7 @@ inline std::vector<size_t> map_shell_to_basis_function(
return result;
}

/// @brief computes the Coulomb matrix (\mu|rij^{-1}|\nu) for a set of shells
/// @brief Computes the Coulomb matrix (\mu|rij^{-1}|\nu) for a set of shells
kshitij-05 marked this conversation as resolved.
Show resolved Hide resolved
/// @param shells set of shells
/// @return Coulomb matrix
inline Eigen::MatrixXd compute_coulomb_matrix(
Expand Down Expand Up @@ -155,7 +155,10 @@ inline Eigen::MatrixXd compute_coulomb_matrix(
return result;
}

/// @brief Sorts a vector of shells by angular momentum
/// @brief Splits a set of shells by angular momentum
/// @param shells set of shells
/// @return vector of vectors of shells split by angular momentum L. The i-th
/// vector contains all shells with angular momentum i
inline std::vector<std::vector<Shell>> split_by_L(
const std::vector<Shell> &shells) {
int lmax = max_l(shells);
Expand All @@ -168,13 +171,18 @@ inline std::vector<std::vector<Shell>> split_by_L(
return sorted_shells;
}

/// @brief computes the reduced set of product functions via pivoted Cholesky
/// decomposition
/// @brief Computes the reduced set of product functions via pivoted Cholesky
/// decomposition as described in J. Chem. Theory Comput. 2021, 17, 6886−6900.
/// Cholesky decomposition is performed on the Coulomb matrix of the product
/// functions and the pivot indices are sorted in ascending order of column sums
/// of the Coulomb matrix. The reduced set of product functions is then
/// constructed by selecting the product functions corresponding to the pivot
/// indices.
/// @param shells set of shells
/// @param cholesky_threshold threshold for choosing a product function via
/// pivoted Cholesky decomposition
/// @return reduced set of product functions
inline std::vector<Shell> shell_pivoted_cholesky(
inline std::vector<Shell> pivoted_cholesky_in_L(
const std::vector<Shell> &shells, const double cholesky_threshold) {
const auto n = shells.size(); // number of shells
std::vector<size_t>
Expand Down Expand Up @@ -218,22 +226,23 @@ inline std::vector<Shell> shell_pivoted_cholesky(
}
} // namespace detail

/// @brief class produces density fitting basis sets from products of AO basis
/// functions eliminates linearly dependent functions via pivoted Cholesky
/// decomposition see: J. Chem. Theory Comput. 2021, 17, 6886−6900
/// (Straightforward and Accurate Automatic Auxiliary Basis Set Generation for
/// Molecular Calculations with Atomic Orbital Basis Sets)
/// @brief This class produces density fitting basis sets for an atom from
/// products of AO basis functions and eliminates linearly dependent functions
/// via pivoted Cholesky decomposition see: J. Chem. Theory Comput. 2021, 17,
/// 6886−6900 (Straightforward and Accurate Automatic Auxiliary Basis Set
/// Generation for Molecular Calculations with Atomic Orbital Basis Sets)
class DFBasisSetGenerator {
public:
/// @brief constructor for DFBS generator class, generates density fitting
/// basis set from products of AO basis functions see: J. Chem. Theory Comput.
/// 2021, 17, 6886−6900 (Straightforward and Accurate Automatic Auxiliary
/// Basis Set Generation for Molecular Calculations with Atomic Orbital Basis
/// Sets)
/// @brief constructor for DFBasisSetGenerator class, generates density
/// fitting basis set from products of AO basis functions of and atom see: J.
/// Chem. Theory Comput. 2021, 17, 6886−6900 (Straightforward and Accurate
/// Automatic Auxiliary Basis Set Generation for Molecular Calculations with
/// Atomic Orbital Basis Sets)
/// @param obs_name name of basis set for AO functions
/// @param atoms vector of atoms
/// @param cholesky_threshold threshold for choosing a product functions via
/// pivoted Cholesky decomposition
/// @param cholesky_threshold threshold for threshold for pivoted Cholesky
/// decomposition to be performed on the Coulomb matrix of the product
/// functions
DFBasisSetGenerator(std::string obs_name, const Atom &atom,
const double cholesky_threshold = 1e-7) {
// get AO basis shells for each atom
Expand All @@ -242,19 +251,19 @@ class DFBasisSetGenerator {
// get primitive shells from AO functions
const auto primitive_shells = detail::uncontract(obs_shells);
// compute candidate shells
candidate_shells_ = detail::candidate_functions(primitive_shells);
candidate_shells_ = detail::product_functions(primitive_shells);
cholesky_threshold_ = cholesky_threshold;
}

/// @brief constructor for DFBS generator class, generates density fitting
/// basis set from products of AO shells provided by user
/// @param cluster vector of vector of shells for each atom
/// @param cholesky_threshold threshold for choosing a product functions via
/// pivoted Cholesky decomposition
/// @brief constructor for DFBasisSetGenerator class, generates density
/// fitting basis set from products of AO shells provided by user
/// @param shells vector of vector of shells for each atom
/// @param cholesky_threshold threshold for pivoted Cholesky decomposition to
/// be performed on the Coulomb matrix of the product functions
DFBasisSetGenerator(const std::vector<Shell> &shells,
const double cholesky_threshold = 1e-7) {
const auto primitive_shells = detail::uncontract(shells);
candidate_shells_ = detail::candidate_functions(primitive_shells);
candidate_shells_ = detail::product_functions(primitive_shells);
cholesky_threshold_ = cholesky_threshold;
}

Expand All @@ -265,8 +274,10 @@ class DFBasisSetGenerator {
/// @brief returns the candidate shells (full set of product functions)
std::vector<Shell> candidate_shells() { return candidate_shells_; }

/// @brief returns the reduced shells (reduced set of product functions)
/// computed via pivoted Cholesky decomposition
/// @brief returns a set of shells reduced via pivoted Cholesky
/// decomposition of the Coulomb matrix of the product functions for each
/// angular momentum L as described in J. Chem. Theory Comput. 2021, 17,
/// 6886−6900.
std::vector<Shell> reduced_shells() {
if (reduced_shells_computed_)
return reduced_shells_;
Expand All @@ -276,7 +287,7 @@ class DFBasisSetGenerator {
for (size_t i = 0; i < candidate_splitted_in_L.size(); ++i) {
std::vector<Shell> reduced_shells_L;
if (candidate_splitted_in_L[i].size() > 1)
reduced_shells_L = detail::shell_pivoted_cholesky(
reduced_shells_L = detail::pivoted_cholesky_in_L(
candidate_splitted_in_L[i], cholesky_threshold_);
else
reduced_shells_L = candidate_splitted_in_L[i];
Expand All @@ -288,9 +299,10 @@ class DFBasisSetGenerator {
return reduced_shells_;
}

/// @brief returns the reduced basis set (reduced set of product
/// functions)
/// computed via pivoted Cholesky decomposition
/// @brief returns a BasisSet of shells reduced via pivoted Cholesky
/// decomposition of the Coulomb matrix of the product functions for each
/// angular momentum L as described in J. Chem. Theory Comput. 2021, 17,
/// 6886−6900.
const BasisSet reduced_basis() { return BasisSet(reduced_shells()); }

private:
Expand Down
Loading