Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit c4a0aeb

Browse files
authored
Merge pull request #36 from molsturm/dev-mfh
Minor changes
2 parents 8fa7431 + 039c7c5 commit c4a0aeb

File tree

14 files changed

+214
-30
lines changed

14 files changed

+214
-30
lines changed

.travis.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ env:
4040
# The regex for tests to run (disable running tests by TESTS=0)
4141
- TESTS=1 TESTS_REGEX="gint_tests_"
4242

43+
4344
# Cache the directory cache_libint, such that libint does not need
4445
# to be rebuild each time.
4546
cache:
@@ -78,7 +79,7 @@ before_install:
7879

7980
matrix:
8081
include:
81-
# Clang 3.5 with disabled c++14 support with libstdc++-4.9
82+
# System clang with disabled c++14 support with libstdc++-4.9
8283
- addons:
8384
apt:
8485
sources: *def_sources
@@ -91,27 +92,33 @@ matrix:
9192
compiler: clang
9293
env: CC_COMP="clang" CXX_COMP="clang++"
9394
#
94-
# Clang 5.0 (has c++17) with libc++-1
95-
# Note that c++17 is disabled due to cmake < 3.8 where c++17 is not yet ready
95+
# TODO Here we used to test with libc++1 by installing libc++-dev,
96+
# but this does not go well with libint any more
97+
# Clang 5.0 with disabled c++17 support
9698
- addons:
9799
apt:
98100
sources: *def_sources
99101
packages:
100102
- *def_packages
101-
- &clang_newest [ clang-5.0, libc++-dev, llvm-5.0, clang-tidy-5.0 ]
103+
- &clang_newest [ clang-5.0, llvm-5.0, clang-tidy-5.0 ]
104+
- libstdc++-5-dev
102105
install:
106+
- export EXTRA_OPTS="-DDRB_MAXIMUM_CXX_STANDARD=14"
103107
- export GCOV="llvm-cov-5.0 gcov"
104108
compiler: clang
105109
env: CC_COMP="clang-5.0" CXX_COMP="clang++-5.0"
106110
#
107-
# gcc-4.8 (c++11 and without tests, since rapidcheck does not compile like this)
108-
- install:
109-
- export TESTS=0 EXTRA_OPTS="-DGINT_ENABLE_TESTS=OFF"
111+
# gcc-5
112+
- addons:
113+
apt:
114+
sources: *def_sources
115+
packages:
116+
- *def_packages
117+
- g++-5
110118
compiler: gcc
111-
env: CC_COMP="gcc" CXX_COMP="g++"
119+
env: CC_COMP="gcc-5" CXX_COMP="g++-5"
112120
#
113121
# gcc-7 (with tests and c++17)
114-
# Note that c++17 is disabled due to cmake < 3.8 where c++17 is not yet ready
115122
- addons:
116123
apt:
117124
sources: *def_sources
@@ -124,7 +131,6 @@ matrix:
124131
env: CC_COMP="gcc-7" CXX_COMP="g++-7"
125132
#
126133
# Clang-tidy 5.0
127-
# Note that c++17 is disabled due to cmake < 3.8 where c++17 is not yet ready
128134
- addons:
129135
apt:
130136
sources: *def_sources
@@ -151,7 +157,8 @@ script:
151157
-DLIBINT_INCLUDE_DIR=$HOME/cache_libint/include
152158
-DLIBINT_LIBRARY=$HOME/cache_libint/lib/libint2.a"
153159
;else
154-
LIBINT_OPTS="-DGINT_LIBINT_MAX_AM=3 -DDEP_BUILD_libint_NJOBS=2"
160+
LIBINT_OPTS="-DGINT_LIBINT_MAX_AM=3 -DDEP_BUILD_libint_NJOBS=2
161+
-DGINT_LIBINT_MAX_MULTIPOLE=2"
155162
;fi
156163
#
157164
# Configure build and test
@@ -167,7 +174,7 @@ script:
167174
-DGINT_ENABLE_LIBCINT=ON
168175
-DGINT_ENABLE_LIBINT=ON ${LIBINT_OPTS}
169176
-GNinja ..
170-
- cmake --build . --target ${BUILD_TARGET:-all} -- -j ${CORES}
177+
- travis_wait 20 cmake --build . --target ${BUILD_TARGET:-all} -- -j ${CORES}
171178
- if [ "${TESTS}" != "0" ]; then
172179
ctest -j ${CORES} --output-on-failure -R "${TESTS_REGEX}"
173180
;else true; fi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ More documentation will follow ...
1616
For *building* `gint` the following things are required:
1717
- ``cmake`` >= 3.0.0
1818
- A compiler supporting ``C++11``: ``clang`` starting from `clang-3.5` and `gcc` starting
19-
from `gcc-4.8` should work.
19+
from `gcc-5` should work.
2020
- [``swig``](http://swig.org/) >= 2.0.11
2121
- [``python``](https://www.python.org/) >= 3.4, including the development headers
2222
- The [usual build process](#building-gint) mentioned below

cmake/findLibint.cmake

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ message(WARNING "AUTOCHECKOUT_FORCED should be worked into this.")
4747
# -------
4848
#
4949

50-
function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM)
50+
function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM LIBINT_MAX_MULTIPOLE_ORDER)
5151
# Determine compiler flags which are in use in outer project
5252
# and remove all -W and -f flags
5353
string(REGEX REPLACE "(-(W|f)[^ ]+|-pedantic)" "" TMP
@@ -81,7 +81,9 @@ function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM)
8181
"CXX=${CMAKE_CXX_COMPILER}"
8282
#
8383
# Optimisation flags for all compilation processes inside libint
84-
"CXXFLAGS=${CXX_STANDARD_FLAG} ${CLANG_CXX_FLAGS}"
84+
# TODO Note that -DBOOST_PP_VARIADICS=1 was added to work around
85+
# a common bug in boost
86+
"CXXFLAGS=${CXX_STANDARD_FLAG} ${CLANG_CXX_FLAGS} -DBOOST_PP_VARIADICS=1"
8587
"LDFLAGS=${CLANG_LD_FLAGS}"
8688
#
8789
# Optimisation flags for the inner compiler
@@ -94,6 +96,9 @@ function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM)
9496
# Optimise maximally up to angular momentum 4
9597
"--with-opt-am=${LIBINT_OPT_AM}"
9698
#
99+
# Limit max multipole order
100+
"--with-multipole-max-order=${LIBINT_MAX_MULTIPOLE_ORDER}"
101+
#
97102
# Disable unrolling shell sets into integrals
98103
"--disable-unrolling"
99104
#
@@ -140,6 +145,10 @@ function(SETUP_LIBINT2_FOR_EXTERNAL_BUILD TARGET LIBINT_MAX_AM)
140145
endfunction()
141146

142147
function(SETUP_SYSTEM_LIBINT TARGET VERSION)
148+
string(REGEX REPLACE "^([0-9.]+).*" "\\1"
149+
LIBINT_VERSION "${VERSION}")
150+
set(VERSION "${LIBINT_VERSION}")
151+
143152
find_package(Libint2 ${VERSION} QUIET MODULE)
144153
if (NOT LIBINT_FOUND)
145154
return()
@@ -191,6 +200,8 @@ Try setting Eigen3_DIR to the location.")
191200
message(STATUS "Found eigen3 include directory at ${Eigen3_DIR}")
192201
endif()
193202

203+
# TODO Only do this if libint autocheckout is not forced.
204+
# i.e. read AUTOCHECKOUT_FORCED
194205
if (LIBINT_SEARCH_SYSTEM STREQUAL "" OR LIBINT_SEARCH_SYSTEM)
195206
set(LIBINT_TARGET "System::libint")
196207
SETUP_SYSTEM_LIBINT(${LIBINT_TARGET} ${LIBINT_VERSION})
@@ -203,7 +214,8 @@ if (LIBINT_SEARCH_SYSTEM STREQUAL "" OR LIBINT_SEARCH_SYSTEM)
203214
endif()
204215
if(AUTOCHECKOUT_MISSING_REPOS)
205216
set(LIBINT_TARGET "External::libint")
206-
SETUP_LIBINT2_FOR_EXTERNAL_BUILD(${LIBINT_TARGET} ${LIBINT_MAX_AM})
217+
SETUP_LIBINT2_FOR_EXTERNAL_BUILD(${LIBINT_TARGET} ${LIBINT_MAX_AM}
218+
${LIBINT_MAX_MULTIPOLE_ORDER})
207219
target_link_libraries(${LIBINT_TARGET} INTERFACE ${EIGEN_TARGET})
208220

209221
message(STATUS "Setting up libint2 as an external project")

cmake/setup_optional.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ option(GINT_ENABLE_STURMINT "Enable the sturmint library to compute Sturmian int
5151

5252
if (GINT_ENABLE_STURMINT)
5353
include_krims_cmake_module(FindPackageAutocheckoutFallback)
54-
find_package_autocheckout_fallback(sturmint 0.0.0)
54+
find_package_autocheckout_fallback(sturmint 0.0.2)
5555

5656
foreach (build ${DRB_BUILD_TYPES})
5757
set(GINT_DEPENDENCIES_${build} ${GINT_DEPENDENCIES_${build}} ${sturmint_${build}_TARGET})
@@ -70,6 +70,7 @@ set(GINT_LIBINT_MAX_AM 6 CACHE STRING
7070
"Maximal angular momentum libint can perform integrals over. \
7171
Choose a smaller value to get a faster build."
7272
) # Note: ORCA uses a value of 7 (up to K) in the setting above.
73+
set(GINT_LIBINT_MAX_MULTIPOLE 10 CACHE STRING "Maximal multipole order to use for builds.")
7374

7475
if (GINT_ENABLE_LIBINT)
7576
# Check options:
@@ -78,13 +79,16 @@ if (GINT_ENABLE_LIBINT)
7879
endif()
7980

8081
# Forward parameters to included module
81-
set(LIBINT_VERSION 2.3.1) # We need at least this version
82+
set(LIBINT_VERSION 2.5.0-beta.1) # We need at least this version
8283
set(LIBINT_SEARCH_SYSTEM ${GINT_LIBINT_USE_SYSTEM})
8384
set(LIBINT_MAX_AM ${GINT_LIBINT_MAX_AM})
85+
set(LIBINT_MAX_MULTIPOLE_ORDER ${GINT_LIBINT_MAX_MULTIPOLE})
8486

8587
include(cmake/findLibint.cmake)
8688
unset(LIBINT_VERSION)
89+
unset(LIBINT_MAX_AM)
8790
unset(LIBINT_SEARCH_SYSTEM)
91+
unset(LIBINT_MAX_MULTIPOLE_ORDER)
8892

8993
set(GINT_DEPENDENCIES ${GINT_DEPENDENCIES} ${LIBINT_TARGET})
9094
enable_feature(libint)

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ function(setup_example_target TARGET)
5353
endfunction()
5454

5555
add_subdirectory(laplace)
56+
add_subdirectory(rhf)

examples/rhf/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## ---------------------------------------------------------------------
2+
##
3+
## Copyright (C) 2017 by the gint authors
4+
##
5+
## This file is part of gint.
6+
##
7+
## gint is free software: you can redistribute it and/or modify
8+
## it under the terms of the GNU General Public License as published
9+
## by the Free Software Foundation, either version 3 of the License, or
10+
## (at your option) any later version.
11+
##
12+
## gint is distributed in the hope that it will be useful,
13+
## but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
## GNU General Public License for more details.
16+
##
17+
## You should have received a copy of the GNU General Public License
18+
## along with gint. If not, see <http://www.gnu.org/licenses/>.
19+
##
20+
## ---------------------------------------------------------------------
21+
22+
add_executable(rhf main.cc)
23+
setup_example_target(rhf)

examples/rhf/main.cc

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// Copyright (C) 2017 by the gint authors
3+
//
4+
// This file is part of gint.
5+
//
6+
// gint is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published
8+
// by the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// gint is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with gint. If not, see <http://www.gnu.org/licenses/>.
18+
//
19+
20+
#include <gint/IntegralLookup.hh>
21+
#include <gint/IntegralUpdateKeys.hh>
22+
#include <gint/Structure.hh>
23+
#include <krims/GenMap.hh>
24+
#include <lazyten/SmallVector.hh>
25+
#include <lazyten/eigensystem.hh>
26+
27+
namespace rhf {
28+
void restricted_hartree_fock(const krims::GenMap& intparams, const size_t n_alpha,
29+
const size_t n_orbs = 4, const size_t max_iter = 100) {
30+
using gint::IntegralTypeKeys;
31+
using gint::IntegralUpdateKeys;
32+
using namespace lazyten;
33+
34+
// Get the integrals for the appropriate integral parameters
35+
auto integrals = gint::IntegralLookup<SmallMatrix<double>>(intparams);
36+
auto S_bb = integrals.lookup_integral(IntegralTypeKeys::overlap);
37+
auto T_bb = integrals.lookup_integral(IntegralTypeKeys::kinetic);
38+
auto V_bb = integrals.lookup_integral(IntegralTypeKeys::nuclear_attraction);
39+
auto J_bb = integrals.lookup_integral(IntegralTypeKeys::coulomb);
40+
auto K_bb = integrals.lookup_integral(IntegralTypeKeys::exchange);
41+
42+
// Get an hcore guess
43+
const auto hcore_bb = T_bb + V_bb;
44+
const auto eigensolution = eigensystem_hermitian(hcore_bb, S_bb, n_orbs);
45+
46+
// Current occupied coefficients in convenient data structure
47+
const auto cocc = eigensolution.evectors().subview({0, n_alpha});
48+
49+
// Initialise two-electron terms with guess coefficients
50+
J_bb.update({{IntegralUpdateKeys::coefficients_occupied, cocc}});
51+
K_bb.update({{IntegralUpdateKeys::coefficients_occupied, cocc}});
52+
53+
double oldene = 0;
54+
std::cout << "Iter etot echange" << std::endl;
55+
for (size_t i = 0; i < max_iter; ++i) {
56+
// Obtain new eigenpairs ...
57+
const auto F_bb = hcore_bb + (2 * J_bb - K_bb);
58+
const auto eigensolution = eigensystem_hermitian(F_bb, S_bb, n_orbs);
59+
60+
// ... and new occupied coefficients
61+
const auto cocc = eigensolution.evectors().subview({0, n_alpha});
62+
63+
// Compute HF energies
64+
// For example coulomb energy is tr(C^T J C)
65+
double ene_one_elec = trace(outer_prod_sum(cocc, hcore_bb * cocc));
66+
double ene_coulomb = 2 * trace(outer_prod_sum(cocc, J_bb * cocc));
67+
double ene_exchge = -trace(outer_prod_sum(cocc, K_bb * cocc));
68+
double energy = 2 * (ene_one_elec + .5 * ene_coulomb + .5 * ene_exchge);
69+
70+
// Display current iteration
71+
double energy_change = energy - oldene;
72+
std::cout << i << " " << energy << " " << energy_change << std::endl;
73+
oldene = energy;
74+
75+
// Check for convergence
76+
if (fabs(energy_change) < 1e-6) break;
77+
78+
// Update the two-electron integrals, before coefficients
79+
// go out of scope
80+
J_bb.update({{IntegralUpdateKeys::coefficients_occupied, cocc}});
81+
K_bb.update({{IntegralUpdateKeys::coefficients_occupied, cocc}});
82+
}
83+
84+
std::cout << "Doubly occupied orbitals: " << std::endl;
85+
for (size_t i = 0; i < n_alpha; ++i) {
86+
std::cout << " " << eigensolution.evalues()[i] << std::endl;
87+
}
88+
}
89+
} // namespace rhf
90+
91+
int main() {
92+
gint::Structure be{
93+
{"Be", {{0., 0., 0.}}},
94+
};
95+
const size_t n_alpha = 2;
96+
97+
krims::GenMap params_gauss{
98+
{"basis_type", "gaussian/libint"},
99+
{"basis_set_name", "pc-2"},
100+
{"structure", be},
101+
};
102+
103+
krims::GenMap params_sturm{
104+
{"basis_type", "sturmian/atomic/cs_dummy"},
105+
{"k_exponent", 1.988},
106+
{"n_max", 5},
107+
{"l_max", 1},
108+
{"m_max", 1},
109+
{"structure", be},
110+
};
111+
112+
rhf::restricted_hartree_fock(params_gauss, n_alpha);
113+
return 0;
114+
}

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
[flake8]
22
ignore = E241,E266
33
max-line-length = 90
4+
5+
[bumpversion]
6+
current_version = 0.0.0
7+
commit = True
8+
tag = True
9+
10+
[bumpversion:file:CMakeLists.txt]

src/gint/ERITensor_i.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ void ERITensor_i<Scalar>::contract_with(const iface_multivector_type& c_wa,
8585
std::vector<Scalar> i1_wbcd(n_w * n_bas() * n_bas() * n_bas());
8686

8787
auto contract_kernel = [&i1_wbcd, &c_wa, &absidx_wbcd](
88-
const std::array<krims::Range<size_t>, 4>& batch, const Scalar* values) {
88+
const std::array<krims::Range<size_t>, 4>& batch,
89+
const Scalar* values) {
8990
#ifdef DEBUG
9091
const size_t values_size =
9192
batch[0].length() * batch[1].length() * batch[2].length() * batch[3].length();
@@ -197,10 +198,9 @@ void ERITensor_i<Scalar>::contract_with(const iface_multivector_type& c_wa,
197198

198199
template <typename Scalar>
199200
void ERITensor_i<Scalar>::extract_block(const std::array<krims::Range<size_t>, 4>& block,
200-
std::vector<Scalar>& out) const {
201+
Scalar* out) const {
201202
using krims::intersection;
202-
assert_size(out.size(), block[0].length() * block[1].length() * block[2].length() *
203-
block[3].length());
203+
204204
assert_greater(block[0].back(), n_bas());
205205
assert_greater(block[1].back(), n_bas());
206206
assert_greater(block[2].back(), n_bas());
@@ -211,6 +211,8 @@ void ERITensor_i<Scalar>::extract_block(const std::array<krims::Range<size_t>, 4
211211
#ifdef DEBUG
212212
const size_t values_size =
213213
batch[0].length() * batch[1].length() * batch[2].length() * batch[3].length();
214+
const size_t block_size =
215+
block[0].length() * block[1].length() * block[2].length() * block[3].length();
214216
#endif
215217

216218
// Get the intersection of the range we have in the current batch
@@ -250,7 +252,7 @@ void ERITensor_i<Scalar>::extract_block(const std::array<krims::Range<size_t>, 4
250252
const size_t idx_bch = absidx_bch({{a_bch, b_bch, c_bch, d_bch}});
251253

252254
assert_internal(idx_bch < values_size);
253-
assert_internal(idx_blk < out.size());
255+
assert_internal(idx_blk < block_size);
254256
out[idx_blk] = it[idx_bch];
255257
} // d
256258
} // c

0 commit comments

Comments
 (0)