7 #ifndef READUCT_BONDORDERTASK_H_
8 #define READUCT_BONDORDERTASK_H_
16 #include "boost/exception/diagnostic_information.hpp"
17 #include <boost/filesystem.hpp>
38 :
Task(std::move(input), std::move(output), std::move(logger)) {
41 std::string
name()
const override {
42 return "Bond Order Calculation";
47 observers = {})
const final {
52 bool stopOnError = stopOnErrorExtraction(taskSettings);
53 bool silentCalculator = taskSettings.extract(
"silent_stdout_calculator",
true);
54 if (!taskSettings.empty()) {
55 throw std::logic_error(falseTaskSettingsErrorMessage(
name()));
57 if (observers.size() > 0) {
58 throw std::logic_error(
"BondOrderTask does not feature algorithm accepting observers, yet one was given");
66 auto calc = copyCalculator(systems, _input.front(),
name());
67 const auto previousResults = calc->results();
68 Utils::CalculationRoutines::setLog(*calc,
true,
true, !silentCalculator);
71 if (!calc->results().has<Utils::Property::BondOrderMatrix>()) {
72 calc->setRequiredProperties(Utils::Property::BondOrderMatrix | Utils::Property::Energy);
74 calc->calculate(
name());
75 if (!calc->results().get<Utils::Property::SuccessfulCalculation>()) {
76 throw std::runtime_error(
name() +
" was not successful");
84 <<
" " +
name() +
" was not successful with error:\n " + boost::current_exception_diagnostic_information()
86 calc->results() = previousResults + calc->results();
91 auto energy = calc->results().get<Utils::Property::Energy>();
92 auto bos = calc->results().get<Utils::Property::BondOrderMatrix>();
95 auto cout = _logger->output;
96 cout.printf(
" The (electronic) energy is: %+16.9f hartree\n\n\n", energy);
97 cout <<
" Showing all bond orders >0.3 a.u.:\n\n";
98 cout <<
" Atom#1 Atom#2 Bond Order\n\n";
99 const auto& mat = bos.getMatrix();
100 for (
int i = 0; i < mat.outerSize(); i++) {
101 for (
typename Eigen::SparseMatrix<double>::InnerIterator it(mat, i); it; ++it) {
102 if (it.value() > 0.3 && it.row() < it.col()) {
103 cout.printf(
" %6d %6d %+16.9f\n", it.row(), it.col(), it.value());
109 calc->results() = previousResults + calc->results();
111 if (!_output.empty()) {
112 systems[_output.front()] = std::move(calc);
115 systems[_input.front()] = std::move(calc);
125 #endif // READUCT_BONDORDERTASK_H_
BondOrderTask(std::vector< std::string > input, std::vector< std::string > output, std::shared_ptr< Core::Log > logger=nullptr)
Construct a new BondOrderTask.
Definition: BondOrderTask.h:37
void warningIfMultipleOutputsGiven() const
Warn if more than one output system was specified.
Definition: Task.h:107
std::string name() const override
Getter for the tasks name.
Definition: BondOrderTask.h:41
static std::ostream & endl(std::ostream &os)
bool run(SystemsMap &systems, Utils::UniversalSettings::ValueCollection taskSettings, bool testRunOnly=false, std::vector< std::function< void(const int &, const Utils::AtomCollection &, const Utils::Results &, const std::string &)>> observers={}) const final
Executes the actual task represented by this class.
Definition: BondOrderTask.h:45
Definition: BondOrderTask.h:26
const std::vector< std::string > & input() const
Getter for the expected names of the input systems.
Definition: Task.h:85
static std::ostream & nl(std::ostream &os)
void warningIfMultipleInputsGiven() const
Warn if more than one input system was specified.
Definition: Task.h:98
const std::vector< std::string > & output() const
Getter for the names of the output systems generated by this task.
Definition: Task.h:92
The base class for all tasks in Readuct.
Definition: Task.h:29