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 *message() const { return _msg.c_str(); };
55 
56  private:
57  std::string _msg;
58 };
59 
60 //! Parse a text block in MDL rxn format into a ChemicalReaction
62  const std::string &rxnBlock);
63 //! Parse a file in MDL rxn format into a ChemicalReaction
65  const std::string &fileName);
66 //! Parse a text stream in MDL rxn format into a ChemicalReaction
68  std::istream &rxnStream, unsigned int &line);
69 
70 //! Parse a string containing "Reaction SMARTS" into a ChemicalReaction
71 /*!
72  Our definition of Reaction SMARTS is something that looks a lot like
73  reaction SMILES, except that SMARTS queries are allowed on the reactant
74  side and that atom-map numbers are required (at least for now)
75 
76  \param text the SMARTS to convert
77  \param replacements a string->string map of replacement strings.
78  \see SmilesToMol for more information about replacements
79  \param useSmiles if set, the SMILES parser will be used instead of the
80  SMARTS
81  parserfor the individual components
82  */
84  const std::string &text,
85  std::map<std::string, std::string> *replacements = 0,
86  bool useSmiles = false);
87 
88 //! Parse a ROMol into a ChemicalReaction, RXN role must be set before
89 /*!
90  Alternative to build a reaction from a molecule (fragments) which have RXN
91  roles
92  set as atom properties: common_properties::molRxnRole (1=reactant, 2=product,
93  3=agent)
94 
95  \param mol ROMol with RXN roles set
96  */
98  const ROMol &mol);
99 
100 //! returns the reaction SMARTS for a reaction
102  const ChemicalReaction &rxn);
103 
104 //! returns the reaction SMILES for a reaction
106  const ChemicalReaction &rxn, bool canonical = true);
107 
108 //! returns an RXN block for a reaction
109 /*!
110  \param rxn chemical reaction
111  \param separateAgents flag to decide if agents were put in a separate block,
112  otherwise they were included in the reactants block
113  (default)
114  */
116  const ChemicalReaction &rxn, bool separateAgents = false);
117 
118 //! returns a ROMol with RXN roles used to describe the reaction
120  const ChemicalReaction &rxn);
121 
122 }; // namespace RDKit
123 
124 #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::ChemicalReactionToRxnSmiles
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnSmiles(const ChemicalReaction &rxn, bool canonical=true)
returns the reaction SMILES for a reaction
RDKit::ChemicalReactionParserException::~ChemicalReactionParserException
~ChemicalReactionParserException()
Definition: ReactionParser.h:54
RDKit::ChemicalReactionToRxnSmarts
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnSmarts(const ChemicalReaction &rxn)
returns the reaction SMARTS for a reaction
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:44
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_CHEMREACTIONS_EXPORT
#define RDKIT_CHEMREACTIONS_EXPORT
Definition: export.h:60
RDKit::ChemicalReactionParserException::message
const char * message() const
get the error message
Definition: ReactionParser.h:53
RDKit::ChemicalReactionToRxnBlock
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnBlock(const ChemicalReaction &rxn, bool separateAgents=false)
returns an RXN block for a reaction
export.h