Repository navigation
Expand file tree
/
Copy pathpy_numerical_radial.cpp
More file actions
168 lines (160 loc) · 6.85 KB
/
Copy pathpy_numerical_radial.cpp
File metadata and controls
168 lines (160 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include "source_basis/module_nao/numerical_radial.h"
namespace py = pybind11;
using namespace pybind11::literals;
template <typename... Args>
using overload_cast_ = pybind11::detail::overload_cast_impl<Args...>;
void bind_numerical_radial(py::module& m)
{
// Create the submodule for NumericalRadial
py::module m_numerical_radial = m.def_submodule("NumericalRadial");
py::class_<NumericalRadial>(m_numerical_radial, "NumericalRadial")
.def(py::init<>())
.def(
"build",
[](NumericalRadial& self,
const int l,
const bool for_r_space,
const int ngrid,
py::array_t<double> grid,
py::array_t<double> value,
const int p = 0,
const int izeta = 0,
const std::string symbol = "",
const int itype,
const bool init_sbt = true) {
py::buffer_info grid_info = grid.request();
py::buffer_info value_info = value.request();
if (grid_info.ndim != 1 || value_info.ndim != 1)
{
throw std::runtime_error("Input arrays must be 1-dimensional");
}
if (grid_info.shape[0] != value_info.shape[0])
{
throw std::runtime_error("Grid and value arrays must have the same size");
}
self.build(l,
for_r_space,
grid_info.shape[0],
static_cast<double*>(grid_info.ptr),
static_cast<double*>(value_info.ptr),
p,
izeta,
symbol,
itype,
init_sbt);
},
"l"_a,
"for_r_space"_a,
"ngrid"_a,
"grid"_a,
"value"_a,
"p"_a = 0,
"izeta"_a = 0,
"symbol"_a = "",
"itype"_a = 0,
"init_sbt"_a = true)
// leave set_transformer for future since no wrapper for Transformer yet
.def(
"set_grid",
[](NumericalRadial& self,
const bool for_r_space,
const int ngrid,
py::array_t<double> grid,
const char mode) {
py::buffer_info grid_info = grid.request();
if (grid_info.ndim != 1)
{
throw std::runtime_error("Input array must be 1-dimensional");
}
self.set_grid(for_r_space, ngrid, static_cast<double*>(grid_info.ptr), mode);
},
"for_r_space"_a,
"ngrid"_a,
"grid"_a,
"mode"_a = 'i')
.def("set_uniform_grid",
&NumericalRadial::set_uniform_grid,
"for_r_space"_a,
"ngrid"_a,
"cutoff"_a,
"mode"_a = 'i',
"enable+fft"_a = false)
.def(
"set_value",
[](NumericalRadial& self, const bool for_r_space, py::array_t<double> value, const int p) {
py::buffer_info value_info = value.request();
if (value_info.ndim != 1)
{
throw std::runtime_error("Input array must be 1-dimensional");
}
self.set_value(for_r_space, static_cast<double*>(value_info.ptr), p);
},
"for_r_space"_a,
"value"_a,
"p"_a)
.def("wipe", &NumericalRadial::wipe, "r_space"_a = true, "k_space"_a = true)
.def(
"radtab",
[](NumericalRadial& self,
const char op,
NumericalRadial& ket,
const int l,
py::array_t<double> table,
const int nr_tab,
const double rmax_tab,
const bool deriv) {
py::buffer_info table_info = table.request();
if (table_info.ndim != 1)
{
throw std::runtime_error("Table array must be 1-dimensional");
}
self.radtab(op, ket, l, static_cast<double*>(table_info.ptr), nr_tab, rmax_tab, deriv);
},
"op"_a,
"ket"_a,
"l"_a,
"table"_a,
"nr_tab"_a,
"rmax_tab"_a,
"deriv"_a = false)
.def("normalize", &NumericalRadial::normalize, "for_r_space"_a = true)
// Getters
.def_property_readonly("symbol", &NumericalRadial::symbol)
.def_property_readonly("itype", &NumericalRadial::itype)
.def_property_readonly("izeta", &NumericalRadial::izeta)
.def_property_readonly("l", &NumericalRadial::l)
.def_property_readonly("nr", &NumericalRadial::nr)
.def_property_readonly("nk", &NumericalRadial::nk)
.def_property_readonly("rcut", &NumericalRadial::rcut)
.def_property_readonly("kcut", &NumericalRadial::kcut)
.def_property_readonly("rgrid",
[](NumericalRadial& self) {
const double* rgrid = self.rgrid();
return py::array_t<double>({self.nr()}, rgrid);
})
.def_property_readonly("kgrid",
[](NumericalRadial& self) {
const double* kgrid = self.kgrid();
return py::array_t<double>({self.nk()}, kgrid);
})
.def_property_readonly("rvalue",
[](NumericalRadial& self) {
const double* rvalue = self.rvalue();
return py::array_t<double>({self.nr()}, rvalue);
})
.def_property_readonly("kvalue",
[](NumericalRadial& self) {
const double* kvalue = self.kvalue();
return py::array_t<double>({self.nk()}, kvalue);
})
.def_property_readonly("pr", &NumericalRadial::pr)
.def_property_readonly("pk", &NumericalRadial::pk)
.def_property_readonly("is_fft_compliant", overload_cast_<>()(&NumericalRadial::is_fft_compliant, py::const_))
// leave transformer for future
.def_property_readonly("rgrid", overload_cast_<int>()(&NumericalRadial::rgrid, py::const_))
.def_property_readonly("kgrid", overload_cast_<int>()(&NumericalRadial::kgrid, py::const_))
.def_property_readonly("rvalue", overload_cast_<int>()(&NumericalRadial::rvalue, py::const_))
.def_property_readonly("kvalue", overload_cast_<int>()(&NumericalRadial::kvalue, py::const_));
}