RDKit: ReactionParser.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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