RDKit
Open-source cheminformatics and machine learning.
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.
51 typedef enum {
52 VERSION = 10000,
61 ENDPROPS
62 } Tags;
63
64 //! pickles a reaction and sends the results to stream \c ss
65 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss,
66 unsigned int propertyFlags);
67 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss);
68 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss) {
70 }
71 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss,
72 unsigned int propertyFlags) {
73 ReactionPickler::pickleReaction(&rxn, ss, propertyFlags);
74 }
75 //! pickles a reaction and adds the results to string \c res
76 static void pickleReaction(const ChemicalReaction *rxn, std::string &res,
77 unsigned int propertyFlags);
78 static void pickleReaction(const ChemicalReaction *rxn, std::string &res);
79 static void pickleReaction(const ChemicalReaction &rxn, std::string &res) {
81 }
82 static void pickleReaction(const ChemicalReaction &rxn, std::string &res,
83 unsigned int propertyFlags) {
84 ReactionPickler::pickleReaction(&rxn, res, propertyFlags);
85 }
86
87 //! constructs a reaction from a pickle stored in a
88 //! string
89 static void reactionFromPickle(const std::string &pickle,
90 ChemicalReaction *rxn);
91 static void reactionFromPickle(const std::string &pickle,
92 ChemicalReaction &rxn) {
94 }
95
96 //! constructs a reaction from a pickle stored in a
97 //! stream
98 static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn);
99 static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn) {
101 }
102
103 private:
104 //! do the actual work of pickling a reaction
105 static void _pickle(const ChemicalReaction *rxn, std::ostream &ss,
106 unsigned int propertyFlags);
107
108 //! do the actual work of de-pickling a reaction
109 static void _depickle(std::istream &ss, ChemicalReaction *rxn, int version);
110
111 //! pickle standard properties
112 static void _pickleProperties(std::ostream &ss, const RDProps &props,
113 unsigned int pickleFlags);
114 //! unpickle standard properties
115 static void _unpickleProperties(std::istream &ss, RDProps &props);
116};
117}; // namespace RDKit
118
119#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
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
RDKIT_CHEMREACTIONS_EXPORT void pickle(const boost::shared_ptr< EnumerationStrategyBase > &enumerator, std::ostream &ss)
pickles a EnumerationStrategy and adds the results to a stream ss
Std stuff.
Definition: Abbreviations.h:18