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 // Maximum number of stored bonded partners (sufficient for organic
38 // molecules). Further partners are silently dropped rather than treated
39 // as an error.
40 static constexpr Index kMaxBondedPartners = 4;
41
57 Atom(Index resnr, std::string md_atom_name, Index atom_id,
58 Eigen::Vector3d pos, std::string element);
59
60 Atom(Index atom_id, std::string element, Eigen::Vector3d pos);
61
62 Atom(data& d) { ReadData(d); }
63
64 static std::string GetElementFromString(const std::string& MDName);
65
66 Index getId() const { return id_; }
67 const std::string& getName() const { return name_; }
68 std::string getElement() const { return element_; }
69
70 Index getResnr() const { return resnr_; }
71
72 void setResnr(Index resnr) { resnr_ = resnr; }
73 void Translate(const Eigen::Vector3d& shift) { pos_ = pos_ + shift; }
74
75 void Rotate(const Eigen::Matrix3d& R, const Eigen::Vector3d& refPos);
76
77 const Eigen::Vector3d& getPos() const { return pos_; }
78 void setPos(const Eigen::Vector3d& r) { pos_ = r; }
79
80 // Unit vector toward a covalently bonded MD atom that lies outside the
81 // segment, i.e. a bond cut by the segment definition. Md2QmEngine sets it
82 // from the MD geometry; SegmentMapper rotates it with the fragment's
83 // MD->template transform for the mapped QMAtom. Only the first external
84 // bond of an atom is stored; check hasExternalBond() before use.
85 //
86 // partner_atom_id is the MD atom ID of the partner. It is transient (not
87 // written to the checkpoint file) and only used within
88 // Md2QmEngine::map() to determine the partner's segment ID
89 // (setExternalBondPartnerSegmentId()) once all segments exist.
90 bool hasExternalBond() const { return has_external_bond_; }
91 const Eigen::Vector3d& getExternalBondDirection() const {
93 }
97 void setExternalBondDirection(const Eigen::Vector3d& dir,
98 Index partner_atom_id) {
99 has_external_bond_ = true;
100 external_bond_direction_ = dir.normalized();
101 external_bond_partner_atom_id_ = partner_atom_id;
102 }
103
104 // Segment::getId() of the segment the external-bond partner belongs to,
105 // -1 if unset. Copied unchanged to the mapped QMAtom by SegmentMapper.
106 // Persisted in the checkpoint file, e.g. for the segment bond graph used
107 // by Topology::FindLinkingSegments.
114
115 // IDs (Atom::getId(), not indices) of all covalently bonded atoms, set by
116 // Md2QmEngine from the MD topology for every atom. The fragment relaxation
117 // in FragmentSaturator needs this full internal connectivity. The IDs are
118 // MD-level here and translated to QM-level IDs in SegmentMapper. Unused
119 // slots hold -1.
121 void AddBondedPartner(Index partner_id) {
122 for (Index& slot : bonded_partner_ids_) {
123 if (slot == -1) {
124 slot = partner_id;
125 return;
126 }
127 }
128 // All slots full: partner is dropped (see kMaxBondedPartners).
129 }
130
131 std::string identify() const { return "atom"; }
132
133 friend std::ostream& operator<<(std::ostream& out, const Atom& atom) {
134 out << atom.getId() << " " << atom.getName() << " " << atom.getElement()
135 << " " << atom.getResnr();
136 out << " " << atom.getPos().x() << "," << atom.getPos().y() << ","
137 << atom.getPos().z() << "\n";
138 return out;
139 }
140
141 static void SetupCptTable(CptTable& table);
142
143 void WriteData(data& d) const;
144
145 void ReadData(const data& d);
146
147 private:
148 Index id_ = -1;
149 std::string name_ = "";
150
151 std::string element_ = "";
153 Eigen::Vector3d pos_ = Eigen::Vector3d::Zero();
154 bool has_external_bond_ = false;
155 Eigen::Vector3d external_bond_direction_ = Eigen::Vector3d::Zero();
159};
160
161} // namespace xtp
162} // namespace votca
163
164#endif // VOTCA_XTP_ATOM_H
Atom(data &d)
Definition atom.h:62
Index bonded_partner_ids_[kMaxBondedPartners]
Definition atom.h:158
Index resnr_
Definition atom.h:152
void setResnr(Index resnr)
Definition atom.h:72
static void SetupCptTable(CptTable &table)
Definition atom.cc:88
void ReadData(const data &d)
Definition atom.cc:143
std::string name_
Definition atom.h:149
bool hasExternalBond() const
Definition atom.h:90
const Index * getBondedPartnerIds() const
Definition atom.h:120
void setPos(const Eigen::Vector3d &r)
Definition atom.h:78
void WriteData(data &d) const
Definition atom.cc:125
Eigen::Vector3d pos_
Definition atom.h:153
Eigen::Vector3d external_bond_direction_
Definition atom.h:155
static std::string GetElementFromString(const std::string &MDName)
Definition atom.cc:71
Index external_bond_partner_atom_id_
Definition atom.h:156
Index external_bond_partner_segment_id_
Definition atom.h:157
Index getId() const
Definition atom.h:66
const Eigen::Vector3d & getPos() const
Definition atom.h:77
void Translate(const Eigen::Vector3d &shift)
Definition atom.h:73
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:154
const std::string & getName() const
Definition atom.h:67
void setExternalBondPartnerSegmentId(Index segment_id)
Definition atom.h:111
const Eigen::Vector3d & getExternalBondDirection() const
Definition atom.h:91
void Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &refPos)
Definition atom.cc:82
Index getExternalBondPartnerAtomId() const
Definition atom.h:94
void AddBondedPartner(Index partner_id)
Definition atom.h:121
friend std::ostream & operator<<(std::ostream &out, const Atom &atom)
Definition atom.h:133
Index getExternalBondPartnerSegmentId() const
Definition atom.h:108
Index getResnr() const
Definition atom.h:70
std::string identify() const
Definition atom.h:131
std::string getElement() const
Definition atom.h:68
std::string element_
Definition atom.h:151
void setExternalBondDirection(const Eigen::Vector3d &dir, Index partner_atom_id)
Definition atom.h:97
static constexpr Index kMaxBondedPartners
Definition atom.h:40
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:53
double ext_bond_dir_x
Definition atom.h:51
Index ext_bond_partner_segment_id
Definition atom.h:54
double ext_bond_dir_y
Definition atom.h:52
Index bonded_partner_ids[kMaxBondedPartners]
Definition atom.h:55