12#ifndef _RD_MOLWRITERS_H_
13#define _RD_MOLWRITERS_H_
21#include <boost/noncopyable.hpp>
23#ifdef RDK_BUILD_MAEPARSER_SUPPORT
24namespace schrodinger {
40 virtual void write(
const ROMol &mol,
int confId = defaultConfId) = 0;
71 SmilesWriter(
const std::string &fileName,
const std::string &delimiter =
" ",
72 const std::string &nameHeader =
"Name",
73 bool includeHeader =
true,
bool isomericSmiles =
true,
74 bool kekuleSmiles =
false);
77 std::string nameHeader =
"Name",
bool includeHeader =
true,
78 bool takeOwnership =
false,
bool isomericSmiles =
true,
79 bool kekuleSmiles =
false);
88 void write(
const ROMol &mol,
int confId = defaultConfId)
override;
97 if (dp_ostream->good()) {
98 dp_ostream->setstate(std::ios::badbit);
100 }
catch (
const std::runtime_error &) {
114 dp_ostream =
nullptr;
118 unsigned int numMols()
const override {
return d_molid; }
122 void init(
const std::string &delimiter,
const std::string &nameHeader,
123 bool includeHeader,
bool isomericSmiles,
bool kekuleSmiles);
126 void dumpHeader()
const;
128 std::ostream *dp_ostream;
130 bool df_includeHeader;
131 unsigned int d_molid;
133 std::string d_nameHeader;
135 bool df_isomericSmiles;
136 bool df_kekuleSmiles;
154 SDWriter(std::ostream *outStream,
bool takeOwnership =
false);
163 static std::string
getText(
const ROMol &mol,
int confId = defaultConfId,
164 bool kekulize =
true,
bool force_V3000 =
false,
165 int molid = -1,
STR_VECT *propNames =
nullptr);
168 void write(
const ROMol &mol,
int confId = defaultConfId)
override;
177 if (dp_ostream->good()) {
178 dp_ostream->setstate(std::ios::badbit);
180 }
catch (
const std::runtime_error &) {
194 dp_ostream =
nullptr;
198 unsigned int numMols()
const override {
return d_molid; }
207 void writeProperty(
const ROMol &mol,
const std::string &name);
209 std::ostream *dp_ostream;
211 unsigned int d_molid;
232 TDTWriter(std::ostream *outStream,
bool takeOwnership =
false);
241 void write(
const ROMol &mol,
int confId = defaultConfId)
override;
250 if (dp_ostream->good()) {
251 dp_ostream->setstate(std::ios::badbit);
253 }
catch (
const std::runtime_error &) {
263 *dp_ostream <<
"|\n";
271 dp_ostream =
nullptr;
275 unsigned int numMols()
const override {
return d_molid; }
287 void writeProperty(
const ROMol &mol,
const std::string &name);
289 std::ostream *dp_ostream;
291 unsigned int d_molid;
303 PDBWriter(
const std::string &fileName,
unsigned int flavor = 0);
304 PDBWriter(std::ostream *outStream,
bool takeOwnership =
false,
305 unsigned int flavor = 0);
309 void write(
const ROMol &mol,
int confId = defaultConfId)
override;
320 if (dp_ostream->good()) {
321 dp_ostream->setstate(std::ios::badbit);
323 }
catch (
const std::runtime_error &) {
337 dp_ostream =
nullptr;
341 unsigned int numMols()
const override {
return d_count; }
344 std::ostream *dp_ostream;
345 unsigned int d_flavor;
346 unsigned int d_count;
350#ifdef RDK_BUILD_MAEPARSER_SUPPORT
378 MaeWriter(
const std::string &fileName);
383 MaeWriter(std::ostream *outStream);
385 MaeWriter(std::shared_ptr<std::ostream> outStream);
387 ~MaeWriter()
override;
391 void setProps(
const STR_VECT &propNames)
override;
394 static std::string getText(
const ROMol &mol,
int confId = defaultConfId,
395 const STR_VECT &propNames = STR_VECT());
398 void write(
const ROMol &mol,
int confId = defaultConfId)
override;
401 void flush()
override;
403 void close()
override;
406 unsigned int numMols()
const override {
return d_molid; }
409 MaeWriter() =
default;
411 std::shared_ptr<std::ostream> dp_ostream;
416 std::unique_ptr<schrodinger::mae::Writer> dp_writer;
417 unsigned d_molid = 0;
#define PRECONDITION(expr, mess)
Defines the primary molecule class ROMol as well as associated typedefs.
virtual void write(const ROMol &mol, int confId=defaultConfId)=0
virtual void setProps(const STR_VECT &propNames)=0
virtual unsigned int numMols() const =0
PDBWriter(const std::string &fileName, unsigned int flavor=0)
void write(const ROMol &mol, int confId=defaultConfId) override
write a new molecule to the file
void flush() override
flush the ostream
PDBWriter(std::ostream *outStream, bool takeOwnership=false, unsigned int flavor=0)
void setProps(const STR_VECT &) override
unsigned int numMols() const override
get the number of molecules written so far
void close() override
close our stream (the writer cannot be used again)
bool getForceV3000() const
unsigned int numMols() const override
get the number of molecules written so far
SDWriter(std::ostream *outStream, bool takeOwnership=false)
void flush() override
flush the ostream
void setProps(const STR_VECT &propNames) override
set a vector of property names that are need to be written out for each molecule
void write(const ROMol &mol, int confId=defaultConfId) override
write a new molecule to the file
static std::string getText(const ROMol &mol, int confId=defaultConfId, bool kekulize=true, bool force_V3000=false, int molid=-1, STR_VECT *propNames=nullptr)
return the text that would be written to the file
void close() override
close our stream (the writer cannot be used again)
void setForceV3000(bool val)
SDWriter(const std::string &fileName)
void setKekulize(bool val)
unsigned int numMols() const override
get the number of molecules written so far
SmilesWriter(const std::string &fileName, const std::string &delimiter=" ", const std::string &nameHeader="Name", bool includeHeader=true, bool isomericSmiles=true, bool kekuleSmiles=false)
void write(const ROMol &mol, int confId=defaultConfId) override
write a new molecule to the file
SmilesWriter(std::ostream *outStream, std::string delimiter=" ", std::string nameHeader="Name", bool includeHeader=true, bool takeOwnership=false, bool isomericSmiles=true, bool kekuleSmiles=false)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setProps(const STR_VECT &propNames) override
set a vector of property names that are need to be written out for each molecule
void close() override
close our stream (the writer cannot be used again)
void flush() override
flush the ostream
void setNumDigits(unsigned int numDigits)
void setWrite2D(bool state=true)
void setProps(const STR_VECT &propNames) override
set a vector of property names that are need to be written out for each molecule
unsigned int numMols() const override
get the number of molecules written so far
unsigned int getNumDigits() const
TDTWriter(std::ostream *outStream, bool takeOwnership=false)
void close() override
close our stream (the writer cannot be used again)
TDTWriter(const std::string &fileName)
void write(const ROMol &mol, int confId=defaultConfId) override
write a new molecule to the file
void setWriteNames(bool state=true)
void flush() override
flush the ostream
bool getWriteNames() const
#define RDKIT_FILEPARSERS_EXPORT
std::vector< std::string > STR_VECT
bool rdvalue_is(const RDValue_cast_t)