00001
00002
00003
00004
00005
00006
00007 #ifndef _RD_MOLWRITERS_H_
00008 #define _RD_MOLWRITERS_H_
00009
00010 #include <RDGeneral/types.h>
00011
00012 #include <string>
00013 #include <iostream>
00014 #include <GraphMol/ROMol.h>
00015
00016 namespace RDKit {
00017
00018 static int defaultConfId=-1;
00019 class MolWriter {
00020 public:
00021 virtual ~MolWriter() {}
00022 virtual void write(ROMol &mol,int confId=defaultConfId) = 0;
00023 virtual void flush() = 0;
00024 virtual void setProps(const STR_VECT &propNames)=0;
00025 virtual unsigned int numMols() const =0;
00026 };
00027
00028 class SmilesWriter : public MolWriter {
00029
00030
00031
00032
00033
00034
00035
00036 public:
00037 SmilesWriter(std::string fileName,
00038 std::string delimiter=" ",
00039 std::string nameHeader="Name",
00040 bool includeHeader=true);
00041 SmilesWriter(std::ostream *outStream,
00042 std::string delimiter=" ",
00043 std::string nameHeader="Name",
00044 bool includeHeader=true,
00045 bool takeOwnership=false);
00046
00047 ~SmilesWriter();
00048
00049
00050
00051
00052
00053
00054
00055 void setProps(const STR_VECT &propNames);
00056
00057
00058
00059
00060 void write(ROMol &mol,int confId=defaultConfId);
00061
00062
00063 void flush() {
00064 PRECONDITION(dp_ostream,"no output stream");
00065 dp_ostream->flush();
00066 };
00067
00068
00069 unsigned int numMols() const { return d_molid;} ;
00070
00071 private:
00072
00073 void init(std::string delimiter,std::string nameHeader,
00074 bool includeHeader);
00075
00076
00077
00078 void dumpHeader() const;
00079
00080
00081 std::ostream *dp_ostream;
00082 bool d_owner;
00083 bool d_includeHeader;
00084 unsigned int d_molid;
00085 std::string d_delim;
00086 std::string d_nameHeader;
00087 STR_VECT d_props;
00088 };
00089
00090
00091 class SDWriter : public MolWriter {
00092
00093
00094
00095
00096
00097
00098 public:
00099 SDWriter(std::string fileName);
00100 SDWriter(std::ostream *outStream,bool takeOwnership=false);
00101
00102 ~SDWriter();
00103
00104
00105
00106
00107
00108
00109
00110 void setProps(const STR_VECT &propNames);
00111
00112
00113
00114
00115 void write(ROMol &mol, int confId=defaultConfId);
00116
00117
00118 void flush() {
00119 PRECONDITION(dp_ostream,"no output stream");
00120 dp_ostream->flush();
00121 } ;
00122
00123
00124 unsigned int numMols() const { return d_molid; };
00125
00126 private:
00127 void writeProperty(const ROMol &mol, std::string name);
00128
00129 std::ostream *dp_ostream;
00130 bool d_owner;
00131 unsigned int d_molid;
00132 STR_VECT d_props;
00133 };
00134
00135 class TDTWriter : public MolWriter {
00136
00137
00138
00139
00140
00141
00142 public:
00143 TDTWriter(std::string fileName);
00144 TDTWriter(std::ostream *outStream,bool takeOwnership=false);
00145
00146 ~TDTWriter();
00147
00148
00149
00150
00151
00152
00153
00154 void setProps(const STR_VECT &propNames);
00155
00156
00157
00158
00159 void write(ROMol &mol, int confId=defaultConfId);
00160
00161
00162 void flush() {
00163 PRECONDITION(dp_ostream,"no output stream");
00164 dp_ostream->flush();
00165 };
00166
00167
00168 unsigned int numMols() const { return d_molid; };
00169
00170 void setWrite2D(bool state=true) { df_write2D=state; };
00171 bool getWrite2D() const { return df_write2D; };
00172
00173 void setWriteNames(bool state=true) { df_writeNames=state; };
00174 bool getWriteNames() const { return df_writeNames; };
00175
00176 void setNumDigits(unsigned int numDigits) { d_numDigits=numDigits; };
00177 unsigned int getNumDigits() const { return d_numDigits;};
00178
00179 private:
00180 void writeProperty(const ROMol &mol, std::string name);
00181
00182 std::ostream *dp_ostream;
00183 bool d_owner;
00184 unsigned int d_molid;
00185 STR_VECT d_props;
00186 bool df_write2D;
00187 bool df_writeNames;
00188 unsigned int d_numDigits;
00189 };
00190
00191 }
00192
00193 #endif
00194