From a270dce7cd9ae1aa7d777664778f9f3f69c815b2 Mon Sep 17 00:00:00 2001 From: Xavier Robin <xavalias-github@xavier.robin.name> Date: Tue, 5 Dec 2023 13:37:48 +0100 Subject: [PATCH] feat: add a function to save an SDF file directly --- modules/io/pymod/wrap_io.cc | 5 +++++ modules/io/src/mol/entity_io_sdf_handler.cc | 10 ++++++++++ modules/io/src/mol/entity_io_sdf_handler.hh | 2 ++ 3 files changed, 17 insertions(+) diff --git a/modules/io/pymod/wrap_io.cc b/modules/io/pymod/wrap_io.cc index 073175112..bae73b1e0 100644 --- a/modules/io/pymod/wrap_io.cc +++ b/modules/io/pymod/wrap_io.cc @@ -69,6 +69,9 @@ ost::mol::alg::StereoChemicalProps (*read_props_b)(bool check) = &ReadStereoChem String (*sdf_str_a)(const mol::EntityHandle&)=&EntityToSDFString; String (*sdf_str_b)(const mol::EntityView&)=&EntityToSDFString; +void (*save_sdf_handle)(const mol::EntityHandle& entity, const String& filename)=&SaveSDF; +void (*save_sdf_view)(const mol::EntityView& entity, const String& filename)=&SaveSDF; + } void export_pdb_io(); @@ -120,6 +123,8 @@ BOOST_PYTHON_MODULE(_ost_io) def("SaveSequence", &SaveSequence, (arg("sequence"), arg("filename"), arg("format")="auto")); def("LoadSDF", &LoadSDF); + def("SaveSDF", save_sdf_view); + def("SaveSDF", save_sdf_handle); def("EntityToSDFStr", sdf_str_a); def("EntityToSDFStr", sdf_str_b); diff --git a/modules/io/src/mol/entity_io_sdf_handler.cc b/modules/io/src/mol/entity_io_sdf_handler.cc index a843d986c..129ce2c86 100644 --- a/modules/io/src/mol/entity_io_sdf_handler.cc +++ b/modules/io/src/mol/entity_io_sdf_handler.cc @@ -103,5 +103,15 @@ mol::EntityHandle LoadSDF(const String& file_name) { return ent_handle; } +void SaveSDF(const mol::EntityHandle& ent, const String& file_name) { + SDFWriter writer(file_name); + writer.Write(ent); +} + +void SaveSDF(const mol::EntityView& ent, const String& file_name) { + SDFWriter writer(file_name); + writer.Write(ent); +} + }} // ns diff --git a/modules/io/src/mol/entity_io_sdf_handler.hh b/modules/io/src/mol/entity_io_sdf_handler.hh index d5b4aef15..1dc593ec5 100644 --- a/modules/io/src/mol/entity_io_sdf_handler.hh +++ b/modules/io/src/mol/entity_io_sdf_handler.hh @@ -49,6 +49,8 @@ public: typedef EntityIOHandlerFactory<EntityIOSDFHandler> EntityIOSDFHandlerFactory; mol::EntityHandle DLLEXPORT_OST_IO LoadSDF(const String& file_name); +void DLLEXPORT_OST_IO SaveSDF(const mol::EntityHandle& ent, const String& file_name); +void DLLEXPORT_OST_IO SaveSDF(const mol::EntityView& ent, const String& file_name); }} // ns -- GitLab