OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pdb_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 #ifndef OST_IO_PDB_READER_HH
20 #define OST_IO_PDB_READER_HH
21 /*
22  Author: Marco Biasini
23  */
24 
25 #include <boost/iostreams/filtering_stream.hpp>
26 #include <boost/filesystem/fstream.hpp>
27 #include <ost/string_ref.hh>
28 #include <ost/seq/sequence_list.hh>
30 #include <ost/mol/entity_handle.hh>
31 #include <ost/mol/chain_handle.hh>
32 #include <ost/mol/atom_handle.hh>
33 #include <ost/mol/xcs_editor.hh>
34 
35 #include <ost/io/module_config.hh>
36 #include <ost/io/mol/io_profile.hh>
37 namespace ost { namespace io {
38 
39 class DLLEXPORT_OST_IO PDBReader {
40  struct HSEntry {
41  mol::ResNum start;
42  mol::ResNum end;
43  String chain;
44  };
45  struct HetEntry {
46  HetEntry(char c, mol::ResNum n): chain(c), num(n) {}
47  char chain;
48  mol::ResNum num;
49  };
50  struct CompndEntry {
51  CompndEntry(std::vector<String> c, int n): chains(c), mol_id(n) {}
52  std::vector<String> chains;
53  int mol_id;
54  };
55  typedef std::vector<HSEntry> HSList;
56  typedef std::vector<HetEntry> HetList;
57  typedef std::vector<CompndEntry> CompndList;
58 public:
59  PDBReader(const String& filename, const IOProfile& profile);
60  PDBReader(const boost::filesystem::path& loc, const IOProfile& profile);
61  PDBReader(std::istream& instream, const IOProfile& profile);
62 
63  bool HasNext();
64 
65  void Import(mol::EntityHandle& ent,
66  const String& restrict_chains="");
67  void SetReadSeqRes(bool flag) { read_seqres_=flag; }
68  bool GetReadSeqRes() const { return read_seqres_; }
69 
70  seq::SequenceList GetSeqRes() const { return seqres_; }
71 private:
72  void ParseSeqRes(const StringRef& line, int line_num);
74  void ParseCompndEntry(const StringRef& line, int line_num);
75  void ClearState();
76  void AssignSecStructure(mol::EntityHandle ent);
78  void AssignMolIds(mol::EntityHandle ent);
79  void ParseAndAddAtom(const StringRef& line, int line_num,
80  mol::EntityHandle& h, const StringRef& record_type);
81  void ThrowFaultTolerant(const String& msg);
83  bool ParseAtomIdent(const StringRef& line, int line_num,
84  String& chain_name, StringRef& res,
85  mol::ResNum& resnum, StringRef& atom_name, char& alt_loc,
86  const StringRef& record_type, int& serial);
87  void ParseAnisou(const StringRef& line, int line_num,
89  void ParseHelixEntry(const StringRef& line);
90  void ParseStrandEntry(const StringRef& line);
91  void Init(const boost::filesystem::path& loc);
92  bool EnsureLineLength(const StringRef& line, size_t size);
93  void ParseConectEntry(const StringRef& line, int line_num, mol::EntityHandle& ent);
94  std::map<int, mol::AtomHandle> amap_; // <serial_number, AtomHandle>
95  mol::ChainHandle curr_chain_;
96  mol::ResidueHandle curr_residue_;
97  int chain_count_;
98  int residue_count_;
99  int atom_count_;
100  int line_num_;
101  bool hard_end_;
102  int num_model_records_;
103  String restrict_chains_;
104  HSList helix_list_;
105  HSList strand_list_;
106  boost::filesystem::ifstream infile_;
107  std::istream& instream_;
108  boost::iostreams::filtering_stream<boost::iostreams::input> in_;
109  String curr_line_;
110  HetList hets_;
111  CompndList compnds_;
112  std::pair <bool, int> mol_id_;
113  bool skip_next_;
114  bool data_continues_;
115  String old_key_;
116  // this needs to be set to true for reading pqr
117  // file (i.e. pdb formatted file with charges in occupacy
118  // column, and radii in b-factor column)
119  bool is_pqr_;
120  IOProfile profile_;
121  bool charmm_style_;
122  bool warned_name_mismatch_;
123  bool read_seqres_;
124  bool warned_rule_based_;
125  seq::SequenceList seqres_;
126 };
127 
128 }}
129 
130 #endif
convenient datatype for referencing character data
Definition: string_ref.hh:39
bool GetReadSeqRes() const
Definition: pdb_reader.hh:68
std::string String
Definition: base.hh:54
Protein or molecule.
pointer_it< T > end(const std::vector< T > &values)
void SetReadSeqRes(bool flag)
Definition: pdb_reader.hh:67
seq::SequenceList GetSeqRes() const
Definition: pdb_reader.hh:70
linear chain of residues
Definition: chain_handle.hh:52
#define DLLEXPORT_OST_IO
list of sequences.