RDKit: ReactionPickler.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
ReactionPickler.h
Go to the documentation of this file.
1//
2// Copyright (C) 2009 Greg Landrum
3// Copyright (c) 2014, Novartis Institutes for BioMedical Research Inc.
4//
5// @@ All Rights Reserved @@
6// This file is part of the RDKit.
7// The contents are covered by the terms of the BSD license
8// which is included in the file license.txt, found at the root
9// of the RDKit source tree.
10//
11#include <RDGeneral/export.h>
12#ifndef RD_RXNPICKLE_H_2JUNE2009
13#define RD_RXNPICKLE_H_2JUNE2009
14
15#include <GraphMol/MolPickler.h>
16// Std stuff
17#include <string>
18#include <exception>
19#ifdef WIN32
20#include <ios>
21#endif
22
23namespace RDKit {
24class ChemicalReaction;
25
26//! used to indicate exceptions whilst pickling (serializing) reactions
27 class RDKIT_CHEMREACTIONS_EXPORT ReactionPicklerException
28 : public std::exception {
29 public:
30 ReactionPicklerException(const char *msg) : _msg(msg) {}
31 ReactionPicklerException(const std::string msg) : _msg(msg) {}
32 const char *what() const noexcept override { return _msg.c_str(); }
33 ~ReactionPicklerException() noexcept override = default;
34
35 private:
36 std::string _msg;
37};
38
39//! handles pickling (serializing) reactions
40class RDKIT_CHEMREACTIONS_EXPORT ReactionPickler {
41 public:
42 static const std::int32_t versionMajor; //!< mark the pickle version
43 static const std::int32_t versionMinor; //!< mark the pickle version
44 static const std::int32_t versionPatch; //!< mark the pickle version
45 static const std::int32_t endianId; //!< mark the endian-ness of the pickle
46
47 //! the pickle format is tagged using these tags:
48 //! NOTE: if you add to this list, be sure to put new entries AT THE BOTTOM,
49 //! otherwise you will break old pickles.
50 typedef enum {
51 VERSION = 10000,
52 BEGINREACTANTS,
53 ENDREACTANTS,
54 BEGINPRODUCTS,
55 ENDPRODUCTS,
56 BEGINAGENTS,
57 ENDAGENTS,
58 ENDREACTION,
59 BEGINPROPS,
60 ENDPROPS,
61 BEGINSSSPARAMS,
62 ENDSSSPARAMS
63 } Tags;
64
65 //! pickles a reaction and sends the results to stream \c ss
66 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss,
67 unsigned int propertyFlags);
68 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss);
69 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss) {
70 ReactionPickler::pickleReaction(&rxn, ss);
71 }
72 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss,
73 unsigned int propertyFlags) {
74 ReactionPickler::pickleReaction(&rxn, ss, propertyFlags);
75 }
76 //! pickles a reaction and adds the results to string \c res
77 static void pickleReaction(const ChemicalReaction *rxn, std::string &res,
78 unsigned int propertyFlags);
79 static void pickleReaction(const ChemicalReaction *rxn, std::string &res);
80 static void pickleReaction(const ChemicalReaction &rxn, std::string &res) {
81 ReactionPickler::pickleReaction(&rxn, res);
82 }
83 static void pickleReaction(const ChemicalReaction &rxn, std::string &res,
84 unsigned int propertyFlags) {
85 ReactionPickler::pickleReaction(&rxn, res, propertyFlags);
86 }
87
88 //! constructs a reaction from a pickle stored in a
89 //! string
90 static void reactionFromPickle(const std::string &pickle,
91 ChemicalReaction *rxn);
92 static void reactionFromPickle(const std::string &pickle,
93 ChemicalReaction &rxn) {
94 ReactionPickler::reactionFromPickle(pickle, &rxn);
95 }
96
97 //! constructs a reaction from a pickle stored in a
98 //! stream
99 static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn);
100 static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn) {
101 ReactionPickler::reactionFromPickle(ss, &rxn);
102 }
103
104 private:
105 //! do the actual work of pickling a reaction
106 static void _pickle(const ChemicalReaction *rxn, std::ostream &ss,
107 unsigned int propertyFlags);
108
109 //! do the actual work of de-pickling a reaction
110 static void _depickle(std::istream &ss, ChemicalReaction *rxn, int version);
111
112 //! pickle standard properties
113 static void _pickleProperties(std::ostream &ss, const RDProps &props,
114 unsigned int pickleFlags);
115 //! unpickle standard properties
116 static void _unpickleProperties(std::istream &ss, RDProps &props);
117};
118}; // namespace RDKit
119
120#endif
MolPickler.h
RDKit::ChemicalReaction
This is a class for storing and applying general chemical reactions.
Definition Reaction.h:121
RDKit::RDProps
Definition RDProps.h:14
RDKit::ReactionPicklerException::~ReactionPicklerException
~ReactionPicklerException() noexcept override=default
RDKit::ReactionPicklerException::what
const char * what() const noexcept override
Definition ReactionPickler.h:32
RDKit::ReactionPicklerException::ReactionPicklerException
ReactionPicklerException(const char *msg)
Definition ReactionPickler.h:30
RDKit::ReactionPicklerException::ReactionPicklerException
ReactionPicklerException(const std::string msg)
Definition ReactionPickler.h:31
RDKit::ReactionPickler
handles pickling (serializing) reactions
Definition ReactionPickler.h:40
RDKit::ReactionPickler::endianId
static const std::int32_t endianId
mark the endian-ness of the pickle
Definition ReactionPickler.h:45
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss)
Definition ReactionPickler.h:69
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss, unsigned int propertyFlags)
Definition ReactionPickler.h:72
RDKit::ReactionPickler::reactionFromPickle
static void reactionFromPickle(const std::string &pickle, ChemicalReaction *rxn)
RDKit::ReactionPickler::versionMajor
static const std::int32_t versionMajor
mark the pickle version
Definition ReactionPickler.h:42
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction *rxn, std::string &res)
RDKit::ReactionPickler::reactionFromPickle
static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn)
Definition ReactionPickler.h:100
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction &rxn, std::string &res)
Definition ReactionPickler.h:80
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction &rxn, std::string &res, unsigned int propertyFlags)
Definition ReactionPickler.h:83
RDKit::ReactionPickler::versionPatch
static const std::int32_t versionPatch
mark the pickle version
Definition ReactionPickler.h:44
RDKit::ReactionPickler::reactionFromPickle
static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn)
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss, unsigned int propertyFlags)
pickles a reaction and sends the results to stream ss
RDKit::ReactionPickler::versionMinor
static const std::int32_t versionMinor
mark the pickle version
Definition ReactionPickler.h:43
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction *rxn, std::string &res, unsigned int propertyFlags)
pickles a reaction and adds the results to string res
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss)
RDKit::ReactionPickler::BEGINPRODUCTS
@ BEGINPRODUCTS
Definition ReactionPickler.h:54
RDKit::ReactionPickler::VERSION
@ VERSION
Definition ReactionPickler.h:51
RDKit::ReactionPickler::BEGINREACTANTS
@ BEGINREACTANTS
Definition ReactionPickler.h:52
RDKit::ReactionPickler::ENDPROPS
@ ENDPROPS
Definition ReactionPickler.h:60
RDKit::ReactionPickler::ENDPRODUCTS
@ ENDPRODUCTS
Definition ReactionPickler.h:55
RDKit::ReactionPickler::ENDREACTION
@ ENDREACTION
Definition ReactionPickler.h:58
RDKit::ReactionPickler::ENDSSSPARAMS
@ ENDSSSPARAMS
Definition ReactionPickler.h:62
RDKit::ReactionPickler::ENDAGENTS
@ ENDAGENTS
Definition ReactionPickler.h:57
RDKit::ReactionPickler::BEGINSSSPARAMS
@ BEGINSSSPARAMS
Definition ReactionPickler.h:61
RDKit::ReactionPickler::ENDREACTANTS
@ ENDREACTANTS
Definition ReactionPickler.h:53
RDKit::ReactionPickler::BEGINPROPS
@ BEGINPROPS
Definition ReactionPickler.h:59
RDKit::ReactionPickler::BEGINAGENTS
@ BEGINAGENTS
Definition ReactionPickler.h:56
RDKit::ReactionPickler::reactionFromPickle
static void reactionFromPickle(const std::string &pickle, ChemicalReaction &rxn)
Definition ReactionPickler.h:92
export.h
RDKIT_CHEMREACTIONS_EXPORT
#define RDKIT_CHEMREACTIONS_EXPORT
Definition export.h:57
RDKit
Std stuff.
Definition Abbreviations.h:19