RDKit
Open-source cheminformatics and machine learning.
ReactionParser.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2007-2014, Novartis Institutes for BioMedical Research Inc.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following
13 // disclaimer in the documentation and/or other materials provided
14 // with the distribution.
15 // * Neither the name of Novartis Institutes for BioMedical Research Inc.
16 // nor the names of its contributors may be used to endorse or promote
17 // products derived from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 //
31 
32 #ifndef __RD_REACTIONPARSER_H_21Aug2006__
33 #define __RD_REACTIONPARSER_H_21Aug2006__
34 
35 #include <string>
36 #include <iostream>
37 
38 namespace RDKit{
39  class ChemicalReaction;
40 
41  //! used to indicate an error in parsing reaction data
42  class ChemicalReactionParserException : public std::exception {
43  public:
44  //! construct with an error message
45  explicit ChemicalReactionParserException(const char *msg) : _msg(msg) {};
46  //! construct with an error message
47  explicit ChemicalReactionParserException(const std::string msg) : _msg(msg) {};
48  //! get the error message
49  const char *message () const { return _msg.c_str(); };
51  private:
52  std::string _msg;
53  };
54 
55 
56 
57  //! Parse a text block in MDL rxn format into a ChemicalReaction
58  ChemicalReaction * RxnBlockToChemicalReaction(const std::string &rxnBlock);
59  //! Parse a file in MDL rxn format into a ChemicalReaction
60  ChemicalReaction * RxnFileToChemicalReaction(const std::string &fileName);
61  //! Parse a text stream in MDL rxn format into a ChemicalReaction
62  ChemicalReaction * RxnDataStreamToChemicalReaction(std::istream &rxnStream,
63  unsigned int &line);
64 
65  //! Parse a string containing "Reaction SMARTS" into a ChemicalReaction
66  /*!
67  Our definition of Reaction SMARTS is something that looks a lot like
68  reaction SMILES, except that SMARTS queries are allowed on the reactant
69  side and that atom-map numbers are required (at least for now)
70 
71  \param text the SMARTS to convert
72  \param replacements a string->string map of replacement strings.
73  \see SmilesToMol for more information about replacements
74  \param useSmiles if set, the SMILES parser will be used instead of the SMARTS
75  parserfor the individual components
76  */
77  ChemicalReaction * RxnSmartsToChemicalReaction(const std::string &text,
78  std::map<std::string,std::string> *replacements=0,
79  bool useSmiles=false);
80 
81  //! Parse a ROMol into a ChemicalReaction, RXN role must be set before
82  /*!
83  Alternative to build a reaction from a molecule (fragments) which have RXN roles
84  set as atom properties: common_properties::molRxnRole (1=reactant, 2=product, 3=agent)
85 
86  \param mol ROMol with RXN roles set
87  */
89 
90 
91 
92  //! returns the reaction SMARTS for a reaction
93  std::string ChemicalReactionToRxnSmarts(const ChemicalReaction &rxn);
94 
95  //! returns the reaction SMILES for a reaction
96  std::string ChemicalReactionToRxnSmiles(const ChemicalReaction &rxn, bool canonical=true);
97 
98  //! returns an RXN block for a reaction
99  /*!
100  \param rxn chemical reaction
101  \param separateAgents flag to decide if agents were put in a seperate block,
102  otherwise they were included in the reactants block (default)
103  */
104  std::string ChemicalReactionToRxnBlock(const ChemicalReaction &rxn, bool separateAgents=false);
105 
106  //! returns a ROMol with RXN roles used to describe the reaction
108 
109 }; // end of RDKit namespace
110 
111 #endif
ChemicalReactionParserException(const char *msg)
construct with an error message
used to indicate an error in parsing reaction data
ChemicalReactionParserException(const std::string msg)
construct with an error message
ChemicalReaction * RxnMolToChemicalReaction(const ROMol &mol)
Parse a ROMol into a ChemicalReaction, RXN role must be set before.
const char * message() const
get the error message
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:113
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:105
ROMol * ChemicalReactionToRxnMol(const ChemicalReaction &rxn)
returns a ROMol with RXN roles used to describe the reaction
ChemicalReaction * RxnBlockToChemicalReaction(const std::string &rxnBlock)
Parse a text block in MDL rxn format into a ChemicalReaction.
ChemicalReaction * RxnFileToChemicalReaction(const std::string &fileName)
Parse a file in MDL rxn format into a ChemicalReaction.
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
std::string ChemicalReactionToRxnSmarts(const ChemicalReaction &rxn)
returns the reaction SMARTS for a reaction
ChemicalReaction * RxnDataStreamToChemicalReaction(std::istream &rxnStream, unsigned int &line)
Parse a text stream in MDL rxn format into a ChemicalReaction.
ChemicalReaction * RxnSmartsToChemicalReaction(const std::string &text, std::map< std::string, std::string > *replacements=0, bool useSmiles=false)
Parse a string containing "Reaction SMARTS" into a ChemicalReaction.
std::string ChemicalReactionToRxnSmiles(const ChemicalReaction &rxn, bool canonical=true)
returns the reaction SMILES for a reaction
std::string ChemicalReactionToRxnBlock(const ChemicalReaction &rxn, bool separateAgents=false)
returns an RXN block for a reaction