OpenStructure
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-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 /*
20  Author: Tobias Schmidt
21  */
22 #ifndef OST_IO_SDF_READER_HH
23 #define OST_IO_SDF_READER_HH
24 
25 #include <boost/filesystem/fstream.hpp>
26 #include <ost/mol/mol.hh>
27 #include <ost/io/module_config.hh>
28 
29 namespace ost { namespace io {
30 
31 class DLLEXPORT_OST_IO SDFReader {
32 public:
33  SDFReader(const String& filename);
34  SDFReader(const boost::filesystem::path& loc);
35  SDFReader(std::istream& instream);
36 
37  bool HasNext();
38 
39  void Import(mol::EntityHandle& ent);
40 
41 private:
42  void ClearState(const boost::filesystem::path& loc);
43  void NextMolecule();
44 
45  void ParseAndAddHeader(const String& line, int line_num, mol::EntityHandle& ent,
46  mol::XCSEditor& editor);
47 
48  void ParseAndAddAtom(const String& line, int line_num, mol::EntityHandle& ent,
49  bool hetatm, mol::XCSEditor& editor);
50 
51  void ParseAndAddBond(const String& line, int line_num, mol::EntityHandle& ent,
52  mol::XCSEditor& editor);
53 
54  mol::ChainHandle curr_chain_;
55  mol::ResidueHandle curr_residue_;
56  int chain_count_;
57  int residue_count_;
58  int atom_count_;
59  int bond_count_;
60  int line_num;
61  boost::filesystem::ifstream infile_;
62  std::istream& instream_;
63 };
64 
65 }}
66 
67 #endif