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();
154 const SmilesWriteParams ¶ms, std::uint32_t flags = SmilesWrite::CXSmilesFields::CX_ALL);
164 const SmilesWriteParams ¶ms, std::uint32_t flags = SmilesWrite::CXSmilesFields::CX_ALL);
197namespace ReactionParser {
217 bool sanitize =
false,
218 bool removeHs =
false,
219 bool strictParsing =
true) {
224 return v2::ReactionParser::ReactionFromRxnBlock(rxnBlock, params).release();
228 bool sanitize =
false,
229 bool removeHs =
false,
230 bool strictParsing =
true) {
235 return v2::ReactionParser::ReactionFromRxnFile(fileName, params).release();
239 std::istream &rxnStream,
unsigned int &line,
bool sanitize =
false,
240 bool removeHs =
false,
bool strictParsing =
true) {
245 return v2::ReactionParser::ReactionFromRxnDataStream(rxnStream, line, params)
262 bool forceV3000 =
false);
289namespace ReactionParser {
305 const std::string &data) {
306 std::stringstream inStream(data);
312 const std::string &fname) {
313 std::ifstream inStream(fname.c_str(), std::ios::binary);
314 if (!inStream || (inStream.bad())) {
335 return v2::ReactionParser::ReactionFromPNGStream(pngStream).release();
340 return v2::ReactionParser::ReactionFromPNGString(data).release();
345 return v2::ReactionParser::ReactionFromPNGFile(fname).release();
363 bool includeSmiles =
true,
bool includeSmarts =
false,
364 bool includeRxn =
false);
368 const std::string &pngString,
369 bool includePkl =
true,
370 bool includeSmiles =
true,
371 bool includeSmarts =
false,
372 bool includeRxn =
false) {
373 std::stringstream inStream(pngString);
375 rxn, inStream, includePkl, includeSmiles, includeSmarts, includeRxn);
380 const std::string &fname,
381 bool includePkl =
true,
382 bool includeSmiles =
true,
383 bool includeSmarts =
false,
384 bool includeRxn =
false) {
385 std::ifstream inStream(fname.c_str(), std::ios::binary);
387 rxn, inStream, includePkl, includeSmiles, includeSmarts, includeRxn);
391inline std::unique_ptr<ChemicalReaction>
operator"" _rxnsmarts(
const char *text,
393 std::string sma(text, len);
394 std::unique_ptr<ChemicalReaction> ptr;
396 ptr = v2::ReactionParser::ReactionFromSmarts(sma);
402inline std::unique_ptr<ChemicalReaction>
operator"" _rxnsmiles(
const char *text,
404 std::string sma(text, len);
405 std::unique_ptr<ChemicalReaction> ptr;
407 ptr = v2::ReactionParser::ReactionFromSmiles(sma);
421 bool removeHs =
false);
425 bool removeHs =
false);
429 bool sanitize =
false,
430 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 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...