votca 2024.2-dev
Loading...
Searching...
No Matches
segid.h
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#pragma once
21#ifndef VOTCA_XTP_SEGID_H
22#define VOTCA_XTP_SEGID_H
23
24// Standard includes
25#include <string>
26
27// VOTCA includes
29
30// Local VOTCA includes
31#include "qmstate.h"
32
41namespace votca {
42namespace xtp {
43
44class SegId {
45 public:
46 SegId(std::string input) {
47 tools::Tokenizer tok(input, ":");
48 std::vector<std::string> results = tok.ToVector();
49 if (results.size() != 2) {
50 throw std::runtime_error("Malformed string '" + input + "' for segment");
51 }
52 id_ = std::stoi(results[0]);
53 TestStringForQMState(results[1]);
54 }
55
56 SegId(Index id, std::string geometry) : id_(id) {
57 TestStringForQMState(geometry);
58 }
59
60 Index Id() const { return id_; }
61 bool hasFile() const { return hasfilename_; }
62 std::string FileName() const { return filename_; }
63 QMState getQMState() const { return state_; }
64
65 private:
66 void TestStringForQMState(const std::string& result) {
67 std::string extension = tools::filesystem::GetFileExtension(result);
68 if (extension == "pdb" || extension == "xyz" || extension == "mps") {
69 hasfilename_ = true;
70 filename_ = result;
71 } else {
72 try {
73 state_ = QMState(result);
74 hasfilename_ = false;
75 } catch (std::runtime_error&) {
76 throw std::runtime_error("'" + result +
77 "' is neither a QMState nor a filename. Did "
78 "you maybe forget the fileending");
79 }
80 }
81 }
82 bool hasfilename_ = false;
84 std::string filename_ = "";
86};
87
88} // namespace xtp
89} // namespace votca
90
91#endif // VOTCA_XTP_SEGID_H
break string into words
Definition tokenizer.h:72
std::vector< T > ToVector()
store all words in a vector of type T, does type conversion.
Definition tokenizer.h:109
Identifier for QMstates. Strings like S1 are converted into enum +zero indexed int.
Definition qmstate.h:132
QMState getQMState() const
Definition segid.h:63
std::string FileName() const
Definition segid.h:62
void TestStringForQMState(const std::string &result)
Definition segid.h:66
QMState state_
Definition segid.h:85
SegId(std::string input)
Definition segid.h:46
bool hasfilename_
Definition segid.h:82
bool hasFile() const
Definition segid.h:61
std::string filename_
Definition segid.h:84
SegId(Index id, std::string geometry)
Definition segid.h:56
Index Id() const
Definition segid.h:60
std::string GetFileExtension(const std::string &filename)
Definition filesystem.cc:34
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26