Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _RD_MOLWRITERS_H_
00012 #define _RD_MOLWRITERS_H_
00013
00014 #include <RDGeneral/types.h>
00015
00016 #include <string>
00017 #include <iostream>
00018 #include <GraphMol/ROMol.h>
00019
00020 namespace RDKit {
00021
00022 static int defaultConfId=-1;
00023 class MolWriter {
00024 public:
00025 virtual ~MolWriter() {}
00026 virtual void write(ROMol &mol,int confId=defaultConfId) = 0;
00027 virtual void flush() = 0;
00028 virtual void close() = 0;
00029 virtual void setProps(const STR_VECT &propNames)=0;
00030 virtual unsigned int numMols() const =0;
00031 };
00032
00033
00034
00035 class SmilesWriter : public MolWriter {
00036
00037
00038
00039
00040
00041
00042
00043 public:
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 SmilesWriter(std::string fileName,
00055 std::string delimiter=" ",
00056 std::string nameHeader="Name",
00057 bool includeHeader=true,
00058 bool isomericSmiles=false,
00059 bool kekuleSmiles=false);
00060
00061 SmilesWriter(std::ostream *outStream,
00062 std::string delimiter=" ",
00063 std::string nameHeader="Name",
00064 bool includeHeader=true,
00065 bool takeOwnership=false,
00066 bool isomericSmiles=false,
00067 bool kekuleSmiles=false);
00068
00069 ~SmilesWriter();
00070
00071
00072
00073 void setProps(const STR_VECT &propNames);
00074
00075
00076 void write(ROMol &mol,int confId=defaultConfId);
00077
00078
00079 void flush() {
00080 PRECONDITION(dp_ostream,"no output stream");
00081 dp_ostream->flush();
00082 };
00083
00084
00085 void close() {
00086 PRECONDITION(dp_ostream,"no output stream");
00087 dp_ostream->flush();
00088 if(df_owner) {
00089 delete dp_ostream;
00090 df_owner=false;
00091 }
00092 dp_ostream=NULL;
00093 };
00094
00095
00096 unsigned int numMols() const { return d_molid;} ;
00097
00098 private:
00099
00100 void init(std::string delimiter,std::string nameHeader,
00101 bool includeHeader,
00102 bool isomericSmiles,
00103 bool kekuleSmiles);
00104
00105
00106
00107 void dumpHeader() const;
00108
00109
00110 std::ostream *dp_ostream;
00111 bool df_owner;
00112 bool df_includeHeader;
00113 unsigned int d_molid;
00114 std::string d_delim;
00115 std::string d_nameHeader;
00116 STR_VECT d_props;
00117 bool df_isomericSmiles;
00118 bool df_kekuleSmiles;
00119 };
00120
00121
00122
00123
00124 class SDWriter : public MolWriter {
00125
00126
00127
00128
00129
00130
00131 public:
00132
00133
00134
00135 SDWriter(std::string fileName);
00136 SDWriter(std::ostream *outStream,bool takeOwnership=false);
00137
00138 ~SDWriter();
00139
00140
00141
00142 void setProps(const STR_VECT &propNames);
00143
00144
00145 void write(ROMol &mol, int confId=defaultConfId);
00146
00147
00148 void flush() {
00149 PRECONDITION(dp_ostream,"no output stream");
00150 dp_ostream->flush();
00151 } ;
00152
00153
00154 void close() {
00155 PRECONDITION(dp_ostream,"no output stream");
00156
00157 if (d_molid > 0) {
00158 (*dp_ostream) << "$$$$\n";
00159 }
00160 dp_ostream->flush();
00161 if(df_owner) {
00162 delete dp_ostream;
00163 df_owner=false;
00164 }
00165 dp_ostream=NULL;
00166 };
00167
00168
00169 unsigned int numMols() const { return d_molid; };
00170
00171 private:
00172 void writeProperty(const ROMol &mol, std::string name);
00173
00174 std::ostream *dp_ostream;
00175 bool df_owner;
00176 unsigned int d_molid;
00177 STR_VECT d_props;
00178 };
00179
00180
00181
00182 class TDTWriter : public MolWriter {
00183
00184
00185
00186
00187
00188
00189 public:
00190
00191
00192
00193 TDTWriter(std::string fileName);
00194 TDTWriter(std::ostream *outStream,bool takeOwnership=false);
00195
00196 ~TDTWriter();
00197
00198
00199
00200 void setProps(const STR_VECT &propNames);
00201
00202
00203 void write(ROMol &mol, int confId=defaultConfId);
00204
00205
00206 void flush() {
00207 PRECONDITION(dp_ostream,"no output stream");
00208 dp_ostream->flush();
00209 };
00210
00211
00212 void close() {
00213 PRECONDITION(dp_ostream,"no output stream");
00214 dp_ostream->flush();
00215 if(df_owner) {
00216 delete dp_ostream;
00217 df_owner=false;
00218 }
00219 dp_ostream=NULL;
00220 };
00221
00222
00223 unsigned int numMols() const { return d_molid; };
00224
00225 void setWrite2D(bool state=true) { df_write2D=state; };
00226 bool getWrite2D() const { return df_write2D; };
00227
00228 void setWriteNames(bool state=true) { df_writeNames=state; };
00229 bool getWriteNames() const { return df_writeNames; };
00230
00231 void setNumDigits(unsigned int numDigits) { d_numDigits=numDigits; };
00232 unsigned int getNumDigits() const { return d_numDigits;};
00233
00234 private:
00235 void writeProperty(const ROMol &mol, std::string name);
00236
00237 std::ostream *dp_ostream;
00238 bool df_owner;
00239 unsigned int d_molid;
00240 STR_VECT d_props;
00241 bool df_write2D;
00242 bool df_writeNames;
00243 unsigned int d_numDigits;
00244 };
00245
00246 }
00247
00248 #endif
00249