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 this.
29 
30  The optional replacements map can be used to do string substitution of abbreviations
31  in the input SMILES. The set of substitutions is repeatedly looped through until
32  the string no longer changes. It is the responsiblity of the caller to make sure
33  that substitutions results in legal and sensible SMILES.
34 
35  Examples of substitutions:
36  \code
37  CC{Q}C with {"{Q}":"OCCO"} -> CCOCCOC
38  C{A}C{Q}C with {"{Q}":"OCCO", "{A}":"C1(CC1)"} -> CC1(CC1)COCCOC
39  C{A}C{Q}C with {"{Q}":"{X}CC{X}", "{A}":"C1CC1", "{X}":"N"} -> CC1CC1CCNCCNC
40  \endcode
41 
42  */
43  RWMol *SmilesToMol(std::string smi,int debugParse=0,bool sanitize=1,
44  std::map<std::string,std::string> *replacements=0);
45  //! Construct a molecule from a SMARTS string
46  /*!
47  \param sma the SMARTS to convert
48  \param debugParse toggles verbose debugging information from the parser
49  \param mergeHs toggles merging H atoms in the SMARTS into neighboring atoms
50  \param replacements a string->string map of replacement strings.
51  \see SmilesToMol for more information about replacements
52 
53  \return a pointer to the new molecule; the caller is responsible for free'ing this.
54  */
55  RWMol *SmartsToMol(std::string sma,int debugParse=0,bool mergeHs=false,
56  std::map<std::string,std::string> *replacements=0);
57 
58  class SmilesParseException : public std::exception {
59  public:
60  SmilesParseException(const char *msg) : _msg(msg) {};
61  SmilesParseException(const std::string msg) : _msg(msg) {};
62  const char *message () const { return _msg.c_str(); };
63  ~SmilesParseException () throw () {};
64  private:
65  std::string _msg;
66  };
67 
68 }
69 
70 #endif
RWMol * SmilesToMol(std::string smi, int debugParse=0, bool sanitize=1, std::map< std::string, std::string > *replacements=0)
Construct a molecule from a SMILES string.
const char * message() const
Definition: SmilesParse.h:62
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
SmilesParseException(const char *msg)
Definition: SmilesParse.h:60
RWMol * SmartsToMol(std::string sma, int debugParse=0, bool mergeHs=false, std::map< std::string, std::string > *replacements=0)
Construct a molecule from a SMARTS string.
SmilesParseException(const std::string msg)
Definition: SmilesParse.h:61