MolWriters.h
Go to the documentation of this file.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
00029
00030 class SmilesWriter : public MolWriter {
00031
00032
00033
00034
00035
00036
00037
00038 public:
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 SmilesWriter(std::string fileName,
00050 std::string delimiter=" ",
00051 std::string nameHeader="Name",
00052 bool includeHeader=true,
00053 bool isomericSmiles=false,
00054 bool kekuleSmiles=false);
00055
00056 SmilesWriter(std::ostream *outStream,
00057 std::string delimiter=" ",
00058 std::string nameHeader="Name",
00059 bool includeHeader=true,
00060 bool takeOwnership=false,
00061 bool isomericSmiles=false,
00062 bool kekuleSmiles=false);
00063
00064 ~SmilesWriter();
00065
00066
00067
00068 void setProps(const STR_VECT &propNames);
00069
00070
00071 void write(ROMol &mol,int confId=defaultConfId);
00072
00073
00074 void flush() {
00075 PRECONDITION(dp_ostream,"no output stream");
00076 dp_ostream->flush();
00077 };
00078
00079
00080 unsigned int numMols() const { return d_molid;} ;
00081
00082 private:
00083
00084 void init(std::string delimiter,std::string nameHeader,
00085 bool includeHeader,
00086 bool isomericSmiles,
00087 bool kekuleSmiles);
00088
00089
00090
00091 void dumpHeader() const;
00092
00093
00094 std::ostream *dp_ostream;
00095 bool df_owner;
00096 bool df_includeHeader;
00097 unsigned int d_molid;
00098 std::string d_delim;
00099 std::string d_nameHeader;
00100 STR_VECT d_props;
00101 bool df_isomericSmiles;
00102 bool df_kekuleSmiles;
00103 };
00104
00105
00106
00107
00108 class SDWriter : public MolWriter {
00109
00110
00111
00112
00113
00114
00115 public:
00116 SDWriter(std::string fileName);
00117 SDWriter(std::ostream *outStream,bool takeOwnership=false);
00118
00119 ~SDWriter();
00120
00121
00122
00123 void setProps(const STR_VECT &propNames);
00124
00125
00126 void write(ROMol &mol, int confId=defaultConfId);
00127
00128
00129 void flush() {
00130 PRECONDITION(dp_ostream,"no output stream");
00131 dp_ostream->flush();
00132 } ;
00133
00134
00135 unsigned int numMols() const { return d_molid; };
00136
00137 private:
00138 void writeProperty(const ROMol &mol, std::string name);
00139
00140 std::ostream *dp_ostream;
00141 bool d_owner;
00142 unsigned int d_molid;
00143 STR_VECT d_props;
00144 };
00145
00146
00147
00148 class TDTWriter : public MolWriter {
00149
00150
00151
00152
00153
00154
00155 public:
00156 TDTWriter(std::string fileName);
00157 TDTWriter(std::ostream *outStream,bool takeOwnership=false);
00158
00159 ~TDTWriter();
00160
00161
00162
00163 void setProps(const STR_VECT &propNames);
00164
00165
00166 void write(ROMol &mol, int confId=defaultConfId);
00167
00168
00169 void flush() {
00170 PRECONDITION(dp_ostream,"no output stream");
00171 dp_ostream->flush();
00172 };
00173
00174
00175 unsigned int numMols() const { return d_molid; };
00176
00177 void setWrite2D(bool state=true) { df_write2D=state; };
00178 bool getWrite2D() const { return df_write2D; };
00179
00180 void setWriteNames(bool state=true) { df_writeNames=state; };
00181 bool getWriteNames() const { return df_writeNames; };
00182
00183 void setNumDigits(unsigned int numDigits) { d_numDigits=numDigits; };
00184 unsigned int getNumDigits() const { return d_numDigits;};
00185
00186 private:
00187 void writeProperty(const ROMol &mol, std::string name);
00188
00189 std::ostream *dp_ostream;
00190 bool d_owner;
00191 unsigned int d_molid;
00192 STR_VECT d_props;
00193 bool df_write2D;
00194 bool df_writeNames;
00195 unsigned int d_numDigits;
00196 };
00197
00198 }
00199
00200 #endif
00201