votca 2026-dev
Loading...
Searching...
No Matches
qmmolecule.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_QMMOLECULE_H
22#define VOTCA_XTP_QMMOLECULE_H
23
24// Local VOTCA includes
25#include "atomcontainer.h"
26#include "qmatom.h"
27
28namespace votca {
29namespace xtp {
30
31class QMMolecule : public AtomContainer<QMAtom> {
32 public:
33 QMMolecule(std::string name, Index id) : AtomContainer<QMAtom>(name, id) {};
34
36 void LoadFromFile(std::string filename);
37
38 void WriteXYZ(std::string filename, std::string header) const;
39
40 void AddContainer(const AtomContainer<QMAtom>& container) {
41 Index offset = atomlist_.size();
42 type_ += "_" + container.getType();
43 for (const auto& at : container) {
44 // Real, direct fix for a real, direct, pre-existing bug --
45 // reconstructing a brand new QMAtom from scratch here (the
46 // (Index, element, pos) constructor, as this used to do)
47 // silently discards everything else about the original atom
48 // at all: hasExternalBond()/external_bond_direction_/
49 // external_bond_partner_segment_id_/bonded_partner_ids_ all
50 // reset to their own, empty defaults. Confirmed directly, this
51 // exact way, from the user's own real, direct diagnostic run:
52 // only ONE of three genuinely expected external bonds ever
53 // actually saturated at all -- specifically the one on the
54 // atom belonging to the FIRST segment merged into a QMMolecule
55 // this way (qmmol = mapper.map(*seg1, stateA), a real, direct
56 // copy-construction, not affected by this bug at all) -- every
57 // subsequent segment's own atoms, merged in via THIS method
58 // (qmmol.AddContainer(mapper.map(seg2, stateB))), silently lost
59 // this data entirely.
60 //
61 // Fixed by copying the whole atom directly (preserving
62 // everything about it), then only mutating what genuinely does
63 // need to change once merged into a larger container: its own
64 // id (via setID(), matching this method's own, already-
65 // established "unique ids" comment/purpose exactly), and its
66 // own bonded_partner_ids_ (via the new setBondedPartnerIds()
67 // added directly alongside this fix, qmatom.h) -- these are
68 // recorded local to the smaller QMMolecule this atom was
69 // originally mapped within, so need the exact same offset
70 // applied to them too, or they would end up pointing at the
71 // wrong atom entirely once merged. hasExternalBond()/
72 // external_bond_direction_/external_bond_partner_segment_id_
73 // need no such offsetting at all -- none of them are ids that
74 // point at another atom within this same container (the first
75 // two are per-atom properties; the third is a real, direct
76 // SEGMENT id, an entirely separate, global id space).
77 QMAtom atom = at;
78 atom.setID(at.getId() + offset);
79 const Index* partners = at.getBondedPartnerIds();
80 Index offset_partners[QMAtom::kMaxBondedPartners];
81 for (Index i = 0; i < QMAtom::kMaxBondedPartners; i++) {
82 offset_partners[i] = (partners[i] == -1) ? -1 : partners[i] + offset;
83 }
84 atom.setBondedPartnerIds(offset_partners);
85 atomlist_.push_back(atom);
86 }
87 calcPos();
88 }
89
91 Index id = 0;
92 for (auto& at : atomlist_) {
93 at.setID(id);
94 id++;
95 }
96 }
97
98 friend std::ostream& operator<<(std::ostream& out,
99 const QMMolecule& container) {
100 out << container.getId() << " " << container.getType() << "\n";
101 for (const QMAtom& atom : container) {
102 out << atom;
103 }
104 out << std::endl;
105 return out;
106 }
107};
108
109} // namespace xtp
110} // namespace votca
111
112#endif // VOTCA_XTP_QMMOLECULE_H
const std::string & getType() const
const QMAtom & at(Index index) const
AtomContainer(std::string type, Index id)
container for QM atoms
Definition qmatom.h:37
void setBondedPartnerIds(const Index(&ids)[kMaxBondedPartners])
Definition qmatom.h:181
void setID(const Index index)
Definition qmatom.h:77
static constexpr Index kMaxBondedPartners
Definition qmatom.h:43
QMMolecule(std::string name, Index id)
Definition qmmolecule.h:33
void LoadFromFile(std::string filename)
Definition qmmolecule.cc:45
friend std::ostream & operator<<(std::ostream &out, const QMMolecule &container)
Definition qmmolecule.h:98
void WriteXYZ(std::string filename, std::string header) const
Definition qmmolecule.cc:37
void AddContainer(const AtomContainer< QMAtom > &container)
Definition qmmolecule.h:40
QMMolecule(CheckpointReader &r)
Definition qmmolecule.h:35
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26