Molassembler  3.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SmilesParseData.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_IO_SMILES_PARSER_DATA_H
9 #define INCLUDE_MOLASSEMBLER_IO_SMILES_PARSER_DATA_H
10 
11 #include <boost/fusion/adapted/struct/adapt_struct.hpp>
12 #include <boost/fusion/include/adapt_struct.hpp>
13 
16 #include "boost/optional.hpp"
17 #include "Molassembler/Types.h"
18 
19 namespace Scine {
20 namespace Molassembler {
21 namespace IO {
22 
23 struct ElementData {
24  unsigned Z = 0;
25  bool aromatic = false;
26 
27  ElementData() = default;
28  explicit ElementData(Utils::ElementType e) : Z(Utils::ElementInfo::Z(e)) {}
29 
30  static inline ElementData aromaticElement(Utils::ElementType e) {
31  ElementData d(e);
32  d.aromatic = true;
33  return d;
34  }
35 };
36 
37 struct ChiralData {
38  Shapes::Shape shape;
39  unsigned chiralIndex;
40 };
41 
42 struct AtomData {
43  unsigned A = 0;
44  ElementData partialElement;
45  boost::optional<ChiralData> chiralOptional;
46  boost::optional<unsigned> hCount;
47  boost::optional<int> chargeOptional;
48  bool atomBracket = false;
49 
50  inline Utils::ElementType getElement() const {
51  if(partialElement.Z == 0) {
52  return Utils::ElementType::none;
53  }
54 
55  if(A == 0) {
56  return Utils::ElementInfo::element(partialElement.Z);
57  }
58 
59  return Utils::ElementInfo::isotope(partialElement.Z, A);
60  }
61 };
62 
63 enum class SmilesBondType {
64  Single,
65  Double,
66  Triple,
67  Quadruple,
68  Aromatic,
69  Forward,
70  Backward
71 };
72 
73 struct BondData {
74  static BondType toBondType(SmilesBondType b) {
75  switch(b) {
76  case SmilesBondType::Single:
77  case SmilesBondType::Aromatic:
78  case SmilesBondType::Forward:
79  case SmilesBondType::Backward:
80  return BondType::Single;
81  case SmilesBondType::Double:
82  return BondType::Double;
83  case SmilesBondType::Triple:
84  return BondType::Triple;
85  case SmilesBondType::Quadruple:
86  return BondType::Quadruple;
87  default:
88  throw std::logic_error("Unhandled bond type");
89  }
90  }
91 
92  boost::optional<SmilesBondType> type;
93  boost::optional<unsigned> ringNumber;
94 };
95 
96 } // namespace IO
97 } // namespace Molassembler
98 } // namespace Scine
99 
100 BOOST_FUSION_ADAPT_STRUCT(
102  (unsigned, Z),
103  (bool, aromatic)
104 )
105 
106 BOOST_FUSION_ADAPT_STRUCT(
107  Scine::Molassembler::IO::ChiralData,
108  (Scine::Molassembler::Shapes::Shape, shape),
109  (unsigned, chiralIndex)
110 )
111 
112 BOOST_FUSION_ADAPT_STRUCT(
113  Scine::Molassembler::IO::AtomData,
114  (unsigned, A),
115  (Scine::Molassembler::IO::ElementData, partialElement),
116  (boost::optional<Scine::Molassembler::IO::ChiralData>, chiralOptional),
117  (boost::optional<unsigned>, hCount),
118  (boost::optional<int>, chargeOptional),
119  (bool, atomBracket)
120 )
121 
122 BOOST_FUSION_ADAPT_STRUCT(
123  Scine::Molassembler::IO::BondData,
124  (boost::optional<Scine::Molassembler::BondType>, type),
125  (boost::optional<unsigned>, ringNumber)
126 )
127 
128 #endif
static ElementType element(unsigned z)
Defines basic types widely shared across the project.
ShapeResult shape(const PositionCollection &normalizedPositions, Shape shape)
Forwarding function to calculate the continuous shape measure.
Definition: SmilesParseData.h:37
static ElementType isotope(unsigned z, unsigned a)
static constexpr unsigned Z(const ElementType e) noexcept
Definition: SmilesParseData.h:42
BondType
Discrete bond type numeration.
Definition: Types.h:26
Definition: SmilesParseData.h:73
Defines symmetry names and total count.
Shape
Enumeration of all contained symmetry names.
Definition: Shapes.h:28
Definition: SmilesParseData.h:23