RDKit
Open-source cheminformatics and machine learning.
SmilesParse.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2016 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 
22  bool sanitize;
23  std::map<std::string, std::string> *replacements;
25  bool parseName;
26  bool removeHs;
28  debugParse(0),
29  sanitize(true),
30  replacements(NULL),
31  allowCXSMILES(false),
32  parseName(false),
33  removeHs(true)
34  {};
35 };
36 RWMol *SmilesToMol(const std::string &smi, const SmilesParserParams &params);
37 
38 
39 //! Construct a molecule from a SMILES string
40 /*!
41  \param smi the SMILES to convert
42  \param debugParse toggles verbose debugging information from the parser
43  \param sanitize toggles H removal and sanitization of the molecule
44  \param replacements a string->string map of replacement strings. See below
45  for more information about replacements.
46 
47  \return a pointer to the new molecule; the caller is responsible for free'ing
48  this.
49 
50  The optional replacements map can be used to do string substitution of
51  abbreviations
52  in the input SMILES. The set of substitutions is repeatedly looped through
53  until
54  the string no longer changes. It is the responsiblity of the caller to make
55  sure
56  that substitutions results in legal and sensible SMILES.
57 
58  Examples of substitutions:
59  \code
60  CC{Q}C with {"{Q}":"OCCO"} -> CCOCCOC
61  C{A}C{Q}C with {"{Q}":"OCCO", "{A}":"C1(CC1)"} -> CC1(CC1)COCCOC
62  C{A}C{Q}C with {"{Q}":"{X}CC{X}", "{A}":"C1CC1", "{X}":"N"} -> CC1CC1CCNCCNC
63  \endcode
64 
65  */
66 inline RWMol *SmilesToMol(const std::string &smi, int debugParse = 0,
67  bool sanitize = true,
68  std::map<std::string, std::string> *replacements = 0){
69  SmilesParserParams params;
70  params.debugParse = debugParse;
71  params.replacements = replacements;
72  if(sanitize) {
73  params.sanitize=true;
74  params.removeHs=true;
75  } else {
76  params.sanitize=false;
77  params.removeHs=false;
78  }
79  return SmilesToMol(smi,params);
80 };
81 
82 
83 //! Construct a molecule from a SMARTS string
84 /*!
85  \param sma the SMARTS to convert
86  \param debugParse toggles verbose debugging information from the parser
87  \param mergeHs toggles merging H atoms in the SMARTS into neighboring
88  atoms
89  \param replacements a string->string map of replacement strings.
90  \see SmilesToMol for more information about replacements
91 
92  \return a pointer to the new molecule; the caller is responsible for free'ing
93  this.
94  */
95 RWMol *SmartsToMol(const std::string &sma, int debugParse = 0,
96  bool mergeHs = false,
97  std::map<std::string, std::string> *replacements = 0);
98 
99 class SmilesParseException : public std::exception {
100  public:
101  SmilesParseException(const char *msg) : _msg(msg){};
102  SmilesParseException(const std::string msg) : _msg(msg){};
103  const char *message() const { return _msg.c_str(); };
105 
106  private:
107  std::string _msg;
108 };
109 }
110 
111 #endif
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:30
const char * message() const
Definition: SmilesParse.h:103
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.
RWMol * SmilesToMol(const std::string &smi, const SmilesParserParams &params)
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
SmilesParseException(const char *msg)
Definition: SmilesParse.h:101
SmilesParseException(const std::string msg)
Definition: SmilesParse.h:102
std::map< std::string, std::string > * replacements
Definition: SmilesParse.h:23