votca 2024.1-dev
Loading...
Searching...
No Matches
mapchecker.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 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_MAPCHECKER_H
22#define VOTCA_XTP_MAPCHECKER_H
23
24// VOTCA includes
26
27// Local VOTCA includes
30
31namespace votca {
32namespace xtp {
33
34class MapChecker final : public QMCalculator {
35 public:
36 MapChecker() = default;
37
38 ~MapChecker() = default;
39
40 std::string Identify() const { return "mapchecker"; }
41 bool WriteToStateFile() const { return false; }
42
43 protected:
44 void ParseOptions(const tools::Property& user_options);
45 bool Evaluate(Topology& top);
46
47 private:
48 std::string AddSteptoFilename(const std::string& filename, Index step) const;
49 std::string AddStatetoFilename(const std::string& filename,
50 QMState state) const;
51
52 std::vector<QMState> StringToStates(const std::string& states_string) const;
53
54 std::string segmentfile_;
55 std::string qmfile_;
56 std::string mpfile_;
57 std::string mapfile_ = "";
58
59 std::vector<QMState> qmstates_;
60 std::vector<QMState> mdstates_;
61};
62
64
65 segmentfile_ = options.get(".md_pdbfile").as<std::string>();
66
67 qmfile_ = options.get(".qm_pdbfile").as<std::string>();
68
69 mpfile_ = options.get(".mp_pdbfile").as<std::string>();
70
71 qmstates_ = options.get(".qm_states").as<std::vector<QMState>>();
72
73 mdstates_ = options.get(".mp_states").as<std::vector<QMState>>();
74 if (!(qmstates_.empty() && mdstates_.empty())) {
75 mapfile_ = options.get(".map_file").as<std::string>();
76 }
77}
78
79std::string MapChecker::AddStatetoFilename(const std::string& filename,
80 QMState state) const {
81 std::string base = tools::filesystem::GetFileBase(filename);
82 std::string fileending = tools::filesystem::GetFileExtension(filename);
83 std::string filename_comp = base + "_" + state.ToString() + "." + fileending;
84 return filename_comp;
85}
86
88 std::cout << std::endl;
89 std::string filename = AddSteptoFilename(segmentfile_, top.getStep());
90 std::cout << "Writing segments to " << filename << std::endl;
91 top.WriteToPdb(filename);
92
93 Logger log;
95 log.setCommonPreface("\n... ...");
96
97 QMMapper map(log);
98
99 for (QMState state : qmstates_) {
100 map.LoadMappingFile(mapfile_);
101 std::string filename_qm = AddStatetoFilename(qmfile_, state);
102 csg::PDBWriter qmwriter;
103 std::string filename_qm_state =
104 AddSteptoFilename(filename_qm, top.getStep());
105 std::cout << "Writing qmmolecules to " << filename_qm_state << std::endl;
106 qmwriter.Open(filename_qm_state, false);
107 qmwriter.WriteHeader("QMFrame:" + std::to_string(top.getStep()) +
108 " state:" + state.ToString());
109 qmwriter.WriteBox(top.getBox() * tools::conv::bohr2ang);
110 for (const Segment& seg : top.Segments()) {
111 QMMolecule mol = map.map(seg, state);
112 qmwriter.WriteContainer(mol);
113 }
114 qmwriter.Close();
115 }
116
117 PolarMapper mp(log);
118 for (QMState state : mdstates_) {
120 std::string filename_mp = AddStatetoFilename(mpfile_, state);
121 csg::PDBWriter mpwriter;
122 std::string filename_mp_state =
123 AddSteptoFilename(filename_mp, top.getStep());
124 std::cout << "Writing polarsegments to " << filename_mp_state << std::endl;
125 mpwriter.Open(filename_mp_state, false);
126 mpwriter.WriteHeader("MPFrame:" + std::to_string(top.getStep()) +
127 " state:" + state.ToString());
128 mpwriter.WriteBox(top.getBox() * tools::conv::bohr2ang);
129 for (const Segment& seg : top.Segments()) {
130 PolarSegment mol = mp.map(seg, state);
131 mpwriter.WriteContainer(mol);
132 }
133 mpwriter.Close();
134 }
135
136 return true;
137}
138
139std::string MapChecker::AddSteptoFilename(const std::string& filename,
140 Index step) const {
141 std::string base = tools::filesystem::GetFileBase(filename);
142 std::string fileending = tools::filesystem::GetFileExtension(filename);
143 std::string filename_comp =
144 base + "_step_" + std::to_string(step) + "." + fileending;
145 return filename_comp;
146}
147
148} // namespace xtp
149} // namespace votca
150
151#endif // VOTCA_XTP_MAPCHECKER_H
void WriteHeader(std::string header)
Definition pdbwriter.cc:41
void WriteBox(const Eigen::Matrix3d &box)
Definition pdbwriter.cc:62
void Close() override
Definition pdbwriter.cc:51
void WriteContainer(T &container)
Definition pdbwriter.h:102
void Open(std::string file, bool bAppend=false) override
Definition pdbwriter.cc:33
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
Logger is used for thread-safe output of messages.
Definition logger.h:164
void setReportLevel(Log::Level ReportLevel)
Definition logger.h:185
void setCommonPreface(const std::string &preface)
Definition logger.h:198
std::string segmentfile_
Definition mapchecker.h:54
std::string Identify() const
Calculator name.
Definition mapchecker.h:40
std::string AddSteptoFilename(const std::string &filename, Index step) const
Definition mapchecker.h:139
std::vector< QMState > StringToStates(const std::string &states_string) const
bool WriteToStateFile() const
Definition mapchecker.h:41
std::string AddStatetoFilename(const std::string &filename, QMState state) const
Definition mapchecker.h:79
std::vector< QMState > qmstates_
Definition mapchecker.h:59
std::vector< QMState > mdstates_
Definition mapchecker.h:60
bool Evaluate(Topology &top)
Definition mapchecker.h:87
void ParseOptions(const tools::Property &user_options)
Definition mapchecker.h:63
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:132
std::string ToString() const
Definition qmstate.cc:146
void LoadMappingFile(const std::string &mapfile)
AtomContainer map(const Segment &seg, const SegId &segid) const
Container for segments and box and atoms.
Definition topology.h:41
Index getStep() const
Definition topology.h:75
std::vector< Segment > & Segments()
Definition topology.h:58
const Eigen::Matrix3d & getBox() const
Definition topology.h:64
void WriteToPdb(std::string filename) const
Definition topology.cc:171
const double bohr2ang
Definition constants.h:49
std::string GetFileBase(const std::string &filename)
Definition filesystem.cc:42
std::string GetFileExtension(const std::string &filename)
Definition filesystem.cc:34
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
static Level current_level
Definition globals.h:30