Skip to content

Commit c4bf04c

Browse files
committed
Merge branch 'devel' of https://github.com/Quantum-Dynamics-Hub/libra-code into devel
2 parents 36cbd46 + 26963db commit c4bf04c

File tree

9 files changed

+840
-29
lines changed

9 files changed

+840
-29
lines changed

backup/libint2_wrappers.cpp

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.

backup/libint2_wrappers.h

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*********************************************************************************
2+
* Copyright (C) 2021 Mohammad Shakiba and Alexey V. Akimov
3+
*
4+
* This file is distributed under the terms of the GNU General Public License
5+
* as published by the Free Software Foundation, either version 3 of
6+
* the License, or (at your option) any later version.
7+
* See the file LICENSE in the root directory of this distribution
8+
* or <http://www.gnu.org/licenses/>.
9+
*
10+
*********************************************************************************/
11+
/**
12+
\file libint2_wrappers.h
13+
\brief The file describes the classes and functions that interface libint2 functions and types with those of Libra and expose them to Python
14+
15+
*/
16+
17+
#ifndef LIBINT2_WRAPPERS_H
18+
#define LIBINT2_WRAPPERS_H
19+
20+
21+
#include "../math_linalg/liblinalg.h"
22+
#include "../math_specialfunctions/libspecialfunctions.h"
23+
24+
25+
// standard C++ headers
26+
#include <cmath>
27+
#include <iostream>
28+
#include <fstream>
29+
#include <sstream>
30+
#include <iomanip>
31+
#include <vector>
32+
#include <chrono>
33+
#include <thread>
34+
35+
// Eigen matrix algebra library
36+
#include <Eigen/Dense>
37+
#include <Eigen/Eigenvalues>
38+
39+
/*
40+
// Pybind11 for interface with Python
41+
#include <pybind11.h>
42+
#include <pybind11/eigen.h>
43+
#include <numpy.h>
44+
#include <stl.h>
45+
#include <complex.h>
46+
#include <functional.h>
47+
#include <chrono.h>
48+
*/
49+
50+
// Libint Gaussian integrals library
51+
#include <libint2.hpp>
52+
53+
#if !LIBINT2_CONSTEXPR_STATICS
54+
# include <libint2/statics_definition.h>
55+
#endif
56+
57+
// OpenMP library
58+
#if defined(_OPENMP)
59+
#include <omp.h>
60+
#endif
61+
62+
63+
64+
65+
66+
/// liblibra namespace
67+
namespace liblibra{
68+
69+
using namespace liblinalg;
70+
using namespace libspecialfunctions;
71+
72+
73+
namespace liblibint2_wrappers{
74+
75+
76+
77+
// fires off \c nthreads instances of lambda in parallel
78+
template <typename Lambda>
79+
void parallel_do(Lambda& lambda, int nthreads) {
80+
#ifdef _OPENMP
81+
#pragma omp parallel
82+
{
83+
auto thread_id = omp_get_thread_num();
84+
lambda(thread_id);
85+
}
86+
#else // use C++11 threads
87+
std::vector<std::thread> threads;
88+
for (int thread_id = 0; thread_id != libint2::nthreads; ++thread_id) {
89+
if (thread_id != nthreads - 1)
90+
threads.push_back(std::thread(lambda, thread_id));
91+
else
92+
lambda(thread_id);
93+
} // threads_id
94+
for (int thread_id = 0; thread_id < nthreads - 1; ++thread_id)
95+
threads[thread_id].join();
96+
#endif
97+
}
98+
99+
100+
101+
102+
std::vector<libint2::Shell> initialize_shell(int l_val, bool is_spherical,
103+
const std::vector<double>& exponents, const std::vector<double>& coeff, VECTOR& coords);
104+
105+
void add_to_shell(std::vector<libint2::Shell>& shells,
106+
int l_val, bool is_spherical , const std::vector<double>& exponents, const std::vector<double>& coeff, VECTOR& coords);
107+
108+
void print_shells(std::vector<libint2::Shell>& shells);
109+
110+
111+
size_t nbasis(const std::vector<libint2::Shell>& shells);
112+
size_t max_nprim(const std::vector<libint2::Shell>& shells);
113+
int max_l(const std::vector<libint2::Shell>& shells);
114+
std::vector<size_t> map_shell_to_basis_function(const std::vector<libint2::Shell>& shells);
115+
116+
using real_t = libint2::scalar_type;
117+
typedef Eigen::Matrix<real_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Matrix;
118+
119+
MATRIX compute_1body_ints(const std::vector<libint2::Shell>& shells_1, const std::vector<libint2::Shell>& shells_2,libint2::Operator obtype);
120+
MATRIX compute_1body_ints_parallel(const std::vector<libint2::Shell>& shells_1, const std::vector<libint2::Shell>& shells_2,libint2::Operator obtype);
121+
MATRIX compute_overlaps(const std::vector<libint2::Shell>& shells_1, const std::vector<libint2::Shell>& shells_2, int number_of_threads);
122+
MATRIX compute_overlaps_serial(const std::vector<libint2::Shell>& shells_1, const std::vector<libint2::Shell>& shells_2);
123+
124+
125+
126+
typedef std::vector< libint2::Shell > libint2_ShellList; ///< Data type that holds a vector of libint2::Shell objects
127+
128+
129+
130+
}// namespace liblibint2_wrappers
131+
}// namespace liblibra
132+
133+
134+
135+
#endif // LIBINT2_WRAPPERS_H

backup/liblibint2_wrappers.cpp

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*********************************************************************************
2+
* Copyright (C) 2021 Mohammad Shakiba and Alexey V. Akimov
3+
*
4+
* This file is distributed under the terms of the GNU General Public License
5+
* as published by the Free Software Foundation, either version 3 of
6+
* the License, or (at your option) any later version.
7+
* See the file LICENSE in the root directory of this distribution
8+
* or <http://www.gnu.org/licenses/>.
9+
*
10+
*********************************************************************************/
11+
/**
12+
\file liblibint2_wrappers.cpp
13+
\brief The file implements Python export function
14+
15+
*/
16+
17+
#define BOOST_PYTHON_MAX_ARITY 30
18+
#include <boost/python.hpp>
19+
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
20+
21+
#include "libint2_wrappers.h"
22+
23+
24+
/// liblibra namespace
25+
namespace liblibra{
26+
27+
using namespace boost::python;
28+
using namespace liblinalg;
29+
using namespace libspecialfunctions;
30+
31+
32+
33+
/// libqobjects namespace
34+
namespace liblibint2_wrappers{
35+
36+
37+
38+
39+
void export_libint2_wrappers_objects(){
40+
/**
41+
\brief Exporter of liblibint2_wrappers classes and functions
42+
43+
*/
44+
/*
45+
double (*expt_electron_repulsion_integral_AO_v2)
46+
( AO& AOa, AO& AOb, AO& AOc, AO& AOd, int is_normalize ) = &electron_repulsion_integral;
47+
boost::python::list (*expt_electron_repulsion_integral_AO_v3)
48+
( AO& AOa, AO& AOb, AO& AOc, AO& AOd, int is_normalize, int is_derivs) = &electron_repulsion_integral;
49+
50+
// ============ Now export functions =============
51+
// Overlaps
52+
def("gaussian_overlap", expt_gaussian_overlap_G_v1);
53+
54+
55+
void (PrimitiveG::*expt_set_position_PrimitiveG_v1)(VECTOR) = &PrimitiveG::set_position;
56+
void (AO::*expt_set_position_AO_v1)(VECTOR) = &AO::set_position;
57+
58+
59+
*/
60+
61+
size_t (*expt_nbasis_v1)(const std::vector<libint2::Shell>& shells) = &nbasis;
62+
def("nbasis", expt_nbasis_v1);
63+
64+
65+
std::vector<libint2::Shell> (*expt_initialize_shell_v1)(
66+
int l_val, bool is_spherical , const std::vector<double>& exponents,
67+
const std::vector<double>& coeff, VECTOR& coords) = &initialize_shell;
68+
69+
def("initialize_shell", expt_initialize_shell_v1);
70+
71+
72+
void (*expt_add_to_shell_v1)(std::vector<libint2::Shell>& shells,
73+
int l_val, bool is_spherical , const std::vector<double>& exponents,
74+
const std::vector<double>& coeff, VECTOR& coords) = &add_to_shell;
75+
76+
def("add_to_shell", expt_add_to_shell_v1);
77+
78+
79+
void (*expt_print_shells_v1)(std::vector<libint2::Shell>& shells) = &print_shells;
80+
def("print_shell", expt_print_shells_v1);
81+
82+
83+
class_<libint2::Shell>("libint2_Shell",init<>())
84+
.def(init<const libint2::Shell&>())
85+
.def("__copy__", &generic__copy__<libint2::Shell>)
86+
.def("__deepcopy__", &generic__deepcopy__<libint2::Shell>)
87+
.def_readwrite("alpha",&libint2::Shell::alpha)
88+
.def_readwrite("contr",&libint2::Shell::contr)
89+
//.def("init",&PrimitiveG::init)
90+
;
91+
92+
class_< libint2_ShellList >("libint2_ShellList")
93+
.def(vector_indexing_suite< libint2_ShellList >())
94+
;
95+
96+
class_<Matrix>("Matrix",init<>())
97+
.def("__copy__", &generic__copy__<Matrix>)
98+
.def("__deepcopy__", &generic__deepcopy__<Matrix>)
99+
;
100+
101+
MATRIX (*expt_compute_overlaps_v1)
102+
(const std::vector<libint2::Shell>& shells_1,
103+
const std::vector<libint2::Shell>& shells_2, int number_of_threads) = &compute_overlaps;
104+
105+
def("compute_overlaps", expt_compute_overlaps_v1);
106+
107+
MATRIX (*expt_compute_overlaps_serial_v1)
108+
(const std::vector<libint2::Shell>& shells_1, const std::vector<libint2::Shell>& shells_2) = &compute_overlaps_serial;
109+
def("compute_overlaps_serial", expt_compute_overlaps_serial_v1);
110+
111+
112+
113+
/**
114+
class_<libint2::Operator>("libint2_Operator",init<>())
115+
.def(init<const libint2::Operator&>())
116+
.def("__copy__", &generic__copy__<libint2::Operator>)
117+
.def("__deepcopy__", &generic__deepcopy__<libint2::Operator>)
118+
//.def_readwrite("x_exp",&PrimitiveG::x_exp)
119+
.def("nbasis",&libint2::Operator::nbasis)
120+
;
121+
122+
*/
123+
/*
124+
py::class_<libint2::Operator>(m, "Operator");
125+
m.def("nbasis", &nbasis, "A function for number of basis sets", py::return_value_policy::reference_internal);
126+
m.def("compute_1body_ints_parallel", &compute_1body_ints_parallel, "A function for computing AO overlaps parallel", py::return_value_policy::reference_internal);
127+
m.def("compute_1body_ints", &compute_1body_ints, "A function for computing integrals serial", py::return_value_policy::reference_internal);
128+
m.def("initialize_shell", &initialize_shell, "A function for creating shells", py::return_value_policy::reference_internal);
129+
m.def("initialize_atom", &initialize_atom, "A function for initializing Atom", py::return_value_policy::reference_internal);
130+
m.def("add_to_shell", &add_to_shell, "A function to add the exponents, contraction coefficients, and Atom structure to a predefined shell", py::return_value_policy::reference_internal);
131+
m.def("print_shell", &print_shell, "A function for printing a shell", py::return_value_policy::reference_internal);
132+
m.def("compute_overlaps", &compute_overlaps, "A function that computes overlaps between pairs of shells", py::return_value_policy::reference_internal);
133+
134+
*/
135+
136+
}
137+
138+
139+
#ifdef CYGWIN
140+
BOOST_PYTHON_MODULE(cyglibint2_wrappers){
141+
#else
142+
BOOST_PYTHON_MODULE(liblibint2_wrappers){
143+
#endif
144+
145+
// Register converters:
146+
// See here: https://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/
147+
//to_python_converter<std::vector<DATA>, VecToList<DATA> >();
148+
149+
export_libint2_wrappers_objects();
150+
151+
}
152+
153+
154+
}// namespace libqobject
155+
}// namespace liblibra
156+

backup/liblibint2_wrappers.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*********************************************************************************
2+
* Copyright (C) 2021 Mohammad Shakiba and Alexey V. Akimov
3+
*
4+
* This file is distributed under the terms of the GNU General Public License
5+
* as published by the Free Software Foundation, either version 3 of
6+
* the License, or (at your option) any later version.
7+
* See the file LICENSE in the root directory of this distribution
8+
* or <http://www.gnu.org/licenses/>.
9+
*
10+
*********************************************************************************/
11+
/**
12+
\file liblibint2_wrappers.h
13+
\brief The file describes Python export function
14+
15+
*/
16+
17+
#ifndef LIB_LIBINT2_WRAPPERS_H
18+
#define LIB_LIBINT2_WRAPPERS_H
19+
20+
#include "libint2_wrappers.h"
21+
22+
/// liblibra namespace
23+
namespace liblibra{
24+
25+
26+
/// liblibint2_wrappers namespace
27+
namespace liblibint2_wrappers{
28+
29+
30+
void export_libint2_wrappers_objects();
31+
32+
33+
}// namespace libqobjects
34+
}// namespace liblibra
35+
36+
37+
38+
#endif// LIB_LIBINT2_WRAPPERS_H

0 commit comments

Comments
 (0)