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/qmnblist.h"
22 #include "votca/xtp/checkpointwriter.h"
23 
24 namespace votca {
25 namespace xtp {
26 
27 QMPair& QMNBList::Add(const Segment& seg1, const Segment& seg2,
28                       const Eigen::Vector3d& r) {
29   assert(this->FindPair(&seg1, &seg2) == nullptr &&
30          "Critical bug: pair already exists");
31   Index id = this->size();
32   QMPair* pair = new QMPair(id, &seg1, &seg2, r);
33   this->AddPair(pair);
34   return *pair;
35 }
36 
37 void QMNBList::WriteToCpt(CheckpointWriter& w) const {
38   Index size = this->size();
39   w(size, "size");
40   if (size == 0) {
41     return;
42   }
43   std::vector<QMPair::data> dataVec(size);
44 
45   CptTable table = w.openTable<QMPair>("pairs", size);
46   for (Index i = 0; i < size; i++) {
47     (pairs_[i]->WriteData(dataVec[i]));
48   }
49   table.write(dataVec);
50   for (QMPair::data data : dataVec) {
51     delete[] data.pair_type;
52   }
av_gcd(int64_t a,int64_t b)53 }
54 
55 void QMNBList::ReadFromCpt(CheckpointReader& r,
56                            const std::vector<Segment>& segments) {
57   Cleanup();
58   Index size = 0;
59   r(size, "size");
60   if (size == 0) {
61     return;
62   }
63   CptTable table = r.openTable<QMPair>("pairs");
64   std::vector<QMPair::data> dataVec(table.numRows());
65   table.read(dataVec);
66 
67   for (const QMPair::data& data : dataVec) {
68     this->AddPair(new QMPair(data, segments));
69   }
70 }
71 
72 }  // namespace xtp
73 }  // namespace votca
74