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:
46  //! construct with an error message
47  explicit ChemicalReactionParserException(const char *msg) : _msg(msg){};
48  //! construct with an error message
49  explicit ChemicalReactionParserException(const std::string &msg)
50  : _msg(msg){};
51  //! get the error message
52  const char *message() const { return _msg.c_str(); };
54 
55  private:
56  std::string _msg;
57 };
58 
59 //! Parse a text block in MDL rxn format into a ChemicalReaction
61 //! Parse a file in MDL rxn format into a ChemicalReaction
63 //! Parse a text stream in MDL rxn format into a ChemicalReaction
65  unsigned int &line);
66 
67 //! Parse a string containing "Reaction SMARTS" into a ChemicalReaction
68 /*!
69  Our definition of Reaction SMARTS is something that looks a lot like
70  reaction SMILES, except that SMARTS queries are allowed on the reactant
71  side and that atom-map numbers are required (at least for now)
72 
73  \param text the SMARTS to convert
74  \param replacements a string->string map of replacement strings.
75  \see SmilesToMol for more information about replacements
76  \param useSmiles if set, the SMILES parser will be used instead of the
77  SMARTS
78  parserfor the individual components
79  */
81  const std::string &text,
82  std::map<std::string, std::string> *replacements = 0,
83  bool useSmiles = false);
84 
85 //! Parse a ROMol into a ChemicalReaction, RXN role must be set before
86 /*!
87  Alternative to build a reaction from a molecule (fragments) which have RXN
88  roles
89  set as atom properties: common_properties::molRxnRole (1=reactant, 2=product,
90  3=agent)
91 
92  \param mol ROMol with RXN roles set
93  */
95 
96 //! returns the reaction SMARTS for a reaction
98 
99 //! returns the reaction SMILES for a reaction
101  bool canonical = true);
102 
103 //! returns an RXN block for a reaction
104 /*!
105  \param rxn chemical reaction
106  \param separateAgents flag to decide if agents were put in a seperate block,
107  otherwise they were included in the reactants block
108  (default)
109  */
111  bool separateAgents = false);
112 
113 //! returns a ROMol with RXN roles used to describe the reaction
115 
116 }; // end of RDKit namespace
117 
118 #endif
ChemicalReactionParserException(const char *msg)
construct with an error message
used to indicate an error in parsing reaction data
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:118
ChemicalReactionParserException(const std::string &msg)
construct with an error message
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnMolToChemicalReaction(const ROMol &mol)
Parse a ROMol into a ChemicalReaction, RXN role must be set before.
Std stuff.
Definition: Atom.h:30
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnSmarts(const ChemicalReaction &rxn)
returns the reaction SMARTS for a reaction
RDKIT_CHEMREACTIONS_EXPORT ROMol * ChemicalReactionToRxnMol(const ChemicalReaction &rxn)
returns a ROMol with RXN roles used to describe the reaction
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnDataStreamToChemicalReaction(std::istream &rxnStream, unsigned int &line)
Parse a text stream in MDL rxn format into a ChemicalReaction.
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnFileToChemicalReaction(const std::string &fileName)
Parse a file in MDL rxn format into a ChemicalReaction.
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnBlockToChemicalReaction(const std::string &rxnBlock)
Parse a text block in MDL rxn format into a ChemicalReaction.
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnSmiles(const ChemicalReaction &rxn, bool canonical=true)
returns the reaction SMILES for a reaction
#define RDKIT_CHEMREACTIONS_EXPORT
Definition: export.h:60
const char * message() const
get the error message
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnBlock(const ChemicalReaction &rxn, bool separateAgents=false)
returns an RXN block for a reaction
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.