votca 2024.2-dev
Loading...
Searching...
No Matches
mmregion.cc
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// Local VOTCA includes
21#include "votca/xtp/mmregion.h"
22
23namespace votca {
24namespace xtp {
25
26template <class T>
27double MMRegion<T>::charge() const {
28 double charge = 0.0;
29 for (const auto& seg : segments_) {
30 for (const auto& site : seg) {
31 charge += site.getCharge();
32 }
33 }
34 return charge;
35}
36
37template <class T>
39 for (const auto& seg : segments_) {
40 writer.WriteContainer(seg);
41 }
42}
44template <class T>
46 w(id_, "id");
47 w(identify(), "type");
48 Index size = Index(segments_.size());
49 w(size, "size");
50 CheckpointWriter ww = w.openChild("segments");
51 for (const auto& seg : segments_) {
53 ww.openChild(seg.identify() + "_" + std::to_string(seg.getId()));
54 seg.WriteToCpt(www);
55 }
56}
57template <class T>
59 r(id_, "id");
60 Index size;
61 r(size, "size");
62 segments_.clear();
63 segments_.reserve(size);
64 T dummy("dummy", 0);
65 CheckpointReader rr = r.openChild("segments");
66 std::vector<std::string> names = rr.getChildGroupNames();
67 if (Index(names.size()) != size) {
68 std::stringstream message;
69 message << "Size inconsistency in region " << std::endl;
70 throw std::runtime_error(message.str());
71 }
72 for (auto name : names) {
73 CheckpointReader rrr = rr.openChild(name);
74 segments_.push_back(T(rrr));
75 }
77
78template class MMRegion<PolarSegment>;
79template class MMRegion<StaticSegment>;
80
81} // namespace xtp
82} // namespace votca
void WriteContainer(T &container)
Definition pdbwriter.h:102
std::vector< std::string > getChildGroupNames() const
CheckpointReader openChild(const std::string &childName) const
CheckpointWriter openChild(const std::string &childName) const
void WriteToCpt(CheckpointWriter &w) const override
Definition mmregion.cc:45
void WritePDB(csg::PDBWriter &writer) const override
Definition mmregion.cc:38
void ReadFromCpt(CheckpointReader &r) override
Definition mmregion.cc:58
double charge() const override
Definition mmregion.cc:27
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26