Gemmi C++ API
Loading...
Searching...
No Matches
enumstr.hpp
Go to the documentation of this file.
1// Copyright 2018 Global Phasing Ltd.
2//
3// Converts between enums (EntityType, PolymerType, Connection::Type,
4// SoftwareItem::Classification) and mmCIF strings.
5
6#ifndef GEMMI_ENUMSTR_HPP_
7#define GEMMI_ENUMSTR_HPP_
8
9#include "metadata.hpp" // for EntityType, PolymerType, SoftwareItem
10#include "util.hpp" // for iequal
11
12namespace gemmi {
13
14inline const char* entity_type_to_string(EntityType entity_type) {
15 switch (entity_type) {
16 case EntityType::Polymer: return "polymer";
17 case EntityType::Branched: return "branched";
18 case EntityType::NonPolymer: return "non-polymer";
19 case EntityType::Water: return "water";
20 default /*EntityType::Unknown*/: return "?";
21 }
22}
23
24inline EntityType entity_type_from_string(const std::string& t) {
25 if (t == "polymer") return EntityType::Polymer;
26 if (t == "branched") return EntityType::Branched;
27 if (t == "non-polymer") return EntityType::NonPolymer;
28 if (t == "water") return EntityType::Water;
30}
31
32
33inline const char* polymer_type_to_string(PolymerType polymer_type) {
34 switch (polymer_type) {
35 case PolymerType::PeptideL: return "polypeptide(L)";
36 case PolymerType::PeptideD: return "polypeptide(D)";
37 case PolymerType::Dna: return "polydeoxyribonucleotide";
38 case PolymerType::Rna: return "polyribonucleotide";
40 return "'polydeoxyribonucleotide/polyribonucleotide hybrid'";
41 case PolymerType::SaccharideD: return "polysaccharide(D)";
42 case PolymerType::SaccharideL: return "polysaccharide(L)";
43 case PolymerType::Other: return "other";
44 case PolymerType::Pna: return "'peptide nucleic acid'";
45 case PolymerType::CyclicPseudoPeptide: return "cyclic-pseudo-peptide";
46 default /*PolymerType::Unknown*/: return "?";
47 }
48}
49
50inline PolymerType polymer_type_from_string(const std::string& t) {
51 if (t == "polypeptide(L)") return PolymerType::PeptideL;
52 if (t == "polydeoxyribonucleotide") return PolymerType::Dna;
53 if (t == "polyribonucleotide") return PolymerType::Rna;
54 if (t == "polydeoxyribonucleotide/polyribonucleotide hybrid")
56 if (t == "polypeptide(D)") return PolymerType::PeptideD;
57 if (t == "polysaccharide(D)") return PolymerType::SaccharideD;
58 if (t == "other") return PolymerType::Other;
59 if (t == "peptide nucleic acid") return PolymerType::Pna;
60 if (t == "cyclic-pseudo-peptide") return PolymerType::CyclicPseudoPeptide;
61 if (t == "polysaccharide(L)") return PolymerType::SaccharideL;
63}
64
65
67 static constexpr const char* type_ids[] = {
68 "covale", "disulf", "hydrog", "metalc", "."
69 };
70 return type_ids[t];
71}
72
74 for (int i = 0; i != Connection::Unknown; ++i)
76 return Connection::Type(i);
78}
79
80inline
82 switch (c) {
83 case SoftwareItem::DataCollection: return "data collection";
84 case SoftwareItem::DataExtraction: return "data extraction";
85 case SoftwareItem::DataProcessing: return "data processing";
86 case SoftwareItem::DataReduction: return "data reduction";
87 case SoftwareItem::DataScaling: return "data scaling";
88 case SoftwareItem::ModelBuilding: return "model building";
89 case SoftwareItem::Phasing: return "phasing";
90 case SoftwareItem::Refinement: return "refinement";
91 case SoftwareItem::Unspecified: return "";
92 }
94}
95
97software_classification_from_string(const std::string& str) {
98 if (iequal(str, "data collection")) return SoftwareItem::DataCollection;
99 if (iequal(str, "data extraction")) return SoftwareItem::DataExtraction;
100 if (iequal(str, "data processing")) return SoftwareItem::DataProcessing;
101 if (iequal(str, "data reduction")) return SoftwareItem::DataReduction;
102 if (iequal(str, "data scaling")) return SoftwareItem::DataScaling;
103 if (iequal(str, "model building")) return SoftwareItem::ModelBuilding;
104 if (iequal(str, "phasing")) return SoftwareItem::Phasing;
105 if (iequal(str, "refinement")) return SoftwareItem::Refinement;
107}
108
109} // namespace gemmi
110#endif
Connection::Type connection_type_from_string(const std::string &t)
Definition enumstr.hpp:73
std::string software_classification_to_string(SoftwareItem::Classification c)
Definition enumstr.hpp:81
const char * polymer_type_to_string(PolymerType polymer_type)
Definition enumstr.hpp:33
const char * connection_type_to_string(Connection::Type t)
Definition enumstr.hpp:66
PolymerType polymer_type_from_string(const std::string &t)
Definition enumstr.hpp:50
EntityType entity_type_from_string(const std::string &t)
Definition enumstr.hpp:24
SoftwareItem::Classification software_classification_from_string(const std::string &str)
Definition enumstr.hpp:97
const char * entity_type_to_string(EntityType entity_type)
Definition enumstr.hpp:14
void unreachable()
Definition fail.hpp:80
bool iequal(const std::string &str, const std::string &low)
Definition util.hpp:89