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
18 // permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 //
32 
33 #include <RDGeneral/export.h>
34 #ifndef __RD_REACTIONPARSER_H_21Aug2006__
35 #define __RD_REACTIONPARSER_H_21Aug2006__
36 
37 #include <string>
38 #include <iostream>
39 
40 namespace RDKit {
41 class ChemicalReaction;
42 
43 //! used to indicate an error in parsing reaction data
45  : public std::exception {
46  public:
47  //! construct with an error message
48  explicit ChemicalReactionParserException(const char *msg) : _msg(msg){};
49  //! construct with an error message
50  explicit ChemicalReactionParserException(const std::string &msg)
51  : _msg(msg){};
52  //! get the error message
53  const char *what() const noexcept override{ return _msg.c_str(); };
54  const char *message() const noexcept{ return what(); };
56 
57  private:
58  std::string _msg;
59 };
60 
61 //! Parse a text block in MDL rxn format into a ChemicalReaction
63  const std::string &rxnBlock);
64 //! Parse a file in MDL rxn format into a ChemicalReaction
66  const std::string &fileName);
67 //! Parse a text stream in MDL rxn format into a ChemicalReaction
69  std::istream &rxnStream, unsigned int &line);
70 
71 //! Parse a string containing "Reaction SMARTS" into a ChemicalReaction
72 /*!
73  Our definition of Reaction SMARTS is something that looks a lot like
74  reaction SMILES, except that SMARTS queries are allowed on the reactant
75  side and that atom-map numbers are required (at least for now)
76 
77  \param text the SMARTS to convert
78  \param replacements a string->string map of replacement strings.
79  \see SmilesToMol for more information about replacements
80  \param useSmiles if set, the SMILES parser will be used instead of the
81  SMARTS
82  parserfor the individual components
83  */
85  const std::string &text,
86  std::map<std::string, std::string> *replacements = 0,
87  bool useSmiles = false);
88 
89 //! Parse a ROMol into a ChemicalReaction, RXN role must be set before
90 /*!
91  Alternative to build a reaction from a molecule (fragments) which have RXN
92  roles
93  set as atom properties: common_properties::molRxnRole (1=reactant, 2=product,
94  3=agent)
95 
96  \param mol ROMol with RXN roles set
97  */
99  const ROMol &mol);
100 
101 //! returns the reaction SMARTS for a reaction
103  const ChemicalReaction &rxn);
104 
105 //! returns the reaction SMILES for a reaction
107  const ChemicalReaction &rxn, bool canonical = true);
108 
109 //! returns an RXN block for a reaction
110 /*!
111  \param rxn chemical reaction
112  \param separateAgents flag to decide if agents were put in a separate block,
113  otherwise they were included in the reactants block
114  (default)
115  */
117  const ChemicalReaction &rxn, bool separateAgents = false);
118 
119 //! returns a ROMol with RXN roles used to describe the reaction
121  const ChemicalReaction &rxn);
122 
123 }; // namespace RDKit
124 
125 #endif
RDKit::RxnMolToChemicalReaction
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnMolToChemicalReaction(const ROMol &mol)
Parse a ROMol into a ChemicalReaction, RXN role must be set before.
RDKit::ChemicalReactionParserException::ChemicalReactionParserException
ChemicalReactionParserException(const std::string &msg)
construct with an error message
Definition: ReactionParser.h:50
RDKit::RxnSmartsToChemicalReaction
RDKIT_CHEMREACTIONS_EXPORT 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.
RDKit::RxnFileToChemicalReaction
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnFileToChemicalReaction(const std::string &fileName)
Parse a file in MDL rxn format into a ChemicalReaction.
RDKit::ChemicalReactionToRxnMol
RDKIT_CHEMREACTIONS_EXPORT ROMol * ChemicalReactionToRxnMol(const ChemicalReaction &rxn)
returns a ROMol with RXN roles used to describe the reaction
RDKit::ChemicalReactionParserException::ChemicalReactionParserException
ChemicalReactionParserException(const char *msg)
construct with an error message
Definition: ReactionParser.h:48
RDKit::ChemicalReactionParserException::message
const char * message() const noexcept
Definition: ReactionParser.h:54
RDKit::ROMol
Definition: ROMol.h:171
RDKit::ChemicalReactionToRxnSmiles
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnSmiles(const ChemicalReaction &rxn, bool canonical=true)
returns the reaction SMILES for a reaction
RDKit::ChemicalReactionParserException::what
const char * what() const noexcept override
get the error message
Definition: ReactionParser.h:53
RDKit::ChemicalReactionToRxnSmarts
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnSmarts(const ChemicalReaction &rxn)
returns the reaction SMARTS for a reaction
RDKit::ChemicalReaction
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:120
RDKit::RxnBlockToChemicalReaction
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnBlockToChemicalReaction(const std::string &rxnBlock)
Parse a text block in MDL rxn format into a ChemicalReaction.
RDKit::ChemicalReactionParserException
used to indicate an error in parsing reaction data
Definition: ReactionParser.h:45
RDKit::RxnDataStreamToChemicalReaction
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnDataStreamToChemicalReaction(std::istream &rxnStream, unsigned int &line)
Parse a text stream in MDL rxn format into a ChemicalReaction.
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::ChemicalReactionParserException::~ChemicalReactionParserException
~ChemicalReactionParserException() noexcept
Definition: ReactionParser.h:55
RDKIT_CHEMREACTIONS_EXPORT
#define RDKIT_CHEMREACTIONS_EXPORT
Definition: export.h:60
RDKit::ChemicalReactionToRxnBlock
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnBlock(const ChemicalReaction &rxn, bool separateAgents=false)
returns an RXN block for a reaction
export.h