votca 2026-dev
Loading...
Searching...
No Matches
atom.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 */
21
22#pragma once
23#ifndef VOTCA_XTP_ATOM_H
24#define VOTCA_XTP_ATOM_H
25
26// Standard includes
27#include "eigen.h"
28#include <exception>
29#include <map>
30#include <string>
31#include <votca/tools/types.h>
32namespace votca {
33namespace xtp {
34class CptTable;
35class Atom {
36 public:
37 // Real, direct MD-level bonded-partner atom IDs, up to this many --
38 // covers virtually all ordinary organic chemistry (a typical carbon
39 // has at most 4 bonded neighbors). A genuine atom with more bonded
40 // partners than this (extremely rare) is a real, known limitation --
41 // only the first kMaxBondedPartners found are recorded; this is not
42 // guarded against/flagged with a hard error anywhere, deliberately,
43 // to avoid making an already-rare edge case fatal.
44 static constexpr Index kMaxBondedPartners = 4;
45
61 Atom(Index resnr, std::string md_atom_name, Index atom_id,
62 Eigen::Vector3d pos, std::string element);
63
64 Atom(Index atom_id, std::string element, Eigen::Vector3d pos);
65
66 Atom(data& d) { ReadData(d); }
67
68 static std::string GetElementFromString(const std::string& MDName);
69
70 Index getId() const { return id_; }
71 const std::string& getName() const { return name_; }
72 std::string getElement() const { return element_; }
73
74 Index getResnr() const { return resnr_; }
75
76 void setResnr(Index resnr) { resnr_ = resnr; }
77 void Translate(const Eigen::Vector3d& shift) { pos_ = pos_ + shift; }
78
79 void Rotate(const Eigen::Matrix3d& R, const Eigen::Vector3d& refPos);
80
81 const Eigen::Vector3d& getPos() const { return pos_; }
82 void setPos(const Eigen::Vector3d& r) { pos_ = r; }
83
84 // Direction (normalized, unitless) toward an atom this one was
85 // covalently bonded to at the MD level, but which fell outside the
86 // mapped segment/fragment -- i.e. a bond that was "cut" by the
87 // segment definition. Set directly by Md2QmEngine/SegmentMapper at
88 // mapping time, using the exact same rigid-body transform already
89 // applied to every other atom in the fragment (so this direction is
90 // consistent with the fragment's own, already-idealized geometry,
91 // not the raw, possibly out-of-plane/distorted MD-level direction).
92 // A given atom may have at most one such recorded direction; an atom
93 // with more than one external bond (rare) only retains the first one
94 // set. Never set for atoms with no external bond at all (the normal
95 // case for most atoms in most fragments) -- callers must check
96 // hasExternalBond() before using getExternalBondDirection() at all.
97 //
98 // partner_atom_id is the raw, MD-level atom ID this external bond
99 // points to (Atom::getId() of the partner) -- known and set here,
100 // at the exact same point the direction itself is computed
101 // (Md2QmEngine's own, real, MD-level bond connectivity). This is
102 // deliberately transient/NOT persisted to the checkpoint file at
103 // all (no CptTable column, unlike everything else on this class) --
104 // it exists only to let Md2QmEngine look up, in a later, second
105 // pass within the same map() call (once every segment's own ID is
106 // known, which it is not yet at the point this direction is first
107 // computed -- segments are still being built), which SEGMENT that
108 // partner atom actually belongs to, and record that instead, via
109 // setExternalBondPartnerSegmentId() below -- the actually useful,
110 // persisted value. getExternalBondPartnerAtomId() is genuinely only
111 // meant to be read within that same Md2QmEngine::map() call, never
112 // afterward.
113 bool hasExternalBond() const { return has_external_bond_; }
114 const Eigen::Vector3d& getExternalBondDirection() const {
116 }
120 void setExternalBondDirection(const Eigen::Vector3d& dir,
121 Index partner_atom_id) {
122 has_external_bond_ = true;
123 external_bond_direction_ = dir.normalized();
124 external_bond_partner_atom_id_ = partner_atom_id;
125 }
126
127 // The SEGMENT ID (Segment::getId()) that this atom's own external-
128 // bond partner (see above) belongs to -- -1 (this class's own
129 // "-1 means unset" convention) until explicitly set. Unlike the
130 // direction itself, a segment ID needs no rigid-body transform at
131 // all (it is not a geometric quantity) -- SegmentMapper's own
132 // TransferExternalBondDirection copies this straight across onto
133 // the mapped QMAtom, alongside the direction transform, rather than
134 // transforming it in any way. This IS persisted (a real CptTable
135 // column, unlike getExternalBondPartnerAtomId() above) -- this is
136 // the value later consumers (a planned linking-segment graph, and
137 // the decision of whether a given external bond is already
138 // satisfied within an assembled supermolecule) are actually meant
139 // to read, from the checkpoint file, independently of
140 // Md2QmEngine::map() itself having ever run in the same process.
147
148 // Real, direct MD-level bonded-partner atom IDs (topological
149 // connectivity, not geometry -- these are Atom::getId() values, MD
150 // atom IDs, not array indices), for EVERY atom, not just ones with
151 // an external bond -- unlike getExternalBondDirection() above, this
152 // is meant to cover a fragment's own, full, internal connectivity
153 // too (needed downstream for FragmentSaturator's own, planned
154 // OpenBabel-based relaxation step, which needs real, known bond
155 // connectivity for the whole fragment, not just the new bond, to
156 // set up its own force field correctly at all -- see
157 // FragmentSaturator's own header comment for why). Set directly by
158 // Md2QmEngine at mapping time, from the real, MD-level topology's
159 // own bond connectivity (the same source
160 // getExternalBondDirection()'s own raw input comes from) -- these
161 // IDs are NOT yet transformed/translated into QM-level IDs here;
162 // that translation happens later, in SegmentMapper, matching the
163 // same "raw here, transformed/translated later" split already used
164 // for the external-bond direction. Unused slots hold -1, matching
165 // this class's own, existing "-1 means unset" convention (id_'s own
166 // default).
168 void AddBondedPartner(Index partner_id) {
169 for (Index& slot : bonded_partner_ids_) {
170 if (slot == -1) {
171 slot = partner_id;
172 return;
173 }
174 }
175 // All kMaxBondedPartners slots already full -- see this class's
176 // own, static kMaxBondedPartners comment above for why this is
177 // silently dropped rather than treated as a hard error.
178 }
179
180 std::string identify() const { return "atom"; }
181
182 friend std::ostream& operator<<(std::ostream& out, const Atom& atom) {
183 out << atom.getId() << " " << atom.getName() << " " << atom.getElement()
184 << " " << atom.getResnr();
185 out << " " << atom.getPos().x() << "," << atom.getPos().y() << ","
186 << atom.getPos().z() << "\n";
187 return out;
188 }
189
190 static void SetupCptTable(CptTable& table);
191
192 void WriteData(data& d) const;
193
194 void ReadData(const data& d);
195
196 private:
197 Index id_ = -1;
198 std::string name_ = "";
199
200 std::string element_ = "";
202 Eigen::Vector3d pos_ = Eigen::Vector3d::Zero();
203 bool has_external_bond_ = false;
204 Eigen::Vector3d external_bond_direction_ = Eigen::Vector3d::Zero();
208};
209
210} // namespace xtp
211} // namespace votca
212
213#endif // VOTCA_XTP_ATOM_H
Atom(data &d)
Definition atom.h:66
Index bonded_partner_ids_[kMaxBondedPartners]
Definition atom.h:207
Index resnr_
Definition atom.h:201
void setResnr(Index resnr)
Definition atom.h:76
static void SetupCptTable(CptTable &table)
Definition atom.cc:88
void ReadData(const data &d)
Definition atom.cc:143
std::string name_
Definition atom.h:198
bool hasExternalBond() const
Definition atom.h:113
const Index * getBondedPartnerIds() const
Definition atom.h:167
void setPos(const Eigen::Vector3d &r)
Definition atom.h:82
void WriteData(data &d) const
Definition atom.cc:125
Eigen::Vector3d pos_
Definition atom.h:202
Eigen::Vector3d external_bond_direction_
Definition atom.h:204
static std::string GetElementFromString(const std::string &MDName)
Definition atom.cc:71
Index external_bond_partner_atom_id_
Definition atom.h:205
Index external_bond_partner_segment_id_
Definition atom.h:206
Index getId() const
Definition atom.h:70
const Eigen::Vector3d & getPos() const
Definition atom.h:81
void Translate(const Eigen::Vector3d &shift)
Definition atom.h:77
Atom(Index resnr, std::string md_atom_name, Index atom_id, Eigen::Vector3d pos, std::string element)
Definition atom.cc:30
bool has_external_bond_
Definition atom.h:203
const std::string & getName() const
Definition atom.h:71
void setExternalBondPartnerSegmentId(Index segment_id)
Definition atom.h:144
const Eigen::Vector3d & getExternalBondDirection() const
Definition atom.h:114
void Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &refPos)
Definition atom.cc:82
Index getExternalBondPartnerAtomId() const
Definition atom.h:117
void AddBondedPartner(Index partner_id)
Definition atom.h:168
friend std::ostream & operator<<(std::ostream &out, const Atom &atom)
Definition atom.h:182
Index getExternalBondPartnerSegmentId() const
Definition atom.h:141
Index getResnr() const
Definition atom.h:74
std::string identify() const
Definition atom.h:180
std::string getElement() const
Definition atom.h:72
std::string element_
Definition atom.h:200
void setExternalBondDirection(const Eigen::Vector3d &dir, Index partner_atom_id)
Definition atom.h:120
static constexpr Index kMaxBondedPartners
Definition atom.h:44
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
double ext_bond_dir_z
Definition atom.h:57
double ext_bond_dir_x
Definition atom.h:55
Index ext_bond_partner_segment_id
Definition atom.h:58
double ext_bond_dir_y
Definition atom.h:56
Index bonded_partner_ids[kMaxBondedPartners]
Definition atom.h:59