votca 2026-dev
Loading...
Searching...
No Matches
interface.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2023 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
18#include "xtp_bind_tools.h"
19#include <iostream>
20#include <pybind11/complex.h>
21#include <pybind11/iostream.h>
22#include <pybind11/pybind11.h>
23#include <pybind11/stl.h>
24
25namespace py = pybind11;
26
27PYBIND11_MODULE(xtp_binds, module) {
28 module.doc() =
29 "VOTCA-XTP is a library which allows you to calculate the electronic "
30 "properties of organic materials,"
31 "https://votca.github.io";
32
33 module.def(
34 "call_calculator",
35 [](const std::string& name,
36 const std::map<std::string, std::string>& dict) {
37 py::scoped_ostream_redirect redirect_cout(
38 std::cout, py::module_::import("sys").attr("stdout"));
39 py::scoped_ostream_redirect redirect_cerr(
40 std::cerr, py::module_::import("sys").attr("stderr"));
41 // Release the GIL while VOTCA runs: OpenMP worker threads that
42 // write to std::cout go through the redirect above, whose sync()
43 // acquires the GIL. If this thread kept it while waiting for them
44 // (e.g. at a critical section), nthreads > 1 would deadlock. The
45 // redirects are destroyed after the GIL is re-acquired.
46 {
47 py::gil_scoped_release release;
48 pyxtp::call_calculator(name, dict);
49 }
50 },
51 R"pbdoc(
52 Invoke a Votca XTP calculator
53
54 Parameters
55 ----------
56 name
57 Calculator's name
58 dict
59 Calculator options
60 )pbdoc");
61
62 module.def(
63 "call_tool",
64 [](const std::string& name, Index nthreads, const std::string& xml_file) {
65 py::scoped_ostream_redirect redirect_cout(
66 std::cout, py::module_::import("sys").attr("stdout"));
67 py::scoped_ostream_redirect redirect_cerr(
68 std::cerr, py::module_::import("sys").attr("stderr"));
69 // Release the GIL while VOTCA runs: OpenMP worker threads that
70 // write to std::cout go through the redirect above, whose sync()
71 // acquires the GIL. If this thread kept it while waiting for them
72 // (e.g. at a critical section), nthreads > 1 would deadlock. The
73 // redirects are destroyed after the GIL is re-acquired.
74 {
75 py::gil_scoped_release release;
76 pyxtp::call_tool(name, nthreads, xml_file);
77 }
78 },
79 R"pbdoc(
80 Invoke a Votca XTP Tool
81
82 Parameters
83 ----------
84 name
85 Tool's name
86 threads
87 Number of threads to perform the computation
88 xml_file
89 Input file specification
90 )pbdoc");
91}
PYBIND11_MODULE(xtp_binds, module)
Definition interface.cc:27
void call_calculator(const std::string &calculatorName, const std::map< std::string, std::string > &dict)
Construct a new pybind11 module object to invoke a votca-xtp Calculator.
void call_tool(const std::string &calculatorName, Index nThreads, std::string xmlfile)
Construct a new pybind11 module object to invoke a votca-xtp QMTool.
Definition xtp_tools.cc:25