votca 2024.2-dev
Loading...
Searching...
No Matches
qmstate.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// Standard includes
21#include <regex>
22
23// Third party includes
24#include <boost/algorithm/string.hpp>
25#include <boost/format.hpp>
26#include <boost/lexical_cast.hpp>
27#include <boost/regex.hpp>
28
29// Local VOTCA includes
30#include "votca/xtp/qmstate.h"
31
32namespace votca {
33namespace xtp {
34
35std::string QMStateType::ToString() const {
36 std::string identifier = "";
37 switch (type_) {
39 identifier = "s";
40 break;
42 identifier = "t";
43 break;
45 identifier = "pqp";
46 break;
48 identifier = "dqp";
49 break;
51 identifier = "ks";
52 break;
54 identifier = "n";
55 break;
57 identifier = "h";
58 break;
60 identifier = "e";
61 break;
63 identifier = "l";
64 break;
65 }
66 return identifier;
67}
68
69std::string QMStateType::ToLongString() const {
70 std::string identifier = "";
71 switch (type_) {
73 identifier = "singlet";
74 break;
76 identifier = "triplet";
77 break;
79 identifier = "pert-qparticle";
80 break;
82 identifier = "diag-qparticle";
83 break;
85 identifier = "Kohn-Sham-orbital";
86 break;
88 identifier = "groundstate";
89 break;
91 identifier = "hole";
92 break;
94 identifier = "electron";
95 break;
97 identifier = "localized-orbital";
98 break;
99 }
100 return identifier;
101}
102
103void QMStateType::FromString(const std::string& statetypestring) {
104 std::string lower = boost::algorithm::to_lower_copy(statetypestring);
105 boost::trim(lower);
106 if (lower == "s" || lower == "singlet") {
108 } else if (lower == "t" || lower == "triplet") {
110 } else if (lower == "pqp" || lower == "pert-qparticle") {
112 } else if (lower == "dqp" || lower == "diag-qparticle" || lower == "qpdiag") {
114 } else if (lower == "ks" || lower == "kohn-sham-orbital") {
116 } else if (lower == "n" || lower == "groundstate" || lower == "gs") {
118 } else if (lower == "h" || lower == "hole") {
120 } else if (lower == "e" || lower == "electron") {
122 } else if (lower == "l" || lower == "localized-orbital") {
124 } else {
125 throw std::runtime_error("Statetype:" + statetypestring +
126 " not recognized");
127 }
128}
129
130std::string QMState::ToLongString() const {
131 Index index = index_;
133 index++;
136 return type_.ToLongString();
137 }
138 std::string result =
139 type_.ToLongString() + (boost::format(" %i") % index).str();
140 if (transition_) {
141 result = "Groundstate to " + result;
142 }
143 return result;
144}
145
146std::string QMState::ToString() const {
147 Index index = index_;
149 index++;
152 return type_.ToString();
153 }
154 std::string result = type_.ToString() + (boost::format("%i") % index).str();
155 if (transition_) {
156 result = "n2" + result;
157 }
158 return result;
159}
160
161Index QMState::DetermineIndex(const std::string& statestring) {
162
163 std::smatch search;
164 std::regex reg("[0-9]+");
165
166 bool found_integer = std::regex_search(statestring, search, reg);
167 if (!found_integer) {
168
170 return 0;
171 }
172
173 throw std::runtime_error("Found no index in string: " + statestring);
174 }
175 if (search.size() > 1) {
176 throw std::runtime_error("Found more than 1 index in string: " +
177 statestring);
178 }
179
180 Index index = boost::lexical_cast<Index>(search.str(0));
183 index--;
184 }
185 return index;
186}
187
188QMStateType QMState::DetermineType(const std::string& statestring) {
189 std::regex reg("[^0-9]+");
190 std::smatch search;
191
192 bool found_typestring = std::regex_search(statestring, search, reg);
193 if (!found_typestring) {
194 throw std::runtime_error("Found no type in string: " + statestring);
195 }
196 if (search.size() > 1) {
197 throw std::runtime_error("Found more than one type in string: " +
198 statestring);
199 }
200 return QMStateType(search.str(0));
201}
202
203void QMState::FromString(const std::string& statestring) {
204 std::string lower = boost::algorithm::to_lower_copy(statestring);
205 boost::trim(lower);
206 std::string rest;
207 if (boost::starts_with(lower, "n2")) {
208 transition_ = true;
209 rest = lower.substr(2);
210 } else if (boost::starts_with(lower, "groundstate to")) {
211 transition_ = true;
212 rest = lower.substr(14);
213 } else {
214 rest = lower;
215 transition_ = false;
216 }
217 boost::trim(rest);
218
219 type_ = DetermineType(rest);
220 if (type_ != QMStateType::Singlet && transition_ == true) {
221 throw std::runtime_error("Transition states only exist for singlets.");
222 }
223 if (type_ == QMStateType::Gstate) {
224 index_ = -1;
225 } else {
226 index_ = DetermineIndex(rest);
227 }
228}
229
230} // namespace xtp
231} // namespace votca
std::string ToLongString() const
Definition qmstate.cc:69
std::string ToString() const
Definition qmstate.cc:35
bool isExciton() const
Definition qmstate.h:71
void FromString(const std::string &statetypestring)
Definition qmstate.cc:103
std::string ToLongString() const
Definition qmstate.cc:130
QMStateType type_
Definition qmstate.h:167
void FromString(const std::string &statestring)
Definition qmstate.cc:203
std::string ToString() const
Definition qmstate.cc:146
QMStateType DetermineType(const std::string &statestring)
Definition qmstate.cc:188
Index DetermineIndex(const std::string &statestring)
Definition qmstate.cc:161
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26