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 <iostream>
18#include <string>
19#include <exception>
20#ifdef WIN32
21#include <ios>
22#endif
23
24namespace RDKit {
25class ChemicalReaction;
26
27//! used to indicate exceptions whilst pickling (serializing) reactions
29 : public std::exception {
30 public:
31 ReactionPicklerException(const char *msg) : _msg(msg) {}
32 ReactionPicklerException(const std::string msg) : _msg(msg) {}
33 const char *what() const noexcept override { return _msg.c_str(); }
34 ~ReactionPicklerException() noexcept override = default;
35
36 private:
37 std::string _msg;
38};
39
40//! handles pickling (serializing) reactions
42 public:
43 static const std::int32_t versionMajor; //!< mark the pickle version
44 static const std::int32_t versionMinor; //!< mark the pickle version
45 static const std::int32_t versionPatch; //!< mark the pickle version
46 static const std::int32_t endianId; //!< mark the endian-ness of the pickle
47
48 //! the pickle format is tagged using these tags:
49 //! NOTE: if you add to this list, be sure to put new entries AT THE BOTTOM,
50 //! otherwise you will break old pickles.
65
66 //! pickles a reaction and sends the results to stream \c ss
67 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss,
68 unsigned int propertyFlags);
69 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss);
70 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss) {
71 ReactionPickler::pickleReaction(&rxn, ss);
72 }
73 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss,
74 unsigned int propertyFlags) {
75 ReactionPickler::pickleReaction(&rxn, ss, propertyFlags);
76 }
77 //! pickles a reaction and adds the results to string \c res
78 static void pickleReaction(const ChemicalReaction *rxn, std::string &res,
79 unsigned int propertyFlags);
80 static void pickleReaction(const ChemicalReaction *rxn, std::string &res);
81 static void pickleReaction(const ChemicalReaction &rxn, std::string &res) {
82 ReactionPickler::pickleReaction(&rxn, res);
83 }
84 static void pickleReaction(const ChemicalReaction &rxn, std::string &res,
85 unsigned int propertyFlags) {
86 ReactionPickler::pickleReaction(&rxn, res, propertyFlags);
87 }
88
89 //! constructs a reaction from a pickle stored in a
90 //! string
91 static void reactionFromPickle(const std::string &pickle,
92 ChemicalReaction *rxn);
93 static void reactionFromPickle(const std::string &pickle,
94 ChemicalReaction &rxn) {
95 ReactionPickler::reactionFromPickle(pickle, &rxn);
96 }
97
98 //! constructs a reaction from a pickle stored in a
99 //! stream
100 static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn);
101 static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn) {
102 ReactionPickler::reactionFromPickle(ss, &rxn);
103 }
104
105 private:
106 //! do the actual work of pickling a reaction
107 static void _pickle(const ChemicalReaction *rxn, std::ostream &ss,
108 unsigned int propertyFlags);
109
110 //! do the actual work of de-pickling a reaction
111 static void _depickle(std::istream &ss, ChemicalReaction *rxn, int version);
112
113 //! pickle standard properties
114 static void _pickleProperties(std::ostream &ss, const RDProps &props,
115 unsigned int pickleFlags);
116 //! unpickle standard properties
117 static void _unpickleProperties(std::istream &ss, RDProps &props);
118};
119}; // namespace RDKit
120
121#endif
This is a class for storing and applying general chemical reactions.
Definition Reaction.h:121
used to indicate exceptions whilst pickling (serializing) reactions
~ReactionPicklerException() noexcept override=default
const char * what() const noexcept override
ReactionPicklerException(const char *msg)
ReactionPicklerException(const std::string msg)
handles pickling (serializing) reactions
static const std::int32_t endianId
mark the endian-ness of the pickle
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss)
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss, unsigned int propertyFlags)
static void reactionFromPickle(const std::string &pickle, ChemicalReaction *rxn)
static const std::int32_t versionMajor
mark the pickle version
static void pickleReaction(const ChemicalReaction *rxn, std::string &res)
static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn)
static void pickleReaction(const ChemicalReaction &rxn, std::string &res)
static void pickleReaction(const ChemicalReaction &rxn, std::string &res, unsigned int propertyFlags)
static const std::int32_t versionPatch
mark the pickle version
static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn)
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss, unsigned int propertyFlags)
pickles a reaction and sends the results to stream ss
static const std::int32_t versionMinor
mark the pickle version
static void pickleReaction(const ChemicalReaction *rxn, std::string &res, unsigned int propertyFlags)
pickles a reaction and adds the results to string res
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss)
static void reactionFromPickle(const std::string &pickle, ChemicalReaction &rxn)
#define RDKIT_CHEMREACTIONS_EXPORT
Definition export.h:49
Std stuff.