36#ifndef RD_REACTIONPARSER_H_21Aug2006
37#define RD_REACTIONPARSER_H_21Aug2006
45#include <boost/format.hpp>
52class ChemicalReaction;
56 :
public std::exception {
62 : _msg(std::move(msg)) {}
64 const char *
what() const noexcept
override {
return _msg.c_str(); }
72namespace ReactionParser {
74 bool sanitize =
false;
75 std::map<std::string, std::string>
77 bool allowCXSMILES =
true;
82 const std::string &smarts,
86 const std::string &smarts,
114 const std::string &text,
115 std::map<std::string, std::string> *replacements =
nullptr,
116 bool useSmiles =
false,
bool allowCXSMILES =
true) {
123 return v2::ReactionParser::ReactionFromSmiles(text, params).release();
125 return v2::ReactionParser::ReactionFromSmarts(text, params).release();
162namespace ReactionParser {
182 bool sanitize =
false,
183 bool removeHs =
false,
184 bool strictParsing =
true) {
189 return v2::ReactionParser::ReactionFromRxnBlock(rxnBlock, params).release();
193 bool sanitize =
false,
194 bool removeHs =
false,
195 bool strictParsing =
true) {
200 return v2::ReactionParser::ReactionFromRxnFile(fileName, params).release();
204 std::istream &rxnStream,
unsigned int &line,
bool sanitize =
false,
205 bool removeHs =
false,
bool strictParsing =
true) {
210 return v2::ReactionParser::ReactionFromRxnDataStream(rxnStream, line, params)
227 bool forceV3000 =
false);
254namespace ReactionParser {
270 const std::string &data) {
271 std::stringstream inStream(data);
277 const std::string &fname) {
278 std::ifstream inStream(fname.c_str(), std::ios::binary);
279 if (!inStream || (inStream.bad())) {
300 return v2::ReactionParser::ReactionFromPNGStream(pngStream).release();
305 return v2::ReactionParser::ReactionFromPNGString(data).release();
310 return v2::ReactionParser::ReactionFromPNGFile(fname).release();
328 bool includeSmiles =
true,
bool includeSmarts =
false,
329 bool includeRxn =
false);
333 const std::string &pngString,
334 bool includePkl =
true,
335 bool includeSmiles =
true,
336 bool includeSmarts =
false,
337 bool includeRxn =
false) {
338 std::stringstream inStream(pngString);
340 rxn, inStream, includePkl, includeSmiles, includeSmarts, includeRxn);
345 const std::string &fname,
346 bool includePkl =
true,
347 bool includeSmiles =
true,
348 bool includeSmarts =
false,
349 bool includeRxn =
false) {
350 std::ifstream inStream(fname.c_str(), std::ios::binary);
352 rxn, inStream, includePkl, includeSmiles, includeSmarts, includeRxn);
356inline std::unique_ptr<ChemicalReaction>
operator"" _rxnsmarts(
const char *text,
358 std::string sma(text, len);
359 std::unique_ptr<ChemicalReaction> ptr;
361 ptr = v2::ReactionParser::ReactionFromSmarts(sma);
367inline std::unique_ptr<ChemicalReaction>
operator"" _rxnsmiles(
const char *text,
369 std::string sma(text, len);
370 std::unique_ptr<ChemicalReaction> ptr;
372 ptr = v2::ReactionParser::ReactionFromSmiles(sma);
386 bool removeHs =
false);
390 bool removeHs =
false);
394 bool sanitize =
false,
395 bool removeHs =
false);
used by various file parsing classes to indicate a bad file
used to indicate an error in parsing reaction data
const char * what() const noexcept override
get the error message
ChemicalReactionParserException(std::string msg)
construct with an error message
~ChemicalReactionParserException() noexcept override=default
ChemicalReactionParserException(const char *msg)
construct with an error message
This is a class for storing and applying general chemical reactions.
#define RDKIT_CHEMREACTIONS_EXPORT
RDKIT_CHEMREACTIONS_EXPORT const std::string rxnRxnTag
RDKIT_CHEMREACTIONS_EXPORT const std::string rxnSmilesTag
RDKIT_CHEMREACTIONS_EXPORT const std::string rxnSmartsTag
RDKIT_CHEMREACTIONS_EXPORT const std::string rxnPklTag
ChemicalReaction * RxnSmartsToChemicalReaction(const std::string &text, std::map< std::string, std::string > *replacements=nullptr, bool useSmiles=false, bool allowCXSMILES=true)
Parse a string containing "Reaction SMARTS" into a ChemicalReaction.
ChemicalReaction * RxnBlockToChemicalReaction(const std::string &rxnBlock, bool sanitize=false, bool removeHs=false, bool strictParsing=true)
Parse a text block in MDL rxn format into a ChemicalReaction.
ChemicalReaction * RxnDataStreamToChemicalReaction(std::istream &rxnStream, unsigned int &line, bool sanitize=false, bool removeHs=false, bool strictParsing=true)
Parse a text stream in MDL rxn format into a ChemicalReaction.
ChemicalReaction * PNGStreamToChemicalReaction(std::istream &pngStream)
constructs a ChemicalReaction from the metadata in a PNG stream
ChemicalReaction * RxnFileToChemicalReaction(const std::string &fileName, bool sanitize=false, bool removeHs=false, bool strictParsing=true)
Parse a file in MDL rxn format into a ChemicalReaction.
ChemicalReaction * PNGStringToChemicalReaction(const std::string &data)
constructs a ChemicalReaction from the metadata in a PNG string See PNGStreamToChemicalReaction() for...
ChemicalReaction * PNGFileToChemicalReaction(const std::string &fname)
constructs a ChemicalReaction from the metadata in a PNG file See PNGStreamToChemicalReaction() for m...
std::unique_ptr< ChemicalReaction > ReactionFromPNGString(const std::string &data)
constructs a ChemicalReaction from the metadata in a PNG string See PNGStreamToChemicalReaction() for...
RDKIT_CHEMREACTIONS_EXPORT std::unique_ptr< ChemicalReaction > ReactionFromRxnBlock(const std::string &rxnBlock, const FileParsers::MolFileParserParams ¶ms=FileParsers::MolFileParserParams())
RDKIT_CHEMREACTIONS_EXPORT std::unique_ptr< ChemicalReaction > ReactionFromRxnDataStream(std::istream &rxnStream, unsigned int &line, const FileParsers::MolFileParserParams ¶ms=FileParsers::MolFileParserParams())
std::unique_ptr< ChemicalReaction > ReactionFromPNGFile(const std::string &fname)
constructs a ChemicalReaction from the metadata in a PNG file See PNGStreamToChemicalReaction() for m...
RDKIT_CHEMREACTIONS_EXPORT std::unique_ptr< ChemicalReaction > ReactionFromSmarts(const std::string &smarts, const ReactionSmartsParserParams ¶ms=ReactionSmartsParserParams())
RDKIT_CHEMREACTIONS_EXPORT std::unique_ptr< ChemicalReaction > ReactionFromRxnFile(const std::string &fileName, const FileParsers::MolFileParserParams ¶ms=FileParsers::MolFileParserParams())
RDKIT_CHEMREACTIONS_EXPORT std::unique_ptr< ChemicalReaction > ReactionFromPNGStream(std::istream &pngStream)
constructs a ChemicalReaction from the metadata in a PNG stream
RDKIT_CHEMREACTIONS_EXPORT std::unique_ptr< ChemicalReaction > ReactionFromSmiles(const std::string &smarts, const ReactionSmartsParserParams ¶ms=ReactionSmartsParserParams())
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnSmiles(const ChemicalReaction &rxn, bool canonical=true)
returns the reaction SMILES for a reaction
RDKIT_CHEMREACTIONS_EXPORT std::vector< std::unique_ptr< ChemicalReaction > > CDXMLFileToChemicalReactions(const std::string &fileName, bool sanitize=false, bool removeHs=false)
Parse a file in CDXML rxn format into a vector of ChemicalReactions.
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnBlock(const ChemicalReaction &rxn, bool separateAgents=false, bool forceV3000=false)
returns an rxn block for a reaction
RDKIT_CHEMREACTIONS_EXPORT std::vector< std::unique_ptr< ChemicalReaction > > CDXMLDataStreamToChemicalReactions(std::istream &rxnStream, bool sanitize=false, bool removeHs=false)
Parse a text stream in CDXML rxn format into a vector of ChemicalReactions.
RDKIT_CHEMREACTIONS_EXPORT std::vector< std::unique_ptr< ChemicalReaction > > CDXMLToChemicalReactions(const std::string &rxnBlock, bool sanitize=false, bool removeHs=false)
Parse text in CDXML rxn format into a vector of ChemicalReactions.
RDKIT_CHEMREACTIONS_EXPORT std::string addChemicalReactionToPNGStream(const ChemicalReaction &rxn, std::istream &iStream, bool includePkl=true, bool includeSmiles=true, bool includeSmarts=false, bool includeRxn=false)
adds metadata for a ChemicalReaction to the data from a PNG stream. The modified PNG data is returned...
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToRxnSmarts(const ChemicalReaction &rxn)
returns the reaction SMARTS for a reaction
std::string addChemicalReactionToPNGFile(const ChemicalReaction &rxn, const std::string &fname, bool includePkl=true, bool includeSmiles=true, bool includeSmarts=false, bool includeRxn=false)
adds metadata for a ChemicalReaction to the data from a PNG string. See addChemicalReactionToPNGStrea...
RDKIT_CHEMREACTIONS_EXPORT std::string ChemicalReactionToV3KRxnBlock(const ChemicalReaction &rxn, bool separateAgents=false)
returns an V3000 rxn block for a reaction
RDKIT_CHEMREACTIONS_EXPORT ChemicalReaction * RxnMolToChemicalReaction(const ROMol &mol)
Parse a ROMol into a ChemicalReaction, RXN role must be set before.
RDKIT_CHEMREACTIONS_EXPORT ROMol * ChemicalReactionToRxnMol(const ChemicalReaction &rxn)
returns a ROMol with RXN roles used to describe the reaction
std::string addChemicalReactionToPNGString(const ChemicalReaction &rxn, const std::string &pngString, bool includePkl=true, bool includeSmiles=true, bool includeSmarts=false, bool includeRxn=false)
adds metadata for a ChemicalReaction to the data from a PNG string. See addChemicalReactionToPNGStrea...
std::map< std::string, std::string > replacements