00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2010 by the OpenStructure authors 00005 // 00006 // This library is free software; you can redistribute it and/or modify it under 00007 // the terms of the GNU Lesser General Public License as published by the Free 00008 // Software Foundation; either version 3.0 of the License, or (at your option) 00009 // any later version. 00010 // This library is distributed in the hope that it will be useful, but WITHOUT 00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00013 // details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, Inc., 00017 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 //------------------------------------------------------------------------------ 00019 #ifndef OST_IO_ENTITY_IO_PLUGIN_CRD_H 00020 #define OST_IO_ENTITY_IO_PLUGIN_CRD_H 00021 00022 /* 00023 CHARMM coordinate file import 00024 Author: Ansgar Philippsen 00025 */ 00026 #include <ost/io/mol/entity_io_handler.hh> 00027 00028 #include <boost/iostreams/filtering_stream.hpp> 00029 #include <boost/filesystem/fstream.hpp> 00030 00031 namespace ost { namespace io { 00032 00033 class DLLEXPORT_OST_IO CRDReader { 00034 public: 00035 CRDReader(const boost::filesystem::path& loc); 00036 00037 void Import(mol::EntityHandle& ent); 00038 00039 std::vector<mol::AtomHandle> GetSequentialAtoms() const; 00040 00041 private: 00042 00043 void ParseAndAddAtom(const String& line, mol::EntityHandle& h); 00044 00045 std::vector<mol::AtomHandle> sequential_atom_list_; 00046 mol::ChainHandle curr_chain_; 00047 mol::ResidueHandle curr_residue_; 00048 int chain_count_; 00049 int residue_count_; 00050 int atom_count_; 00051 boost::filesystem::ifstream infile_; 00052 boost::iostreams::filtering_stream<boost::iostreams::input> in_; 00053 }; 00054 00055 00056 class DLLEXPORT_OST_IO CRDWriter : public mol::EntityVisitor { 00057 public: 00058 CRDWriter(const String& filename); 00059 CRDWriter(const boost::filesystem::path& filename); 00060 CRDWriter(std::ostream& outstream); 00061 00062 virtual bool VisitAtom(const mol::AtomHandle& atom); 00063 00064 void WriteHeader(const mol::EntityView& ent); 00065 00066 private: 00067 std::ofstream outfile_; 00068 std::ostream& outstream_; 00069 int atom_count_; 00070 }; 00071 00072 class DLLEXPORT_OST_IO EntityIOCRDHandler: public EntityIOHandler { 00073 public: 00074 virtual void Import(mol::EntityHandle& ent, const boost::filesystem::path& loc); 00075 00076 virtual void Export(const mol::EntityView& ent, 00077 const boost::filesystem::path& loc) const; 00078 00079 virtual void Import(mol::EntityHandle& ent, std::istream& stream); 00080 00081 virtual void Export(const mol::EntityView& ent, std::ostream& stream) const; 00082 00083 static bool ProvidesImport(const boost::filesystem::path& loc, 00084 const String& format="auto"); 00085 static bool ProvidesExport(const boost::filesystem::path& loc, 00086 const String& format="auto"); 00087 virtual bool RequiresBuilder() const; 00088 00089 static String GetFormatName() { return String("Crd"); } 00090 static String GetFormatDescription() { return String("CARD format file used by the Charmm software package"); } 00091 }; 00092 00093 00094 typedef EntityIOHandlerFactory<EntityIOCRDHandler> EntityIOCRDHandlerFactory; 00095 00096 mol::EntityHandle DLLEXPORT_OST_IO LoadCRD(const String& file_name); 00097 00098 }} // ns 00099 00100 #endif
1.5.8