00001 // 00002 // Copyright (C) 2001-2011 Greg Landrum and Rational Discovery LLC 00003 // 00004 // @@ All Rights Reserved @@ 00005 // This file is part of the RDKit. 00006 // The contents are covered by the terms of the BSD license 00007 // which is included in the file license.txt, found at the root 00008 // of the RDKit source tree. 00009 // 00010 #ifndef _RD_SMILESPARSE_H_ 00011 #define _RD_SMILESPARSE_H_ 00012 00013 #include <string> 00014 #include <exception> 00015 #include <map> 00016 00017 namespace RDKit{ 00018 class RWMol; 00019 00020 //! Construct a molecule from a SMILES string 00021 /*! 00022 \param smi the SMILES to convert 00023 \param debugParse toggles verbose debugging information from the parser 00024 \param sanitize toggles H removal and sanitization of the molecule 00025 \param replacements a string->string map of replacement strings. See below 00026 for more information about replacements. 00027 00028 \return a pointer to the new molecule; the caller is responsible for free'ing this. 00029 00030 The optional replacements map can be used to do string substitution of abbreviations 00031 in the input SMILES. The set of substitutions is repeatedly looped through until 00032 the string no longer changes. It is the responsiblity of the caller to make sure 00033 that substitutions results in legal and sensible SMILES. 00034 00035 Examples of substitutions: 00036 \code 00037 CC{Q}C with {"{Q}":"OCCO"} -> CCOCCOC 00038 C{A}C{Q}C with {"{Q}":"OCCO", "{A}":"C1(CC1)"} -> CC1(CC1)COCCOC 00039 C{A}C{Q}C with {"{Q}":"{X}CC{X}", "{A}":"C1CC1", "{X}":"N"} -> CC1CC1CCNCCNC 00040 \endcode 00041 00042 */ 00043 RWMol *SmilesToMol(std::string smi,int debugParse=0,bool sanitize=1, 00044 std::map<std::string,std::string> *replacements=0); 00045 //! Construct a molecule from a SMARTS string 00046 /*! 00047 \param sma the SMARTS to convert 00048 \param debugParse toggles verbose debugging information from the parser 00049 \param mergeHs toggles merging H atoms in the SMARTS into neighboring atoms 00050 \param replacements a string->string map of replacement strings. 00051 \see SmilesToMol for more information about replacements 00052 00053 \return a pointer to the new molecule; the caller is responsible for free'ing this. 00054 */ 00055 RWMol *SmartsToMol(std::string sma,int debugParse=0,bool mergeHs=false, 00056 std::map<std::string,std::string> *replacements=0); 00057 00058 class SmilesParseException : public std::exception { 00059 public: 00060 SmilesParseException(const char *msg) : _msg(msg) {}; 00061 SmilesParseException(const std::string msg) : _msg(msg) {}; 00062 const char *message () const { return _msg.c_str(); }; 00063 ~SmilesParseException () throw () {}; 00064 private: 00065 std::string _msg; 00066 }; 00067 00068 } 00069 00070 #endif
1.7.1