Skip to content
Snippets Groups Projects
Verified Commit fb5352c8 authored by Xavier Robin's avatar Xavier Robin
Browse files

feat: read/write SDF from/to string

parent b6251b71
Branches
Tags
No related merge requests found
......@@ -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
......
......@@ -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,
......
......@@ -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
......
//------------------------------------------------------------------------------
// 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;
}
}}
//------------------------------------------------------------------------------
// 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment