RDKit
Open-source cheminformatics and machine learning.
SmilesParse.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2011 Greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #ifndef _RD_SMILESPARSE_H_
11 #define _RD_SMILESPARSE_H_
12 
13 #include <string>
14 #include <exception>
15 #include <map>
16 
17 namespace RDKit {
18 class RWMol;
19 
20 //! Construct a molecule from a SMILES string
21 /*!
22  \param smi the SMILES to convert
23  \param debugParse toggles verbose debugging information from the parser
24  \param sanitize toggles H removal and sanitization of the molecule
25  \param replacements a string->string map of replacement strings. See below
26  for more information about replacements.
27 
28  \return a pointer to the new molecule; the caller is responsible for free'ing
29  this.
30 
31  The optional replacements map can be used to do string substitution of
32  abbreviations
33  in the input SMILES. The set of substitutions is repeatedly looped through
34  until
35  the string no longer changes. It is the responsiblity of the caller to make
36  sure
37  that substitutions results in legal and sensible SMILES.
38 
39  Examples of substitutions:
40  \code
41  CC{Q}C with {"{Q}":"OCCO"} -> CCOCCOC
42  C{A}C{Q}C with {"{Q}":"OCCO", "{A}":"C1(CC1)"} -> CC1(CC1)COCCOC
43  C{A}C{Q}C with {"{Q}":"{X}CC{X}", "{A}":"C1CC1", "{X}":"N"} -> CC1CC1CCNCCNC
44  \endcode
45 
46  */
47 RWMol *SmilesToMol(const std::string &smi, int debugParse = 0,
48  bool sanitize = 1,
49  std::map<std::string, std::string> *replacements = 0);
50 //! Construct a molecule from a SMARTS string
51 /*!
52  \param sma the SMARTS to convert
53  \param debugParse toggles verbose debugging information from the parser
54  \param mergeHs toggles merging H atoms in the SMARTS into neighboring
55  atoms
56  \param replacements a string->string map of replacement strings.
57  \see SmilesToMol for more information about replacements
58 
59  \return a pointer to the new molecule; the caller is responsible for free'ing
60  this.
61  */
62 RWMol *SmartsToMol(const std::string &sma, int debugParse = 0,
63  bool mergeHs = false,
64  std::map<std::string, std::string> *replacements = 0);
65 
66 class SmilesParseException : public std::exception {
67  public:
68  SmilesParseException(const char *msg) : _msg(msg){};
69  SmilesParseException(const std::string msg) : _msg(msg){};
70  const char *message() const { return _msg.c_str(); };
71  ~SmilesParseException() throw(){};
72 
73  private:
74  std::string _msg;
75 };
76 }
77 
78 #endif
const char * message() const
Definition: SmilesParse.h:70
RWMol * SmartsToMol(const std::string &sma, int debugParse=0, bool mergeHs=false, std::map< std::string, std::string > *replacements=0)
Construct a molecule from a SMARTS string.
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
SmilesParseException(const char *msg)
Definition: SmilesParse.h:68
RWMol * SmilesToMol(const std::string &smi, int debugParse=0, bool sanitize=1, std::map< std::string, std::string > *replacements=0)
Construct a molecule from a SMILES string.
SmilesParseException(const std::string msg)
Definition: SmilesParse.h:69