36#ifndef RD_REACTIONPARSER_H_21Aug2006
37#define RD_REACTIONPARSER_H_21Aug2006
44#include <boost/format.hpp>
56 :
public std::exception {
62 : _msg(std::move(msg)) {}
64 const char *
what() const noexcept
override {
return _msg.c_str(); }
75 std::map<std::string, std::string>
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) {
154 std::uint32_t flags = SmilesWrite::CXSmilesFields::CX_ALL);
165 std::uint32_t flags = SmilesWrite::CXSmilesFields::CX_ALL);
168 bool canonical =
true) {
199namespace ReactionParser {
219 bool sanitize =
false,
220 bool removeHs =
false,
221 bool strictParsing =
true) {
230 bool sanitize =
false,
231 bool removeHs =
false,
232 bool strictParsing =
true) {
241 std::istream &rxnStream,
unsigned int &line,
bool sanitize =
false,
242 bool removeHs =
false,
bool strictParsing =
true) {
264 bool forceV3000 =
false);
291namespace ReactionParser {
307 const std::string &data) {
308 std::stringstream inStream(data);
314 const std::string &fname) {
315 std::ifstream inStream(fname.c_str(), std::ios::binary);
316 if (!inStream || (inStream.bad())) {
365 bool includeSmiles =
true,
bool includeSmarts =
false,
366 bool includeRxn =
false);
370 const std::string &pngString,
371 bool includePkl =
true,
372 bool includeSmiles =
true,
373 bool includeSmarts =
false,
374 bool includeRxn =
false) {
375 std::stringstream inStream(pngString);
377 rxn, inStream, includePkl, includeSmiles, includeSmarts, includeRxn);
382 const std::string &fname,
383 bool includePkl =
true,
384 bool includeSmiles =
true,
385 bool includeSmarts =
false,
386 bool includeRxn =
false) {
387 std::ifstream inStream(fname.c_str(), std::ios::binary);
389 rxn, inStream, includePkl, includeSmiles, includeSmarts, includeRxn);
393inline std::unique_ptr<ChemicalReaction>
operator""_rxnsmarts(
const char *text,
395 std::string sma(text, len);
396 std::unique_ptr<ChemicalReaction> ptr;
404inline std::unique_ptr<ChemicalReaction>
operator""_rxnsmiles(
const char *text,
406 std::string sma(text, len);
407 std::unique_ptr<ChemicalReaction> ptr;
423 bool removeHs =
false);
427 bool removeHs =
false);
431 bool sanitize =
false,
432 bool removeHs =
false);
used by various file parsing classes to indicate a bad file
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
Tags used for PNG metadata.
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 ChemicalReactionToCXRxnSmarts(const ChemicalReaction &rxn, const SmilesWriteParams ¶ms, std::uint32_t flags=SmilesWrite::CXSmilesFields::CX_ALL)
returns the reaction SMARTS for a reaction with CX extension
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 ChemicalReactionToCXRxnSmiles(const ChemicalReaction &rxn, const SmilesWriteParams ¶ms, std::uint32_t flags=SmilesWrite::CXSmilesFields::CX_ALL)
returns the reaction SMILES for a reaction with CX extension
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...
std::map< std::string, std::string > replacements