diff --git a/modules/io/doc/io.rst b/modules/io/doc/io.rst index b64a01e797dda4d2357720923c493c507b8d0097..57677f7a5df111fefe328e35c1e2e64ba1fcfb4f 100644 --- a/modules/io/doc/io.rst +++ b/modules/io/doc/io.rst @@ -95,6 +95,13 @@ behaviour. pdb_str = pdb.read() ent = io.PDBStrToEntity(pdb_str, ost.io.profiles['DEFAULT'], True) +.. function:: SDFStrToEntity(sdf_string) + + Load entity from a string in SDF format. + + :param pdb_string: A SDF file as a string. + + :rtype: :class:`~ost.mol.EntityHandle`. .. class:: ost.io.OMF @@ -267,6 +274,14 @@ file: :rtype: string. +.. function:: EntityToSDFStr(ent) + + Return entity as a string in SDF format. + + :param entity: The :class:`~ost.mol.EntityHandle` or :class:`~ost.mol.EntityView` + + :rtype: string. + .. _seq-io: Sequences and Alignments diff --git a/modules/io/pymod/wrap_io.cc b/modules/io/pymod/wrap_io.cc index ccf86b566efb31ca271eb81f4840cf483dd56ba7..0731751124b73221c44440191147c2b101276389 100644 --- a/modules/io/pymod/wrap_io.cc +++ b/modules/io/pymod/wrap_io.cc @@ -32,6 +32,7 @@ using namespace boost::python; #include <ost/io/mol/entity_io_mae_handler.hh> #include <ost/io/mol/entity_io_sdf_handler.hh> #include <ost/io/mol/pdb_reader.hh> +#include <ost/io/mol/sdf_str.hh> #include <ost/io/mol/dcd_io.hh> #include <ost/io/stereochemical_params_reader.hh> using namespace ost; @@ -65,6 +66,9 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(save_entity_view_ov, ost::mol::alg::StereoChemicalProps (*read_props_a)(String filename, bool check) = &ReadStereoChemicalPropsFile; ost::mol::alg::StereoChemicalProps (*read_props_b)(bool check) = &ReadStereoChemicalPropsFile; +String (*sdf_str_a)(const mol::EntityHandle&)=&EntityToSDFString; +String (*sdf_str_b)(const mol::EntityView&)=&EntityToSDFString; + } void export_pdb_io(); @@ -117,6 +121,11 @@ BOOST_PYTHON_MODULE(_ost_io) (arg("sequence"), arg("filename"), arg("format")="auto")); def("LoadSDF", &LoadSDF); + def("EntityToSDFStr", sdf_str_a); + def("EntityToSDFStr", sdf_str_b); + + def("SDFStrToEntity", &SDFStringToEntity); + def("LoadCRD", &LoadCRD); def("LoadCHARMMTraj_", &LoadCHARMMTraj, (arg("ent"), arg("trj_filename"), arg("stride")=1, arg("lazy_load")=false, diff --git a/modules/io/src/mol/CMakeLists.txt b/modules/io/src/mol/CMakeLists.txt index 92d769f38df294adefa3d740840201416986ae0f..5f17d12bc4ba6d5c991275b859ce1330253f5551 100644 --- a/modules/io/src/mol/CMakeLists.txt +++ b/modules/io/src/mol/CMakeLists.txt @@ -20,6 +20,7 @@ star_parser.cc mmcif_reader.cc mmcif_info.cc pdb_str.cc +sdf_str.cc mmcif_str.cc stereochemical_params_reader.cc omf.cc @@ -50,6 +51,7 @@ surface_io_handler.hh load_surface.hh surface_io_msms_handler.hh pdb_str.hh +sdf_str.hh mmcif_str.hh stereochemical_params_reader.hh omf.hh diff --git a/modules/io/src/mol/sdf_str.cc b/modules/io/src/mol/sdf_str.cc new file mode 100644 index 0000000000000000000000000000000000000000..a2977c432bf3ec90647de1b05dc8eb5a2afb3f74 --- /dev/null +++ b/modules/io/src/mol/sdf_str.cc @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2020 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/sdf_str.hh> +#include <ost/io/mol/sdf_writer.hh> +#include <ost/io/mol/sdf_reader.hh> + +namespace ost { namespace io { + +String EntityToSDFString(const mol::EntityHandle& ent) { + std::stringstream stream; + SDFWriter writer(stream); + writer.Write(ent); + return stream.str(); +} + +String EntityToSDFString(const mol::EntityView& ent) { + std::stringstream stream; + SDFWriter writer(stream); + writer.Write(ent); + return stream.str(); +} + +mol::EntityHandle SDFStringToEntity(const String& sdf) { + std::stringstream stream(sdf); + SDFReader reader(stream); + mol::EntityHandle ent = mol::CreateEntity(); + reader.Import(ent); + return ent; +} + +}} diff --git a/modules/io/src/mol/sdf_str.hh b/modules/io/src/mol/sdf_str.hh new file mode 100644 index 0000000000000000000000000000000000000000..87987679ed7ad28a6e3023f536ad6c6fb716f7f7 --- /dev/null +++ b/modules/io/src/mol/sdf_str.hh @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2020 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_SDF_STR_HH +#define OST_IO_SDF_STR_HH + +#include <ost/io/module_config.hh> +#include <ost/mol/entity_view.hh> +#include <ost/mol/entity_handle.hh> + +namespace ost { namespace io { + +// Saves an entity to a string in PDB format. +String DLLEXPORT_OST_IO +EntityToSDFString(const mol::EntityHandle& ent); + +String DLLEXPORT_OST_IO +EntityToSDFString(const mol::EntityView& ent); + +mol::EntityHandle DLLEXPORT_OST_IO +SDFStringToEntity(const String& pdb); + +}} + +#endif