votca 2024.2-dev
Loading...
Searching...
No Matches
orbreorder.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
22#include "votca/xtp/basisset.h"
23
24namespace votca {
25namespace xtp {
26
27std::vector<Transposition> OrbReorder::computeTranspositions(
28 std::vector<Index> vStart, std::vector<Index> vTarget) const {
29 if (vStart.size() != vTarget.size()) {
30 throw std::runtime_error(
31 "Can't compute transpositions, reorder vectors have different "
32 "size!\n");
33 }
34 std::vector<Transposition> transpositions;
35 for (Index i = 0; i < static_cast<Index>(vStart.size()); i++) {
36 std::vector<Index>::iterator it;
37 it = std::find(vStart.begin(), vStart.end(), vTarget[i]);
38 Index pos = std::distance(vStart.begin(), it);
39 std::swap(vStart[i], vStart[pos]);
40 if (i != pos) {
41 transpositions.push_back(Transposition{i, pos});
42 }
43 }
44 return transpositions;
45}
46
47std::vector<Index> OrbReorder::copySegment(const std::array<Index, 49>& input,
48 Index start, Index size) const {
49 return std::vector<Index>{input.begin() + start,
50 input.begin() + start + size};
51}
52
53OrbReorder::OrbReorder(std::array<Index, 49> reorder,
54 std::array<Index, 49> multipliers, bool reverse)
55 : multipliers_(multipliers), reorder_(reorder), reverse_(reverse) {
56
57 // Compute transpositions for every individual shell
58 Index currentFunction = 0;
59 for (int l = 0; l < 7; l++) {
60 Index nrOfFunctions = NumFuncShell(static_cast<L>(l));
61 if (!reverse_) { // ordering from external to votca order
63 copySegment(reorder_, currentFunction, nrOfFunctions),
64 copySegment(votcaOrder_, currentFunction, nrOfFunctions));
65 } else { // votca order to external order
67 copySegment(votcaOrder_, currentFunction, nrOfFunctions),
68 copySegment(reorder_, currentFunction, nrOfFunctions));
69 }
70 currentFunction += nrOfFunctions;
71 }
72}
73
74void OrbReorder::reorderOrbitals(Eigen::MatrixXd& moCoefficients,
75 const AOBasis& basis) {
76
77 for (const AOShell& shell : basis) {
78 Index currentFunction = shell.getStartIndex();
79
80 if (reverse_) { // multiply first before reversing ordering
81 // Get multiplier vector for shell
82 std::vector<Index> shellmultiplier =
83 copySegment(multipliers_, shell.getOffset(), shell.getNumFunc());
84
85 // multiply shell
86 for (Index i = 0; i < shell.getNumFunc(); i++) {
87 moCoefficients.row(currentFunction + i) *= double(shellmultiplier[i]);
88 }
89 }
90
91 // reorder shell
92 Index l = static_cast<Index>(shell.getL());
93 for (const Transposition& transposition : transpositions_[l]) {
94 moCoefficients.row(currentFunction + transposition.first)
95 .swap(moCoefficients.row(currentFunction + transposition.second));
96 }
97
98 if (!reverse_) { // multiply after reordering
99 // Get multiplier vector for shell
100 std::vector<Index> shellmultiplier =
101 copySegment(multipliers_, shell.getOffset(), shell.getNumFunc());
102
103 // multiply shell
104 for (Index i = 0; i < shell.getNumFunc(); i++) {
105 moCoefficients.row(currentFunction + i) *= double(shellmultiplier[i]);
106 }
107 }
108 }
109}
110void OrbReorder::reorderOperator(Eigen::MatrixXd& Matrixoperator,
111 const AOBasis& basis) {
112 // reorder rows first
113 reorderOrbitals(Matrixoperator, basis);
114 Matrixoperator.transposeInPlace();
115 reorderOrbitals(Matrixoperator, basis);
116 Matrixoperator.transposeInPlace();
117}
118
119} // namespace xtp
120} // namespace votca
Container to hold Basisfunctions for all atoms.
Definition aobasis.h:42
std::vector< Transposition > computeTranspositions(std::vector< Index > vStart, std::vector< Index > vTarget) const
Definition orbreorder.cc:27
OrbTranspositions transpositions_
Definition orbreorder.h:65
OrbReorder(std::array< Index, 49 > reorder, std::array< Index, 49 > multipliers, bool reverse=false)
Definition orbreorder.cc:53
std::array< Index, 49 > reorder_
Definition orbreorder.h:51
void reorderOrbitals(Eigen::MatrixXd &moCoefficients, const AOBasis &basis)
Definition orbreorder.cc:74
void reorderOperator(Eigen::MatrixXd &Matrixoperator, const AOBasis &basis)
std::vector< Index > copySegment(const std::array< Index, 49 > &input, Index start, Index size) const
Definition orbreorder.cc:47
std::array< Index, 49 > votcaOrder_
Definition orbreorder.h:54
std::array< Index, 49 > multipliers_
Definition orbreorder.h:50
Index NumFuncShell(L l)
Definition basisset.cc:100
std::pair< Index, Index > Transposition
Definition orbreorder.h:34
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26