OpenStructure
entity_io_crd_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-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_IO_ENTITY_IO_PLUGIN_CRD_H
20 #define OST_IO_ENTITY_IO_PLUGIN_CRD_H
21 
22 /*
23  CHARMM coordinate file import
24  Author: Ansgar Philippsen
25  */
27 
28 #include <boost/iostreams/filtering_stream.hpp>
29 #include <boost/filesystem/fstream.hpp>
30 
31 namespace ost { namespace io {
32 
33 class DLLEXPORT_OST_IO CRDReader {
34 public:
35  CRDReader(const boost::filesystem::path& loc);
36 
37  void Import(mol::EntityHandle& ent);
38 
39  std::vector<mol::AtomHandle> GetSequentialAtoms() const;
40 
41 private:
42 
43  void ParseAndAddAtom(const String& line, mol::EntityHandle& h);
44  void ParseAndAddAtomExpanded(const String& line, mol::EntityHandle& h);
45 
46  std::vector<mol::AtomHandle> sequential_atom_list_;
47  mol::ChainHandle curr_chain_;
48  mol::ResidueHandle curr_residue_;
49  int chain_count_;
50  int residue_count_;
51  int atom_count_;
52  boost::filesystem::ifstream infile_;
53  boost::iostreams::filtering_stream<boost::iostreams::input> in_;
54 };
55 
56 
57 class DLLEXPORT_OST_IO CRDWriter : public mol::EntityVisitor {
58 public:
59  CRDWriter(const String& filename);
60  CRDWriter(const boost::filesystem::path& filename);
61  CRDWriter(std::ostream& outstream);
62 
63  virtual bool VisitAtom(const mol::AtomHandle& atom);
64 
65  void WriteHeader(const mol::EntityView& ent);
66 
67 private:
68  std::ofstream outfile_;
69  std::ostream& outstream_;
70  int atom_count_;
71  int atom_total_;
72 };
73 
74 class DLLEXPORT_OST_IO EntityIOCRDHandler: public EntityIOHandler {
75 public:
76  virtual void Import(mol::EntityHandle& ent, const boost::filesystem::path& loc);
77 
78  virtual void Export(const mol::EntityView& ent,
79  const boost::filesystem::path& loc) const;
80 
81  virtual void Import(mol::EntityHandle& ent, std::istream& stream);
82 
83  virtual void Export(const mol::EntityView& ent, std::ostream& stream) const;
84 
85  static bool ProvidesImport(const boost::filesystem::path& loc,
86  const String& format="auto");
87  static bool ProvidesExport(const boost::filesystem::path& loc,
88  const String& format="auto");
89  virtual bool RequiresBuilder() const;
90 
91  static String GetFormatName() { return String("Crd"); }
92  static String GetFormatDescription() { return String("CARD format file used by the Charmm software package"); }
93 };
94 
95 
96 typedef EntityIOHandlerFactory<EntityIOCRDHandler> EntityIOCRDHandlerFactory;
97 
99 
100 }} // ns
101 
102 #endif