votca 2026-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;
66 identifier = "XU";
67 break;
68 }
69 return identifier;
70}
71
72std::string QMStateType::ToLongString() const {
73 std::string identifier = "";
74 switch (type_) {
76 identifier = "singlet";
77 break;
79 identifier = "triplet";
80 break;
82 identifier = "pert-qparticle";
83 break;
85 identifier = "diag-qparticle";
86 break;
88 identifier = "Kohn-Sham-orbital";
89 break;
91 identifier = "groundstate";
92 break;
94 identifier = "hole";
95 break;
97 identifier = "electron";
98 break;
100 identifier = "localized-orbital";
101 break;
103 identifier = "uks-exciton";
104 break;
105 }
106 return identifier;
107}
108
109void QMStateType::FromString(const std::string& statetypestring) {
110 std::string lower = boost::algorithm::to_lower_copy(statetypestring);
111 boost::trim(lower);
112 if (lower == "s" || lower == "singlet") {
114 } else if (lower == "t" || lower == "triplet") {
116 } else if (lower == "pqp" || lower == "pert-qparticle") {
118 } else if (lower == "dqp" || lower == "diag-qparticle" || lower == "qpdiag") {
120 } else if (lower == "ks" || lower == "kohn-sham-orbital") {
122 } else if (lower == "n" || lower == "groundstate" || lower == "gs") {
124 } else if (lower == "h" || lower == "hole") {
126 } else if (lower == "e" || lower == "electron") {
128 } else if (lower == "l" || lower == "localized-orbital") {
130 } else if (lower == "xu" || lower == "uks-exciton" ||
131 lower == "exciton_uks") {
133 } else {
134 throw std::runtime_error("Statetype:" + statetypestring +
135 " not recognized");
136 }
137}
138
139std::string QMState::ToLongString() const {
140 Index index = index_;
142 index++;
145 return type_.ToLongString();
146 }
147 std::string result =
148 type_.ToLongString() + (boost::format(" %i") % index).str();
149 if (transition_) {
150 result = "Groundstate to " + result;
151 }
152 return result;
153}
154
155std::string QMState::ToString() const {
156 Index index = index_;
158 index++;
161 return type_.ToString();
162 }
163 std::string result = type_.ToString() + (boost::format("%i") % index).str();
164 if (transition_) {
165 result = "n2" + result;
166 }
167 return result;
168}
169
170Index QMState::DetermineIndex(const std::string& statestring) {
171
172 std::smatch search;
173 std::regex reg("[0-9]+");
174
175 bool found_integer = std::regex_search(statestring, search, reg);
176 if (!found_integer) {
177
179 return 0;
180 }
181
182 throw std::runtime_error("Found no index in string: " + statestring);
183 }
184 if (search.size() > 1) {
185 throw std::runtime_error("Found more than 1 index in string: " +
186 statestring);
187 }
188
189 Index index = boost::lexical_cast<Index>(search.str(0));
190 if (type_.isExciton() || type_ == QMStateType::Electron ||
192 index--;
193 }
194 return index;
195}
196
197QMStateType QMState::DetermineType(const std::string& statestring) {
198 std::regex reg("[^0-9]+");
199 std::smatch search;
200
201 bool found_typestring = std::regex_search(statestring, search, reg);
202 if (!found_typestring) {
203 throw std::runtime_error("Found no type in string: " + statestring);
204 }
205 if (search.size() > 1) {
206 throw std::runtime_error("Found more than one type in string: " +
207 statestring);
208 }
209 return QMStateType(search.str(0));
210}
211
212void QMState::FromString(const std::string& statestring) {
213 std::string lower = boost::algorithm::to_lower_copy(statestring);
214 boost::trim(lower);
215 std::string rest;
216 if (boost::starts_with(lower, "n2")) {
217 transition_ = true;
218 rest = lower.substr(2);
219 } else if (boost::starts_with(lower, "groundstate to")) {
220 transition_ = true;
221 rest = lower.substr(14);
222 } else {
223 rest = lower;
224 transition_ = false;
225 }
226 boost::trim(rest);
227
228 type_ = DetermineType(rest);
229 if (type_ != QMStateType::Singlet && transition_ == true) {
230 throw std::runtime_error("Transition states only exist for singlets.");
231 }
232 if (type_ == QMStateType::Gstate) {
233 index_ = -1;
234 } else {
235 index_ = DetermineIndex(rest);
236 }
237}
238
239} // namespace xtp
240} // namespace votca
std::string ToLongString() const
Definition qmstate.cc:72
std::string ToString() const
Definition qmstate.cc:35
void FromString(const std::string &statetypestring)
Definition qmstate.cc:109
std::string ToLongString() const
Definition qmstate.cc:139
QMStateType type_
Definition qmstate.h:170
void FromString(const std::string &statestring)
Definition qmstate.cc:212
std::string ToString() const
Definition qmstate.cc:155
QMStateType DetermineType(const std::string &statestring)
Definition qmstate.cc:197
Index DetermineIndex(const std::string &statestring)
Definition qmstate.cc:170
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26