diff --git a/modules/io/src/CMakeLists.txt b/modules/io/src/CMakeLists.txt index 08b65a7a2f2f8509834db7dfcb97a0fdd35d0646..c2a465686698258543707f91b5097e7d5f98ff11 100644 --- a/modules/io/src/CMakeLists.txt +++ b/modules/io/src/CMakeLists.txt @@ -13,6 +13,7 @@ io_utils.hh io_exception.hh convert.hh converting_streams.hh + formatted_line.hh ) diff --git a/modules/io/src/io_manager.cc b/modules/io/src/io_manager.cc index 071be5c11461382803e8a3704bdbd32ba760ed18..6edc7fe430dd928159152bed7ebea0bde53aeb44 100644 --- a/modules/io/src/io_manager.cc +++ b/modules/io/src/io_manager.cc @@ -21,6 +21,7 @@ #include <ost/io/mol/entity_io_crd_handler.hh> #include <ost/io/mol/entity_io_sdf_handler.hh> #include <ost/io/mol/entity_io_mae_handler.hh> +#include <ost/io/mol/entity_io_mmcif_handler.hh> #include <ost/io/seq/fasta_io_handler.hh> #include <ost/io/seq/pir_io_handler.hh> #include <ost/io/seq/promod_io_handler.hh> @@ -44,6 +45,7 @@ namespace ost { namespace io { IOManager::IOManager() { + RegisterFactory(EntityIOHandlerFactoryBaseP(new EntityIOMMCIFHandlerFactory)); RegisterFactory(EntityIOHandlerFactoryBaseP(new EntityIOPDBHandlerFactory)); RegisterFactory(EntityIOHandlerFactoryBaseP(new EntityIOCRDHandlerFactory)); RegisterFactory(EntityIOHandlerFactoryBaseP(new EntityIOSDFHandlerFactory)); diff --git a/modules/io/src/mol/CMakeLists.txt b/modules/io/src/mol/CMakeLists.txt index 05c813456155e14b540e7f00b3848932124db523..cb80b67a9600ed5ec3f98e19a5669dcb4b1f1a1b 100644 --- a/modules/io/src/mol/CMakeLists.txt +++ b/modules/io/src/mol/CMakeLists.txt @@ -5,6 +5,7 @@ pdb_reader.cc entity_io_pdb_handler.cc pdb_writer.cc entity_io_sdf_handler.cc +entity_io_mmcif_handler.cc sdf_reader.cc sdf_writer.cc save_entity.cc @@ -29,6 +30,7 @@ io_profile.hh dcd_io.hh entity_io_crd_handler.hh entity_io_mae_handler.hh +entity_io_mmcif_handler.hh entity_io_handler.hh pdb_reader.hh entity_io_pdb_handler.hh diff --git a/modules/io/src/mol/entity_io_mmcif_handler.cc b/modules/io/src/mol/entity_io_mmcif_handler.cc new file mode 100644 index 0000000000000000000000000000000000000000..4d4d99777cb45970b113f9c337f428dfce7162ad --- /dev/null +++ b/modules/io/src/mol/entity_io_mmcif_handler.cc @@ -0,0 +1,98 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +/* + Author: Marco Biasini, Ansgar Philippsen + */ +#include <iostream> +#include <sstream> +#include <iomanip> + +#include <boost/algorithm/string.hpp> +#include <boost/filesystem/convenience.hpp> +#include <boost/format.hpp> +#include <boost/lexical_cast.hpp> + +#include <ost/log.hh> +#include <ost/io/io_exception.hh> +#include "entity_io_mmcif_handler.hh" +#include <ost/profile.hh> +#include <ost/io/mol/mmcif_reader.hh> +namespace ost { namespace io { + +using boost::format; + + +bool EntityIOMMCIFHandler::RequiresBuilder() const +{ + return true; +} + + +void EntityIOMMCIFHandler::Export(const mol::EntityView& ent, + const boost::filesystem::path& loc) const +{ +} + +void EntityIOMMCIFHandler::Import(mol::EntityHandle& ent, + std::istream& stream) +{ + MMCifParser reader(stream,ent, + IOProfileRegistry::Instance().GetDefault()); + reader.Parse(); +} + +void EntityIOMMCIFHandler::Export(const mol::EntityView& ent, + std::ostream& stream) const +{ +} + +void EntityIOMMCIFHandler::Import(mol::EntityHandle& ent, + const boost::filesystem::path& loc) +{ + std::string filename=loc.string(); + MMCifParser reader(filename, ent, + IOProfileRegistry::Instance().GetDefault()); + reader.Parse(); +} + +bool EntityIOMMCIFHandler::ProvidesImport(const boost::filesystem::path& loc, + const String& type) +{ + if (type=="auto") { + String match_suf_string=loc.string(); + std::transform(match_suf_string.begin(),match_suf_string.end(), + match_suf_string.begin(),tolower); + if(detail::FilenameEndsWith(match_suf_string,".cif") || + detail::FilenameEndsWith(match_suf_string,".cif.gz")){ + return true; + } + } + return type=="cif"; +} + +bool EntityIOMMCIFHandler::ProvidesExport(const boost::filesystem::path& loc, + const String& type) +{ + return false; +} + + +}} // ns + + diff --git a/modules/io/src/mol/entity_io_mmcif_handler.hh b/modules/io/src/mol/entity_io_mmcif_handler.hh new file mode 100644 index 0000000000000000000000000000000000000000..2fa262156d4867f665a8fc3f4d5ea8e71877f16f --- /dev/null +++ b/modules/io/src/mol/entity_io_mmcif_handler.hh @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#ifndef OST_IO_ENTITY_IO_PLUGIN_MMCIF_HH +#define OST_IO_ENTITY_IO_PLUGIN_MMCIF_HH + +#include <vector> + +#include <ost/io/mol/entity_io_handler.hh> + +namespace ost { namespace io { + + +class DLLEXPORT_OST_IO EntityIOMMCIFHandler: public EntityIOHandler { +public: + virtual void Import(mol::EntityHandle& ent, + const boost::filesystem::path& loc); + + virtual void Export(const mol::EntityView& ent, + const boost::filesystem::path& loc) const; + + virtual void Import(mol::EntityHandle& ent, std::istream& stream); + + virtual void Export(const mol::EntityView& ent, std::ostream& stream) const; + + static bool ProvidesImport(const boost::filesystem::path& loc, + const String& format="auto"); + static bool ProvidesExport(const boost::filesystem::path& loc, + const String& format="auto"); + virtual bool RequiresBuilder() const; + + static String GetFormatName() { return String("mmCIF"); } + static String GetFormatDescription() { + return String("macromolecular Crystallographic Information File "); + } +}; + + +typedef EntityIOHandlerFactory<EntityIOMMCIFHandler> EntityIOMMCIFHandlerFactory; + + +}} // ns + +#endif diff --git a/modules/io/src/mol/star_parser.cc b/modules/io/src/mol/star_parser.cc index d8903a9de0baac3dfc3c037c20f449f9cabaa2da..0de35fec5072aff97c421fa8a9de409b8cb2011b 100644 --- a/modules/io/src/mol/star_parser.cc +++ b/modules/io/src/mol/star_parser.cc @@ -51,6 +51,7 @@ StarParser::StarParser(const String& filename, bool items_as_row): items_row_header_(), file_open_(true), items_row_columns_(), items_row_values_() { + items_as_row_=items_as_row; if (filename.length() >= 3 && filename.substr(filename.length() - 3) == ".gz") { stream_.push(boost::iostreams::gzip_decompressor());