votca 2024.2-dev
Loading...
Searching...
No Matches
Density_filter.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 private VOTCA includes
21#include "Density_filter.h"
22
23namespace votca {
24namespace xtp {
25
27 threshold_ = options.get(".").as<double>();
28}
29
30void Density_filter::Info(Logger& log) const {
31 if (threshold_ == 0.0) {
33 << "Using density filter with no threshold " << std::flush;
34 } else {
36 << "Using density filter with threshold " << threshold_ << std::flush;
37 }
38}
39
42}
43
44Eigen::VectorXd Density_filter::CalculateDNorm(const Orbitals& orb,
45 QMStateType type) const {
46 Index nostates = orb.NumberofStates(type);
47 Eigen::VectorXd norm = Eigen::VectorXd::Zero(nostates);
48 for (Index i = 0; i < nostates; i++) {
49 QMState state(type, i, false);
50 norm(i) = (orb.DensityMatrixFull(state) - laststate_dmat_).norm();
51 }
52 double lastnorm = laststate_dmat_.norm();
53 return norm / lastnorm;
54}
55
56std::vector<Index> Density_filter::CalcIndeces(const Orbitals& orb,
57 QMStateType type) const {
58 Eigen::VectorXd Overlap = CalculateDNorm(orb, type);
59 Index offset = 0;
60 if (type == QMStateType::DQPstate) {
61 offset = orb.getGWAmin();
62 }
63 return ReduceAndSortIndecesDown(Overlap, offset, threshold_);
64}
65
67 w(laststate_dmat_, "laststatedmat");
68 w(threshold_, "threshold");
69}
70
72 r(laststate_dmat_, "laststatedmat");
73 r(threshold_, "threshold");
74}
75
76} // namespace xtp
77} // namespace votca
class to manage program options with xml serialization functionality
Definition property.h:55
Property & get(const std::string &key)
get existing property
Definition property.cc:79
T as() const
return value as type
Definition property.h:283
std::vector< Index > CalcIndeces(const Orbitals &orb, QMStateType type) const final
void Initialize(const tools::Property &options) final
Eigen::MatrixXd laststate_dmat_
void ReadFromCpt(CheckpointReader &r) final
void UpdateHist(const Orbitals &orb, QMState state) final
Eigen::VectorXd CalculateDNorm(const Orbitals &orb, QMStateType type) const
void WriteToCpt(CheckpointWriter &w) final
void Info(Logger &log) const final
Logger is used for thread-safe output of messages.
Definition logger.h:164
container for molecular orbitals
Definition orbitals.h:46
Eigen::MatrixXd DensityMatrixFull(const QMState &state) const
Definition orbitals.cc:140
Index getGWAmin() const
Definition orbitals.h:249
Index NumberofStates(QMStateType type) const
Definition orbitals.h:135
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:132
std::vector< Index > ReduceAndSortIndecesDown(const Eigen::VectorXd &overlap, Index offset, double threshold) const
#define XTP_LOG(level, log)
Definition logger.h:40
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26