• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

adc-connect / adcc / 11687183074

05 Nov 2024 03:20PM UTC coverage: 73.291% (-0.5%) from 73.743%
11687183074

Pull #169

github

web-flow
Merge e14f10df3 into e2e1bce49
Pull Request #169: Additional operator integrals and selection of gauge origin

1166 of 1868 branches covered (62.42%)

Branch coverage included in aggregate %.

132 of 233 new or added lines in 12 files covered. (56.65%)

5 existing lines in 3 files now uncovered.

7313 of 9701 relevant lines covered (75.38%)

271899.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.67
/libadcc/pyiface/export_ReferenceState.cc
1
//
2
// Copyright (C) 2018 by the adcc authors
3
//
4
// This file is part of adcc.
5
//
6
// adcc 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
// adcc 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 adcc. If not, see <http://www.gnu.org/licenses/>.
18
//
19

20
#include "../ReferenceState.hh"
21
#include "hartree_fock_solution_hack.hh"
22
#include <pybind11/numpy.h>
23
#include <pybind11/pybind11.h>
24
#include <pybind11/stl.h>
25

26
namespace libadcc {
27
namespace py = pybind11;
28

29
py::object convert_timer(const Timer& timer) {
932✔
30
  // Determine the shift between the C++ and the python clocks
31
  py::object pynow         = py::module::import("time").attr("perf_counter");
1,864✔
32
  const double clock_shift = pynow().cast<double>() - Timer::now();
932✔
33

34
  // Shift the data and convert to python
35
  py::dict shifted_intervals;
932✔
36
  for (const auto& kv : timer.intervals) {
14,660✔
37
    py::list intlist;
13,728✔
38
    for (const auto& p : kv.second) {
27,456✔
39
      intlist.append(py::make_tuple(clock_shift + p.first, clock_shift + p.second));
13,728✔
40
    }
41
    shifted_intervals[py::cast(kv.first)] = intlist;
13,728✔
42
  }
13,728✔
43
  py::dict shifted_start_times;
932✔
44
  for (const auto& kv : timer.start_times) {
932✔
45
    shifted_start_times[py::cast(kv.first)] = kv.second + clock_shift;
×
46
  }
47

48
  py::object pyTimer            = py::module::import("adcc.timings").attr("Timer");
1,864✔
49
  py::object ret                = pyTimer();
932✔
50
  ret.attr("raw_data")          = shifted_intervals;
932✔
51
  ret.attr("start_times")       = shifted_start_times;
932✔
52
  ret.attr("time_construction") = timer.time_construction + clock_shift;
932✔
53
  return ret;
1,864✔
54
}
932✔
55

56
void export_ReferenceState(py::module& m) {
5✔
57

58
  py::class_<ReferenceState, std::shared_ptr<ReferenceState>>(
5✔
59
        m, "ReferenceState",
60
        "Class representing information about the reference state for adcc. Python "
61
        "binding to"
62
        ":cpp:class:`libadcc::ReferenceState`.")
63
        .def(py::init<std::shared_ptr<const HartreeFockSolution_i>,
5✔
64
                      std::shared_ptr<const MoSpaces>, bool>(),
5✔
65
             "Setup a ReferenceStateject using an MoSpaces object.\n"
66
             "\n"
67
             "hfsoln_ptr        Pointer to the Interface to the host program,\n"
68
             "                  providing the HartreeFockSolution data, which\n"
69
             "                  will be provided by this object.\n"
70
             "mo_ptr            MoSpaces object containing info about the MoSpace setup\n"
71
             "                  and the point group symmetry.\n"
72
             "symmetry_check_on_import\n"
73
             "                  Should symmetry of the imported objects be checked\n"
74
             "                  explicitly during the import process. This massively "
75
             "slows\n"
76
             "                  down the import process and has a dramatic impact on "
77
             "memory\n"
78
             "                  usage and should thus only be used for debugging import "
79
             "routines\n"
80
             "                  from the host programs. Do not enable this unless you "
81
             "know\n"
82
             "                  that you really want to.\n")
83
        .def_property_readonly("restricted", &ReferenceState::restricted,
5✔
84
                               "Return whether the reference is restricted or not.")
85
        .def_property_readonly(
10✔
86
              "spin_multiplicity", &ReferenceState::spin_multiplicity,
5✔
87
              "Return the spin multiplicity of the reference state. 0 indicates "
88
              "that the spin cannot be determined or is not integer (e.g. UHF)")
89
        .def_property_readonly("has_core_occupied_space",
10✔
90
                               &ReferenceState::has_core_occupied_space,
5✔
91
                               "Is a core occupied space setup, such that a core-valence "
92
                               "separation can be applied.")
93
        .def_property_readonly("irreducible_representation",
10✔
94
                               &ReferenceState::irreducible_representation,
5✔
95
                               "Reference state irreducible representation")
96
        .def_property_readonly("mospaces", &ReferenceState::mospaces_ptr,
5✔
97
                               "The MoSpaces object supplied on initialisation")
98
        .def_property_readonly(
10✔
99
              "backend", &ReferenceState::backend,
5✔
100
              "The identifier of the back end used for the SCF calculation.")
101
        .def_property_readonly("n_orbs", &ReferenceState::n_orbs,
5✔
102
                               "Number of molecular orbitals")
103
        .def_property_readonly("n_orbs_alpha", &ReferenceState::n_orbs_alpha,
5✔
104
                               "Number of alpha orbitals")
105
        .def_property_readonly("n_orbs_beta", &ReferenceState::n_orbs_beta,
5✔
106
                               "Number of beta orbitals")
107
        .def_property_readonly("n_alpha", &ReferenceState::n_alpha,
5✔
108
                               "Number of alpha electrons")
109
        .def_property_readonly("n_beta", &ReferenceState::n_beta,
5✔
110
                               "Number of beta electrons")
111
        .def_property_readonly(
5✔
112
              "nuclear_total_charge",
113
              [](const ReferenceState& ref) { return ref.nuclear_multipole(0)[0]; })
44✔
114
        .def_property_readonly("nuclear_dipole",
5✔
115
                               [](const ReferenceState& ref) {
418✔
116
                                 py::array_t<scalar_type> ret(std::vector<ssize_t>{3});
836✔
117
                                 auto res = ref.nuclear_multipole(1);
836✔
118
                                 std::copy(res.begin(), res.end(), ret.mutable_data());
418✔
119
                                 return res;
836✔
120
                               })
418✔
121
        .def("nuclear_quadrupole",
5✔
NEW
122
             [](const ReferenceState& ref, py::list gauge_origin) {
×
NEW
123
               py::array_t<scalar_type> ret(std::vector<ssize_t>{6});
×
124
               auto res = ref.nuclear_multipole(
NEW
125
                     2, py::cast<std::vector<scalar_type>>(gauge_origin));
×
NEW
126
               std::copy(res.begin(), res.end(), ret.mutable_data());
×
NEW
127
               return res;
×
NEW
128
             })
×
129
        .def("determine_gauge_origin", &ReferenceState::determine_gauge_origin,
5✔
130
             "Determine the gauge origin.")
131
        .def_property_readonly("conv_tol", &ReferenceState::conv_tol,
5✔
132
                               "SCF convergence tolererance")
133
        .def_property_readonly("energy_scf", &ReferenceState::energy_scf,
5✔
134
                               "Final total SCF energy")
135
        //
136
        .def("orbital_energies", &ReferenceState::orbital_energies,
5✔
137
             "Return the orbital energies corresponding to the provided space")
138
        .def("orbital_coefficients", &ReferenceState::orbital_coefficients,
5✔
139
             "Return the molecular orbital coefficients corresponding to the provided "
140
             "space (alpha and beta coefficients are returned)")
141
        .def("orbital_coefficients_alpha", &ReferenceState::orbital_coefficients_alpha,
5✔
142
             "Return the alpha molecular orbital coefficients corresponding to the "
143
             "provided space")
144
        .def("orbital_coefficients_beta", &ReferenceState::orbital_coefficients_beta,
5✔
145
             "Return the beta molecular orbital coefficients corresponding to the "
146
             "provided space")
147
        .def("fock", &ReferenceState::fock,
5✔
148
             "Return the Fock matrix block corresponding to the provided space.")
149
        .def("eri", &ReferenceState::eri,
5✔
150
             "Return the ERI (electron-repulsion integrals) tensor block corresponding "
151
             "to the provided space.")
152
        //
153
        .def("import_all", &ReferenceState::import_all,
5✔
154
             "Normally the class only imports the Fock matrix blocks and "
155
             "electron-repulsion integrals of a particular space combination when this "
156
             "is requested by a call to above fock() or eri() functions. This function "
157
             "call, however, instructs the class to immediately import *all* such "
158
             "blocks. Typically you do not want to do this.")
159
        .def_property("cached_fock_blocks", &ReferenceState::cached_fock_blocks,
×
160
                      &ReferenceState::set_cached_fock_blocks,
5✔
161
                      "Get or set the list of momentarily cached Fock matrix blocks\n"
162
                      "\n"
163
                      "Setting this property allows to drop fock matrix blocks if they "
164
                      "are no longer needed to save memory.")
165
        .def_property("cached_eri_blocks", &ReferenceState::cached_eri_blocks,
×
166
                      &ReferenceState::set_cached_eri_blocks,
5✔
167
                      "Get or set the list of momentarily cached ERI tensor blocks\n"
168
                      "\n"
169
                      "Setting this property allows to drop ERI tensor blocks if they "
170
                      "are no longer needed to save memory.")
171
        .def("flush_hf_cache", &ReferenceState::flush_hf_cache,
5✔
172
             "Tell the contained HartreeFockSolution_i object (which was passed upon "
173
             "construction), that a larger amount of import operations is done and that "
174
             "the next request for further imports will most likely take some time, such "
175
             "that intermediate caches can now be flushed to save some memory or other "
176
             "resources.")
177
        .def_property_readonly(
5✔
178
              "timer",
179
              [](const ReferenceState& self) { return convert_timer(self.timer()); },
932✔
180
              "Obtain the timer object of this class.")
181
        //
182
        ;
183
}
5✔
184

185
}  // namespace libadcc
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc