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/populationanalysis.h"
22 
23 // Local private VOTCA includes
24 #include "DeltaQ_filter.h"
25 
26 namespace votca {
27 namespace xtp {
28 
Initialize(const tools::Property & options)29 void DeltaQ_filter::Initialize(const tools::Property& options) {
30   std::string indices = options.get("fragment").as<std::string>();
31   fragment_ = QMFragment<double>(0, indices);
32   fragment_.value() = options.get("threshold").as<double>();
33 }
34 
Info(Logger & log) const35 void DeltaQ_filter::Info(Logger& log) const {
36   XTP_LOG(Log::error, log) << "Using Delta Q tracker for fragment " << fragment_
37                            << std::flush;
38 }
39 
UpdateHist(const Orbitals &,QMState)40 void DeltaQ_filter::UpdateHist(const Orbitals&, QMState) { return; }
41 
CalcIndeces(const Orbitals & orb,QMStateType type) const42 std::vector<Index> DeltaQ_filter::CalcIndeces(const Orbitals& orb,
43                                               QMStateType type) const {
44 
45   if (!type.isExciton()) {
46     throw std::runtime_error("ChargeTransfer filter only works for excitons.");
47   }
48   std::vector<Index> indexes;
49   Lowdin low;
50   QMFragment<BSE_Population> frag;
51 
52   frag.copy_withoutvalue(fragment_);
53   std::vector<QMFragment<BSE_Population> > loc = {frag};
54   low.CalcChargeperFragment(loc, orb, type);
55   Eigen::VectorXd dq = (loc[0].value().H + loc[0].value().E).cwiseAbs();
56   for (Index i = 0; i < dq.size(); i++) {
57     if (dq[i] > fragment_.value()) {
58       indexes.push_back(i);
59     }
60   }
61   return indexes;
62 }
63 
WriteToCpt(CheckpointWriter & w)64 void DeltaQ_filter::WriteToCpt(CheckpointWriter& w) { fragment_.WriteToCpt(w); }
65 
ReadFromCpt(CheckpointReader & r)66 void DeltaQ_filter::ReadFromCpt(CheckpointReader& r) {
67   fragment_.ReadFromCpt(r);
68 }
69 
70 }  // namespace xtp
71 }  // namespace votca
72