OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
chemdict_parser.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_CONOP_CHEMDICT_PARSER_HH
20 #define OST_CONOP_CHEMDICT_PARSER_HH
21 
22 /*
23  Author: Marco Biasini
24  */
25 
26 
27 #include <ost/mol/chem_class.hh>
28 #include <ost/mol/chem_type.hh>
31 
32 namespace ost { namespace io {
33 
34 typedef enum {
35  ATOM_SPEC,
36  BOND_SPEC,
37  DESC_SPEC,
38  DONT_KNOW
39 } LoopType;
40 
41 class DLLEXPORT_OST_IO ChemdictParser : public StarParser {
42 public:
43  ChemdictParser(std::istream& stream, conop::Compound::Dialect dialect,
44  bool ignore_reserved=false, bool ignore_obsolete=false):
45  StarParser(stream), compound_(new conop::Compound("UNK")),
46  last_(0), loop_type_(DONT_KNOW), dialect_(dialect),
47  ignore_reserved_(ignore_reserved), ignore_obsolete_(ignore_obsolete)
48  {
49  this->InitTypeMap();
50  this->InitPDBXTypeMap();
51  }
52 
53  virtual bool OnBeginData(const StringRef& data_name);
54 
55  virtual bool OnBeginLoop(const StarLoopDesc& header);
56 
57  virtual void OnDataRow(const StarLoopDesc& header,
58  const std::vector<StringRef>& columns);
59 
60  virtual void OnDataItem(const StarDataItem& item);
61 
62  virtual void OnEndData();
63 
65  {
66  lib_=lib;
67  }
68 private:
69  void InitTypeMap();
70  void InitPDBXTypeMap();
71  bool IsNameReserved(const String& data_name);
73  conop::CompoundPtr compound_;
74  typedef enum {
75  ATOM_NAME=0,
76  ALT_ATOM_NAME=1,
77  IS_AROMATIC=2,
78  ORDINAL=3,
79  IS_LEAVING=4,
80  ELE=5,
81  CHARGE=6,
82  ATOM_ID1=0,
83  ATOM_ID2=1,
84  BOND_ORDER=2,
85  DESC_TYPE=0,
86  DESC=1,
87  PROGRAM=2,
88  } PropIndex;
89  char last_;
90  int indices_[10];
91  static std::map<String, mol::ChemClass> tm_;
92  static std::map<String, mol::ChemType> xtm_;
93  std::map<String, int> atom_map_;
94  LoopType loop_type_;
95  conop::AtomSpec atom_;
96  conop::Compound::Dialect dialect_;
97  bool ignore_reserved_;
98  bool ignore_obsolete_;
99 };
100 
101 
102 }}
103 
104 
105 #endif
convenient datatype for referencing character data
Definition: string_ref.hh:39
std::string String
Definition: base.hh:54
parser for the STAR file format
Definition: star_parser.hh:114
boost::shared_ptr< CompoundLib > CompoundLibPtr
Definition: compound_lib.hh:32
ChemdictParser(std::istream &stream, conop::Compound::Dialect dialect, bool ignore_reserved=false, bool ignore_obsolete=false)
boost::shared_ptr< Compound > CompoundPtr
Definition: compound.hh:134
#define DLLEXPORT_OST_IO
void SetCompoundLib(const conop::CompoundLibPtr &lib)