OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sdf_reader.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 /*
20  Author: Tobias Schmidt
21  */
22 #ifndef OST_IO_SDF_READER_HH
23 #define OST_IO_SDF_READER_HH
24 
25 #include <tuple>
26 #include <boost/iostreams/filtering_stream.hpp>
27 #include <boost/filesystem/fstream.hpp>
28 #include <ost/mol/chain_handle.hh>
30 #include <ost/io/module_config.hh>
31 
32 namespace ost { namespace io {
33 
34 
35 
36 
37 class DLLEXPORT_OST_IO SDFReader {
38 public:
39  SDFReader(const String& filename);
40  SDFReader(const boost::filesystem::path& loc);
41  SDFReader(std::istream& instream);
42 
43  bool HasNext();
44 
45  void Import(mol::EntityHandle& ent);
46 
47 private:
48  typedef std::tuple<int, String, String, String, String, String> atom_data;
49  typedef std::tuple<String, String, String> bond_data;
50  typedef std::tuple<String, String> charge_data;
51  typedef std::tuple<std::vector<String>, std::map<String, String>> v3000_line_tokens;
52 
53  boost::iostreams::filtering_stream<boost::iostreams::input>& GetLine(
54  boost::iostreams::filtering_stream<boost::iostreams::input>& in,
55  String& line);
56 
57  void ClearState(const boost::filesystem::path& loc);
58  void NextMolecule();
59 
60  void ParseHeader(const String& line, int line_num, mol::EntityHandle& ent,
61  mol::XCSEditor& editor);
62  void SetCounts(const String& anum, const String bnum, int line_num);
63 
64  atom_data ParseAtom(const String& line, int line_num);
65  void AddAtom(const atom_data& atom_tuple, int line_num, mol::EntityHandle& ent,
66  bool hetatm, mol::XCSEditor& editor);
67 
68  bond_data ParseBond(const String& line, int line_num);
69  void AddBond(const bond_data& bond_tuple, int line_num, mol::EntityHandle& ent,
70  mol::XCSEditor& editor);
71 
72  std::vector<charge_data> ParseMCharge(const String& line, int line_num);
73  void AddCharge(const charge_data& charge_tuple, int line_num, mol::EntityHandle& ent,
74  mol::XCSEditor& editor);
75  void ResetCharges();
76 
77  // V3000 methods
78  v3000_line_tokens TokenizeV3000Line(const String& line, int line_num,
79  int num_posval);
80  String CleanupV3000Line(const String& line);
81  void ProcessV3000Line(const String& line, mol::EntityHandle& ent,
82  mol::XCSEditor& editor);
83  atom_data ParseV3000Atom(const String& line, int line_num);
84  bond_data ParseV3000Bond(const String& line, int line_num);
85  std::tuple<String, String> ParseV3000Counts(const String& line, int line_num);
86  void VerifyV3000Counts();
87 
88  String curr_chain_name_;
89  mol::ResidueKey curr_res_key_;
90  mol::ChainHandle curr_chain_;
91  mol::ResidueHandle curr_residue_;
92  int chain_count_;
93  int residue_count_;
94  int atom_count_;
95  int bond_count_;
96  int line_num;
97  boost::filesystem::ifstream infile_;
98  std::istream& instream_;
99  boost::iostreams::filtering_stream<boost::iostreams::input> in_;
100  String version_;
101  bool v3000_atom_block_;
102  bool v3000_bond_block_;
103  bool charges_reset_;
104 };
105 
106 }}
107 
108 #endif
String ResidueKey
std::string String
Definition: base.hh:54
#define DLLEXPORT_OST_IO