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 
24 namespace RDKit {
25 class ChemicalReaction;
26 
27 //! used to indicate exceptions whilst pickling (serializing) reactions
29  public:
30  ReactionPicklerException(const char *msg) : _msg(msg){};
31  ReactionPicklerException(const std::string msg) : _msg(msg){};
32  const char *message() const { return _msg.c_str(); };
34 
35  private:
36  std::string _msg;
37 };
38 
39 //! handles pickling (serializing) reactions
41  public:
42  static const boost::int32_t versionMajor; //!< mark the pickle version
43  static const boost::int32_t versionMinor; //!< mark the pickle version
44  static const boost::int32_t versionPatch; //!< mark the pickle version
45  static const boost::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,
60  ENDPROPS
61  } Tags;
62 
63  //! pickles a reaction and sends the results to stream \c ss
64  static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss,
65  unsigned int propertyFlags);
66  static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss);
67  static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss) {
69  };
70  static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss,
71  unsigned int propertyFlags) {
72  ReactionPickler::pickleReaction(&rxn, ss, propertyFlags);
73  };
74  //! pickles a reaction and adds the results to string \c res
75  static void pickleReaction(const ChemicalReaction *rxn, std::string &res,
76  unsigned int propertyFlags);
77  static void pickleReaction(const ChemicalReaction *rxn, std::string &res);
78  static void pickleReaction(const ChemicalReaction &rxn, std::string &res) {
80  };
81  static void pickleReaction(const ChemicalReaction &rxn, std::string &res,
82  unsigned int propertyFlags) {
83  ReactionPickler::pickleReaction(&rxn, res, propertyFlags);
84  };
85 
86  //! constructs a reaction from a pickle stored in a
87  //! string
88  static void reactionFromPickle(const std::string &pickle,
89  ChemicalReaction *rxn);
90  static void reactionFromPickle(const std::string &pickle,
91  ChemicalReaction &rxn) {
93  };
94 
95  //! constructs a reaction from a pickle stored in a
96  //! stream
97  static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn);
98  static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn) {
100  };
101 
102  private:
103  //! do the actual work of pickling a reaction
104  static void _pickle(const ChemicalReaction *rxn, std::ostream &ss,
105  unsigned int propertyFlags);
106 
107  //! do the actual work of de-pickling a reaction
108  static void _depickle(std::istream &ss, ChemicalReaction *rxn, int version);
109 
110  //! pickle standard properties
111  static void _pickleProperties(std::ostream &ss, const RDProps &props,
112  unsigned int pickleFlags);
113  //! unpickle standard properties
114  static void _unpickleProperties(std::istream &ss, RDProps &props);
115 };
116 };
117 
118 #endif
static void pickleReaction(const ChemicalReaction &rxn, std::string &res, unsigned int propertyFlags)
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss, unsigned int propertyFlags)
static const boost::int32_t versionPatch
mark the pickle version
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss)
const char * message() const
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:118
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
ReactionPicklerException(const std::string msg)
used to indicate exceptions whilst pickling (serializing) reactions
static void reactionFromPickle(const std::string &pickle, ChemicalReaction *rxn)
static const boost::int32_t versionMinor
mark the pickle version
static void reactionFromPickle(const std::string &pickle, ChemicalReaction &rxn)
Std stuff.
Definition: Atom.h:30
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss, unsigned int propertyFlags)
pickles a reaction and sends the results to stream ss
Tags
mark the endian-ness of the pickle
static void pickleReaction(const ChemicalReaction &rxn, std::string &res)
static const boost::int32_t endianId
static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn)
static const boost::int32_t versionMajor
mark the pickle version
#define RDKIT_CHEMREACTIONS_EXPORT
Definition: export.h:60
handles pickling (serializing) reactions
ReactionPicklerException(const char *msg)