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-2011 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  DONT_KNOW
38 } LoopType;
39 
40 class DLLEXPORT_OST_IO ChemdictParser : public StarParser {
41 public:
42  ChemdictParser(std::istream& stream, conop::Compound::Dialect dialect):
43  StarParser(stream), compound_(new conop::Compound("UNK")),
44  last_(0), loop_type_(DONT_KNOW), dialect_(dialect)
45  {
46  this->InitTypeMap();
47  this->InitPDBXTypeMap();
48  }
49 
50  virtual bool OnBeginData(const StringRef& data_name);
51 
52  virtual bool OnBeginLoop(const StarLoopDesc& header);
53 
54  virtual void OnDataRow(const StarLoopDesc& header,
55  const std::vector<StringRef>& columns);
56 
57  virtual void OnDataItem(const StarDataItem& item);
58 
59  virtual void OnEndData();
60 
61  void SetCompoundLib(const conop::CompoundLibPtr& lib)
62  {
63  lib_=lib;
64  }
65 private:
66  void InitTypeMap();
67  void InitPDBXTypeMap();
69  conop::CompoundPtr compound_;
70  typedef enum {
71  ATOM_NAME=0,
72  ALT_ATOM_NAME=1,
73  IS_AROMATIC=2,
74  ORDINAL=3,
75  IS_LEAVING=4,
76  ELE=5,
77  STEREO_CONF=6,
78  ATOM_ID1=0,
79  ATOM_ID2=1,
80  BOND_ORDER=2
81  } PropIndex;
82  char last_;
83  int indices_[10];
84  bool insert_;
85  static std::map<String, mol::ChemClass> tm_;
86  static std::map<String, mol::ChemType> xtm_;
87  std::map<String, int> atom_map_;
88  LoopType loop_type_;
89  conop::AtomSpec atom_;
90  conop::Compound::Dialect dialect_;
91 };
92 
93 
94 }}
95 
96 
97 #endif