votca 2024.1-dev
Loading...
Searching...
No Matches
qmfragment.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 */
19
20#pragma once
21#ifndef VOTCA_XTP_QMFRAGMENT_H
22#define VOTCA_XTP_QMFRAGMENT_H
23
24// Local VOTCA includes
25#include "IndexParser.h"
26#include "bse_population.h"
27
37namespace votca {
38namespace xtp {
39
40template <class T>
42 public:
43 QMFragment(Index id, std::string atoms) : id_(id) { FillAtomIndices(atoms); }
44
45 QMFragment() = default;
46
48
49 template <class T2>
51 id_ = frag.getId();
52 atomindices_ = frag.getIndices();
53 }
54
55 void setId(Index id) { id_ = id; }
56 Index getId() const { return id_; }
57 void FillFromString(std::string atoms) { FillAtomIndices(atoms); }
58
59 const T& value() const { return value_; }
60
61 T& value() { return value_; }
62
63 Index size() const { return Index(atomindices_.size()); }
64
65 const std::vector<Index>& getIndices() const { return atomindices_; }
66
67 double ExtractFromVector(const Eigen::VectorXd& atomentries) const {
68 double result = 0;
69 for (Index index : atomindices_) {
70 result += atomentries(index);
71 }
72 return result;
73 }
74
75 typename std::vector<Index>::const_iterator begin() const {
76 return atomindices_.begin();
77 }
78 typename std::vector<Index>::const_iterator end() const {
79 return atomindices_.end();
80 }
81
82 friend std::ostream& operator<<(std::ostream& out,
83 const QMFragment& fragment) {
84 out << "Fragment id:" << fragment.id_ << "\n";
85 out << "AtomIndices[" << fragment.size() << "]:";
87 out << p.CreateIndexString(fragment.atomindices_) << "\n";
88 out << "\nValue:" << fragment.value_;
89 out << "\n";
90 return out;
91 };
92
94 w(atomindices_, "indices");
95 w(id_, "id");
96 WriteValue(w);
97 }
98
100 r(atomindices_, "indices");
101 r(id_, "id");
102 ReadValue(r);
103 }
104
105 private:
108
109 void FillAtomIndices(const std::string& atoms) {
110 IndexParser p;
112 }
113
114 std::vector<Index> atomindices_;
115 Index id_ = -1;
117};
118
119template <class T>
121 r(value_, "value");
122}
123template <class T>
125 w(value_, "value");
126}
127
128template <>
130 CheckpointReader rr = r.openChild("BSE_pop");
131 value_.ReadFromCpt(rr);
132}
133
134template <>
136 CheckpointWriter ww = w.openChild("BSE_pop");
137 value_.WriteToCpt(ww);
138}
139
140} // namespace xtp
141} // namespace votca
142
143#endif // VOTCA_XTP_QMFRAGMENT_H
CheckpointReader openChild(const std::string &childName) const
CheckpointWriter openChild(const std::string &childName) const
std::vector< Index > CreateIndexVector(const std::string &Ids) const
std::string CreateIndexString(const std::vector< Index > &indeces) const
QMFragment(CheckpointReader &r)
Definition qmfragment.h:47
std::vector< Index >::const_iterator end() const
Definition qmfragment.h:78
void ReadFromCpt(CheckpointReader &r)
Definition qmfragment.h:99
void FillAtomIndices(const std::string &atoms)
Definition qmfragment.h:109
Index size() const
Definition qmfragment.h:63
void ReadValue(CheckpointReader &r)
Definition qmfragment.h:120
void WriteToCpt(CheckpointWriter &w) const
Definition qmfragment.h:93
std::vector< Index >::const_iterator begin() const
Definition qmfragment.h:75
const std::vector< Index > & getIndices() const
Definition qmfragment.h:65
void setId(Index id)
Definition qmfragment.h:55
std::vector< Index > atomindices_
Definition qmfragment.h:114
friend std::ostream & operator<<(std::ostream &out, const QMFragment &fragment)
Definition qmfragment.h:82
QMFragment(Index id, std::string atoms)
Definition qmfragment.h:43
Index getId() const
Definition qmfragment.h:56
void copy_withoutvalue(const QMFragment< T2 > &frag)
Definition qmfragment.h:50
const T & value() const
Definition qmfragment.h:59
double ExtractFromVector(const Eigen::VectorXd &atomentries) const
Definition qmfragment.h:67
void FillFromString(std::string atoms)
Definition qmfragment.h:57
void WriteValue(CheckpointWriter &w) const
Definition qmfragment.h:124
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26