Skip to content
Snippets Groups Projects
Commit 20fa3602 authored by Marco Biasini's avatar Marco Biasini
Browse files

add function to read/write PDB directly from/to string

While it has been possible to read/write PDb directly
from/to arbitrary streams, the stream interface is not
exposed to Python yet.
parent b90f8373
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ using namespace boost::python; ...@@ -22,6 +22,8 @@ using namespace boost::python;
#include <ost/io/mol/io_profile.hh> #include <ost/io/mol/io_profile.hh>
#include <ost/io/mol/pdb_reader.hh> #include <ost/io/mol/pdb_reader.hh>
#include <ost/io/mol/pdb_writer.hh> #include <ost/io/mol/pdb_writer.hh>
#include <ost/io/mol/pdb_str.hh>
using namespace ost; using namespace ost;
using namespace ost::io; using namespace ost::io;
...@@ -33,6 +35,9 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(load_PDB_ov, LoadPDB, 1, 2) ...@@ -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_a)(const mol::EntityHandle&)=&PDBWriter::Write;
void (PDBWriter::*write_b)(const mol::EntityView&)=&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() { void remove_profiles() {
IOProfileRegistry::RemoveProfiles(); IOProfileRegistry::RemoveProfiles();
} }
...@@ -88,6 +93,12 @@ void export_pdb_io() ...@@ -88,6 +93,12 @@ void export_pdb_io()
&PDBWriter::SetWriteMultiModel) &PDBWriter::SetWriteMultiModel)
.def("Write", write_b) .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 // we need to make sure there are no pending references to Python objects
// tied to the IOProfileRegistry singleton. The destructor of // tied to the IOProfileRegistry singleton. The destructor of
......
...@@ -19,6 +19,7 @@ dcd_io.cc ...@@ -19,6 +19,7 @@ dcd_io.cc
star_parser.cc star_parser.cc
mmcif_reader.cc mmcif_reader.cc
mmcif_info.cc mmcif_info.cc
pdb_str.cc
PARENT_SCOPE PARENT_SCOPE
) )
...@@ -45,5 +46,6 @@ load_entity.hh ...@@ -45,5 +46,6 @@ load_entity.hh
surface_io_handler.hh surface_io_handler.hh
load_surface.hh load_surface.hh
surface_io_msms_handler.hh surface_io_msms_handler.hh
pdb_str.hh
PARENT_SCOPE PARENT_SCOPE
) )
//------------------------------------------------------------------------------
// 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;
}
}}
//------------------------------------------------------------------------------
// 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment