RDKit
Open-source cheminformatics and machine learning.
MolCatalogEntry.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Greg Landrum
3 //
4 #ifndef _RD_MOLCATALOGENTRY_H_
5 #define _RD_MOLCATALOGENTRY_H_
6 
7 #include <RDGeneral/Dict.h>
9 #include <fstream>
10 #include <string>
11 
12 namespace RDKit {
13 class ROMol;
14 
15 //! This class is used to store ROMol objects in a MolCatalog
17  public:
18  MolCatalogEntry() : dp_mol(0), d_descrip("") {
19  dp_props = new Dict();
20  setBitId(-1);
21  }
22 
23  //! copy constructor
24  MolCatalogEntry(const MolCatalogEntry &other);
25 
26  //! create an entry to hold the provided ROMol
27  /*!
28  The MolCatalogEntry takes ownership of the pointer
29  */
30  MolCatalogEntry(const ROMol *omol);
31 
32  //! construct from a pickle
33  MolCatalogEntry(const std::string &pickle) { this->initFromString(pickle); }
34 
36 
37  std::string getDescription() const { return d_descrip; }
38 
39  void setDescription(std::string val) { d_descrip = val; }
40 
41  unsigned int getOrder() const { return d_order; };
42  void setOrder(unsigned int order) { d_order = order; };
43 
44  const ROMol *getMol() const { return dp_mol; };
45  //! hold the provided ROMol
46  /*!
47  The MolCatalogEntry takes ownership of the pointer.
48  If the MolCatalogEntry already has a molecule, this one will be deleted.
49  */
50  void setMol(const ROMol *molPtr);
51 
52  //! set a named property
53  template <typename T>
54  void setProp(const char *key, T &val) const {
55  dp_props->setVal(key, val);
56  }
57 
58  //! \overload
59  template <typename T>
60  void setProp(const std::string &key, T &val) const {
61  setProp(key.c_str(), val);
62  }
63 
64  //! get the value of a named property
65  template <typename T>
66  void getProp(const char *key, T &res) const {
67  dp_props->getVal(key, res);
68  }
69  //! \overload
70  template <typename T>
71  void getProp(const std::string &key, T &res) const {
72  getProp(key.c_str(), res);
73  }
74 
75  //! returns true if such a property exists
76  bool hasProp(const char *key) const {
77  if (!dp_props) return false;
78  return dp_props->hasVal(key);
79  }
80  //! \overload
81  bool hasProp(const std::string &key) const { return hasProp(key.c_str()); }
82 
83  //! clears a named property
84  void clearProp(const char *key) const { dp_props->clearVal(key); }
85  //! \overload
86  void clearProp(const std::string &key) const { clearProp(key.c_str()); }
87 
88  //! serializes this entry to the stream
89  void toStream(std::ostream &ss) const;
90  //! returns a serialized (pickled) form of the entry
91  std::string Serialize() const;
92  //! initialize from a stream containing a pickle
93  void initFromStream(std::istream &ss);
94  //! initialize from a string containing a pickle
95  void initFromString(const std::string &text);
96 
97  private:
98  const ROMol *dp_mol;
99  Dict *dp_props;
100 
101  unsigned int d_order;
102  std::string d_descrip;
103 };
104 }
105 
106 #endif
unsigned int getOrder() const
bool hasVal(const std::string &what) const
Returns whether or not the dictionary contains a particular key.
Definition: Dict.h:90
This class is used to store ROMol objects in a MolCatalog.
void setVal(const std::string &what, T &val)
Sets the value associated with a key.
Definition: Dict.h:186
bool hasProp(const std::string &key) const
bool hasProp(const char *key) const
returns true if such a property exists
void getProp(const std::string &key, T &res) const
void initFromString(const std::string &text)
initialize from a string containing a pickle
Defines the Dict class.
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:106
void clearVal(const std::string &what)
Clears the value associated with a particular key, removing the key from the dictionary.
Definition: Dict.h:248
void getVal(const std::string &what, T &res) const
Gets the value associated with a particular key.
Definition: Dict.h:125
void setOrder(unsigned int order)
void setBitId(int bid)
sets our bit Id
Definition: CatalogEntry.h:24
const ROMol * getMol() const
std::string getDescription() const
returns a text description of this entry
void setProp(const char *key, T &val) const
set a named property
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
void clearProp(const char *key) const
clears a named property
void setMol(const ROMol *molPtr)
hold the provided ROMol
Abstract base class to be used to represent an entry in a Catalog.
Definition: CatalogEntry.h:19
void setProp(const std::string &key, T &val) const
MolCatalogEntry(const std::string &pickle)
construct from a pickle
void initFromStream(std::istream &ss)
initialize from a stream containing a pickle
std::string Serialize() const
returns a serialized (pickled) form of the entry
void toStream(std::ostream &ss) const
serializes this entry to the stream
The Dict class can be used to store objects of arbitrary type keyed by strings.
Definition: Dict.h:35
void setDescription(std::string val)
void clearProp(const std::string &key) const
void pickle(const boost::shared_ptr< EnumerationStrategyBase > &enumerator, std::ostream &ss)
pickles a EnumerationStrategy and adds the results to a stream ss
void getProp(const char *key, T &res) const
get the value of a named property