votca 2024.2-dev
Loading...
Searching...
No Matches
log2mps.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2023 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_LOG2MPS_H
22#define VOTCA_XTP_LOG2MPS_H
23
24// Third party includes
25#include <boost/format.hpp>
26
27// Local VOTCA includes
30#include "votca/xtp/qmtool.h"
31
32namespace votca {
33namespace xtp {
34
35class Log2Mps final : public QMTool {
36 public:
37 Log2Mps() = default;
38 ~Log2Mps() = default;
39
40 std::string Identify() const { return "log2mps"; }
41
42 protected:
43 void ParseOptions(const tools::Property &user_options);
44 bool Run();
45
46 private:
47 std::string package_;
48 std::string logfile_;
49 std::string mpsfile_;
50};
51
53
55
56 package_ = options.get(".dftpackage").as<std::string>();
57
58 if (package_ == "xtp") {
59 throw std::runtime_error(
60 "XTP has no log file. For xtp package just run the partialcharges tool "
61 "on you .orb file");
62 }
63
64 logfile_ = options.ifExistsReturnElseReturnDefault<std::string>(
65 ".input", job_name_ + ".log");
66
67 mpsfile_ = options.ifExistsReturnElseReturnDefault<std::string>(
68 ".output", job_name_ + ".mps");
69
70 std::cout << "\n... ... " << logfile_ << " => " << mpsfile_ << "\n";
71}
72
74
75 // Logger (required for QM package, so we can just as well use it)
76 Logger log;
77 log.setCommonPreface("\n... ...");
79 log.setMultithreading(true);
80
81 // Set-up QM package
82 XTP_LOG(Log::error, log) << "Using package <" << package_ << ">"
83 << std::flush;
84
85 std::unique_ptr<QMPackage> qmpack =
86 std::unique_ptr<QMPackage>(QMPackageFactory().Create(package_));
87 qmpack->setLog(&log);
88 qmpack->setRunDir(".");
89 qmpack->setLogFileName(logfile_);
90
91 // Create orbitals, fill with life & extract QM atoms
92
93 StaticSegment atoms = qmpack->GetCharges();
94
95 // Sanity checks, total charge
96
97 if (atoms.size() < 1) {
98 throw std::runtime_error("ERROR No charges extracted from " + logfile_);
99 }
100
101 double Q = atoms.CalcTotalQ();
102 XTP_LOG(Log::error, log) << atoms.size()
103 << " QM atoms, total charge Q = " << Q << std::flush;
104
105 std::string tag =
106 "::LOG2MPS " + (boost::format("(log-file='%1$s' : %2$d QM atoms)") %
107 logfile_ % atoms.size())
108 .str();
109 atoms.WriteMPS(mpsfile_, tag);
110 return true;
111}
112
113} // namespace xtp
114} // namespace votca
115
116#endif // VOTCA_XTP_LOG2MPS_H
class to manage program options with xml serialization functionality
Definition property.h:55
Property & get(const std::string &key)
get existing property
Definition property.cc:79
T as() const
return value as type
Definition property.h:283
T ifExistsReturnElseReturnDefault(const std::string &key, T defaultvalue) const
Definition property.h:321
void WriteMPS(std::string filename, std::string header) const
std::string logfile_
Definition log2mps.h:48
std::string mpsfile_
Definition log2mps.h:49
void ParseOptions(const tools::Property &user_options)
Definition log2mps.h:52
std::string Identify() const
Calculator name.
Definition log2mps.h:40
std::string package_
Definition log2mps.h:47
Logger is used for thread-safe output of messages.
Definition logger.h:164
void setReportLevel(Log::Level ReportLevel)
Definition logger.h:185
void setMultithreading(bool maverick)
Definition logger.h:186
void setCommonPreface(const std::string &preface)
Definition logger.h:198
std::string job_name_
Definition qmtool.h:50
#define XTP_LOG(level, log)
Definition logger.h:40
base class for all analysis tools
Definition basebead.h:33
static Level current_level
Definition globals.h:30