votca 2026-dev
Loading...
Searching...
No Matches
qmatom.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_QMATOM_H
22#define VOTCA_XTP_QMATOM_H
23
24// VOTCA includes
25#include "eigen.h"
27#include <votca/tools/types.h>
28
29namespace votca {
30namespace xtp {
31class CptTable;
37class QMAtom {
38 friend class ECPAOBasis;
39
40 public:
41 // Same value as Atom::kMaxBondedPartners -- see its own comment
42 // (atom.h) for why 4.
43 static constexpr Index kMaxBondedPartners = 4;
44
60
61 QMAtom(Index index, std::string element, Eigen::Vector3d pos);
62
63 QMAtom(const data& d);
64
65 const Eigen::Vector3d& getPos() const { return pos_; }
66
67 void Translate(const Eigen::Vector3d& shift) { pos_ += shift; }
68
69 void Rotate(const Eigen::Matrix3d& R, const Eigen::Vector3d& refPos);
70
71 void setPos(const Eigen::Vector3d& position) { pos_ = position; }
72
73 const std::string& getElement() const { return element_; }
74
75 Index getId() const { return index_; }
76
77 void setID(const Index index) { index_ = index; }
78
80
81 Index getElementNumber() const { return nuccharge_; }
82
83 // Same meaning as Atom::hasExternalBond()/getExternalBondDirection()
84 // (a direction toward an MD-level atom this one was covalently
85 // bonded to, but which fell outside the mapped fragment) -- a
86 // SEPARATE field from Atom's own, since QMAtom does not inherit
87 // from Atom at all. Set directly by SegmentMapper::MapMapAtomonMD/
88 // PlaceMapAtomonMD, by transforming the corresponding MD-level
89 // Atom's own, already-recorded, raw direction through the exact
90 // same rigid-body transform already applied to every other atom in
91 // the fragment there -- never computed independently here.
92 bool hasExternalBond() const { return has_external_bond_; }
93 const Eigen::Vector3d& getExternalBondDirection() const {
95 }
96 void setExternalBondDirection(const Eigen::Vector3d& dir) {
97 has_external_bond_ = true;
98 external_bond_direction_ = dir.normalized();
99 }
100
101 // Marks this atom's own external bond as resolved/no longer
102 // needing saturation -- e.g. because, within a specific, assembled
103 // supermolecule, its own external-bond partner segment
104 // (getExternalBondPartnerSegmentId()) turns out to already be
105 // present too, so the bond is already satisfied there and does not
106 // need a new H at all. Deliberately resets has_external_bond_ to
107 // false entirely (not merely a separate "skip saturation" flag) --
108 // once a bond is known to be satisfied within a given, specific
109 // supermolecule, it genuinely is no longer "external" to it at all,
110 // so hasExternalBond() itself should honestly report false for it,
111 // not some separate, parallel notion of "external but exempt".
112 // Deliberately only ever affects THIS, specific, already-mapped
113 // QMAtom instance/copy -- SegmentMapper::map() constructs a
114 // brand-new QMMolecule from scratch on every call, re-deriving
115 // hasExternalBond()/getExternalBondPartnerSegmentId() fresh each
116 // time from the underlying MD-level Segment's own, persisted atom
117 // data (never from a previously-cleared copy) -- so clearing this
118 // on one, specific mapped copy (e.g. within one specific pair's own
119 // supermolecule) has no effect at all on any other, separate
120 // mapping of the same underlying segment (e.g. within a different
121 // pair).
123 has_external_bond_ = false;
124 external_bond_direction_ = Eigen::Vector3d::Zero();
126 }
127
128 // Same meaning as Atom::getExternalBondPartnerSegmentId() -- the
129 // Segment::getId() this external bond crosses into. Unlike the
130 // direction itself, a segment id needs no rigid-body transform at
131 // all (it is not a geometric quantity) -- SegmentMapper copies it
132 // straight across from the corresponding MD-level Atom, alongside
133 // the direction transform, rather than transforming it in any way.
134 // Only meaningful when hasExternalBond() is true (matches -1, this
135 // class's own "-1 means unset" convention, otherwise). Unlike
136 // Atom's own version, QMAtom needs no separate, transient "partner
137 // ATOM id" field at all -- that value only ever existed to let
138 // Md2QmEngine resolve it into this, real, final segment id in the
139 // first place (see Atom::getExternalBondPartnerAtomId's own header
140 // comment, atom.h); QMAtom only ever needs the already-resolved
141 // result.
148
149 // Same meaning as Atom::getBondedPartnerIds() (a fragment's own,
150 // full, internal bond connectivity) -- but, unlike that one, these
151 // are already QM-LEVEL atom IDs (i.e. QMAtom::getId() values,
152 // matching this same QMMolecule's own atom numbering), NOT the raw,
153 // MD-level IDs Atom itself stores. Set directly by
154 // SegmentMapper::MapMapAtomonMD/PlaceMapAtomonMD, by translating
155 // each corresponding MD-level Atom's own, already-recorded, raw
156 // partner IDs into QM-level ones there, via the same
157 // mapatom_ids/mdatom_ids correspondence already used elsewhere in
158 // that same class -- never computed independently here. Same
159 // "-1 means unset" sentinel convention as Atom's own.
161 void AddBondedPartner(Index partner_id) {
162 for (Index& slot : bonded_partner_ids_) {
163 if (slot == -1) {
164 slot = partner_id;
165 return;
166 }
167 }
168 // All kMaxBondedPartners slots already full -- see
169 // Atom::kMaxBondedPartners's own comment for why this is silently
170 // dropped rather than treated as a hard error.
171 }
172 // Real, direct addition -- needed for QMMolecule::AddContainer()
173 // (qmmolecule.h) to be able to correctly offset an atom's own
174 // bonded_partner_ids_ when merging it into a larger QMMolecule
175 // (its own ids, as recorded, are local to the smaller QMMolecule
176 // it was originally mapped within -- a real, direct offset is
177 // needed once merged into a bigger one). AddBondedPartner() alone
178 // cannot do this: it only ever appends into the next available -1
179 // slot, never overwrites the whole array at once, so it cannot
180 // replace already-set values with their own, new, offset ones.
182 for (Index i = 0; i < kMaxBondedPartners; i++) {
183 bonded_partner_ids_[i] = ids[i];
184 }
185 }
186
187 std::string identify() const { return "qmatom"; }
188
189 friend std::ostream& operator<<(std::ostream& out, const QMAtom& atom) {
190 out << atom.getId() << " " << atom.getElement();
191 out << " " << atom.getPos().x() << "," << atom.getPos().y() << ","
192 << atom.getPos().z() << " " << atom.getNuccharge() << "\n";
193 return out;
194 }
195
196 private:
198 std::string element_;
199 Eigen::Vector3d pos_; // Bohr
201 Index ecpcharge_ = 0; // ecp charge is set in ecpaobasis.fill
202 bool has_external_bond_ = false;
203 Eigen::Vector3d external_bond_direction_ = Eigen::Vector3d::Zero();
206
207 public:
208 static void SetupCptTable(CptTable& table);
209
210 void WriteData(data& d) const;
211
212 void ReadData(const data& d);
213};
214} // namespace xtp
215} // namespace votca
216
217#endif // VOTCA_XTP_QMATOM_H
void AddBondedPartner(Index partner_id)
Definition qmatom.h:161
friend std::ostream & operator<<(std::ostream &out, const QMAtom &atom)
Definition qmatom.h:189
std::string element_
Definition qmatom.h:198
const Eigen::Vector3d & getPos() const
Definition qmatom.h:65
Index external_bond_partner_segment_id_
Definition qmatom.h:204
void Translate(const Eigen::Vector3d &shift)
Definition qmatom.h:67
const Index * getBondedPartnerIds() const
Definition qmatom.h:160
void clearExternalBond()
Definition qmatom.h:122
Eigen::Vector3d external_bond_direction_
Definition qmatom.h:203
Eigen::Vector3d pos_
Definition qmatom.h:199
Index getElementNumber() const
Definition qmatom.h:81
void setPos(const Eigen::Vector3d &position)
Definition qmatom.h:71
void WriteData(data &d) const
Definition qmatom.cc:68
friend class ECPAOBasis
Definition qmatom.h:38
Index getId() const
Definition qmatom.h:75
const std::string & getElement() const
Definition qmatom.h:73
const Eigen::Vector3d & getExternalBondDirection() const
Definition qmatom.h:93
void Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &refPos)
Definition qmatom.cc:34
static void SetupCptTable(CptTable &table)
Definition qmatom.cc:40
std::string identify() const
Definition qmatom.h:187
bool hasExternalBond() const
Definition qmatom.h:92
void setExternalBondDirection(const Eigen::Vector3d &dir)
Definition qmatom.h:96
Index bonded_partner_ids_[kMaxBondedPartners]
Definition qmatom.h:205
void setBondedPartnerIds(const Index(&ids)[kMaxBondedPartners])
Definition qmatom.h:181
Index getNuccharge() const
Definition qmatom.h:79
void setExternalBondPartnerSegmentId(Index segment_id)
Definition qmatom.h:145
Index getExternalBondPartnerSegmentId() const
Definition qmatom.h:142
void ReadData(const data &d)
Definition qmatom.cc:86
QMAtom(Index index, std::string element, Eigen::Vector3d pos)
Definition qmatom.cc:26
void setID(const Index index)
Definition qmatom.h:77
static constexpr Index kMaxBondedPartners
Definition qmatom.h:43
bool has_external_bond_
Definition qmatom.h:202
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
Index ext_bond_partner_segment_id
Definition qmatom.h:57
Index bonded_partner_ids[kMaxBondedPartners]
Definition qmatom.h:58