diff --git a/modules/io/pymod/export_pdb_io.cc b/modules/io/pymod/export_pdb_io.cc index 237b2918c4e0188c1af301d212e073195266d87f..18d82b7c3c8f5163433745e853ba63c9ed5e21c3 100644 --- a/modules/io/pymod/export_pdb_io.cc +++ b/modules/io/pymod/export_pdb_io.cc @@ -22,6 +22,8 @@ using namespace boost::python; #include <ost/io/mol/io_profile.hh> #include <ost/io/mol/pdb_reader.hh> #include <ost/io/mol/pdb_writer.hh> +#include <ost/io/mol/pdb_str.hh> + using namespace ost; using namespace ost::io; @@ -33,6 +35,9 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(load_PDB_ov, LoadPDB, 1, 2) void (PDBWriter::*write_a)(const mol::EntityHandle&)=&PDBWriter::Write; void (PDBWriter::*write_b)(const mol::EntityView&)=&PDBWriter::Write; +String (*pdb_str_a)(const mol::EntityHandle&, const IOProfile&)=&EntityToPDBString; +String (*pdb_str_b)(const mol::EntityView&, const IOProfile&)=&EntityToPDBString; + void remove_profiles() { IOProfileRegistry::RemoveProfiles(); } @@ -88,6 +93,12 @@ void export_pdb_io() &PDBWriter::SetWriteMultiModel) .def("Write", write_b) ; + def("EntityToPDBStr", pdb_str_a, + (arg("entity"), arg("profile")=IOProfile())); + def("EntityToPDBStr", pdb_str_b, + (arg("entity"), arg("profile")=IOProfile())); + + def("PDBStrToEntity", &PDBStringToEntity, (arg("pdb_string"),arg("profile")=IOProfile())); // we need to make sure there are no pending references to Python objects // tied to the IOProfileRegistry singleton. The destructor of diff --git a/modules/io/src/mol/CMakeLists.txt b/modules/io/src/mol/CMakeLists.txt index e7b729cb67c2361636103b86e1cb02f225db4c66..e0792e93ee64ec6038451cad5a283a5c5c12144c 100644 --- a/modules/io/src/mol/CMakeLists.txt +++ b/modules/io/src/mol/CMakeLists.txt @@ -19,6 +19,7 @@ dcd_io.cc star_parser.cc mmcif_reader.cc mmcif_info.cc +pdb_str.cc PARENT_SCOPE ) @@ -45,5 +46,6 @@ load_entity.hh surface_io_handler.hh load_surface.hh surface_io_msms_handler.hh +pdb_str.hh PARENT_SCOPE ) diff --git a/modules/io/src/mol/pdb_str.cc b/modules/io/src/mol/pdb_str.cc new file mode 100644 index 0000000000000000000000000000000000000000..7168dfb16fb3d8d304ae58b747d125668600883e --- /dev/null +++ b/modules/io/src/mol/pdb_str.cc @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// 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 +//------------------------------------------------------------------------------ +#include <sstream> +#include <ost/io/mol/pdb_str.hh> +#include <ost/io/mol/pdb_writer.hh> +#include <ost/io/mol/pdb_reader.hh> + +namespace ost { namespace io { + +String EntityToPDBString(const mol::EntityHandle& ent, const IOProfile& profile) { + std::stringstream stream; + PDBWriter writer(stream, profile); + writer.Write(ent); + return stream.str(); +} + +String EntityToPDBString(const mol::EntityView& ent, const IOProfile& profile) { + std::stringstream stream; + PDBWriter writer(stream, profile); + writer.Write(ent); + return stream.str(); +} + +mol::EntityHandle PDBStringToEntity(const String& pdb, const IOProfile& profile) { + std::stringstream stream(pdb); + PDBReader reader(stream, profile); + mol::EntityHandle ent = mol::CreateEntity(); + reader.Import(ent); + return ent; +} + +}} diff --git a/modules/io/src/mol/pdb_str.hh b/modules/io/src/mol/pdb_str.hh new file mode 100644 index 0000000000000000000000000000000000000000..d376dce59dce243ac9783c09d2dad6b9ade24ad8 --- /dev/null +++ b/modules/io/src/mol/pdb_str.hh @@ -0,0 +1,41 @@ +//------------------------------------------------------------------------------ +// 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_PDB_STR_HH +#define OST_IO_PDB_STR_HH + +#include <ost/io/module_config.hh> +#include <ost/mol/entity_view.hh> +#include <ost/mol/entity_handle.hh> +#include <ost/io/mol/io_profile.hh> + +namespace ost { namespace io { + +// Saves an entity to a string in PDB format. +String DLLEXPORT_OST_IO +EntityToPDBString(const mol::EntityHandle& ent, const IOProfile& profile=IOProfile()); + +String DLLEXPORT_OST_IO +EntityToPDBString(const mol::EntityView& ent, const IOProfile& profile=IOProfile()); + +mol::EntityHandle DLLEXPORT_OST_IO +PDBStringToEntity(const String& pdb, const IOProfile& profile=IOProfile()); + +}} + +#endif