OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
entity_io_pqr_handler.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: Ansgar Philippsen
21 */
22 
23 #ifndef OST_IO_ENTITY_IO_PLUGIN_PQR_H
24 #define OST_IO_ENTITY_IO_PLUGIN_PQR_H
25 
26 #include <ost/mol/entity_handle.hh>
27 #include <ost/mol/chain_handle.hh>
31 
32 #include <boost/iostreams/filtering_stream.hpp>
33 #include <boost/filesystem/fstream.hpp>
34 
35 namespace ost { namespace io {
36 
38 class DLLEXPORT_OST_IO PQRReader {
39 public:
40  PQRReader(const boost::filesystem::path& loc);
41 
42  void Import(mol::EntityHandle& ent);
43 
44  std::vector<mol::AtomHandle> GetSequentialAtoms() const;
45 
46 private:
47 
48  void ParseAndAddAtom(const String& line, mol::EntityHandle& h);
49  void ParseAndAddAtomExpanded(const String& line, mol::EntityHandle& h);
50 
51  std::vector<mol::AtomHandle> sequential_atom_list_;
52  mol::ChainHandle curr_chain_;
53  mol::ResidueHandle curr_residue_;
54  int chain_count_;
55  int residue_count_;
56  int atom_count_;
57  boost::filesystem::ifstream infile_;
58  boost::iostreams::filtering_stream<boost::iostreams::input> in_;
59 };
60 
62 class DLLEXPORT_OST_IO PQRWriter : public mol::EntityVisitor {
63 public:
64  PQRWriter(const String& filename, bool ext=false);
65  PQRWriter(const boost::filesystem::path& filename, bool ext=false);
66  PQRWriter(std::ostream& outstream, bool ext=false);
67 
68  void Write(const mol::EntityView& ent);
69  void Write(const mol::EntityHandle& ent);
70 
71  virtual bool VisitAtom(const mol::AtomHandle& atom);
72  virtual bool VisitResidue(const mol::ResidueHandle& r);
73 
74  void WriteHeader(const mol::EntityView& ent);
75 
76 private:
77  void Init();
78 
79  std::ofstream outfile_;
80  std::ostream& outstream_;
81  bool ext_;
82  int atom_count_;
83  int atom_total_;
84  int res_count_;
85 };
86 
87 class DLLEXPORT_OST_IO EntityIOPQRHandler: public EntityIOHandler {
88 public:
89  virtual void Import(mol::EntityHandle& ent, const boost::filesystem::path& loc);
90 
91  virtual void Export(const mol::EntityView& ent,
92  const boost::filesystem::path& loc) const;
93 
94  virtual void Import(mol::EntityHandle& ent, std::istream& stream);
95 
96  virtual void Export(const mol::EntityView& ent, std::ostream& stream) const;
97 
98  static bool ProvidesImport(const boost::filesystem::path& loc,
99  const String& format="auto");
100  static bool ProvidesExport(const boost::filesystem::path& loc,
101  const String& format="auto");
102  virtual bool RequiresBuilder() const;
103 
104  static String GetFormatName() { return String("Crd"); }
105  static String GetFormatDescription() { return String("CARD format file used by the Charmm software package"); }
106 };
107 
108 
109 typedef EntityIOHandlerFactory<EntityIOPQRHandler> EntityIOPQRHandlerFactory;
110 
112 
113 }} // ns
114 
115 #endif
std::string String
Definition: base.hh:54
Protein or molecule.
mol::EntityHandle DLLEXPORT_OST_IO LoadPQR(const String &file_name)
EntityIOHandlerFactory< EntityIOPQRHandler > EntityIOPQRHandlerFactory
#define DLLEXPORT_OST_IO