votca 2026-dev
Loading...
Searching...
No Matches
segmentmapper.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 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 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#pragma once
19#ifndef VOTCA_XTP_SEGMENTMAPPER_H
20#define VOTCA_XTP_SEGMENTMAPPER_H
21
22// Standard includes
23#include <type_traits>
24
25// VOTCA includes
26#include <votca/csg/pdbwriter.h>
28
29// Local VOTCA includes
30#include "classicalsegment.h"
31#include "logger.h"
32#include "qmmolecule.h"
33#include "segid.h"
34#include "topology.h"
35
36namespace votca {
37namespace xtp {
38template <class AtomContainer>
40 public:
42
43 void LoadMappingFile(const std::string& mapfile);
44
45 AtomContainer map(const Segment& seg, const SegId& segid) const;
46
47 AtomContainer map(const Segment& seg, QMState state) const;
48
49 AtomContainer map(const Segment& seg, const std::string& coordfilename) const;
50
51 private:
53
54 using atom_id = std::pair<Index, std::string>;
55
56 struct FragInfo {
57 std::vector<double> weights;
58 std::vector<atom_id> mapatom_ids;
59 std::vector<atom_id> mdatom_ids;
60 std::vector<Index> map_local_frame;
61 };
62
63 struct Seginfo {
64 std::pair<Index, Index> minmax;
65 std::vector<Index> mdatoms;
66 std::vector<FragInfo> fragments;
67 bool map2md;
68 std::string segname;
69 std::vector<double> weights;
70 std::vector<atom_id> mapatoms;
71 std::map<std::string, std::string> coordfiles;
72 // chargeresponse_<state>: .crm files of the charge-response model
73 // (polar segments only), next to multipoles_<state>
74 std::map<std::string, std::string> crfiles;
75 };
76
77 // Attaches the charge-response matrix of the state, if the mapping file
78 // has one, in the atom order of the mapped segment. No-op except for
79 // PolarSegment (specialized in segmentmapper.cc).
80 void AttachChargeResponse(AtomContainer&, const Seginfo&,
81 const QMState&) const {}
82 std::map<std::string, std::string> mapatom_xml_;
83 std::map<std::string, Seginfo> segment_info_;
84
86 Index atomid, const std::vector<mapAtom*>& fragment_mapatoms) const;
87
88 void ParseFragment(Seginfo& seginfo, const tools::Property& frag);
89
90 template <typename T>
91 Eigen::Vector3d CalcWeightedPos(const std::vector<double>& weights,
92 const T& atoms) const;
93
94 void PlaceMapAtomonMD(const std::vector<mapAtom*>& fragment_mapatoms,
95 const std::vector<const Atom*>& fragment_mdatoms) const;
96
97 void MapMapAtomonMD(const FragInfo& frag,
98 const std::vector<mapAtom*>& fragment_mapatoms,
99 const std::vector<const Atom*>& fragment_mdatoms) const;
100
101 // Transfers the external-bond direction of the MD atom, rotated by rot
102 // (no translation, a direction is translation invariant), and the ID of
103 // the segment the bond crosses into. No-op by default; only QMAtom has
104 // this interface (see the QMMolecule specialization below).
106 const Eigen::Matrix3d&) const {}
107
108 // Translates the MD-level bonded-partner IDs of md_atom into mapped IDs
109 // via the segment-wide lookup MD atom ID -> mapped atom, and adds them to
110 // map_atom. Partners outside the segment are skipped. No-op by default;
111 // specialized for QMMolecule below.
113 const std::map<Index, mapAtom*>&) const {}
114
115 // Rewrites the bonded-partner IDs of atom from template atom IDs to the
116 // IDs of the returned container (old_to_new). No-op by default;
117 // specialized for QMMolecule below.
118 void RemapBondedPartners(mapAtom&, const std::map<Index, Index>&) const {}
119
121 std::pair<Index, Index> CalcAtomIdRange(const Segment& seg) const;
122 std::pair<Index, Index> CalcAtomIdRange(const std::vector<Index>& seg) const;
123
124 atom_id StringToMapIndex(const std::string& map_string) const;
125
126 atom_id StringToMDIndex(const std::string& md_string) const;
127
128 Index getRank(const mapAtom& atom) const { return atom.getRank(); }
129
130 std::vector<double> getWeights(const tools::Property& frag) const;
131
132 std::string getFrame(const tools::Property& frag) const {
133 if (frag.exists(mapatom_xml_.at("frame"))) {
134 return frag.get(mapatom_xml_.at("frame")).template as<std::string>();
135 }
136 return frag.get("localframe").template as<std::string>();
137 }
138
139 void FillMap() {
140 mapatom_xml_["tag"] = "MP";
141 mapatom_xml_["name"] = "MPole";
142 mapatom_xml_["atoms"] = "mpoles";
143 mapatom_xml_["coords"] = "multipoles";
144 mapatom_xml_["weights"] = "mp_weights";
145 mapatom_xml_["frame"] = "mp_localframe";
146 }
147};
148
149template <>
151 mapatom_xml_["tag"] = "QM";
152 mapatom_xml_["name"] = "QMAtom";
153 mapatom_xml_["atoms"] = "qmatoms";
154 mapatom_xml_["coords"] = "qmcoords";
155 mapatom_xml_["weights"] = "qm_weights";
156 mapatom_xml_["frame"] = "qm_localframe";
157}
158
159template <>
161 return 0;
162}
163
164template <>
166 QMAtom* map_atom, const Atom* md_atom, const Eigen::Matrix3d& rot) const {
167 if (md_atom->hasExternalBond()) {
168 map_atom->setExternalBondDirection(rot *
169 md_atom->getExternalBondDirection());
172 }
173}
174
175template <>
177 QMAtom* map_atom, const Atom* md_atom,
178 const std::map<Index, QMAtom*>& md_id_to_map_atom) const {
179 for (Index i = 0; i < Atom::kMaxBondedPartners; i++) {
180 Index partner_md_id = md_atom->getBondedPartnerIds()[i];
181 if (partner_md_id == -1) {
182 continue;
183 }
184 auto it = md_id_to_map_atom.find(partner_md_id);
185 if (it != md_id_to_map_atom.end()) {
186 map_atom->AddBondedPartner(it->second->getId());
187 }
188 }
189}
190
191template <>
193 QMAtom& atom, const std::map<Index, Index>& old_to_new) const {
195 Index n = 0;
196 for (Index i = 0; i < QMAtom::kMaxBondedPartners; i++) {
197 auto it = old_to_new.find(atom.getBondedPartnerIds()[i]);
198 if (it != old_to_new.end()) {
199 ids[n++] = it->second;
200 }
201 }
202 for (Index i = n; i < QMAtom::kMaxBondedPartners; i++) {
203 ids[i] = -1;
204 }
205 atom.setBondedPartnerIds(ids);
206}
207
208template <>
210 PolarSegment& result, const Seginfo& seginfo, const QMState& state) const;
211
215} // namespace xtp
216} // namespace votca
217
218#endif // VOTCA_XTP_SEGMENTMAPPER_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
bool exists(const std::string &key) const
check whether property exists
Definition property.cc:122
bool hasExternalBond() const
Definition atom.h:90
const Index * getBondedPartnerIds() const
Definition atom.h:120
const Eigen::Vector3d & getExternalBondDirection() const
Definition atom.h:91
Index getExternalBondPartnerSegmentId() const
Definition atom.h:108
static constexpr Index kMaxBondedPartners
Definition atom.h:40
Logger is used for thread-safe output of messages.
Definition logger.h:164
container for QM atoms
Definition qmatom.h:37
void AddBondedPartner(Index partner_id)
Definition qmatom.h:120
const Index * getBondedPartnerIds() const
Definition qmatom.h:119
void setExternalBondDirection(const Eigen::Vector3d &dir)
Definition qmatom.h:89
void setBondedPartnerIds(const Index(&ids)[kMaxBondedPartners])
Definition qmatom.h:131
void setExternalBondPartnerSegmentId(Index segment_id)
Definition qmatom.h:111
static constexpr Index kMaxBondedPartners
Definition qmatom.h:42
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:135
std::pair< Index, std::string > atom_id
void LoadMappingFile(const std::string &mapfile)
std::map< std::string, Seginfo > segment_info_
void MapMapAtomonMD(const FragInfo &frag, const std::vector< mapAtom * > &fragment_mapatoms, const std::vector< const Atom * > &fragment_mdatoms) const
std::pair< Index, Index > CalcAtomIdRange(const std::vector< Index > &seg) const
std::map< std::string, std::string > mapatom_xml_
void ParseFragment(Seginfo &seginfo, const tools::Property &frag)
std::pair< Index, Index > CalcAtomIdRange(const Segment &seg) const
atom_id StringToMapIndex(const std::string &map_string) const
atom_id StringToMDIndex(const std::string &md_string) const
void AttachChargeResponse(AtomContainer &, const Seginfo &, const QMState &) const
Index getRank(const mapAtom &atom) const
void TransferExternalBondDirection(mapAtom *, const Atom *, const Eigen::Matrix3d &) const
void PlaceMapAtomonMD(const std::vector< mapAtom * > &fragment_mapatoms, const std::vector< const Atom * > &fragment_mdatoms) const
AtomContainer map(const Segment &seg, const std::string &coordfilename) const
Index FindVectorIndexFromAtomId(Index atomid, const std::vector< mapAtom * > &fragment_mapatoms) const
Eigen::Vector3d CalcWeightedPos(const std::vector< double > &weights, const T &atoms) const
std::string getFrame(const tools::Property &frag) const
AtomContainer map(const Segment &seg, QMState state) const
void RemapBondedPartners(mapAtom &, const std::map< Index, Index > &) const
AtomContainer map(const Segment &seg, const SegId &segid) const
typename AtomContainer::Atom_Type mapAtom
std::vector< double > getWeights(const tools::Property &frag) const
void TransferBondedPartners(mapAtom *, const Atom *, const std::map< Index, mapAtom * > &) const
ClassicalSegment< PolarSite > PolarSegment
SegmentMapper< PolarSegment > PolarMapper
SegmentMapper< QMMolecule > QMMapper
SegmentMapper< StaticSegment > StaticMapper
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
std::vector< Index > map_local_frame
std::vector< atom_id > mapatom_ids
std::vector< atom_id > mdatom_ids
std::pair< Index, Index > minmax
std::vector< FragInfo > fragments
std::map< std::string, std::string > crfiles
std::map< std::string, std::string > coordfiles
std::vector< atom_id > mapatoms