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 Utils::CalculationRoutines::setLog(*calc,
true,
true, !silentCalculator);
70 if (!calc->results().has<Utils::Property::BondOrderMatrix>()) {
71 calc->setRequiredProperties(Utils::Property::BondOrderMatrix | Utils::Property::Energy);
73 calc->calculate(
name());
74 if (!calc->results().get<Utils::Property::SuccessfulCalculation>()) {
75 throw std::runtime_error(
name() +
" was not successful");
83 <<
" " +
name() +
" was not successful with error:\n " + boost::current_exception_diagnostic_information()
89 auto energy = calc->results().get<Utils::Property::Energy>();
90 auto bos = calc->results().get<Utils::Property::BondOrderMatrix>();
93 auto cout = _logger->output;
94 cout.printf(
" The (electronic) energy is: %+16.9f hartree\n\n\n", energy);
95 cout <<
" Showing all bond orders >0.3 a.u.:\n\n";
96 cout <<
" Atom#1 Atom#2 Bond Order\n\n";
97 const auto& mat = bos.getMatrix();
98 for (
int i = 0; i < mat.outerSize(); i++) {
99 for (
typename Eigen::SparseMatrix<double>::InnerIterator it(mat, i); it; ++it) {
100 if (it.value() > 0.3 && it.row() < it.col()) {
101 cout.printf(
" %6d %6d %+16.9f\n", it.row(), it.col(), it.value());
108 if (!_output.empty()) {
109 systems[_output.front()] = std::move(calc);
112 systems[_input.front()] = std::move(calc);
122 #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:104
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:82
static std::ostream & nl(std::ostream &os)
void warningIfMultipleInputsGiven() const
Warn if more than one input system was specified.
Definition: Task.h:95
const std::vector< std::string > & output() const
Getter for the names of the output systems generated by this task.
Definition: Task.h:89
The base class for all tasks in Readuct.
Definition: Task.h:28