36#ifndef RD_REACTIONPARSER_H_21Aug2006
37#define RD_REACTIONPARSER_H_21Aug2006
45#include <boost/format.hpp>
53class ChemicalReaction;
57 :
public std::exception {
63 : _msg(std::move(msg)) {}
65 const char *
what() const noexcept
override {
return _msg.c_str(); }
73namespace ReactionParser {
75 bool sanitize =
false;
76 std::map<std::string, std::string>
78 bool allowCXSMILES =
true;
83 const std::string &smarts,
84 const ReactionSmartsParserParams ¶ms = ReactionSmartsParserParams());
87 const std::string &smarts,
88 const ReactionSmartsParserParams ¶ms = ReactionSmartsParserParams());
115 const std::string &text,
116 std::map<std::string, std::string> *replacements =
nullptr,
117 bool useSmiles =
false,
bool allowCXSMILES =
true) {
118 v2::ReactionParser::ReactionSmartsParserParams params;
120 params.replacements = *replacements;
122 params.allowCXSMILES = allowCXSMILES;
124 return v2::ReactionParser::ReactionFromSmiles(text, params).release();
126 return v2::ReactionParser::ReactionFromSmarts(text, params).release();
177namespace ReactionParser {
197 bool sanitize =
false,
198 bool removeHs =
false,
199 bool strictParsing =
true) {
204 return v2::ReactionParser::ReactionFromRxnBlock(rxnBlock, params).release();
208 bool sanitize =
false,
209 bool removeHs =
false,
210 bool strictParsing =
true) {
215 return v2::ReactionParser::ReactionFromRxnFile(fileName, params).release();
219 std::istream &rxnStream,
unsigned int &line,
bool sanitize =
false,
220 bool removeHs =
false,
bool strictParsing =
true) {
225 return v2::ReactionParser::ReactionFromRxnDataStream(rxnStream, line, params)
242 bool forceV3000 =
false);
269namespace ReactionParser {
285 const std::string &data) {
286 std::stringstream inStream(data);
292 const std::string &fname) {
293 std::ifstream inStream(fname.c_str(), std::ios::binary);
294 if (!inStream || (inStream.bad())) {
315 return v2::ReactionParser::ReactionFromPNGStream(pngStream).release();
320 return v2::ReactionParser::ReactionFromPNGString(data).release();
325 return v2::ReactionParser::ReactionFromPNGFile(fname).release();
343 bool includeSmiles =
true,
bool includeSmarts =
false,
344 bool includeRxn =
false);
348 const std::string &pngString,
349 bool includePkl =
true,
350 bool includeSmiles =
true,
351 bool includeSmarts =
false,
352 bool includeRxn =
false) {
353 std::stringstream inStream(pngString);
355 rxn, inStream, includePkl, includeSmiles, includeSmarts, includeRxn);
360 const std::string &fname,
361 bool includePkl =
true,
362 bool includeSmiles =
true,
363 bool includeSmarts =
false,
364 bool includeRxn =
false) {
365 std::ifstream inStream(fname.c_str(), std::ios::binary);
367 rxn, inStream, includePkl, includeSmiles, includeSmarts, includeRxn);
371inline std::unique_ptr<ChemicalReaction>
operator"" _rxnsmarts(
const char *text,
373 std::string sma(text, len);
374 std::unique_ptr<ChemicalReaction> ptr;
376 ptr = v2::ReactionParser::ReactionFromSmarts(sma);
382inline std::unique_ptr<ChemicalReaction>
operator"" _rxnsmiles(
const char *text,
384 std::string sma(text, len);
385 std::unique_ptr<ChemicalReaction> ptr;
387 ptr = v2::ReactionParser::ReactionFromSmiles(sma);
401 bool removeHs =
false);
405 bool removeHs =
false);
409 bool sanitize =
false,
410 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 > 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::string ChemicalReactionToRxnSmarts(const ChemicalReaction &rxn, const SmilesWriteParams ¶ms)
returns the reaction SMARTS 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 ChemicalReactionToRxnSmiles(const ChemicalReaction &rxn, const SmilesWriteParams ¶ms=SmilesWriteParams())
returns the reaction SMILES 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...