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 };
73 std::map<std::string, std::string> mapatom_xml_;
74 std::map<std::string, Seginfo> segment_info_;
75
77 Index atomid, const std::vector<mapAtom*>& fragment_mapatoms) const;
78
79 void ParseFragment(Seginfo& seginfo, const tools::Property& frag);
80
81 template <typename T>
82 Eigen::Vector3d CalcWeightedPos(const std::vector<double>& weights,
83 const T& atoms) const;
84
85 void PlaceMapAtomonMD(const std::vector<mapAtom*>& fragment_mapatoms,
86 const std::vector<const Atom*>& fragment_mdatoms) const;
87
88 void MapMapAtomonMD(const FragInfo& frag,
89 const std::vector<mapAtom*>& fragment_mapatoms,
90 const std::vector<const Atom*>& fragment_mdatoms) const;
91
92 // Default, no-op implementation for AtomContainer types whose own
93 // mapAtom type has no hasExternalBond()/setExternalBondDirection()
94 // interface at all (StaticSegment/PolarSegment's own atom types --
95 // this feature is currently QM-specific only). Given an already-
96 // computed rotation (rot, no translation -- a direction is
97 // translation-invariant by construction, matching the same
98 // "rotate the position-minus-reference-point difference only"
99 // principle Atom::Rotate/QMAtom::Rotate's own, existing
100 // implementation already uses), transfers the MD atom's own,
101 // already-recorded, raw external-bond direction onto the mapped
102 // atom, rotated into the mapped atom's own reference frame -- and,
103 // alongside it, the SEGMENT id (Atom::
104 // getExternalBondPartnerSegmentId()) that bond crosses into, copied
105 // straight across, unchanged (a segment id needs no rigid-body
106 // transform at all, it is not a geometric quantity). Explicitly
107 // specialized for SegmentMapper<QMMolecule> below, where QMAtom
108 // actually does have this interface -- matching the same,
109 // already-established pattern this class already uses for
110 // FillMap()/getRank() above.
112 const Eigen::Matrix3d&) const {}
113
114 // Same default, no-op/specialization pattern as
115 // TransferExternalBondDirection above, for the same reason
116 // (StaticSegment/PolarSegment's own atom types have no
117 // getBondedPartnerIds()/AddBondedPartner() interface at all).
118 // Given a "MD-level atom ID -> mapped atom" lookup covering the
119 // WHOLE segment (not just this one fragment -- a bonded partner can
120 // genuinely be in a different fragment of the same segment), and
121 // the corresponding MD-level Atom whose own, raw, MD-level partner
122 // IDs need translating, looks each one up in that lookup and, if
123 // found (i.e. the partner is itself part of this same segment --
124 // if not found, the partner belongs to a genuinely different
125 // segment, and is silently skipped, since that partner has no
126 // corresponding mapped atom within this call's own Result at all,
127 // matching this class's own, existing convention of never crossing
128 // segment boundaries within a single map() call), adds its own
129 // mapped ID onto map_atom directly. Explicitly specialized for
130 // SegmentMapper<QMMolecule> below.
132 const std::map<Index, mapAtom*>&) const {}
133
135 std::pair<Index, Index> CalcAtomIdRange(const Segment& seg) const;
136 std::pair<Index, Index> CalcAtomIdRange(const std::vector<Index>& seg) const;
137
138 atom_id StringToMapIndex(const std::string& map_string) const;
139
140 atom_id StringToMDIndex(const std::string& md_string) const;
141
142 Index getRank(const mapAtom& atom) const { return atom.getRank(); }
143
144 std::vector<double> getWeights(const tools::Property& frag) const;
145
146 std::string getFrame(const tools::Property& frag) const {
147 if (frag.exists(mapatom_xml_.at("frame"))) {
148 return frag.get(mapatom_xml_.at("frame")).template as<std::string>();
149 }
150 return frag.get("localframe").template as<std::string>();
151 }
152
153 void FillMap() {
154 mapatom_xml_["tag"] = "MP";
155 mapatom_xml_["name"] = "MPole";
156 mapatom_xml_["atoms"] = "mpoles";
157 mapatom_xml_["coords"] = "multipoles";
158 mapatom_xml_["weights"] = "mp_weights";
159 mapatom_xml_["frame"] = "mp_localframe";
160 }
161};
162
163template <>
165 mapatom_xml_["tag"] = "QM";
166 mapatom_xml_["name"] = "QMAtom";
167 mapatom_xml_["atoms"] = "qmatoms";
168 mapatom_xml_["coords"] = "qmcoords";
169 mapatom_xml_["weights"] = "qm_weights";
170 mapatom_xml_["frame"] = "qm_localframe";
171}
172
173template <>
175 return 0;
176}
177
178template <>
180 QMAtom* map_atom, const Atom* md_atom, const Eigen::Matrix3d& rot) const {
181 if (md_atom->hasExternalBond()) {
182 map_atom->setExternalBondDirection(rot *
183 md_atom->getExternalBondDirection());
186 }
187}
188
189template <>
191 QMAtom* map_atom, const Atom* md_atom,
192 const std::map<Index, QMAtom*>& md_id_to_map_atom) const {
193 for (Index i = 0; i < Atom::kMaxBondedPartners; i++) {
194 Index partner_md_id = md_atom->getBondedPartnerIds()[i];
195 if (partner_md_id == -1) {
196 continue;
197 }
198 auto it = md_id_to_map_atom.find(partner_md_id);
199 if (it != md_id_to_map_atom.end()) {
200 map_atom->AddBondedPartner(it->second->getId());
201 }
202 }
203}
204
208} // namespace xtp
209} // namespace votca
210
211#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:113
const Index * getBondedPartnerIds() const
Definition atom.h:167
const Eigen::Vector3d & getExternalBondDirection() const
Definition atom.h:114
Index getExternalBondPartnerSegmentId() const
Definition atom.h:141
static constexpr Index kMaxBondedPartners
Definition atom.h:44
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:161
void setExternalBondDirection(const Eigen::Vector3d &dir)
Definition qmatom.h:96
void setExternalBondPartnerSegmentId(Index segment_id)
Definition qmatom.h:145
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
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
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
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 > coordfiles
std::vector< atom_id > mapatoms