-
Notifications
You must be signed in to change notification settings - Fork 109
Automatic Density Fitting basis generator #281
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
Merged
Merged
Changes from 2 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 6f0583a
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 f86a3fc
implemented pivoted cholesky algorithm and addressed comments
kshitij-05 b6d8b50
removed unnecessary typedefs and used std::tgamma
kshitij-05 74cf2fc
DFBasisSetGenerator produces reduced set of shells using pivoted chol…
kshitij-05 c2f1dac
DFBasisSetGenerator return a reduced BasisSet, updated hartree-fock++…
kshitij-05 7d43e26
refactored `uncontract()` function from `basis.h.in` to `shell.h`
kshitij-05 2cea2c4
increased supported `with-eri3-max-am` to 13
kshitij-05 56801c3
bugfix: `uncontract()` is in 'libint2::detail'
kshitij-05 1473522
added dox for `DFBasisGenerator`, made `reduced_basis()` return const…
kshitij-05 b62e2fa
`uncontract()` refactored back to `dfbs_generator.h` because its not …
kshitij-05 0d243c6
bugfix: `hartree-fock++` btas tensor def if btas provided
kshitij-05 49d1667
used && in range based for loop
kshitij-05 2d45d69
non-templated functions in headers are now inline
kshitij-05 bdf7c47
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 c4886a7
`DFBasisGenerator` generates density fitting basis set for one atom n…
kshitij-05 aeaf535
`DFBasisGenerator` generates density fitting basis set for one atom n…
kshitij-05 1492d0f
Merge remote-tracking branch 'origin/kshitij/feature/dfbs_generator' …
kshitij-05 7025626
Bugfix: `DFBasisGenerator.reduced_basis()` will not return NULL basis
kshitij-05 bdce06c
switched from deducing size type by `auto` to explicit `size_t`
kshitij-05 cb04647
reformatted code in `bfbs_generator.h` and `pivoted_cholesky.h`
kshitij-05 aca6d34
libint initialized before computing integrals in `hartree-fock++.cc`
kshitij-05 7a6fc5b
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 62ceda3
reformatted code in `dfbs_generator.h` and `pivoted_cholesky.h` with …
kshitij-05 6640567
bugfix: if only one product shell exist for an `L` then is included i…
kshitij-05 0884613
clang-format: reformat to resolve merge conflict
kshitij-05 68d4109
removed unnecessary empty file, removed passing copies as arguments
kshitij-05 0b6a961
use `const auto` for `const` variables, and bumped up eri2 available …
kshitij-05 527be9e
added unit test for `DFBasisGenerator`
kshitij-05 e272283
`DFBasisGenerator` uses FD occupation number as importance factor
kshitij-05 78fb30d
generalized weights handeling in `DFBasisGenerator` with` std::tuple<…
kshitij-05 77bfe57
merge master
kshitij-05 4343994
revert `DFBasisGenerator` back to basic cholesky implementation
kshitij-05 48ab8d9
removed function overload of `shell_pivoted_cholesky`
kshitij-05 43e79c0
enabled '--with-eri2' in CI configuration
kshitij-05 a3e73c5
to use autoDF `hartree-fock++.cc` uses `autodf(chol_tol)` as command …
kshitij-05 8f817d4
CI configures with `--enable-eri2=1`
kshitij-05 ad9164f
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 5d551bb
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 580ac6b
cleanup and dox fixes in `dfbs_generator.h`
kshitij-05 ecf3343
Merge branch 'master' into kshitij/feature/dfbs_generator
kshitij-05 8665657
revert changes to ci configuration to compute 1st order derivatives o…
kshitij-05 1c239c4
revert changes to ci configuration to compute 1st order derivatives o…
kshitij-05 f8d117b
Merge remote-tracking branch 'origin/kshitij/feature/dfbs_generator' …
kshitij-05 3f0f729
renamed `shell_pivoted_cholesky()` to `pivoted_cholesky_in_L()`
kshitij-05 7f2bbd7
use `\f$` to embed LaTeX into dox of `DFBasisSetGenerator` and define…
kshitij-05 cbe5144
can configure with `--with-eri3-max-am=12` and `--with-eri2-max-am=12`
kshitij-05 e8b9b0e
[skip ci] dox++
evaleev 8ca8948
C -> C++ headers
evaleev e9c577d
factorials and related quantities are computed in a safer manner, wit…
kshitij-05 c02797c
LIBINT_HARD_MAX_AM appears in config.h
evaleev c6776f6
to allow SolidHarmonicsCoefficients support higher angular momenta ge…
evaleev 01a94ff
introduced SolidHarmonicsCoefficients::make_instance that does not ca…
evaleev 0d1a1a5
DF autogen unit test only enabled if ERI, ERI3, and ERI2 are all supp…
evaleev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| /* | ||
| * Copyright (C) 2004-2021 Edward F. Valeev | ||
| * | ||
| * This file is part of Libint. | ||
| * | ||
| * Libint is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * Libint is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with Libint. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef _libint2_src_lib_libint_dfbs_generator_h_ | ||
| #define _libint2_src_lib_libint_dfbs_generator_h_ | ||
|
|
||
| #include <algorithm> | ||
| #include <libint2.h> | ||
| #include <math.h> | ||
| #include <libint2/shell.h> | ||
| #include <libint2/basis.h> | ||
| #include <libint2/atom.h> | ||
| #include <libint2/boys.h> | ||
| #include <Eigen/Dense> | ||
| #include <Eigen/Eigenvalues> | ||
| #include <boost/math/special_functions/gamma.hpp> | ||
|
|
||
| namespace libint2 { | ||
| typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Matrix; | ||
| typedef Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Matrix_int; | ||
| typedef std::vector<Shell> Shellvec; | ||
|
|
||
| namespace datail { | ||
|
|
||
| /// @brief returns \Gamma(x) of x | ||
| double gamma(const double &x) { | ||
|
kshitij-05 marked this conversation as resolved.
Outdated
|
||
| return boost::math::tgamma(x); | ||
| } | ||
|
|
||
| /// @brief return effective exponent of product of two primitive shells | ||
| /// @param shell1 first shell | ||
| /// @param shell2 second shell | ||
| /// @param L total angular momentum of product function | ||
| /// @return effective exponent of product function | ||
| double alpha_eff(const Shell &shell1, const Shell &shell2, const int &L) { | ||
|
kshitij-05 marked this conversation as resolved.
Outdated
|
||
| auto alpha1 = shell1.alpha[0]; | ||
| auto alpha2 = shell2.alpha[0]; | ||
| auto l1 = shell1.contr[0].l; | ||
| auto l2 = shell2.contr[0].l; | ||
| auto prefactor = std::pow((gamma(L + 2.) * gamma(l1 + l2 + 1.5)) / (gamma(l1 + l2 + 2.) * gamma(L + 1.5)), | ||
| 2.); | ||
| return prefactor * (alpha1 + alpha2); | ||
| } | ||
|
|
||
| /// @brief creates a set of product functions from a set of primitive shells | ||
| /// @param primitive_shells set of primitive shells | ||
| Shellvec product_functions(const Shellvec &primitive_shells) { | ||
| Shellvec product_functions; | ||
| for (auto i = 0; i < primitive_shells.size(); ++i) { | ||
| for (auto j = 0; j <= i; ++j) { | ||
| auto li = primitive_shells[i].contr[0].l; | ||
| auto lj = primitive_shells[j].contr[0].l; | ||
| for (auto L = std::abs(li - lj); L <= li + lj; L++) { | ||
| auto alpha = libint2::svector<double>({alpha_eff(primitive_shells[i], primitive_shells[j], L)}); | ||
| libint2::svector<Shell::Contraction> contr_; | ||
| Shell::Contraction contr1; | ||
| contr1.l = L; | ||
| contr1.pure = true; // libint2 needs solid harmonics for 2c2b integrals | ||
| contr1.coeff = {1.0}; | ||
| contr_.push_back(contr1); | ||
| assert(primitive_shells[i].O == primitive_shells[j].O); | ||
| auto shell = Shell(alpha, contr_, primitive_shells[i].O); | ||
| if (std::find(product_functions.begin(), product_functions.end(), | ||
| shell) == product_functions.end()) | ||
| product_functions.emplace_back(shell); | ||
| } | ||
| } | ||
| } | ||
| 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 | ||
| std::vector<Shellvec> candidate_functions(const std::vector<Shellvec> &primitive_shells) { | ||
| std::vector<Shellvec> candidate_functions; | ||
| for (auto i = 0; i < primitive_shells.size(); ++i) { | ||
| candidate_functions.push_back(product_functions(primitive_shells[i])); | ||
| } | ||
| return candidate_functions; | ||
| } | ||
|
|
||
| /// @brief returns a hash map of shell indices to basis function indices | ||
| std::vector<size_t> map_shell_to_basis_function(const std::vector<libint2::Shell> &shells) { | ||
| std::vector<size_t> result; | ||
| result.reserve(shells.size()); | ||
|
|
||
| size_t n = 0; | ||
| for (auto shell: shells) { | ||
|
kshitij-05 marked this conversation as resolved.
Outdated
|
||
| result.push_back(n); | ||
| n += shell.size(); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /// @brief computes the Coulomb matrix (\mu|rij^{-1}|\nu) for a set of shells | ||
| /// @param shells set of shells | ||
| /// @return Coulomb matrix | ||
| Matrix compute_coulomb_matrix(const Shellvec &shells) { | ||
| const auto n = nbf(shells); | ||
| Matrix result = Matrix::Zero(n, n); | ||
| using libint2::Engine; | ||
| Engine engine(libint2::Operator::coulomb, max_nprim(shells), max_l(shells), 0); | ||
| engine.set(BraKet::xs_xs); | ||
| engine.set(ScreeningMethod::Conservative); | ||
| auto shell2bf = map_shell_to_basis_function(shells); | ||
| const auto &buf = engine.results(); | ||
| for (auto s1 = 0; s1 != shells.size(); ++s1) { | ||
| auto bf1 = shell2bf[s1]; | ||
| auto n1 = shells[s1].size(); | ||
| for (auto s2 = 0; s2 <= s1; ++s2) { | ||
| auto bf2 = shell2bf[s2]; | ||
| auto n2 = shells[s2].size(); | ||
| engine.compute(shells[s1], shells[s2]); | ||
| Eigen::Map<const Matrix> buf_mat(buf[0], n1, n2); | ||
| result.block(bf1, bf2, n1, n2) = buf_mat; | ||
| if (s1 != s2) | ||
| result.block(bf2, bf1, n2, n1) = buf_mat.transpose(); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /// @brief Sorts a vector of shells by angular momentum | ||
|
kshitij-05 marked this conversation as resolved.
Outdated
|
||
| std::vector<Shellvec> sort_by_L(const Shellvec& shells){ | ||
| int lmax = max_l(shells); | ||
| std::vector<Shellvec> sorted_shells; | ||
| sorted_shells.resize(lmax+1); | ||
| for(auto shell:shells){ | ||
| auto l = shell.contr[0].l; | ||
| sorted_shells[l].push_back(shell); | ||
| } | ||
| return sorted_shells; | ||
| } | ||
|
|
||
| }// namespace detail | ||
|
|
||
| class DFBS_generator { | ||
|
kshitij-05 marked this conversation as resolved.
Outdated
|
||
| public: | ||
| /// @brief constructor for DFBS generator class, generates density fitting basis set from products of AO basis functions | ||
| /// @param obs_name name of basis set for AO functions | ||
| /// @param atoms vector of atoms | ||
| DFBS_generator(std::string obs_name, | ||
|
kshitij-05 marked this conversation as resolved.
Outdated
|
||
| const std::vector<Atom> &atoms) : obs_name_(std::move(obs_name)), atoms_(std::move(atoms)) { | ||
| std::vector<Shellvec> obs_shell_vec; | ||
| std::vector<Shellvec> primitive_cluster; | ||
| // get AO basis shells for each atom | ||
| for (auto atom: atoms) { | ||
| auto atom_bs = BasisSet(obs_name_, {atom}); | ||
| obs_shell_vec.emplace_back(atom_bs.shells()); | ||
| } | ||
| // get primitive shells from AO functions | ||
| for (auto obs_shells: obs_shell_vec) { | ||
| primitive_cluster.emplace_back(uncontract(obs_shells)); | ||
| } | ||
|
|
||
| //compute candidate shells | ||
| candidate_shells_ = datail::candidate_functions(primitive_cluster); | ||
|
|
||
| // initialize libint2 | ||
| libint2::initialize(); | ||
|
kshitij-05 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| DFBS_generator() = default; | ||
|
|
||
| ~DFBS_generator() = default; | ||
|
|
||
| /// @brief returns the candidate shells (full set of product functions) | ||
| std::vector<Shellvec> candidate_shells() { | ||
| return candidate_shells_; | ||
| } | ||
|
|
||
| /// @brief returns the candidate shells sorted by angular momentum | ||
| std::vector<std::vector<Shellvec>> candidates_sorted_in_L(){ | ||
| std::vector<std::vector<Shellvec>> sorted_shells; | ||
| for(auto shells:candidate_shells_){ | ||
| sorted_shells.push_back(datail::sort_by_L(shells)); | ||
| } | ||
| return sorted_shells; | ||
| } | ||
|
|
||
| private: | ||
| std::string obs_name_; //name of AO basis set | ||
| std::vector<Atom> atoms_; //vector of atoms | ||
| std::vector<Shellvec> candidate_shells_; //full set of product functions | ||
| std::vector<Shellvec> reduced_shells_; //reduced set of product functions | ||
|
|
||
| }; | ||
|
|
||
| } // namespace libint2 | ||
|
|
||
| #endif /* _libint2_src_lib_libint_dfbs_generator_h_ */ | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.