00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef OST_IO_ENTITY_IO_PLUGIN_CRD_H
00024 #define OST_IO_ENTITY_IO_PLUGIN_CRD_H
00025
00026 #include <ost/mol/entity_handle.hh>
00027 #include <ost/mol/chain_handle.hh>
00028 #include <ost/mol/residue_handle.hh>
00029 #include <ost/mol/entity_visitor.hh>
00030 #include <ost/io/mol/entity_io_handler.hh>
00031
00032 #include <boost/iostreams/filtering_stream.hpp>
00033 #include <boost/filesystem/fstream.hpp>
00034
00035 namespace ost { namespace io {
00036
00038 class DLLEXPORT_OST_IO CRDReader {
00039 public:
00040 CRDReader(const boost::filesystem::path& loc);
00041
00042 void Import(mol::EntityHandle& ent);
00043
00044 std::vector<mol::AtomHandle> GetSequentialAtoms() const;
00045
00046 private:
00047
00048 void ParseAndAddAtom(const String& line, mol::EntityHandle& h);
00049 void ParseAndAddAtomExpanded(const String& line, mol::EntityHandle& h);
00050
00051 std::vector<mol::AtomHandle> sequential_atom_list_;
00052 mol::ChainHandle curr_chain_;
00053 mol::ResidueHandle curr_residue_;
00054 int chain_count_;
00055 int residue_count_;
00056 int atom_count_;
00057 boost::filesystem::ifstream infile_;
00058 boost::iostreams::filtering_stream<boost::iostreams::input> in_;
00059 };
00060
00062 class DLLEXPORT_OST_IO CRDWriter : public mol::EntityVisitor {
00063 public:
00064 CRDWriter(const String& filename, bool ext=false);
00065 CRDWriter(const boost::filesystem::path& filename, bool ext=false);
00066 CRDWriter(std::ostream& outstream, bool ext=false);
00067
00068 void Write(const mol::EntityView& ent);
00069 void Write(const mol::EntityHandle& ent);
00070
00071 virtual bool VisitAtom(const mol::AtomHandle& atom);
00072 virtual bool VisitResidue(const mol::ResidueHandle& r);
00073
00074 void WriteHeader(const mol::EntityView& ent);
00075
00076 private:
00077 void Init();
00078
00079 std::ofstream outfile_;
00080 std::ostream& outstream_;
00081 bool ext_;
00082 int atom_count_;
00083 int atom_total_;
00084 int res_count_;
00085 };
00086
00087 class DLLEXPORT_OST_IO EntityIOCRDHandler: public EntityIOHandler {
00088 public:
00089 virtual void Import(mol::EntityHandle& ent, const boost::filesystem::path& loc);
00090
00091 virtual void Export(const mol::EntityView& ent,
00092 const boost::filesystem::path& loc) const;
00093
00094 virtual void Import(mol::EntityHandle& ent, std::istream& stream);
00095
00096 virtual void Export(const mol::EntityView& ent, std::ostream& stream) const;
00097
00098 static bool ProvidesImport(const boost::filesystem::path& loc,
00099 const String& format="auto");
00100 static bool ProvidesExport(const boost::filesystem::path& loc,
00101 const String& format="auto");
00102 virtual bool RequiresProcessor() const;
00103
00104 static String GetFormatName() { return String("Crd"); }
00105 static String GetFormatDescription() { return String("CARD format file used by the Charmm software package"); }
00106 };
00107
00108
00109 typedef EntityIOHandlerFactory<EntityIOCRDHandler> EntityIOCRDHandlerFactory;
00110
00111 mol::EntityHandle DLLEXPORT_OST_IO LoadCRD(const String& file_name);
00112
00113 }}
00114
00115 #endif